]> granicus.if.org Git - apache/blob - server/util_script.c
0f3733bea4e06a7054b4f6c1785ac124f866367c
[apache] / server / util_script.c
1 /* ====================================================================
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2000-2001 The Apache Software Foundation.  All rights
5  * reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  *
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in
16  *    the documentation and/or other materials provided with the
17  *    distribution.
18  *
19  * 3. The end-user documentation included with the redistribution,
20  *    if any, must include the following acknowledgment:
21  *       "This product includes software developed by the
22  *        Apache Software Foundation (http://www.apache.org/)."
23  *    Alternately, this acknowledgment may appear in the software itself,
24  *    if and wherever such third-party acknowledgments normally appear.
25  *
26  * 4. The names "Apache" and "Apache Software Foundation" must
27  *    not be used to endorse or promote products derived from this
28  *    software without prior written permission. For written
29  *    permission, please contact apache@apache.org.
30  *
31  * 5. Products derived from this software may not be called "Apache",
32  *    nor may "Apache" appear in their name, without prior written
33  *    permission of the Apache Software Foundation.
34  *
35  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
37  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
42  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
43  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
45  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
46  * SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Apache Software Foundation.  For more
51  * information on the Apache Software Foundation, please see
52  * <http://www.apache.org/>.
53  *
54  * Portions of this software are based upon public domain software
55  * originally written at the National Center for Supercomputing Applications,
56  * University of Illinois, Urbana-Champaign.
57  */
58
59 #include "apr.h"
60 #include "apr_lib.h"
61 #include "apr_strings.h"
62
63 #define APR_WANT_STRFUNC
64 #include "apr_want.h"
65
66 #if APR_HAVE_STDLIB_H
67 #include <stdlib.h>
68 #endif
69
70 #define CORE_PRIVATE
71 #include "ap_config.h"
72 #include "httpd.h"
73 #include "http_config.h"
74 #include "http_main.h"
75 #include "http_log.h"
76 #include "http_core.h"
77 #include "http_protocol.h"
78 #include "http_request.h"       /* for sub_req_lookup_uri() */
79 #include "util_script.h"
80 #include "apr_date.h"           /* For apr_date_parse_http() */
81 #include "util_ebcdic.h"
82
83 #ifdef OS2
84 #define INCL_DOS
85 #include <os2.h>
86 #endif
87
88 /*
89  * Various utility functions which are common to a whole lot of
90  * script-type extensions mechanisms, and might as well be gathered
91  * in one place (if only to avoid creating inter-module dependancies
92  * where there don't have to be).
93  */
94
95 #define MALFORMED_MESSAGE "malformed header from script. Bad header="
96 #define MALFORMED_HEADER_LENGTH_TO_SHOW 30
97
98 static char *http2env(apr_pool_t *a, const char *w)
99 {
100     char *res = (char *)apr_palloc(a, sizeof("HTTP_") + strlen(w));
101     char *cp = res;
102     char c;
103
104     *cp++ = 'H';
105     *cp++ = 'T';
106     *cp++ = 'T';
107     *cp++ = 'P';
108     *cp++ = '_';
109
110     while ((c = *w++) != 0) {
111         if (!apr_isalnum(c)) {
112             *cp++ = '_';
113         }
114         else {
115             *cp++ = apr_toupper(c);
116         }
117     }
118     *cp = 0;
119  
120     return res;
121 }
122
123 AP_DECLARE(char **) ap_create_environment(apr_pool_t *p, apr_table_t *t)
124 {
125     apr_array_header_t *env_arr = apr_table_elts(t);
126     apr_table_entry_t *elts = (apr_table_entry_t *) env_arr->elts;
127     char **env = (char **) apr_palloc(p, (env_arr->nelts + 2) * sizeof(char *));
128     int i, j;
129     char *tz;
130     char *whack;
131
132     j = 0;
133     if (!apr_table_get(t, "TZ")) {
134         tz = getenv("TZ");
135         if (tz != NULL) {
136             env[j++] = apr_pstrcat(p, "TZ=", tz, NULL);
137         }
138     }
139     for (i = 0; i < env_arr->nelts; ++i) {
140         if (!elts[i].key) {
141             continue;
142         }
143         env[j] = apr_pstrcat(p, elts[i].key, "=", elts[i].val, NULL);
144         whack = env[j];
145         if (apr_isdigit(*whack)) {
146             *whack++ = '_';
147         }
148         while (*whack != '=') {
149             if (!apr_isalnum(*whack) && *whack != '_') {
150                 *whack = '_';
151             }
152             ++whack;
153         }
154         ++j;
155     }
156
157     env[j] = NULL;
158     return env;
159 }
160
161 AP_DECLARE(void) ap_add_common_vars(request_rec *r)
162 {
163     apr_table_t *e;
164     server_rec *s = r->server;
165     conn_rec *c = r->connection;
166     const char *rem_logname;
167     char *env_path;
168 #if defined(WIN32) || defined(OS2) || defined(BEOS)
169     char *env_temp;
170 #endif
171     const char *host;
172     apr_array_header_t *hdrs_arr = apr_table_elts(r->headers_in);
173     apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts;
174     int i;
175     apr_port_t rport;
176     apr_sockaddr_t *remotesa;
177
178     /* use a temporary apr_table_t which we'll overlap onto
179      * r->subprocess_env later
180      */
181     e = apr_table_make(r->pool, 25 + hdrs_arr->nelts);
182
183     /* First, add environment vars from headers... this is as per
184      * CGI specs, though other sorts of scripting interfaces see
185      * the same vars...
186      */
187
188     for (i = 0; i < hdrs_arr->nelts; ++i) {
189         if (!hdrs[i].key) {
190             continue;
191         }
192
193         /* A few headers are special cased --- Authorization to prevent
194          * rogue scripts from capturing passwords; content-type and -length
195          * for no particular reason.
196          */
197
198         if (!strcasecmp(hdrs[i].key, "Content-type")) {
199             apr_table_addn(e, "CONTENT_TYPE", hdrs[i].val);
200         }
201         else if (!strcasecmp(hdrs[i].key, "Content-length")) {
202             apr_table_addn(e, "CONTENT_LENGTH", hdrs[i].val);
203         }
204         /*
205          * You really don't want to disable this check, since it leaves you
206          * wide open to CGIs stealing passwords and people viewing them
207          * in the environment with "ps -e".  But, if you must...
208          */
209 #ifndef SECURITY_HOLE_PASS_AUTHORIZATION
210         else if (!strcasecmp(hdrs[i].key, "Authorization") 
211                  || !strcasecmp(hdrs[i].key, "Proxy-Authorization")) {
212             continue;
213         }
214 #endif
215         else {
216             apr_table_addn(e, http2env(r->pool, hdrs[i].key), hdrs[i].val);
217         }
218     }
219
220     if (!(env_path = getenv("PATH"))) {
221         env_path = DEFAULT_PATH;
222     }
223     apr_table_addn(e, "PATH", apr_pstrdup(r->pool, env_path));
224
225 #ifdef WIN32
226     if (env_temp = getenv("SystemRoot")) {
227         apr_table_addn(e, "SystemRoot", env_temp);         
228     }
229     if (env_temp = getenv("COMSPEC")) {
230         apr_table_addn(e, "COMSPEC", env_temp);            
231     }
232     if (env_temp = getenv("PATHEXT")) {
233         apr_table_addn(e, "PATHEXT", env_temp);            
234     }
235     if (env_temp = getenv("WINDIR")) {
236         apr_table_addn(e, "WINDIR", env_temp);
237     }
238 #endif
239
240 #ifdef OS2
241     if ((env_temp = getenv("COMSPEC")) != NULL) {
242         apr_table_addn(e, "COMSPEC", env_temp);            
243     }
244     if ((env_temp = getenv("ETC")) != NULL) {
245         apr_table_addn(e, "ETC", env_temp);            
246     }
247     if ((env_temp = getenv("DPATH")) != NULL) {
248         apr_table_addn(e, "DPATH", env_temp);            
249     }
250     if ((env_temp = getenv("PERLLIB_PREFIX")) != NULL) {
251         apr_table_addn(e, "PERLLIB_PREFIX", env_temp);            
252     }
253 #endif
254
255 #ifdef BEOS
256     if ((env_temp = getenv("LIBRARY_PATH")) != NULL) {
257         apr_table_addn(e, "LIBRARY_PATH", env_temp);            
258     }
259 #endif
260
261     apr_table_addn(e, "SERVER_SIGNATURE", ap_psignature("", r));
262     apr_table_addn(e, "SERVER_SOFTWARE", ap_get_server_version());
263     apr_table_addn(e, "SERVER_NAME", ap_get_server_name(r));
264     apr_table_addn(e, "SERVER_ADDR", r->connection->local_ip);  /* Apache */
265     apr_table_addn(e, "SERVER_PORT",
266                   apr_psprintf(r->pool, "%u", ap_get_server_port(r)));
267     host = ap_get_remote_host(c, r->per_dir_config, REMOTE_HOST, NULL);
268     if (host) {
269         apr_table_addn(e, "REMOTE_HOST", host);
270     }
271     apr_table_addn(e, "REMOTE_ADDR", c->remote_ip);
272     apr_table_addn(e, "DOCUMENT_ROOT", ap_document_root(r));    /* Apache */
273     apr_table_addn(e, "SERVER_ADMIN", s->server_admin); /* Apache */
274     apr_table_addn(e, "SCRIPT_FILENAME", r->filename);  /* Apache */
275
276     apr_socket_addr_get(&remotesa, APR_REMOTE, c->client_socket);
277     apr_sockaddr_port_get(&rport, remotesa);
278     apr_table_addn(e, "REMOTE_PORT", apr_psprintf(r->pool, "%d", rport));
279
280     if (r->user) {
281         apr_table_addn(e, "REMOTE_USER", r->user);
282     }
283     if (r->ap_auth_type) {
284         apr_table_addn(e, "AUTH_TYPE", r->ap_auth_type);
285     }
286     rem_logname = ap_get_remote_logname(r);
287     if (rem_logname) {
288         apr_table_addn(e, "REMOTE_IDENT", apr_pstrdup(r->pool, rem_logname));
289     }
290
291     /* Apache custom error responses. If we have redirected set two new vars */
292
293     if (r->prev) {
294         if (r->prev->args) {
295             apr_table_addn(e, "REDIRECT_QUERY_STRING", r->prev->args);
296         }
297         if (r->prev->uri) {
298             apr_table_addn(e, "REDIRECT_URL", r->prev->uri);
299         }
300     }
301
302     apr_table_overlap(r->subprocess_env, e, APR_OVERLAP_TABLES_SET);
303 }
304
305 /* This "cute" little function comes about because the path info on
306  * filenames and URLs aren't always the same. So we take the two,
307  * and find as much of the two that match as possible.
308  */
309
310 AP_DECLARE(int) ap_find_path_info(const char *uri, const char *path_info)
311 {
312     int lu = strlen(uri);
313     int lp = strlen(path_info);
314
315     while (lu-- && lp-- && uri[lu] == path_info[lp]);
316
317     if (lu == -1) {
318         lu = 0;
319     }
320
321     while (uri[lu] != '\0' && uri[lu] != '/') {
322         lu++;
323     }
324     return lu;
325 }
326
327 /* Obtain the Request-URI from the original request-line, returning
328  * a new string from the request pool containing the URI or "".
329  */
330 static char *original_uri(request_rec *r)
331 {
332     char *first, *last;
333
334     if (r->the_request == NULL) {
335         return (char *) apr_pcalloc(r->pool, 1);
336     }
337
338     first = r->the_request;     /* use the request-line */
339
340     while (*first && !apr_isspace(*first)) {
341         ++first;                /* skip over the method */
342     }
343     while (apr_isspace(*first)) {
344         ++first;                /*   and the space(s)   */
345     }
346
347     last = first;
348     while (*last && !apr_isspace(*last)) {
349         ++last;                 /* end at next whitespace */
350     }
351
352     return apr_pstrndup(r->pool, first, last - first);
353 }
354
355 AP_DECLARE(void) ap_add_cgi_vars(request_rec *r)
356 {
357     apr_table_t *e = r->subprocess_env;
358
359     apr_table_setn(e, "GATEWAY_INTERFACE", "CGI/1.1");
360     apr_table_setn(e, "SERVER_PROTOCOL", r->protocol);
361     apr_table_setn(e, "REQUEST_METHOD", r->method);
362     apr_table_setn(e, "QUERY_STRING", r->args ? r->args : "");
363     apr_table_setn(e, "REQUEST_URI", original_uri(r)); 
364
365     /* Note that the code below special-cases scripts run from includes,
366      * because it "knows" that the sub_request has been hacked to have the
367      * args and path_info of the original request, and not any that may have
368      * come with the script URI in the include command.  Ugh.
369      */
370
371     if (!strcmp(r->protocol, "INCLUDED")) {
372         apr_table_setn(e, "SCRIPT_NAME", r->uri);
373         if (r->path_info && *r->path_info) {
374             apr_table_setn(e, "PATH_INFO", r->path_info);
375         }
376     }
377     else if (!r->path_info || !*r->path_info) {
378         apr_table_setn(e, "SCRIPT_NAME", r->uri);
379     }
380     else {
381         int path_info_start = ap_find_path_info(r->uri, r->path_info);
382
383         apr_table_setn(e, "SCRIPT_NAME",
384                       apr_pstrndup(r->pool, r->uri, path_info_start));
385
386         apr_table_setn(e, "PATH_INFO", r->path_info);
387     }
388
389     if (r->path_info && r->path_info[0]) {
390         /*
391          * To get PATH_TRANSLATED, treat PATH_INFO as a URI path.
392          * Need to re-escape it for this, since the entire URI was
393          * un-escaped before we determined where the PATH_INFO began.
394          */
395         request_rec *pa_req;
396
397         pa_req = ap_sub_req_lookup_uri(ap_escape_uri(r->pool, r->path_info), r,
398                                        NULL);
399
400         if (pa_req->filename) {
401             char *pt = apr_pstrcat(r->pool, pa_req->filename, pa_req->path_info,
402                                   NULL);
403 #ifdef WIN32
404             /* We need to make this a real Windows path name */
405             apr_filepath_merge(&pt, "", pt, APR_FILEPATH_NATIVE, r->pool);
406 #endif
407             apr_table_setn(e, "PATH_TRANSLATED", pt);
408         }
409         ap_destroy_sub_req(pa_req);
410     }
411 }
412
413
414 static int set_cookie_doo_doo(void *v, const char *key, const char *val)
415 {
416     apr_table_addn(v, key, val);
417     return 1;
418 }
419
420 AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer,
421                                        int (*getsfunc) (char *, int, void *),
422                                        void *getsfunc_data)
423 {
424     char x[MAX_STRING_LEN];
425     char *w, *l;
426     int p;
427     int cgi_status = HTTP_OK;
428     apr_table_t *merge;
429     apr_table_t *cookie_table;
430
431     if (buffer) {
432         *buffer = '\0';
433     }
434     w = buffer ? buffer : x;
435
436     /* temporary place to hold headers to merge in later */
437     merge = apr_table_make(r->pool, 10);
438
439     /* The HTTP specification says that it is legal to merge duplicate
440      * headers into one.  Some browsers that support Cookies don't like
441      * merged headers and prefer that each Set-Cookie header is sent
442      * separately.  Lets humour those browsers by not merging.
443      * Oh what a pain it is.
444      */
445     cookie_table = apr_table_make(r->pool, 2);
446     apr_table_do(set_cookie_doo_doo, cookie_table, r->err_headers_out, "Set-Cookie", NULL);
447
448     while (1) {
449
450         if ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data) == 0) {
451             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
452                           "Premature end of script headers: %s", r->filename);
453             return HTTP_INTERNAL_SERVER_ERROR;
454         }
455
456         /* Delete terminal (CR?)LF */
457
458         p = strlen(w);
459              /* Indeed, the host's '\n':
460                 '\012' for UNIX; '\015' for MacOS; '\025' for OS/390
461                  -- whatever the script generates.
462              */                                  
463         if (p > 0 && w[p - 1] == '\n') {
464             if (p > 1 && w[p - 2] == CR) {
465                 w[p - 2] = '\0';
466             }
467             else {
468                 w[p - 1] = '\0';
469             }
470         }
471
472         /*
473          * If we've finished reading the headers, check to make sure any
474          * HTTP/1.1 conditions are met.  If so, we're done; normal processing
475          * will handle the script's output.  If not, just return the error.
476          * The appropriate thing to do would be to send the script process a
477          * SIGPIPE to let it know we're ignoring it, close the channel to the
478          * script process, and *then* return the failed-to-meet-condition
479          * error.  Otherwise we'd be waiting for the script to finish
480          * blithering before telling the client the output was no good.
481          * However, we don't have the information to do that, so we have to
482          * leave it to an upper layer.
483          */
484         if (w[0] == '\0') {
485             int cond_status = OK;
486
487             if ((cgi_status == HTTP_OK) && (r->method_number == M_GET)) {
488                 cond_status = ap_meets_conditions(r);
489             }
490             apr_table_overlap(r->err_headers_out, merge,
491                 APR_OVERLAP_TABLES_MERGE);
492             if (!apr_is_empty_table(cookie_table)) {
493                 /* the cookies have already been copied to the cookie_table */
494                 apr_table_unset(r->err_headers_out, "Set-Cookie");
495                 r->err_headers_out = apr_table_overlay(r->pool,
496                     r->err_headers_out, cookie_table);
497             }
498             return cond_status;
499         }
500
501         /* if we see a bogus header don't ignore it. Shout and scream */
502
503 #if APR_CHARSET_EBCDIC
504             /* Chances are that we received an ASCII header text instead of
505              * the expected EBCDIC header lines. Try to auto-detect:
506              */
507         if (!(l = strchr(w, ':'))) {
508             int maybeASCII = 0, maybeEBCDIC = 0;
509             unsigned char *cp, native;
510             apr_size_t inbytes_left, outbytes_left;
511
512             for (cp = w; *cp != '\0'; ++cp) {
513                 native = apr_xlate_conv_byte(ap_hdrs_from_ascii, *cp);
514                 if (isprint(*cp) && !isprint(native))
515                     ++maybeEBCDIC;
516                 if (!isprint(*cp) && isprint(native))
517                     ++maybeASCII;
518             }
519             if (maybeASCII > maybeEBCDIC) {
520                 ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r->server,
521                              "CGI Interface Error: Script headers apparently ASCII: (CGI = %s)",
522                              r->filename);
523                 inbytes_left = outbytes_left = cp - w;
524                 apr_xlate_conv_buffer(ap_hdrs_from_ascii,
525                                       w, &inbytes_left, w, &outbytes_left);
526             }
527         }
528 #endif /*APR_CHARSET_EBCDIC*/
529         if (!(l = strchr(w, ':'))) {
530             char malformed[(sizeof MALFORMED_MESSAGE) + 1
531                            + MALFORMED_HEADER_LENGTH_TO_SHOW];
532
533             strcpy(malformed, MALFORMED_MESSAGE);
534             strncat(malformed, w, MALFORMED_HEADER_LENGTH_TO_SHOW);
535
536             if (!buffer) {
537                 /* Soak up all the script output - may save an outright kill */
538                 while ((*getsfunc) (w, MAX_STRING_LEN - 1, getsfunc_data)) {
539                     continue;
540                 }
541             }
542
543             ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, 0, r,
544                           "%s: %s", malformed, r->filename);
545             return HTTP_INTERNAL_SERVER_ERROR;
546         }
547
548         *l++ = '\0';
549         while (*l && apr_isspace(*l)) {
550             ++l;
551         }
552
553         if (!strcasecmp(w, "Content-type")) {
554             char *tmp;
555
556             /* Nuke trailing whitespace */
557
558             char *endp = l + strlen(l) - 1;
559             while (endp > l && apr_isspace(*endp)) {
560                 *endp-- = '\0';
561             }
562
563             tmp = apr_pstrdup(r->pool, l);
564             ap_content_type_tolower(tmp);
565             r->content_type = tmp;
566         }
567         /*
568          * If the script returned a specific status, that's what
569          * we'll use - otherwise we assume 200 OK.
570          */
571         else if (!strcasecmp(w, "Status")) {
572             r->status = cgi_status = atoi(l);
573             r->status_line = apr_pstrdup(r->pool, l);
574         }
575         else if (!strcasecmp(w, "Location")) {
576             apr_table_set(r->headers_out, w, l);
577         }
578         else if (!strcasecmp(w, "Content-Length")) {
579             apr_table_set(r->headers_out, w, l);
580         }
581         else if (!strcasecmp(w, "Transfer-Encoding")) {
582             apr_table_set(r->headers_out, w, l);
583         }
584         /*
585          * If the script gave us a Last-Modified header, we can't just
586          * pass it on blindly because of restrictions on future values.
587          */
588         else if (!strcasecmp(w, "Last-Modified")) {
589             ap_update_mtime(r, apr_date_parse_http(l));
590             ap_set_last_modified(r);
591         }
592         else if (!strcasecmp(w, "Set-Cookie")) {
593             apr_table_add(cookie_table, w, l);
594         }
595         else {
596             apr_table_add(merge, w, l);
597         }
598     }
599
600     return OK;
601 }
602
603 static int getsfunc_FILE(char *buf, int len, void *f)
604 {
605     return apr_file_gets(buf, len, (apr_file_t *) f) == APR_SUCCESS;
606 }
607
608 AP_DECLARE(int) ap_scan_script_header_err(request_rec *r, apr_file_t *f,
609                                           char *buffer)
610 {
611     return ap_scan_script_header_err_core(r, buffer, getsfunc_FILE, f);
612 }
613
614 struct vastrs {
615     va_list args;
616     int arg;
617     const char *curpos;
618 };
619
620 static int getsfunc_STRING(char *w, int len, void *pvastrs)
621 {
622     struct vastrs *strs = (struct vastrs*) pvastrs;
623     const char *p;
624     int t;
625     
626     if (!strs->curpos || !*strs->curpos) 
627         return 0;
628     p = ap_strchr_c(strs->curpos, '\n');
629     if (p)
630         ++p;
631     else
632         p = ap_strchr_c(strs->curpos, '\0');
633     t = p - strs->curpos;
634     if (t > len)
635         t = len;
636     strncpy (w, strs->curpos, t);
637     w[t] = '\0';
638     if (!strs->curpos[t]) {
639         ++strs->arg;
640         strs->curpos = va_arg(strs->args, const char *);
641     }
642     else
643         strs->curpos += t;
644     return t;    
645 }
646
647 /* ap_scan_script_header_err_strs() accepts additional const char* args...
648  * each is treated as one or more header lines, and the first non-header
649  * character is returned to **arg, **data.  (The first optional arg is
650  * counted as 0.)
651  */
652 AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r, 
653                                                       char *buffer, 
654                                                       const char **termch,
655                                                       int *termarg, ...)
656 {
657     struct vastrs strs;
658     int res;
659
660     va_start(strs.args, termarg);
661     strs.arg = 0;
662     strs.curpos = va_arg(strs.args, char*);
663     res = ap_scan_script_header_err_core(r, buffer, getsfunc_STRING, (void *) &strs);
664     if (termch)
665         *termch = strs.curpos;
666     if (termarg)
667         *termarg = strs.arg;
668     va_end(strs.args);
669     return res;
670 }