httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William A. Rowe, Jr." <wr...@lnd.com>
Subject RE: util_script headers from strings?
Date Fri, 28 Jul 2000 03:26:14 GMT
> From: dean gaudet [mailto:dgaudet-list-new-httpd@arctic.org]
> Sent: Thursday, July 27, 2000 9:43 PM
> 
> this sort of thing could/should be done with i/o filtering.

Actually, a function is worth a thousand words (written well,
though I do have a few legitimate 4kb funcs :)

Here's what the function replaces...

Index: os/win32/mod_isapi.c
===================================================================
RCS file: /home/cvs/apache-2.0/src/os/win32/mod_isapi.c,v
retrieving revision 1.15
diff -u -r1.15 mod_isapi.c

[snip]
-static char* ComposeHeaders(request_rec *r, char* data)
-{
-    /* We *should* break before this while loop ends */
-    while (*data) 
-    {
-        char *value, *lf = strchr(data, '\n');
-        int p;
-
-#ifdef RELAX_HEADER_RULE
-        if (lf)
-            *lf = '\0';
-#else
-        if (!lf) { /* Huh? Invalid data, I think */
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, r,
-                          "ISAPI %s sent invalid headers", r->filename);
-            SetLastError(TODO_ERROR);
-            return FALSE;
-        }
-
-        /* Get rid of \n and \r */
-        *lf = '\0';
-#endif
-        p = strlen(data);
-        if (p > 0 && data[p-1] == '\r') data[p-1] = '\0';
-
-        /* End of headers */
-        if (*data == '\0') {
-#ifdef RELAX_HEADER_RULE
-            if (lf)
-#endif
-                data = lf + 1;  /* Reset data */
-            break;
-        }
-
-        if (!(value = strchr(data, ':'))) {
-            SetLastError(TODO_ERROR);
-            /* ### euh... we're passing the wrong type of error
-               ### code here */
-            ap_log_rerror(APLOG_MARK, APLOG_ERR, HTTP_INTERNAL_SERVER_ERROR, r,
-                          "ISAPI %s sent invalid headers", r->filename);
-            return FALSE;
-        }
-
-        *value++ = '\0';
-        while (*value && ap_isspace(*value)) ++value;
-
-        /* Check all the special-case headers. Similar to what
-         * ap_scan_script_header_err() does (see that function for
-         * more detail)
-         */
-
-        if (!strcasecmp(data, "Content-Type")) 
-        {
-            /* Nuke trailing whitespace */    
-            char *tmp;
-            char *endp = value + strlen(value) - 1;
-            while (endp > value && ap_isspace(*endp)) 
-                *endp-- = '\0';
-
-            tmp = ap_pstrdup (r->pool, value);
-            ap_str_tolower(tmp);
-            r->content_type = tmp;
-        }
-        else if (!strcasecmp(data, "Content-Length")) {
-            ap_table_set(r->headers_out, data, value);
-        }
-        else if (!strcasecmp(data, "Transfer-Encoding")) {
-            ap_table_set(r->headers_out, data, value);
-        }
-        else if (!strcasecmp(data, "Set-Cookie")) {
-            ap_table_add(r->err_headers_out, data, value);
-        }
-        else {
-            ap_table_merge(r->err_headers_out, data, value);
-        }
-
-        /* Reset data */
-#ifdef RELAX_HEADER_RULE
-        if (!lf) {
-            data += p;
-            break;
-        }
-#endif
-        data = lf + 1;
-    }
-    return data;
-}
@@ -619,39 +301,10 @@
             return TRUE;
 
         case HSE_REQ_SEND_RESPONSE_HEADER:
-            r->status_line = lpvBuffer ? lpvBuffer : ap_pstrdup(r->pool, "200 OK");
-            sscanf(r->status_line, "%d", &r->status);
-            cid->ecb->dwHttpStatusCode = r->status;
-
-            /* Now fill in the HTTP headers, and the rest of it. Ick.
-             * lpdwDataType contains a string that has headers (in MIME
-             * format), a blank like, then (possibly) data. We need
-             * to parse it.
-             *
-             * Easy case first:
-             */
-            if (!lpdwDataType) {
-                ap_send_http_header(r);
-                return TRUE;
-            }
-                        
-            /* Make a copy - don't disturb the original */
-            data = ap_pstrdup(r->pool, (char *)lpdwDataType);
-            
             /* Parse them out, or die trying */
-            data = ComposeHeaders(r, data);
-            if (!data)
-                return FALSE;
-
-            /* All the headers should be set now */
-            ap_send_http_header(r);
-
-            /* Any data left should now be sent directly */
-            if (*data)
-                ap_rputs(data, r);
-
-            return TRUE;
-
+            return SendResponseHeaderEx(cid, (char*) lpvBuffer, 
+                                        (char*) lpdwDataType, -1, -1);
+            
@@ -783,75 +434,309 @@
             return FALSE;
 
         case HSE_REQ_SEND_RESPONSE_HEADER_EX:  /* Added in ISAPI 4.0 */
+        {
+            LPHSE_SEND_HEADER_EX_INFO shi 
+                                      = (LPHSE_SEND_HEADER_EX_INFO) lpvBuffer;
+            return SendResponseHeaderEx(cid, shi->pszStatus, shi->pszHeader,
+                                             shi->cchStatus, shi->cchHeader);
+            /* Ignored shi->fKeepConn, we shouldn't need the advise */
+        }
+


> > On Thu, 27 Jul 2000, William A. Rowe, Jr. wrote:
> > 
> > > Does anyone have a conceptual problem with my adding this code
> > > to the util_script.c source?  Resolves an issue that ISAPI
> > > (and perhaps others) pass strings to the webserver, rather than
> > > a buff or file, for header parsing.
> > > 
> > > Is there code in Apache that would simplify this implementation?
> > > 
> > > Index: include/util_script.h
> > > 
> ===================================================================
> > > RCS file: /home/cvs/apache-2.0/src/include/util_script.h,v
> > > retrieving revision 1.8
> > > diff -u -r1.8 util_script.h
> > > --- include/util_script.h	2000/04/14 15:58:17	1.8
> > > +++ include/util_script.h	2000/07/27 17:20:12
> > > @@ -81,6 +81,10 @@
> > >  API_EXPORT(int) ap_scan_script_header_err_core(request_rec 
> > *r, char *buffer,
> > >  				       int (*getsfunc) (char *, 
> > int, void *),
> > >  				       void *getsfunc_data);
> > > +API_EXPORT_NONSTD(int) 
> > ap_scan_script_header_err_strs(request_rec *r, 
> > > +                                                      char 
> > *buffer, 
> > > +                                                      
> > const char **data,
> > > +                                                      ...);
> > >  API_EXPORT(void) ap_send_size(ap_ssize_t size, request_rec *r);
> > >  
> > >  #ifdef __cplusplus
> 

Mime
View raw message