/*
* =====================================================================================
*
* Filename: main.c
* Description: 简单例程测试:客户端通过ONVIF协议搜索前端设备
* Compiler: gcc
* Author: miibotree
*
* =====================================================================================
*/
#include "wsdd.h"
#include "wsseapi.h"
#include <stdio.h>
#define ONVIF_USER "admin"
#define ONVIF_PASSWORD "19921203"
static struct soap* ONVIF_Initsoap(struct SOAP_ENV__Header *header, const char *was_To, const char *was_Action, int timeout);
int ONVIF_ClientDiscovery( );
int ONVIF_Capabilities(struct __wsdd__ProbeMatches *resp);
void UserGetProfiles(struct soap *soap, struct _tds__GetCapabilitiesResponse *capa_resp);
void UserGetUri(struct soap *soap, struct _trt__GetProfilesResponse *trt__GetProfilesResponse,struct _tds__GetCapabilitiesResponse *capa_resp);
int HasDev = 0;//the number of devices
int main(void )
{
//发现协议
if (ONVIF_ClientDiscovery() != 0 )
{
printf("discovery failed!\n");
return -1;
}
return 0;
}
//初始化soap函数
static struct soap* ONVIF_Initsoap(struct SOAP_ENV__Header *header, const char *was_To, const char *was_Action,
int timeout)
{
struct soap *soap = NULL;
unsigned char macaddr[6];
char _HwId[1024];
unsigned int Flagrand;
soap = soap_new();
if(soap == NULL)
{
printf("[%d]soap = NULL\n", __LINE__);
return NULL;
}
soap_set_namespaces( soap, namespaces);
//超过5秒钟没有数据就退出
if (timeout > 0)
{
soap->recv_timeout = timeout;
soap->send_timeout = timeout;
soap->connect_timeout = timeout;
}
else
{
//如果外部接口没有设备默认超时时间的话,我这里给了一个默认值10s
soap->recv_timeout = 10;
soap->send_timeout = 10;
soap->connect_timeout = 10;
}
soap_default_SOAP_ENV__Header(soap, header);
// 为了保证每次搜索的时候MessageID都是不相同的!因为简单,直接取了随机值
srand((int)time(0));
Flagrand = rand()%9000 + 1000; //保证四位整数
macaddr[0] = 0x1; macaddr[1] = 0x2; macaddr[2] = 0x3; macaddr[3] = 0x4; macaddr[4] = 0x5; macaddr[5] = 0x6;
sprintf(_HwId,"urn:uuid:%ud68a-1dd2-11b2-a105-%02X%02X%02X%02X%02X%02X",
Flagrand, macaddr[0], macaddr[1], macaddr[2], macaddr[3], macaddr[4], macaddr[5]);
header->wsa__MessageID =(char *)malloc( 100);
memset(header->wsa__MessageID, 0, 100);
strncpy(header->wsa__MessageID, _HwId, strlen(_HwId));
if (was_Action != NULL)
{
header->wsa__Action =(char *)malloc(1024);
memset(header->wsa__Actio