[asterisk-bugs] [Asterisk 0019314]: Last character of XML data gets cut off, in mxml interface

Asterisk Bug Tracker noreply at bugs.digium.com
Wed May 18 04:43:31 CDT 2011


A NOTE has been added to this issue. 
====================================================================== 
https://issues.asterisk.org/view.php?id=19314 
====================================================================== 
Reported By:                jborg
Assigned To:                
====================================================================== 
Project:                    Asterisk
Issue ID:                   19314
Category:                   Core/ManagerInterface
Reproducibility:            always
Severity:                   major
Priority:                   normal
Status:                     new
Asterisk Version:           1.8.3.3 
JIRA:                        
Regression:                 No 
Reviewboard Link:            
SVN Branch (only for SVN checkouts, not tarball releases): N/A 
SVN Revision (number only!):  
Request Review:              
====================================================================== 
Date Submitted:             2011-05-18 04:25 CDT
Last Modified:              2011-05-18 04:43 CDT
====================================================================== 
Summary:                    Last character of XML data gets cut off, in mxml
interface
Description: 
When using the mxml interface of the HTTP manager, a typical response can
look like this:

---

<ajax-response>
<response type='object' id='unknown'><generic response='Error'
message='Permission denied' /></response>
</ajax-response
---

Note that the closing ">" in the last tag is missing. This causes parse
errors on the client side.

The problem is caused by an extra newline before the response, that is not
counted in the content-length. The newline in question exists because two
newlines are added between the HTTP headers and the body, but the the
headers are already newline-terminated. The following patch resolved the
problem:

--- main/http.c.orig 2011-05-18 11:11:02.030771501 +0200
+++ main/http.c      2011-05-18 11:11:32.630788080 +0200
@@ -398,13 +398,13 @@
                "Connection: close\r\n"
                "%s"
                "Content-Length: %d\r\n"
-               "%s\r\n\r\n",
+               "%s\r\n",
                status_code, status_title ? status_title : "OK",
                ast_get_version(),
                timebuf,
                static_content ? "" : "Cache-Control: no-cache,
no-store\r\n",
                content_length,
-               http_header ? ast_str_buffer(http_header) : ""
+               http_header ? ast_str_buffer(http_header) : "\r\n"
                );

        /* send content */

====================================================================== 

---------------------------------------------------------------------- 
 (0135085) jborg (reporter) - 2011-05-18 04:43
 https://issues.asterisk.org/view.php?id=19314#c135085 
---------------------------------------------------------------------- 
... which broke serving static files, since the headers weren't
newline-terminated there. This fixes both issues:


--- main/http.c.orig    2011-05-18 11:11:02.030771501 +0200
+++ main/http.c 2011-05-18 11:40:09.030755410 +0200
@@ -272,7 +272,7 @@

        ast_str_set(&http_header, 0, "Content-type: %s\r\n"
                "ETag: %s\r\n"
-               "Last-Modified: %s",
+               "Last-Modified: %s\r\n",
                mtype,
                etag,
                timebuf);
@@ -398,13 +398,13 @@
                "Connection: close\r\n"
                "%s"
                "Content-Length: %d\r\n"
-               "%s\r\n\r\n",
+               "%s\r\n",
                status_code, status_title ? status_title : "OK",
                ast_get_version(),
                timebuf,
                static_content ? "" : "Cache-Control: no-cache,
no-store\r\n",
                content_length,
-               http_header ? ast_str_buffer(http_header) : ""
+               http_header ? ast_str_buffer(http_header) : "\r\n"
                );

        /* send content */ 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2011-05-18 04:43 jborg          Note Added: 0135085                          
======================================================================




More information about the asterisk-bugs mailing list