added _instsize to qse_httpd_t, qse_httpd_server_t, qse_httpd_client_t, etc

This commit is contained in:
hyung-hwan 2019-06-25 02:36:32 +00:00
parent 74b48b87ec
commit 03bdfda578
17 changed files with 270 additions and 298 deletions

View File

@ -290,7 +290,7 @@ static void sig_reconf (int sig)
if (g_httpd)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn = qse_httpd_getxtnstd (g_httpd);
httpd_xtn = qse_httpd_getxtn(g_httpd);
httpd_xtn->impede_code = sig;
qse_httpd_impede (g_httpd);
}
@ -429,7 +429,7 @@ static int make_resource (
{
server_xtn_t* server_xtn;
server_xtn = qse_httpd_getserverstdxtn (httpd, client->server);
server_xtn = qse_httpd_getserverxtn(httpd, client->server);
if (server_xtn->orgmakersrc (httpd, client, req, rsrc) <= -1) return -1;
if (server_xtn->nodir && rsrc->type == QSE_HTTPD_RSRC_DIR)
@ -448,7 +448,7 @@ static void free_resource (
{
server_xtn_t* server_xtn;
server_xtn = qse_httpd_getserverstdxtn (httpd, client->server);
server_xtn = qse_httpd_getserverxtn(httpd, client->server);
server_xtn->orgfreersrc (httpd, client, req, rsrc);
}
/* --------------------------------------------------------------------- */
@ -748,8 +748,8 @@ static int query_server (
server_xtn_t* server_xtn;
loccfg_t* loccfg = QSE_NULL;
httpd_xtn = qse_httpd_getxtnstd (httpd);
server_xtn = qse_httpd_getserverstdxtn (httpd, server);
httpd_xtn = qse_httpd_getxtn(httpd);
server_xtn = qse_httpd_getserverxtn(httpd, server);
if (code == QSE_HTTPD_SERVERSTD_SSL)
{
@ -1733,7 +1733,7 @@ static int load_loccfg (qse_httpd_t* httpd, qse_xli_t* xli, qse_xli_list_t* list
{
/*httpd_xtn_t* httpd_xtn;
httpd_xtn = qse_httpd_getxtnstd (httpd);*/
httpd_xtn = qse_httpd_getxtn(httpd);*/
if (load_loccfg_basic (httpd, xli, list, cfg) <= -1 ||
load_loccfg_index (httpd, xli, list, cfg) <= -1 ||
@ -1900,8 +1900,8 @@ static int load_server_config (qse_httpd_t* httpd, qse_httpd_server_t* server, q
QSE_HTB_HASHER_DEFAULT
};
httpd_xtn = qse_httpd_getxtnstd (httpd);
server_xtn = qse_httpd_getserverstdxtn (httpd, server);
httpd_xtn = qse_httpd_getxtn(httpd);
server_xtn = qse_httpd_getserverxtn(httpd, server);
/* load the server-wide configuration not specific to host/location */
for (i = 0; i < SCFG_MAX; i++)
@ -2007,7 +2007,7 @@ static void free_server_config (qse_httpd_t* httpd, qse_httpd_server_t* server)
server_xtn_t* server_xtn;
qse_size_t i;
server_xtn = qse_httpd_getserverstdxtn (httpd, server);
server_xtn = qse_httpd_getserverxtn(httpd, server);
for (i = 0; i < SCFG_MAX; i++)
{
@ -2033,7 +2033,7 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l
server_xtn_t* server_xtn;
qse_xli_pair_t* pair;
httpd_xtn = qse_httpd_getxtnstd (httpd);
httpd_xtn = qse_httpd_getxtn(httpd);
qse_memset (&dope, 0, QSE_SIZEOF(dope));
@ -2081,7 +2081,7 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, int num, qse_xli_l
return QSE_NULL;
}
server_xtn = qse_httpd_getserverstdxtn (httpd, xserver);
server_xtn = qse_httpd_getserverxtn(httpd, xserver);
/* remember original callbacks */
qse_httpd_getserverstdopt (httpd, xserver, QSE_HTTPD_SERVERSTD_QUERY, &server_xtn->orgquery);
@ -2110,7 +2110,7 @@ static int load_hook_modules (qse_httpd_t* httpd, qse_xli_list_t* hook_list)
int i;
httpd_xtn = qse_httpd_getxtnstd (httpd);
httpd_xtn = qse_httpd_getxtn(httpd);
for (i = 0; ; i++)
{
@ -2315,7 +2315,7 @@ static int open_config_file (qse_httpd_t* httpd)
};
httpd_xtn = (httpd_xtn_t*) qse_httpd_getxtnstd (httpd);
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
QSE_ASSERT (httpd_xtn->xli == QSE_NULL);
httpd_xtn->xli = qse_xli_openstd (0, 0, QSE_NULL);
@ -2372,7 +2372,7 @@ static int close_config_file (qse_httpd_t* httpd)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn = (httpd_xtn_t*) qse_httpd_getxtnstd (httpd);
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
if (httpd_xtn->xli)
{
qse_xli_close (httpd_xtn->xli);
@ -2387,7 +2387,7 @@ static void set_limit (qse_httpd_t* httpd, const qse_char_t* name, int what)
qse_xli_pair_t* pair;
httpd_xtn_t* httpd_xtn;
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtnstd (httpd);
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
pair = qse_xli_findpair (httpd_xtn->xli, QSE_NULL, name);
if (pair)
@ -2426,7 +2426,7 @@ static int load_config (qse_httpd_t* httpd)
httpd_xtn_t* httpd_xtn;
int i;
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtnstd (httpd);
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
if (open_config_file (httpd) <= -1) goto oops;
@ -2506,14 +2506,13 @@ oops:
static void reconf_server (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
server_xtn_t* server_xtn;
qse_xli_pair_t* pair;
/* reconfigure the server when the server is impeded in sig_reconf(). */
httpd_xtn = qse_httpd_getxtnstd (httpd);
server_xtn = qse_httpd_getserverstdxtn (httpd, server);
server_xtn = qse_httpd_getserverxtn(httpd, server);
if (httpd_xtn->xli)
{
@ -2531,11 +2530,10 @@ static void reconf_server (qse_httpd_t* httpd, qse_httpd_server_t* server)
static void impede_httpd (qse_httpd_t* httpd)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
/* reconfigure the server when the server is impeded in sig_reconf(). */
httpd_xtn = qse_httpd_getxtnstd (httpd);
if (httpd_xtn->impede_code == 9999)
{
qse_httpd_stop (httpd);
@ -2564,9 +2562,7 @@ static void impede_httpd (qse_httpd_t* httpd)
static int prerewrite_url (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, const qse_mchar_t* host, qse_mchar_t** url)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn = qse_httpd_getxtnstd (httpd);
httpd_xtn_t* httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
printf ("PREREWRITING.....................\n");
/*
@ -2583,11 +2579,9 @@ printf ("PREREWRITING.....................\n");
static void logact_httpd (qse_httpd_t* httpd, const qse_httpd_act_t* act)
{
/*httpd_xtn_t* httpd_xtn;*/
/*httpd_xtn_t* httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);*/
qse_char_t tmp[128], tmp2[128], tmp3[128];
/*httpd_xtn = qse_httpd_getxtnstd (httpd);*/
switch (act->code)
{
case QSE_HTTPD_CATCH_MERRMSG:
@ -2727,8 +2721,7 @@ wrongusage:
static void free_httpd_xtn (qse_httpd_t* httpd)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn = qse_httpd_getxtnstd (httpd);
httpd_xtn_t* httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
free_loccfg_contents (httpd, &httpd_xtn->dflcfg);
}
@ -2756,7 +2749,7 @@ static int httpd_main (int argc, qse_char_t* argv[])
qse_memset (&ecb, 0, QSE_SIZEOF(ecb));
ecb.close = free_httpd_xtn;
qse_httpd_pushecb (httpd, &ecb);
httpd_xtn = qse_httpd_getxtnstd (httpd);
httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(httpd);
httpd_xtn->cfgfile = g_cfgfile;
if (load_config (httpd) <= -1) goto oops;
@ -2815,11 +2808,10 @@ static void interrupt new_keyboard_handler (void)
{
if (!impeded_for_keyboard && g_httpd)
{
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = (httpd_xtn_t*)qse_httpd_getxtn(g_httpd);
int c;
/* TODO: read a keystroke... etc */
httpd_xtn = qse_httpd_getxtnstd (g_httpd);
httpd_xtn->impede_code = 9999;
qse_httpd_impede (g_httpd);
impeded_for_keyboard = 1;

View File

@ -1559,12 +1559,16 @@ QSE_EXPORT void qse_awk_close (
qse_awk_t* awk /**< awk */
);
#if defined(QSE_HAVE_INLINE)
/**
* The qse_awk_getxtn() function returns the pointer to the extension area
* placed behind the actual awk object.
*/
static QSE_INLINE void* qse_awk_getxtn (qse_awk_t* awk) { return (void*)((qse_uint8_t*)awk + ((qse_awk_alt_t*)awk)->_instsize); }
/**
* The qse_awk_getmmgr() function gets the memory manager used in
* qse_awk_open().
*/
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE void* qse_awk_getxtn (qse_awk_t* awk) { return (void*)((qse_uint8_t*)awk + ((qse_awk_alt_t*)awk)->_instsize); }
static QSE_INLINE qse_mmgr_t* qse_awk_getmmgr (qse_awk_t* awk) { return ((qse_awk_alt_t*)awk)->_mmgr; }
static QSE_INLINE qse_cmgr_t* qse_awk_getcmgr (qse_awk_t* awk) { return ((qse_awk_alt_t*)awk)->_cmgr; }
static QSE_INLINE void qse_awk_setcmgr (qse_awk_t* awk, qse_cmgr_t* cmgr) { ((qse_awk_alt_t*)awk)->_cmgr = cmgr; }
@ -1609,7 +1613,7 @@ QSE_EXPORT void qse_awk_clear (
* The qse_awk_geterrstr() gets an error string getter.
*/
QSE_EXPORT qse_awk_errstr_t qse_awk_geterrstr (
const qse_awk_t* awk /**< awk */
qse_awk_t* awk /**< awk */
);
/**
@ -1647,7 +1651,7 @@ QSE_EXPORT void qse_awk_seterrstr (
* \return error number
*/
QSE_EXPORT qse_awk_errnum_t qse_awk_geterrnum (
const qse_awk_t* awk /**< awk */
qse_awk_t* awk /**< awk */
);
/**
@ -1655,7 +1659,7 @@ QSE_EXPORT qse_awk_errnum_t qse_awk_geterrnum (
* last error has occurred.
*/
QSE_EXPORT const qse_awk_loc_t* qse_awk_geterrloc (
const qse_awk_t* awk /**< awk */
qse_awk_t* awk /**< awk */
);
/**
@ -1665,7 +1669,7 @@ QSE_EXPORT const qse_awk_loc_t* qse_awk_geterrloc (
* \return error message
*/
QSE_EXPORT const qse_char_t* qse_awk_geterrmsg (
const qse_awk_t* awk /**< awk */
qse_awk_t* awk /**< awk */
);
QSE_EXPORT const qse_char_t* qse_awk_backuperrmsg (
@ -1678,7 +1682,7 @@ QSE_EXPORT const qse_char_t* qse_awk_backuperrmsg (
* pointed to by \a errinf from \a awk.
*/
QSE_EXPORT void qse_awk_geterrinf (
const qse_awk_t* awk, /**< awk */
qse_awk_t* awk, /**< awk */
qse_awk_errinf_t* errinf /**< error information buffer */
);
@ -1718,7 +1722,7 @@ QSE_EXPORT void qse_awk_seterrinf (
* The qse_awk_geterror() function gets error information via parameters.
*/
QSE_EXPORT void qse_awk_geterror (
const qse_awk_t* awk, /**< awk */
qse_awk_t* awk, /**< awk */
qse_awk_errnum_t* errnum, /**< error number */
const qse_char_t** errmsg, /**< error message */
qse_awk_loc_t* errloc /**< error location */
@ -2331,7 +2335,7 @@ QSE_EXPORT qse_htb_t* qse_awk_rtx_getnvmap (
* \return error number
*/
QSE_EXPORT qse_awk_errnum_t qse_awk_rtx_geterrnum (
const qse_awk_rtx_t* rtx /**< runtime context */
qse_awk_rtx_t* rtx /**< runtime context */
);
/**
@ -2340,7 +2344,7 @@ QSE_EXPORT qse_awk_errnum_t qse_awk_rtx_geterrnum (
* \return error location
*/
QSE_EXPORT const qse_awk_loc_t* qse_awk_rtx_geterrloc (
const qse_awk_rtx_t* rtx /**< runtime context */
qse_awk_rtx_t* rtx /**< runtime context */
);
/**
@ -2349,7 +2353,7 @@ QSE_EXPORT const qse_awk_loc_t* qse_awk_rtx_geterrloc (
* \return error message
*/
QSE_EXPORT const qse_char_t* qse_awk_rtx_geterrmsg (
const qse_awk_rtx_t* rtx /**< runtime context */
qse_awk_rtx_t* rtx /**< runtime context */
);
QSE_EXPORT const qse_char_t* qse_awk_rtx_backuperrmsg (
@ -2361,7 +2365,7 @@ QSE_EXPORT const qse_char_t* qse_awk_rtx_backuperrmsg (
* pointed to by \a errinf from a runtime context \a rtx.
*/
QSE_EXPORT void qse_awk_rtx_geterrinf (
const qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_errinf_t* errinf /**< error information */
);
@ -2372,7 +2376,7 @@ QSE_EXPORT void qse_awk_rtx_geterrinf (
* \a errmsg; the error line into memory pointed to by \a errlin.
*/
QSE_EXPORT void qse_awk_rtx_geterror (
const qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_rtx_t* rtx, /**< runtime context */
qse_awk_errnum_t* errnum, /**< error number */
const qse_char_t** errmsg, /**< error message */
qse_awk_loc_t* errloc /**< error location */

View File

@ -37,6 +37,18 @@
#include <qse/si/nwad.h>
typedef struct qse_httpd_t qse_httpd_t;
#define QSE_HTTPD_HDR \
qse_size_t _instsize; \
qse_mmgr_t* _mmgr
typedef struct qse_httpd_alt_t qse_httpd_alt_t;
struct qse_httpd_alt_t
{
/* ensure that qse_httpd_alt_t matches the beginning part of qse_httpd_t */
QSE_HTTPD_HDR;
};
typedef struct qse_httpd_mate_t qse_httpd_mate_t;
typedef struct qse_httpd_server_t qse_httpd_server_t;
typedef struct qse_httpd_client_t qse_httpd_client_t;
@ -676,6 +688,7 @@ typedef enum qse_httpd_mate_type_t qse_httpd_mate_type_t;
/* it contains header fields common between
* qse_httpd_cleint_t and qse_httpd_server_t. */
#define QSE_HTTPD_MATE_HDR \
qse_size_t _instsize; \
qse_httpd_mate_type_t type
struct qse_httpd_mate_t
@ -1077,13 +1090,22 @@ QSE_EXPORT void qse_httpd_close (
qse_httpd_t* httpd
);
QSE_EXPORT qse_mmgr_t* qse_httpd_getmmgr (
qse_httpd_t* httpd
);
QSE_EXPORT void* qse_httpd_getxtn (
qse_httpd_t* httpd
);
#if defined(QSE_HAVE_INLINE)
/**
* The qse_httpd_getxtn() function returns the pointer to the extension area
* placed behind the actual httpd object.
*/
static QSE_INLINE void* qse_httpd_getxtn (qse_httpd_t* httpd) { return (void*)((qse_uint8_t*)httpd + ((qse_httpd_alt_t*)httpd)->_instsize); }
/**
* The qse_httpd_gethttpd() function gets the memory manager used in
* qse_httpd_open().
*/
static QSE_INLINE qse_mmgr_t* qse_httpd_getmmgr (qse_httpd_t* httpd) { return ((qse_httpd_alt_t*)httpd)->_mmgr; }
#else
# define qse_httpd_getxtn(httpd) ((void*)((qse_uint8_t*)httpd + ((qse_httpd_alt_t*)httpd)->_instsize))
# define qse_httpd_getmmgr(httpd) (((qse_httpd_alt_t*)(httpd))->_mmgr)
#endif /* QSE_HAVE_INLINE */
QSE_EXPORT qse_httpd_errnum_t qse_httpd_geterrnum (
qse_httpd_t* httpd
@ -1140,9 +1162,6 @@ QSE_EXPORT void qse_httpd_stop (
QSE_EXPORT void qse_httpd_impede (
qse_httpd_t* httpd
);
#define qse_httpd_getserverxtn(httpd,server) ((void*)(server+1))
QSE_EXPORT qse_httpd_server_t* qse_httpd_attachserver (
qse_httpd_t* httpd,
const qse_httpd_server_dope_t* dope,
@ -1154,6 +1173,12 @@ QSE_EXPORT void qse_httpd_detachserver (
qse_httpd_server_t* server
);
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE void* qse_httpd_getserverxtn (qse_httpd_t* httpd, qse_httpd_server_t* server) { return (void*)((qse_uint8_t*)server + ((qse_httpd_mate_t*)server)->_instsize); }
#else
# define qse_httpd_getserverxtn(httpd, server) ((void*)((qse_uint8_t*)server + ((qse_httpd_mate_t*)server)->_instsize))
#endif
QSE_EXPORT qse_httpd_server_t* qse_httpd_getfirstserver (
qse_httpd_t* httpd
);

View File

@ -233,10 +233,6 @@ QSE_EXPORT qse_httpd_t* qse_httpd_openstdwithmmgr (
qse_httpd_errnum_t* errnum
);
QSE_EXPORT void* qse_httpd_getxtnstd (
qse_httpd_t* httpd
);
QSE_EXPORT qse_httpd_server_t* qse_httpd_attachserverstd (
qse_httpd_t* httpd,
const qse_httpd_server_dope_t* dope,
@ -268,11 +264,6 @@ QSE_EXPORT int qse_httpd_setserverstdopt (
const void* value
);
QSE_EXPORT void* qse_httpd_getserverstdxtn (
qse_httpd_t* httpd,
qse_httpd_server_t* server
);
QSE_EXPORT int qse_httpd_loopstd (
qse_httpd_t* httpd,
const qse_httpd_dnsstd_t* dns,

View File

@ -306,13 +306,10 @@ protected:
private:
static ssize_t sin (
sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len);
static ssize_t xin (
sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len);
static ssize_t xout (
sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* dat, size_t len);
static const char_t* xerrstr (const sed_t* s, errnum_t num);
static ssize_t sin (sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len);
static ssize_t xin (sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* buf, size_t len);
static ssize_t xout (sed_t* s, io_cmd_t cmd, io_arg_t* arg, char_t* dat, size_t len);
static const char_t* xerrstr (sed_t* s, errnum_t num);
};
/////////////////////////////////

View File

@ -62,6 +62,17 @@
*/
typedef struct qse_sed_t qse_sed_t;
#define QSE_SED_HDR \
qse_size_t _instsize; \
qse_mmgr_t* _mmgr
typedef struct qse_sed_alt_t qse_sed_alt_t;
struct qse_sed_alt_t
{
/* ensure that qse_sed_alt_t matches the beginning part of qse_sed_t */
QSE_SED_HDR;
};
typedef struct qse_sed_loc_t qse_sed_loc_t;
typedef struct qse_sed_adr_t qse_sed_adr_t;
typedef struct qse_sed_cmd_t qse_sed_cmd_t;
@ -274,7 +285,7 @@ typedef enum qse_sed_errnum_t qse_sed_errnum_t;
* editor with the qse_sed_seterrstr() function to customize an error string.
*/
typedef const qse_char_t* (*qse_sed_errstr_t) (
const qse_sed_t* sed, /**< stream editor */
qse_sed_t* sed, /**< stream editor */
qse_sed_errnum_t num /**< an error number */
);
@ -436,22 +447,23 @@ QSE_EXPORT void qse_sed_close (
qse_sed_t* sed /**< stream editor */
);
/**
* The qse_sed_getmmgr() function returns the memory
* manager used in qse_sed_open().
*/
QSE_EXPORT qse_mmgr_t* qse_sed_getmmgr (
qse_sed_t* sed
);
#if defined(QSE_HAVE_INLINE)
/**
* The qse_sed_getxtn() function returns the pointer
* to the beginning of the extension area created with
* The qse_sed_getxtn() function returns the pointer to the extension area
* placed behind the actual sed object.
*/
static QSE_INLINE void* qse_sed_getxtn (qse_sed_t* sed) { return (void*)((qse_uint8_t*)sed + ((qse_sed_alt_t*)sed)->_instsize); }
/**
* The qse_sed_getmmgr() function gets the memory manager used in
* qse_sed_open().
*/
QSE_EXPORT void* qse_sed_getxtn (
qse_sed_t* sed
);
static QSE_INLINE qse_mmgr_t* qse_sed_getmmgr (qse_sed_t* sed) { return ((qse_sed_alt_t*)sed)->_mmgr; }
#else
# define qse_sed_getxtn(sed) ((void*)((qse_uint8_t*)sed + ((qse_sed_alt_t*)sed)->_instsize))
# define qse_sed_getmmgr(sed) (((qse_sed_alt_t*)(sed))->_mmgr)
#endif /* QSE_HAVE_INLINE */
/**
@ -492,7 +504,7 @@ QSE_EXPORT int qse_sed_setopt (
* The qse_sed_geterrstr() gets an error string getter.
*/
QSE_EXPORT qse_sed_errstr_t qse_sed_geterrstr (
const qse_sed_t* sed /**< stream editor */
qse_sed_t* sed /**< stream editor */
);
/**
@ -529,7 +541,7 @@ QSE_EXPORT void qse_sed_seterrstr (
* @return error number
*/
QSE_EXPORT qse_sed_errnum_t qse_sed_geterrnum (
const qse_sed_t* sed /**< stream editor */
qse_sed_t* sed /**< stream editor */
);
/**
@ -538,7 +550,7 @@ QSE_EXPORT qse_sed_errnum_t qse_sed_geterrnum (
* @return error location
*/
QSE_EXPORT const qse_sed_loc_t* qse_sed_geterrloc (
const qse_sed_t* sed /**< stream editor */
qse_sed_t* sed /**< stream editor */
);
/**
@ -546,7 +558,7 @@ QSE_EXPORT const qse_sed_loc_t* qse_sed_geterrloc (
* @return error message pointer
*/
QSE_EXPORT const qse_char_t* qse_sed_geterrmsg (
const qse_sed_t* sed /**< stream editor */
qse_sed_t* sed /**< stream editor */
);
/**
@ -555,7 +567,7 @@ QSE_EXPORT const qse_char_t* qse_sed_geterrmsg (
* to by each parameter.
*/
QSE_EXPORT void qse_sed_geterror (
const qse_sed_t* sed, /**< stream editor */
qse_sed_t* sed, /**< stream editor */
qse_sed_errnum_t* errnum, /**< error number */
const qse_char_t** errmsg, /**< error message */
qse_sed_loc_t* errloc /**< error location */

View File

@ -103,8 +103,7 @@ extern "C" {
/**
* The qse_sed_openstd() function creates a stream editor with the default
* memory manager and initializes it. Use qse_sed_getxtnstd() to get the
* pointer to the extension area. Do not use qse_sed_getxtn() for this.
* memory manager and initializes it.
* \return pointer to a stream editor on success, #QSE_NULL on failure.
*/
QSE_EXPORT qse_sed_t* qse_sed_openstd (
@ -115,8 +114,7 @@ QSE_EXPORT qse_sed_t* qse_sed_openstd (
/**
* The qse_sed_openstdwithmmgr() function creates a stream editor with a
* user-defined memory manager. It is equivalent to qse_sed_openstd(),
* except that you can specify your own memory manager.Use qse_sed_getxtnstd(),
* not qse_sed_getxtn() to get the pointer to the extension area.
* except that you can specify your own memory manager.
* \return pointer to a stream editor on success, #QSE_NULL on failure.
*/
QSE_EXPORT qse_sed_t* qse_sed_openstdwithmmgr (
@ -125,15 +123,6 @@ QSE_EXPORT qse_sed_t* qse_sed_openstdwithmmgr (
qse_sed_errnum_t* errnum
);
/**
* The qse_sed_getxtnstd() gets the pointer to extension space.
* Note that you must not call qse_sed_getxtn() for a stream editor
* created with qse_sed_openstd() and qse_sed_openstdwithmmgr().
*/
QSE_EXPORT void* qse_sed_getxtnstd (
qse_sed_t* sed /**< stream editor */
);
/**
* The qse_sed_compstd() function compiles sed scripts specified in
* an array of stream resources. The end of the array is indicated

View File

@ -478,16 +478,16 @@ static int cgi_add_env (
tmp[1] = suffix;
tmp[2] = QSE_NULL;
tr = qse_mbsadup (tmp, QSE_NULL, httpd->mmgr);
tr = qse_mbsadup(tmp, QSE_NULL, qse_httpd_getmmgr(httpd));
if (tr)
{
qse_canonmbspath (tr, tr, 0);
if (qse_env_insertmbs (env, QSE_MT("PATH_TRANSLATED"), tr) <= -1)
{
QSE_MMGR_FREE (httpd->mmgr, tr);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tr);
goto oops_nomem;
}
QSE_MMGR_FREE (httpd->mmgr, tr);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tr);
}
if (qse_env_insertmbs (env, QSE_MT("PATH_INFO"), suffix) <= -1) goto oops_nomem;
}
@ -795,7 +795,7 @@ static int task_init_cgi (
else
{
/* do chunking to cgi */
cgi->reqfwdbuf = qse_mbs_open (httpd->mmgr, 0, (len < 512? 512: len));
cgi->reqfwdbuf = qse_mbs_open (qse_httpd_getmmgr(httpd), 0, (len < 512? 512: len));
if (cgi->reqfwdbuf == QSE_NULL)
{
httpd->errnum = QSE_HTTPD_ENOMEM;
@ -832,7 +832,7 @@ static int task_init_cgi (
{
/* create a buffer to hold request content from the client
* and copy content received already */
cgi->reqfwdbuf = qse_mbs_open (httpd->mmgr, 0, (len < 512? 512: len));
cgi->reqfwdbuf = qse_mbs_open (qse_httpd_getmmgr(httpd), 0, (len < 512? 512: len));
if (cgi->reqfwdbuf == QSE_NULL)
{
httpd->errnum = QSE_HTTPD_ENOMEM;
@ -886,7 +886,7 @@ static int task_init_cgi (
}
done:
cgi->env = qse_env_open (httpd->mmgr, 0, 0);
cgi->env = qse_env_open (qse_httpd_getmmgr(httpd), 0, 0);
if (cgi->env == QSE_NULL)
{
httpd->errnum = QSE_HTTPD_ENOMEM;
@ -1462,7 +1462,7 @@ static int task_main_cgi (
else
{
cgi_script_htrd_xtn_t* xtn;
cgi->script_htrd = qse_htrd_open (httpd->mmgr, QSE_SIZEOF(cgi_script_htrd_xtn_t));
cgi->script_htrd = qse_htrd_open (qse_httpd_getmmgr(httpd), QSE_SIZEOF(cgi_script_htrd_xtn_t));
if (cgi->script_htrd == QSE_NULL) goto oops;
xtn = (cgi_script_htrd_xtn_t*) qse_htrd_getxtn (cgi->script_htrd);
@ -1477,7 +1477,7 @@ static int task_main_cgi (
QSE_HTRD_REQUEST
);
cgi->res = qse_mbs_open (httpd->mmgr, 0, 256);
cgi->res = qse_mbs_open (qse_httpd_getmmgr(httpd), 0, 256);
if (cgi->res == QSE_NULL) goto oops;
}
@ -1507,17 +1507,17 @@ static int task_main_cgi (
tmp[1] = QSE_MT(" ");
tmp[2] = cgi->path;
tmp[3] = QSE_NULL;
xpath = qse_mbsadup (tmp, QSE_NULL, httpd->mmgr);
xpath = qse_mbsadup (tmp, QSE_NULL, qse_httpd_getmmgr(httpd));
if (xpath == QSE_NULL) goto oops;
}
else xpath = cgi->path;
}
x = qse_pio_init (
&cgi->pio, httpd->mmgr, (const qse_char_t*)xpath,
&cgi->pio, qse_httpd_getmmgr(httpd), (const qse_char_t*)xpath,
cgi->env, pio_options);
if (xpath != cgi->path &&
xpath != (qse_mchar_t*)&cgi->fnc) QSE_MMGR_FREE (httpd->mmgr, xpath);
xpath != (qse_mchar_t*)&cgi->fnc) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), xpath);
if (x <= -1)
{

View File

@ -160,7 +160,7 @@ static qse_size_t format_dirent (
* a lot of file names to escape. */
/* perform percent-encoding for the anchor */
encname = qse_perenchttpstrdup (0, dirent->name, httpd->mmgr);
encname = qse_perenchttpstrdup (0, dirent->name, qse_httpd_getmmgr(httpd));
if (encname == QSE_NULL)
{
httpd->errnum = QSE_HTTPD_ENOMEM;
@ -171,7 +171,7 @@ static qse_size_t format_dirent (
escname = qse_httpd_escapehtml (httpd, dirent->name);
if (escname == QSE_NULL)
{
if (encname != dirent->name) QSE_MMGR_FREE (httpd->mmgr, encname);
if (encname != dirent->name) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), encname);
return -1;
}
@ -205,7 +205,7 @@ static qse_size_t format_dirent (
);
if (escname != dirent->name) qse_httpd_freemem (httpd, escname);
if (encname != dirent->name) QSE_MMGR_FREE (httpd->mmgr, encname);
if (encname != dirent->name) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), encname);
if (x == (qse_size_t)-1) httpd->errnum = QSE_HTTPD_ENOBUF;
return x;

View File

@ -1055,7 +1055,7 @@ static int task_init_proxy (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_
/* TODO: DETERMINE THIS SIZE */
len = MAX_SEND_SIZE;
proxy->reqfwdbuf = qse_mbs_open (httpd->mmgr, 0, (len < 512? 512: len));
proxy->reqfwdbuf = qse_mbs_open (qse_httpd_getmmgr(httpd), 0, (len < 512? 512: len));
if (proxy->reqfwdbuf == QSE_NULL) goto nomem_oops;
if (proxy->flags & PROXY_RAW)
@ -1094,12 +1094,12 @@ static int task_init_proxy (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_
qse_size_t x;
qpath = qse_htre_getqpath(arg->req);
qpath_enc = qse_perenchttpstrdup (QSE_PERENCHTTPSTR_KEEP_SLASH, qpath, httpd->mmgr);
qpath_enc = qse_perenchttpstrdup (QSE_PERENCHTTPSTR_KEEP_SLASH, qpath, qse_httpd_getmmgr(httpd));
if (qpath_enc == QSE_NULL) goto nomem_oops;
x = qse_mbs_cat (proxy->reqfwdbuf, qpath_enc);
if (qpath != qpath_enc) QSE_MMGR_FREE (httpd->mmgr, qpath_enc);
if (qpath != qpath_enc) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), qpath_enc);
if (x == (qse_size_t)-1) goto nomem_oops;
#else
@ -2381,7 +2381,7 @@ static int task_main_proxy (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_
if (!(proxy->flags & PROXY_RAW))
{
/* set up a http reader to read a response from the peer */
proxy->peer_htrd = qse_htrd_open (httpd->mmgr, QSE_SIZEOF(proxy_peer_htrd_xtn_t));
proxy->peer_htrd = qse_htrd_open (qse_httpd_getmmgr(httpd), QSE_SIZEOF(proxy_peer_htrd_xtn_t));
if (proxy->peer_htrd == QSE_NULL) goto oops;
xtn = (proxy_peer_htrd_xtn_t*) qse_htrd_getxtn (proxy->peer_htrd);
xtn->proxy = proxy;
@ -2391,7 +2391,7 @@ static int task_main_proxy (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_
qse_htrd_setopt (proxy->peer_htrd, QSE_HTRD_RESPONSE | QSE_HTRD_TRAILERS);
}
proxy->res = qse_mbs_open (httpd->mmgr, 0, 256);
proxy->res = qse_mbs_open (qse_httpd_getmmgr(httpd), 0, 256);
if (proxy->res == QSE_NULL) goto oops;
proxy->res_consumed = 0;
proxy->res_pending = 0;

View File

@ -295,9 +295,7 @@ static int dns_open (qse_httpd_t* httpd, qse_httpd_dns_t* dns)
{
qse_nwad_t nwad;
dns_ctx_t* dc;
httpd_xtn_t* httpd_xtn;
httpd_xtn = qse_httpd_getxtn (httpd);
httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);
dns->handle[0] = QSE_INVALID_SCKHND;
dns->handle[1] = QSE_INVALID_SCKHND;
@ -605,7 +603,7 @@ static dns_ans_t* dns_get_answer_from_cache (dns_ctx_t* dc, const qse_mchar_t* n
static int dns_recv (qse_httpd_t* httpd, qse_httpd_dns_t* dns, qse_httpd_hnd_t handle)
{
dns_ctx_t* dc = (dns_ctx_t*)dns->ctx;
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);
qse_skad_t fromaddr;
qse_sck_len_t fromlen;
@ -627,8 +625,6 @@ static int dns_recv (qse_httpd_t* httpd, qse_httpd_dns_t* dns, qse_httpd_hnd_t h
qse_nwad_t* resolved_nwad = QSE_NULL;
int cache_ttl = 0;
httpd_xtn = qse_httpd_getxtn (httpd);
fromlen = QSE_SIZEOF(fromaddr);
len = recvfrom (handle, buf, QSE_SIZEOF(buf), 0, (struct sockaddr*)&fromaddr, &fromlen);
@ -838,7 +834,7 @@ static void tmr_dns_tmout_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tm
/*httpd_xtn_t* httpd_xtn;*/
qse_tmr_event_t tmout_event;
/*httpd_xtn = qse_httpd_getxtn (dc->httpd);*/
/*httpd_xtn = GET_HTTPD_XTN(dc->httpd);*/
QSE_MEMSET (&tmout_event, 0, QSE_SIZEOF(tmout_event));
qse_gettime (&tmout_event.when);
@ -898,7 +894,7 @@ static void tmr_dns_tmout_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tm
static int dns_send (qse_httpd_t* httpd, qse_httpd_dns_t* dns, const qse_mchar_t* name, qse_httpd_resolve_t resol, const qse_httpd_dns_server_t* dns_server, void* ctx)
{
dns_ctx_t* dc = (dns_ctx_t*)dns->ctx;
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);
qse_uint32_t seq;
qse_uint16_t xid;
@ -908,8 +904,6 @@ static int dns_send (qse_httpd_t* httpd, qse_httpd_dns_t* dns, const qse_mchar_t
qse_tmr_event_t tmout_event;
int dns_flags;
httpd_xtn = qse_httpd_getxtn (httpd);
ans = dns_get_answer_from_cache (dc, name);
if (ans)
{

View File

@ -15,7 +15,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
modpath = sysname;
#else
modpath = qse_wcstombsdup (sysname, QSE_NULL, httpd->mmgr);
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
if (!modpath)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -29,7 +29,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
/* do nothing */
#else
QSE_MMGR_FREE (httpd->mmgr, modpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
#endif
return h;
@ -54,7 +54,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
modpath = sysname;
#else
modpath = qse_wcstombsdup (sysname, QSE_NULL, httpd->mmgr);
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
if (!modpath)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -74,7 +74,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
/* do nothing */
#else
QSE_MMGR_FREE (httpd->mmgr, modpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
#endif
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
@ -91,7 +91,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
modpath = sysname;
#else
modpath = qse_wcstombsdup (sysname, QSE_NULL, httpd->mmgr);
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
if (!modpath)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -105,7 +105,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
/* do nothing */
#else
QSE_MMGR_FREE (httpd->mmgr, modpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
#endif
QSE_ASSERT (QSE_SIZEOF(h) <= QSE_SIZEOF(void*));
@ -118,7 +118,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
modpath = sysname;
#else
modpath = qse_wcstombsdup (sysname, QSE_NULL, httpd->mmgr);
modpath = qse_wcstombsdup (sysname, QSE_NULL, qse_httpd_getmmgr(httpd));
if (!modpath)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -132,7 +132,7 @@ static void* mod_open (qse_httpd_t* httpd, const qse_char_t* sysname)
#if defined(QSE_CHAR_IS_MCHAR)
/* do nothing */
#else
QSE_MMGR_FREE (httpd->mmgr, modpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), modpath);
#endif
return h;
@ -168,7 +168,7 @@ static void* mod_symbol (qse_httpd_t* httpd, void* handle, const qse_char_t* nam
#if defined(QSE_CHAR_IS_MCHAR)
mname = name;
#else
mname = qse_wcstombsdup (name, QSE_NULL, httpd->mmgr);
mname = qse_wcstombsdup (name, QSE_NULL, qse_httpd_getmmgr(httpd));
if (!mname)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -207,7 +207,7 @@ static void* mod_symbol (qse_httpd_t* httpd, void* handle, const qse_char_t* nam
#if defined(QSE_CHAR_IS_MCHAR)
/* nothing to do */
#else
QSE_MMGR_FREE (httpd->mmgr, mname);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), mname);
#endif
return s;

View File

@ -100,11 +100,9 @@ static int urs_open (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
{
qse_nwad_t nwad;
urs_ctx_t* dc;
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);
int type, proto = 0; /*IPPROTO_UDP;*/ /*IPPROTO_SCTP*/
httpd_xtn = qse_httpd_getxtn (httpd);
urs->handle[0] = QSE_INVALID_SCKHND;
urs->handle[1] = QSE_INVALID_SCKHND;
urs->handle[2] = QSE_INVALID_SCKHND;
@ -280,7 +278,7 @@ static void urs_close (qse_httpd_t* httpd, qse_httpd_urs_t* urs)
static int urs_recv (qse_httpd_t* httpd, qse_httpd_urs_t* urs, qse_httpd_hnd_t handle)
{
urs_ctx_t* dc = (urs_ctx_t*)urs->ctx;
/*httpd_xtn_t* httpd_xtn;*/
/*httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);*/
qse_skad_t fromaddr;
qse_sck_len_t fromlen;
@ -291,8 +289,6 @@ static int urs_recv (qse_httpd_t* httpd, qse_httpd_urs_t* urs, qse_httpd_hnd_t h
urs_req_t* req;
qse_mchar_t* spc;
/*httpd_xtn = qse_httpd_getxtn (httpd);*/
/* TODO: use recvmsg with MSG_ERRQUEUE... set socket option IP_RECVERR... */
fromlen = QSE_SIZEOF(fromaddr);
len = recvfrom (handle, dc->rcvbuf, QSE_SIZEOF(dc->rcvbuf) - 1, 0, (struct sockaddr*)&fromaddr, &fromlen);
@ -363,11 +359,9 @@ static void tmr_urs_tmout_handle (qse_tmr_t* tmr, const qse_ntime_t* now, qse_tm
*---------------------------------------------------------------- */
if (req->urs_retries > 0)
{
/*httpd_xtn_t* httpd_xtn;*/
/*httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(dc->httpd);*/
qse_tmr_event_t tmout_event;
/*httpd_xtn = qse_httpd_getxtn (dc->httpd);*/
QSE_MEMSET (&tmout_event, 0, QSE_SIZEOF(tmout_event));
qse_gettime (&tmout_event.when);
qse_addtime (&tmout_event.when, &req->urs_tmout, &tmout_event.when);
@ -422,7 +416,7 @@ printf ("urs timed out....\n");
static int urs_send (qse_httpd_t* httpd, qse_httpd_urs_t* urs, const qse_mchar_t* url, qse_httpd_rewrite_t rewrite, const qse_httpd_urs_server_t* urs_server, void* ctx)
{
urs_ctx_t* dc = (urs_ctx_t*)urs->ctx;
httpd_xtn_t* httpd_xtn;
httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);
qse_uint16_t xid;
qse_uint32_t seq;
@ -430,8 +424,6 @@ static int urs_send (qse_httpd_t* httpd, qse_httpd_urs_t* urs, const qse_mchar_t
qse_size_t url_len;
qse_tmr_event_t tmout_event;
httpd_xtn = qse_httpd_getxtn (httpd);
if (dc->req_count >= QSE_COUNTOF(dc->reqs))
{
/* too many pending requests */

View File

@ -168,7 +168,6 @@ typedef struct server_xtn_t server_xtn_t;
struct server_xtn_t
{
qse_httpd_server_detach_t detach;
qse_httpd_serverstd_query_t query;
qse_httpd_serverstd_makersrc_t makersrc;
qse_httpd_serverstd_freersrc_t freersrc;
@ -635,15 +634,22 @@ struct httpd_xtn_t
qse_httpd_ursstd_t urs;
};
#if defined(QSE_HAVE_INLINE)
static QSE_INLINE httpd_xtn_t* GET_HTTPD_XTN(qse_httpd_t* httpd) { return (httpd_xtn_t*)((qse_uint8_t*)qse_httpd_getxtn(httpd) - QSE_SIZEOF(httpd_xtn_t)); }
static QSE_INLINE server_xtn_t* GET_SERVER_XTN(qse_httpd_t* httpd,qse_httpd_server_t* server) { return (server_xtn_t*)((qse_uint8_t*)qse_httpd_getserverxtn(httpd, server) - QSE_SIZEOF(server_xtn_t)); }
#else
#define GET_HTTPD_XTN(httpd) ((httpd_xtn_t*)((qse_uint8_t*)qse_httpd_getxtn(httpd) - QSE_SIZEOF(httpd_xtn_t)))
#define GET_SERVER_XTN(httpd,server) ((server_xtn_t*)((qse_uint8_t*)qse_httpd_getserverxtn(httpd, server) - QSE_SIZEOF(server_xtn_t)))
#endif
#if defined(USE_SSL)
static int init_server_ssl (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
SSL_CTX* ssl_ctx = QSE_NULL;
server_xtn_t* server_xtn;
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, server);
qse_httpd_serverstd_ssl_t ssl;
server_xtn = (server_xtn_t*)qse_httpd_getserverxtn (httpd, server);
if (server_xtn->query (httpd, server, QSE_HTTPD_SERVERSTD_SSL, QSE_NULL, &ssl) <= -1)
{
goto oops;
@ -707,9 +713,7 @@ static void fini_server_ssl (server_xtn_t* xtn)
static int init_xtn_peer_ssl (qse_httpd_t* httpd)
{
SSL_CTX* peer_ctx = QSE_NULL;
httpd_xtn_t* xtn;
xtn = (httpd_xtn_t*)qse_httpd_getxtn (httpd);
httpd_xtn_t* xtn = GET_HTTPD_XTN(httpd);
peer_ctx = SSL_CTX_new (SSLv23_client_method());
if (!peer_ctx)
@ -738,8 +742,7 @@ static void fini_xtn_peer_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);
httpd_xtn_t* xtn = GET_HTTPD_XTN(httpd);
#if defined(USE_SSL)
if (xtn->ssl_peer_ctx) fini_xtn_peer_ssl (xtn);
@ -766,7 +769,9 @@ qse_httpd_t* qse_httpd_openstdwithmmgr (qse_mmgr_t* mmgr, qse_size_t xtnsize, qs
httpd = qse_httpd_open (mmgr, QSE_SIZEOF(httpd_xtn_t) + xtnsize, errnum);
if (httpd == QSE_NULL) goto oops;
xtn = (httpd_xtn_t*)qse_httpd_getxtn (httpd);
httpd->_instsize += QSE_SIZEOF(httpd_xtn_t);
xtn = GET_HTTPD_XTN(httpd);
/* the extension area has been cleared in qse_httpd_open().
* QSE_MEMSET (xtn, 0, QSE_SIZEOF(*xtn));*/
@ -817,11 +822,6 @@ oops:
return QSE_NULL;
}
void* qse_httpd_getxtnstd (qse_httpd_t* httpd)
{
return (void*)((httpd_xtn_t*)QSE_XTN(httpd) + 1);
}
/* ------------------------------------------------------------------- */
static qse_sck_hnd_t open_client_socket (qse_httpd_t* httpd, int domain, int type, int proto)
@ -1299,9 +1299,7 @@ static int client_accepted (qse_httpd_t* httpd, qse_httpd_client_t* client)
#if defined(USE_SSL)
int ret;
SSL* ssl;
server_xtn_t* server_xtn;
server_xtn = (server_xtn_t*)qse_httpd_getserverxtn (httpd, client->server);
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, client->server);
if (!server_xtn->ssl_ctx)
{
@ -1389,7 +1387,7 @@ static int peer_open (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
{
/* -------------------------------------------------------------------- */
httpd_xtn_t* xtn;
httpd_xtn_t* xtn = GET_HTTPD_XTN(httpd);
qse_skad_t connaddr, bindaddr;
int connaddrsize, bindaddrsize;
int connected = 1;
@ -1409,7 +1407,6 @@ static int peer_open (qse_httpd_t* httpd, qse_httpd_peer_t* peer)
int flag;
#endif
xtn = (httpd_xtn_t*) qse_httpd_getxtn (httpd);
/* turn off internally used bits */
peer->flags &= ~QSE_HTTPD_PEER_ALL_INTERNALS;
@ -1790,7 +1787,7 @@ static void* mux_open (qse_httpd_t* httpd, qse_httpd_muxcb_t cbfun)
qse_mux_t* mux;
mux_xtn_t* xtn;
mux = qse_mux_open (httpd->mmgr, QSE_SIZEOF(*xtn), dispatch_muxcb, 256, QSE_NULL);
mux = qse_mux_open (qse_httpd_getmmgr(httpd), QSE_SIZEOF(*xtn), dispatch_muxcb, 256, QSE_NULL);
if (!mux)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ESYSERR);
@ -2148,7 +2145,7 @@ static qse_fio_t* __open_file (qse_httpd_t* httpd, const qse_mchar_t* path, int
fio = qse_httpd_allocmem (httpd, QSE_SIZEOF(*fio));
if (fio == QSE_NULL) return QSE_NULL;
if (qse_fio_init (fio, httpd->mmgr, (const qse_char_t*)path, fio_flags, fio_mode) <= -1)
if (qse_fio_init (fio, qse_httpd_getmmgr(httpd), (const qse_char_t*)path, fio_flags, fio_mode) <= -1)
{
qse_httpd_seterrnum (httpd, fioerr_to_errnum(qse_fio_geterrnum(fio)));
qse_httpd_freemem (httpd, fio);
@ -2327,23 +2324,23 @@ static int dir_open (qse_httpd_t* httpd, const qse_mchar_t* path, qse_httpd_hnd_
dir_t* d;
qse_dir_errnum_t direrrnum;
d = QSE_MMGR_ALLOC (httpd->mmgr, QSE_SIZEOF(*d));
d = QSE_MMGR_ALLOC (qse_httpd_getmmgr(httpd), QSE_SIZEOF(*d));
if (d == QSE_NULL)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
return -1;
}
d->path = qse_mbsdup (path, httpd->mmgr);
d->path = qse_mbsdup (path, qse_httpd_getmmgr(httpd));
if (d->path == QSE_NULL)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
QSE_MMGR_FREE (httpd->mmgr, d);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), d);
return -1;
}
d->dp = qse_dir_open (
httpd->mmgr, 0,
qse_httpd_getmmgr(httpd), 0,
(const qse_char_t*)d->path,
QSE_DIR_MBSPATH | QSE_DIR_SORT,
&direrrnum
@ -2351,8 +2348,8 @@ static int dir_open (qse_httpd_t* httpd, const qse_mchar_t* path, qse_httpd_hnd_
if (d->dp == QSE_NULL)
{
qse_httpd_seterrnum (httpd, direrr_to_errnum(direrrnum));
QSE_MMGR_FREE (httpd->mmgr, d->path);
QSE_MMGR_FREE (httpd->mmgr, d);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), d->path);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), d);
return -1;
}
@ -2372,8 +2369,8 @@ static void dir_close (qse_httpd_t* httpd, qse_httpd_hnd_t handle)
qse_dir_close (d->dp);
QSE_MMGR_FREE (httpd->mmgr, d->path);
QSE_MMGR_FREE (httpd->mmgr, d);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), d->path);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), d);
}
static int dir_read (qse_httpd_t* httpd, qse_httpd_hnd_t handle, qse_httpd_dirent_t* dirent)
@ -2394,7 +2391,7 @@ static int dir_read (qse_httpd_t* httpd, qse_httpd_hnd_t handle, qse_httpd_diren
else if (n == 0) return 0;
/* i assume that d->path ends with a slash */
fpath = qse_mbsdup2 (d->path, (const qse_mchar_t*)de.name, httpd->mmgr);
fpath = qse_mbsdup2 (d->path, (const qse_mchar_t*)de.name, qse_httpd_getmmgr(httpd));
if (fpath == QSE_NULL)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -2402,7 +2399,7 @@ static int dir_read (qse_httpd_t* httpd, qse_httpd_hnd_t handle, qse_httpd_diren
}
n = stat_file (httpd, fpath, &dirent->stat, 0);
QSE_MMGR_FREE (httpd->mmgr, fpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), fpath);
if (n <= -1) QSE_MEMSET (dirent, 0, QSE_SIZEOF(*dirent));
dirent->name = (const qse_mchar_t*)de.name;
@ -2426,15 +2423,13 @@ static qse_htb_walk_t walk (qse_htb_t* htb, qse_htb_pair_t* pair, void* ctx)
}
#endif
static int process_request (
qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, int peek)
static int process_request (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, int peek)
{
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, client->server);
qse_httpd_task_t* task;
server_xtn_t* server_xtn;
qse_http_method_t mth;
qse_httpd_rsrc_t rsrc;
server_xtn = (server_xtn_t*)qse_httpd_getserverxtn (httpd, client->server);
/* percent-decode the query path to the original buffer
* since i'm not going to need it in the original form
@ -2628,15 +2623,12 @@ static int poke_request (
return process_request (httpd, client, req, 0);
}
static int format_error (
qse_httpd_t* httpd, qse_httpd_client_t* client, int code, qse_mchar_t* buf, int bufsz)
static int format_error (qse_httpd_t* httpd, qse_httpd_client_t* client, int code, qse_mchar_t* buf, int bufsz)
{
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, client->server);
qse_size_t n;
server_xtn_t* server_xtn;
const qse_mchar_t* head, * foot, * msg;
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
if (server_xtn->query (httpd, client->server, QSE_HTTPD_SERVERSTD_ERRHEAD, QSE_NULL, &head) <= -1) head = QSE_NULL;
if (head == QSE_NULL) head = 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>");
@ -2796,32 +2788,32 @@ static void free_resource (
{
case QSE_HTTPD_RSRC_CGI:
if (target->u.cgi.suffix)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.cgi.suffix);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.cgi.suffix);
if (target->u.cgi.script != qpath)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.cgi.script);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.cgi.script);
if (!(target->u.cgi.flags & QSE_HTTPD_RSRC_CGI_FNC))
{
if (target->u.cgi.path != qpath)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.cgi.path);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.cgi.path);
if (target->u.cgi.shebang)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.cgi.shebang);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.cgi.shebang);
}
break;
case QSE_HTTPD_RSRC_DIR:
if (target->u.dir.path != qpath)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.dir.path);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.dir.path);
break;
case QSE_HTTPD_RSRC_FILE:
if (target->u.file.path != qpath)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.file.path);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.file.path);
break;
case QSE_HTTPD_RSRC_RELOC:
if (target->u.reloc.target != qpath)
QSE_MMGR_FREE (httpd->mmgr, (qse_mchar_t*)target->u.reloc.target);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), (qse_mchar_t*)target->u.reloc.target);
break;
default:
@ -2844,7 +2836,7 @@ static qse_mchar_t* merge_paths (
ta[idx++] = path;
}
ta[idx++] = QSE_NULL;
xpath = qse_mbsadup (ta, QSE_NULL, httpd->mmgr);
xpath = qse_mbsadup (ta, QSE_NULL, qse_httpd_getmmgr(httpd));
if (xpath == QSE_NULL)
{
httpd->errnum = QSE_HTTPD_ENOMEM;
@ -2904,14 +2896,12 @@ static int attempt_cgi (
qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req,
struct rsrc_tmp_t* tmp, qse_httpd_rsrc_t* target)
{
server_xtn_t* server_xtn;
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, client->server);
qse_mchar_t* shebang = QSE_NULL;
qse_mchar_t* suffix = QSE_NULL;
qse_mchar_t* script = QSE_NULL;
qse_httpd_serverstd_cgi_t cgi;
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
if (tmp->final_match)
{
qse_httpd_serverstd_query_info_t qinfo;
@ -2940,7 +2930,7 @@ static int attempt_cgi (
/* free tmp->xpath here upon success since it's not used for relocation.
* upon failure, it is freed by the caller. so the 'oops' part
* of this function doesn't free it. */
QSE_MMGR_FREE (httpd->mmgr, tmp->xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp->xpath);
return 1;
}
else script = (qse_mchar_t*)tmp->qpath;
@ -3004,8 +2994,8 @@ static int attempt_cgi (
/* the script name is composed of the orginal query path.
* the pointer held in 'slash' is valid for tmp->qpath as
* tmp->qpath_rp is at most the tail part of tmp->qpath. */
script = qse_mbsxdup (tmp->qpath, slash - tmp->qpath, httpd->mmgr);
suffix = qse_mbsdup (slash, httpd->mmgr);
script = qse_mbsxdup (tmp->qpath, slash - tmp->qpath, qse_httpd_getmmgr(httpd));
suffix = qse_mbsdup (slash, qse_httpd_getmmgr(httpd));
if (!script || !suffix) goto oops;
goto bingo;
@ -3051,7 +3041,7 @@ static int attempt_cgi (
if (server_xtn->query (httpd, client->server, QSE_HTTPD_SERVERSTD_CGI, &qinfo, &cgi) >= 0 && cgi.cgi && cgi.fncptr)
{
/* virtual cgi script */
script = qse_mbsdup (tmp->qpath, httpd->mmgr);
script = qse_mbsdup (tmp->qpath, qse_httpd_getmmgr(httpd));
if (!script) goto oops;
suffix = QSE_NULL;
@ -3085,7 +3075,7 @@ bingo:
{
if (cgi.shebang)
{
shebang = qse_mbsdup (cgi.shebang, httpd->mmgr);
shebang = qse_mbsdup (cgi.shebang, qse_httpd_getmmgr(httpd));
if (shebang == QSE_NULL) goto oops;
}
@ -3101,9 +3091,9 @@ bingo:
oops:
httpd->errnum = QSE_HTTPD_ENOMEM;
if (shebang) QSE_MMGR_FREE (httpd->mmgr, shebang);
if (suffix) QSE_MMGR_FREE (httpd->mmgr, suffix);
if (script && script != tmp->qpath) QSE_MMGR_FREE (httpd->mmgr, script);
if (shebang) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), shebang);
if (suffix) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), suffix);
if (script && script != tmp->qpath) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), script);
return -1;
}
@ -3111,7 +3101,7 @@ static int make_resource (
qse_httpd_t* httpd, qse_httpd_client_t* client,
qse_htre_t* req, qse_httpd_rsrc_t* target)
{
server_xtn_t* server_xtn;
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, client->server);
struct rsrc_tmp_t tmp;
qse_httpd_stat_t st;
@ -3125,8 +3115,6 @@ static int make_resource (
QSE_MEMSET (target, 0, QSE_SIZEOF(*target));
server_xtn = qse_httpd_getserverxtn (httpd, client->server);
QSE_MEMSET (&qinfo, 0, QSE_SIZEOF(qinfo));
qinfo.req = req;
qinfo.client = client;
@ -3314,20 +3302,20 @@ auth_ok:
tpath = merge_paths (httpd, tmp.xpath, ptr);
if (tpath == QSE_NULL)
{
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
return -1;
}
if (httpd->opt.scb.file.stat (httpd, tpath, &st) >= 0 && !st.isdir)
{
/* the index file is found */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
tmp.xpath = tpath;
tmp.idxfile = ptr;
goto attempt_file;
}
QSE_MMGR_FREE (httpd->mmgr, tpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tpath);
}
}
@ -3340,7 +3328,7 @@ auth_ok:
qse_htre_discardcontent (req);
target->type = QSE_HTTPD_RSRC_ERROR;
/* free xpath since it won't be used */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
}
else if (tmp.qpath[tmp.qpath_len - 1] != QSE_MT('/'))
{
@ -3350,7 +3338,7 @@ auth_ok:
target->u.reloc.flags = QSE_HTTPD_RSRC_RELOC_APPENDSLASH | QSE_HTTPD_RSRC_RELOC_PERMANENT;
target->u.reloc.target = tmp.qpath;
/* free xpath since it won't be used */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
}
else
{
@ -3375,7 +3363,7 @@ auth_ok:
n = attempt_cgi (httpd, client, req, &tmp, target);
if (n <= -1)
{
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
return -1;
}
if (n >= 1)
@ -3384,7 +3372,7 @@ auth_ok:
{
/* tmp.xpath is not set to target->u.cgi.path when
* this flag is set. it must be deallocated */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
}
return 0;
}
@ -3400,7 +3388,7 @@ auth_ok:
{
/* free xpath since it won't be used */
qse_htre_discardcontent (req);
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
target->type = QSE_HTTPD_RSRC_ERROR;
}
else
@ -3411,7 +3399,7 @@ auth_ok:
qse_htre_discardcontent (req);
/* free xpath since it won't be used */
QSE_MMGR_FREE (httpd->mmgr, tmp.xpath);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), tmp.xpath);
/* create a relocation resource */
target->type = QSE_HTTPD_RSRC_RELOC;
@ -3447,11 +3435,9 @@ auth_ok:
static void detach_server (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
server_xtn_t* server_xtn;
server_xtn = (server_xtn_t*) qse_httpd_getserverxtn (httpd, server);
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, server);
if (server_xtn->detach) server_xtn->detach (httpd, server);
if (server_xtn->auth.ptr) QSE_MMGR_FREE (httpd->mmgr, server_xtn->auth.ptr);
if (server_xtn->auth.ptr) QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), server_xtn->auth.ptr);
#if defined(USE_SSL)
if (server_xtn->ssl_ctx) fini_server_ssl (server_xtn);
@ -3608,7 +3594,9 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
xserver = qse_httpd_attachserver(httpd, &xdope, QSE_SIZEOF(*server_xtn) + xtnsize);
if (xserver == QSE_NULL) return QSE_NULL;
server_xtn = qse_httpd_getserverxtn (httpd, xserver);
xserver->_instsize += QSE_SIZEOF(*server_xtn);
server_xtn = GET_SERVER_XTN(httpd, xserver);
QSE_MEMSET (server_xtn, 0, QSE_SIZEOF(*server_xtn));
/* chain the original detach function */
@ -3705,9 +3693,7 @@ int qse_httpd_getserverstdopt (
qse_httpd_t* httpd, qse_httpd_server_t* server,
qse_httpd_serverstd_opt_t id, void* value)
{
server_xtn_t* server_xtn;
server_xtn = qse_httpd_getserverxtn (httpd, server);
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, server);
switch (id)
{
@ -3733,9 +3719,7 @@ int qse_httpd_setserverstdopt (
qse_httpd_t* httpd, qse_httpd_server_t* server,
qse_httpd_serverstd_opt_t id, const void* value)
{
server_xtn_t* server_xtn;
server_xtn = qse_httpd_getserverxtn (httpd, server);
server_xtn_t* server_xtn = GET_SERVER_XTN(httpd, server);
switch (id)
{
@ -3756,18 +3740,11 @@ int qse_httpd_setserverstdopt (
return -1;
}
void* qse_httpd_getserverstdxtn (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
server_xtn_t* xtn = qse_httpd_getserverxtn (httpd, server);
return (void*)(xtn + 1);
}
/* ------------------------------------------------------------------- */
int qse_httpd_loopstd (qse_httpd_t* httpd, const qse_httpd_dnsstd_t* dns, const qse_httpd_ursstd_t* urs)
{
httpd_xtn_t* httpd_xtn = qse_httpd_getxtn (httpd);
httpd_xtn_t* httpd_xtn = GET_HTTPD_XTN(httpd);
/* default dns server info */
if (dns)

View File

@ -91,7 +91,7 @@ qse_httpd_t* qse_httpd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, qse_httpd_err
void qse_httpd_close (qse_httpd_t* httpd)
{
qse_httpd_fini (httpd);
QSE_MMGR_FREE (httpd->mmgr, httpd);
QSE_MMGR_FREE (httpd->_mmgr, httpd);
}
int qse_httpd_init (qse_httpd_t* httpd, qse_mmgr_t* mmgr)
@ -100,7 +100,9 @@ int qse_httpd_init (qse_httpd_t* httpd, qse_mmgr_t* mmgr)
QSE_MEMSET (httpd, 0, QSE_SIZEOF(*httpd));
httpd->mmgr = mmgr;
httpd->_instsize = QSE_SIZEOF(*httpd);
httpd->_mmgr = mmgr;
httpd->tmr = qse_tmr_open (mmgr, QSE_SIZEOF(tmr_xtn_t), 2048);
if (httpd->tmr == QSE_NULL) return -1;
@ -119,6 +121,7 @@ int qse_httpd_init (qse_httpd_t* httpd, qse_mmgr_t* mmgr)
void qse_httpd_fini (qse_httpd_t* httpd)
{
qse_httpd_ecb_t* ecb;
qse_size_t i;
unload_all_modules (httpd);
@ -127,6 +130,16 @@ void qse_httpd_fini (qse_httpd_t* httpd)
free_server_list (httpd);
qse_tmr_close (httpd->tmr);
for (i = 0; i < QSE_COUNTOF(httpd->opt.mod); i++)
{
if (httpd->opt.mod[i].ptr)
{
qse_httpd_freemem (httpd, httpd->opt.mod[i].ptr);
httpd->opt.mod[i].ptr = QSE_NULL;
httpd->opt.mod[i].len = 0;
}
}
}
void qse_httpd_stop (qse_httpd_t* httpd)
@ -149,21 +162,11 @@ void qse_httpd_seterrnum (qse_httpd_t* httpd, qse_httpd_errnum_t errnum)
httpd->errnum = errnum;
}
qse_mmgr_t* qse_httpd_getmmgr (qse_httpd_t* httpd)
{
return httpd->mmgr;
}
void* qse_httpd_getxtn (qse_httpd_t* httpd)
{
return QSE_XTN (httpd);
}
static int dup_str_opt (qse_httpd_t* httpd, const void* value, qse_cstr_t* tmp)
{
if (value)
{
tmp->ptr = qse_strdup (value, httpd->mmgr);
tmp->ptr = qse_strdup(value, qse_httpd_getmmgr(httpd));
if (tmp->ptr == QSE_NULL)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
@ -239,7 +242,7 @@ int qse_httpd_setopt (qse_httpd_t* httpd, qse_httpd_opt_t id, const void* value)
if (dup_str_opt(httpd, value, &tmp) <= -1) return -1;
idx = id - QSE_HTTPD_MODPREFIX;
if (httpd->opt.mod[idx].ptr) QSE_MMGR_FREE (httpd->mmgr, httpd->opt.mod[idx].ptr);
if (httpd->opt.mod[idx].ptr) qse_httpd_freemem (httpd, httpd->opt.mod[idx].ptr);
httpd->opt.mod[idx] = tmp;
return 0;
@ -276,32 +279,32 @@ void qse_httpd_pushecb (qse_httpd_t* httpd, qse_httpd_ecb_t* ecb)
/* ----------------------------------------------------------------------- */
QSE_INLINE void* qse_httpd_allocmem (qse_httpd_t* httpd, qse_size_t size)
void* qse_httpd_allocmem (qse_httpd_t* httpd, qse_size_t size)
{
void* ptr = QSE_MMGR_ALLOC (httpd->mmgr, size);
void* ptr = QSE_MMGR_ALLOC (qse_httpd_getmmgr(httpd), size);
if (ptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
return ptr;
}
QSE_INLINE void* qse_httpd_callocmem (qse_httpd_t* httpd, qse_size_t size)
void* qse_httpd_callocmem (qse_httpd_t* httpd, qse_size_t size)
{
void* ptr = QSE_MMGR_ALLOC (httpd->mmgr, size);
void* ptr = QSE_MMGR_ALLOC (qse_httpd_getmmgr(httpd), size);
if (ptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
else QSE_MEMSET (ptr, 0, size);
return ptr;
}
QSE_INLINE void* qse_httpd_reallocmem (
void* qse_httpd_reallocmem (
qse_httpd_t* httpd, void* ptr, qse_size_t size)
{
void* nptr = QSE_MMGR_REALLOC (httpd->mmgr, ptr, size);
void* nptr = QSE_MMGR_REALLOC (qse_httpd_getmmgr(httpd), ptr, size);
if (nptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
return nptr;
}
QSE_INLINE void qse_httpd_freemem (qse_httpd_t* httpd, void* ptr)
void qse_httpd_freemem (qse_httpd_t* httpd, void* ptr)
{
QSE_MMGR_FREE (httpd->mmgr, ptr);
QSE_MMGR_FREE (qse_httpd_getmmgr(httpd), ptr);
}
qse_mchar_t* qse_httpd_strtombsdup (qse_httpd_t* httpd, const qse_char_t* str)
@ -309,9 +312,9 @@ qse_mchar_t* qse_httpd_strtombsdup (qse_httpd_t* httpd, const qse_char_t* str)
qse_mchar_t* mptr;
#if defined(QSE_CHAR_IS_MCHAR)
mptr = qse_mbsdup (str, httpd->mmgr);
mptr = qse_mbsdup (str, qse_httpd_getmmgr(httpd));
#else
mptr = qse_wcstombsdup (str, QSE_NULL, httpd->mmgr);
mptr = qse_wcstombsdup (str, QSE_NULL, qse_httpd_getmmgr(httpd));
#endif
if (mptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
@ -323,9 +326,9 @@ qse_mchar_t* qse_httpd_strntombsdup (qse_httpd_t* httpd, const qse_char_t* str,
qse_mchar_t* mptr;
#if defined(QSE_CHAR_IS_MCHAR)
mptr = qse_mbsxdup (str, len, httpd->mmgr);
mptr = qse_mbsxdup (str, len, qse_httpd_getmmgr(httpd));
#else
mptr = qse_wcsntombsdup (str, len, QSE_NULL, httpd->mmgr);
mptr = qse_wcsntombsdup (str, len, QSE_NULL, qse_httpd_getmmgr(httpd));
#endif
if (mptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
@ -336,7 +339,7 @@ qse_mchar_t* qse_httpd_mbsdup (qse_httpd_t* httpd, const qse_mchar_t* str)
{
qse_mchar_t* mptr;
mptr = qse_mbsdup (str, httpd->mmgr);
mptr = qse_mbsdup (str, qse_httpd_getmmgr(httpd));
if (mptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
return mptr;
@ -346,7 +349,7 @@ qse_mchar_t* qse_httpd_mbsxdup (qse_httpd_t* httpd, const qse_mchar_t* str, qse_
{
qse_mchar_t* mptr;
mptr = qse_mbsxdup (str, len, httpd->mmgr);
mptr = qse_mbsxdup (str, len, qse_httpd_getmmgr(httpd));
if (mptr == QSE_NULL) httpd->errnum = QSE_HTTPD_ENOMEM;
return mptr;
@ -626,8 +629,9 @@ static qse_httpd_client_t* new_client (qse_httpd_t* httpd, qse_httpd_client_t* t
QSE_MEMSET (client, 0, QSE_SIZEOF(*client));
client->tmr_idle = QSE_TMR_INVALID_INDEX;
client->_instsize = QSE_SIZEOF(*client);
client->type = QSE_HTTPD_CLIENT;
client->htrd = qse_htrd_open (httpd->mmgr, QSE_SIZEOF(*xtn));
client->htrd = qse_htrd_open (qse_httpd_getmmgr(httpd), QSE_SIZEOF(*xtn));
if (client->htrd == QSE_NULL)
{
httpd->errnum = QSE_HTTPD_ENOMEM;
@ -1031,6 +1035,7 @@ qse_httpd_server_t* qse_httpd_attachserver (
server = qse_httpd_callocmem (httpd, QSE_SIZEOF(*server) + xtnsize);
if (server == QSE_NULL) return QSE_NULL;
server->_instsize = QSE_SIZEOF(*server);
server->type = QSE_HTTPD_SERVER;
/* copy the server dope */
server->dope = *dope;

View File

@ -64,7 +64,7 @@
struct qse_httpd_t
{
qse_mmgr_t* mmgr;
QSE_HTTPD_HDR;
qse_httpd_errnum_t errnum;
qse_httpd_ecb_t* ecb; /* event callbacks */
qse_tmr_t* tmr;

View File

@ -1,5 +1,6 @@
#include <qse/sed/StdSed.hpp>
#include <qse/cmn/main.h>
#include <qse/Exception.hpp>
#include <iostream>
#include "sed00.h"
@ -15,29 +16,22 @@
class MySed: protected QSE::StdSed
{
public:
class Error
{
public:
Error (const char_t* msg) throw (): msg (msg) {}
const char_t* getMessage() const throw() { return msg; }
protected:
const char_t* msg;
};
QSE_EXCEPTION(Error);
MySed () { if (open() <= -1) throw Error (QSE_T("cannot open")); }
~MySed () { close (); }
MySed () { if (this->open() <= -1) QSE_THROW_WITH_MSG (Error, QSE_T("cannot open sed")); }
~MySed () { this->close (); }
void compile (const char_t* sptr)
{
QSE::StdSed::StringStream stream(sptr);
if (QSE::StdSed::compile (stream) <= -1)
throw Error (getErrorMessage());
QSE_THROW_WITH_MSG(Error, this->getErrorMessage());
}
void execute (Stream& stream)
{
if (QSE::StdSed::execute (stream) <= -1)
throw Error (getErrorMessage());
QSE_THROW_WITH_MSG(Error, this->getErrorMessage());
}
};
@ -57,7 +51,7 @@ int sed_main (int argc, qse_char_t* argv[])
}
catch (MySed::Error& err)
{
xcout << QSE_T("ERROR: ") << err.getMessage() << std::endl;
xcout << QSE_T("ERROR: ") << QSE_EXCEPTION_MSG(err) << std::endl;
return -1;
}