發送消息的主要內容:
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;