标签:for mil 建立 ocs start 链表 ns2 deb microsoft
?soap结构中count(soap->count)成员
soap结构中count(soap->count)成员记录的是http协议中Content-Length的数值。
?keep_alive
keep_alive既是在通讯过程中的正常链接的一个状态标示也是关系到http协议中Connection:keep-alive的填写open还是close。
?如何生成http协议部分
gsoap中生成的*.c文件中在生成xml协议信息时,是通过soap->fposthdr,soap_puthttphdr生成一些http协议部分。
?如何发送http协议
在gsoap通讯过程中,通过soap->fpost(),生成发送协议中的http协议部分。
?函数soap_set_local_namespaces(struct soap *soap)
?soap_connect()函数中把原来的soap->mode进行了修改,这样在下次调用,同时对填入soap->buf的字符进行计数。
?soap_connect()中soap->bufidx统计的是http协议部分的字符数。
?soap_envelope_begin_out()统计envelope部分的计数,同时填写xml中envelope部分
?soap_putheader()统计putheader部分的计数,同时填写xml中putheader部分。
?soap_body_begin_out()统计body部分的计数,同时填写xml中body部分。
?soap_put___tds__(*)(*标示相关功能标识,例如GetNetworkInterfaces)统计__(*)(*标示相关功能标识,例如GetNetworkInterfaces)部分的计数,同时填写xml中__(*)(*标示相关功能标识,例如GetNetworkInterfaces)部分。
?soap_body_end_outconnect()中soap->bufidx统计的是body部分结束标签的字符数同时把结束标签写入xml。
?soap_envelope_end_out()同前。
?soap_end_send()中,soap_end_send()->soap_flush()->soap_flush_raw()->soap->fsend(),在函数soap_end_send()中进行sock发送,在此函数中第一次使用soap结构(接受/发送结束),对soap->budidx,soap->count进行清零。在此之前结构中soap->buflen一次未用到,猜测次成员只在解析时使用。在这些处理过程中,如果(soap->bufidx > SOAP_BUFLEN),那么,由于soap_connect()已经建立了socket通讯,所以只要条件满足就用soap->flush()把buf中的协议包发送给服务器端,不会丢失协议内容,至于服务器端怎样处理,只有读代码了。
?soap_element()
#ifndef PALM_2
SOAP_FMAC1
int
SOAP_FMAC2
soap_element(struct soap *soap, const char *tag, int id, const char *type)
{
#ifndef WITH_LEAN
const char *s;
#endif
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Element begin tag=‘%s‘ level=‘%u‘ id=‘%d‘ type=‘%s‘\n", tag, soap->level, id, type ? type : SOAP_STR_EOS));
#ifdef WITH_DOM
#ifndef WITH_LEAN
if (soap_tagsearch(soap->wsuid, tag))
{ size_t i;
for (s = tag, i = 0; *s && i < sizeof(soap->tag) - 1; s++, i++)
soap->tag[i] = *s == ‘:‘ ? ‘-‘ : *s;
soap->tag[i] = ‘\0‘;
if (soap_set_attr(soap, "wsu:Id", soap->tag, 1))
return soap->error;
}
#endif
#endif
soap->level++;
if (soap->level > soap->maxlevel)
return soap->error = SOAP_LEVEL;
#ifdef WITH_DOM
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL) && !(soap->mode & SOAP_DOM_ASIS))
{ if (soap->evlev >= soap->level)
soap->evlev = 0;
if (soap->event == SOAP_SEC_BEGIN && !soap->evlev)
{ struct soap_nlist *np;
/* non-nested wsu:Id found: clear xmlns, re-emit them for exc-c14n */
for (np = soap->nlist; np; np = np->next)
{ int p = soap_tagsearch(soap->c14ninclude, np->id) != NULL;
if (np->index == 2 || p)
{ struct soap_nlist *np1 = soap_push_ns(soap, np->id, np->ns, 1, 0);
if (np1 && !p)
np1->index = 0;
}
}
soap->evlev = soap->level;
}
}
#endif
if (soap->mode & SOAP_XML_DOM)
{ struct soap_dom_element *elt = (struct soap_dom_element*)soap_malloc(soap, sizeof(struct soap_dom_element));
if (!elt)
return soap->error = SOAP_EOM;
DBGLOG(TEST, SOAP_MESSAGE(fdebug, "Adding DOM element tag=‘%s‘ %p (parent=‘%s‘ %p)\n", tag, elt, soap->dom ? soap->dom->name : "(null)", soap->dom));
elt->soap = soap;
elt->next = NULL;
elt->prnt = soap->dom;
elt->elts = NULL;
elt->atts = NULL;
elt->nstr = NULL;
elt->name = soap_strdup(soap, tag);
elt->lead = NULL;
elt->text = NULL;
elt->code = NULL;
elt->tail = NULL;
elt->node = NULL;
elt->type = 0;
if (soap->dom)
{ struct soap_dom_element *p = soap->dom->elts;
if (p)
{ while (p->next)
p = p->next;
p->next = elt;
}
else
soap->dom->elts = elt;
}
soap->dom = elt;
if (!elt->name)
return soap->error = SOAP_EOM;
}
else
{
#endif
#ifndef WITH_LEAN
if (!soap->ns)
{ if (!(soap->mode & SOAP_XML_CANONICAL) && soap_send(soap, soap->prolog))
return soap->error;
}
else if (soap->mode & SOAP_XML_INDENT)
{ if (soap->ns == 1 && soap_send_raw(soap, soap_indent, soap->level < sizeof(soap_indent) ? soap->level : sizeof(soap_indent) - 1))
return soap->error;
soap->body = 1;
}
if ((soap->mode & SOAP_XML_DEFAULTNS))
{ size_t n = 0;
s = strchr(tag, ‘:‘);
if (s)
n = s++ - tag;
else
s = tag;
if (soap_send_raw(soap, "<", 1)
|| soap_send(soap, s))
return soap->error;
if (n)
{ struct Namespace *ns = soap->local_namespaces;
for (; ns && ns->id; ns++)
{ if (*ns->id && ns->ns && !strncmp(ns->id, tag, n) && !ns->id[n])
{ if (!soap->nlist || *soap->nlist->id || strcmp(soap->nlist->ns, ns->ns))
{ soap_push_ns(soap, SOAP_STR_EOS, ns->out ? ns->out : ns->ns, 0, 0);
if (soap_attribute(soap, "xmlns", ns->out ? ns->out : ns->ns))
return soap->error;
}
break;
}
}
}
else if (!soap->nlist || *soap->nlist->id || *soap->nlist->ns)
{ soap_push_ns(soap, SOAP_STR_EOS, SOAP_STR_EOS, 0, 0);
if (soap_attribute(soap, "xmlns", SOAP_STR_EOS))
return soap->error;
}
}
else
#endif
if (soap_send_raw(soap, "<", 1)
|| soap_send(soap, tag))
return soap->error;
#ifdef WITH_DOM
}
#endif
if (!soap->ns)
{ struct Namespace *ns = soap->local_namespaces;
int k = -1;
if (ns)
{ while (k-- && ns->id)
{ const char *t = ns->out;
if (!t)
t = ns->ns;
if (*ns->id && t && *t)
{ (SOAP_SNPRINTF(soap->tmpbuf, sizeof(soap->tmpbuf), strlen(ns->id) + 6), "xmlns:%s", ns->id);
if (soap_attribute(soap, soap->tmpbuf, t))
return soap->error;
}
ns++;
}
}
}
soap->ns = 1; /* namespace table control: ns = 0 or 2 to start, then 1 to stop dumping the table */
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
{ if ((soap->mode & SOAP_XML_DEFAULTNS))
soap_utilize_ns(soap, SOAP_STR_EOS, 0);
else
soap_utilize_ns(soap, tag, 0);
}
#endif
if (id > 0)
{ (SOAP_SNPRINTF(soap->tmpbuf, sizeof(soap->tmpbuf), sizeof(SOAP_BASEREFNAME) + 20), SOAP_BASEREFNAME "%d", id);
if (soap->version == 2)
{ if (soap_attribute(soap, "SOAP-ENC:id", soap->tmpbuf))
return soap->error;
}
else if (soap_attribute(soap, "id", soap->tmpbuf))
return soap->error;
}
if (type && *type && !(soap->mode & SOAP_XML_NOTYPE))
{ const char *t = type;
#ifndef WITH_LEAN
if ((soap->mode & SOAP_XML_CANONICAL))
soap_utilize_ns(soap, type, 0);
#endif
if (soap_attribute(soap, "xsi:type", t))
return soap->error;
}
if (soap->null && soap->position > 0 && soap->version == 1)
{ int i;
(SOAP_SNPRINTF(soap->tmpbuf, sizeof(soap->tmpbuf) - 1, 20), "[%d", soap->positions[0]);
for (i = 1; i < soap->position; i++)
{ size_t l = strlen(soap->tmpbuf);
(SOAP_SNPRINTF(soap->tmpbuf + l, sizeof(soap->tmpbuf) - l - 1, 20), ",%d", soap->positions[i]);
}
(void)soap_strncat(soap->tmpbuf, sizeof(soap->tmpbuf), "]", 1);
if (soap_attribute(soap, "SOAP-ENC:position", soap->tmpbuf))
return soap->error;
}
if (soap->mustUnderstand)
{ if (soap->actor && *soap->actor)
{ if (soap_attribute(soap, soap->version == 2 ? "SOAP-ENV:role" : "SOAP-ENV:actor", soap->actor))
return soap->error;
}
if (soap_attribute(soap, "SOAP-ENV:mustUnderstand", soap->version == 2 ? "true" : "1"))
return soap->error;
soap->mustUnderstand = 0;
}
if (soap->encoding)
{ if (soap->encodingStyle && soap->local_namespaces && soap->local_namespaces[0].id && soap->local_namespaces[1].id)
{ if (!*soap->encodingStyle)
{ if (soap->local_namespaces[1].out)
soap->encodingStyle = soap->local_namespaces[1].out;
else
soap->encodingStyle = soap->local_namespaces[1].ns;
}
if (soap->encodingStyle && soap_attribute(soap, "SOAP-ENV:encodingStyle", soap->encodingStyle))
return soap->error;
}
else
soap->encodingStyle = NULL;
soap->encoding = 0;
}
soap->null = 0;
soap->position = 0;
return SOAP_OK;
}
#endif
黑体字标示的地方,作用是吧ns2为首地址的各个成员指针指向在*.nsmap中的。
?SOAP_NMAC struct Namespace namespaces[]{...}定义成员
soap_attribute(){}函数是填写/处理xml协议中的"<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope" xmlns:SOAP-ENC="http://www.w3.org/2003/05/soap-encoding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa5="http://www.w3.org/2005/08/addressing" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:xenc="http://www.w3.org/2001/04/xmlenc#" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:xmime="http://tempuri.org/xmime.xsd" xmlns:tt="http://www.onvif.org/ver10/schema" xmlns:tds="http://www.onvif.org/ver10/device/wsdl" xmlns:ter=">"类似xmlns:SOAP-ENV这些信息。
?soap_element_begin_out()
填写/处理一个标签的开始部分,包括它的属性信息,例如:
xmlns:SOAP-ENV="http://www.w3.org/2003/05/soap-envelope
{
.............
soap_element()函数填写/处理一个xml节点标签的从“<”开始到">"之前的所有信息,
..............
soap_element_start_end_out()函数填写/处理同一xml节点标签的">".
.................
}
?soap_putheader()
该函调用soap_out_SOAP_ENV__Header()
soap_out_SOAP_ENV__Header()
{//用于处理(填写)xml中的soapheader部分标签
if (soap_element_begin_out()){//填写/处理header的开始标签
}
if (soap_out__wsa__MessageID()){
//soap_out__wsa__MessageID()==soap_out_string(){
//soap_outstring(){
// id = soap_element_id()//该id值可以是soap->malloc动态分配的空间在soap机构中struct soap_plist *pht[SOAP_PTRHASH];链表中的id值
//
}
//}
}
}
?SOAP_FMAC5 int SOAP_FMAC6 soap_call___tds__(*)(例如GetNetworkInterfaces){
}
该函数用于最顶层的调用函数功能,具体包含实现了设备所具有的所有功能
?soap_default__<*>()
<*>代表相应的功能函数标识, 例如soap_default__tds__GetNetworkInterfacesResponse,该函数仅仅是对恢复结构进行初始化。
?soap_begin_count()
该函数在再次soap结构中一些在该请求中要用到和可能用到的量进行清零/初始化,最主要是的设置xml结构的mode信息默认情况下是soap->mode=0x20008;
?soap_begin_recv()
soap_begin_recv()
{
.......//前面在进行一些在接收/解析过程中的用到的一些数据的初始化/清理
c = soap_getchar(soap);/*第一次进行接收数据,然而即使这次数据量为零,也 没有关 系,因为在后面的soap_envelope_begin_in()等函数中可以再次接收,也就是说第一次接收到数据量为0或者没有接收完完整的协议内容也可以在后面的soap_envelope_begin_in()等这些函数中继续接收,只要soap->socket不释放掉就可以.其中soap->buflen中记录了一次接收到的数据的字符统计数字,同时soap->count统计总的接收到的字符数.soap->bufidx = 0;soap->buflen = ret = soap->frecv()在每次socket接收前对soap->budidx进行清零;每次在soap_getchar(struct soap *soap){.......return soap_get1(soap);}之前对soap->ahead进行清零/处理;整理得知:soap_getchar()->soap_get1()->soap_recv()/return (unsigned char)soap->buf[soap->bufidx++];->soap_recv_raw(soap)->soap->frecv()*/
......//这里是些宏选择代码
while (soap_blank(c))//Ⅰ) Ⅱ) Ⅲ) 这三句代码目的:找到第一次接收到的数据信息中从soap->buf[0]开始的第一个不是0x00-0x20之间asii码之间的字符
c = soap_getchar(soap);
.....//通过一系列的if()判断后从接收到的buf中找打第一个符合协议的要求的字符,这个字符存储在c变量中.然后把这个符合协议要求起始字符存储在soap->ahead中(存储的是ASII码).
soap->error = soap->fparse(soap);//解析出http协议部分.
}
?soap_envelope_begin_in()
soap_envelope_begin_in()
{//对指定的协议标识字符串进行解析, 例如SOAP-ENV:Envelope
if (soap_element_begin_in(soap, "SOAP-ENV:Envelope", 0, NULL)){
//soap_element_begin_in()=>if (!soap_peek_element(soap)){//soap_peek_element主要目的是在xml中找到相应的匹配字符串.例如SOAP-ENV:Envelope,存储在soap->tag中
..............
soap_unget(soap, c);//获取到第一个xml协议的第一个"<"
................
while (soap_blank(c))
c = soap_get(soap););//把xml协议的头部信息过滤掉.即:<?xml .....?>
....................
s = soap->tag;
do c = soap_get1(soap);
while (soap_blank(c));
i = sizeof(soap->tag);
while (c != ‘>‘ && c != ‘/‘ && soap_notblank(c) && (int)c != EOF)
{ if (--i > 0)
*s++ = (char)c;
c = soap_get1(soap);
}
while (soap_blank(c))
c = soap_get1(soap);
*s = ‘\0‘;//这几行把要解析的目标在xml中找到,即:"SOAP-ENV:Envelope"
...........
soap_pop_namespace(soap);//根据soap结构定义,可能和首选什么命名空间有关,在命令中也许和-n/-N有关,不确定.在测试中它返回值为NULL,即soap->nlist=NULL
........//后面紧接着是对命名空间的解析过程,同时对soap->body进行赋值if (!(soap->body = (c != ‘/‘)))
}
}
}
?soap_recv_header()
把xml数据中的相应解析得到数据放置在在soap->header中
?soap_body_begin_in()
与前面的连个函数相似功能.
标签:for mil 建立 ocs start 链表 ns2 deb microsoft
原文地址:http://www.cnblogs.com/big-devil/p/7625766.html