Gsoap bug note

Source: Internet
Author: User

The bug of using the _ write Method for socket communication check before sending socket data

Version: gsoap_2.7.13

Operate System: WindowsXP

Describe:

I want to send the HTTP request mulitie times by the same socket. And I coded as follow:

For (size_t retrytimes = 0; retrytimes <3; retrytimes ++)
{
// Whenever connected; send the HTTP request;
If (
Soap_end_send (DOM. Soap)
)
{
// If failed, try to create the socket session;
Soap_connect (DOM. Soap, URL, null );
}
// Once send success, break the loop;
Else
That is {
Break;
}
}

 

The problam is: wheath the CONNECT is estabilsh or not, soap_end_send () always success.

I find that is because some code valide the socket connnect as follow:

In soapstd2.cpp: fsend,

# Ifdef Win32
Nwritten = _ write (soap-> sendfd, S, (unsigned INT) N );
# Else
Nwritten = write (soap-> sendfd, S, (unsigned INT) N );
# Endif

The write is just a normaly is function and it can't sure weather the fild handle is a socket handle. So, if I just open a normal file, it is just return success.

I think send () is more appropriate.

 

 

2 \ Fault Tolerance:

 

Such Tag:

 

<Div> <ul> <span> hello! </Span>
</Div>

Soap_element_end_in (struct soap * soap, const char * tag)

If (TAG & (soap-> mode & soap_xml_strict ))
{Soap_pop_namespace (SOAP );
If (soap_match_tag (soap, soap-> tag, tag ))
{Dbglog (test, soap_message (fdebug, "End Element tag name does not match \ n "));
//// If the end string does not match, manually add the end string to match it.
Soap-> bufidx-= strlen (soap-> tag );
Soap-> bufidx = offset;
Soap-> ahead = soap_tt;
Strncpy (soap-> tag, Tag, strlen (TAG ));

 

 

If the first character in a tag is a Chinese character, garbled characters may occur.

The following is a UTF-8 encoded string:

Soap_get

<Ul>
<Li> company: xianyuan property Jialin store </LI>
<Li> address: No. 134, Jialin Road, Pudong New Area, Shanghai </LI>
</Ul>

 

The parsed result is

<Ul>
<Li> L Division: Lixin Housing </LI>
<Li> 0 address: No.-1041, Changde road </LI>
</Ul>

"Public" and "land" are garbled. This is an algorithm defect in gosp parsing XML.

In the soap_wchar soap_get (struct soap * soap) function, the algorithm for reading a single character is:

If gsoap> ahead contains a character, this character is returned. Otherwise, take a character from gsoap> Buf, gsoap> bufidx ++.

The value of gsoap-> ahead comes from soap_peek_element (), and its logic is:

When the tag <li> is obtained, a UTF-8 character is read. If it is not <, it is determined to be the data (rather than the child node) of the label <li> ). In this case, we need to return the read UTF-8.

Here we do not return gsoap-> bufidx --, but store this value in gosp-> ahead. Here, gsoap-> ahead stores the Unicode encoding of characters.

 

If (C! = Soap_lt)
{* Soap-> tag = '\ 0 ';
If (INT) C = EOF)
Return soap-> error = soap_eof;
Soap_unget (soap, C );

3. Abstraction Level

The gosp Dom has two basic objects: node and attribute. Each object has two attributes: Name and value. Simple rules. Easy to use. However, if the following HTML content exists:

<Div>
The sea is the hometown of <span> You </span>
<Div>

 

Gosp considers the sea as a value attribute in the hometown of <span> You </span>. Instead of parsing <span> as a node.

 

Xmlspy provides a higher level of abstraction than gsoap. In XML, node is an abstract DOM tree, and value represents the real value. The value may be a tag, a value, or a xmpspy. The preceding HTML statement is parsed

 

<Div>
The sea is
<Span>
You
</Span>
Hometown
<Div>

That is, a div node has three subnodes.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.