added the hio-webs command

added the extension size parameter to hio_svc_htts_start()
added the docker build step
This commit is contained in:
2022-10-07 14:08:40 +09:00
parent 384925992c
commit 913bb7e0b7
15 changed files with 343 additions and 31 deletions

View File

@ -7,8 +7,16 @@ CPPFLAGS_COMMON = \
-I$(abs_srcdir)/../lib \
-I$(includedir)
CFLAGS_COMMON =
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
LIBADD_COMMON = ../lib/libhio.la
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
LIBADD_COMMON = ../lib/libhio.la
if ENABLE_ALL_STATIC
LDFLAGS_ALL_STATIC = -all-static
LIBADD_ALL_STATIC = -ldl -lm ## TODO: this may very depending on platforms
else
LDFLAGS_ALL_STATIC =
LIBADD_ALL_STATIC =
endif
bin_PROGRAMS = hio-execd
hio_execd_SOURCES = execd.c
@ -72,3 +80,10 @@ hio_t06_CPPFLAGS = $(CPPFLAGS_COMMON)
hio_t06_CFLAGS = $(CFLAGS_COMMON)
hio_t06_LDFLAGS = $(LDFLAGS_COMMON)
hio_t06_LDADD = $(LIBADD_COMMON)
bin_PROGRAMS += hio-webs
hio_webs_SOURCES = webs.c
hio_webs_CPPFLAGS = $(CPPFLAGS_COMMON)
hio_webs_CFLAGS = $(CFLAGS_COMMON)
hio_webs_LDFLAGS = $(LDFLAGS_COMMON) $(LDFLAGS_ALL_STATIC)
hio_webs_LDADD = $(LIBADD_COMMON) $(LIBADD_ALL_STATIC)

View File

