gsoap框架下的onvif程序流程分析
SOAP_FMAC5 int SOAP_FMAC6 soap_serve(struct soap *soap) { do { unsigned int k = soap->max_keep_alive; if (soap->max_keep_alive > 0 && !--k) soap->keep_alive = 0; if (soap_begin_serve(soap)) { if (soap->error >= SOAP_STOP) continue; return soap->error; } /*soap_begin_serve()函数在buf中解析到<body>位置,soap_server_request继续解析下一个元素,这个元素就是一种request。 soap_serve_request()函数就是我们开放新功能的地方*/ if (soap_serve_request(soap) || (soap->fserveloop && soap->fserveloop(soap))) { return soap_send_fault(soap); } } while (soap->keep_alive); return SOAP_OK; } soap_begin_serve(struct soap *soap) { soap_begin(soap); if (soap_begin_recv(soap) //阻塞在这里 收到消息后 调用http_parse解析http头部 || soap_envelope_begin_in(soap) /*从buf中找寻envelope开始标签(begin),in代表是从buf中解析结构 out代表把结构填充到buf中去。可以在这里做分流, 有<envelope>认为是onvif部分继续交gsoap处理,没有的交http服务器处理。*/ || soap_recv_header(soap) //从buf中分离出header域。 || soap_body_begin_in(soap)) //找寻body的开始标签 { if (soap->error < SOAP_STOP) { if(soap->error!=SOAP_GET_METHOD && soap->error!=405) { return soap_send_fault(soap); //此句是原句 } else { return soap->error; } } return soap_closesock(soap); } return SOAP_OK; }