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:
parent
384925992c
commit
913bb7e0b7
6
Dockerfile.in
Normal file
6
Dockerfile.in
Normal file
@ -0,0 +1,6 @@
|
||||
FROM scratch
|
||||
|
||||
COPY bin/hio-webs /bin
|
||||
RUN mkdir -p /data
|
||||
|
||||
CMD [ "/bin/hio-webs", "0.0.0.0:80", "/data" ]
|
@ -19,3 +19,5 @@ rpm: dist-gzip
|
||||
cp @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz "@abs_builddir@/pkgs/RPM/SOURCES"
|
||||
rpmbuild --define "_topdir @abs_builddir@/pkgs/RPM" -ba @abs_builddir@/pkgs/hio.spec --target=@build_cpu@
|
||||
|
||||
docker:
|
||||
docker -t hio:webs Dockerfile .
|
||||
|
21
Makefile.in
21
Makefile.in
@ -103,7 +103,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
|
||||
configure.lineno config.status.lineno
|
||||
mkinstalldirs = $(install_sh) -d
|
||||
CONFIG_HEADER = $(top_builddir)/lib/hio-cfg.h
|
||||
CONFIG_CLEAN_FILES = pkgs/hio.spec
|
||||
CONFIG_CLEAN_FILES = Dockerfile pkgs/hio.spec
|
||||
CONFIG_CLEAN_VPATH_FILES =
|
||||
AM_V_P = $(am__v_P_@AM_V@)
|
||||
am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
|
||||
@ -160,13 +160,13 @@ am__define_uniq_tagged_files = \
|
||||
ETAGS = etags
|
||||
CTAGS = ctags
|
||||
CSCOPE = cscope
|
||||
am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/ar-lib \
|
||||
$(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \
|
||||
$(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \
|
||||
$(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing \
|
||||
$(top_srcdir)/pkgs/hio.spec.in ac/ar-lib ac/compile \
|
||||
ac/config.guess ac/config.sub ac/depcomp ac/install-sh \
|
||||
ac/ltmain.sh ac/missing
|
||||
am__DIST_COMMON = $(srcdir)/Dockerfile.in $(srcdir)/Makefile.in \
|
||||
$(top_srcdir)/ac/ar-lib $(top_srcdir)/ac/compile \
|
||||
$(top_srcdir)/ac/config.guess $(top_srcdir)/ac/config.sub \
|
||||
$(top_srcdir)/ac/install-sh $(top_srcdir)/ac/ltmain.sh \
|
||||
$(top_srcdir)/ac/missing $(top_srcdir)/pkgs/hio.spec.in \
|
||||
ac/ar-lib ac/compile ac/config.guess ac/config.sub ac/depcomp \
|
||||
ac/install-sh ac/ltmain.sh ac/missing
|
||||
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
|
||||
distdir = $(PACKAGE)-$(VERSION)
|
||||
top_distdir = $(distdir)
|
||||
@ -389,6 +389,8 @@ $(top_srcdir)/configure: $(am__configure_deps)
|
||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||
$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
|
||||
$(am__aclocal_m4_deps):
|
||||
Dockerfile: $(top_builddir)/config.status $(srcdir)/Dockerfile.in
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $@
|
||||
pkgs/hio.spec: $(top_builddir)/config.status $(top_srcdir)/pkgs/hio.spec.in
|
||||
cd $(top_builddir) && $(SHELL) ./config.status $@
|
||||
|
||||
@ -838,6 +840,9 @@ rpm: dist-gzip
|
||||
cp @PACKAGE_NAME@-@PACKAGE_VERSION@.tar.gz "@abs_builddir@/pkgs/RPM/SOURCES"
|
||||
rpmbuild --define "_topdir @abs_builddir@/pkgs/RPM" -ba @abs_builddir@/pkgs/hio.spec --target=@build_cpu@
|
||||
|
||||
docker:
|
||||
docker -t hio:webs Dockerfile .
|
||||
|
||||
# Tell versions [3.59,3.63) of GNU make to not export all variables.
|
||||
# Otherwise a system limit (for SysV at least) may be exceeded.
|
||||
.NOEXPORT:
|
||||
|
@ -10,6 +10,14 @@ CFLAGS_COMMON =
|
||||
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
|
||||
hio_execd_CPPFLAGS = $(CPPFLAGS_COMMON)
|
||||
@ -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)
|
||||
|
@ -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;; \
|
||||
@ -390,6 +396,10 @@ CPPFLAGS_COMMON = \
|
||||
CFLAGS_COMMON =
|
||||
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
|
||||
|
||||
|
@ -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));
|
||||
|
||||
|
@ -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
152
bin/webs.c
Normal 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;
|
||||
}
|
||||
|
27
configure
vendored
27
configure
vendored
@ -657,6 +657,8 @@ ENABLE_MARIADB_TRUE
|
||||
ENABLE_SSL_FALSE
|
||||
ENABLE_SSL_TRUE
|
||||
SSL_LIBS
|
||||
ENABLE_ALL_STATIC_FALSE
|
||||
ENABLE_ALL_STATIC_TRUE
|
||||
UNICOWS_LIBS
|
||||
PTHREAD_CFLAGS
|
||||
PTHREAD_LIBS
|
||||
@ -798,6 +800,7 @@ with_gnu_ld
|
||||
with_sysroot
|
||||
enable_libtool_lock
|
||||
enable_largefile
|
||||
enable_all_static
|
||||
enable_ssl
|
||||
enable_mariadb
|
||||
with_mariadb
|
||||
@ -1457,6 +1460,7 @@ Optional Features:
|
||||
optimize for fast installation [default=yes]
|
||||
--disable-libtool-lock avoid locking (might break parallel builds)
|
||||
--disable-largefile omit support for large files
|
||||
--enable-all-static build the full static binaries(default. no)
|
||||
--enable-ssl build the library in the ssl mode (default. yes)
|
||||
--enable-mariadb enable mariadb support (default. no)
|
||||
--enable-debug build the library in the debug mode (default. no)
|
||||
@ -15506,6 +15510,22 @@ fi
|
||||
|
||||
|
||||
|
||||
# Check whether --enable-all-static was given.
|
||||
if test "${enable_all_static+set}" = set; then :
|
||||
enableval=$enable_all_static; enable_all_static_is=$enableval
|
||||
else
|
||||
enable_all_static_is=no
|
||||
fi
|
||||
|
||||
if test "x${enable_all_static_is}" = "xyes"; then
|
||||
ENABLE_ALL_STATIC_TRUE=
|
||||
ENABLE_ALL_STATIC_FALSE='#'
|
||||
else
|
||||
ENABLE_ALL_STATIC_TRUE='#'
|
||||
ENABLE_ALL_STATIC_FALSE=
|
||||
fi
|
||||
|
||||
|
||||
# Check whether --enable-ssl was given.
|
||||
if test "${enable_ssl+set}" = set; then :
|
||||
enableval=$enable_ssl; enable_ssl_is=$enableval
|
||||
@ -19279,7 +19299,7 @@ HIO_PROJECT_AUTHOR="${PACKAGE_BUGREPORT}"
|
||||
HIO_PROJECT_URL="${PACKAGE_URL}"
|
||||
|
||||
|
||||
ac_config_files="$ac_config_files Makefile lib/Makefile bin/Makefile t/Makefile pkgs/hio.spec"
|
||||
ac_config_files="$ac_config_files Makefile Dockerfile lib/Makefile bin/Makefile t/Makefile pkgs/hio.spec"
|
||||
|
||||
cat >confcache <<\_ACEOF
|
||||
# This file is a shell script that caches the results of configure
|
||||
@ -19426,6 +19446,10 @@ if test -z "${MACOSX_TRUE}" && test -z "${MACOSX_FALSE}"; then
|
||||
as_fn_error $? "conditional \"MACOSX\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
if test -z "${ENABLE_ALL_STATIC_TRUE}" && test -z "${ENABLE_ALL_STATIC_FALSE}"; then
|
||||
as_fn_error $? "conditional \"ENABLE_ALL_STATIC\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
if test -z "${ENABLE_SSL_TRUE}" && test -z "${ENABLE_SSL_FALSE}"; then
|
||||
as_fn_error $? "conditional \"ENABLE_SSL\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
@ -20323,6 +20347,7 @@ do
|
||||
"depfiles") CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
|
||||
"libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
|
||||
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||
"Dockerfile") CONFIG_FILES="$CONFIG_FILES Dockerfile" ;;
|
||||
"lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;;
|
||||
"bin/Makefile") CONFIG_FILES="$CONFIG_FILES bin/Makefile" ;;
|
||||
"t/Makefile") CONFIG_FILES="$CONFIG_FILES t/Makefile" ;;
|
||||
|
@ -248,6 +248,11 @@ dnl the existence of the libaray.
|
||||
AC_CHECK_LIB([unicows], [main], [UNICOWS_LIBS="-lunicows"])
|
||||
AC_SUBST(UNICOWS_LIBS)
|
||||
|
||||
dnl ===== enable-all-static =====
|
||||
AC_ARG_ENABLE([all-static], [AS_HELP_STRING([--enable-all-static],[build the full static binaries(default. no)])],
|
||||
enable_all_static_is=$enableval,enable_all_static_is=no)
|
||||
AM_CONDITIONAL(ENABLE_ALL_STATIC, test "x${enable_all_static_is}" = "xyes")
|
||||
|
||||
dnl ===== enable-ssl =====
|
||||
AC_ARG_ENABLE([ssl], [AS_HELP_STRING([--enable-ssl],[build the library in the ssl mode (default. yes)])],
|
||||
enable_ssl_is=$enableval,enable_ssl_is=yes)
|
||||
@ -875,6 +880,7 @@ AC_SUBST(HIO_PROJECT_URL, "${PACKAGE_URL}")
|
||||
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
Dockerfile
|
||||
lib/Makefile
|
||||
bin/Makefile
|
||||
t/Makefile
|
||||
|
@ -251,6 +251,7 @@ HIO_EXPORT int hio_scan_http_qparam (
|
||||
|
||||
HIO_EXPORT hio_svc_htts_t* hio_svc_htts_start (
|
||||
hio_t* hio,
|
||||
hio_oow_t xtnsize,
|
||||
hio_dev_sck_bind_t* binds,
|
||||
hio_oow_t nbinds,
|
||||
hio_svc_htts_proc_req_t proc_req
|
||||
@ -260,6 +261,10 @@ HIO_EXPORT void hio_svc_htts_stop (
|
||||
hio_svc_htts_t* htts
|
||||
);
|
||||
|
||||
HIO_EXPORT void* hio_svc_htts_getxtn (
|
||||
hio_svc_htts_t* htts
|
||||
);
|
||||
|
||||
#if defined(HIO_HAVE_INLINE)
|
||||
static HIO_INLINE hio_t* hio_svc_htts_gethio(hio_svc_htts_t* svc) { return hio_svc_gethio((hio_svc_t*)svc); }
|
||||
#else
|
||||
|
@ -429,6 +429,22 @@ HIO_EXPORT void hio_sub_ntime (
|
||||
const hio_ntime_t* y
|
||||
);
|
||||
|
||||
/* =========================================================================
|
||||
* PATH STRING
|
||||
* ========================================================================= */
|
||||
HIO_EXPORT const hio_uch_t* hio_get_base_name_ucstr (
|
||||
const hio_uch_t* path
|
||||
);
|
||||
|
||||
HIO_EXPORT const hio_bch_t* hio_get_base_name_bcstr (
|
||||
const hio_bch_t* path
|
||||
);
|
||||
|
||||
#if defined(HIO_OOCH_IS_UCH)
|
||||
# define hio_get_base_name_oocstr hio_get_base_name_ucstr
|
||||
#else
|
||||
# define hio_get_base_name_oocstr hio_get_base_name_bcstr
|
||||
#endif
|
||||
|
||||
/* =========================================================================
|
||||
* BIT SWAP
|
||||
|
@ -145,15 +145,18 @@ static int file_send_final_status_to_client (file_t* file, int status_code, int
|
||||
{
|
||||
hio_svc_htts_cli_t* cli = file->client;
|
||||
hio_bch_t dtbuf[64];
|
||||
const hio_bch_t* status_msg;
|
||||
|
||||
hio_svc_htts_fmtgmtime (cli->htts, HIO_NULL, dtbuf, HIO_COUNTOF(dtbuf));
|
||||
status_msg = hio_http_status_to_bcstr(status_code);
|
||||
|
||||
if (!force_close) force_close = !file->keep_alive;
|
||||
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %s\r\nConnection: %hs\r\nContent-Length: 0\r\n\r\n",
|
||||
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %s\r\nConnection: %hs\r\nContent-Length: %zu\r\n\r\n%s",
|
||||
file->req_version.major, file->req_version.minor,
|
||||
status_code, hio_http_status_to_bcstr(status_code),
|
||||
status_code, status_msg,
|
||||
cli->htts->server_name, dtbuf,
|
||||
(force_close? "close": "keep-alive")) == (hio_oow_t)-1) return -1;
|
||||
(force_close? "close": "keep-alive"),
|
||||
hio_count_bcstr(status_msg), status_msg) == (hio_oow_t)-1) return -1;
|
||||
|
||||
return (file_write_to_client(file, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf)) <= -1 ||
|
||||
(force_close && file_write_to_client(file, HIO_NULL, 0) <= -1))? -1: 0;
|
||||
|
@ -329,8 +329,7 @@ static void halt_idle_clients (hio_t* hio, const hio_ntime_t* now, hio_tmrjob_t*
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------ */
|
||||
|
||||
hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_oow_t nbinds, hio_svc_htts_proc_req_t proc_req)
|
||||
hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_oow_t xtnsize, hio_dev_sck_bind_t* binds, hio_oow_t nbinds, hio_svc_htts_proc_req_t proc_req)
|
||||
{
|
||||
hio_svc_htts_t* htts = HIO_NULL;
|
||||
union
|
||||
@ -347,7 +346,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
|
||||
goto oops;
|
||||
}
|
||||
|
||||
htts = (hio_svc_htts_t*)hio_callocmem(hio, HIO_SIZEOF(*htts));
|
||||
htts = (hio_svc_htts_t*)hio_callocmem(hio, HIO_SIZEOF(*htts) + xtnsize);
|
||||
if (HIO_UNLIKELY(!htts)) goto oops;
|
||||
|
||||
HIO_DEBUG1 (hio, "HTTS - STARTING SERVICE %p\n", htts);
|
||||
@ -543,6 +542,11 @@ void hio_svc_htts_stop (hio_svc_htts_t* htts)
|
||||
hio_freemem (hio, htts);
|
||||
}
|
||||
|
||||
void* hio_svc_htts_getxtn (hio_svc_htts_t* htts)
|
||||
{
|
||||
return (void*)(htts + 1);
|
||||
}
|
||||
|
||||
int hio_svc_htts_setservernamewithbcstr (hio_svc_htts_t* htts, const hio_bch_t* name)
|
||||
{
|
||||
hio_t* hio = htts->hio;
|
||||
@ -608,6 +612,19 @@ int hio_svc_htts_getsockaddr (hio_svc_htts_t* htts, hio_oow_t idx, hio_skad_t* s
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
/* rsrc_size must be the total size to allocate including the header.
|
||||
*
|
||||
* For instance, if you define a resource like below,
|
||||
*
|
||||
* struct my_rsrc_t
|
||||
* {
|
||||
* HIO_SVC_HTTS_RSRC_HEADER;
|
||||
* int a;
|
||||
* int b;
|
||||
* };
|
||||
*
|
||||
* you can pass sizeof(my_rsrc_t) to hio_svc_htts_rsrc_make()
|
||||
*/
|
||||
hio_svc_htts_rsrc_t* hio_svc_htts_rsrc_make (hio_svc_htts_t* htts, hio_oow_t rsrc_size, hio_svc_htts_rsrc_on_kill_t on_kill)
|
||||
{
|
||||
hio_t* hio = htts->hio;
|
||||
@ -631,12 +648,6 @@ void hio_svc_htts_rsrc_kill (hio_svc_htts_rsrc_t* rsrc)
|
||||
hio_freemem (hio, rsrc);
|
||||
}
|
||||
|
||||
#if defined(HIO_HAVE_INLINE)
|
||||
static HIO_INLINE void* hio_svc_htts_rsrc_getxtn (hio_svc_htts_rsrc_t* rsrc) { return rsrc + 1; }
|
||||
#else
|
||||
#define hio_svc_htts_rsrc_getxtn(rsrc) ((void*)((hio_svc_htts_rsrc_t*)rsrc + 1))
|
||||
#endif
|
||||
|
||||
/* ----------------------------------------------------------------- */
|
||||
|
||||
|
||||
|
30
lib/utl.c
30
lib/utl.c
@ -927,3 +927,33 @@ void hio_sub_ntime (hio_ntime_t* z, const hio_ntime_t* x, const hio_ntime_t* y)
|
||||
}
|
||||
|
||||
/* ========================================================================= */
|
||||
|
||||
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
|
||||
# define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\')
|
||||
#else
|
||||
# define IS_PATH_SEP(c) ((c) == '/')
|
||||
#endif
|
||||
|
||||
const hio_uch_t* hio_get_base_name_ucstr (const hio_uch_t* path)
|
||||
{
|
||||
const hio_uch_t* p, * last = HIO_NULL;
|
||||
|
||||
for (p = path; *p != '\0'; p++)
|
||||
{
|
||||
if (IS_PATH_SEP(*p)) last = p;
|
||||
}
|
||||
|
||||
return last? (last +1): path;
|
||||
}
|
||||
|
||||
const hio_bch_t* hio_get_base_name_bcstr (const hio_bch_t* path)
|
||||
{
|
||||
const hio_bch_t* p, * last = HIO_NULL;
|
||||
|
||||
for (p = path; *p != '\0'; p++)
|
||||
{
|
||||
if (IS_PATH_SEP(*p)) last = p;
|
||||
}
|
||||
|
||||
return last? (last +1): path;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user