GetServices:获取媒体地址(有些h265的摄像头必须用到这个接口,得到获取能力时没获取到的另一个媒体地址)

鉴权:但是在使用这个接口之前是需要鉴权的。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 secvre_addr[] = "http://172.168.0.211/onvif/device_service"; //设备搜索获取得到的服务地址
struct SOAP_ENV__Header header;
struct _tds__GetServices *tds__GetServices;
struct _tds__GetServicesResponse *tds__GetServicesResponse; struct soap* soap = ONVIF_Initsoap(&header, NULL, NULL, ); //tds__GetServices->IncludeCapability = (enum xsd__boolean *)soap_malloc(soap, sizeof(int));
//*(tds__GetServices->IncludeCapability) = (enum xsd__boolean)0; tds__GetServices->IncludeCapability = ; ONVIF_SetAuthInfo(soap,"admin",""); //鉴权
soap_call___tds__GetServices(soap,secvre_addr,NULL, tds__GetServices, tds__GetServicesResponse);
if(soap->error){
ret = -;
printf("soap error: %d, %s, %s\n", soap->error, *soap_faultcode(soap), *soap_faultstring(soap));
return ret;
}else{
if (tds__GetServicesResponse->Service[i].Namespace != NULL ){
for(i=; i<tds__GetServicesResponse->__sizeService; i++)
{
if(strcmp(tds__GetServicesResponse->Service[i].Namespace, "http://www.onvif.org/ver20/media/wsdl") == )
{
printf(" media_addr[%d] %s\n", i, tds__GetServicesResponse->Service[i].XAddr);
}
if(strcmp(tds__GetServicesResponse->Service[i].Namespace, "http://www.onvif.org/ver10/media/wsdl") == )
{
printf(" media_addr->XAddr[%d] %s\n", i, tds__GetServicesResponse->Service[i].XAddr); }
} }
} ONVIF_soap_delete(soap);
return ret;
}

编译:gcc -o test get_GetServices_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

结果:

Linux下onvif客户端获取ipc摄像头 GetServices:获取媒体地址(有的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摄像头 GetStreamUri:rtsp地址(h264、h265)

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

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

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

  5. Linux下onvif客户端获取ipc摄像头 GetProfiles:获取h265媒体信息文件

    GetProfiles:获取媒体信息文件 鉴权:但是在使用这个接口之前是需要鉴权的.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下,如何监控某个进程到底向哪个地址发起了网络调用

    Linux下,如何监控某个进程到底向哪个地址发起了网络调用 有时候,有些应用,比如idea,你发起某个操作时,其底层会去请求网络,获取一些数据. 但是不知道,请求了什么地址.举个例子,在idea中,m ...

  9. Linux下的几种IPC方式及其C语言实现

    写在前面:本博客为本人原创,严禁任何形式的转载!本博客只允许放在博客园(.cnblogs.com),如果您在其他网站看到这篇博文,请通过下面这个唯一的合法链接转到原文! 本博客全网唯一合法URL:ht ...

随机推荐

  1. MyBatis -01- 初识 MyBatis + MyBatis 环境搭建

    MyBatis -01- 初识 MyBatis + MyBatis 环境搭建 MyBatis 本是 apache 的一个开源项目 iBatis(iBATIS = "internet" ...

  2. 如何快速开发一个支持高效、高并发的分布式ID生成器

    ID生成器是指能产生不重复ID服务的程序,在后台开发过程中,尤其是分布式服务.微服务程序开发过程中,经常会用到,例如,为用户的每个请求产生一个唯一ID.为每个消息产生一个ID等等,ID生成器也是进行无 ...

  3. 理解 Linux 的平均负载和性能监控

      在本文中,我们将解释 Linux 系统中最关键的管理任务之一——关于系统 / CPU 的负载load和平均负载Load average的性能监控. 首先来看所有的类 UNIX 系统中两个重要的表述 ...

  4. java+redis+lua生成自动增长的ID序列号

    1.编写lua脚本用于生成主键ID序列号,内容如下 local key = tostring(KEYS[1]); local count = tonumber(KEYS[2]); local date ...

  5. September 15th 2017 Week 37th Friday

    First I need your hand, then forever can begin. 我需要牵着你的手,才能告诉你什么是永远. If you want to shake hands with ...

  6. MyISAM和innoDB对比,覆盖索引简单回顾

    MyISAM Myisam是Mysql的默认存储引擎,当create创建新表时,未指定新表的存储引擎时,默认使用Myisam. 它不支持事务,也不支持外键,尤其是访问速度快,对事务完整性没有要求或者以 ...

  7. SAP CX Upscale Commerce : SAP全新推出的电商云平台

    大家好,我是Andy Chen,是SAP成都研究院年轻的SAP CX Upscale Commerce (后面将会以Upscale简称)开发团队的一名产品经理.CX的全称是Customer Exper ...

  8. acl 4 year statistics

  9. AbstractApplicationContext 笔记

    一.这个类的属性 public abstract class AbstractApplicationContext extends DefaultResourceLoader implements C ...

  10. 本地项目关联git仓库

    Command line instructions Git global setup git config --global user.name "zhoushuo" git co ...