发送消息的主要内容:
1、初始化请求
2、填充要发送的数据
3、发送并接受返回的数据
4、解析数据
5、清理缓存
正文
1、初始化onvif请求
定义一个onvif请求req
定义一个onvif标签tag
临时资源*tmpValue
临时结果tmpresult
主机ip acHostIp[16]
ip地址 acLocalAddress[128]
临时标记tmp_mask[20]
//初始化reqInitOnvifReq(req);
int InitOnvifReq(onvif_req *req)
{//onvif_req req;int sendlen;int tmplen; memset(req,0,sizeof(onvif_req));xml_init_onvif(req);req->buf = NULL;//发送的数据req->buflen = 0;req->currlen = 0;req->query_str = NULL;//填入接收到数据req->specia_fault_code = NULL;req->fault_detail = NULL;req->fault_head = NULL;req->error_string[0] = 0;return 0;
}
2、填充需要发送的数据
//接收缓存
char *pRecvBuf=new char [BUF_SIZE];
if (xml_init_out_buf(req,ONVIF_BUF_SIZE_10K) < 0){tmpresult=-1;goto End;}
3、发送并接收返回的数据
ret=SendAndGetData(req,tag,pInfo->acRemoteaddr,pInfo->acRemoteIp,pRecvBuf, pInfo->port);if(ret!=0){printf("COnvifClientCmd::c_OnvifSendRenew()>>>>>>SendAndGetData() error:%s:%d\r\n",__FILE__,__LINE__);tmpresult=-1;goto End;}
4、解析收到的数据
#if 1OnvifDebug("COnvifClientCmd::c_OnvifSendRenew()>>>>>>start parse c_OnvifSendRenew data\r\n");tag_t_onvif *tag1, *tag2, *tag3;struct tm * timeinfo;tag1=xml_parse_get_child_tag(tag,TAG_WSNT_RenewResponse,TAG_WSNT_TerminationTime);tmpValue=xml_parse_get_Value(tag1);if(tmpValue){ //timeinfo = localtime ( tmpValue);//printf ( "The renew date/time is: %s", asctime (timeinfo) );OnvifDebug ( "COnvifClientCmd::c_OnvifSendRenew()>>>>>>The renew date/time is: %s\r\n", tmpValue );}tag1=xml_parse_get_child_tag(tag,TAG_WSNT_RenewResponse,TAG_WSNT_CurrentTime);tmpValue=xml_parse_get_Value(tag1);if(tmpValue){ //timeinfo = localtime (tmpValue);//printf ( "The current date/time is: %s", asctime (timeinfo) );OnvifDebug ( "COnvifClientCmd::c_OnvifSendRenew()>>>>>>The current date/time is: %s\r\n", tmpValue );}OnvifDebug("COnvifClientCmd::c_OnvifSendRenew()>>>>>>end parse c_OnvifSendRenew data\r\n");
#endif
End:
5、释放内存
if(pRecvBuf){delete []pRecvBuf;pRecvBuf=NULL;}ReleaseData(req,tag);OnvifDebug("COnvifClientCmd::c_OnvifSendRenew()>>>>>>out\r\n");return tmpresult;