[mapserver-commits] r11163 - in trunk/mapserver: . mapscript/swiginc

svn at osgeo.org svn at osgeo.org
Tue Mar 15 16:54:31 EDT 2011


Author: schpidi
Date: 2011-03-15 13:54:31 -0700 (Tue, 15 Mar 2011)
New Revision: 11163

Modified:
   trunk/mapserver/mapio.c
   trunk/mapserver/mapio.h
   trunk/mapserver/mapscript/swiginc/msio.i
Log:
Adding msIO_stripStdoutBufferContentHeaders() to strip off all Content-* headers from a buffer. Needed in WCS where multiple Content-* headers are included (see #3673 and #3665) but msIO_stripStdoutBufferContentType() only strips off the Content-Type header.


Modified: trunk/mapserver/mapio.c
===================================================================
--- trunk/mapserver/mapio.c	2011-03-15 20:45:20 UTC (rev 11162)
+++ trunk/mapserver/mapio.c	2011-03-15 20:54:31 UTC (rev 11163)
@@ -934,6 +934,90 @@
 }
 
 /************************************************************************/
+/*                 msIO_stripStdoutBufferContentHeaders()               */
+/*                                                                      */
+/*      Strip off Content-* headers from buffer.                        */
+/************************************************************************/
+
+void msIO_stripStdoutBufferContentHeaders()
+{
+/* -------------------------------------------------------------------- */
+/*      Find stdout buffer.                                             */
+/* -------------------------------------------------------------------- */
+    msIOContext *ctx = msIO_getHandler( (FILE *) "stdout" );
+    msIOBuffer  *buf;
+    int start_of_data;
+
+    if( ctx == NULL || ctx->write_channel == MS_FALSE
+        || strcmp(ctx->label,"buffer") != 0 )
+    {
+    msSetError( MS_MISCERR, "Can't identify msIO buffer.",
+                    "msIO_stripStdoutBufferContentHeaders" );
+    return;
+    }
+
+    buf = (msIOBuffer *) ctx->cbData;
+
+/* -------------------------------------------------------------------- */
+/*      Exit if we don't have any content-* header.                     */
+/* -------------------------------------------------------------------- */
+    if( buf->data_offset < 8 
+        || strncasecmp((const char*) buf->data,"Content-",8) != 0 )
+        return;
+
+/* -------------------------------------------------------------------- */
+/*      Loop over all content-* headers.                                */
+/* -------------------------------------------------------------------- */
+    start_of_data = 0;
+    while( buf->data_offset > start_of_data
+        && strncasecmp((const char*) buf->data+start_of_data,"Content-",8) == 0 )
+    {
+/* -------------------------------------------------------------------- */
+/*      Find newline marker at end of content-* header argument.        */
+/* -------------------------------------------------------------------- */
+        start_of_data +=7;
+        while( start_of_data+1 < buf->data_offset 
+               && buf->data[start_of_data+1] != 10 )
+            start_of_data++;
+
+        if( start_of_data+1 == buf->data_offset )
+        {
+        msSetError( MS_MISCERR, "Corrupt Content-* header.",
+                        "msIO_stripStdoutBufferContentHeaders" );
+        return;
+        }
+        start_of_data +=2;
+    }
+
+/* -------------------------------------------------------------------- */
+/*      Continue on to the start of data ... skipping two newline       */
+/*      markers.                                                        */
+/* -------------------------------------------------------------------- */
+    while( start_of_data  < buf->data_offset 
+           && buf->data[start_of_data] != 10 )
+        start_of_data++;
+
+    if( start_of_data == buf->data_offset )
+    {
+    msSetError( MS_MISCERR, "Corrupt Content-* header.",
+                    "msIO_stripStdoutBufferContentHeaders" );
+    return;
+    }
+
+    start_of_data++;
+
+/* -------------------------------------------------------------------- */
+/*      Move data to front of buffer, and reset length.                 */
+/* -------------------------------------------------------------------- */
+    memmove( buf->data, buf->data+start_of_data,
+             buf->data_offset - start_of_data );
+    buf->data[buf->data_offset - start_of_data] = '\0';
+    buf->data_offset -= start_of_data;
+
+    return;
+}
+
+/************************************************************************/
 /*                          msIO_bufferWrite()                          */
 /************************************************************************/
 

Modified: trunk/mapserver/mapio.h
===================================================================
--- trunk/mapserver/mapio.h	2011-03-15 20:45:20 UTC (rev 11162)
+++ trunk/mapserver/mapio.h	2011-03-15 20:54:31 UTC (rev 11163)
@@ -115,6 +115,7 @@
 void MS_DLL_EXPORT msIO_installStdinFromBuffer(void);
 void MS_DLL_EXPORT msIO_Cleanup(void);
 char MS_DLL_EXPORT *msIO_stripStdoutBufferContentType(void);
+void MS_DLL_EXPORT msIO_stripStdoutBufferContentHeaders(void);
 
 /* this is just for setting normal stdout's to binary mode on windows */
 

Modified: trunk/mapserver/mapscript/swiginc/msio.i
===================================================================
--- trunk/mapserver/mapscript/swiginc/msio.i	2011-03-15 20:45:20 UTC (rev 11162)
+++ trunk/mapserver/mapscript/swiginc/msio.i	2011-03-15 20:54:31 UTC (rev 11163)
@@ -37,6 +37,7 @@
 void msIO_installStdoutToBuffer(void);
 void msIO_installStdinFromBuffer(void);
 const char *msIO_stripStdoutBufferContentType(void);
+void msIO_stripStdoutBufferContentHeaders(void);
 
 /* mapscript only extensions */
 



More information about the mapserver-commits mailing list