1 diff -purN bb.old/editors/awk.c bb.dev/editors/awk.c
2 --- bb.old/editors/awk.c 2007-03-06 19:38:07.278092000 +0100
3 +++ bb.dev/editors/awk.c 2007-03-11 05:14:11.776304544 +0100
5 /* these flags are static, don't change them when value is changed */
6 #define VF_DONTTOUCH (VF_ARRAY | VF_SPECIAL | VF_WALK | VF_CHILD | VF_DIRTY)
9 +#define fputs(s, stream) fputs_hook(s, stream)
10 +static inline int fputs_hook (__const char *__restrict __s, FILE *__restrict __stream);
14 typedef struct var_s {
15 unsigned short type; /* flags */
16 @@ -50,10 +55,15 @@ typedef struct chain_s {
20 +typedef var *(*awk_cfunc)(var *res, var *args, int nargs);
22 typedef struct func_s {
24 - struct chain_s body;
25 + enum { AWKFUNC, CFUNC } type;
28 + struct chain_s body;
33 @@ -1312,7 +1322,8 @@ static void parse_program(char *p)
34 next_token(TC_FUNCTION);
36 f = newfunc(t.string);
37 - f->body.first = NULL;
39 + f->x.body.first = NULL;
41 while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) {
42 v = findvar(ahash, t.string);
43 @@ -1321,7 +1332,7 @@ static void parse_program(char *p)
44 if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
52 @@ -2260,7 +2271,8 @@ static var *evaluate(node *op, var *res)
56 - if (! op->r.f->body.first)
57 + if ((op->r.f->type == AWKFUNC) &&
58 + !op->r.f->x.body.first)
59 runtime_error(EMSG_UNDEF_FUNC);
61 X.v = R.v = nvalloc(op->r.f->nargs+1);
62 @@ -2277,7 +2289,11 @@ static var *evaluate(node *op, var *res)
66 - res = evaluate(op->r.f->body.first, res);
67 + if (op->r.f->type == AWKFUNC)
68 + res = evaluate(op->r.f->x.body.first, res);
69 + else if (op->r.f->type == CFUNC)
70 + res = op->r.f->x.cfunc(res, fnargs, op->r.f->nargs);
75 @@ -2637,6 +2653,11 @@ static rstream *next_input_file(void)
80 +static int is_awx = 0;
84 int awk_main(int argc, char **argv)
87 @@ -2693,6 +2714,10 @@ int awk_main(int argc, char **argv)
96 while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
98 diff -purN bb.old/editors/awx.c bb.dev/editors/awx.c
99 --- bb.old/editors/awx.c 1970-01-01 01:00:00.000000000 +0100
100 +++ bb.dev/editors/awx.c 2007-03-14 02:03:50.566202928 +0100
103 + * awk web extension
105 + * Copyright (C) 2007 by Felix Fietkau <nbd@openwrt.org>
107 + * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
113 +#define LINE_BUF 2048
114 +#define HASH_MAX 1536
115 +#define TR_START "@TR<<"
118 +#define SSI_START "<%"
119 +#define SSI_END "%>"
123 +static xhash *lstr = NULL;
124 +static xhash *formvar = NULL;
125 +static int lang_inuse = 0;
127 +/* look up a translation symbol from the hash */
128 +static inline char *translate_lookup(char *str)
130 + char *name, *def, *p;
135 + if (((p = strchr(str, '|')) != NULL)
136 + || ((p = strchr(str, '#')) != NULL)) {
141 + hi = hash_search(lstr, name);
147 + return getvar_s(v);
150 +/* look for translation markers in the line and return the translated string */
151 +static char *translate_line(char *line)
153 + char *tok[MAX_TR * 3];
154 + char *l, *p, *p2, *res;
155 + int len = 0, _pos = 0, i;
158 + while (l != NULL) {
159 + if ((p = strstr(l, TR_START)) == NULL) {
160 + len += strlen((tok[_pos++] = l));
164 + p2 = strstr(p, TR_END);
170 + len += strlen((tok[_pos++] = l));
171 + len += strlen((tok[_pos++] = translate_lookup(p + strlen(TR_START))));
174 + l += strlen(TR_END);
178 + p = xmalloc(len + 1);
181 + for (i = 0; i < _pos; i++) {
183 + p += strlen(tok[i]);
189 +/* hook for intercepting awk's use of puts. used for running all printed strings
190 + * through the translation system */
191 +static inline int fputs_hook (__const char *__restrict __s, FILE *__restrict __stream)
193 + if (lang_inuse && (__stream == stdout)) {
197 + str = translate_line((char *) __s);
198 + ret = fputs(str, __stream);
204 + return fputs(__s, __stream);
207 +static var *init_lang(var *res, var *args, int nargs)
210 + lstr = hash_init();
217 +/* load and parse language file */
218 +static void load_lang_file(char *file)
221 + char *b, *name, *value;
222 + char buf1[LINE_BUF];
224 + if ((f = fopen(file, "r")) == NULL)
227 + while (!feof(f) && (fgets(buf1, LINE_BUF - 1, f) != NULL)) {
230 + continue; /* skip comments */
232 + while (isspace(*b))
233 + b++; /* skip leading spaces */
238 + if ((b = strstr(name, "=>")) == NULL)
239 + continue; /* separator not found */
246 + for (b--; isspace(*b); b--)
247 + *b = 0; /* remove trailing spaces */
249 + while (isspace(*value))
250 + value++; /* skip leading spaces */
252 + for (b = value + strlen(value) - 1; isspace(*b); b--)
253 + *b = 0; /* remove trailing spaces */
258 + setvar_s(findvar(lstr,name), value);
264 +static var *load_lang(var *res, var *args, int nargs)
266 + const char *langfmt = "/usr/lib/webif/lang/%s.txt";
267 + char lbuf[LINE_BUF];
271 + init_lang(res, args, nargs);
273 + lang = getvar_s(args);
274 + if (!lang || !strcmp(lang, ""))
277 + sprintf(lbuf, langfmt, lang);
278 + load_lang_file(lbuf);
283 +/* read the contents of an entire file */
284 +static char *get_file(char *fname)
290 + F = fopen(fname, "r");
295 + if (fseek(F, 0, SEEK_END) == 0) {
297 + s = (char *)xmalloc(flen+4);
298 + fseek(F, 0, SEEK_SET);
299 + i = 1 + fread(s+1, 1, flen, F);
301 + for (i=j=1; j>0; i+=j) {
302 + s = (char *)xrealloc(s, i+4096);
303 + j = fread(s+i, 1, 4094, F);
315 + * taken from parse_program from awk.c
316 + * END{} is not parsed here, and BEGIN{} is executed immediately
318 +static void parse_include(char *p)
321 + chain *initseq = NULL;
328 + while ((tclass = next_token(TC_EOF | TC_OPSEQ |
329 + TC_OPTERM | TC_BEGIN | TC_FUNCDECL)) != TC_EOF) {
330 + if (tclass & TC_OPTERM)
334 + if (tclass & TC_BEGIN) {
335 + initseq = xzalloc(sizeof(chain));
338 + } else if (tclass & TC_FUNCDECL) {
339 + next_token(TC_FUNCTION);
341 + f = newfunc(t.string);
343 + f->x.body.first = NULL;
345 + while (next_token(TC_VARIABLE | TC_SEQTERM) & TC_VARIABLE) {
346 + v = findvar(ahash, t.string);
347 + v->x.aidx = (f->nargs)++;
349 + if (next_token(TC_COMMA | TC_SEQTERM) & TC_SEQTERM)
352 + seq = &(f->x.body);
354 + clear_array(ahash);
358 + evaluate(initseq->first, &tv);
362 +/* include an awk file and run its BEGIN{} section */
363 +static xhash *includes = NULL;
364 +static void include_file(char *filename)
370 + includes = hash_init();
372 + /* find out if the file has been included already */
373 + v = findvar(includes, filename);
378 + /* read include file */
379 + s = get_file(filename);
381 + fprintf(stderr, "Could not open file.\n");
384 + parse_include(s+1);
388 +static var *include(var *res, var *args, int nargs)
392 + s = getvar_s(args);
393 + if (s && (strlen(s) > 0))
400 +/* parse and evaluate an awk expression and return the result as string */
401 +static char *render_lookup(char *fname, int lnr, char *str)
406 + memset(&body, 0, sizeof(body));
411 + /* end of expression, assume that there's going to be a free byte
412 + * at the end of the string that can be used for the ')' */
413 + strcat(str + strlen(str), ")");
414 + return getvar_s(evaluate(parse_expr(TC_SEQTERM), &tv));
417 +static inline void print_translate(char *s)
421 + str = translate_line(s);
422 + fputs(str, stdout);
428 +/* process awk calls in a template line and print the output to stdout */
429 +static void render_line(char *fname, int lnr, char *line)
431 + char *tok[MAX_TR * 3];
432 + char *l, *p, *p2, *res;
433 + int len = 0, _pos = 0, i;
436 + while (l != NULL) {
437 + if ((p = strstr(l, SSI_START)) == NULL) {
438 + len += strlen((tok[_pos++] = l));
442 + p2 = strstr(p, SSI_END);
444 + fprintf(stderr, "Parse error in '%s', line '%d', unmatched %s\n", fname, lnr, SSI_END);
451 + len += strlen((tok[_pos++] = l));
452 + len += strlen((tok[_pos++] = render_lookup(fname, lnr, p + strlen(SSI_START))));
455 + l += strlen(SSI_END);
459 + p = xmalloc(len + 1);
462 + for (i = 0; i < _pos; i++) {
464 + p += strlen(tok[i]);
466 + print_translate(res);
470 +/* awk method render(), which opens a template file and processes all awk ssi calls */
471 +static void render_file(char *filename)
477 + f = fopen(filename, "r");
481 + buf1 = xmalloc(LINE_BUF);
482 + while (!feof(f) && (fgets(buf1, LINE_BUF - 1, f) != NULL)) {
483 + render_line(filename, ++lnr, buf1);
487 +static var *render(var *res, var *args, int nargs)
491 + s = getvar_s(args);
500 +/* Call render, but only if this function hasn't been called already */
501 +static int layout_rendered = 0;
502 +static var *render_layout(var *res, var *args, int nargs)
504 + if (layout_rendered)
506 + layout_rendered = 1;
507 + return render(res, args, nargs);
510 +/* registers a global c function for the awk interpreter */
511 +static void register_cfunc(char *name, awk_cfunc cfunc, int nargs)
517 + f->x.cfunc = cfunc;
521 +static void putvar(vartype type, char *name, char *value)
523 + if (type != FORM_VAR)
526 + setvar_u(findvar(formvar, name), value);
529 +static char *cgi_getvar(char *name)
532 + formvar = hash_init();
536 + if (!formvar || !name)
539 + return getvar_s(findvar(formvar, name));
542 +/* function call for accessing cgi form variables */
543 +static var *getvar(var *res, var *args, int nargs)
548 + s = getvar_s(args);
552 + svar = cgi_getvar(s);
556 + setvar_u(res, svar);
561 +/* call an awk function without arguments by string reference */
562 +static var *call(var *res, var *args, int nargs)
564 + char *s = getvar_s(args);
571 + if (f && f->type == AWKFUNC && f->x.body.first)
572 + return evaluate(f->x.body.first, res);
579 +static int run_awxscript(char *name)
581 + var tv, *layout, *action;
582 + char *tmp, *s = NULL;
585 + programname = name;
587 + /* read the main controller source */
588 + s = get_file(programname);
590 + fprintf(stderr, "Could not open file\n");
593 + parse_program(s+1);
597 + /* set some defaults for ACTION and LAYOUT, which will have special meaning */
598 + layout = newvar("LAYOUT");
599 + setvar_s(layout, "views/layout.ahtml");
601 + /* run the BEGIN {} block */
602 + evaluate(beginseq.first, &tv);
604 + action = newvar("ACTION");
605 + if (!(strlen(getvar_s(action)) > 0)) {
606 + tmp = cgi_getvar("action");
607 + if (!tmp || (strlen(tmp) <= 0))
608 + tmp = strdup("default");
610 + setvar_p(action, tmp);
613 + /* call the action (precedence: begin block override > cgi parameter > "default") */
614 + tmp = xmalloc(strlen(getvar_s(action)) + 7);
615 + sprintf(tmp, "handle_%s", getvar_s(action));
616 + setvar_s(action, tmp);
617 + call(&tv, action, 1);
620 + /* render the selected layout, will do nothing if render_layout has been called from awk */
621 + render_layout(&tv, layout, 1);
627 +/* main awx processing function. called from awk_main() */
628 +static int do_awx(int argc, char **argv)
633 + char **args = argv;
637 + /* register awk C callbacks */
638 + register_cfunc("getvar", getvar, 1);
639 + register_cfunc("render", render, 1);
640 + register_cfunc("render_layout", render_layout, 1);
641 + register_cfunc("call", call, 1);
642 + register_cfunc("include", include, 1);
643 + register_cfunc("init_lang", init_lang, 1);
644 + register_cfunc("load_lang", load_lang, 1);
649 + /* fill in ARGV array */
650 + setvar_i(V[ARGC], argc + 1);
651 + setari_u(V[ARGV], 0, "awx");
654 + setari_u(V[ARGV], ++i, *args++);
656 + while((c = getopt(argc, argv, "i:f:")) != EOF) {
659 + programname = optarg;
660 + include_file(optarg);
664 + programname = optarg;
665 + render_file(optarg);
673 + fprintf(stderr, "Invalid argument.\n");
677 + ret = run_awxscript(*argv);
683 +/* entry point for awx applet */
684 +int awx_main(int argc, char **argv)
687 + return awk_main(argc, argv);
690 diff -purN bb.old/editors/Config.in bb.dev/editors/Config.in
691 --- bb.old/editors/Config.in 2007-01-24 22:34:50.000000000 +0100
692 +++ bb.dev/editors/Config.in 2007-03-11 06:19:51.469380160 +0100
693 @@ -12,6 +12,13 @@ config AWK
694 Awk is used as a pattern scanning and processing language. This is
695 the BusyBox implementation of that programming language.
698 + bool "Enable awx (awk web extension)"
702 + awx - awk web extension
704 config FEATURE_AWK_MATH
705 bool "Enable math functions (requires libm)"
707 diff -purN bb.old/include/applets.h bb.dev/include/applets.h
708 --- bb.old/include/applets.h 2007-03-06 19:38:07.355081000 +0100
709 +++ bb.dev/include/applets.h 2007-03-07 02:12:24.280681880 +0100
710 @@ -60,6 +60,7 @@ USE_ARP(APPLET(arp, _BB_DIR_SBIN, _BB_SU
711 USE_ARPING(APPLET(arping, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
712 USE_ASH(APPLET_NOUSAGE(ash, ash, _BB_DIR_BIN, _BB_SUID_NEVER))
713 USE_AWK(APPLET(awk, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
714 +USE_AWX(APPLET_NOUSAGE(awx, awx, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
715 USE_BASENAME(APPLET(basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER))
716 USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER))
717 //USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER))
718 diff -purN bb.old/include/cgi.h bb.dev/include/cgi.h
719 --- bb.old/include/cgi.h 1970-01-01 01:00:00.000000000 +0100
720 +++ bb.dev/include/cgi.h 2007-03-11 18:58:10.708444448 +0100
725 +typedef enum { FORM_VAR, COOKIE_VAR } vartype;
726 +typedef void (*var_handler) (vartype, char *, char *);
727 +int cgi_init(var_handler);
730 diff -purN bb.old/libbb/cgi.c bb.dev/libbb/cgi.c
731 --- bb.old/libbb/cgi.c 1970-01-01 01:00:00.000000000 +0100
732 +++ bb.dev/libbb/cgi.c 2007-03-11 19:02:04.691873560 +0100
734 +/* --------------------------------------------------------------------------
735 + * functions for processing cgi form data
736 + * Copyright (C) 2007 by Felix Fietkau <nbd@openwrt.org>
738 + * parts taken from the core of haserl.cgi - a poor-man's php for embedded/lightweight environments
739 + * $Id: haserl.c,v 1.13 2004/11/10 17:59:35 nangel Exp $
740 + * Copyright (c) 2003,2004 Nathan Angelacos (nangel@users.sourceforge.net)
742 + * This program is free software; you can redistribute it and/or modify
743 + * it under the terms of the GNU General Public License as published by
744 + * the Free Software Foundation; either version 2 of the License, or
745 + * (at your option) any later version.
747 + * This program is distributed in the hope that it will be useful,
748 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
749 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
750 + * General Public License for more details.
752 + * You should have received a copy of the GNU General Public License
753 + * along with this program; if not, write to the Free Software
754 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
757 + * The x2c() and unescape_url() routines were taken from
758 + * http://www.jmarshall.com/easy/cgi/getcgi.c.txt
760 + * The comments in that text file state:
762 + *** Written in 1996 by James Marshall, james@jmarshall.com, except
763 + *** that the x2c() and unescape_url() routines were lifted directly
764 + *** from NCSA's sample program util.c, packaged with their HTTPD.
765 + *** For the latest, see http://www.jmarshall.com/easy/cgi/
768 + ------------------------------------------------------------------------- */
773 +#include <sys/mman.h>
774 +#include <sys/types.h>
775 +#include <sys/wait.h>
776 +#include <sys/stat.h>
777 +#include <sys/fcntl.h>
782 +#ifndef MAX_UPLOAD_KB
783 +#define MAX_UPLOAD_KB 2048
785 +#define TEMPDIR "/tmp"
787 +static int global_upload_size = 0;
788 +static int ReadMimeEncodedInput(char *qs);
789 +static var_handler do_putvar = NULL;
792 + * Convert 2 char hex string into char it represents
793 + * (from http://www.jmarshall.com/easy/cgi)
795 +static char x2c (char *what) {
798 + digit=(what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
800 + digit+=(what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
806 + * unsescape %xx to the characters they represent
809 +static void unescape_url (char *url) {
812 + for (i=0, j=0; url[j]; ++i, ++j) {
813 + if ((url[i] = url[j]) == '%') {
814 + url[i] = x2c(&url[j+1]);
821 +static inline void put_var(vartype type, char *var)
828 + val = strchr(var, '=');
834 + do_putvar(type, var, val);
841 + * if HTTP_COOKIE is passed as an environment variable,
842 + * attempt to parse its values into environment variables
844 +static void CookieVars (void)
849 + if (getenv("HTTP_COOKIE") != NULL)
850 + qs=strdup(getenv("HTTP_COOKIE"));
854 + /** split on; to extract name value pairs */
855 + token=strtok(qs, ";");
857 + // skip leading spaces
858 + while ( token[0] == ' ' )
861 + put_var(COOKIE_VAR, token);
863 + token = strtok(NULL, ";");
869 + * Read cgi variables from query string, and put in environment
871 +static int ReadCGIQueryString (void)
877 + if (getenv("QUERY_STRING") != NULL)
878 + qs=strdup(getenv("QUERY_STRING"));
882 + /* change plusses into spaces */
883 + for (i=0; qs[i]; i++ ) { if (qs[i] == '+' ) { qs[i] = ' ';} };
885 + /** split on & and ; to extract name value pairs */
887 + token=strtok(qs, "&;");
889 + unescape_url(token);
890 + put_var(FORM_VAR, token);
891 + token=strtok(NULL, "&;");
900 + * Read cgi variables from stdin (for POST queries)
901 + * (oh... and if its mime-encoded file upload, we save the
902 + * file to /tmp; and return the name of the tmp file
903 + * the cgi script is responsible for disposing of the tmp file
906 +static int ReadCGIPOSTValues (void) {
908 + int content_length;
913 + if (getenv("CONTENT_LENGTH") == NULL)
916 + content_length = atoi(getenv("CONTENT_LENGTH"));
918 + /* protect ourselves from 20GB file uploads */
919 + if (content_length > MAX_UPLOAD_KB * 1024 ) {
920 + /* But we need to finish reading the content */
921 + while ( fread( &i, sizeof(int), 1, stdin) == 1 );
925 + if (!(qs=malloc(content_length+1)))
928 + /* set the buffer to null, so that a browser messing with less
929 + data than content_length won't buffer underrun us */
930 + memset(qs, 0 ,content_length+1);
932 + if ((!fread(qs,content_length,1,stdin) &&
933 + (content_length > 0)
934 + && !feof(stdin))) {
940 + if (getenv("CONTENT_TYPE") && (strncasecmp(getenv("CONTENT_TYPE"), "multipart/form-data", 19) == 0)) {
941 + /* This is a mime request, we need to go to the mime handler */
942 + i=ReadMimeEncodedInput(qs);
948 + /* change plusses into spaces */
949 + for (i=0; qs[i]; i++ ) { if (qs[i] == '+' ) { qs[i] = ' ';} };
951 + /** split on & and ; to extract name value pairs */
952 + token=strtok(qs, "&;");
954 + unescape_url(token);
955 + put_var(FORM_VAR, token);
956 + token=strtok(NULL, "&;");
965 + * LineToStr - Scans char and replaces the first "\n" with a "\0";
966 + * If it finds a "\r", it does that to; (fix DOS brokennes) returns
967 + * the length of the string;
969 +static int LineToStr (char *string, size_t max) {
972 + while ((offset < max) && (string[offset] != '\n') && (string[offset] != '\r'))
975 + if (string[offset] == '\r') {
976 + string[offset]='\0';
979 + if (string[offset] == '\n') {
980 + string[offset]='\0';
989 + * ReadMimeEncodedInput - handles things that are mime encoded
990 + * takes a pointer to the input; returns 0 on success
993 +static int ReadMimeEncodedInput(char *qs)
1005 + char tmpname[] = TEMPDIR "/XXXXXX";
1007 + /* we should only get here if the content type was set. Segfaults happen
1008 + if Content_Type is null */
1010 + if (getenv("CONTENT_LENGTH") == NULL)
1011 + /* No content length?! */
1014 + cl=atoi(getenv("CONTENT_LENGTH"));
1016 + /* we do this 'cause we can't mess with the real env. variable - it would
1017 + * overwrite the environment - I tried.
1019 + i=strlen(getenv("CONTENT_TYPE"))+1;
1022 + memcpy(ct, getenv("CONTENT_TYPE"), i);
1028 + while (i < strlen(ct) && (strncmp("boundary=", &ct[i], 9) != 0))
1031 + if (i == strlen(ct)) {
1032 + /* no boundary informaiton found */
1036 + boundary=&ct[i+7];
1037 + /* add two leading -- to the boundary */
1041 + /* begin the big loop. Look for:
1043 + Content-Disposition: form-data; name="......."
1048 + Content-Disposition: form-data; name="....." filename="....."
1056 + while (offset < cl) {
1057 + /* first look for boundary */
1058 + while ((offset < cl) && (memcmp(&qs[offset], boundary, strlen(boundary))))
1061 + /* if we got here and we ran off the end, its an error */
1062 + if (offset >= cl) {
1067 + /* if the two characters following the boundary are --, */
1068 + /* then we are at the end, exit */
1069 + if (memcmp(&qs[offset+strlen(boundary)], "--", 2) == 0) {
1073 + /* find where the offset should be */
1074 + line=LineToStr(&qs[offset], cl-offset);
1077 + /* Now we're going to look for content-disposition */
1078 + line=LineToStr(&qs[offset], cl-offset);
1079 + if (strncasecmp(&qs[offset], "Content-Disposition", 19) != 0) {
1080 + /* hmm... content disposition was not where we expected it */
1084 + /* Found it, so let's go find "name=" */
1085 + if (!(envname=strstr(&qs[offset], "name="))) {
1086 + /* now name= is missing?! */
1092 + /* is there a filename tag? */
1093 + if ((filename=strstr(&qs[offset], "filename="))!= NULL)
1098 + /* make envname and filename ASCIIZ */
1099 + for (i=0; (envname[i] != '"') && (envname[i] != '\0'); i++);
1101 + envname[i] = '\0';
1103 + for (i=0; (filename[i] != '"') && (filename[i] != '\0'); i++);
1104 + filename[i] = '\0';
1108 + /* Ok, by some miracle, we have the name; let's skip till we */
1109 + /* come to a blank line */
1110 + line=LineToStr(&qs[offset], cl-offset);
1111 + while (strlen(&qs[offset]) > 1) {
1113 + line=LineToStr(&qs[offset], cl-offset);
1117 + /* And we go back to looking for a boundary */
1118 + while ((offset < cl) && (memcmp(&qs[offset], boundary, strlen(boundary))))
1121 + /* strip [cr] lf */
1122 + if ((qs[offset-1] == '\n') && (qs[offset-2] == '\r'))
1129 + /* ok, at this point, we know where the name is, and we know */
1130 + /* where the content is... we have to do one of two things */
1131 + /* based on whether its a file or not */
1132 + if (filename==NULL) { /* its not a file, so its easy */
1133 + /* just jam the content after the name */
1134 + memcpy(&envname[strlen(envname)+1], &qs[datastart], offset-datastart+1);
1135 + envname[strlen(envname)]='=';
1136 + put_var(FORM_VAR, envname);
1137 + } else { /* handle the fileupload case */
1138 + if (offset-datastart) { /* only if they uploaded */
1139 + if ( global_upload_size == 0 ) {
1142 + /* stuff in the filename */
1143 + ptr= calloc ( sizeof (char), strlen(envname)+strlen(filename)+2+5 );
1144 + sprintf (ptr, "%s_name=%s", envname, filename);
1145 + put_var(FORM_VAR, ptr);
1148 + fd=mkstemp(tmpname);
1153 + write(fd, &qs[datastart], offset-datastart);
1155 + ptr= calloc (sizeof(char), strlen(envname)+strlen(tmpname)+2);
1156 + sprintf (ptr, "%s=%s", envname, tmpname);
1157 + put_var(FORM_VAR, ptr);
1167 +/*-------------------------------------------------------------------------
1171 + *------------------------------------------------------------------------*/
1173 +int cgi_init(var_handler putvar_handler)
1177 + do_putvar = putvar_handler;
1179 + /* Read the current environment into our chain */
1181 + if (getenv("REQUEST_METHOD")) {
1182 + if (strcasecmp(getenv("REQUEST_METHOD"), "GET") == 0)
1183 + retval = ReadCGIQueryString();
1185 + if (strcasecmp(getenv("REQUEST_METHOD"), "POST") == 0)
1186 + retval = ReadCGIPOSTValues();
1191 diff -purN bb.old/libbb/Kbuild bb.dev/libbb/Kbuild
1192 --- bb.old/libbb/Kbuild 2007-03-06 19:38:07.361080000 +0100
1193 +++ bb.dev/libbb/Kbuild 2007-03-11 18:40:51.384445712 +0100
1194 @@ -118,3 +118,6 @@ lib-$(CONFIG_GREP) += xregcomp.o
1195 lib-$(CONFIG_MDEV) += xregcomp.o
1196 lib-$(CONFIG_LESS) += xregcomp.o
1197 lib-$(CONFIG_DEVFSD) += xregcomp.o
1199 +lib-$(CONFIG_AWX) += cgi.o