GetProfiles:获取媒体信息文件

鉴权:但是在使用这个接口之前是需要鉴权的。ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需要鉴权的接口时不使用鉴权,会导致接口调用失败。实现鉴权的方式之一可以调用gSOAP源码中的 soap_wsse_add_UsernameTokenDigest()函数。要安装依赖库OpenSSL

实现代码:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h> #include "soapH.h"
#include "stdsoap2.h"
#include "soapStub.h"
#include "wsseapi.h" #include "wsdd.nsmap" //命名空间 static struct soap* ONVIF_Initsoap(struct SOAP_ENV__Header *header, const char *was_To, const char *was_Action, int timeout)
{
struct soap *soap = NULL; // soap环境变量
unsigned char macaddr[];
char _HwId[];
unsigned int Flagrand; soap = soap_new();
if(soap == NULL)
{
printf("[%d]soap = NULL\n", __LINE__);
return NULL;
} soap_set_namespaces(soap, namespaces); // 设置soap的namespaces,即设置命名空间 // 设置超时(超过指定时间没有数据就退出)
if(timeout > )
{
soap->recv_timeout = timeout;
soap->send_timeout = timeout;
soap->connect_timeout = timeout;
}
else
{
//Maximum waittime : 20s
soap->recv_timeout = ;
soap->send_timeout = ;
soap->connect_timeout = ;
} soap_default_SOAP_ENV__Header(soap, header); //Create SessionID randomly,生成uuid(windows下叫guid,linux下叫uuid),格式为urn:uuid:8-4-4-4-12,由系统随机产生
srand((int)time());
Flagrand = rand()% + ;
macaddr[] = 0x1;
macaddr[] = 0x2;
macaddr[] = 0x3;
macaddr[] = 0x4;
macaddr[] = 0x5;
macaddr[] = 0x6;
sprintf(_HwId, "urn:uuid:%ud68a-1dd2-11b2-a105-%02X%02X%02X%02X%02X%02X", Flagrand, macaddr[], macaddr[], macaddr[],macaddr[],macaddr[],macaddr[]);
header->wsa__MessageID = (char *)malloc();
memset(header->wsa__MessageID, , );
strncpy(header->wsa__MessageID, _HwId, strlen(_HwId)); //wsa__MessageID存放的是uuid if(was_Action != NULL)
{
header->wsa__Action = (char*)malloc();
memset(header->wsa__Action, '\0', );
strncpy(header->wsa__Action, was_Action, ); //
}
if(was_To != NULL)
{
header->wsa__To = (char *)malloc();
memset(header->wsa__To, '\0', );
strncpy(header->wsa__To, was_To, );//"urn:schemas-xmlsoap-org:ws:2005:04:discovery";
}
soap->header = header;
return soap;
} //释放函数
void ONVIF_soap_delete(struct soap *soap)
{
soap_destroy(soap); // remove deserialized class instances (C++ only)
soap_end(soap); // Clean up deserialized data (except class instances) and temporary data
soap_free(soap); // Reset and deallocate the context created with soap_new or soap_copy
} //鉴权
static int ONVIF_SetAuthInfo(struct soap *soap, const char *username, const char *password)
{
int result = ;
if((NULL != username) || (NULL != password)){
soap_wsse_add_UsernameTokenDigest(soap, NULL, username, password);
}else{
printf("un etAuth\n");
result = -;
} return result;
} int main(int argc,char *argv[])
{
int i = ;
int ret = ;
char media_addr[] = "http://172.168.0.211/onvif/media_service"; //GetCapabilities得到的地址
char media_addr2[] = "http://172.168.0.211/onvif/media2_service"; //GetServices得到的地址
struct SOAP_ENV__Header header;
struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, ); struct _tr2__GetProfiles tr2__GetProfiles;
struct _tr2__GetProfilesResponse tr2__GetProfilesResponse; tr2__GetProfiles.__sizeType = ;
tr2__GetProfiles.Token = NULL;
tr2__GetProfiles.Type = NULL;
ONVIF_SetAuthInfo(soap,"admin",""); //鉴权
soap_call___tr2__GetProfiles(soap, media_addr2, NULL, &tr2__GetProfiles, &tr2__GetProfilesResponse); if(soap->error){
ret = -;
printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
return ret;
}else{
for(i=; i<tr2__GetProfilesResponse.__sizeProfiles; i++)
{
printf( "Profiles Name:%s \n",tr2__GetProfilesResponse.Profiles[i].Name);
printf( "Profiles Taken:%s\n",tr2__GetProfilesResponse.Profiles[i].token);
}
} ONVIF_soap_delete(soap);
return ret;
}

编译:gcc -o test get_ GetProfiles_test.c stdsoap2.c soapC.c md5.c dom.c mecevp.c smdevp.c threads.c wsaapi.c wsseapi.c soapClient.c -I import/ -DWITH_OPENSSL -lssl -lcrypto -ldl -pthread

结果:

 

