enhanced cmd/http/httpd.c to load host/location-specific configuration data

This commit is contained in:
2013-03-11 16:34:41 +00:00
parent 357aec132a
commit 847a08c455
22 changed files with 596 additions and 821 deletions

View File

@ -32,8 +32,8 @@
#define sizer_t qse_htb_sizer_t
#define walker_t qse_htb_walker_t
#define cbserter_t qse_htb_cbserter_t
#define mancbs_t qse_htb_mancbs_t
#define mancbs_kind_t qse_htb_mancbs_kind_t
#define style_t qse_htb_style_t
#define style_kind_t qse_htb_style_kind_t
#define KPTR(p) QSE_HTB_KPTR(p)
#define KLEN(p) QSE_HTB_KLEN(p)
@ -53,10 +53,13 @@ QSE_INLINE pair_t* qse_htb_allocpair (
htb_t* htb, void* kptr, size_t klen, void* vptr, size_t vlen)
{
pair_t* n;
copier_t kcop = htb->mancbs->copier[QSE_HTB_KEY];
copier_t vcop = htb->mancbs->copier[QSE_HTB_VAL];
copier_t kcop, vcop;
size_t as;
size_t as = SIZEOF(pair_t);
kcop = htb->style->copier[QSE_HTB_KEY];
vcop = htb->style->copier[QSE_HTB_VAL];
as = SIZEOF(pair_t);
if (kcop == QSE_HTB_COPIER_INLINE) as += KTOB(htb,klen);
if (vcop == QSE_HTB_COPIER_INLINE) as += VTOB(htb,vlen);
@ -106,8 +109,8 @@ QSE_INLINE pair_t* qse_htb_allocpair (
VPTR(n) = vcop (htb, vptr, vlen);
if (VPTR(n) != QSE_NULL)
{
if (htb->mancbs->freeer[QSE_HTB_KEY] != QSE_NULL)
htb->mancbs->freeer[QSE_HTB_KEY] (htb, KPTR(n), KLEN(n));
if (htb->style->freeer[QSE_HTB_KEY] != QSE_NULL)
htb->style->freeer[QSE_HTB_KEY] (htb, KPTR(n), KLEN(n));
QSE_MMGR_FREE (htb->mmgr, n);
return QSE_NULL;
}
@ -118,10 +121,10 @@ QSE_INLINE pair_t* qse_htb_allocpair (
QSE_INLINE void qse_htb_freepair (htb_t* htb, pair_t* pair)
{
if (htb->mancbs->freeer[QSE_HTB_KEY] != QSE_NULL)
htb->mancbs->freeer[QSE_HTB_KEY] (htb, KPTR(pair), KLEN(pair));
if (htb->mancbs->freeer[QSE_HTB_VAL] != QSE_NULL)
htb->mancbs->freeer[QSE_HTB_VAL] (htb, VPTR(pair), VLEN(pair));
if (htb->style->freeer[QSE_HTB_KEY] != QSE_NULL)
htb->style->freeer[QSE_HTB_KEY] (htb, KPTR(pair), KLEN(pair));
if (htb->style->freeer[QSE_HTB_VAL] != QSE_NULL)
htb->style->freeer[QSE_HTB_VAL] (htb, VPTR(pair), VLEN(pair));
QSE_MMGR_FREE (htb->mmgr, pair);
}
@ -133,14 +136,14 @@ static QSE_INLINE pair_t* change_pair_val (
/* if the old value and the new value are the same,
* it just calls the handler for this condition.
* No value replacement occurs. */
if (htb->mancbs->keeper != QSE_NULL)
if (htb->style->keeper != QSE_NULL)
{
htb->mancbs->keeper (htb, vptr, vlen);
htb->style->keeper (htb, vptr, vlen);
}
}
else
{
copier_t vcop = htb->mancbs->copier[QSE_HTB_VAL];
copier_t vcop = htb->style->copier[QSE_HTB_VAL];
void* ovptr = VPTR(pair);
size_t ovlen = VLEN(pair);
@ -176,9 +179,9 @@ static QSE_INLINE pair_t* change_pair_val (
}
/* free up the old value */
if (htb->mancbs->freeer[QSE_HTB_VAL] != QSE_NULL)
if (htb->style->freeer[QSE_HTB_VAL] != QSE_NULL)
{
htb->mancbs->freeer[QSE_HTB_VAL] (htb, ovptr, ovlen);
htb->style->freeer[QSE_HTB_VAL] (htb, ovptr, ovlen);
}
}
@ -186,9 +189,9 @@ static QSE_INLINE pair_t* change_pair_val (
return pair;
}
static mancbs_t mancbs[] =
static style_t style[] =
{
/* == QSE_HTB_MANCBS_DEFAULT == */
/* == QSE_HTB_STYLE_DEFAULT == */
{
{
QSE_HTB_COPIER_DEFAULT,
@ -204,7 +207,7 @@ static mancbs_t mancbs[] =
QSE_HTB_HASHER_DEFAULT
},
/* == QSE_HTB_MANCBS_INLINE_COPIERS == */
/* == QSE_HTB_STYLE_INLINE_COPIERS == */
{
{
QSE_HTB_COPIER_INLINE,
@ -220,7 +223,7 @@ static mancbs_t mancbs[] =
QSE_HTB_HASHER_DEFAULT
},
/* == QSE_HTB_MANCBS_INLINE_KEY_COPIER == */
/* == QSE_HTB_STYLE_INLINE_KEY_COPIER == */
{
{
QSE_HTB_COPIER_INLINE,
@ -236,7 +239,7 @@ static mancbs_t mancbs[] =
QSE_HTB_HASHER_DEFAULT
},
/* == QSE_HTB_MANCBS_INLINE_VALUE_COPIER == */
/* == QSE_HTB_STYLE_INLINE_VALUE_COPIER == */
{
{
QSE_HTB_COPIER_DEFAULT,
@ -253,9 +256,9 @@ static mancbs_t mancbs[] =
}
};
const mancbs_t* qse_gethtbmancbs (mancbs_kind_t kind)
const style_t* qse_gethtbstyle (style_kind_t kind)
{
return &mancbs[kind];
return &style[kind];
}
htb_t* qse_htb_open (
@ -318,7 +321,7 @@ int qse_htb_init (
htb->threshold = htb->capa * htb->factor / 100;
if (htb->capa > 0 && htb->threshold <= 0) htb->threshold = 1;
htb->mancbs = &mancbs[0];
htb->style = &style[0];
return 0;
}
@ -338,15 +341,15 @@ void* qse_htb_getxtn (qse_htb_t* htb)
return QSE_XTN (htb);
}
const mancbs_t* qse_htb_getmancbs (const htb_t* htb)
const style_t* qse_htb_getstyle (const htb_t* htb)
{
return htb->mancbs;
return htb->style;
}
void qse_htb_setmancbs (htb_t* htb, const mancbs_t* mancbs)
void qse_htb_setstyle (htb_t* htb, const style_t* style)
{
QSE_ASSERT (mancbs != QSE_NULL);
htb->mancbs = mancbs;
QSE_ASSERT (style != QSE_NULL);
htb->style = style;
}
size_t qse_htb_getsize (const htb_t* htb)
@ -364,12 +367,12 @@ pair_t* qse_htb_search (const htb_t* htb, const void* kptr, size_t klen)
pair_t* pair;
size_t hc;
hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa;
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
pair = htb->bucket[hc];
while (pair != QSE_NULL)
{
if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
{
return pair;
}
@ -385,9 +388,9 @@ static QSE_INLINE_ALWAYS int reorganize (htb_t* htb)
size_t i, hc, new_capa;
pair_t** new_buck;
if (htb->mancbs->sizer)
if (htb->style->sizer)
{
new_capa = htb->mancbs->sizer (htb, htb->capa + 1);
new_capa = htb->style->sizer (htb, htb->capa + 1);
/* if no change in capacity, return success
* without reorganization */
@ -423,7 +426,7 @@ static QSE_INLINE_ALWAYS int reorganize (htb_t* htb)
{
pair_t* next = NEXT(pair);
hc = htb->mancbs->hasher (htb,
hc = htb->style->hasher (htb,
KPTR(pair),
KLEN(pair)) % new_capa;
@ -454,7 +457,7 @@ static pair_t* insert (
pair_t* pair, * p, * prev, * next;
size_t hc;
hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa;
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
pair = htb->bucket[hc];
prev = QSE_NULL;
@ -462,7 +465,7 @@ static pair_t* insert (
{
next = NEXT(pair);
if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
{
/* found a pair with a matching key */
switch (opt)
@ -509,7 +512,7 @@ static pair_t* insert (
* more bucket collision and performance penalty. */
if (reorganize(htb) == 0)
{
hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa;
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
}
}
@ -556,7 +559,7 @@ pair_t* qse_htb_cbsert (
pair_t* pair, * p, * prev, * next;
size_t hc;
hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa;
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
pair = htb->bucket[hc];
prev = QSE_NULL;
@ -564,7 +567,7 @@ pair_t* qse_htb_cbsert (
{
next = NEXT(pair);
if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
{
/* found a pair with a matching key */
p = cbserter (htb, pair, kptr, klen, ctx);
@ -596,7 +599,7 @@ pair_t* qse_htb_cbsert (
* more bucket collision and performance penalty. */
if (reorganize(htb) == 0)
{
hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa;
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
}
}
@ -617,13 +620,13 @@ int qse_htb_delete (htb_t* htb, const void* kptr, size_t klen)
pair_t* pair, * prev;
size_t hc;
hc = htb->mancbs->hasher(htb,kptr,klen) % htb->capa;
hc = htb->style->hasher(htb,kptr,klen) % htb->capa;
pair = htb->bucket[hc];
prev = QSE_NULL;
while (pair != QSE_NULL)
{
if (htb->mancbs->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
if (htb->style->comper (htb, KPTR(pair), KLEN(pair), kptr, klen) == 0)
{
if (prev == QSE_NULL)
htb->bucket[hc] = NEXT(pair);

View File

@ -30,8 +30,8 @@
#define keeper_t qse_rbt_keeper_t
#define walker_t qse_rbt_walker_t
#define cbserter_t qse_rbt_cbserter_t
#define mancbs_t qse_rbt_mancbs_t
#define mancbs_kind_t qse_rbt_mancbs_kind_t
#define style_t qse_rbt_style_t
#define style_kind_t qse_rbt_style_kind_t
#define KPTR(p) QSE_RBT_KPTR(p)
#define KLEN(p) QSE_RBT_KLEN(p)
@ -64,8 +64,8 @@ QSE_INLINE pair_t* qse_rbt_allocpair (
{
pair_t* n;
copier_t kcop = rbt->mancbs->copier[QSE_RBT_KEY];
copier_t vcop = rbt->mancbs->copier[QSE_RBT_VAL];
copier_t kcop = rbt->style->copier[QSE_RBT_KEY];
copier_t vcop = rbt->style->copier[QSE_RBT_VAL];
size_t as = SIZEOF(pair_t);
if (kcop == QSE_RBT_COPIER_INLINE) as += KTOB(rbt,klen);
@ -116,8 +116,8 @@ QSE_INLINE pair_t* qse_rbt_allocpair (
VPTR(n) = vcop (rbt, vptr, vlen);
if (VPTR(n) != QSE_NULL)
{
if (rbt->mancbs->freeer[QSE_RBT_KEY] != QSE_NULL)
rbt->mancbs->freeer[QSE_RBT_KEY] (rbt, KPTR(n), KLEN(n));
if (rbt->style->freeer[QSE_RBT_KEY] != QSE_NULL)
rbt->style->freeer[QSE_RBT_KEY] (rbt, KPTR(n), KLEN(n));
QSE_MMGR_FREE (rbt->mmgr, n);
return QSE_NULL;
}
@ -128,14 +128,14 @@ QSE_INLINE pair_t* qse_rbt_allocpair (
QSE_INLINE void qse_rbt_freepair (rbt_t* rbt, pair_t* pair)
{
if (rbt->mancbs->freeer[QSE_RBT_KEY] != QSE_NULL)
rbt->mancbs->freeer[QSE_RBT_KEY] (rbt, KPTR(pair), KLEN(pair));
if (rbt->mancbs->freeer[QSE_RBT_VAL] != QSE_NULL)
rbt->mancbs->freeer[QSE_RBT_VAL] (rbt, VPTR(pair), VLEN(pair));
if (rbt->style->freeer[QSE_RBT_KEY] != QSE_NULL)
rbt->style->freeer[QSE_RBT_KEY] (rbt, KPTR(pair), KLEN(pair));
if (rbt->style->freeer[QSE_RBT_VAL] != QSE_NULL)
rbt->style->freeer[QSE_RBT_VAL] (rbt, VPTR(pair), VLEN(pair));
QSE_MMGR_FREE (rbt->mmgr, pair);
}
static mancbs_t mancbs[] =
static style_t style[] =
{
{
{
@ -190,9 +190,9 @@ static mancbs_t mancbs[] =
}
};
const mancbs_t* qse_getrbtmancbs (mancbs_kind_t kind)
const style_t* qse_getrbtstyle (style_kind_t kind)
{
return &mancbs[kind];
return &style[kind];
}
rbt_t* qse_rbt_open (mmgr_t* mmgr, size_t xtnsize, int kscale, int vscale)
@ -228,7 +228,7 @@ int qse_rbt_init (rbt_t* rbt, mmgr_t* mmgr, int kscale, int vscale)
rbt->scale[QSE_RBT_VAL] = (vscale < 1)? 1: vscale;
rbt->size = 0;
rbt->mancbs = &mancbs[0];
rbt->style = &style[0];
/* self-initializing nil */
QSE_MEMSET(&rbt->xnil, 0, QSE_SIZEOF(rbt->xnil));
@ -257,15 +257,15 @@ void* qse_rbt_getxtn (qse_rbt_t* rbt)
return QSE_XTN (rbt);
}
const mancbs_t* qse_rbt_getmancbs (const rbt_t* rbt)
const style_t* qse_rbt_getstyle (const rbt_t* rbt)
{
return rbt->mancbs;
return rbt->style;
}
void qse_rbt_setmancbs (rbt_t* rbt, const mancbs_t* mancbs)
void qse_rbt_setstyle (rbt_t* rbt, const style_t* style)
{
QSE_ASSERT (mancbs != QSE_NULL);
rbt->mancbs = mancbs;
QSE_ASSERT (style != QSE_NULL);
rbt->style = style;
}
size_t qse_rbt_getsize (const rbt_t* rbt)
@ -279,7 +279,7 @@ pair_t* qse_rbt_search (const rbt_t* rbt, const void* kptr, size_t klen)
while (!IS_NIL(rbt,pair))
{
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(pair), KLEN(pair));
int n = rbt->style->comper (rbt, kptr, klen, KPTR(pair), KLEN(pair));
if (n == 0) return pair;
if (n > 0) pair = pair->right;
@ -429,14 +429,14 @@ static pair_t* change_pair_val (
/* if the old value and the new value are the same,
* it just calls the handler for this condition.
* No value replacement occurs. */
if (rbt->mancbs->keeper != QSE_NULL)
if (rbt->style->keeper != QSE_NULL)
{
rbt->mancbs->keeper (rbt, vptr, vlen);
rbt->style->keeper (rbt, vptr, vlen);
}
}
else
{
copier_t vcop = rbt->mancbs->copier[QSE_RBT_VAL];
copier_t vcop = rbt->style->copier[QSE_RBT_VAL];
void* ovptr = VPTR(pair);
size_t ovlen = VLEN(pair);
@ -495,9 +495,9 @@ static pair_t* change_pair_val (
}
/* free up the old value */
if (rbt->mancbs->freeer[QSE_RBT_VAL] != QSE_NULL)
if (rbt->style->freeer[QSE_RBT_VAL] != QSE_NULL)
{
rbt->mancbs->freeer[QSE_RBT_VAL] (rbt, ovptr, ovlen);
rbt->style->freeer[QSE_RBT_VAL] (rbt, ovptr, ovlen);
}
}
@ -513,7 +513,7 @@ static pair_t* insert (
while (!IS_NIL(rbt,x_cur))
{
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur));
int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur));
if (n == 0)
{
switch (opt)
@ -552,7 +552,7 @@ static pair_t* insert (
else
{
/* perform normal binary insert */
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par));
int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par));
if (n > 0)
{
QSE_ASSERT (x_par->right == &rbt->xnil);
@ -607,7 +607,7 @@ pair_t* qse_rbt_cbsert (
while (!IS_NIL(rbt,x_cur))
{
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur));
int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_cur), KLEN(x_cur));
if (n == 0)
{
/* back up the contents of the current pair
@ -672,7 +672,7 @@ pair_t* qse_rbt_cbsert (
else
{
/* perform normal binary insert */
int n = rbt->mancbs->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par));
int n = rbt->style->comper (rbt, kptr, klen, KPTR(x_par), KLEN(x_par));
if (n > 0)
{
QSE_ASSERT (x_par->right == &rbt->xnil);