diff --git a/bin/Makefile.am b/bin/Makefile.am index 4cff93c..048c0a5 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -81,6 +81,13 @@ hio_t06_CFLAGS = $(CFLAGS_COMMON) hio_t06_LDFLAGS = $(LDFLAGS_COMMON) hio_t06_LDADD = $(LIBADD_COMMON) +bin_PROGRAMS += hio-untar +hio_untar_SOURCES = untar.c +hio_untar_CPPFLAGS = $(CPPFLAGS_COMMON) +hio_untar_CFLAGS = $(CFLAGS_COMMON) +hio_untar_LDFLAGS = $(LDFLAGS_COMMON) +hio_untar_LDADD = $(LIBADD_COMMON) + bin_PROGRAMS += hio-webs hio_webs_SOURCES = webs.c hio_webs_CPPFLAGS = $(CPPFLAGS_COMMON) diff --git a/bin/Makefile.in b/bin/Makefile.in index 6f398d4..f0f849c 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -90,7 +90,8 @@ 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-webs$(EXEEXT) + hio-t05$(EXEEXT) hio-t06$(EXEEXT) hio-untar$(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 +169,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_untar_OBJECTS = hio_untar-untar.$(OBJEXT) +hio_untar_OBJECTS = $(am_hio_untar_OBJECTS) +hio_untar_DEPENDENCIES = $(LIBADD_COMMON) +hio_untar_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(hio_untar_CFLAGS) \ + $(CFLAGS) $(hio_untar_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) @@ -193,7 +200,8 @@ 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_webs-webs.Po + ./$(DEPDIR)/hio_te-te.Po ./$(DEPDIR)/hio_untar-untar.Po \ + ./$(DEPDIR)/hio_webs-webs.Po am__mv = mv -f COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -215,11 +223,13 @@ 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_webs_SOURCES) + $(hio_t06_SOURCES) $(hio_te_SOURCES) $(hio_untar_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) $(hio_webs_SOURCES) + $(am__hio_te_SOURCES_DIST) $(hio_untar_SOURCES) \ + $(hio_webs_SOURCES) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -438,6 +448,11 @@ hio_t06_CPPFLAGS = $(CPPFLAGS_COMMON) hio_t06_CFLAGS = $(CFLAGS_COMMON) hio_t06_LDFLAGS = $(LDFLAGS_COMMON) hio_t06_LDADD = $(LIBADD_COMMON) +hio_untar_SOURCES = untar.c +hio_untar_CPPFLAGS = $(CPPFLAGS_COMMON) +hio_untar_CFLAGS = $(CFLAGS_COMMON) +hio_untar_LDFLAGS = $(LDFLAGS_COMMON) +hio_untar_LDADD = $(LIBADD_COMMON) hio_webs_SOURCES = webs.c hio_webs_CPPFLAGS = $(CPPFLAGS_COMMON) hio_webs_CFLAGS = $(CFLAGS_COMMON) @@ -558,6 +573,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-untar$(EXEEXT): $(hio_untar_OBJECTS) $(hio_untar_DEPENDENCIES) $(EXTRA_hio_untar_DEPENDENCIES) + @rm -f hio-untar$(EXEEXT) + $(AM_V_CCLD)$(hio_untar_LINK) $(hio_untar_OBJECTS) $(hio_untar_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) @@ -576,6 +595,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_untar-untar.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): @@ -720,6 +740,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_untar-untar.o: untar.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_untar_CPPFLAGS) $(CPPFLAGS) $(hio_untar_CFLAGS) $(CFLAGS) -MT hio_untar-untar.o -MD -MP -MF $(DEPDIR)/hio_untar-untar.Tpo -c -o hio_untar-untar.o `test -f 'untar.c' || echo '$(srcdir)/'`untar.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hio_untar-untar.Tpo $(DEPDIR)/hio_untar-untar.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='untar.c' object='hio_untar-untar.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_untar_CPPFLAGS) $(CPPFLAGS) $(hio_untar_CFLAGS) $(CFLAGS) -c -o hio_untar-untar.o `test -f 'untar.c' || echo '$(srcdir)/'`untar.c + +hio_untar-untar.obj: untar.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(hio_untar_CPPFLAGS) $(CPPFLAGS) $(hio_untar_CFLAGS) $(CFLAGS) -MT hio_untar-untar.obj -MD -MP -MF $(DEPDIR)/hio_untar-untar.Tpo -c -o hio_untar-untar.obj `if test -f 'untar.c'; then $(CYGPATH_W) 'untar.c'; else $(CYGPATH_W) '$(srcdir)/untar.c'; fi` +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/hio_untar-untar.Tpo $(DEPDIR)/hio_untar-untar.Po +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='untar.c' object='hio_untar-untar.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_untar_CPPFLAGS) $(CPPFLAGS) $(hio_untar_CFLAGS) $(CFLAGS) -c -o hio_untar-untar.obj `if test -f 'untar.c'; then $(CYGPATH_W) 'untar.c'; else $(CYGPATH_W) '$(srcdir)/untar.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 @@ -875,6 +909,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_untar-untar.Po -rm -f ./$(DEPDIR)/hio_webs-webs.Po -rm -f Makefile distclean-am: clean-am distclean-compile distclean-generic \ @@ -929,6 +964,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_untar-untar.Po -rm -f ./$(DEPDIR)/hio_webs-webs.Po -rm -f Makefile maintainer-clean-am: distclean-am maintainer-clean-generic diff --git a/bin/webs.c b/bin/webs.c index 4c46fd2..0e9369f 100644 --- a/bin/webs.c +++ b/bin/webs.c @@ -1,7 +1,9 @@ #include +#include #include #include #include +#include struct htts_ext_t { @@ -9,6 +11,40 @@ struct htts_ext_t }; typedef struct htts_ext_t htts_ext_t; + +void untar (hio_t* hio, hio_dev_thr_iopair_t* iop, hio_svc_htts_thr_func_info_t* tfi, void* ctx) +{ + FILE* wfp = NULL; + htts_ext_t* ext; + + ext = hio_svc_htts_getxtn(tfi->htts); + + wfp = fdopen(iop->wfd, "w"); + if (!wfp) + { + write (iop->wfd, "Status: 500\r\n\r\n", 15); /* internal server error */ + goto done; + } + +#if 0 + if (hio_extract_tarfd(hio, iop->rfd, ext->docroot + tfi->req_path) <= -1) + { +/* TODO: better error message */ + write (iop->wfd, "Status: 500\r\n\r\n", 15); + goto done; + } +#endif + + write (iop->wfd, "Status: 200\r\n\r\n", 15); + +done: + if (wfp) + { + iop->wfd = HIO_SYSHND_INVALID; /* prevent double close by the main library */ + fclose (wfp); + } +} + 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); @@ -22,6 +58,11 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_ qpath = hio_htre_getqpath(req); + if (mth == HIO_HTTP_OTHER && hio_comp_bcstr(hio_htre_getqmethodname(req), "UNTAR", 1) == 0) + { + hio_svc_htts_dothr(htts, csck, req, untar, HIO_NULL, 0); + } + else // if (mth == HIO_HTTP_GET || mth == HIO_HTTP_POST) { /* TODO: proper mime-type */ @@ -38,7 +79,7 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_ } #endif return 0; - + oops: hio_dev_sck_halt (csck); return 0; diff --git a/lib/Makefile.am b/lib/Makefile.am index 33c5533..375ff55 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -60,6 +60,7 @@ include_HEADERS = \ hio-shw.h \ hio-skad.h \ hio-str.h \ + hio-tar.h \ hio-thr.h \ hio-upac.h \ hio-utl.h \ @@ -113,6 +114,7 @@ libhio_la_SOURCES = \ thr.c \ uch-case.h \ uch-prop.h \ + tar.c \ tmr.c \ utf8.c \ utl.c \ diff --git a/lib/Makefile.in b/lib/Makefile.in index 5a30f77..48a11a5 100644 --- a/lib/Makefile.in +++ b/lib/Makefile.in @@ -154,7 +154,7 @@ am__libhio_la_SOURCES_DIST = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c \ nwif.c opt.c opt-imp.h path.c pipe.c pro.c pty.c rad-msg.c \ sck.c shw.c skad.c sys.c sys-ass.c sys-err.c sys-log.c \ sys-mux.c sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h \ - tmr.c utf8.c utl.c utl-siph.c utl-str.c mar.c mar-cli.c + tar.c tmr.c utf8.c utl.c utl-siph.c utl-str.c mar.c mar-cli.c @ENABLE_MARIADB_TRUE@am__objects_1 = libhio_la-mar.lo \ @ENABLE_MARIADB_TRUE@ libhio_la-mar-cli.lo am_libhio_la_OBJECTS = libhio_la-chr.lo libhio_la-dhcp-svr.lo \ @@ -170,9 +170,9 @@ am_libhio_la_OBJECTS = libhio_la-chr.lo libhio_la-dhcp-svr.lo \ libhio_la-sck.lo libhio_la-shw.lo libhio_la-skad.lo \ libhio_la-sys.lo libhio_la-sys-ass.lo libhio_la-sys-err.lo \ libhio_la-sys-log.lo libhio_la-sys-mux.lo libhio_la-sys-tim.lo \ - libhio_la-thr.lo libhio_la-tmr.lo libhio_la-utf8.lo \ - libhio_la-utl.lo libhio_la-utl-siph.lo libhio_la-utl-str.lo \ - $(am__objects_1) + libhio_la-thr.lo libhio_la-tar.lo libhio_la-tmr.lo \ + libhio_la-utf8.lo libhio_la-utl.lo libhio_la-utl-siph.lo \ + libhio_la-utl-str.lo $(am__objects_1) libhio_la_OBJECTS = $(am_libhio_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -225,8 +225,9 @@ am__depfiles_remade = ./$(DEPDIR)/libhio_la-chr.Plo \ ./$(DEPDIR)/libhio_la-sys-log.Plo \ ./$(DEPDIR)/libhio_la-sys-mux.Plo \ ./$(DEPDIR)/libhio_la-sys-tim.Plo \ - ./$(DEPDIR)/libhio_la-sys.Plo ./$(DEPDIR)/libhio_la-thr.Plo \ - ./$(DEPDIR)/libhio_la-tmr.Plo ./$(DEPDIR)/libhio_la-utf8.Plo \ + ./$(DEPDIR)/libhio_la-sys.Plo ./$(DEPDIR)/libhio_la-tar.Plo \ + ./$(DEPDIR)/libhio_la-thr.Plo ./$(DEPDIR)/libhio_la-tmr.Plo \ + ./$(DEPDIR)/libhio_la-utf8.Plo \ ./$(DEPDIR)/libhio_la-utl-siph.Plo \ ./$(DEPDIR)/libhio_la-utl-str.Plo \ ./$(DEPDIR)/libhio_la-utl.Plo @@ -260,8 +261,8 @@ am__include_HEADERS_DIST = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h \ hio-ecs.h hio-fcgi.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h \ hio-http.h hio-json.h hio-md5.h hio-nwif.h hio-opt.h \ hio-pac1.h hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h \ - hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-thr.h hio-upac.h \ - hio-utl.h hio.h hio-mar.h + hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-tar.h hio-thr.h \ + hio-upac.h hio-utl.h hio.h hio-mar.h HEADERS = $(include_HEADERS) am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) \ hio-cfg.h.in @@ -463,8 +464,8 @@ include_HEADERS = hio-chr.h hio-cmn.h hio-dhcp.h hio-dns.h hio-ecs.h \ hio-fcgi.h hio-fmt.h hio-htb.h hio-htrd.h hio-htre.h \ hio-http.h hio-json.h hio-md5.h hio-nwif.h hio-opt.h \ hio-pac1.h hio-path.h hio-pipe.h hio-pro.h hio-pty.h hio-rad.h \ - hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-thr.h hio-upac.h \ - hio-utl.h hio.h $(am__append_1) + hio-sck.h hio-shw.h hio-skad.h hio-str.h hio-tar.h hio-thr.h \ + hio-upac.h hio-utl.h hio.h $(am__append_1) lib_LTLIBRARIES = libhio.la libhio_la_SOURCES = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c ecs-imp.h \ err.c fcgi-cli.c fmt.c fmt-imp.h htb.c htrd.c htre.c http.c \ @@ -472,8 +473,8 @@ libhio_la_SOURCES = chr.c dhcp-svr.c dns.c dns-cli.c ecs.c ecs-imp.h \ http-thr.c http-txt.c json.c hio-prv.h hio.c md5.c nwif.c \ opt.c opt-imp.h path.c pipe.c pro.c pty.c rad-msg.c sck.c \ shw.c skad.c sys.c sys-ass.c sys-err.c sys-log.c sys-mux.c \ - sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h tmr.c utf8.c \ - utl.c utl-siph.c utl-str.c $(am__append_2) + sys-prv.h sys-tim.c thr.c uch-case.h uch-prop.h tar.c tmr.c \ + utf8.c utl.c utl-siph.c utl-str.c $(am__append_2) libhio_la_CPPFLAGS = $(CPPFLAGS_LIB_COMMON) libhio_la_CFLAGS = $(CFLAGS_LIB_COMMON) $(am__append_3) libhio_la_LDFLAGS = $(LDFLAGS_LIB_COMMON) $(am__append_4) @@ -612,6 +613,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-sys-mux.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-sys-tim.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-sys.Plo@am__quote@ # am--include-marker +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-tar.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-thr.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-tmr.Plo@am__quote@ # am--include-marker @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libhio_la-utf8.Plo@am__quote@ # am--include-marker @@ -915,6 +917,13 @@ libhio_la-thr.lo: thr.c @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-thr.lo `test -f 'thr.c' || echo '$(srcdir)/'`thr.c +libhio_la-tar.lo: tar.c +@am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-tar.lo -MD -MP -MF $(DEPDIR)/libhio_la-tar.Tpo -c -o libhio_la-tar.lo `test -f 'tar.c' || echo '$(srcdir)/'`tar.c +@am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-tar.Tpo $(DEPDIR)/libhio_la-tar.Plo +@AMDEP_TRUE@@am__fastdepCC_FALSE@ $(AM_V_CC)source='tar.c' object='libhio_la-tar.lo' libtool=yes @AMDEPBACKSLASH@ +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ +@am__fastdepCC_FALSE@ $(AM_V_CC@am__nodep@)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -c -o libhio_la-tar.lo `test -f 'tar.c' || echo '$(srcdir)/'`tar.c + libhio_la-tmr.lo: tmr.c @am__fastdepCC_TRUE@ $(AM_V_CC)$(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libhio_la_CPPFLAGS) $(CPPFLAGS) $(libhio_la_CFLAGS) $(CFLAGS) -MT libhio_la-tmr.lo -MD -MP -MF $(DEPDIR)/libhio_la-tmr.Tpo -c -o libhio_la-tmr.lo `test -f 'tmr.c' || echo '$(srcdir)/'`tmr.c @am__fastdepCC_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libhio_la-tmr.Tpo $(DEPDIR)/libhio_la-tmr.Plo @@ -1161,6 +1170,7 @@ distclean: distclean-am -rm -f ./$(DEPDIR)/libhio_la-sys-mux.Plo -rm -f ./$(DEPDIR)/libhio_la-sys-tim.Plo -rm -f ./$(DEPDIR)/libhio_la-sys.Plo + -rm -f ./$(DEPDIR)/libhio_la-tar.Plo -rm -f ./$(DEPDIR)/libhio_la-thr.Plo -rm -f ./$(DEPDIR)/libhio_la-tmr.Plo -rm -f ./$(DEPDIR)/libhio_la-utf8.Plo @@ -1252,6 +1262,7 @@ maintainer-clean: maintainer-clean-am -rm -f ./$(DEPDIR)/libhio_la-sys-mux.Plo -rm -f ./$(DEPDIR)/libhio_la-sys-tim.Plo -rm -f ./$(DEPDIR)/libhio_la-sys.Plo + -rm -f ./$(DEPDIR)/libhio_la-tar.Plo -rm -f ./$(DEPDIR)/libhio_la-thr.Plo -rm -f ./$(DEPDIR)/libhio_la-tmr.Plo -rm -f ./$(DEPDIR)/libhio_la-utf8.Plo diff --git a/lib/hio-http.h b/lib/hio-http.h index 3187817..424dba4 100644 --- a/lib/hio-http.h +++ b/lib/hio-http.h @@ -113,7 +113,7 @@ typedef int (*hio_svc_htts_proc_req_t) ( /* -------------------------------------------------------------- */ struct hio_svc_htts_thr_func_info_t { - hio_t* hio; + hio_svc_htts_t* htts; hio_http_method_t req_method; hio_http_version_t req_version; @@ -131,7 +131,7 @@ typedef struct hio_svc_htts_thr_func_info_t hio_svc_htts_thr_func_info_t; typedef void (*hio_svc_htts_thr_func_t) ( hio_t* hio, hio_dev_thr_iopair_t* iop, - hio_svc_htts_thr_func_info_t* info, + hio_svc_htts_thr_func_info_t* tfi, void* ctx ); diff --git a/lib/hio-tar.h b/lib/hio-tar.h new file mode 100644 index 0000000..65907f7 --- /dev/null +++ b/lib/hio-tar.h @@ -0,0 +1,122 @@ +#ifndef _HIO_TAR_H_ +#define _HIO_TAR_H_ + +#include + + +/* tar Header Block, from POSIX 1003.1-1990. */ +struct hio_tar_hdr_t +{ /* byte offset */ + char name[100]; /* 0 */ + char mode[8]; /* 100 */ + char uid[8]; /* 108 */ + char gid[8]; /* 116 */ + char size[12]; /* 124 */ + char mtime[12]; /* 136 */ + char chksum[8]; /* 148 */ + char typeflag; /* 156 */ + char linkname[100]; /* 157 */ + char magic[6]; /* 257 */ + char version[2]; /* 263 */ + char uname[32]; /* 265 */ + char gname[32]; /* 297 */ + char devmajor[8]; /* 329 */ + char devminor[8]; /* 337 */ + char prefix[155]; /* 345 */ + char padding[12]; /* 500 */ +#if 0 + char *gnu_longname; + char *gnu_longlink; +#endif +}; + +typedef struct hio_tar_hdr_t hio_tar_hdr_t; + + +#define HIO_TAR_MAGIC "ustar" /* ustar and a null */ +#define HIO_TAR_MAGLEN 6 +#define HIO_TAR_VERSION "00" /* 00 and no null */ +#define HIO_TAR_VERSLEN 2 + +/* Values used in typeflag field. */ +#define HIO_TAR_REGTYPE '0' /* regular file */ +#define HIO_TAR_AREGTYPE '\0' /* regular file */ +#define HIO_TAR_LNKTYPE '1' /* link */ +#define HIO_TAR_SYMTYPE '2' /* reserved */ +#define HIO_TAR_CHRTYPE '3' /* character special */ +#define HIO_TAR_BLKTYPE '4' /* block special */ +#define HIO_TAR_DIRTYPE '5' /* directory */ +#define HIO_TAR_FIFOTYPE '6' /* FIFO special */ +#define HIO_TAR_CONTTYPE '7' /* reserved */ + +#define HIO_TAR_XHDTYPE 'x' /* Extended header referring to the next file in the archive */ +#define HIO_TAR_XGLTYPE 'g' /* Global extended header */ + +/* Bits used in the mode field, values in octal. */ +#define HIO_TAR_SUID 04000 /* set UID on execution */ +#define HIO_TAR_SGID 02000 /* set GID on execution */ +#define HIO_TAR_SVTX 01000 /* reserved */ + +/* file permissions */ +#define HIO_TAR_UREAD 00400 /* read by owner */ +#define HIO_TAR_UWRITE 00200 /* write by owner */ +#define HIO_TAR_UEXEC 00100 /* execute/search by owner */ +#define HIO_TAR_GREAD 00040 /* read by group */ +#define HIO_TAR_GWRITE 00020 /* write by group */ +#define HIO_TAR_GEXEC 00010 /* execute/search by group */ +#define HIO_TAR_OREAD 00004 /* read by other */ +#define HIO_TAR_OWRITE 00002 /* write by other */ +#define HIO_TAR_OEXEC 00001 /* execute/search by other */ + +#define HIO_TAR_BLKSIZE (512) + +enum hio_tar_state_t +{ + HIO_TAR_STATE_START, + HIO_TAR_STATE_FILE, + HIO_TAR_STATE_END +}; +typedef enum hio_tar_state_t hio_tar_state_t; + +struct hio_tar_t +{ + hio_t* hio; + + hio_tar_state_t state; + struct + { + hio_uint8_t buf[HIO_TAR_BLKSIZE]; + hio_oow_t len; + } blk; +}; +typedef struct hio_tar_t hio_tar_t; + +#if defined(__cplusplus) +extern "C" { +#endif + +HIO_EXPORT int hio_extract_tar (hio_t* hio, const hio_bch_t* archive_file); + + +hio_tar_t* hio_tar_open ( + hio_t* hio, + hio_oow_t xtnsize +); + +void hio_tar_close ( + hio_tar_t* tar +); + +int hio_tar_init ( + hio_tar_t* tar +); + +void hio_tar_fini ( + hio_tar_t* tar +); + +#if defined(__cplusplus) +} +#endif + +#endif diff --git a/lib/http-thr.c b/lib/http-thr.c index ffa1377..598cfee 100644 --- a/lib/http-thr.c +++ b/lib/http-thr.c @@ -836,6 +836,7 @@ int hio_svc_htts_dothr (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* r tfs->thr_func = func; tfs->thr_ctx = ctx; + tfs->tfi.htts = htts; tfs->tfi.req_method = hio_htre_getqmethodtype(req); tfs->tfi.req_version = *hio_htre_getversion(req); tfs->tfi.req_path = hio_dupbcstr(hio, hio_htre_getqpath(req), HIO_NULL); diff --git a/lib/tar.c b/lib/tar.c new file mode 100644 index 0000000..17a165c --- /dev/null +++ b/lib/tar.c @@ -0,0 +1,286 @@ +#include +#include +#include +#include +#include +#include + +static hio_uint8_t _end_block[HIO_TAR_BLKSIZE] = { 0, }; + +#if 0 +static int verify_checksum(const char *p) +{ + int n, u = 0; + + for (n = 0; n < 512; n++) + { + if (n < 148 || n > 155) + /* Standard tar checksum adds unsigned bytes. */ + u += ((hio_uint8_t*)p)[n]; + else + u += 0x20; + + } + return (u == parseoct(p + 148, 8)); +} +#endif + +static int create_dir (hio_bch_t *pathname, int mode) +{ + char *p; + int n; + hio_oow_t pathlen; + + pathlen = hio_count_bcstr(pathname); + + /* Strip trailing '/' TODO: improve ...*/ + if (pathname[pathlen - 1] == '/') + pathname[pathlen - 1] = '\0'; + + n = mkdir(pathname, mode); + if (n <= -1) + { + /* On failure, try creating parent directory. */ + p = hio_rfind_bchar_in_bcstr(pathname, '/'); + if (p) + { + *p = '\0'; + create_dir(pathname, 0755); + *p = '/'; + n = mkdir(pathname, mode); + } + } + + return n; +} + +static FILE* create_file (char *pathname, int mode) +{ + FILE *fp; + fp = fopen(pathname, "wb+"); + if (!fp) + { + char* p = hio_rfind_bchar_in_bcstr(pathname, '/'); + if (p) + { + *p = '\0'; + create_dir(pathname, 0755); + *p = '/'; + fp = fopen(pathname, "wb+"); + } + } + return fp; +} + +static int extract_tar (hio_t* hio, FILE* fp) +{ + char buf[HIO_TAR_BLKSIZE]; + FILE* f = NULL; + int filesize; + + while (1) + { + int is_sober; + const hio_bch_t* endptr; + hio_iolen_t nbytes; + hio_tar_hdr_t* hdr; + hio_uint32_t mode; + + nbytes = fread(buf, 1, HIO_TAR_BLKSIZE, fp); + if (nbytes < HIO_TAR_BLKSIZE) + { + hio_seterrbfmt (hio, HIO_EINVAL, "truncated trailing block"); + return -1; + } + + /* all-zero byte block ends the archive */ + if (HIO_MEMCMP(buf, _end_block, HIO_TAR_BLKSIZE) == 0) break; + +#if 0 + if (!verify_checksum(buf)) + { + hio_seterrbfmt (hio, HIO_EINVAL, "invalid checksum value"); + return -1; + } +#endif + + hdr = (hio_tar_hdr_t*)buf; + filesize = hio_bchars_to_uintmax(hdr->size, HIO_COUNTOF(hdr->size), HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(0,0,0,8), &endptr, &is_sober); + mode = hio_bchars_to_uintmax(hdr->mode, HIO_COUNTOF(hdr->mode), HIO_BCHARS_TO_UINTMAX_MAKE_OPTION(0,0,0,8), &endptr, &is_sober); + + switch (hdr->typeflag) + { + case HIO_TAR_LNKTYPE: + printf(" Ignoring hardlink %s\n", hdr->name); + break; + case HIO_TAR_SYMTYPE: + printf(" Ignoring symlink %s\n", hdr->name); + break; + case HIO_TAR_CHRTYPE: + printf(" Ignoring character device %s\n", hdr->name); + break; + case HIO_TAR_BLKTYPE: + printf(" Ignoring block device %s\n", hdr->name); + break; + case HIO_TAR_DIRTYPE: + printf(" Extracting dir %s\n", hdr->name); + if (filesize != 0) + { + /* something wrong */ + } + create_dir(hdr->name, mode); + break; + case HIO_TAR_FIFOTYPE: + printf(" Ignoring FIFO %s\n", hdr->name); + break; + + case HIO_TAR_CONTTYPE: + printf(" Ignoring cont %s\n", hdr->name); + break; + + default: + printf(" Extracting file %s\n", hdr->name); + f = create_file(hdr->name, mode); + + while (filesize > 0) + { + nbytes = fread(buf, 1, HIO_TAR_BLKSIZE, fp); + if (nbytes < HIO_TAR_BLKSIZE) + { + fprintf(stderr, "Short read - Expected 512, got %d\n", (int)nbytes); + return -1; + } + if (filesize < HIO_TAR_BLKSIZE) nbytes = filesize; + + if (f) + { + if (fwrite(buf, 1, nbytes, f) != nbytes) + { + fprintf(stderr, "Failed write\n"); + break; + } + } + filesize -= nbytes; + } + + fclose (f); + break; + } + } + + return 0; +} + + +int hio_extract_tar (hio_t* hio, const hio_bch_t* archive_file) +{ + FILE* fp; + int n; + + fp = fopen(archive_file, "r"); + if (!fp) return -1; + + n = extract_tar(hio, fp); + + fclose (fp); + return n; +} + + + + +hio_tar_t* hio_tar_open (hio_t* hio, hio_oow_t xtnsize) +{ + hio_tar_t* tar; + + tar = (hio_tar_t*)hio_callocmem(hio, HIO_SIZEOF(*tar) + xtnsize); + if (tar) + { + if (hio_tar_init(tar) <= -1) + { + hio_freemem (hio, tar); + tar = HIO_NULL; + } + } + + return tar; +} + +void hio_tar_close (hio_tar_t* tar) +{ + hio_tar_fini (tar); + hio_freemem (tar->hio, tar); +} + +int hio_tar_init (hio_tar_t* tar) +{ + tar->state = HIO_TAR_STATE_START; + tar->blk.len = 0; + return 0; +} + +void hio_tar_fini (hio_tar_t* tar) +{ +} + + +static int process_header (hio_tar_t* tar) +{ + hio_tar_hdr_t* hdr; + + HIO_ASSERT (tar->hio, tar->blk.len == HIO_TAR_BLKSIZE); + hdr = (hio_tar_hdr_t*)tar->blk.buf; + + /* all-zero byte block ends the archive */ + if (HIO_MEMCMP(hdr, _end_block, HIO_TAR_BLKSIZE) == 0) + { + tar->state = HIO_TAR_STATE_END; + return 0; + } + + return 0; +} + +#define hio_tar_endfeed(tar) hio_tar_feed(tar, HIO_NULL, 0) + +int hio_tar_feed (hio_tar_t* tar, const void* ptr, hio_oow_t len) +{ + if (!ptr) + { + /* EOF indicator */ + if (tar->state != HIO_TAR_STATE_END || tar->blk.len > 0) + { + /* ERROR - premature end of file */ + return -1; + } + } + + while (len > 0) + { + switch (tar->state) + { + case HIO_TAR_STATE_START: + { + hio_oow_t cplen; + cplen = HIO_COUNTOF(tar->blk.buf) - tar->blk.len; + if (len < cplen) cplen = len; + HIO_MEMCPY (&tar->blk.buf[tar->blk.len], ptr, cplen); + len -= cplen; + break; + } + + case HIO_TAR_STATE_FILE: + break; + + case HIO_TAR_STATE_END: + if (len > 0) + { + /* garbage after the final ending block */ + return -1; + } + break; + } + } + + return 0; +}