@ -90,7 +90,7 @@ build_triplet = @build@
host_triplet = @host@
bin_PROGRAMS = hio-execd$(EXEEXT) $(am__EXEEXT_1) hio-t01$(EXEEXT) \
hio-t02$(EXEEXT) hio-t03$(EXEEXT) hio-t04$(EXEEXT) \
hio-t05$(EXEEXT) hio-t06$(EXEEXT)
hio-t05$(EXEEXT) hio-t06$(EXEEXT) hio-webs$(EXEEXT)
@HAVE_X11_LIB_TRUE@am__append_1 = hio-te
@ENABLE_MARIADB_TRUE@am__append_2 = $(MARIADB_CFLAGS)
@ENABLE_MARIADB_TRUE@am__append_3 = $(MARIADB_LDFLAGS)
@ -168,6 +168,12 @@ hio_te_OBJECTS = $(am_hio_te_OBJECTS)
hio_te_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(hio_te_CFLAGS) $(CFLAGS) \
$(hio_te_LDFLAGS) $(LDFLAGS) -o $@
am_hio_webs_OBJECTS = hio_webs-webs.$(OBJEXT)
hio_webs_OBJECTS = $(am_hio_webs_OBJECTS)
hio_webs_DEPENDENCIES = $(LIBADD_COMMON) $(am__DEPENDENCIES_1)
hio_webs_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(hio_webs_CFLAGS) \
$(CFLAGS) $(hio_webs_LDFLAGS) $(LDFLAGS) -o $@
AM_V_P = $(am__v_P_@AM_V@)
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
am__v_P_0 = false
@ -187,7 +193,7 @@ am__depfiles_remade = ./$(DEPDIR)/hio_execd-execd.Po \
./$(DEPDIR)/hio_t01-t01.Po ./$(DEPDIR)/hio_t02-t02.Po \
./$(DEPDIR)/hio_t03-t03.Po ./$(DEPDIR)/hio_t04-t04.Po \
./$(DEPDIR)/hio_t05-t05.Po ./$(DEPDIR)/hio_t06-t06.Po \
./$(DEPDIR)/hio_te-te.Po
./$(DEPDIR)/hio_te-te.Po ./$(DEPDIR)/hio_webs-webs.Po
am__mv = mv -f
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
@ -209,11 +215,11 @@ am__v_CCLD_0 = @echo " CCLD " $@;
am__v_CCLD_1 =
SOURCES = $(hio_execd_SOURCES) $(hio_t01_SOURCES) $(hio_t02_SOURCES) \
$(hio_t03_SOURCES) $(hio_t04_SOURCES) $(hio_t05_SOURCES) \
$(hio_t06_SOURCES) $(hio_te_SOURCES)
$(hio_t06_SOURCES) $(hio_te_SOURCES) $(hio_webs_SOURCES)
DIST_SOURCES = $(hio_execd_SOURCES) $(hio_t01_SOURCES) \
$(hio_t02_SOURCES) $(hio_t03_SOURCES) $(hio_t04_SOURCES) \
$(hio_t05_SOURCES) $(hio_t06_SOURCES) \
$(am__hio_te_SOURCES_DIST)
$(am__hio_te_SOURCES_DIST) $(hio_webs_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
@ -388,8 +394,12 @@ CPPFLAGS_COMMON = \
-I$(includedir)
CFLAGS_COMMON =
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
LIBADD_COMMON = ../lib/libhio.la
LDFLAGS_COMMON = -L$(abs_builddir)/../lib -L$(libdir)
LIBADD_COMMON = ../lib/libhio.la
@ENABLE_ALL_STATIC_FALSE@LDFLAGS_ALL_STATIC =
@ENABLE_ALL_STATIC_TRUE@LDFLAGS_ALL_STATIC = -all-static
@ENABLE_ALL_STATIC_FALSE@LIBADD_ALL_STATIC =
@ENABLE_ALL_STATIC_TRUE@LIBADD_ALL_STATIC = -ldl -lm ## TODO: this may very depending on platforms
hio_execd_SOURCES = execd.c
hio_execd_CPPFLAGS = $(CPPFLAGS_COMMON)
hio_execd_CFLAGS = $(CFLAGS_COMMON)
@ -430,6 +440,11 @@ hio_t06_CPPFLAGS = $(CPPFLAGS_COMMON)
hio_t06_CFLAGS = $(CFLAGS_COMMON)
hio_t06_LDFLAGS = $(LDFLAGS_COMMON)
hio_t06_LDADD = $(LIBADD_COMMON)
hio_webs_SOURCES = webs.c
hio_webs_CPPFLAGS = $(CPPFLAGS_COMMON)
hio_webs_CFLAGS = $(CFLAGS_COMMON)
hio_webs_LDFLAGS = $(LDFLAGS_COMMON) $(LDFLAGS_ALL_STATIC)
hio_webs_LDADD = $(LIBADD_COMMON) $(LIBADD_ALL_STATIC)
all: all-am
.SUFFIXES:
@ -545,6 +560,10 @@ hio-te$(EXEEXT): $(hio_te_OBJECTS) $(hio_te_DEPENDENCIES) $(EXTRA_hio_te_DEPENDE
@rm -f hio-te$(EXEEXT)
$(AM_V_CCLD)$(hio_te_LINK) $(hio_te_OBJECTS) $(hio_te_LDADD) $(LIBS)
hio-webs$(EXEEXT): $(hio_webs_OBJECTS) $(hio_webs_DEPENDENCIES) $(EXTRA_hio_webs_DEPENDENCIES)
@rm -f hio-webs$(EXEEXT)
$(AM_V_CCLD)$(hio_webs_LINK) $(hio_webs_OBJECTS) $(hio_webs_LDADD) $(LIBS)
mostlyclean-compile:
-rm -f *.$(OBJEXT)
@ -559,6 +578,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_t05-t05.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_t06-t06.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_te-te.Po@am__quote@ # am--include-marker
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/hio_webs-webs.Po@am__quote@ # am--include-marker
$(am__depfiles_remade):
@$(MKDIR_P) $(@D)
@ -702,6 +722,20 @@ hio_te-te.obj: te.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_te_CPPFLAGS) $(CPPFLAGS) $(hio_te_CFLAGS) $(CFLAGS) -c -o hio_te-te.obj `if test -f 'te.c'; then $(CYGPATH_W) 'te.c'; else $(CYGPATH_W) '$(srcdir)/te.c'; fi`
hio_webs-webs.o: webs.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_webs_CPPFLAGS) $(CPPFLAGS) $(hio_webs_CFLAGS) $(CFLAGS) -MT hio_webs-webs.o -MD -MP -MF $(DEPDIR)/hio_webs-webs.Tpo -c -o hio_webs-webs.o `test -f 'webs.c' || echo '$(srcdir)/'`webs.c
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hio_webs-webs.Tpo $(DEPDIR)/hio_webs-webs.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='webs.c' object='hio_webs-webs.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_webs_CPPFLAGS) $(CPPFLAGS) $(hio_webs_CFLAGS) $(CFLAGS) -c -o hio_webs-webs.o `test -f 'webs.c' || echo '$(srcdir)/'`webs.c
hio_webs-webs.obj: webs.c
@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_webs_CPPFLAGS) $(CPPFLAGS) $(hio_webs_CFLAGS) $(CFLAGS) -MT hio_webs-webs.obj -MD -MP -MF $(DEPDIR)/hio_webs-webs.Tpo -c -o hio_webs-webs.obj `if test -f 'webs.c'; then $(CYGPATH_W) 'webs.c'; else $(CYGPATH_W) '$(srcdir)/webs.c'; fi`
@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hio_webs-webs.Tpo $(DEPDIR)/hio_webs-webs.Po
@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='webs.c' object='hio_webs-webs.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_webs_CPPFLAGS) $(CPPFLAGS) $(hio_webs_CFLAGS) $(CFLAGS) -c -o hio_webs-webs.obj `if test -f 'webs.c'; then $(CYGPATH_W) 'webs.c'; else $(CYGPATH_W) '$(srcdir)/webs.c'; fi`
mostlyclean-libtool:
-rm -f *.lo
@ -843,6 +877,7 @@ distclean: distclean-am
-rm -f ./$(DEPDIR)/hio_t05-t05.Po
-rm -f ./$(DEPDIR)/hio_t06-t06.Po
-rm -f ./$(DEPDIR)/hio_te-te.Po
-rm -f ./$(DEPDIR)/hio_webs-webs.Po
-rm -f Makefile
distclean-am: clean-am distclean-compile distclean-generic \
distclean-tags
@ -896,6 +931,7 @@ maintainer-clean: maintainer-clean-am
-rm -f ./$(DEPDIR)/hio_t05-t05.Po
-rm -f ./$(DEPDIR)/hio_t06-t06.Po
-rm -f ./$(DEPDIR)/hio_te-te.Po
-rm -f ./$(DEPDIR)/hio_webs-webs.Po
-rm -f Makefile
maintainer-clean-am: distclean-am maintainer-clean-generic

