added qse_awk_pushecb()/qse_awk_popecb()/qse_sed_pushecb()/qse_sed_popecb()/qse_httpd_pushecb()/qse_httpd_popecb().

started reorganizing samples/httpd01 to net/httpd-std.c
This commit is contained in:
2012-09-07 15:13:55 +00:00
parent 69b118fcbf
commit ea3ebef8f1
16 changed files with 1930 additions and 64 deletions

View File

@ -262,8 +262,14 @@ oops:
int qse_awk_close (qse_awk_t* awk)
{
qse_awk_ecb_t* ecb;
if (qse_awk_clear (awk) <= -1) return -1;
/*qse_awk_clrfnc (awk);*/
for (ecb = awk->ecb; ecb; ecb = ecb->next)
if (ecb->close) ecb->close (awk);
qse_htb_close (awk->fnc.user);
qse_lda_close (awk->parse.params);
@ -287,6 +293,11 @@ int qse_awk_close (qse_awk_t* awk)
int qse_awk_clear (qse_awk_t* awk)
{
qse_awk_ecb_t* ecb;
for (ecb = awk->ecb; ecb; ecb = ecb->next)
if (ecb->clear) ecb->clear (awk);
awk->stopall = QSE_FALSE;
clear_token (&awk->tok);
@ -439,3 +450,18 @@ void qse_awk_setmaxdepth (qse_awk_t* awk, int types, qse_size_t depth)
awk->parse.depth.max.incl = depth;
}
}
qse_awk_ecb_t* qse_awk_popecb (qse_awk_t* awk)
{
qse_awk_ecb_t* top = awk->ecb;
if (top) awk->ecb = top->next;
return top;
}
void qse_awk_pushecb (qse_awk_t* awk, qse_awk_ecb_t* ecb)
{
ecb->next = awk->ecb;
awk->ecb = ecb;
}

View File

@ -235,6 +235,7 @@ struct qse_awk_t
qse_awk_errinf_t errinf;
qse_bool_t stopall;
qse_awk_ecb_t* ecb;
};
struct qse_awk_chain_t
@ -371,7 +372,7 @@ struct qse_awk_rtx_t
qse_awk_errinf_t errinf;
qse_awk_t* awk;
qse_awk_rcb_t* rcb;
qse_awk_rtx_ecb_t* ecb;
};

View File