Linux下onvif客户端获取ipc摄像头 GetProfiles:获取h265媒体信息文件的更多相关文章

  1. Linux下onvif客户端关于ipc摄像头的搜索

    设备搜索:要访问一个IPC摄像头,或者说要调用IPC摄像头提供的WEB服务接口,就要先知道其IP地址,这就是设备发现的过程,或者叫设备搜索的过程.IPC摄像头用的是239.255.255.250(端口 ...

  2. Linux下onvif客户端获取h265 IPC摄像头的RTSP地址

    1. 设备搜索,去获取webserver 的地址 ,目的是在获取能力提供服务地址,demo:https://www.cnblogs.com/croxd/p/10683429.html 2. GetCa ...

  3. Linux下onvif客户端获取ipc摄像头 GetServices:获取媒体地址(有的h265摄像头必须要这个接口)

    GetServices:获取媒体地址(有些h265的摄像头必须用到这个接口,得到获取能力时没获取到的另一个媒体地址) 鉴权:但是在使用这个接口之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部 ...

  4. Linux下onvif客户端获取ipc摄像头 GetStreamUri:rtsp地址(h264、h265)

    GetStreamUri:rtsp地址 鉴权:但是在使用这个接口之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需要鉴权的接口时不使用鉴权,会导致接口调用失败.实现鉴 ...

  5. Linux下onvif客户端获取ipc摄像头 获取能力:GetCapabilities

    GetCapabilities:获取能力,主要目的获取设备能力信息(获取媒体服务地址) 鉴权:但是在调用获取设备能力之前是需要鉴权的.ONVIF协议规定,部分接口需要鉴权,部分接口不需要鉴权,在调用需 ...

  6. Linux下librdkafka客户端的编译运行

    Linux下librdkafka客户端的编译运行 librdkafka是一个开源的Kafka客户端C/C++实现,提供了Kafka生产者.消费者接口. 由于项目需要,我要将Kafka生产者接口封装起来 ...

  7. Linux 下 简单客户端服务器通讯模型(TCP)

    原文:Linux 下 简单客户端服务器通讯模型(TCP) 服务器端:server.c #include<stdio.h> #include<stdlib.h> #include ...

  8. Linux下用FFMPEG采集usb摄像头到RTMP

    Linux下用 FFMPEG 采集 usb摄像头视频 和 摄像头内置麦克风音频 到RTMP服务   ffmpeg -f video4linux2 -qscale 10 -r 12 -s 640x480 ...

  9. Linux下安装mysql5.6.11(找点有用的信息太费劲)(转)

    Linux下安装mysql5.6.11(找点有用的信息太费劲) (2013-04-25 10:25:09)     1.申请阿里云Linux服务器 昨天在阿里云申请了一个免费试用5天的Linux云服务 ...

随机推荐

  1. 然之协同系统6.4.1 SQL注入导致getshell

     前言 先知上一个大佬挖的洞,也有了简单的分析 https://xianzhi.aliyun.com/forum/topic/2135 我自己复现分析过程,漏洞的原理比较简单,但是漏洞的利用方式对我而 ...

  2. [算法练习]Excel Sheet Column Title

    题目: Given a positive integer, return its corresponding column title as appear in an Excel sheet. For ...

  3. 实用爬虫-02-爬虫真正使用代理 ip

    实用爬虫-02-爬虫真正使用代理 ip 因为这里呢,是实用爬虫,想要仔细学习一些基础的,可以去查看: Python 爬虫教程:https://www.cnblogs.com/xpwi/category ...

  4. Python爬虫教程-07-post介绍(百度翻译)(上)

    Python爬虫教程-07-post介绍(百度翻译)(上) 访问网络两种方法 get: 利用参数给服务器传递信息 参数为dict,使用parse编码 post :(今天给大家介绍的post) 一般向服 ...

  5. 小米OJ 有多少个等差数列

    题目链接 https://code.mi.com/problem/list/view?id=20 代码 #include <bits/stdc++.h> using namespace s ...

  6. Python初学者第二十一天 函数(4)-内置函数

    21day 内置函数: 1.abs()绝对值函数 2.dict()创建一个字典 3.help()获取帮助信息 4.min()从一个列表中取出最小的数 5.max()从一个列表中取出最大值 6.bool ...

  7. HTML简单框架网页制作 吴昊

  8. Linux kill/pkill/killall命令详解

    kill kill(terminate a process)命令用来终止指定的进程, 对于一个后台进程就须用kill命令来终止,我们就需要先使用ps/pidof/pstree/top等工具获取进程PI ...

  9. 【MySQL】MySQL数据库再安装

    解决问题 安装时提示此产品配置信息损坏,怎么办? 环境检测时未响应,怎么办? 服务不能启动,怎么办? 输入密码不能登陆,不使用密码却能登录,是什么原因? 涉及到的错误代码:windows启动MySQL ...

  10. wind10优化

    windows10启动优化 启动时: 1)关闭windows自动更新 2)关闭windows防火墙 3)关闭Windows Defender (1)使用快捷键(WIN+R)调出运行工具,然后再输入组策 ...