added qse_httpd_getserveroptstd() and qse_httpd_setserveroptstd().
added an output length parameter to qse_mbstowcsdup() and similar functions
This commit is contained in:
parent
8f5a0a3933
commit
e2f152c927
@ -1,2 +1,2 @@
|
||||
SUBDIRS = awk sed stx
|
||||
SUBDIRS = awk sed
|
||||
DIST_SUBDIRS = $(SUBDIRS)
|
||||
|
@ -242,7 +242,7 @@ target_alias = @target_alias@
|
||||
top_build_prefix = @top_build_prefix@
|
||||
top_builddir = @top_builddir@
|
||||
top_srcdir = @top_srcdir@
|
||||
SUBDIRS = awk sed stx
|
||||
SUBDIRS = awk sed
|
||||
DIST_SUBDIRS = $(SUBDIRS)
|
||||
all: all-recursive
|
||||
|
||||
|
@ -1165,7 +1165,7 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
if (codepage == CP_UTF8)
|
||||
{
|
||||
/*SetConsoleOUtputCP (CP_UTF8);*/
|
||||
qse_setdflcmgr (qse_utf8cmgr);
|
||||
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1,4 +1,4 @@
|
||||
/**
|
||||
/*
|
||||
* $Id$
|
||||
*
|
||||
Copyright 2006-2012 Chung, Hyung-Hwan.
|
||||
@ -1022,7 +1022,7 @@ int qse_main (int argc, qse_achar_t* argv[])
|
||||
if (codepage == CP_UTF8)
|
||||
{
|
||||
/*SetConsoleOUtputCP (CP_UTF8);*/
|
||||
qse_setdflcmgr (qse_utf8cmgr);
|
||||
qse_setdflcmgrbyid (QSE_CMGR_UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -140,24 +140,28 @@ int qse_mbsntowcsnuptowithcmgr (
|
||||
|
||||
qse_wchar_t* qse_mbstowcsdupwithcmgr (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_mbstowcsalldupwithcmgr (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsdupwithcmgr (
|
||||
const qse_mchar_t* mbs[],
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsalldupwithcmgr (
|
||||
const qse_mchar_t* mbs[],
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
@ -183,24 +187,34 @@ int qse_wcsntombsnwithcmgr (
|
||||
|
||||
qse_mchar_t* qse_wcstombsdupwithcmgr (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_wcntombsdupwithcmgr (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_size_t len,
|
||||
qse_size_t wcslen,
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_wcsatombsdupwithcmgr (
|
||||
const qse_wchar_t* wcs[],
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
|
||||
qse_mchar_t* qse_wcsnatombsdupwithcmgr (
|
||||
const qse_wcstr_t wcs[],
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr,
|
||||
qse_cmgr_t* cmgr
|
||||
);
|
||||
|
||||
/* --------------------------------------------------- */
|
||||
/* STRING CONVERSION WITH DEFAULT GLOBAL CMGR */
|
||||
/* --------------------------------------------------- */
|
||||
@ -283,21 +297,25 @@ int qse_mbsntowcsnupto (
|
||||
|
||||
qse_wchar_t* qse_mbstowcsdup (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_mbstowcsalldup (
|
||||
const qse_mchar_t* mbs,
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsdup (
|
||||
const qse_mchar_t* mbs[],
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsalldup (
|
||||
const qse_mchar_t* mbs[],
|
||||
qse_size_t* wcslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
@ -373,20 +391,29 @@ int qse_wcsntombsn (
|
||||
|
||||
qse_mchar_t* qse_wcstombsdup (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_wcsntombsdup (
|
||||
const qse_wchar_t* wcs,
|
||||
qse_size_t len,
|
||||
qse_size_t wcslen,
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_wcsatombsdup (
|
||||
const qse_wchar_t* wcs[],
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
qse_mchar_t* qse_wcsnatombsdup (
|
||||
const qse_wcstr_t wcs[],
|
||||
qse_size_t* mbslen,
|
||||
qse_mmgr_t* mmgr
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -257,7 +257,7 @@ struct qse_httpd_rcb_t
|
||||
int (*handle_request) (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req);
|
||||
|
||||
int (*format_error) (
|
||||
int (*format_err) (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client,
|
||||
int code, qse_mchar_t* buf, int bufsz);
|
||||
int (*format_dir) (
|
||||
@ -363,7 +363,7 @@ enum qse_httpd_rsrc_type_t
|
||||
QSE_HTTPD_RSRC_AUTH,
|
||||
QSE_HTTPD_RSRC_CGI,
|
||||
QSE_HTTPD_RSRC_DIR,
|
||||
QSE_HTTPD_RSRC_ERROR,
|
||||
QSE_HTTPD_RSRC_ERR,
|
||||
QSE_HTTPD_RSRC_FILE,
|
||||
QSE_HTTPD_RSRC_PROXY,
|
||||
QSE_HTTPD_RSRC_RELOC,
|
||||
@ -399,7 +399,7 @@ struct qse_httpd_rsrc_t
|
||||
struct
|
||||
{
|
||||
int code;
|
||||
} error;
|
||||
} err;
|
||||
|
||||
struct
|
||||
{
|
||||
@ -489,30 +489,20 @@ struct qse_httpd_server_idxstd_t
|
||||
const qse_mchar_t* name;
|
||||
};
|
||||
|
||||
enum qse_httpd_server_xtn_cfg_idx_t
|
||||
enum qse_httpd_server_optstd_t
|
||||
{
|
||||
QSE_HTTPD_SERVER_XTN_CFG_DOCROOT = 0,
|
||||
QSE_HTTPD_SERVER_XTN_CFG_REALM,
|
||||
QSE_HTTPD_SERVER_XTN_CFG_USERNAME,
|
||||
QSE_HTTPD_SERVER_XTN_CFG_PASSWORD,
|
||||
QSE_HTTPD_SERVER_XTN_CFG_BASICAUTH,
|
||||
QSE_HTTPD_SERVER_XTN_CFG_DIRCSS, /* can't be too long due to internal buffer size */
|
||||
QSE_HTTPD_SERVER_XTN_CFG_ERRORCSS,
|
||||
QSE_HTTPD_SERVER_XTN_CFG_MAX
|
||||
};
|
||||
QSE_HTTPD_SERVER_DOCROOT = 0, /* const qse_mchar_t* */
|
||||
QSE_HTTPD_SERVER_REALM, /* const qse_mchar_t* */
|
||||
QSE_HTTPD_SERVER_AUTH, /* const qse_mchar_t* */
|
||||
QSE_HTTPD_SERVER_DIRCSS, /* const qse_mchar_t* */
|
||||
QSE_HTTPD_SERVER_ERRCSS, /* const qse_mchar_t* */
|
||||
|
||||
struct qse_httpd_server_xtn_t
|
||||
{
|
||||
qse_mchar_t* cfg[QSE_HTTPD_SERVER_XTN_CFG_MAX];
|
||||
qse_httpd_server_cbstd_t* cbstd;
|
||||
qse_httpd_server_cgistd_t* cgistd;
|
||||
qse_httpd_server_mimestd_t* mimestd;
|
||||
qse_httpd_server_idxstd_t* idxstd;
|
||||
|
||||
/* private */
|
||||
qse_httpd_server_predetach_t predetach;
|
||||
QSE_HTTPD_SERVER_CBSTD, /* qse_httpd_server_cbstd_t* */
|
||||
QSE_HTTPD_SERVER_CGISTD, /* qse_httpd_server_cgistd_t[] */
|
||||
QSE_HTTPD_SERVER_MIMESTD, /* qse_httpd_server_mimestd_t[] */
|
||||
QSE_HTTPD_SERVER_IDXSTD /* qse_httpd_server_idxstd_t[] */
|
||||
};
|
||||
typedef struct qse_httpd_server_xtn_t qse_httpd_server_xtn_t;
|
||||
typedef enum qse_httpd_server_optstd_t qse_httpd_server_optstd_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -680,7 +670,7 @@ qse_httpd_task_t* qse_httpd_entasktext (
|
||||
qse_htre_t* req
|
||||
);
|
||||
|
||||
qse_httpd_task_t* qse_httpd_entaskerror (
|
||||
qse_httpd_task_t* qse_httpd_entaskerr (
|
||||
qse_httpd_t* httpd,
|
||||
qse_httpd_client_t* client,
|
||||
qse_httpd_task_t* pred,
|
||||
@ -818,6 +808,20 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
|
||||
qse_size_t xtnsize
|
||||
);
|
||||
|
||||
int qse_httpd_getserveroptstd (
|
||||
qse_httpd_t* httpd,
|
||||
qse_httpd_server_t* server,
|
||||
qse_httpd_server_optstd_t id,
|
||||
void** value
|
||||
);
|
||||
|
||||
int qse_httpd_setserveroptstd (
|
||||
qse_httpd_t* httpd,
|
||||
qse_httpd_server_t* server,
|
||||
qse_httpd_server_optstd_t id,
|
||||
void* value
|
||||
);
|
||||
|
||||
void* qse_httpd_getserverxtnstd (
|
||||
qse_httpd_t* httpd,
|
||||
qse_httpd_server_t* server
|
||||
|
@ -253,8 +253,8 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
|
||||
*eq = QSE_MT('\0');
|
||||
|
||||
kptr = qse_mbstowcsdup (envarr[count], mmgr);
|
||||
vptr = qse_mbstowcsdup (eq + 1, mmgr);
|
||||
kptr = qse_mbstowcsdup (envarr[count], &klen, mmgr);
|
||||
vptr = qse_mbstowcsdup (eq + 1, QSE_NULL, mmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (mmgr, kptr);
|
||||
@ -266,7 +266,6 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
klen = qse_wcslen (kptr);
|
||||
*eq = QSE_MT('=');
|
||||
#else
|
||||
eq = qse_wcschr (envarr[count], QSE_WT('='));
|
||||
@ -274,8 +273,8 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
|
||||
*eq = QSE_WT('\0');
|
||||
|
||||
kptr = qse_wcstombsdup (envarr[count], mmgr);
|
||||
vptr = qse_wcstombsdup (eq + 1, mmgr);
|
||||
kptr = qse_wcstombsdup (envarr[count], &klen, mmgr);
|
||||
vptr = qse_wcstombsdup (eq + 1, QSE_NULL, mmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (mmgr, kptr);
|
||||
@ -287,7 +286,6 @@ int StdAwk::__build_environ (Run* run, void* envptr)
|
||||
return -1;
|
||||
}
|
||||
|
||||
klen = qse_mbslen (kptr);
|
||||
*eq = QSE_WT('=');
|
||||
#endif
|
||||
|
||||
@ -459,7 +457,7 @@ int StdAwk::system (Run& run, Value& ret, const Value* args, size_t nargs,
|
||||
#else
|
||||
|
||||
qse_mchar_t* mbs;
|
||||
mbs = qse_wcstombsdup (ptr, ((Awk*)run)->getMmgr());
|
||||
mbs = qse_wcstombsdup (ptr, QSE_NULL, ((Awk*)run)->getMmgr());
|
||||
if (mbs == QSE_NULL) return -1;
|
||||
int n = ret.setInt ((long_t)::system(mbs));
|
||||
QSE_MMGR_FREE (((Awk*)run)->getMmgr(), mbs);
|
||||
|
@ -155,7 +155,7 @@ qse_awk_rtx_t* qse_awk_rtx_openmpi (
|
||||
#else
|
||||
|
||||
mmgr = qse_awk_getmmgr(awk);
|
||||
tmp = qse_mbstowcsdup (buf, mmgr);
|
||||
tmp = qse_mbstowcsdup (buf, QSE_NULL, mmgr);
|
||||
if (tmp == QSE_NULL)
|
||||
{
|
||||
qse_awk_rtx_close (rtx);
|
||||
|
@ -6374,7 +6374,6 @@ static int read_record (qse_awk_rtx_t* rtx)
|
||||
{
|
||||
qse_ssize_t n;
|
||||
qse_str_t* buf;
|
||||
qse_awk_rtx_ecb_t* ecb;
|
||||
|
||||
read_again:
|
||||
if (qse_awk_rtx_clrrec (rtx, QSE_FALSE) == -1) return -1;
|
||||
|
@ -1628,8 +1628,8 @@ static int __build_environ (
|
||||
|
||||
*eq = QSE_MT('\0');
|
||||
|
||||
kptr = qse_mbstowcsdup (envarr[count], rtx->awk->mmgr);
|
||||
vptr = qse_mbstowcsdup (eq + 1, rtx->awk->mmgr);
|
||||
kptr = qse_mbstowcsdup (envarr[count], &klen, rtx->awk->mmgr);
|
||||
vptr = qse_mbstowcsdup (eq + 1, QSE_NULL, rtx->awk->mmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr);
|
||||
@ -1642,7 +1642,6 @@ static int __build_environ (
|
||||
return -1;
|
||||
}
|
||||
|
||||
klen = qse_wcslen (kptr);
|
||||
*eq = QSE_MT('=');
|
||||
#else
|
||||
eq = qse_wcschr (envarr[count], QSE_WT('='));
|
||||
@ -1650,8 +1649,8 @@ static int __build_environ (
|
||||
|
||||
*eq = QSE_WT('\0');
|
||||
|
||||
kptr = qse_wcstombsdup (envarr[count], rtx->awk->mmgr);
|
||||
vptr = qse_wcstombsdup (eq + 1, rtx->awk->mmgr);
|
||||
kptr = qse_wcstombsdup (envarr[count], &klen, rtx->awk->mmgr);
|
||||
vptr = qse_wcstombsdup (eq + 1, QSE_NULL, rtx->awk->mmgr);
|
||||
if (kptr == QSE_NULL || vptr == QSE_NULL)
|
||||
{
|
||||
if (kptr) QSE_MMGR_FREE (rtx->awk->mmgr, kptr);
|
||||
@ -1664,7 +1663,6 @@ static int __build_environ (
|
||||
return -1;
|
||||
}
|
||||
|
||||
klen = qse_mbslen (kptr);
|
||||
*eq = QSE_WT('=');
|
||||
#endif
|
||||
|
||||
@ -2083,7 +2081,7 @@ static int fnc_system (qse_awk_rtx_t* rtx, const qse_cstr_t* fnm)
|
||||
|
||||
{
|
||||
qse_mchar_t* mbs;
|
||||
mbs = qse_wcstombsdup (str, rtx->awk->mmgr);
|
||||
mbs = qse_wcstombsdup (str, QSE_NULL, rtx->awk->mmgr);
|
||||
if (mbs == QSE_NULL)
|
||||
{
|
||||
n = -1;
|
||||
|
@ -332,9 +332,9 @@ static QSE_INLINE int insert_wcs (
|
||||
qse_mchar_t* namedup, * valuedup[2];
|
||||
int n;
|
||||
|
||||
namedup = qse_wcstombsdup (name, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
namedup = qse_wcstombsdup (name, QSE_NULL, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
if (namedup == QSE_NULL) return -1;
|
||||
valuedup[0] = qse_wcsatombsdup (value, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
valuedup[0] = qse_wcsatombsdup (value, QSE_NULL, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
if (valuedup == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (env->mmgr, namedup);
|
||||
@ -357,9 +357,9 @@ static QSE_INLINE int insert_mbs (
|
||||
qse_wchar_t* namedup, * valuedup[2];
|
||||
int n;
|
||||
|
||||
namedup = qse_mbstowcsalldup (name, env->mmgr);
|
||||
namedup = qse_mbstowcsalldup (name, QSE_NULL, env->mmgr);
|
||||
if (namedup == QSE_NULL) return -1;
|
||||
valuedup[0] = qse_mbsatowcsalldup (value, env->mmgr);
|
||||
valuedup[0] = qse_mbsatowcsalldup (value, QSE_NULL, env->mmgr);
|
||||
if (valuedup[0] == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (env->mmgr, namedup);
|
||||
@ -495,7 +495,7 @@ static int insert_sys_wcs (qse_env_t* env, const qse_wchar_t* name)
|
||||
qse_mchar_t* namedup;
|
||||
int ret = -1;
|
||||
|
||||
namedup = qse_wcstombsdup (name, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
namedup = qse_wcstombsdup (name, QSE_NULL, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
if (namedup)
|
||||
{
|
||||
ret = insert_sys_mbs (env, namedup);
|
||||
@ -513,7 +513,7 @@ static int insert_sys_mbs (qse_env_t* env, const qse_mchar_t* name)
|
||||
qse_wchar_t* namedup;
|
||||
int ret = -1;
|
||||
|
||||
namedup = qse_mbstowcsdup (name, env->mmgr); /* TODO: ignroe mbwcerr */
|
||||
namedup = qse_mbstowcsdup (name, QSE_NULL, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
if (namedup)
|
||||
{
|
||||
ret = insert_sys_wcs (env, namedup);
|
||||
@ -672,7 +672,7 @@ int qse_env_deletewcs (qse_env_t* env, const qse_wchar_t* name)
|
||||
qse_mchar_t* namedup;
|
||||
int n;
|
||||
|
||||
namedup = qse_wcstombsdup (name, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
namedup = qse_wcstombsdup (name, QSE_NULL, env->mmgr); /* TODO: ignore mbwcerr */
|
||||
if (namedup == QSE_NULL) return -1;
|
||||
|
||||
n = deletem (env, namedup);
|
||||
@ -689,7 +689,7 @@ int qse_env_deletembs (qse_env_t* env, const qse_mchar_t* name)
|
||||
qse_wchar_t* namedup;
|
||||
int n;
|
||||
|
||||
namedup = qse_mbstowcsalldup (name, env->mmgr);
|
||||
namedup = qse_mbstowcsalldup (name, QSE_NULL, env->mmgr);
|
||||
if (namedup == QSE_NULL) return -1;
|
||||
|
||||
n = deletew (env, namedup);
|
||||
|
@ -451,7 +451,7 @@ int qse_fio_init (
|
||||
{
|
||||
/* the static buffer is too small.
|
||||
* dynamically allocate a buffer */
|
||||
path_mb = qse_wcstombsdup (path, mmgr);
|
||||
path_mb = qse_wcstombsdup (path, QSE_NULL, mmgr);
|
||||
if (path_mb == QSE_NULL)
|
||||
{
|
||||
fio->errnum = QSE_FIO_ENOMEM;
|
||||
@ -574,7 +574,7 @@ int qse_fio_init (
|
||||
px = qse_wcstombs (path, &wl, path_mb, &ml);
|
||||
if (px == -2)
|
||||
{
|
||||
path_mb = qse_wcstombsdup (path, mmgr);
|
||||
path_mb = qse_wcstombsdup (path, QSE_NULL, mmgr);
|
||||
if (path_mb == QSE_NULL)
|
||||
{
|
||||
fio->errnum = QSE_FIO_ENOMEM;
|
||||
@ -784,7 +784,7 @@ int qse_fio_init (
|
||||
{
|
||||
/* the static buffer is too small.
|
||||
* allocate a buffer */
|
||||
path_mb = qse_wcstombsdup (path, mmgr);
|
||||
path_mb = qse_wcstombsdup (path, QSE_NULL, mmgr);
|
||||
if (path_mb == QSE_NULL)
|
||||
{
|
||||
fio->errnum = QSE_FIO_ENOMEM;
|
||||
|
@ -106,8 +106,8 @@ int qse_fs_move (
|
||||
fop.old_path = oldpath;
|
||||
fop.new_path = newpath;
|
||||
#else
|
||||
fop.old_path = qse_wcstombsdup (oldpath, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, fs->mmgr);
|
||||
fop.old_path = qse_wcstombsdup (oldpath, QSE_NULL, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, QSE_NULL, fs->mmgr);
|
||||
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
@ -156,8 +156,8 @@ int qse_fs_move (
|
||||
fop.old_path = oldpath;
|
||||
fop.new_path = newpath;
|
||||
#else
|
||||
fop.old_path = qse_wcstombsdup (oldpath, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, fs->mmgr);
|
||||
fop.old_path = qse_wcstombsdup (oldpath, QSE_NULL, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, QSE_NULL, fs->mmgr);
|
||||
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
@ -201,8 +201,8 @@ int qse_fs_move (
|
||||
fop.old_path = oldpath;
|
||||
fop.new_path = newpath;
|
||||
#else
|
||||
fop.old_path = qse_wcstombsdup (oldpath, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, fs->mmgr);
|
||||
fop.old_path = qse_wcstombsdup (oldpath, QSE_NULL, fs->mmgr);
|
||||
fop.new_path = qse_wcstombsdup (newpath, QSE_NULL, fs->mmgr);
|
||||
if (fop.old_path == QSE_NULL || fop.old_path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
@ -272,7 +272,7 @@ int qse_fs_move (
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
fop.new_path2 = qse_stradup (arr, QSE_NULL, fs->mmgr);
|
||||
#else
|
||||
fop.new_path2 = qse_wcsatombsdup (arr, fs->mmgr);
|
||||
fop.new_path2 = qse_wcsatombsdup (arr, QSE_NULL, fs->mmgr);
|
||||
#endif
|
||||
if (fop.new_path2 == QSE_NULL)
|
||||
{
|
||||
@ -392,7 +392,7 @@ int qse_fs_delete (qse_fs_t* fs, const qse_char_t* path)
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
dop.path = path;
|
||||
#else
|
||||
dop.path = qse_wcstombsdup (path, fs->mmgr);
|
||||
dop.path = qse_wcstombsdup (path, QSE_NULL, fs->mmgr);
|
||||
if (dop.path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
@ -435,7 +435,7 @@ oops:
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
dop.path = path;
|
||||
#else
|
||||
dop.path = qse_wcstombsdup (path, fs->mmgr);
|
||||
dop.path = qse_wcstombsdup (path, QSE_NULL, fs->mmgr);
|
||||
if (dop.path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
@ -477,7 +477,7 @@ oops:
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
dop.path = path;
|
||||
#else
|
||||
dop.path = qse_wcstombsdup (path, fs->mmgr);
|
||||
dop.path = qse_wcstombsdup (path, QSE_NULL, fs->mmgr);
|
||||
if (dop.path == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
|
@ -272,7 +272,7 @@ int qse_fs_chdir (qse_fs_t* fs, const qse_char_t* name)
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
mfsname = fsname;
|
||||
#else
|
||||
mfsname = qse_wcstombsdup (fsname, fs->mmgr);
|
||||
mfsname = qse_wcstombsdup (fsname, QSE_NULL, fs->mmgr);
|
||||
if (mfsname == QSE_NULL)
|
||||
{
|
||||
fs->errnum = QSE_FS_ENOMEM;
|
||||
|
@ -43,7 +43,7 @@ int qse_runmain (
|
||||
|
||||
for (i = 0; i < argc; i++)
|
||||
{
|
||||
v[i]= qse_mbstowcsalldup (argv[i], mmgr);
|
||||
v[i]= qse_mbstowcsalldup (argv[i], QSE_NULL, mmgr);
|
||||
if (v[i] == QSE_NULL)
|
||||
{
|
||||
ret = -1;
|
||||
@ -93,7 +93,7 @@ int qse_runmainwithenv (
|
||||
else if (i == argc) continue;
|
||||
else x = envp[i - argc - 1];
|
||||
|
||||
v[i]= qse_mbstowcsalldup (x, mmgr);
|
||||
v[i]= qse_mbstowcsalldup (x, QSE_NULL, mmgr);
|
||||
if (v[i] == QSE_NULL)
|
||||
{
|
||||
ret = -1;
|
||||
|
@ -246,45 +246,47 @@ int qse_mbsntowcsnuptowithcmgr (
|
||||
}
|
||||
|
||||
static qse_wchar_t* mbs_to_wcs_dup_with_cmgr (
|
||||
const qse_mchar_t* mbs, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr, int all)
|
||||
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr, int all)
|
||||
{
|
||||
qse_size_t mbslen, wcslen;
|
||||
qse_size_t ml, wl;
|
||||
qse_wchar_t* wcs;
|
||||
|
||||
if (mbs_to_wcs_with_cmgr (
|
||||
mbs, &mbslen, QSE_NULL, &wcslen, cmgr, all) <= -1) return QSE_NULL;
|
||||
mbs, &ml, QSE_NULL, &wl, cmgr, all) <= -1) return QSE_NULL;
|
||||
|
||||
wcslen++; /* for terminating null */
|
||||
wcs = QSE_MMGR_ALLOC (mmgr, wcslen * QSE_SIZEOF(*wcs));
|
||||
wl++; /* for terminating null */
|
||||
wcs = QSE_MMGR_ALLOC (mmgr, wl * QSE_SIZEOF(*wcs));
|
||||
if (wcs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
mbs_to_wcs_with_cmgr (mbs, &mbslen, wcs, &wcslen, cmgr, all);
|
||||
mbs_to_wcs_with_cmgr (mbs, &ml, wcs, &wl, cmgr, all);
|
||||
|
||||
if (wcslen) *wcslen = wl;
|
||||
return wcs;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbstowcsdupwithcmgr (
|
||||
const qse_mchar_t* mbs, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbs_to_wcs_dup_with_cmgr (mbs, mmgr, cmgr, 0);
|
||||
return mbs_to_wcs_dup_with_cmgr (mbs, wcslen, mmgr, cmgr, 0);
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbstowcsalldupwithcmgr (
|
||||
const qse_mchar_t* mbs, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbs_to_wcs_dup_with_cmgr (mbs, mmgr, cmgr, 1);
|
||||
return mbs_to_wcs_dup_with_cmgr (mbs, wcslen, mmgr, cmgr, 1);
|
||||
}
|
||||
|
||||
static qse_wchar_t* mbsa_to_wcs_dup_with_cmgr (
|
||||
const qse_mchar_t* mbs[], qse_mmgr_t* mmgr, qse_cmgr_t* cmgr, int all)
|
||||
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr, int all)
|
||||
{
|
||||
qse_wchar_t* buf, * ptr;
|
||||
qse_wchar_t* buf;
|
||||
qse_size_t i;
|
||||
qse_size_t capa = 0;
|
||||
qse_size_t capa, pos;
|
||||
qse_size_t wl, ml;
|
||||
|
||||
QSE_ASSERT (mmgr != QSE_NULL);
|
||||
|
||||
for (i = 0; mbs[i]; i++)
|
||||
for (capa = 0, i = 0; mbs[i]; i++)
|
||||
{
|
||||
if (mbs_to_wcs_with_cmgr (mbs[i], &ml, QSE_NULL, &wl, cmgr, all) <= -1)
|
||||
return QSE_NULL;
|
||||
@ -295,28 +297,29 @@ static qse_wchar_t* mbsa_to_wcs_dup_with_cmgr (
|
||||
mmgr, (capa + 1) * QSE_SIZEOF(*buf));
|
||||
if (buf == QSE_NULL) return QSE_NULL;
|
||||
|
||||
ptr = buf;
|
||||
for (i = 0; mbs[i]; i++)
|
||||
for (pos = 0, i = 0; mbs[i]; i++)
|
||||
{
|
||||
wl = capa + 1;
|
||||
mbs_to_wcs_with_cmgr (mbs[i], &ml, ptr, &wl, cmgr, all);
|
||||
ptr += wl;
|
||||
capa -= wl;
|
||||
wl = capa - pos + 1;
|
||||
mbs_to_wcs_with_cmgr (mbs[i], &ml, &buf[pos], &wl, cmgr, all);
|
||||
pos += wl;
|
||||
}
|
||||
|
||||
QSE_ASSERT (pos == capa);
|
||||
|
||||
if (wcslen) *wcslen = capa;
|
||||
return buf;
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsdupwithcmgr (
|
||||
const qse_mchar_t* mbs[], qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbsa_to_wcs_dup_with_cmgr (mbs, mmgr, cmgr, 0);
|
||||
return mbsa_to_wcs_dup_with_cmgr (mbs, wcslen, mmgr, cmgr, 0);
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsalldupwithcmgr (
|
||||
const qse_mchar_t* mbs[], qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
return mbsa_to_wcs_dup_with_cmgr (mbs, mmgr, cmgr, 1);
|
||||
return mbsa_to_wcs_dup_with_cmgr (mbs, wcslen, mmgr, cmgr, 1);
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
@ -473,64 +476,99 @@ int qse_wcsntombsnwithcmgr (
|
||||
return ret;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcstombsdupwithcmgr (const qse_wchar_t* wcs, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
qse_mchar_t* qse_wcstombsdupwithcmgr (
|
||||
const qse_wchar_t* wcs, qse_size_t* mbslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_size_t wcslen, mbslen;
|
||||
qse_mchar_t* mbs;
|
||||
|
||||
if (qse_wcstombswithcmgr (wcs, &wcslen, QSE_NULL, &mbslen, cmgr) <= -1) return QSE_NULL;
|
||||
|
||||
mbslen++; /* for the terminating null character */
|
||||
|
||||
mbs = QSE_MMGR_ALLOC (mmgr, mbslen * QSE_SIZEOF(*mbs));
|
||||
if (mbs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
qse_wcstombswithcmgr (wcs, &wcslen, mbs, &mbslen, cmgr);
|
||||
return mbs;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsntombsdupwithcmgr (const qse_wchar_t* wcs, qse_size_t len, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_size_t mbslen;
|
||||
qse_mchar_t* mbs;
|
||||
|
||||
if (qse_wcsntombsnwithcmgr (wcs, &len, QSE_NULL, &mbslen, cmgr) <= -1) return QSE_NULL;
|
||||
|
||||
mbs = QSE_MMGR_ALLOC (mmgr, (mbslen + 1) * QSE_SIZEOF(*mbs));
|
||||
if (mbs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
qse_wcsntombsnwithcmgr (wcs, &len, mbs, &mbslen, cmgr);
|
||||
mbs[mbslen] = QSE_MT('\0');
|
||||
return mbs;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsatombsdupwithcmgr (const qse_wchar_t* wcs[], qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_mchar_t* buf, * ptr;
|
||||
qse_size_t i;
|
||||
qse_size_t wl, ml;
|
||||
qse_size_t capa = 0;
|
||||
qse_mchar_t* mbs;
|
||||
|
||||
if (qse_wcstombswithcmgr (wcs, &wl, QSE_NULL, &ml, cmgr) <= -1) return QSE_NULL;
|
||||
|
||||
ml++; /* for the terminating null character */
|
||||
|
||||
mbs = QSE_MMGR_ALLOC (mmgr, ml * QSE_SIZEOF(*mbs));
|
||||
if (mbs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
qse_wcstombswithcmgr (wcs, &wl, mbs, &ml, cmgr);
|
||||
|
||||
if (mbslen) *mbslen = ml;
|
||||
return mbs;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsntombsdupwithcmgr (
|
||||
const qse_wchar_t* wcs, qse_size_t wcslen,
|
||||
qse_size_t* mbslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_size_t ml;
|
||||
qse_mchar_t* mbs;
|
||||
|
||||
if (qse_wcsntombsnwithcmgr (wcs, &wcslen, QSE_NULL, &ml, cmgr) <= -1) return QSE_NULL;
|
||||
|
||||
mbs = QSE_MMGR_ALLOC (mmgr, (ml + 1) * QSE_SIZEOF(*mbs));
|
||||
if (mbs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
qse_wcsntombsnwithcmgr (wcs, &wcslen, mbs, &ml, cmgr);
|
||||
mbs[ml] = QSE_MT('\0');
|
||||
|
||||
if (mbslen) *mbslen = ml;
|
||||
return mbs;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsatombsdupwithcmgr (
|
||||
const qse_wchar_t* wcs[], qse_size_t* mbslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_size_t wl, ml, capa, pos, i;
|
||||
qse_mchar_t* mbs;
|
||||
|
||||
QSE_ASSERT (mmgr != QSE_NULL);
|
||||
|
||||
for (i = 0; wcs[i]; i++)
|
||||
for (capa = 0, i = 0; wcs[i]; i++)
|
||||
{
|
||||
if (qse_wcstombswithcmgr (wcs[i], &wl, QSE_NULL, &ml, cmgr) <= -1) return QSE_NULL;
|
||||
capa += ml;
|
||||
}
|
||||
|
||||
buf = (qse_mchar_t*) QSE_MMGR_ALLOC (
|
||||
mmgr, (capa + 1) * QSE_SIZEOF(*buf));
|
||||
if (buf == QSE_NULL) return QSE_NULL;
|
||||
mbs = (qse_mchar_t*) QSE_MMGR_ALLOC (mmgr, (capa + 1) * QSE_SIZEOF(*mbs));
|
||||
if (mbs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
ptr = buf;
|
||||
for (i = 0; wcs[i]; i++)
|
||||
for (pos = 0, i = 0; wcs[i]; i++)
|
||||
{
|
||||
ml = capa + 1;
|
||||
qse_wcstombswithcmgr (wcs[i], &wl, ptr, &ml, cmgr);
|
||||
ptr += ml;
|
||||
capa -= ml;
|
||||
ml = capa - pos + 1;
|
||||
qse_wcstombswithcmgr (wcs[i], &wl, &mbs[pos], &ml, cmgr);
|
||||
pos += ml;
|
||||
}
|
||||
|
||||
return buf;
|
||||
if (mbslen) *mbslen = capa;
|
||||
return mbs;
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsnatombsdupwithcmgr (
|
||||
const qse_wcstr_t wcs[], qse_size_t* mbslen, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
|
||||
{
|
||||
qse_size_t wl, ml, capa, pos, i;
|
||||
qse_mchar_t* mbs;
|
||||
|
||||
for (capa = 0, i = 0; wcs[i].ptr; i++)
|
||||
{
|
||||
wl = wcs[i].len;
|
||||
if (qse_wcsntombsnwithcmgr (wcs[i].ptr, &wl, QSE_NULL, &ml, cmgr) <= -1) return QSE_NULL;
|
||||
capa += ml;
|
||||
}
|
||||
|
||||
mbs = QSE_MMGR_ALLOC (mmgr, (capa + 1) * QSE_SIZEOF(*mbs));
|
||||
if (mbs == QSE_NULL) return QSE_NULL;
|
||||
|
||||
for (pos = 0, i = 0; wcs[i].ptr; i++)
|
||||
{
|
||||
wl = wcs[i].len;
|
||||
ml = capa - pos + 1;
|
||||
qse_wcsntombsnwithcmgr (wcs[i].ptr, &wl, &mbs[pos], &ml, cmgr);
|
||||
pos += ml;
|
||||
}
|
||||
mbs[pos] = QSE_MT('\0');
|
||||
|
||||
QSE_ASSERT (pos == capa);
|
||||
|
||||
if (mbslen) *mbslen = capa;
|
||||
return mbs;
|
||||
}
|
||||
|
@ -171,24 +171,28 @@ int qse_mbsntowcsnupto (
|
||||
mbs, mbslen, wcs, wcslen, stopper, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbstowcsdup (const qse_mchar_t* mbs, qse_mmgr_t* mmgr)
|
||||
qse_wchar_t* qse_mbstowcsdup (
|
||||
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_mbstowcsdupwithcmgr (mbs, mmgr, dfl_cmgr);
|
||||
return qse_mbstowcsdupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbstowcsalldup (const qse_mchar_t* mbs, qse_mmgr_t* mmgr)
|
||||
qse_wchar_t* qse_mbstowcsalldup (
|
||||
const qse_mchar_t* mbs, qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_mbstowcsalldupwithcmgr (mbs, mmgr, dfl_cmgr);
|
||||
return qse_mbstowcsalldupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsdup (const qse_mchar_t* mbs[], qse_mmgr_t* mmgr)
|
||||
qse_wchar_t* qse_mbsatowcsdup (
|
||||
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_mbsatowcsdupwithcmgr (mbs, mmgr, dfl_cmgr);
|
||||
return qse_mbsatowcsdupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_wchar_t* qse_mbsatowcsalldup (const qse_mchar_t* mbs[], qse_mmgr_t* mmgr)
|
||||
qse_wchar_t* qse_mbsatowcsalldup (
|
||||
const qse_mchar_t* mbs[], qse_size_t* wcslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_mbsatowcsalldupwithcmgr (mbs, mmgr, dfl_cmgr);
|
||||
return qse_mbsatowcsalldupwithcmgr (mbs, wcslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------- */
|
||||
@ -207,18 +211,27 @@ int qse_wcsntombsn (
|
||||
return qse_wcsntombsnwithcmgr (wcs, wcslen, mbs, mbslen, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcstombsdup (const qse_wchar_t* wcs, qse_mmgr_t* mmgr)
|
||||
qse_mchar_t* qse_wcstombsdup (
|
||||
const qse_wchar_t* wcs, qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_wcstombsdupwithcmgr (wcs, mmgr, dfl_cmgr);
|
||||
return qse_wcstombsdupwithcmgr (wcs, mbslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsntombsdup (const qse_wchar_t* wcs, qse_size_t len, qse_mmgr_t* mmgr)
|
||||
qse_mchar_t* qse_wcsntombsdup (
|
||||
const qse_wchar_t* wcs, qse_size_t wcslen,
|
||||
qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_wcsntombsdupwithcmgr (wcs, len, mmgr, dfl_cmgr);
|
||||
return qse_wcsntombsdupwithcmgr (wcs, wcslen, mbslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsatombsdup (const qse_wchar_t* wcs[], qse_mmgr_t* mmgr)
|
||||
qse_mchar_t* qse_wcsatombsdup (
|
||||
const qse_wchar_t* wcs[], qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_wcsatombsdupwithcmgr (wcs, mmgr, dfl_cmgr);
|
||||
return qse_wcsatombsdupwithcmgr (wcs, mbslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
||||
qse_mchar_t* qse_wcsnatombsdup (
|
||||
const qse_wcstr_t wcs[], qse_size_t* mbslen, qse_mmgr_t* mmgr)
|
||||
{
|
||||
return qse_wcsnatombsdupwithcmgr (wcs, mbslen, mmgr, dfl_cmgr);
|
||||
}
|
||||
|
@ -756,7 +756,7 @@ create_process:
|
||||
x[0] = mcmdname[create_retried];
|
||||
x[1] = (const qse_mchar_t*)cmd;
|
||||
x[2] = QSE_NULL;
|
||||
dupcmd = qse_mbsatowcsdup (x, mmgr);
|
||||
dupcmd = qse_mbsatowcsdup (x, QSE_NULL, mmgr);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -771,7 +771,7 @@ create_process:
|
||||
#if defined(QSE_CHAR_IS_WCHAR)
|
||||
if (flags & QSE_PIO_MBSCMD)
|
||||
{
|
||||
dupcmd = qse_mbstowcsdup ((const qse_mchar_t*)cmd, mmgr);
|
||||
dupcmd = qse_mbstowcsdup ((const qse_mchar_t*)cmd, QSE_NULL, mmgr);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -389,8 +389,8 @@ QSE_FILE* qse_fopen (const qse_char_t* path, const qse_char_t* mode)
|
||||
qse_mchar_t* path_mb;
|
||||
qse_mchar_t* mode_mb;
|
||||
|
||||
path_mb = qse_wcstombsdup (path, QSE_MMGR_GETDFL());
|
||||
mode_mb = qse_wcstombsdup (mode, QSE_MMGR_GETDFL());
|
||||
path_mb = qse_wcstombsdup (path, QSE_NULL, QSE_MMGR_GETDFL());
|
||||
mode_mb = qse_wcstombsdup (mode, QSE_NULL, QSE_MMGR_GETDFL());
|
||||
|
||||
if (path_mb && mode_mb)
|
||||
{
|
||||
@ -428,7 +428,7 @@ QSE_FILE* qse_popen (const qse_char_t* cmd, const qse_char_t* mode)
|
||||
QSE_FILE* fp = QSE_NULL;
|
||||
qse_mchar_t* cmd_mb;
|
||||
|
||||
cmd_mb = qse_wcstombsdup (cmd, QSE_MMGR_GETDFL());
|
||||
cmd_mb = qse_wcstombsdup (cmd, QSE_NULL, QSE_MMGR_GETDFL());
|
||||
if (cmd_mb)
|
||||
{
|
||||
char mode_mb[3];
|
||||
|
@ -1320,7 +1320,7 @@ qse_printf (QSE_T("TRAILING DATA=[%.*hs]\n"), (int)QSE_MBS_LEN(cgi->res), QSE_MB
|
||||
return 1;
|
||||
|
||||
oops:
|
||||
return (qse_httpd_entask_error (httpd, client, task, 500, &cgi->version, cgi->keepalive) == QSE_NULL)? -1: 0;
|
||||
return (qse_httpd_entask_err (httpd, client, task, 500, &cgi->version, cgi->keepalive) == QSE_NULL)? -1: 0;
|
||||
}
|
||||
|
||||
static int task_main_cgi (
|
||||
@ -1450,7 +1450,7 @@ oops:
|
||||
cgi->script_htrd = QSE_NULL;
|
||||
}
|
||||
|
||||
return (qse_httpd_entask_error (
|
||||
return (qse_httpd_entask_err (
|
||||
httpd, client, task, http_errnum,
|
||||
&cgi->version, cgi->keepalive) == QSE_NULL)? -1: 0;
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ static QSE_INLINE int task_main_dir (
|
||||
int http_errnum;
|
||||
http_errnum = (httpd->errnum == QSE_HTTPD_ENOENT)? 404:
|
||||
(httpd->errnum == QSE_HTTPD_EACCES)? 403: 500;
|
||||
x = qse_httpd_entask_error (
|
||||
x = qse_httpd_entask_err (
|
||||
httpd, client, x, http_errnum,
|
||||
&dir->version, dir->keepalive);
|
||||
|
||||
|
@ -175,7 +175,7 @@ static QSE_INLINE int task_main_file (
|
||||
int http_errnum;
|
||||
http_errnum = (httpd->errnum == QSE_HTTPD_ENOENT)? 404:
|
||||
(httpd->errnum == QSE_HTTPD_EACCES)? 403: 500;
|
||||
x = qse_httpd_entask_error (
|
||||
x = qse_httpd_entask_err (
|
||||
httpd, client, x, http_errnum,
|
||||
&file->version, file->keepalive);
|
||||
goto no_file_send;
|
||||
@ -187,7 +187,7 @@ static QSE_INLINE int task_main_file (
|
||||
int http_errnum;
|
||||
http_errnum = (httpd->errnum == QSE_HTTPD_ENOENT)? 404:
|
||||
(httpd->errnum == QSE_HTTPD_EACCES)? 403: 500;
|
||||
x = qse_httpd_entask_error (
|
||||
x = qse_httpd_entask_err (
|
||||
httpd, client, x, http_errnum,
|
||||
&file->version, file->keepalive);
|
||||
goto no_file_send;
|
||||
@ -210,7 +210,7 @@ static QSE_INLINE int task_main_file (
|
||||
|
||||
if (file->range.from >= st.size)
|
||||
{
|
||||
x = qse_httpd_entask_error (
|
||||
x = qse_httpd_entask_err (
|
||||
httpd, client, x, 416, &file->version, file->keepalive);
|
||||
goto no_file_send;
|
||||
}
|
||||
@ -337,7 +337,7 @@ qse_httpd_task_t* qse_httpd_entaskfile (
|
||||
while (tmp->next) tmp = tmp->next; /* get the last value */
|
||||
if (qse_parsehttprange (tmp->ptr, &data.range) <= -1)
|
||||
{
|
||||
return qse_httpd_entaskerror (httpd, client, pred, 416, req);
|
||||
return qse_httpd_entaskerr (httpd, client, pred, 416, req);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1294,7 +1294,7 @@ qse_printf (QSE_T("TRAILING DATA=%d, [%hs]\n"), (int)QSE_MBS_LEN(proxy->res), QS
|
||||
|
||||
oops:
|
||||
if (proxy->resflags & PROXY_RES_EVER_SENTBACK) return -1;
|
||||
return (qse_httpd_entask_error (httpd, client, task, http_errnum, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0;
|
||||
return (qse_httpd_entask_err (httpd, client, task, http_errnum, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0;
|
||||
}
|
||||
|
||||
static int task_main_proxy_1 (
|
||||
@ -1352,7 +1352,7 @@ qse_printf (QSE_T("FINALLY connected to peer ...............................\n")
|
||||
return 1;
|
||||
|
||||
oops:
|
||||
return (qse_httpd_entask_error (httpd, client, task, http_errnum, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0;
|
||||
return (qse_httpd_entask_err (httpd, client, task, http_errnum, &proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0;
|
||||
}
|
||||
|
||||
static int task_main_proxy (
|
||||
@ -1438,7 +1438,7 @@ oops:
|
||||
proxy->peer_htrd = QSE_NULL;
|
||||
}
|
||||
|
||||
return (qse_httpd_entask_error (
|
||||
return (qse_httpd_entask_err (
|
||||
httpd, client, task, http_errnum,
|
||||
&proxy->version, proxy->keepalive) == QSE_NULL)? -1: 0;
|
||||
}
|
||||
|
@ -70,13 +70,37 @@
|
||||
#define DEFAULT_PORT 80
|
||||
#define DEFAULT_SECURE_PORT 443
|
||||
|
||||
#define server_xtn_t qse_httpd_server_xtn_t
|
||||
#define SERVER_XTN_CFG_DOCROOT QSE_HTTPD_SERVER_XTN_CFG_DOCROOT
|
||||
#define SERVER_XTN_CFG_REALM QSE_HTTPD_SERVER_XTN_CFG_REALM
|
||||
#define SERVER_XTN_CFG_USERNAME QSE_HTTPD_SERVER_XTN_CFG_USERNAME
|
||||
#define SERVER_XTN_CFG_PASSWORD QSE_HTTPD_SERVER_XTN_CFG_PASSWORD
|
||||
#define SERVER_XTN_CFG_BASICAUTH QSE_HTTPD_SERVER_XTN_CFG_BASICAUTH
|
||||
#define SERVER_XTN_CFG_DIRCSS QSE_HTTPD_SERVER_XTN_CFG_DIRCSS
|
||||
enum server_xtn_cfg_id_t
|
||||
{
|
||||
SERVER_XTN_CFG_DOCROOT = 0,
|
||||
SERVER_XTN_CFG_REALM,
|
||||
SERVER_XTN_CFG_AUTH, /* basic auth */
|
||||
SERVER_XTN_CFG_DIRCSS, /* can't be too long due to internal buffer size */
|
||||
SERVER_XTN_CFG_ERRCSS,
|
||||
SERVER_XTN_CFG_MAX
|
||||
};
|
||||
|
||||
typedef struct server_xtn_t server_xtn_t;
|
||||
struct server_xtn_t
|
||||
{
|
||||
qse_mchar_t* cfg[SERVER_XTN_CFG_MAX];
|
||||
|
||||
union
|
||||
{
|
||||
void* a[4];
|
||||
struct
|
||||
{
|
||||
qse_httpd_server_cbstd_t* cbstd;
|
||||
qse_httpd_server_cgistd_t* cgistd;
|
||||
qse_httpd_server_mimestd_t* mimestd;
|
||||
qse_httpd_server_idxstd_t* idxstd;
|
||||
} s;
|
||||
} cfg2;
|
||||
|
||||
/* private */
|
||||
qse_httpd_server_predetach_t predetach;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------- */
|
||||
|
||||
#if defined(_WIN32)
|
||||
@ -371,11 +395,9 @@ static void fini_xtn_ssl (httpd_xtn_t* xtn)
|
||||
|
||||
static void cleanup_standard_httpd (qse_httpd_t* httpd)
|
||||
{
|
||||
httpd_xtn_t* xtn;
|
||||
|
||||
xtn = (httpd_xtn_t*)qse_httpd_getxtn (httpd);
|
||||
|
||||
#if defined(HAVE_SSL)
|
||||
httpd_xtn_t* xtn;
|
||||
xtn = (httpd_xtn_t*)qse_httpd_getxtn (httpd);
|
||||
if (xtn->ssl_ctx) fini_xtn_ssl (xtn);
|
||||
#endif
|
||||
}
|
||||
@ -1356,14 +1378,15 @@ static qse_ssize_t client_sendfile (
|
||||
|
||||
static int client_accepted (qse_httpd_t* httpd, qse_httpd_client_t* client)
|
||||
{
|
||||
httpd_xtn_t* xtn = (httpd_xtn_t*) qse_httpd_getxtn (httpd);
|
||||
|
||||
if (client->status & CLIENT_SECURE)
|
||||
{
|
||||
#if defined(HAVE_SSL)
|
||||
int ret;
|
||||
SSL* ssl;
|
||||
httpd_xtn_t* xtn;
|
||||
|
||||
xtn = (httpd_xtn_t*) qse_httpd_getxtn (httpd);
|
||||
if (!xtn->ssl_ctx)
|
||||
{
|
||||
/* delayed initialization of ssl */
|
||||
@ -1525,22 +1548,22 @@ if (qse_htre_getcontentlen(req) > 0)
|
||||
{
|
||||
req->attr.flags &= ~QSE_HTRE_ATTR_KEEPALIVE;
|
||||
qse_httpd_discardcontent (httpd, req);
|
||||
task = qse_httpd_entaskerror (httpd, client, QSE_NULL, 411, req);
|
||||
task = qse_httpd_entaskerr (httpd, client, QSE_NULL, 411, req);
|
||||
if (task)
|
||||
{
|
||||
/* 411 Length Required - can't keep alive. Force disconnect */
|
||||
task = qse_httpd_entaskdisconnect (httpd, client, QSE_NULL);
|
||||
}
|
||||
}
|
||||
else if (server_xtn->cbstd->makersrc (httpd, client, req, &rsrc) <= -1)
|
||||
else if (server_xtn->cfg2.s.cbstd->makersrc (httpd, client, req, &rsrc) <= -1)
|
||||
{
|
||||
qse_httpd_discardcontent (httpd, req);
|
||||
task = qse_httpd_entaskerror (httpd, client, QSE_NULL, 500, req);
|
||||
task = qse_httpd_entaskerr (httpd, client, QSE_NULL, 500, req);
|
||||
}
|
||||
else
|
||||
{
|
||||
task = qse_httpd_entaskrsrc (httpd, client, QSE_NULL, &rsrc, req);
|
||||
if (server_xtn->cbstd->freersrc) server_xtn->cbstd->freersrc (httpd, client, req, &rsrc);
|
||||
if (server_xtn->cfg2.s.cbstd->freersrc) server_xtn->cfg2.s.cbstd->freersrc (httpd, client, req, &rsrc);
|
||||
}
|
||||
if (task == QSE_NULL) goto oops;
|
||||
}
|
||||
@ -1553,7 +1576,7 @@ if (qse_htre_getcontentlen(req) > 0)
|
||||
}
|
||||
else
|
||||
{
|
||||
task = qse_httpd_entaskerror (httpd, client, QSE_NULL, 405, req);
|
||||
task = qse_httpd_entaskerr (httpd, client, QSE_NULL, 405, req);
|
||||
if (task == QSE_NULL) goto oops;
|
||||
}
|
||||
}
|
||||
@ -1586,7 +1609,7 @@ static int handle_request (
|
||||
return process_request (httpd, client, req, 0);
|
||||
}
|
||||
|
||||
static int format_error (
|
||||
static int format_err (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client, int code, qse_mchar_t* buf, int bufsz)
|
||||
{
|
||||
int n;
|
||||
@ -1595,7 +1618,7 @@ static int format_error (
|
||||
|
||||
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
|
||||
|
||||
css = server_xtn->cfg[QSE_HTTPD_SERVER_XTN_CFG_ERRORCSS];
|
||||
css = server_xtn->cfg[SERVER_XTN_CFG_ERRCSS];
|
||||
if (!css) css = QSE_MT("");
|
||||
|
||||
msg = qse_httpstatustombs(code);
|
||||
@ -1633,7 +1656,7 @@ static int format_dir (
|
||||
const qse_mchar_t* css;
|
||||
int is_root = (qse_mbscmp (qpath, QSE_MT("/")) == 0);
|
||||
|
||||
css = server_xtn->cfg[QSE_HTTPD_SERVER_XTN_CFG_DIRCSS];
|
||||
css = server_xtn->cfg[SERVER_XTN_CFG_DIRCSS];
|
||||
if (!css) css = QSE_MT("");
|
||||
|
||||
/* TODO: html escaping of qpath */
|
||||
@ -1760,7 +1783,7 @@ static qse_httpd_rcb_t httpd_request_callbacks =
|
||||
{
|
||||
peek_request,
|
||||
handle_request,
|
||||
format_error,
|
||||
format_err,
|
||||
format_dir
|
||||
};
|
||||
|
||||
@ -1920,7 +1943,7 @@ static int make_resource (
|
||||
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
|
||||
|
||||
if (server_xtn->cfg[SERVER_XTN_CFG_REALM] &&
|
||||
server_xtn->cfg[SERVER_XTN_CFG_BASICAUTH])
|
||||
server_xtn->cfg[SERVER_XTN_CFG_AUTH])
|
||||
{
|
||||
const qse_htre_hdrval_t* auth;
|
||||
|
||||
@ -1931,7 +1954,7 @@ static int make_resource (
|
||||
|
||||
if (qse_mbszcasecmp(auth->ptr, QSE_MT("Basic "), 6) == 0)
|
||||
{
|
||||
if (qse_mbscmp (&auth->ptr[6], server_xtn->cfg[SERVER_XTN_CFG_BASICAUTH]) == 0) goto auth_ok;
|
||||
if (qse_mbscmp (&auth->ptr[6], server_xtn->cfg[SERVER_XTN_CFG_AUTH]) == 0) goto auth_ok;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1948,14 +1971,14 @@ auth_ok:
|
||||
if (QSE_STAT (xpath, &st) == 0 && S_ISDIR(st.st_mode))
|
||||
{
|
||||
/* it is a directory */
|
||||
if (server_xtn->idxstd)
|
||||
if (server_xtn->cfg2.s.idxstd)
|
||||
{
|
||||
/* try to locate an index file */
|
||||
for (i = 0; server_xtn->idxstd[i].name; i++)
|
||||
for (i = 0; server_xtn->cfg2.s.idxstd[i].name; i++)
|
||||
{
|
||||
qse_mchar_t* tpath;
|
||||
|
||||
tpath = merge_paths (httpd, xpath, server_xtn->idxstd[i].name);
|
||||
tpath = merge_paths (httpd, xpath, server_xtn->cfg2.s.idxstd[i].name);
|
||||
if (tpath == QSE_NULL)
|
||||
{
|
||||
QSE_MMGR_FREE (httpd->mmgr, xpath);
|
||||
@ -1967,7 +1990,7 @@ auth_ok:
|
||||
/* the index file is found */
|
||||
QSE_MMGR_FREE (httpd->mmgr, xpath);
|
||||
xpath = tpath;
|
||||
idxfile = server_xtn->idxstd[i].name;
|
||||
idxfile = server_xtn->cfg2.s.idxstd[i].name;
|
||||
goto attempt_file;
|
||||
}
|
||||
|
||||
@ -1981,11 +2004,11 @@ auth_ok:
|
||||
else
|
||||
{
|
||||
attempt_file:
|
||||
if (server_xtn->cgistd)
|
||||
if (server_xtn->cfg2.s.cgistd)
|
||||
{
|
||||
/* check if the request can resolve to a cgi script */
|
||||
n = attempt_cgi (httpd, server_xtn->cfg[SERVER_XTN_CFG_DOCROOT],
|
||||
xpath, qpath, idxfile, server_xtn->cgistd, target);
|
||||
xpath, qpath, idxfile, server_xtn->cfg2.s.cgistd, target);
|
||||
if (n <= -1)
|
||||
{
|
||||
QSE_MMGR_FREE (httpd->mmgr, xpath);
|
||||
@ -1998,13 +2021,13 @@ auth_ok:
|
||||
target->type = QSE_HTTPD_RSRC_FILE;
|
||||
target->u.file.path = xpath;
|
||||
target->u.file.mime = QSE_NULL;
|
||||
if (server_xtn->mimestd)
|
||||
if (server_xtn->cfg2.s.mimestd)
|
||||
{
|
||||
for (i = 0; server_xtn->mimestd[i].ext; i++)
|
||||
for (i = 0; server_xtn->cfg2.s.mimestd[i].ext; i++)
|
||||
{
|
||||
/* TODO: require the table sorted and so the binary search */
|
||||
if (qse_mbsend (qpath, server_xtn->mimestd[i].ext))
|
||||
target->u.file.mime = server_xtn->mimestd[i].type;
|
||||
if (qse_mbsend (qpath, server_xtn->cfg2.s.mimestd[i].ext))
|
||||
target->u.file.mime = server_xtn->cfg2.s.mimestd[i].type;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2045,7 +2068,6 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
|
||||
qse_httpd_server_t server;
|
||||
qse_httpd_server_t* xserver;
|
||||
server_xtn_t* server_xtn;
|
||||
const qse_mchar_t* tmp[4];
|
||||
qse_mxstr_t ba;
|
||||
qse_size_t balen2;
|
||||
|
||||
@ -2079,6 +2101,24 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
|
||||
{ QSE_NULL, QSE_NULL }
|
||||
};
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
qse_mcstr_t tmp[4] =
|
||||
{
|
||||
{ QSE_MT(""), 0 },
|
||||
{ QSE_MT(":"), 1 },
|
||||
{ QSE_MT(""), 0 },
|
||||
{ QSE_NULL, 0 }
|
||||
};
|
||||
#else
|
||||
qse_wcstr_t tmp[4] =
|
||||
{
|
||||
{ QSE_WT(""), 0 },
|
||||
{ QSE_WT(":"), 1 },
|
||||
{ QSE_WT(""), 0 },
|
||||
{ QSE_NULL, 0 }
|
||||
};
|
||||
#endif
|
||||
|
||||
QSE_MEMSET (&server, 0, QSE_SIZEOF(server));
|
||||
|
||||
if (qse_strtouri (uri, &xuri, QSE_STRTOURI_NOQUERY) <= -1) goto invalid;
|
||||
@ -2126,37 +2166,40 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
|
||||
xuri.path.len = 1;
|
||||
}
|
||||
|
||||
if (xuri.auth.user.ptr)
|
||||
{
|
||||
tmp[0].ptr = xuri.auth.user.ptr;
|
||||
tmp[0].len = xuri.auth.user.len;
|
||||
}
|
||||
if (xuri.auth.pass.ptr)
|
||||
{
|
||||
tmp[2].ptr = xuri.auth.pass.ptr;
|
||||
tmp[2].len = xuri.auth.pass.len;
|
||||
}
|
||||
|
||||
#if defined(QSE_CHAR_IS_MCHAR)
|
||||
server_xtn->cfg[SERVER_XTN_CFG_DOCROOT] = qse_mbsxdup (xuri.path.ptr, xuri.path.len, httpd->mmgr);
|
||||
if (xuri.path.ptr) server_xtn->cfg[SERVER_XTN_CFG_DOCROOT] = qse_mbsxdup (xuri.path.ptr, xuri.path.len, httpd->mmgr);
|
||||
if (xuri.auth.user.ptr) server_xtn->cfg[SERVER_XTN_CFG_USERNAME] = qse_mbsxdup (xuri.auth.user.ptr, xuri.auth.user.len, httpd->mmgr);
|
||||
if (xuri.auth.pass.ptr) server_xtn->cfg[SERVER_XTN_CFG_PASSWORD] = qse_mbsxdup (xuri.auth.pass.ptr, xuri.auth.pass.len, httpd->mmgr);
|
||||
if (xuri.frag.ptr) server_xtn->cfg[SERVER_XTN_CFG_REALM] = qse_mbsxdup (xuri.frag.ptr, xuri.frag.len, httpd->mmgr);
|
||||
|
||||
ba.ptr = qse_mbsxadup (tmp, &ba.len, httpd->mmgr);
|
||||
|
||||
#else
|
||||
server_xtn->cfg[SERVER_XTN_CFG_DOCROOT] = qse_wcsntombsdup (xuri.path.ptr, xuri.path.len, httpd->mmgr);
|
||||
if (xuri.auth.user.ptr) server_xtn->cfg[SERVER_XTN_CFG_USERNAME] = qse_wcsntombsdup (xuri.auth.user.ptr, xuri.auth.user.len, httpd->mmgr);
|
||||
if (xuri.auth.pass.ptr) server_xtn->cfg[SERVER_XTN_CFG_PASSWORD] = qse_wcsntombsdup (xuri.auth.pass.ptr, xuri.auth.pass.len, httpd->mmgr);
|
||||
if (xuri.frag.ptr) server_xtn->cfg[SERVER_XTN_CFG_REALM] = qse_wcsntombsdup (xuri.frag.ptr, xuri.frag.len, httpd->mmgr);
|
||||
|
||||
server_xtn->cfg[SERVER_XTN_CFG_DOCROOT] = qse_wcsntombsdup (xuri.path.ptr, xuri.path.len, QSE_NULL, httpd->mmgr);
|
||||
if (xuri.frag.ptr) server_xtn->cfg[SERVER_XTN_CFG_REALM] = qse_wcsntombsdup (xuri.frag.ptr, xuri.frag.len, QSE_NULL, httpd->mmgr);
|
||||
ba.ptr = qse_wcsnatombsdup (tmp, &ba.len, httpd->mmgr);
|
||||
#endif
|
||||
|
||||
if ((!server_xtn->cfg[SERVER_XTN_CFG_DOCROOT]) ||
|
||||
(xuri.auth.user.ptr && !server_xtn->cfg[SERVER_XTN_CFG_USERNAME]) ||
|
||||
(xuri.auth.pass.ptr && !server_xtn->cfg[SERVER_XTN_CFG_PASSWORD]) ||
|
||||
(xuri.frag.ptr && !server_xtn->cfg[SERVER_XTN_CFG_REALM])) goto nomem_after_attach;
|
||||
|
||||
tmp[0] = server_xtn->cfg[SERVER_XTN_CFG_USERNAME]? server_xtn->cfg[SERVER_XTN_CFG_USERNAME]: QSE_MT("");
|
||||
tmp[1] = QSE_MT(":");
|
||||
tmp[2] = server_xtn->cfg[SERVER_XTN_CFG_PASSWORD]? server_xtn->cfg[SERVER_XTN_CFG_PASSWORD]: QSE_MT("");
|
||||
tmp[3] = QSE_NULL;
|
||||
|
||||
ba.ptr = qse_mbsadup (tmp, &ba.len, httpd->mmgr);
|
||||
if (!ba.ptr) goto nomem_after_attach;
|
||||
(xuri.frag.ptr && !server_xtn->cfg[SERVER_XTN_CFG_REALM]) ||
|
||||
!ba.ptr)
|
||||
{
|
||||
if (ba.ptr) QSE_MMGR_FREE (httpd->mmgr, ba.ptr);
|
||||
goto nomem_after_attach;
|
||||
}
|
||||
|
||||
balen2 = ((ba.len / 3) + 1) * 4;
|
||||
server_xtn->cfg[SERVER_XTN_CFG_BASICAUTH] = QSE_MMGR_ALLOC (
|
||||
server_xtn->cfg[SERVER_XTN_CFG_AUTH] = QSE_MMGR_ALLOC (
|
||||
httpd->mmgr, (balen2 + 1) * QSE_SIZEOF(qse_mchar_t));
|
||||
if (!server_xtn->cfg[SERVER_XTN_CFG_BASICAUTH])
|
||||
if (!server_xtn->cfg[SERVER_XTN_CFG_AUTH])
|
||||
{
|
||||
QSE_MMGR_FREE (httpd->mmgr, ba.ptr);
|
||||
goto nomem_after_attach;
|
||||
@ -2164,18 +2207,18 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
|
||||
|
||||
qse_enbase64 (
|
||||
ba.ptr, ba.len,
|
||||
server_xtn->cfg[SERVER_XTN_CFG_BASICAUTH],
|
||||
server_xtn->cfg[SERVER_XTN_CFG_AUTH],
|
||||
balen2,
|
||||
&balen2
|
||||
);
|
||||
QSE_MMGR_FREE (httpd->mmgr, ba.ptr);
|
||||
(server_xtn->cfg[SERVER_XTN_CFG_BASICAUTH])[balen2] = QSE_MT('\0');
|
||||
(server_xtn->cfg[SERVER_XTN_CFG_AUTH])[balen2] = QSE_MT('\0');
|
||||
|
||||
server_xtn->predetach = predetach;
|
||||
server_xtn->cbstd = &server_cbstd;
|
||||
server_xtn->cgistd = server_cgistd;
|
||||
server_xtn->mimestd = server_mimestd;
|
||||
server_xtn->idxstd = QSE_NULL;
|
||||
server_xtn->cfg2.s.cbstd = &server_cbstd;
|
||||
server_xtn->cfg2.s.cgistd = server_cgistd;
|
||||
server_xtn->cfg2.s.mimestd = server_mimestd;
|
||||
server_xtn->cfg2.s.idxstd = QSE_NULL;
|
||||
|
||||
return xserver;
|
||||
|
||||
@ -2189,6 +2232,85 @@ nomem_after_attach:
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
int qse_httpd_getserveroptstd (
|
||||
qse_httpd_t* httpd, qse_httpd_server_t* server,
|
||||
qse_httpd_server_optstd_t id, void** value)
|
||||
{
|
||||
server_xtn_t* server_xtn;
|
||||
|
||||
server_xtn = qse_httpd_getserverxtn (httpd, server);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case QSE_HTTPD_SERVER_DOCROOT:
|
||||
case QSE_HTTPD_SERVER_REALM:
|
||||
case QSE_HTTPD_SERVER_AUTH:
|
||||
case QSE_HTTPD_SERVER_ERRCSS:
|
||||
case QSE_HTTPD_SERVER_DIRCSS:
|
||||
*value = (void*)server_xtn->cfg[id - QSE_HTTPD_SERVER_DOCROOT];
|
||||
return 0;
|
||||
|
||||
case QSE_HTTPD_SERVER_CBSTD:
|
||||
case QSE_HTTPD_SERVER_CGISTD:
|
||||
case QSE_HTTPD_SERVER_MIMESTD:
|
||||
case QSE_HTTPD_SERVER_IDXSTD:
|
||||
*value = (void*)server_xtn->cfg2.a[id - QSE_HTTPD_SERVER_CBSTD];
|
||||
return 0;
|
||||
}
|
||||
|
||||
httpd->errnum = QSE_HTTPD_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int qse_httpd_setserveroptstd (
|
||||
qse_httpd_t* httpd, qse_httpd_server_t* server,
|
||||
qse_httpd_server_optstd_t id, void* value)
|
||||
{
|
||||
server_xtn_t* server_xtn;
|
||||
qse_mchar_t* mctmp;
|
||||
|
||||
server_xtn = qse_httpd_getserverxtn (httpd, server);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case QSE_HTTPD_SERVER_DOCROOT:
|
||||
case QSE_HTTPD_SERVER_REALM:
|
||||
case QSE_HTTPD_SERVER_AUTH:
|
||||
case QSE_HTTPD_SERVER_ERRCSS:
|
||||
case QSE_HTTPD_SERVER_DIRCSS:
|
||||
mctmp = (qse_mchar_t*)value;
|
||||
if(mctmp)
|
||||
{
|
||||
mctmp = qse_mbsdup ((qse_mchar_t*)mctmp, httpd->mmgr);
|
||||
if (mctmp == QSE_NULL)
|
||||
{
|
||||
httpd->errnum = QSE_HTTPD_ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (server_xtn->cfg[id - QSE_HTTPD_SERVER_DOCROOT])
|
||||
{
|
||||
QSE_MMGR_FREE (httpd->mmgr,
|
||||
server_xtn->cfg[id - QSE_HTTPD_SERVER_DOCROOT]);
|
||||
}
|
||||
|
||||
server_xtn->cfg[id - QSE_HTTPD_SERVER_DOCROOT] = mctmp;
|
||||
return 0;
|
||||
|
||||
case QSE_HTTPD_SERVER_CBSTD:
|
||||
case QSE_HTTPD_SERVER_CGISTD:
|
||||
case QSE_HTTPD_SERVER_MIMESTD:
|
||||
case QSE_HTTPD_SERVER_IDXSTD:
|
||||
server_xtn->cfg2.a[id - QSE_HTTPD_SERVER_CBSTD] = value;
|
||||
return 0;
|
||||
}
|
||||
|
||||
httpd->errnum = QSE_HTTPD_EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
void* qse_httpd_getserverxtnstd (qse_httpd_t* httpd, qse_httpd_server_t* server)
|
||||
{
|
||||
server_xtn_t* xtn = qse_httpd_getserverxtn (httpd, server);
|
||||
|
@ -239,7 +239,9 @@ static qse_httpd_task_t* entask_status (
|
||||
}
|
||||
else
|
||||
{
|
||||
if (httpd->rcb->format_error (httpd, client, code, text, QSE_COUNTOF(text)) <= -1) return -1;
|
||||
if (httpd->rcb->format_err (httpd, client, code, text, QSE_COUNTOF(text)) <= -1)
|
||||
return QSE_NULL;
|
||||
|
||||
if (code == 401)
|
||||
{
|
||||
extrapre = QSE_MT("WWW-Authenticate: Basic realm=\"");
|
||||
@ -260,7 +262,7 @@ static qse_httpd_task_t* entask_status (
|
||||
}
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
qse_httpd_task_t* qse_httpd_entask_error (
|
||||
qse_httpd_task_t* qse_httpd_entask_err (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client,
|
||||
qse_httpd_task_t* pred, int code,
|
||||
const qse_http_version_t* version, int keepalive)
|
||||
@ -268,7 +270,7 @@ qse_httpd_task_t* qse_httpd_entask_error (
|
||||
return entask_status (httpd, client, pred, code, QSE_NULL, version, keepalive);
|
||||
}
|
||||
|
||||
qse_httpd_task_t* qse_httpd_entaskerror (
|
||||
qse_httpd_task_t* qse_httpd_entaskerr (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client,
|
||||
qse_httpd_task_t* pred, int code, qse_htre_t* req)
|
||||
{
|
||||
@ -427,9 +429,9 @@ qse_httpd_task_t* qse_httpd_entaskrsrc (
|
||||
task = qse_httpd_entaskdir (httpd, client, QSE_NULL, rsrc->u.dir.path, req);
|
||||
break;
|
||||
|
||||
case QSE_HTTPD_RSRC_ERROR:
|
||||
case QSE_HTTPD_RSRC_ERR:
|
||||
qse_httpd_discardcontent (httpd, req);
|
||||
task = qse_httpd_entaskerror (httpd, client, QSE_NULL, rsrc->u.error.code, req);
|
||||
task = qse_httpd_entaskerr (httpd, client, QSE_NULL, rsrc->u.err.code, req);
|
||||
break;
|
||||
|
||||
case QSE_HTTPD_RSRC_FILE:
|
||||
|
@ -101,7 +101,7 @@ void qse_httpd_fini (
|
||||
qse_httpd_t* httpd
|
||||
);
|
||||
|
||||
qse_httpd_task_t* qse_httpd_entask_error (
|
||||
qse_httpd_task_t* qse_httpd_entask_err (
|
||||
qse_httpd_t* httpd,
|
||||
qse_httpd_client_t* client,
|
||||
qse_httpd_task_t* pred,
|
||||
|
@ -167,7 +167,7 @@ static int test3 (void)
|
||||
{
|
||||
qse_wchar_t* wcs;
|
||||
|
||||
wcs = qse_mbstowcsdup (x[i], QSE_MMGR_GETDFL());
|
||||
wcs = qse_mbstowcsdup (x[i], QSE_NULL, QSE_MMGR_GETDFL());
|
||||
if (wcs == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[ERROR]"));
|
||||
@ -198,7 +198,7 @@ static int test4 (void)
|
||||
};
|
||||
qse_wchar_t* wcs;
|
||||
|
||||
wcs = qse_mbsatowcsdup (x, QSE_MMGR_GETDFL());
|
||||
wcs = qse_mbsatowcsdup (x, QSE_NULL, QSE_MMGR_GETDFL());
|
||||
if (wcs == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[ERROR]\n"));
|
||||
|
@ -235,7 +235,7 @@ static int test3 (void)
|
||||
|
||||
for (i = 0; i < QSE_COUNTOF(x); i++)
|
||||
{
|
||||
qse_mchar_t* m = qse_wcstombsdup (x[i], QSE_MMGR_GETDFL());
|
||||
qse_mchar_t* m = qse_wcstombsdup (x[i], QSE_NULL, QSE_MMGR_GETDFL());
|
||||
if (m == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[ERROR]\n"), m);
|
||||
@ -277,7 +277,7 @@ static int test4 (void)
|
||||
|
||||
x[1] = unistr;
|
||||
|
||||
m = qse_wcsatombsdup (x, QSE_MMGR_GETDFL());
|
||||
m = qse_wcsatombsdup (x, QSE_NULL, QSE_MMGR_GETDFL());
|
||||
if (m == QSE_NULL)
|
||||
{
|
||||
qse_printf (QSE_T("[ERROR]\n"), m);
|
||||
|
@ -59,7 +59,6 @@ static int httpd_main (int argc, qse_char_t* argv[])
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
qse_httpd_server_t* server;
|
||||
qse_httpd_server_xtn_t* server_xtn;
|
||||
|
||||
server = qse_httpd_attachserverstd (httpd, argv[i], QSE_NULL, 0);
|
||||
if (server == QSE_NULL)
|
||||
@ -69,13 +68,10 @@ static int httpd_main (int argc, qse_char_t* argv[])
|
||||
goto oops;
|
||||
}
|
||||
|
||||
server_xtn = qse_httpd_getserverxtn (httpd, server);
|
||||
/* don't care about failure */
|
||||
server_xtn->cfg[QSE_HTTPD_SERVER_XTN_CFG_DIRCSS] =
|
||||
qse_mbsdup (QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; } table { font-size: 0.9em; } td { white-space: nowrap; } td.size { text-align: right; }</style>"), qse_httpd_getmmgr(httpd));
|
||||
|
||||
server_xtn->cfg[QSE_HTTPD_SERVER_XTN_CFG_ERRORCSS] =
|
||||
qse_mbsdup (QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; }</style>"), qse_httpd_getmmgr(httpd));
|
||||
qse_httpd_setserveroptstd (httpd, server, QSE_HTTPD_SERVER_DIRCSS,
|
||||
QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; } table { font-size: 0.9em; } td { white-space: nowrap; } td.size { text-align: right; }</style>"));
|
||||
qse_httpd_setserveroptstd (httpd, server, QSE_HTTPD_SERVER_ERRCSS,
|
||||
QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; }</style>"));
|
||||
}
|
||||
|
||||
g_httpd = httpd;
|
||||
|
@ -52,7 +52,8 @@ struct server_xtn_t
|
||||
};
|
||||
|
||||
static int makersrc (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, qse_httpd_rsrc_t* rsrc)
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client,
|
||||
qse_htre_t* req, qse_httpd_rsrc_t* rsrc)
|
||||
{
|
||||
server_xtn_t* server_xtn;
|
||||
|
||||
@ -65,8 +66,8 @@ static int makersrc (
|
||||
/* TODO: implement a better check that the
|
||||
* destination is not one of the local addresses */
|
||||
|
||||
rsrc->type = QSE_HTTPD_RSRC_ERROR;
|
||||
rsrc->u.error.code = 500;
|
||||
rsrc->type = QSE_HTTPD_RSRC_ERR;
|
||||
rsrc->u.err.code = 500;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -100,7 +101,9 @@ static int makersrc (
|
||||
}
|
||||
}
|
||||
|
||||
static void freersrc (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, qse_httpd_rsrc_t* rsrc)
|
||||
static void freersrc (
|
||||
qse_httpd_t* httpd, qse_httpd_client_t* client,
|
||||
qse_htre_t* req, qse_httpd_rsrc_t* rsrc)
|
||||
{
|
||||
server_xtn_t* server_xtn;
|
||||
|
||||
@ -123,7 +126,6 @@ static qse_httpd_server_t* attach_server (
|
||||
qse_httpd_t* httpd, qse_char_t* uri, qse_httpd_server_cbstd_t* cbstd)
|
||||
{
|
||||
qse_httpd_server_t* server;
|
||||
qse_httpd_server_xtn_t* server_xtn_inner;
|
||||
server_xtn_t* server_xtn;
|
||||
int tproxy = 0;
|
||||
|
||||
@ -154,18 +156,27 @@ static qse_httpd_server_t* attach_server (
|
||||
* extension space created by qse_httpd_attachserverstd()
|
||||
* internally.
|
||||
*/
|
||||
server_xtn_inner = qse_httpd_getserverxtn (httpd, server);
|
||||
/* remember the callback set in qse_httpd_attachserverstd() */
|
||||
server_xtn->orgcbstd = server_xtn_inner->cbstd;
|
||||
qse_httpd_getserveroptstd (
|
||||
httpd, server,
|
||||
QSE_HTTPD_SERVER_CBSTD, (void**)&server_xtn->orgcbstd);
|
||||
/* override it with a new callback for chaining */
|
||||
server_xtn_inner->cbstd = cbstd;
|
||||
server_xtn_inner->idxstd = idxstd; /* override index file list */
|
||||
qse_httpd_setserveroptstd (
|
||||
httpd, server,
|
||||
QSE_HTTPD_SERVER_CBSTD, cbstd);
|
||||
|
||||
/* don't care about failure */
|
||||
server_xtn_inner->cfg[QSE_HTTPD_SERVER_XTN_CFG_DIRCSS] =
|
||||
qse_mbsdup (QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; } table { font-size: 0.9em; } td { white-space: nowrap; } td.size { text-align: right; }</style>"), qse_httpd_getmmgr(httpd));
|
||||
server_xtn_inner->cfg[QSE_HTTPD_SERVER_XTN_CFG_ERRORCSS] =
|
||||
qse_mbsdup (QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; }</style>"), qse_httpd_getmmgr(httpd));
|
||||
/* totally override idxstd without remembering the old idxstd */
|
||||
qse_httpd_setserveroptstd (
|
||||
httpd, server,
|
||||
QSE_HTTPD_SERVER_IDXSTD, idxstd);
|
||||
|
||||
qse_httpd_setserveroptstd (
|
||||
httpd, server, QSE_HTTPD_SERVER_DIRCSS,
|
||||
QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; } table { font-size: 0.9em; } td { white-space: nowrap; } td.size { text-align: right; }</style>"));
|
||||
|
||||
qse_httpd_setserveroptstd (
|
||||
httpd, server, QSE_HTTPD_SERVER_ERRCSS,
|
||||
QSE_MT("<style type='text/css'>body { background-color:#d0e4fe; font-size: 0.9em; } div.header { font-weight: bold; margin-bottom: 5px; } div.footer { border-top: 1px solid #99AABB; text-align: right; }</style>"));
|
||||
|
||||
return server;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user