diff --git a/qse/include/qse/cmn/env.h b/qse/include/qse/cmn/env.h index 6e82c9b7..ded0b3e6 100644 --- a/qse/include/qse/cmn/env.h +++ b/qse/include/qse/cmn/env.h @@ -29,6 +29,15 @@ * an environment block. */ + +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + typedef qse_wchar_t qse_env_char_t; +# define QSE_ENV_CHAR_IS_WCHAR +#else + typedef qse_mchar_t qse_env_char_t; +# define QSE_ENV_CHAR_IS_MCHAR +#endif + /** * The qse_env_t type defines a cross-platform environment block. */ @@ -42,14 +51,14 @@ struct qse_env_t { qse_size_t capa; qse_size_t len; - qse_char_t* ptr; + qse_env_char_t* ptr; } str; struct { qse_size_t capa; qse_size_t len; - qse_char_t** ptr; + qse_env_char_t** ptr; } arr; }; @@ -87,17 +96,36 @@ void qse_env_clear ( #define qse_env_getstr(env) ((env)->str.ptr) #define qse_env_getarr(env) ((env)->arr.ptr) -int qse_env_insert ( +int qse_env_insertw ( qse_env_t* env, - const qse_char_t* name, - const qse_char_t* value + const qse_wchar_t* name, + const qse_wchar_t* value ); -int qse_env_delete ( +int qse_env_insertm ( qse_env_t* env, - const qse_char_t* name + const qse_mchar_t* name, + const qse_mchar_t* value ); +int qse_env_deletew ( + qse_env_t* env, + const qse_wchar_t* name +); + +int qse_env_deletem ( + qse_env_t* env, + const qse_mchar_t* name +); + +#if defined(QSE_CHAR_IS_WCHAR) +# define qse_env_insert(env,name,value) qse_env_insertw(env,name,value) +# define qse_env_delete(env,name) qse_env_deletew(env,name) +#else +# define qse_env_insert(env,name,value) qse_env_insertm(env,name,value) +# define qse_env_delete(env,name) qse_env_deletem(env,name) +#endif + #ifdef __cplusplus } #endif diff --git a/qse/include/qse/cmn/pio.h b/qse/include/qse/cmn/pio.h index 9372ba25..b9e9fa0d 100644 --- a/qse/include/qse/cmn/pio.h +++ b/qse/include/qse/cmn/pio.h @@ -1,5 +1,5 @@ /* - * $Id: pio.h 533 2011-08-04 15:43:28Z hyunghwan.chung $ + * $Id: pio.h 538 2011-08-09 16:08:26Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -24,6 +24,7 @@ #include #include #include +#include /** @file * This file defines a piped interface to a child process. You can execute @@ -190,12 +191,15 @@ QSE_DEFINE_COMMON_FUNCTIONS (pio) * pipes to it. #QSE_PIO_SHELL causes the function to execute @a cmd via * the default shell of an underlying system: /bin/sh on *nix, cmd.exe on win32. * On *nix systems, a full path to the command is needed if it is not specified. + * If @a env is #QSE_NULL, the environment of @a cmd inherits that of the + * calling process. * @return #qse_pio_t object on success, #QSE_NULL on failure */ qse_pio_t* qse_pio_open ( qse_mmgr_t* mmgr, /**< memory manager */ qse_size_t ext, /**< extension size */ const qse_char_t* cmd, /**< command to execute */ + qse_env_t* env, /**< environment */ int oflags /**< 0 or a number OR'ed of the #qse_pio_oflag_t enumerators*/ ); @@ -218,6 +222,7 @@ qse_pio_t* qse_pio_init ( qse_pio_t* pio, /**< pio object */ qse_mmgr_t* mmgr, /**< memory manager */ const qse_char_t* cmd, /**< command to execute */ + qse_env_t* env, /**< environment */ int oflags /**< 0 or a number OR'ed of the #qse_pio_oflag_t enumerators*/ ); diff --git a/qse/lib/awk/StdAwk.cpp b/qse/lib/awk/StdAwk.cpp index f43da3d9..13a28ab9 100644 --- a/qse/lib/awk/StdAwk.cpp +++ b/qse/lib/awk/StdAwk.cpp @@ -1,5 +1,5 @@ /* - * $Id: StdAwk.cpp 516 2011-07-23 09:03:48Z hyunghwan.chung $ + * $Id: StdAwk.cpp 538 2011-08-09 16:08:26Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -165,6 +165,7 @@ int StdAwk::openPipe (Pipe& io) this->getMmgr(), 0, io.getName(), + QSE_NULL, flags ); if (pio == QSE_NULL) return -1; diff --git a/qse/lib/awk/std.c b/qse/lib/awk/std.c index 67757636..3295ea82 100644 --- a/qse/lib/awk/std.c +++ b/qse/lib/awk/std.c @@ -1,5 +1,5 @@ /* - * $Id: std.c 519 2011-07-24 14:42:23Z hyunghwan.chung $ + * $Id: std.c 538 2011-08-09 16:08:26Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -780,6 +780,7 @@ static qse_ssize_t awk_rio_pipe ( rtx->awk->mmgr, 0, riod->name, + QSE_NULL, flags|QSE_PIO_SHELL|QSE_PIO_TEXT ); diff --git a/qse/lib/cmn/env.c b/qse/lib/cmn/env.c index ca3841e8..7089cf66 100644 --- a/qse/lib/cmn/env.c +++ b/qse/lib/cmn/env.c @@ -81,7 +81,11 @@ void qse_env_clear (qse_env_t* env) { if (env->str.ptr) { - env->str.ptr[0] = QSE_T('\0'); +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + env->str.ptr[0] = QSE_WT('\0'); +#else + env->str.ptr[0] = QSE_MT('\0'); +#endif env->str.len = 0; } if (env->arr.ptr) @@ -93,10 +97,10 @@ void qse_env_clear (qse_env_t* env) static int expandarr (qse_env_t* env) { - qse_char_t** tmp; + qse_env_char_t** tmp; qse_size_t ncapa = env->arr.capa + ARRSIZE; - tmp = (qse_char_t**) QSE_MMGR_REALLOC ( + tmp = (qse_env_char_t**) QSE_MMGR_REALLOC ( env->mmgr, env->arr.ptr, QSE_SIZEOF(qse_char_t*) * (ncapa + 1)); if (tmp == QSE_NULL) return -1; @@ -109,15 +113,15 @@ static int expandarr (qse_env_t* env) static int expandstr (qse_env_t* env, qse_size_t inc) { - qse_char_t* tmp; + qse_env_char_t* tmp; qse_size_t ncapa; ncapa = (inc > STRSIZE)? (env->str.capa + inc): (env->str.capa + STRSIZE); - tmp = (qse_char_t*) QSE_MMGR_REALLOC ( + tmp = (qse_env_char_t*) QSE_MMGR_REALLOC ( env->mmgr, env->str.ptr, - QSE_SIZEOF(qse_char_t) * (ncapa + 1)); + QSE_SIZEOF(*tmp) * (ncapa + 1)); if (tmp == QSE_NULL) return -1; if (tmp != env->str.ptr) @@ -127,7 +131,8 @@ static int expandstr (qse_env_t* env, qse_size_t inc) qse_size_t i; for (i = 0; i < env->arr.len; i++) { - env->arr.ptr[i] = tmp + (env->arr.ptr[i] - env->str.ptr); + qse_env_char_t* cur = env->arr.ptr[i]; + env->arr.ptr[i] = tmp + (cur - env->str.ptr); } } @@ -137,13 +142,13 @@ static int expandstr (qse_env_t* env, qse_size_t inc) return 0; } -int qse_env_insert ( - qse_env_t* env, const qse_char_t* name, const qse_char_t* value) +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) +static int insertw (qse_env_t* env, const qse_wchar_t* name, const qse_wchar_t* value) { qse_size_t nl, vl, tl; - nl = qse_strlen (name); - vl = qse_strlen (value); + nl = qse_wcslen (name); + vl = qse_wcslen (value); if (env->arr.len >= env->arr.capa && expandarr(env) <= -1) return -1; @@ -155,44 +160,53 @@ int qse_env_insert ( env->arr.ptr[env->arr.len++] = &env->str.ptr[env->str.len]; env->arr.ptr[env->arr.len] = QSE_NULL; - env->str.len += qse_strcpy (&env->str.ptr[env->str.len], name); - env->str.ptr[env->str.len++] = QSE_T('='); - env->str.len += qse_strcpy (&env->str.ptr[env->str.len], value); - env->str.ptr[++env->str.len] = QSE_T('\0'); + env->str.len += qse_wcscpy (&env->str.ptr[env->str.len], name); + env->str.ptr[env->str.len++] = QSE_WT('='); + env->str.len += qse_wcscpy (&env->str.ptr[env->str.len], value); + env->str.ptr[++env->str.len] = QSE_WT('\0'); return -1; } -int qse_env_delete (qse_env_t* env, const qse_char_t* name) +static int add_envstrw (qse_env_t* env, const qse_wchar_t* nv) +{ + qse_size_t tl; + + if (env->arr.len >= env->arr.capa && + expandarr(env) <= -1) return -1; + + tl = qse_wcslen(nv) + 1; + if (env->str.len + tl > env->str.capa && + expandstr (env, tl) <= -1) return -1; + + env->arr.ptr[env->arr.len++] = &env->str.ptr[env->str.len]; + env->arr.ptr[env->arr.len] = QSE_NULL; + + env->str.len += qse_wcscpy (&env->str.ptr[env->str.len], nv); + env->str.ptr[++env->str.len] = QSE_WT('\0'); + return 0; +} + +static int deletem (qse_env_t* env, const qse_wchar_t* name) { qse_size_t i; for (i = 0; i < env->arr.len; i++) { - const qse_char_t* eq; - qse_char_t* vp; + const qse_wchar_t* eq; + qse_wchar_t* vp; vp = env->arr.ptr[i]; -//qse_printf (QSE_T("comparing [%s] []\n"), vp); - eq = qse_strbeg (vp, name); - if (eq && *eq == QSE_T('=')) + eq = qse_wcsbeg (vp, name); + if (eq && *eq == QSE_WT('=')) { /* bingo */ qse_size_t len, rem; -/* -5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 -A B C = D E F \0 X = Y Y \0 Z = T T \0 \0 - -env->str.len = 18 -env->str.ptr = 5 -vp = 13 -len = 4 + 1 -*/ - len = qse_strlen (vp) + 1; + len = qse_mbslen (vp) + 1; rem = env->str.len - (vp + len - env->str.ptr) + 1; - QSE_MEMCPY (vp, vp + len, rem * QSE_SIZEOF(qse_char_t)); + QSE_MEMCPY (vp, vp + len, rem * QSE_SIZEOF(*vp)); env->str.len -= len; env->arr.len--; @@ -207,25 +221,180 @@ len = 4 + 1 return -1; } -static int add_envstr (qse_env_t* env, const qse_char_t* nv) +#else +static int insertm (qse_env_t* env, const qse_mchar_t* name, const qse_mchar_t* value) { - qse_size_t tl; - + qse_size_t nl, vl, tl; + + nl = qse_mbslen (name); + vl = qse_mbslen (value); + if (env->arr.len >= env->arr.capa && expandarr(env) <= -1) return -1; - tl = qse_strlen(nv) + 1; + tl = nl + 1 + vl + 1; /* name = value '\0' */ if (env->str.len + tl > env->str.capa && expandstr (env, tl) <= -1) return -1; env->arr.ptr[env->arr.len++] = &env->str.ptr[env->str.len]; env->arr.ptr[env->arr.len] = QSE_NULL; - env->str.len += qse_strcpy (&env->str.ptr[env->str.len], nv); - env->str.ptr[++env->str.len] = QSE_T('\0'); + env->str.len += qse_mbscpy (&env->str.ptr[env->str.len], name); + env->str.ptr[env->str.len++] = QSE_MT('='); + env->str.len += qse_mbscpy (&env->str.ptr[env->str.len], value); + env->str.ptr[++env->str.len] = QSE_MT('\0'); + + return -1; +} + +static int add_envstrm (qse_env_t* env, const qse_mchar_t* nv) +{ + qse_size_t tl; + + if (env->arr.len >= env->arr.capa && + expandarr(env) <= -1) return -1; + + tl = qse_mbslen(nv) + 1; + if (env->str.len + tl > env->str.capa && + expandstr (env, tl) <= -1) return -1; + + env->arr.ptr[env->arr.len++] = &env->str.ptr[env->str.len]; + env->arr.ptr[env->arr.len] = QSE_NULL; + + env->str.len += qse_mbscpy (&env->str.ptr[env->str.len], nv); + env->str.ptr[++env->str.len] = QSE_MT('\0'); return 0; } +static int deletem (qse_env_t* env, const qse_mchar_t* name) +{ + qse_size_t i; + + for (i = 0; i < env->arr.len; i++) + { + const qse_mchar_t* eq; + qse_mchar_t* vp; + + vp = env->arr.ptr[i]; + + eq = qse_mbsbeg (vp, name); + if (eq && *eq == QSE_MT('=')) + { + /* bingo */ + qse_size_t len, rem; + + len = qse_mbslen (vp) + 1; + rem = env->str.len - (vp + len - env->str.ptr) + 1; + QSE_MEMCPY (vp, vp + len, rem * QSE_SIZEOF(*vp)); + env->str.len -= len; + + env->arr.len--; + for (; i < env->arr.len; i++) + env->arr.ptr[i] = env->arr.ptr[i+1] - len; + env->arr.ptr[i] = QSE_NULL; + + return 0; + } + } + + return -1; +} + +#endif + +int qse_env_insertw ( + qse_env_t* env, const qse_wchar_t* name, const qse_wchar_t* value) +{ +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + /* no conversion -> wchar */ + return insertw (env, name, value); +#else + /* convert wchar to mchar */ + qse_mchar_t* namedup, * valuedup; + int n; + + namedup = qse_wcstombsdup (name, env->mmgr); + if (namedup == QSE_NULL) return -1; + valuedup = qse_wcstombsdup (value, env->mmgr); + if (valuedup == QSE_NULL) + { + QSE_MMGR_FREE (env->mmgr, namedup); + return -1; + } + n = insertm (env, namedup, valuedup); + QSE_MMGR_FREE (env->mmgr, valuedup); + QSE_MMGR_FREE (env->mmgr, namedup); + + return n; +#endif +} + +int qse_env_insertm ( + qse_env_t* env, const qse_mchar_t* name, const qse_mchar_t* value) +{ +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + /* convert mchar to wchar */ + qse_wchar_t* namedup, * valuedup; + int n; + + namedup = qse_mbstowcsdup (name, env->mmgr); + if (namedup == QSE_NULL) return -1; + valuedup = qse_mbstowcsdup (value, env->mmgr); + if (valuedup == QSE_NULL) + { + QSE_MMGR_FREE (env->mmgr, namedup); + return -1; + } + n = insertw (env, namedup, valuedup); + QSE_MMGR_FREE (env->mmgr, valuedup); + QSE_MMGR_FREE (env->mmgr, namedup); + + return n; +#else + /* no conversion -> mchar */ + return insertm (env, name, value); +#endif + +} + +int qse_env_deletew (qse_env_t* env, const qse_wchar_t* name) +{ +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + return deletew (env, name); +#else + /* convert wchar to mchar */ + qse_mchar_t* namedup; + int n; + + namedup = qse_wcstombsdup (name, env->mmgr); + if (namedup == QSE_NULL) return -1; + + n = deletem (env, namedup); + + QSE_MMGR_FREE (env->mmgr, namedup); + return n; +#endif +} + +int qse_env_deletem (qse_env_t* env, const qse_mchar_t* name) +{ +#if defined(_WIN32) && defined(QSE_CHAR_IS_WCHAR) + /* convert mchar to wchar */ + qse_wchar_t* namedup; + int n; + + namedup = qse_mbstowcsdup (name, env->mmgr); + if (namedup == QSE_NULL) return -1; + + n = deletew (env, namedup); + + QSE_MMGR_FREE (env->mmgr, namedup); + return n; +#else + return deletem (env, name); +#endif +} + static int load_curenv (qse_env_t* env) { #if defined(_WIN32) @@ -235,15 +404,19 @@ static int load_curenv (qse_env_t* env) envstr = GetEnvironmentStrings (); if (envstr == QSE_NULL) return -1; - while (*envstr != QSE_T('\0')) +#if defined(QSE_CHAR_IS_WCHAR) + while (*envstr != QSE_WT('\0')) { - if (qse_env_addraw (env, envstr) <= -1) - { - ret = -1; - goto done; - } - envstr += qse_strlen(lpszVariable) + 1; + if (add_envstrw (env, envstr) <= -1) { ret = -1; goto done; } + envstr += qse_wcslen(evnstr) + 1; } +#else + while (*envstr != QSE_MT('\0')) + { + if (add_envstrm (env, envstr) <= -1) { ret = -1; goto done; } + envstr += qse_mbslen(evnstr) + 1; + } +#endif done: FreeEnvironmentStrings (envstr); @@ -259,31 +432,12 @@ done: extern char** environ; char** p = environ; -#if defined(QSE_CHAR_IS_MCHAR) while (*p) { - if (qse_env_addraw (env, *p) <= -1) return -1; + if (add_envstrm (env, *p) <= -1) return -1; p++; } -#else - while (*p) - { - int n; - qse_char_t* x; - - x = qse_mbstowcsdup (*p, env->mmgr); - if (x == QSE_NULL) return -1; - - n = add_envstr (env, x); - QSE_MMGR_FREE (env->mmgr, x); - - if (n <= -1) return -1; - - p++; - } -#endif - return 0; #endif } diff --git a/qse/lib/cmn/pio.c b/qse/lib/cmn/pio.c index eca43a9c..1c1641f3 100644 --- a/qse/lib/cmn/pio.c +++ b/qse/lib/cmn/pio.c @@ -1,5 +1,5 @@ /* - * $Id: pio.c 534 2011-08-04 15:53:43Z hyunghwan.chung $ + * $Id: pio.c 538 2011-08-09 16:08:26Z hyunghwan.chung $ * Copyright 2006-2011 Chung, Hyung-Hwan. This file is part of QSE. @@ -45,7 +45,7 @@ static qse_ssize_t pio_output (int cmd, void* arg, void* buf, qse_size_t size); qse_pio_t* qse_pio_open ( qse_mmgr_t* mmgr, qse_size_t ext, - const qse_char_t* cmd, int oflags) + const qse_char_t* cmd, qse_env_t* env, int oflags) { qse_pio_t* pio; @@ -62,7 +62,7 @@ qse_pio_t* qse_pio_open ( pio = QSE_MMGR_ALLOC (mmgr, QSE_SIZEOF(qse_pio_t) + ext); if (pio == QSE_NULL) return QSE_NULL; - if (qse_pio_init (pio, mmgr, cmd, oflags) == QSE_NULL) + if (qse_pio_init (pio, mmgr, cmd, env, oflags) == QSE_NULL) { QSE_MMGR_FREE (mmgr, pio); return QSE_NULL; @@ -78,7 +78,8 @@ void qse_pio_close (qse_pio_t* pio) } qse_pio_t* qse_pio_init ( - qse_pio_t* pio, qse_mmgr_t* mmgr, const qse_char_t* cmd, int oflags) + qse_pio_t* pio, qse_mmgr_t* mmgr, const qse_char_t* cmd, + qse_env_t* env, int oflags) { qse_pio_hnd_t handle[6] = { @@ -270,7 +271,7 @@ qse_pio_t* qse_pio_init ( #else CREATE_UNICODE_ENVIRONMENT, /* DWORD dwCreationFlags */ #endif - NULL, /* LPVOID lpEnvironment */ + (env? qse_env_getstr(env): QSE_NULL), /* LPVOID lpEnvironment */ NULL, /* LPCTSTR lpCurrentDirectory */ &startup, /* LPSTARTUPINFO lpStartupInfo */ &procinfo /* LPPROCESS_INFORMATION lpProcessInformation */ @@ -574,7 +575,6 @@ qse_pio_t* qse_pio_init ( qse_pio_hnd_t devnull; qse_mchar_t* mcmd; - extern char** environ; int fcnt = 0; #ifndef QSE_CHAR_IS_MCHAR qse_size_t n, mn, wl; @@ -763,6 +763,7 @@ qse_pio_t* qse_pio_init ( if (oflags & QSE_PIO_SHELL) { const qse_mchar_t* argv[4]; + extern char** environ; argv[0] = QSE_MT("/bin/sh"); argv[1] = QSE_MT("-c"); @@ -771,12 +772,15 @@ qse_pio_t* qse_pio_init ( QSE_EXECVE ( QSE_MT("/bin/sh"), - (qse_mchar_t*const*)argv, environ); + (qse_mchar_t*const*)argv, + (env? qse_env_getarr(env): environ) + ); } else { int i; qse_mchar_t** argv; + extern char** environ; argv = QSE_MMGR_ALLOC (pio->mmgr, (fcnt+1)*QSE_SIZEOF(argv[0])); if (argv == QSE_NULL) goto child_oops; @@ -789,7 +793,7 @@ qse_pio_t* qse_pio_init ( } argv[i] = QSE_NULL; - QSE_EXECVE (argv[0], argv, environ); + QSE_EXECVE (argv[0], argv, (env? qse_env_getarr(env): environ)); /* this won't be reached if execve succeeds */ QSE_MMGR_FREE (pio->mmgr, argv); diff --git a/qse/lib/net/httpd_task.c b/qse/lib/net/httpd_task.c index 115cd198..afae3e1c 100644 --- a/qse/lib/net/httpd_task.c +++ b/qse/lib/net/httpd_task.c @@ -675,6 +675,7 @@ struct task_cgi_t const qse_char_t* path; qse_http_version_t version; + qse_env_t* env; qse_pio_t* pio; qse_htrd_t* htrd; @@ -839,6 +840,7 @@ static void task_fini_cgi ( qse_httpd_t* httpd, qse_httpd_client_t* client, qse_httpd_task_t* task) { task_cgi_t* cgi = (task_cgi_t*)task->ctx; + if (cgi->env) qse_env_close (cgi->env); if (cgi->pio) qse_pio_close (cgi->pio); if (cgi->res) qse_mbs_close (cgi->res); if (cgi->htrd) qse_htrd_close (cgi->htrd); @@ -1090,11 +1092,7 @@ static int task_main_cgi ( cgi_htrd_xtn_t* xtn; cgi->htrd = qse_htrd_open (httpd->mmgr, QSE_SIZEOF(cgi_htrd_xtn_t)); - if (cgi->htrd == QSE_NULL) - { -qse_printf (QSE_T("internal server error....\n")); -return 0; - } + if (cgi->htrd == QSE_NULL) goto oops; xtn = (cgi_htrd_xtn_t*) qse_htrd_getxtn (cgi->htrd); xtn->cgi = cgi; qse_htrd_setrecbs (cgi->htrd, &cgi_htrd_cbs); @@ -1106,31 +1104,32 @@ return 0; ); cgi->res = qse_mbs_open (httpd->mmgr, 0, 256); - if (cgi->res == QSE_NULL) - { - /* TODO: entask internal server errror */ - qse_htrd_close (cgi->htrd); -qse_printf (QSE_T("internal server error....\n")); - return 0; - } + if (cgi->res == QSE_NULL) goto oops; + + cgi->env = qse_env_open (httpd->mmgr, 0, 0); + if (cgi->env == QSE_NULL) goto oops; + +qse_env_insertm (cgi->env, QSE_MT("QUERY_STRING"), QSE_MT("what the hell")); +qse_env_insertm (cgi->env, QSE_MT("CLIENT_IPADDR"), QSE_MT("2.3.4.5")); qse_printf (QSE_T("[pio open for %s]\n"), cgi->path); - cgi->pio = qse_pio_open (httpd->mmgr, 0, cgi->path, QSE_PIO_READOUT | QSE_PIO_WRITEIN | QSE_PIO_ERRTONUL); - if (cgi->pio == QSE_NULL) - { - /* TODO: entask internal server errror */ - qse_mbs_close (cgi->res); - qse_htrd_close (cgi->htrd); -qse_printf (QSE_T("internal server error....\n")); - return 0; - } - else - { - } - + cgi->pio = qse_pio_open ( + httpd->mmgr, 0, cgi->path, cgi->env, + QSE_PIO_READOUT | QSE_PIO_WRITEIN | QSE_PIO_ERRTONUL + ); + if (cgi->pio == QSE_NULL) goto oops; + qse_printf (QSE_T("[calling cgi_2 ]\n")); task->main = task_main_cgi_2; /* cause this function to be called subsequently */ return task_main_cgi_2 (httpd, client, task); /* let me call it here once */ + +oops: +/* TODO: internal server error */ + if (cgi->env) qse_env_close (cgi->env); + if (cgi->res) qse_mbs_close (cgi->res); + if (cgi->htrd) qse_htrd_close (cgi->htrd); +qse_printf (QSE_T("internal server error....\n")); + return 0; } qse_httpd_task_t* qse_httpd_entaskcgi ( diff --git a/qse/samples/cmn/env.c b/qse/samples/cmn/env.c index 8b4ed824..96ee2889 100644 --- a/qse/samples/cmn/env.c +++ b/qse/samples/cmn/env.c @@ -8,11 +8,56 @@ if (f() == -1) return -1; \ } while (0) +static void dump (qse_env_t* env) +{ + const qse_env_char_t* envstr; + qse_env_char_t** envarr; + + envstr = qse_env_getstr (env); + if (envstr) + { +#if (defined(QSE_ENV_CHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR)) || \ + (defined(QSE_ENV_CHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR)) + while (*envstr != QSE_T('\0')) + { + qse_printf (QSE_T("%p [%s]\n"), envstr, envstr); + envstr += qse_strlen(envstr) + 1; + } +#elif defined(QSE_ENV_CHAR_IS_WCHAR) + while (*envstr != QSE_WT('\0')) + { + qse_printf (QSE_T("%p [%S]\n"), envstr, envstr); + envstr += qse_wcslen(envstr) + 1; + } +#else + while (*envstr != QSE_MT('\0')) + { + qse_printf (QSE_T("%p [%S]\n"), envstr, envstr); + envstr += qse_mbslen(envstr) + 1; + } +#endif + } + + qse_printf (QSE_T("=====\n")); + envarr = qse_env_getarr (env); + if (envarr) + { + while (*envarr) + { +#if (defined(QSE_ENV_CHAR_IS_WCHAR) && defined(QSE_CHAR_IS_WCHAR)) || \ + (defined(QSE_ENV_CHAR_IS_MCHAR) && defined(QSE_CHAR_IS_MCHAR)) + qse_printf (QSE_T("%p [%s]\n"), *envarr, *envarr); +#else + qse_printf (QSE_T("%p [%S]\n"), *envarr, *envarr); +#endif + envarr++; + } + } +} + static int test1 (void) { qse_env_t* env; - const qse_char_t* envstr; - qse_char_t** envarr; env = qse_env_open (QSE_NULL, 0, 0); @@ -30,30 +75,10 @@ static int test1 (void) qse_env_insert (env, QSE_T("donkey"), QSE_T("mule")); qse_env_insert (env, QSE_T("lily"), QSE_T("rose")); - qse_env_delete (env, QSE_T("cool")); qse_env_insert (env, QSE_T("spider"), QSE_T("man")); - envstr = qse_env_getstr (env); - if (envstr) - { - while (*envstr != QSE_T('\0')) - { - qse_printf (QSE_T("%p [%s]\n"), envstr, envstr); - envstr += qse_strlen(envstr) + 1; - } - } - - qse_printf (QSE_T("=====\n")); - envarr = qse_env_getarr (env); - if (envarr) - { - while (*envarr) - { - qse_printf (QSE_T("%p [%s]\n"), *envarr, *envarr); - envarr++; - } - } + dump (env); qse_env_close (env); return 0; @@ -62,8 +87,6 @@ static int test1 (void) static int test2 (void) { qse_env_t* env; - const qse_char_t* envstr; - qse_char_t** envarr; env = qse_env_open (QSE_NULL, 0, 1); @@ -76,27 +99,7 @@ static int test2 (void) QSE_T("SUCCESS"): QSE_T("FAILURE")) ); - envstr = qse_env_getstr (env); - if (envstr) - { - while (*envstr != QSE_T('\0')) - { - qse_printf (QSE_T("%p [%s]\n"), envstr, envstr); - envstr += qse_strlen(envstr) + 1; - } - } - - - qse_printf (QSE_T("=====\n")); - envarr = qse_env_getarr (env); - if (envarr) - { - while (*envarr) - { - qse_printf (QSE_T("%p [%s]\n"), *envarr, *envarr); - envarr++; - } - } + dump (env); qse_env_close (env); return 0; diff --git a/qse/samples/cmn/pio.c b/qse/samples/cmn/pio.c index 4c42d77f..e4a2c989 100644 --- a/qse/samples/cmn/pio.c +++ b/qse/samples/cmn/pio.c @@ -30,6 +30,7 @@ static int pio1 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid) QSE_NULL, 0, cmd, + QSE_NULL, oflags ); if (pio == QSE_NULL) @@ -89,6 +90,7 @@ static int pio2 (const qse_char_t* cmd, int oflags, qse_pio_hid_t rhid) QSE_NULL, 0, cmd, + QSE_NULL, oflags | QSE_PIO_TEXT ); if (pio == QSE_NULL) @@ -254,6 +256,7 @@ static int test9 (void) #else QSE_T("/bin/ls -laF"), #endif + QSE_NULL, QSE_PIO_READOUT|QSE_PIO_READERR|QSE_PIO_WRITEIN ); if (pio == QSE_NULL)