added QSE_HTTPD_MODPREFIX and QSE_HTTPD_MODPOSTFIX

This commit is contained in:
hyung-hwan 2014-09-03 17:11:01 +00:00
parent 4b0f12a896
commit d8f8f93207
3 changed files with 76 additions and 20 deletions

View File

@ -67,10 +67,12 @@ typedef enum qse_httpd_errnum_t qse_httpd_errnum_t;
enum qse_httpd_opt_t
{
QSE_HTTPD_TRAIT,
QSE_HTTPD_SCB,
QSE_HTTPD_RCB,
QSE_HTTPD_TMOUT,
QSE_HTTPD_IDLELIMIT
QSE_HTTPD_IDLELIMIT,
QSE_HTTPD_MODPREFIX,
QSE_HTTPD_MODPOSTFIX,
QSE_HTTPD_SCB,
QSE_HTTPD_RCB
};
typedef enum qse_httpd_opt_t qse_httpd_opt_t;
@ -1128,6 +1130,16 @@ QSE_EXPORT int qse_httpd_rewriteurl (
);
QSE_EXPORT int qse_httpd_loadmod (
qse_httpd_t* httpd,
const qse_char_t* name
);
QSE_EXPORT qse_httpd_mod_t* qse_httpd_findmod (
qse_httpd_t* httpd,
const qse_char_t* name
);
#ifdef __cplusplus
}
#endif

View File

@ -123,6 +123,27 @@ 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);
if (tmp->ptr == QSE_NULL)
{
qse_httpd_seterrnum (httpd, QSE_HTTPD_ENOMEM);
return -1;
}
tmp->len = qse_strlen (tmp->ptr);
}
else
{
tmp->ptr = QSE_NULL;
tmp->len = 0;
}
return 0;
}
int qse_httpd_getopt (qse_httpd_t* httpd, qse_httpd_opt_t id, void* value)
{
switch (id)
@ -131,14 +152,6 @@ int qse_httpd_getopt (qse_httpd_t* httpd, qse_httpd_opt_t id, void* value)
*(int*)value = httpd->opt.trait;
return 0;
case QSE_HTTPD_SCB:
*(qse_httpd_scb_t*)value = httpd->opt.scb;
return 0;
case QSE_HTTPD_RCB:
*(qse_httpd_rcb_t*)value = httpd->opt.rcb;
return 0;
case QSE_HTTPD_TMOUT:
*(qse_ntime_t*)value = httpd->opt.tmout;
return 0;
@ -146,6 +159,19 @@ int qse_httpd_getopt (qse_httpd_t* httpd, qse_httpd_opt_t id, void* value)
case QSE_HTTPD_IDLELIMIT:
*(qse_ntime_t*)value = httpd->opt.idle_limit;
return 0;
case QSE_HTTPD_MODPREFIX:
case QSE_HTTPD_MODPOSTFIX:
*(const qse_char_t**)value = httpd->opt.mod[id - QSE_HTTPD_MODPREFIX].ptr;
return 0;
case QSE_HTTPD_SCB:
*(qse_httpd_scb_t*)value = httpd->opt.scb;
return 0;
case QSE_HTTPD_RCB:
*(qse_httpd_rcb_t*)value = httpd->opt.rcb;
return 0;
}
httpd->errnum = QSE_HTTPD_EINVAL;
@ -160,6 +186,29 @@ int qse_httpd_setopt (qse_httpd_t* httpd, qse_httpd_opt_t id, const void* value)
httpd->opt.trait = *(const int*)value;
return 0;
case QSE_HTTPD_TMOUT:
httpd->opt.tmout = *(qse_ntime_t*)value;
return 0;
case QSE_HTTPD_IDLELIMIT:
httpd->opt.idle_limit = *(qse_ntime_t*)value;
return 0;
case QSE_HTTPD_MODPREFIX:
case QSE_HTTPD_MODPOSTFIX:
{
qse_cstr_t tmp;
int idx;
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);
httpd->opt.mod[idx] = tmp;
return 0;
}
case QSE_HTTPD_SCB:
httpd->opt.scb = *(qse_httpd_scb_t*)value;
return 0;
@ -168,13 +217,7 @@ int qse_httpd_setopt (qse_httpd_t* httpd, qse_httpd_opt_t id, const void* value)
httpd->opt.rcb = *(qse_httpd_rcb_t*)value;
return 0;
case QSE_HTTPD_TMOUT:
httpd->opt.tmout = *(qse_ntime_t*)value;
return 0;
case QSE_HTTPD_IDLELIMIT:
httpd->opt.idle_limit = *(qse_ntime_t*)value;
return 0;
}
httpd->errnum = QSE_HTTPD_EINVAL;

View File

@ -38,10 +38,11 @@ struct qse_httpd_t
struct
{
int trait;
qse_httpd_scb_t scb; /* system callbacks */
qse_httpd_rcb_t rcb; /* request callbacks */
qse_ntime_t tmout; /* poll timeout */
qse_ntime_t idle_limit;
qse_cstr_t mod[2]; /* module prefix and postfix */
qse_httpd_scb_t scb; /* system callbacks */
qse_httpd_rcb_t rcb; /* request callbacks */
} opt;
int stopreq: 1;