View File

@ -1245,7 +1245,7 @@ for (i = 0; i < 5; i++)
HIO_INFO1 (hio, "UNABLE TO START DNC - %js\n", hio_geterrmsg(hio));
}
htts = hio_svc_htts_start(hio, &htts_bind_info, 1, process_http_request);
htts = hio_svc_htts_start(hio, 0, &htts_bind_info, 1, process_http_request);
if (htts) hio_svc_htts_setservernamewithbcstr (htts, "HIO-HTTP");
else HIO_INFO1 (hio, "UNABLE TO START HTTS - %js\n", hio_geterrmsg(hio));

View File

@ -252,7 +252,7 @@ void* thr_func (void* arg)
htts_bind_info[1].ssl_keyfile = "localhost.key";
#endif
htts = hio_svc_htts_start(hio, htts_bind_info, HIO_COUNTOF(htts_bind_info), process_http_request);
htts = hio_svc_htts_start(hio, 0, htts_bind_info, HIO_COUNTOF(htts_bind_info), process_http_request);
if (!htts)
{
printf ("Unable to start htts\n");

152
bin/webs.c Normal file
View File

@ -0,0 +1,152 @@
#include <hio-http.h>
#include <signal.h>
#include <string.h>
#include <stdio.h>
struct htts_ext_t
{
const hio_bch_t* docroot;
};
typedef struct htts_ext_t htts_ext_t;
static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req)
{
htts_ext_t* ext = hio_svc_htts_getxtn(htts);
hio_http_method_t mth;
const hio_bch_t* qpath;
hio_htre_perdecqpath (req);
mth = hio_htre_getqmethodtype(req);
qpath = hio_htre_getqpath(req);
if (mth == HIO_HTTP_GET)
{
/* TODO: mime-type */
if (hio_svc_htts_dofile(htts, csck, req, ext->docroot, qpath, "text/plain") <= -1) goto oops;
}
else
{
if (hio_svc_htts_dotxt(htts, csck, req, 403, "text/plain", hio_http_status_to_bcstr(403)) <= -1) goto oops;
}
return 0;
oops:
hio_dev_sck_halt (csck);
return 0;
}
int webs_start (hio_t* hio, const hio_bch_t* addrs, const hio_bch_t* docroot)
{
const hio_bch_t* ptr, * end;
hio_bcs_t tok;
hio_dev_sck_bind_t bi[100];
hio_oow_t bic;
hio_svc_htts_t* webs;
htts_ext_t* ext;
bic = 0;
ptr = addrs;
end = ptr + hio_count_bcstr(ptr);
while (ptr)
{
ptr = hio_tokenize_bchars(ptr, end - ptr, ", ", 2, &tok, 0);
if (tok.len > 0)
{
if (hio_bcharstoskad(hio, tok.ptr, tok.len, &bi[bic].localaddr) <= -1)
{
/* TODO: logging */
continue;
}
bi[bic].options = HIO_DEV_SCK_BIND_REUSEADDR | HIO_DEV_SCK_BIND_REUSEPORT | HIO_DEV_SCK_BIND_IGNERR;
bic++;
if (bic >= HIO_COUNTOF(bi)) break; /* TODO: make 'bi' dynamic */
}
}
webs = hio_svc_htts_start(hio, HIO_SIZEOF(htts_ext_t), bi, bic, process_http_request);
if (!webs) return -1; /* TODO: logging */
ext = hio_svc_htts_getxtn(webs);
ext->docroot = docroot;
return 0;
}
static hio_t* g_hio = HIO_NULL;
static void handle_sigint (int sig)
{
if (g_hio) hio_stop (g_hio, HIO_STOPREQ_TERMINATION);
}
int main (int argc, char* argv[])
{
hio_t* hio = HIO_NULL;
hio_oow_t i;
struct sigaction sigact;
int xret = -1;
#if 0
// TODO: use getopt() or something similar
for (i = 1; i < argc; )
{
if (strcmp(argv[i], "-s") == 0)
{
i++;
g_dev_type4 = HIO_DEV_SCK_SCTP4;
g_dev_type6 = HIO_DEV_SCK_SCTP6;
}
else
{
printf ("Error: invalid argument %s\n", argv[i]);
return -1;
}
}
#else
if (argc < 3)
{
printf ("Error: %s listen-address doc-root\n", hio_get_base_name_bcstr(argv[0]));
return -1;
}
#endif
memset (&sigact, 0, HIO_SIZEOF(sigact));
sigact.sa_handler = SIG_IGN;
sigaction (SIGPIPE, &sigact, HIO_NULL);
memset (&sigact, 0, HIO_SIZEOF(sigact));
sigact.sa_handler = handle_sigint;
sigaction (SIGINT, &sigact, HIO_NULL);
hio = hio_open(HIO_NULL, 0, HIO_NULL, HIO_FEATURE_ALL, 512, HIO_NULL);
if (!hio)
{
printf ("Cannot open hio\n");
goto oops;
}
hio_setoption (hio, HIO_LOG_TARGET_BCSTR, "/dev/stderr");
g_hio = hio;
if (webs_start(hio, argv[1], argv[2]) <= -1) goto oops;
hio_loop (hio);
g_hio = HIO_NULL;
xret = 0;
oops:
memset (&sigact, 0, HIO_SIZEOF(sigact));
sigact.sa_handler = SIG_IGN;
sigaction (SIGINT, &sigact, HIO_NULL);
if (hio) hio_close (hio);
return xret;
}