diff options
author | Nathan Angelacos <nangel@alpinelinux.org> | 2008-02-23 22:13:31 +0000 |
---|---|---|
committer | Nathan Angelacos <nangel@alpinelinux.org> | 2008-02-23 22:13:31 +0000 |
commit | 383a75a92082400bffdc28fb9ef1a3cee906e220 (patch) | |
tree | a3bddd32ccc7a91efc7deb9eee365432db1b3dfa /src | |
parent | f4aea20f868fd544d45c1bb1ff4349bc51e940ca (diff) | |
download | haserl-383a75a92082400bffdc28fb9ef1a3cee906e220.tar.bz2 haserl-383a75a92082400bffdc28fb9ef1a3cee906e220.tar.xz |
add Scott's idea for newline-separating multi-selects
Diffstat (limited to 'src')
-rw-r--r-- | src/common.c | 4 | ||||
-rw-r--r-- | src/haserl.c | 178 | ||||
-rw-r--r-- | src/sliding_buffer.c | 1 |
3 files changed, 104 insertions, 79 deletions
diff --git a/src/common.c b/src/common.c index 8f5ad6b..3b02442 100644 --- a/src/common.c +++ b/src/common.c @@ -186,12 +186,12 @@ argc_argv (char *instr, argv_t ** argv, char *commentstr) ALLOC_CHUNK)); } - if (argv_array == (char) NULL) + if (argv_array == NULL) { return (-1); } argv_array[arg_count - 1].string = instr; - argv_array[arg_count].quoted = (char) NULL; + argv_array[arg_count].quoted = 0; state = WORDSPACE; } diff --git a/src/haserl.c b/src/haserl.c index 3c342d1..5b7bad8 100644 --- a/src/haserl.c +++ b/src/haserl.c @@ -91,11 +91,11 @@ haserl_t global; /* declare the shell_ function pointers here */ -void (*shell_exec)(buffer_t *buf, char *str); -void (*shell_echo)(buffer_t *buf, char *str, size_t len); -void (*shell_eval)(buffer_t *buf, char *str, size_t len); -void (*shell_setup)( char *, list_t *); -void (*shell_doscript)( buffer_t *, char *); +void (*shell_exec) (buffer_t * buf, char *str); +void (*shell_echo) (buffer_t * buf, char *str, size_t len); +void (*shell_eval) (buffer_t * buf, char *str, size_t len); +void (*shell_setup) (char *, list_t *); +void (*shell_doscript) (buffer_t *, char *); void (*shell_destroy) (void); @@ -114,7 +114,7 @@ struct option ga_long_options[] = { {"debug", no_argument, 0, 'D'}, {"upload-limit", required_argument, 0, 'u'}, {"upload-dir", required_argument, 0, 'U'}, - {"upload-handler", required_argument, 0, 'H' }, + {"upload-handler", required_argument, 0, 'H'}, {"accept-all", no_argument, 0, 'a'}, {"accept-none", no_argument, 0, 'n'}, {"shell", required_argument, 0, 's'}, @@ -202,20 +202,37 @@ myputenv (list_t * cur, char *str, char *prefix) list_t *prev = NULL; size_t keylen; char *entry = NULL; + char *temp = NULL; + int array = 0; + + keylen = (size_t) ((char *) memchr (str, '=', strlen (str)) - (char *) str); + if (keylen <= 0) + { + return (NULL); + } + + /* is this an array */ + if (memcmp (str + keylen - 2, "[]", 2) == 0) + { + keylen = keylen - 2; + array = 1; + } entry = xmalloc (strlen (str) + strlen (prefix) + 1); + entry[0] = '\0'; if (strlen (prefix)) { - memcpy (entry, prefix, strlen (prefix)); + strncat (entry, prefix, strlen (prefix)); } - memcpy ((char *) (entry + strlen (prefix)), str, strlen (str)); - keylen = (size_t) (index (entry, '=') - entry); - - if (keylen <= 0) + if (array == 1) { - free (entry); - return (NULL); + strncat (entry, str, keylen); + strcat (entry, str + keylen + 2); + } + else + { + strcat (entry, str); } /* does the value already exist? */ @@ -223,9 +240,17 @@ myputenv (list_t * cur, char *str, char *prefix) { if (memcmp (cur->buf, entry, keylen + 1) == 0) { - entry[keylen] = '\0'; - // unsetenv (entry); - entry[keylen] = '='; + if (array == 1) + { + /* if an array, add this value to the old array */ + temp = xmalloc (strlen (cur->buf) + strlen (entry + keylen)); + memmove (temp, cur->buf, strlen (cur->buf)); + strcat (temp, "\n"); + strcat (temp, str + keylen + 3); + free (entry); + entry = temp; + } + /* delete the old entry */ free (cur->buf); if (prev != NULL) prev->next = cur->next; @@ -233,15 +258,15 @@ myputenv (list_t * cur, char *str, char *prefix) cur = prev; } /* end if found a matching key */ prev = cur; - if ( cur ) { - cur = (list_t *) cur->next; + if (cur) + { + cur = (list_t *) cur->next; } } /* end if matching key */ /* add the value to the end of the chain */ cur = xmalloc (sizeof (list_t)); cur->buf = entry; - // putenv (cur->buf); if (prev != NULL) prev->next = cur; @@ -416,8 +441,8 @@ ReadCGIPOSTValues (list_t * env) buffer_t token; unsigned char *data; - if (getenv ("CONTENT_LENGTH" ) == NULL ) - return (0); + if (getenv ("CONTENT_LENGTH") == NULL) + return (0); if (getenv ("CONTENT_TYPE")) { @@ -432,9 +457,9 @@ ReadCGIPOSTValues (list_t * env) s_buffer_init (&sbuf, 32768); sbuf.fh = STDIN; - if ( getenv( "CONTENT_LENGTH" ) ) + if (getenv ("CONTENT_LENGTH")) { - sbuf.maxread = strtoul(getenv("CONTENT_LENGTH"), NULL, 10); + sbuf.maxread = strtoul (getenv ("CONTENT_LENGTH"), NULL, 10); } buffer_init (&token); @@ -470,7 +495,7 @@ ReadCGIPOSTValues (list_t * env) } /* change plusses into spaces */ - j = strlen((char *) data); + j = strlen ((char *) data); for (i = 0; i <= j; i++) { if (data[i] == '+') @@ -538,7 +563,7 @@ parseCommandLine (int argc, char *argv[]) case 'U': global.uploaddir = optarg; break; - case 'H' : + case 'H': global.uploadhandler = optarg; break; case 'v': @@ -557,14 +582,14 @@ BecomeUser (uid_t uid, gid_t gid) { /* This silently fails if it doesn't work */ /* Following is from Timo Teras */ - if (getuid() == 0) - setgroups(1, &gid); - + if (getuid () == 0) + setgroups (1, &gid); + setgid (gid); - setgid(getgid()); + setgid (getgid ()); setuid (uid); - setuid(getuid()); + setuid (getuid ()); return (0); } @@ -580,7 +605,7 @@ assignGlobalStartupValues () global.shell = SUBSHELL_CMD; /* The shell we use */ global.silent = FALSE; /* We do print errors if we find them */ global.uploaddir = TEMPDIR; /* where to upload to */ - global.uploadhandler = NULL; /* the upload handler */ + global.uploadhandler = NULL; /* the upload handler */ global.debug = FALSE; /* Not in debug mode. */ global.acceptall = FALSE; /* don't allow POST data for GET method */ global.uploadlist = NULL; /* we don't have any uploaded files */ @@ -616,10 +641,10 @@ unlink_uploadlist () int main (int argc, char *argv[]) { - #ifndef JUST_LUACSHELL +#ifndef JUST_LUACSHELL token_t *tokenchain = NULL; buffer_t script_text; - #endif +#endif script_t *scriptchain; int retval = 0; @@ -633,10 +658,10 @@ main (int argc, char *argv[]) list_t *env = NULL; - assignGlobalStartupValues(); - #ifndef JUST_LUACSHELL + assignGlobalStartupValues (); +#ifndef JUST_LUACSHELL buffer_init (&script_text); - #endif +#endif /* if more than argv[1] and argv[1] is not a file */ switch (argc) @@ -676,47 +701,47 @@ main (int argc, char *argv[]) BecomeUser (scriptchain->uid, scriptchain->gid); /* populate the function pointers based on the shell selected */ - if (strcmp(global.shell, "lua") && strcmp(global.shell, "luac")) /* default to "bash" */ + if (strcmp (global.shell, "lua") && strcmp (global.shell, "luac")) /* default to "bash" */ { - #ifdef INCLUDE_BASHSHELL +#ifdef INCLUDE_BASHSHELL shell_exec = &bash_exec; shell_echo = &bash_echo; shell_eval = &bash_eval; shell_setup = &bash_setup; shell_doscript = &bash_doscript; shell_destroy = &bash_destroy; - #else +#else die_with_message (NULL, NULL, "Bash shell is not enabled."); - #endif +#endif } else { - #ifdef USE_LUA +#ifdef USE_LUA shell_setup = &lua_common_setup; shell_destroy = &lua_common_destroy; global.var_prefix = "FORM."; global.nul_prefix = "ENV."; - if(global.shell[3] == 'c') /* compiled Lua specific function ptr... */ - #ifdef INCLUDE_LUACSHELL - shell_doscript = &luac_doscript; - #else - die_with_message (NULL, NULL, "Compiled Lua shell is not enabled."); - #endif + if (global.shell[3] == 'c') /* compiled Lua specific function ptr... */ +#ifdef INCLUDE_LUACSHELL + shell_doscript = &luac_doscript; +#else + die_with_message (NULL, NULL, "Compiled Lua shell is not enabled."); +#endif else - { - #ifdef INCLUDE_LUASHELL - shell_exec = &lua_exec; - shell_echo = &lua_echo; - shell_eval = &lua_eval; - shell_doscript = &lua_doscript; - #else - die_with_message (NULL, NULL, "Standard Lua shell is not enabled."); - #endif - } - #else + { +#ifdef INCLUDE_LUASHELL + shell_exec = &lua_exec; + shell_echo = &lua_echo; + shell_eval = &lua_eval; + shell_doscript = &lua_doscript; +#else + die_with_message (NULL, NULL, "Standard Lua shell is not enabled."); +#endif + } +#else die_with_message (NULL, NULL, "Lua shells are not enabled."); - #endif +#endif } /* Read the current environment into our chain */ @@ -725,13 +750,13 @@ main (int argc, char *argv[]) sessionid (env); haserlflags (env); - #ifndef JUST_LUACSHELL +#ifndef JUST_LUACSHELL if (strcmp (global.shell, "luac")) { tokenchain = build_token_list (scriptchain, NULL); preprocess_token_list (tokenchain); } - #endif +#endif /* Read the request data */ if (global.acceptall != NONE) @@ -757,34 +782,35 @@ main (int argc, char *argv[]) } /* build a copy of the script to send to the shell */ - #ifndef JUST_LUACSHELL +#ifndef JUST_LUACSHELL if (strcmp (global.shell, "luac")) { process_token_list (&script_text, tokenchain); } - #endif +#endif /* run the script */ if (global.debug == TRUE) { - #ifndef JUST_LUACSHELL +#ifndef JUST_LUACSHELL if (getenv ("REQUEST_METHOD")) - { - write (1, "Content-Type: text/plain\n\n", 26); - } + { + write (1, "Content-Type: text/plain\n\n", 26); + } write (1, script_text.data, script_text.ptr - script_text.data); - #else - die_with_message (NULL, NULL, "Debugging output doesn't work with the compiled Lua shell."); - #endif +#else + die_with_message (NULL, NULL, + "Debugging output doesn't work with the compiled Lua shell."); +#endif } else { shell_setup (global.shell, env); - #ifdef JUST_LUACSHELL +#ifdef JUST_LUACSHELL shell_doscript (NULL, scriptchain->name); - #else +#else shell_doscript (&script_text, scriptchain->name); - #endif +#endif shell_destroy (); } @@ -794,12 +820,12 @@ main (int argc, char *argv[]) unlink_uploadlist (); free_token_list (global.uploadlist); } - - #ifndef JUST_LUACSHELL + +#ifndef JUST_LUACSHELL /* destroy the script */ buffer_destroy (&script_text); free_token_list (tokenchain); - #endif +#endif free_list_chain (env); free_script_list (scriptchain); diff --git a/src/sliding_buffer.c b/src/sliding_buffer.c index 707de46..2b5ef33 100644 --- a/src/sliding_buffer.c +++ b/src/sliding_buffer.c @@ -68,7 +68,6 @@ s_buffer_read (sliding_buffer_t * sbuf, char *matchstr) { int len, pos; int r; - size_t max; /* * if eof and ptr ran off the buffer, then we are done |