@ -744,10 +744,10 @@ qse_awk_rtx_t* qse_awk_rtx_open (
void qse_awk_rtx_close (qse_awk_rtx_t* rtx)
{
qse_awk_rcb_t* rcb;
qse_awk_rtx_ecb_t* ecb;
for (rcb = rtx->rcb; rcb; rcb = rcb->next)
if (rcb->close) rcb->close (rtx, rcb->ctx);
for (ecb = rtx->ecb; ecb; ecb = ecb->next)
if (ecb->close) ecb->close (rtx);
/* NOTE:
* the close callbacks are called before data in rtx
@ -784,17 +784,17 @@ void qse_awk_rtx_setrio (qse_awk_rtx_t* rtx, const qse_awk_rio_t* rio)
rtx->rio.handler[QSE_AWK_RIO_CONSOLE] = rio->console;
}
qse_awk_rcb_t* qse_awk_rtx_poprcb (qse_awk_rtx_t* rtx)
qse_awk_rtx_ecb_t* qse_awk_rtx_popecb (qse_awk_rtx_t* rtx)
{
qse_awk_rcb_t* top = rtx->rcb;
if (top) rtx->rcb = top->next;
qse_awk_rtx_ecb_t* top = rtx->ecb;
if (top) rtx->ecb = top->next;
return top;
}
void qse_awk_rtx_pushrcb (qse_awk_rtx_t* rtx, qse_awk_rcb_t* rcb)
void qse_awk_rtx_pushecb (qse_awk_rtx_t* rtx, qse_awk_rtx_ecb_t* ecb)
{
rcb->next = rtx->rcb;
rtx->rcb = rcb;
ecb->next = rtx->ecb;
rtx->ecb = ecb;
}
static void free_namedval (qse_htb_t* map, void* dptr, qse_size_t dlen)
@ -1826,10 +1826,10 @@ static int run_block0 (qse_awk_rtx_t* rtx, qse_awk_nde_blk_t* nde)
}
#define ON_STATEMENT(rtx,nde) QSE_BLOCK ( \
qse_awk_rcb_t* rcb; \
qse_awk_rtx_ecb_t* ecb; \
if ((rtx)->awk->stopall) (rtx)->exit_level = EXIT_ABORT; \
for (rcb = (rtx)->rcb; rcb; rcb = rcb->next) \
if (rcb->stmt) rcb->stmt (rtx, nde, rcb->ctx); \
for (ecb = (rtx)->ecb; ecb; ecb = ecb->next) \
if (ecb->stmt) ecb->stmt (rtx, nde); \
)
static int run_statement (qse_awk_rtx_t* rtx, qse_awk_nde_t* nde)

View File

@ -1478,7 +1478,7 @@ static qse_ssize_t awk_rio_console (
return -1;
}
static void fini_rxtn (qse_awk_rtx_t* rtx, void* ctx)
static void fini_rxtn (qse_awk_rtx_t* rtx)
{
rxtn_t* rxtn = (rxtn_t*) QSE_XTN (rtx);
@ -1876,11 +1876,10 @@ qse_awk_rtx_t* qse_awk_rtx_openstd (
const qse_char_t*const ocf[],
qse_cmgr_t* cmgr)
{
static qse_awk_rcb_t rcb =
static qse_awk_rtx_ecb_t ecb =
{
fini_rxtn,
QSE_NULL,
QSE_NULL
QSE_FV (.close, fini_rxtn),
QSE_FV (.stmt, QSE_NULL)
};
qse_awk_rtx_t* rtx;
@ -1921,7 +1920,7 @@ qse_awk_rtx_t* qse_awk_rtx_openstd (
rxtn->cmgrtab_inited = 1;
}
qse_awk_rtx_pushrcb (rtx, &rcb);
qse_awk_rtx_pushecb (rtx, &ecb);
rxtn->seed = (qse_gettime (&now) <= -1)? 0u: (qse_long_t)now;
/* i don't care if the seed becomes negative or overflows.

View File

@ -16,6 +16,7 @@ libqsenet_la_SOURCES = \
httpd-cgi.c \
httpd-proxy.c \
httpd-resol.c \
httpd-std.c \
httpd-task.c \
upxd.c

View File

@ -79,8 +79,8 @@ am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES)
libqsenet_la_DEPENDENCIES =
am_libqsenet_la_OBJECTS = http.lo htre.lo htrd.lo httpd.lo \
httpd-cgi.lo httpd-proxy.lo httpd-resol.lo httpd-task.lo \
upxd.lo
httpd-cgi.lo httpd-proxy.lo httpd-resol.lo httpd-std.lo \
httpd-task.lo upxd.lo
libqsenet_la_OBJECTS = $(am_libqsenet_la_OBJECTS)
libqsenet_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@ -273,6 +273,7 @@ libqsenet_la_SOURCES = \
httpd-cgi.c \
httpd-proxy.c \
httpd-resol.c \
httpd-std.c \
httpd-task.c \
upxd.c
@ -358,6 +359,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpd-cgi.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpd-proxy.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpd-resol.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpd-std.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpd-task.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/httpd.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/upxd.Plo@am__quote@

1627
qse/lib/net/httpd-std.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -84,6 +84,11 @@ qse_httpd_t* qse_httpd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
void qse_httpd_close (qse_httpd_t* httpd)
{
qse_httpd_ecb_t* ecb;
for (ecb = httpd->ecb; ecb; ecb = ecb->next)
if (ecb->close) ecb->close (httpd);
qse_httpd_fini (httpd);
QSE_MMGR_FREE (httpd->mmgr, httpd);
}
@ -128,6 +133,23 @@ void qse_httpd_setoption (qse_httpd_t* httpd, int option)
httpd->option = option;
}
/* --------------------------------------------------- */
qse_httpd_ecb_t* qse_httpd_popecb (qse_httpd_t* httpd)
{
qse_httpd_ecb_t* top = httpd->ecb;
if (top) httpd->ecb = top->next;
return top;
}
void qse_httpd_pushecb (qse_httpd_t* httpd, qse_httpd_ecb_t* ecb)
{
ecb->next = httpd->ecb;
httpd->ecb = ecb;
}
/* --------------------------------------------------- */
QSE_INLINE void* qse_httpd_allocmem (qse_httpd_t* httpd, qse_size_t size)
{
void* ptr = QSE_MMGR_ALLOC (httpd->mmgr, size);

View File

@ -29,7 +29,8 @@ struct qse_httpd_t
{
QSE_DEFINE_COMMON_FIELDS (httpd)
qse_httpd_errnum_t errnum;
qse_httpd_cbs_t* cbs;
qse_httpd_ecb_t* ecb; /* event callbacks */
qse_httpd_cbs_t* cbs;
int option;
int stopreq;

View File

@ -75,6 +75,11 @@ qse_sed_t* qse_sed_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
void qse_sed_close (qse_sed_t* sed)
{
qse_sed_ecb_t* ecb;
for (ecb = sed->ecb; ecb; ecb = ecb->next)
if (ecb->close) ecb->close (sed);
qse_sed_fini (sed);
QSE_MMGR_FREE (sed->mmgr, sed);
}
@ -4142,6 +4147,19 @@ void qse_sed_setlinenum (qse_sed_t* sed, qse_size_t num)
sed->e.in.num = num;
}
qse_sed_ecb_t* qse_sed_popecb (qse_sed_t* sed)
{
qse_sed_ecb_t* top = sed->ecb;
if (top) sed->ecb = top->next;
return top;
}
void qse_sed_pushecb (qse_sed_t* sed, qse_sed_ecb_t* ecb)
{
ecb->next = sed->ecb;
sed->ecb = ecb;
}
#ifdef QSE_ENABLE_SEDTRACER
qse_sed_exec_tracer_t qse_sed_getexectracer (qse_sed_t* sed)
{

View File

@ -99,6 +99,8 @@ struct qse_sed_t
} rex;
} depth;
qse_sed_ecb_t* ecb;
/** source text pointers */
struct
{