added qse_mbstouri()/qse_wcstouri()/qse_strtouri().

added qse_enbase64()/qse_debase64().
enhanced basic authorization to httpd-std
This commit is contained in:
hyung-hwan 2012-09-30 13:56:20 +00:00
parent 8736743eeb
commit 001ede6afa
33 changed files with 826 additions and 245 deletions

View File

@ -39,6 +39,7 @@ pkginclude_HEADERS = \
time.h \ time.h \
tio.h \ tio.h \
tre.h \ tre.h \
uri.h \
utf8.h \ utf8.h \
xma.h xma.h

View File

@ -55,8 +55,8 @@ am__pkginclude_HEADERS_DIST = alg.h chr.h cp949.h cp950.h dll.h env.h \
fio.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h \ fio.h fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h \
main.h map.h mbwc.h mem.h nwad.h nwif.h nwio.h oht.h opt.h \ main.h map.h mbwc.h mem.h nwad.h nwif.h nwio.h oht.h opt.h \
path.h pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h stdio.h \ path.h pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h stdio.h \
str.h time.h tio.h tre.h utf8.h xma.h Mmgr.hpp StdMmgr.hpp \ str.h time.h tio.h tre.h uri.h utf8.h xma.h Mmgr.hpp \
Mmged.hpp StdMmgr.hpp Mmged.hpp
am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
am__vpath_adj = case $$p in \ am__vpath_adj = case $$p in \
$(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
@ -247,7 +247,7 @@ pkginclude_HEADERS = alg.h chr.h cp949.h cp950.h dll.h env.h fio.h \
fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h main.h \ fma.h fmt.h fs.h gdl.h glob.h htb.h hton.h ipad.h lda.h main.h \
map.h mbwc.h mem.h nwad.h nwif.h nwio.h oht.h opt.h path.h \ map.h mbwc.h mem.h nwad.h nwif.h nwio.h oht.h opt.h path.h \
pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h stdio.h str.h \ pio.h pma.h rbt.h rex.h sio.h sll.h slmb.h stdio.h str.h \
time.h tio.h tre.h utf8.h xma.h $(am__append_1) time.h tio.h tre.h uri.h utf8.h xma.h $(am__append_1)
all: all-am all: all-am
.SUFFIXES: .SUFFIXES:

View File

@ -170,6 +170,23 @@ qse_uint64_t qse_randxs64 (
#endif #endif
qse_size_t qse_enbase64 (
const qse_uint8_t* in,
qse_size_t isz,
qse_mchar_t* out,
qse_size_t osz,
qse_size_t* xsz
);
qse_size_t qse_debase64 (
const qse_mchar_t* in,
qse_size_t isz,
qse_uint8_t* out,
qse_size_t osz,
qse_size_t* xsz
);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -187,6 +187,13 @@ qse_mchar_t* qse_wcstombsdupwithcmgr (
qse_cmgr_t* cmgr qse_cmgr_t* cmgr
); );
qse_mchar_t* qse_wcntombsdupwithcmgr (
const qse_wchar_t* wcs,
qse_size_t len,
qse_mmgr_t* mmgr,
qse_cmgr_t* cmgr
);
qse_mchar_t* qse_wcsatombsdupwithcmgr ( qse_mchar_t* qse_wcsatombsdupwithcmgr (
const qse_wchar_t* wcs[], const qse_wchar_t* wcs[],
qse_mmgr_t* mmgr, qse_mmgr_t* mmgr,
@ -369,6 +376,12 @@ qse_mchar_t* qse_wcstombsdup (
qse_mmgr_t* mmgr qse_mmgr_t* mmgr
); );
qse_mchar_t* qse_wcsntombsdup (
const qse_wchar_t* wcs,
qse_size_t len,
qse_mmgr_t* mmgr
);
qse_mchar_t* qse_wcsatombsdup ( qse_mchar_t* qse_wcsatombsdup (
const qse_wchar_t* wcs[], const qse_wchar_t* wcs[],
qse_mmgr_t* mmgr qse_mmgr_t* mmgr

View File

@ -929,12 +929,23 @@ int qse_mbszcmp (
qse_size_t n qse_size_t n
); );
int qse_mbszcasecmp (
const qse_mchar_t* s1,
const qse_mchar_t* s2,
qse_size_t n
);
int qse_wcszcmp ( int qse_wcszcmp (
const qse_wchar_t* s1, const qse_wchar_t* s1,
const qse_wchar_t* s2, const qse_wchar_t* s2,
qse_size_t n qse_size_t n
); );
int qse_wcszcasecmp (
const qse_wchar_t* s1,
const qse_wchar_t* s2,
qse_size_t n
);
#ifdef QSE_CHAR_IS_MCHAR #ifdef QSE_CHAR_IS_MCHAR
# define qse_strcmp(s1,s2) qse_mbscmp(s1,s2) # define qse_strcmp(s1,s2) qse_mbscmp(s1,s2)
@ -944,6 +955,7 @@ int qse_wcszcmp (
# define qse_strxcasecmp(s1,ln1,s2) qse_mbsxcasecmp(s1,ln1,s2) # define qse_strxcasecmp(s1,ln1,s2) qse_mbsxcasecmp(s1,ln1,s2)
# define qse_strxncasecmp(s1,ln1,s2,ln2) qse_mbsxncasecmp(s1,ln1,s2,ln2) # define qse_strxncasecmp(s1,ln1,s2,ln2) qse_mbsxncasecmp(s1,ln1,s2,ln2)
# define qse_strzcmp(s1,s2,n) qse_mbszcmp(s1,s2,n) # define qse_strzcmp(s1,s2,n) qse_mbszcmp(s1,s2,n)
# define qse_strzcasecmp(s1,s2,n) qse_mbszcasecmp(s1,s2,n)
#else #else
# define qse_strcmp(s1,s2) qse_wcscmp(s1,s2) # define qse_strcmp(s1,s2) qse_wcscmp(s1,s2)
# define qse_strxcmp(s1,ln1,s2) qse_wcsxcmp(s1,ln1,s2) # define qse_strxcmp(s1,ln1,s2) qse_wcsxcmp(s1,ln1,s2)
@ -952,6 +964,7 @@ int qse_wcszcmp (
# define qse_strxcasecmp(s1,ln1,s2) qse_wcsxcasecmp(s1,ln1,s2) # define qse_strxcasecmp(s1,ln1,s2) qse_wcsxcasecmp(s1,ln1,s2)
# define qse_strxncasecmp(s1,ln1,s2,ln2) qse_wcsxncasecmp(s1,ln1,s2,ln2) # define qse_strxncasecmp(s1,ln1,s2,ln2) qse_wcsxncasecmp(s1,ln1,s2,ln2)
# define qse_strzcmp(s1,s2,n) qse_wcszcmp(s1,s2,n) # define qse_strzcmp(s1,s2,n) qse_wcszcmp(s1,s2,n)
# define qse_strzcasecmp(s1,s2,n) qse_wcszcasecmp(s1,s2,n)
#endif #endif
qse_mchar_t* qse_mbsdup ( qse_mchar_t* qse_mbsdup (
@ -984,6 +997,11 @@ qse_mchar_t* qse_mbsadup (
qse_mmgr_t* mmgr qse_mmgr_t* mmgr
); );
qse_mchar_t* qse_mbsxadup (
const qse_mcstr_t str[],
qse_mmgr_t* mmgr
);
qse_wchar_t* qse_wcsdup ( qse_wchar_t* qse_wcsdup (
const qse_wchar_t* str, const qse_wchar_t* str,
qse_mmgr_t* mmgr qse_mmgr_t* mmgr
@ -1014,18 +1032,25 @@ qse_wchar_t* qse_wcsadup (
qse_mmgr_t* mmgr qse_mmgr_t* mmgr
); );
qse_wchar_t* qse_wcsxadup (
const qse_wcstr_t str[],
qse_mmgr_t* mmgr
);
#ifdef QSE_CHAR_IS_MCHAR #ifdef QSE_CHAR_IS_MCHAR
# define qse_strdup(s,mmgr) qse_mbsdup(s,mmgr) # define qse_strdup(s,mmgr) qse_mbsdup(s,mmgr)
# define qse_strdup2(s1,s2,mmgr) qse_mbsdup2(s1,s2,mmgr) # define qse_strdup2(s1,s2,mmgr) qse_mbsdup2(s1,s2,mmgr)
# define qse_strxdup(s,l,mmgr) qse_mbsxdup(s,l,mmgr) # define qse_strxdup(s,l,mmgr) qse_mbsxdup(s,l,mmgr)
# define qse_strxdup2(s1,l1,s2,l2,mmgr) qse_mbsxdup(s1,l1,s2,l2,mmgr) # define qse_strxdup2(s1,l1,s2,l2,mmgr) qse_mbsxdup(s1,l1,s2,l2,mmgr)
# define qse_stradup(sa,mmgr) qse_mbsadup(sa,mmgr) # define qse_stradup(sa,mmgr) qse_mbsadup(sa,mmgr)
# define qse_strxadup(sa,mmgr) qse_mbsxadup(sa,mmgr)
#else #else
# define qse_strdup(s,mmgr) qse_wcsdup(s,mmgr) # define qse_strdup(s,mmgr) qse_wcsdup(s,mmgr)
# define qse_strdup2(s1,s2,mmgr) qse_wcsdup2(s1,s2,mmgr) # define qse_strdup2(s1,s2,mmgr) qse_wcsdup2(s1,s2,mmgr)
# define qse_strxdup(s,l,mmgr) qse_wcsxdup(s,l,mmgr) # define qse_strxdup(s,l,mmgr) qse_wcsxdup(s,l,mmgr)
# define qse_strxdup2(s1,l1,s2,l2,mmgr) qse_wcsxdup(s1,l1,s2,l2,mmgr) # define qse_strxdup2(s1,l1,s2,l2,mmgr) qse_wcsxdup(s1,l1,s2,l2,mmgr)
# define qse_stradup(sa,mmgr) qse_wcsadup(sa,mmgr) # define qse_stradup(sa,mmgr) qse_wcsadup(sa,mmgr)
# define qse_strxadup(sa,mmgr) qse_wcsxadup(sa,mmgr)
#endif #endif
/** /**

View File

@ -709,6 +709,12 @@ qse_httpd_server_t* qse_httpd_attachserverstd (
qse_size_t xtnsize qse_size_t xtnsize
); );
void* qse_httpd_getserverxtnstd (
qse_httpd_t* httpd,
qse_httpd_server_t* server
);
int qse_httpd_loopstd ( int qse_httpd_loopstd (
qse_httpd_t* httpd, qse_httpd_t* httpd,
qse_httpd_cbstd_t* cbstd, qse_httpd_cbstd_t* cbstd,

View File

@ -22,6 +22,7 @@ noinst_HEADERS = \
tre-stack.h tre-stack.h
libqsecmn_la_SOURCES = \ libqsecmn_la_SOURCES = \
alg-base64.c \
alg-rand.c \ alg-rand.c \
alg-search.c \ alg-search.c \
alg-sort.c \ alg-sort.c \
@ -100,6 +101,7 @@ libqsecmn_la_SOURCES = \
tre-match-parallel.c \ tre-match-parallel.c \
tre-parse.c \ tre-parse.c \
tre-stack.c \ tre-stack.c \
uri.c \
utf8.c \ utf8.c \
xma.c xma.c

View File

@ -82,11 +82,11 @@ am__installdirs = "$(DESTDIR)$(libdir)"
LTLIBRARIES = $(lib_LTLIBRARIES) LTLIBRARIES = $(lib_LTLIBRARIES)
am__DEPENDENCIES_1 = am__DEPENDENCIES_1 =
libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1) libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
am_libqsecmn_la_OBJECTS = alg-rand.lo alg-search.lo alg-sort.lo \ am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
assert.lo chr.lo cp949.lo cp950.lo dll.lo env.lo gdl.lo htb.lo \ alg-sort.lo assert.lo chr.lo cp949.lo cp950.lo dll.lo env.lo \
fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo glob.lo \ gdl.lo htb.lo fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo \
hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo mem.lo \ glob.lo hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo \
nwad.lo nwif.lo nwio.lo oht.lo opt.lo path-basename.lo \ mem.lo nwad.lo nwif.lo nwio.lo oht.lo opt.lo path-basename.lo \
path-canon.lo pio.lo pma.lo rbt.lo rex.lo sio.lo sll.lo \ path-canon.lo pio.lo pma.lo rbt.lo rex.lo sio.lo sll.lo \
slmb.lo stdio.lo str-beg.lo str-cat.lo str-chr.lo str-cnv.lo \ slmb.lo stdio.lo str-beg.lo str-cat.lo str-chr.lo str-cnv.lo \
str-cmp.lo str-cpy.lo str-del.lo str-dup.lo str-dynm.lo \ str-cmp.lo str-cpy.lo str-del.lo str-dup.lo str-dynm.lo \
@ -96,7 +96,7 @@ am_libqsecmn_la_OBJECTS = alg-rand.lo alg-search.lo alg-sort.lo \
str-str.lo str-subst.lo str-tok.lo str-trm.lo str-word.lo \ str-str.lo str-subst.lo str-tok.lo str-trm.lo str-word.lo \
time.lo tio.lo tre.lo tre-ast.lo tre-compile.lo \ time.lo tio.lo tre.lo tre-ast.lo tre-compile.lo \
tre-match-backtrack.lo tre-match-parallel.lo tre-parse.lo \ tre-match-backtrack.lo tre-match-parallel.lo tre-parse.lo \
tre-stack.lo utf8.lo xma.lo tre-stack.lo uri.lo utf8.lo xma.lo
libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS) libqsecmn_la_OBJECTS = $(am_libqsecmn_la_OBJECTS)
libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \ libqsecmn_la_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
@ -312,6 +312,7 @@ noinst_HEADERS = \
tre-stack.h tre-stack.h
libqsecmn_la_SOURCES = \ libqsecmn_la_SOURCES = \
alg-base64.c \
alg-rand.c \ alg-rand.c \
alg-search.c \ alg-search.c \
alg-sort.c \ alg-sort.c \
@ -390,6 +391,7 @@ libqsecmn_la_SOURCES = \
tre-match-parallel.c \ tre-match-parallel.c \
tre-parse.c \ tre-parse.c \
tre-stack.c \ tre-stack.c \
uri.c \
utf8.c \ utf8.c \
xma.c xma.c
@ -478,6 +480,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Mmgr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Mmgr.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StdMmgr.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/StdMmgr.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-base64.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-rand.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-rand.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-search.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-search.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-sort.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/alg-sort.Plo@am__quote@
@ -556,6 +559,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre-parse.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre-parse.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre-stack.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre-stack.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uri.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utf8.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/utf8.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xma.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xma.Plo@am__quote@

109
qse/lib/cmn/alg-base64.c Normal file
View File

@ -0,0 +1,109 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/alg.h>
#define ENC(x) \
((x < 26)? (QSE_MT('A') + x): \
(x < 52)? (QSE_MT('a') + (x - 26)): \
(x < 62)? (QSE_MT('0') + (x - 52)): \
(x == 62)? QSE_MT('+'): QSE_MT('/'))
#define DEC(x) \
((x >= QSE_MT('A') && x <= QSE_MT('Z'))? (x - QSE_MT('A')): \
(x >= QSE_MT('a') && x <= QSE_MT('z'))? (x - QSE_MT('a') + 26): \
(x >= QSE_MT('0') && x <= QSE_MT('9'))? (x - QSE_MT('0') + 52): \
(x == QSE_MT('+'))? 62: 63)
qse_size_t qse_enbase64 (
const qse_uint8_t* in, qse_size_t isz,
qse_mchar_t* out, qse_size_t osz, qse_size_t* xsz)
{
qse_size_t idx = 0, idx2 = 0, i;
/* 3 8-bit values to 4 6-bit values */
for (i = 0; i < isz; i += 3)
{
qse_uint8_t b1, b2, b3;
qse_uint8_t c1, c2, c3, c4;
b1 = in[i];
b2 = (i + 1 < isz)? in[i + 1]: 0;
b3 = (i + 2 < isz)? in[i + 2]: 0;
c1 = b1 >> 2;
c2 = ((b1 & 0x03) << 4) | (b2 >> 4);
c3 = ((b2 & 0x0F) << 2) | (b3 >> 6);
c4 = b3 & 0x3F;
if (idx + 3 < osz)
{
out[idx++] = ENC(c1);
out[idx++] = ENC(c2);
out[idx++] = (i + 1 < isz)? ENC(c3): QSE_MT('=');
out[idx++] = (i + 2 < isz)? ENC(c4): QSE_MT('=');
}
idx2 += 4;
}
if (xsz) *xsz = idx2;
return idx;
}
qse_size_t qse_debase64 (
const qse_mchar_t* in, qse_size_t isz,
qse_uint8_t* out, qse_size_t osz, qse_size_t* xsz)
{
qse_size_t idx = 0, idx2 = 0, i;
for (i = 0; i < isz; i += 4)
{
qse_uint8_t c1, c2, c3, c4;
qse_uint8_t b1, b2, b3, b4;
c1 = in[i];
c2 = (i + 1 < isz)? in[i + 1]: QSE_MT('A');
c3 = (i + 2 < isz)? in[i + 2]: QSE_MT('A');
c4 = (i + 3 < isz)? in[i + 3]: QSE_MT('A');
b1 = DEC(c1);
b2 = DEC(c2);
b3 = DEC(c3);
b4 = DEC(c4);
idx2++;
if (idx < osz) out[idx++] = (b1 << 2) | (b2 >> 4);
if (c3 != QSE_MT('='))
{
idx2++;
if (idx < osz) out[idx++] = ((b2 & 0x0F) << 4) | (b3 >> 2);
}
if (c4 != QSE_MT('='))
{
idx2++;
if (idx < osz) out[idx++] = ((b3 & 0x03) << 6) | b4;
}
}
if (xsz) *xsz = idx2;
return idx;
}

View File

@ -60,6 +60,7 @@ qse_dll_t* qse_dll_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (dll + 1, 0, xtnsize);
return dll; return dll;
} }
@ -71,7 +72,7 @@ void qse_dll_close (qse_dll_t* dll)
int qse_dll_init (qse_dll_t* dll, qse_mmgr_t* mmgr) int qse_dll_init (qse_dll_t* dll, qse_mmgr_t* mmgr)
{ {
/* do not zero out the xtnsizeension */ /* do not zero out the extension */
QSE_MEMSET (dll, 0, QSE_SIZEOF(*dll)); QSE_MEMSET (dll, 0, QSE_SIZEOF(*dll));
dll->mmgr = mmgr; dll->mmgr = mmgr;

View File

@ -50,6 +50,7 @@ qse_env_t* qse_env_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, int fromcurenv)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (env + 1, 0, xtnsize);
return env; return env;
} }

View File

@ -38,6 +38,7 @@ qse_fma_t* qse_fma_open (
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (fma + 1, 0, xtnsize);
return fma; return fma;
} }

View File

@ -67,6 +67,7 @@ qse_fs_t* qse_fs_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (fs + 1, 0, xtnsize);
return fs; return fs;
} }

View File

@ -274,6 +274,7 @@ htb_t* qse_htb_open (
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (htb + 1, 0, xtnsize);
return htb; return htb;
} }

View File

@ -489,6 +489,21 @@ qse_mchar_t* qse_wcstombsdupwithcmgr (const qse_wchar_t* wcs, qse_mmgr_t* mmgr,
return mbs; return mbs;
} }
qse_mchar_t* qse_wcsntombsdupwithcmgr (const qse_wchar_t* wcs, qse_size_t len, qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
{
qse_size_t mbslen;
qse_mchar_t* mbs;
if (qse_wcsntombsnwithcmgr (wcs, &len, QSE_NULL, &mbslen, cmgr) <= -1) return QSE_NULL;
mbs = QSE_MMGR_ALLOC (mmgr, (mbslen + 1) * QSE_SIZEOF(*mbs));
if (mbs == QSE_NULL) return QSE_NULL;
qse_wcsntombsnwithcmgr (wcs, &len, mbs, &mbslen, cmgr);
mbs[mbslen] = QSE_MT('\0');
return mbs;
}
qse_mchar_t* qse_wcsatombsdupwithcmgr (const qse_wchar_t* wcs[], qse_mmgr_t* mmgr, qse_cmgr_t* cmgr) qse_mchar_t* qse_wcsatombsdupwithcmgr (const qse_wchar_t* wcs[], qse_mmgr_t* mmgr, qse_cmgr_t* cmgr)
{ {
qse_mchar_t* buf, * ptr; qse_mchar_t* buf, * ptr;

View File

@ -212,6 +212,11 @@ qse_mchar_t* qse_wcstombsdup (const qse_wchar_t* wcs, qse_mmgr_t* mmgr)
return qse_wcstombsdupwithcmgr (wcs, mmgr, dfl_cmgr); return qse_wcstombsdupwithcmgr (wcs, mmgr, dfl_cmgr);
} }
qse_mchar_t* qse_wcsntombsdup (const qse_wchar_t* wcs, qse_size_t len, qse_mmgr_t* mmgr)
{
return qse_wcsntombsdupwithcmgr (wcs, len, mmgr, dfl_cmgr);
}
qse_mchar_t* qse_wcsatombsdup (const qse_wchar_t* wcs[], qse_mmgr_t* mmgr) qse_mchar_t* qse_wcsatombsdup (const qse_wchar_t* wcs[], qse_mmgr_t* mmgr)
{ {
return qse_wcsatombsdupwithcmgr (wcs, mmgr, dfl_cmgr); return qse_wcsatombsdupwithcmgr (wcs, mmgr, dfl_cmgr);

View File

@ -343,6 +343,7 @@ qse_nwio_t* qse_nwio_open (
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (nwio + 1, 0, xtnsize);
return nwio; return nwio;
} }

View File

@ -57,6 +57,7 @@ qse_oht_t* qse_oht_open (
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (oht + 1, 0, xtnsize);
return oht; return oht;
} }

View File

@ -62,6 +62,7 @@ qse_pma_t* qse_pma_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (pma + 1, 0, xtnsize);
return pma; return pma;
} }

View File

@ -210,6 +210,7 @@ rbt_t* qse_rbt_open (mmgr_t* mmgr, size_t xtnsize, int kscale, int vscale)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (rbt + 1, 0, xtnsize);
return rbt; return rbt;
} }

View File

@ -106,6 +106,7 @@ qse_sio_t* qse_sio_open (
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (sio + 1, 0, xtnsize);
return sio; return sio;
} }

View File

@ -130,6 +130,21 @@ int qse_mbszcmp (const qse_mchar_t* s1, const qse_mchar_t* s2, qse_size_t n)
return (*s1 > *s2)? 1: -1; return (*s1 > *s2)? 1: -1;
} }
int qse_mbszcasecmp (const qse_mchar_t* s1, const qse_mchar_t* s2, qse_size_t n)
{
if (n == 0) return 0;
while (QSE_TOMUPPER(*s1) == QSE_TOMUPPER(*s2))
{
if (*s1 == QSE_MT('\0') || n == 1) return 0;
s1++, s2++, n--;
}
return (QSE_TOMUPPER(*s1) > QSE_TOMUPPER(*s2))? 1: -1;
}
/* ------------------------------------------------------------- */
int qse_wcscmp (const qse_wchar_t* s1, const qse_wchar_t* s2) int qse_wcscmp (const qse_wchar_t* s1, const qse_wchar_t* s2)
{ {
while (*s1 == *s2) while (*s1 == *s2)
@ -237,3 +252,16 @@ int qse_wcszcmp (const qse_wchar_t* s1, const qse_wchar_t* s2, qse_size_t n)
return (*s1 > *s2)? 1: -1; return (*s1 > *s2)? 1: -1;
} }
int qse_wcszcasecmp (const qse_wchar_t* s1, const qse_wchar_t* s2, qse_size_t n)
{
if (n == 0) return 0;
while (QSE_TOWUPPER(*s1) == QSE_TOWUPPER(*s2))
{
if (*s1 == QSE_WT('\0') || n == 1) return 0;
s1++, s2++, n--;
}
return (QSE_TOWUPPER(*s1) > QSE_TOWUPPER(*s2))? 1: -1;
}

View File

@ -91,6 +91,25 @@ qse_mchar_t* qse_mbsadup (const qse_mchar_t* str[], qse_mmgr_t* mmgr)
return buf; return buf;
} }
qse_mchar_t* qse_mbsxadup (const qse_mcstr_t str[], qse_mmgr_t* mmgr)
{
qse_mchar_t* buf, * ptr;
qse_size_t i;
qse_size_t capa = 0;
QSE_ASSERT (mmgr != QSE_NULL);
for (i = 0; str[i].ptr; i++) capa += str[i].len;
buf = (qse_mchar_t*) QSE_MMGR_ALLOC (mmgr, (capa+1)*QSE_SIZEOF(*buf));
if (buf == QSE_NULL) return QSE_NULL;
ptr = buf;
for (i = 0; str[i].ptr; i++) ptr += qse_mbsncpy (ptr, str[i].ptr, str[i].len);
return buf;
}
/* --------------------------------------------------------------- */ /* --------------------------------------------------------------- */
qse_wchar_t* qse_wcsdup (const qse_wchar_t* str, qse_mmgr_t* mmgr) qse_wchar_t* qse_wcsdup (const qse_wchar_t* str, qse_mmgr_t* mmgr)
@ -165,3 +184,21 @@ qse_wchar_t* qse_wcsadup (const qse_wchar_t* str[], qse_mmgr_t* mmgr)
return buf; return buf;
} }
qse_wchar_t* qse_wcsxadup (const qse_wcstr_t str[], qse_mmgr_t* mmgr)
{
qse_wchar_t* buf, * ptr;
qse_size_t i;
qse_size_t capa = 0;
QSE_ASSERT (mmgr != QSE_NULL);
for (i = 0; str[i].ptr; i++) capa += str[i].len;
buf = (qse_wchar_t*) QSE_MMGR_ALLOC (mmgr, (capa+1)*QSE_SIZEOF(*buf));
if (buf == QSE_NULL) return QSE_NULL;
ptr = buf;
for (i = 0; str[i].ptr; i++) ptr += qse_wcsncpy (ptr, str[i].ptr, str[i].len);
return buf;
}

View File

@ -45,6 +45,7 @@ qse_tio_t* qse_tio_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, int flags)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (tio + 1, 0, xtnsize);
return tio; return tio;
} }

View File

@ -37,6 +37,7 @@ qse_tre_t* qse_tre_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (tre + 1, 0, xtnsize);
return tre; return tre;
} }

View File

@ -1,104 +1,268 @@
/*
* $Id$
*
Copyright 2006-2012 Chung, Hyung-Hwan.
This file is part of QSE.
static int qse_ripuri (qse_httpd_t* httpd, const qse_char_t* uri, int flags) QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/uri.h>
#include "mem.h"
int qse_mbstouri (const qse_mchar_t* str, qse_uri_t* uri, int flags)
{ {
const qse_char_t* ptr, * colon, * at; const qse_mchar_t* ptr, * colon;
qse_size_t len;
qse_uri_t xuri; qse_uri_t xuri;
QSE_MEMSET (xuri, 0, QSE_SIZEOF(xuri)); QSE_MEMSET (&xuri, 0, QSE_SIZEOF(xuri));
/* scheme */ /* scheme */
xuri.scheme.ptr = ptr; xuri.scheme.ptr = str;
while (*uri != QSE_T(':')) while (*str != QSE_MT(':'))
{ {
if (*uri == QSE_T('\0')) return -1; if (*str == QSE_MT('\0')) return -1;
uri++; str++;
} }
xuri.scheme.len = uri - xuri.scheme.ptr; xuri.scheme.len = str - (const qse_mchar_t*)xuri.scheme.ptr;
uri++; /* skip : */ str++; /* skip : */
if (*uri != QSE_T('/')) return -1; if (*str != QSE_MT('/')) return -1;
uri++; /* skip / */ str++; /* skip / */
if (*uri != QSE_T('/')) return -1; if (*str != QSE_MT('/')) return -1;
uri++; /* skip / */ str++; /* skip / */
/* username, password, host, port */ /* username, password, host, port */
for (colon = QSE_NULL, at = QSE_NULL, ptr = uri; ; uri++) for (colon = QSE_NULL, ptr = str; ; str++)
{ {
if (at == QSE_NULL) if (flags & QSE_MBSTOURI_NOAUTH)
{ {
if (colon == QSE_NULL && *uri == QSE_T(':')) colon = uri; if (colon == QSE_NULL && *str == QSE_MT(':')) colon = str;
else if (*uri == QSE_T('@')) else if (*str == QSE_MT('/') || *str == QSE_MT('\0'))
{
if (colon)
{
xuri.user.ptr = ptr;
xuri.user.len = colon - ptr;
xuri.pass.ptr = colon + 1;
xuri.pass.len = uri - colon - 1;
colon = QSE_NULL;
}
else
{
xuri.user.ptr = ptr;
xuri.user.len = uri - ptr;
}
}
else if (*uri == QSE_T('/') || *uri == QSE_T('\0'))
{
xuri.host = xuri.user;
xuir.port = xuri.pass;
xuri.user.ptr = QSE_NULL;
xuri.user.len = 0;
xuri.pass.ptr = QSE_NULL;
xuri.pass.len = 0;
break;
}
}
else
{
if (colon == QSE_NULL && *uri == QSE_T(':')) colon = uri;
else if (*uri == QSE_T('/') || *uri == QSE_T('\0'))
{ {
if (colon) if (colon)
{ {
xuri.host.ptr = ptr; xuri.host.ptr = ptr;
xuri.host.len = colon - ptr; xuri.host.len = colon - ptr;
xuri.port.ptr = colon + 1; xuri.port.ptr = colon + 1;
xuri.port.len = uri - colon - 1; xuri.port.len = str - colon - 1;
} }
else else
{ {
xuri.host.ptr = ptr; xuri.host.ptr = ptr;
xuri.host.len = uri - ptr; xuri.host.len = str - ptr;
} }
break;
} }
} }
} else
if (uri == QSE_T('/'))
{
xuri.path.ptr = uri;
while (*uri != QSE_T('\0') && *uri != QSE_T('?')) uri++;
xuri.path.len = uri - xuri.path.ptr;
if (uri == QSE('#'))
{ {
xuri.query.ptr = ++uri; if (colon == QSE_NULL && *str == QSE_MT(':')) colon = str;
while (*uri != QSE_T('\0') && *uri != QSE_T('#')) uri++; else if (xuri.auth.user.ptr == QSE_NULL && *str == QSE_MT('@'))
xuri.query.len = uri - xuri.query.ptr;
if (uri == QSE_T('#'))
{ {
xuri.query.ptr = ++uri; if (colon)
while (*uri != QSE_T('\0')) uri++; {
xuri.fragment.len = uri - xuri.fragment.ptr; xuri.auth.user.ptr = ptr;
xuri.auth.user.len = colon - ptr;
xuri.auth.pass.ptr = colon + 1;
xuri.auth.pass.len = str - colon - 1;
colon = QSE_NULL;
}
else
{
xuri.auth.user.ptr = ptr;
xuri.auth.user.len = str - ptr;
}
ptr = str + 1;
}
else if (*str == QSE_MT('/') || *str == QSE_MT('\0'))
{
if (colon)
{
xuri.host.ptr = ptr;
xuri.host.len = colon - ptr;
xuri.port.ptr = colon + 1;
xuri.port.len = str - colon - 1;
}
else
{
xuri.host.ptr = ptr;
xuri.host.len = str - ptr;
}
break;
} }
} }
} }
*xuri = scheme; if (*str == QSE_MT('/'))
{
xuri.path.ptr = str;
while (*str != QSE_MT('\0'))
{
if ((!(flags & QSE_MBSTOURI_NOQUERY) && *str == QSE_MT('?')) ||
(!(flags & QSE_MBSTOURI_NOFRAG) && *str == QSE_MT('#'))) break;
str++;
}
xuri.path.len = str - (const qse_mchar_t*)xuri.path.ptr;
if (!(flags & QSE_MBSTOURI_NOQUERY) && *str == QSE_MT('?'))
{
xuri.query.ptr = ++str;
while (*str != QSE_MT('\0'))
{
if (!(flags & QSE_MBSTOURI_NOFRAG) && *str == QSE_MT('#')) break;
str++;
}
xuri.query.len = str - (const qse_mchar_t*)xuri.query.ptr;
}
if (!(flags & QSE_MBSTOURI_NOFRAG) && *str == QSE_MT('#'))
{
xuri.frag.ptr = ++str;
while (*str != QSE_MT('\0')) str++;
xuri.frag.len = str - (const qse_mchar_t*)xuri.frag.ptr;
}
}
QSE_ASSERT (*str == QSE_MT('\0'));
*uri = xuri;
return 0;
}
/* -------------------------------------------------------- */
int qse_wcstouri (const qse_wchar_t* str, qse_uri_t* uri, int flags)
{
const qse_wchar_t* ptr, * colon;
qse_uri_t xuri;
QSE_MEMSET (&xuri, 0, QSE_SIZEOF(xuri));
/* scheme */
xuri.scheme.ptr = str;
while (*str != QSE_WT(':'))
{
if (*str == QSE_WT('\0')) return -1;
str++;
}
xuri.scheme.len = str - (const qse_wchar_t*)xuri.scheme.ptr;
str++; /* skip : */
if (*str != QSE_WT('/')) return -1;
str++; /* skip / */
if (*str != QSE_WT('/')) return -1;
str++; /* skip / */
/* username, password, host, port */
for (colon = QSE_NULL, ptr = str; ; str++)
{
if (flags & QSE_WCSTOURI_NOAUTH)
{
if (colon == QSE_NULL && *str == QSE_WT(':')) colon = str;
else if (*str == QSE_WT('/') || *str == QSE_WT('\0'))
{
if (colon)
{
xuri.host.ptr = ptr;
xuri.host.len = colon - ptr;
xuri.port.ptr = colon + 1;
xuri.port.len = str - colon - 1;
}
else
{
xuri.host.ptr = ptr;
xuri.host.len = str - ptr;
}
break;
}
}
else
{
if (colon == QSE_NULL && *str == QSE_WT(':')) colon = str;
else if (xuri.auth.user.ptr == QSE_NULL && *str == QSE_WT('@'))
{
if (colon)
{
xuri.auth.user.ptr = ptr;
xuri.auth.user.len = colon - ptr;
xuri.auth.pass.ptr = colon + 1;
xuri.auth.pass.len = str - colon - 1;
colon = QSE_NULL;
}
else
{
xuri.auth.user.ptr = ptr;
xuri.auth.user.len = str - ptr;
}
ptr = str + 1;
}
else if (*str == QSE_WT('/') || *str == QSE_WT('\0'))
{
if (colon)
{
xuri.host.ptr = ptr;
xuri.host.len = colon - ptr;
xuri.port.ptr = colon + 1;
xuri.port.len = str - colon - 1;
}
else
{
xuri.host.ptr = ptr;
xuri.host.len = str - ptr;
}
break;
}
}
}
if (*str == QSE_WT('/'))
{
xuri.path.ptr = str;
while (*str != QSE_WT('\0'))
{
if ((!(flags & QSE_WCSTOURI_NOQUERY) && *str == QSE_WT('?')) ||
(!(flags & QSE_WCSTOURI_NOFRAG) && *str == QSE_WT('#'))) break;
str++;
}
xuri.path.len = str - (const qse_wchar_t*)xuri.path.ptr;
if (!(flags & QSE_WCSTOURI_NOQUERY) && *str == QSE_WT('?'))
{
xuri.query.ptr = ++str;
while (*str != QSE_WT('\0'))
{
if (!(flags & QSE_WCSTOURI_NOFRAG) && *str == QSE_WT('#')) break;
str++;
}
xuri.query.len = str - (const qse_wchar_t*)xuri.query.ptr;
}
if (!(flags & QSE_WCSTOURI_NOFRAG) && *str == QSE_WT('#'))
{
xuri.frag.ptr = ++str;
while (*str != QSE_WT('\0')) str++;
xuri.frag.len = str - (const qse_wchar_t*)xuri.frag.ptr;
}
}
QSE_ASSERT (*str == QSE_WT('\0'));
*uri = xuri;
return 0; return 0;
} }

View File

@ -118,6 +118,7 @@ qse_xma_t* qse_xma_open (
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (xma + 1, 0, xtnsize);
return xma; return xma;
} }

View File

@ -24,6 +24,8 @@
#include <qse/cmn/nwif.h> #include <qse/cmn/nwif.h>
#include <qse/cmn/mbwc.h> #include <qse/cmn/mbwc.h>
#include <qse/cmn/str.h> #include <qse/cmn/str.h>
#include <qse/cmn/uri.h>
#include <qse/cmn/alg.h>
#if defined(_WIN32) #if defined(_WIN32)
# include <winsock2.h> # include <winsock2.h>
@ -68,7 +70,13 @@
struct server_xtn_t struct server_xtn_t
{ {
qse_mxstr_t docroot; #define CFG_DOCROOT 0
#define CFG_REALM 1
#define CFG_USERNAME 2
#define CFG_PASSWORD 3
#define CFG_BASICAUTH 4
#define CFG_BASICAUTH_B64 5
qse_mxstr_t cfg[6];
}; };
typedef struct server_xtn_t server_xtn_t; typedef struct server_xtn_t server_xtn_t;
@ -421,132 +429,143 @@ void* qse_httpd_getxtnstd (qse_httpd_t* httpd)
return (void*)((httpd_xtn_t*)QSE_XTN(httpd) + 1); return (void*)((httpd_xtn_t*)QSE_XTN(httpd) + 1);
} }
static int parse_server_uri (
qse_httpd_t* httpd, const qse_char_t* uri,
qse_httpd_server_t* server, const qse_char_t** docroot)
{
qse_uint16_t default_port;
qse_cstr_t tmp;
server->flags = 0;
/* check the protocol part */
tmp.ptr = uri;
while (*uri != QSE_T(':'))
{
if (*uri == QSE_T('\0'))
{
httpd->errnum = QSE_HTTPD_EINVAL;
return -1;
}
uri++;
}
tmp.len = uri - tmp.ptr;
if (qse_strxcmp (tmp.ptr, tmp.len, QSE_T("http")) == 0)
{
default_port = DEFAULT_PORT;
}
else if (qse_strxcmp (tmp.ptr, tmp.len, QSE_T("https")) == 0)
{
server->flags |= QSE_HTTPD_SERVER_SECURE;
default_port = DEFAULT_SECURE_PORT;
}
else
{
httpd->errnum = QSE_HTTPD_EINVAL;
return -1;
}
uri++; /* skip : */
if (*uri != QSE_T('/'))
{
httpd->errnum = QSE_HTTPD_EINVAL;
return -1;
}
uri++; /* skip / */
if (*uri != QSE_T('/'))
{
httpd->errnum = QSE_HTTPD_EINVAL;
return -1;
}
uri++; /* skip / */
tmp.ptr = uri;
while (*uri != QSE_T('\0') && *uri != QSE_T('/')) uri++;
tmp.len = uri - tmp.ptr;
if (qse_strntonwad (tmp.ptr, tmp.len, &server->nwad) <= -1)
{
httpd->errnum = QSE_HTTPD_EINVAL;
return -1;
}
*docroot = uri;
if (server->nwad.type == QSE_NWAD_IN4)
{
if (server->nwad.u.in4.port == 0)
server->nwad.u.in4.port = qse_hton16(default_port);
}
else if (server->nwad.type == QSE_NWAD_IN6)
{
if (server->nwad.u.in6.port == 0)
server->nwad.u.in6.port = qse_hton16(default_port);
}
return 0;
}
static void predetach_server (qse_httpd_t* httpd, qse_httpd_server_t* server) static void predetach_server (qse_httpd_t* httpd, qse_httpd_server_t* server)
{ {
server_xtn_t* server_xtn; server_xtn_t* server_xtn;
qse_size_t i;
server_xtn = (server_xtn_t*) qse_httpd_getserverxtn (httpd, server); server_xtn = (server_xtn_t*) qse_httpd_getserverxtn (httpd, server);
if (server_xtn->docroot.ptr)
for (i = QSE_COUNTOF(server_xtn->cfg); i > 0; )
{ {
QSE_MMGR_FREE (httpd->mmgr, server_xtn->docroot.ptr); i--;
server_xtn->docroot.ptr = QSE_NULL; if (server_xtn->cfg[i].ptr)
server_xtn->docroot.len = 0; {
QSE_MMGR_FREE (httpd->mmgr, server_xtn->cfg[i].ptr);
server_xtn->cfg[i].ptr = QSE_NULL;
server_xtn->cfg[i].len = 0;
}
} }
} }
qse_httpd_server_t* qse_httpd_attachserverstd ( qse_httpd_server_t* qse_httpd_attachserverstd (
qse_httpd_t* httpd, const qse_char_t* uri, qse_size_t xtnsize) qse_httpd_t* httpd, const qse_char_t* uri, qse_size_t xtnsize)
{ {
qse_httpd_server_t server, * xserver; qse_httpd_server_t server;
const qse_char_t* docroot; qse_httpd_server_t* xserver;
server_xtn_t* server_xtn; server_xtn_t* server_xtn;
qse_mcstr_t tmp[4];
if (parse_server_uri (httpd, uri, &server, &docroot) <= -1) return QSE_NULL; qse_uint16_t default_port;
server.predetach = predetach_server; qse_size_t i;
qse_uri_t xuri;
xserver = qse_httpd_attachserver ( QSE_MEMSET (&server, 0, QSE_SIZEOF(server));
httpd, &server, QSE_SIZEOF(*server_xtn) + xtnsize);
if (xserver == QSE_NULL) return QSE_NULL;
if (docroot[0] == QSE_T('/') && docroot[1] != QSE_T('\0')) if (qse_strtouri (uri, &xuri, QSE_STRTOURI_NOQUERY) <= -1) goto invalid;
if (qse_strxcmp (xuri.scheme.ptr, xuri.scheme.len, QSE_T("http")) == 0)
{ {
server_xtn = qse_httpd_getserverxtn (httpd, xserver); default_port = DEFAULT_PORT;
}
else if (qse_strxcmp (xuri.scheme.ptr, xuri.scheme.len, QSE_T("https")) == 0)
{
server.flags |= QSE_HTTPD_SERVER_SECURE;
default_port = DEFAULT_SECURE_PORT;
}
else goto invalid;
#if defined(QSE_CHAR_IS_MCHAR) if (qse_strntonwad (
server_xtn->docroot.ptr = qse_mbsdup (docroot, httpd->mmgr); xuri.host.ptr,
#else xuri.host.len + (xuri.port.ptr? (xuri.port.len + 1): 0),
server_xtn->docroot.ptr = qse_wcstombsdup (docroot, httpd->mmgr); &server.nwad) <= -1) goto invalid;
#endif
if (server_xtn->docroot.ptr == QSE_NULL)
{
qse_httpd_detachserver (httpd, xserver);
httpd->errnum = QSE_HTTPD_ENOMEM;
return QSE_NULL;
}
server_xtn->docroot.len = qse_mbslen(server_xtn->docroot.ptr); if (server.nwad.type == QSE_NWAD_IN4)
{
if (server.nwad.u.in4.port == 0)
server.nwad.u.in4.port = qse_hton16(default_port);
}
else if (server.nwad.type == QSE_NWAD_IN6)
{
if (server.nwad.u.in6.port == 0)
server.nwad.u.in6.port = qse_hton16(default_port);
} }
server.predetach = predetach_server;
xserver = qse_httpd_attachserver (httpd, &server, QSE_SIZEOF(*server_xtn) + xtnsize);
if (xserver == QSE_NULL) return QSE_NULL;
server_xtn = qse_httpd_getserverxtn (httpd, xserver);
#if defined(QSE_CHAR_IS_MCHAR)
if (xuri.path.ptr) server_xtn->cfg[CFG_DOCROOT].ptr = qse_mbsxdup (xuri.path.ptr, xuri.path.len, httpd->mmgr);
if (xuri.auth.user.ptr) server_xtn->cfg[CFG_USERNAME].ptr = qse_mbsxdup (xuri.auth.user.ptr, xuri.auth.user.len, httpd->mmgr);
if (xuri.auth.pass.ptr) server_xtn->cfg[CFG_PASSWORD].ptr = qse_mbsxdup (xuri.auth.pass.ptr, xuri.auth.pass.len, httpd->mmgr);
if (xuri.frag.ptr) server_xtn->cfg[CFG_REALM].ptr = qse_mbsxdup (xuri.frag.ptr, xuri.frag.len, httpd->mmgr);
#else
if (xuri.path.ptr) server_xtn->cfg[CFG_DOCROOT].ptr = qse_wcsntombsdup (xuri.path.ptr, xuri.path.len, httpd->mmgr);
if (xuri.auth.user.ptr) server_xtn->cfg[CFG_USERNAME].ptr = qse_wcsntombsdup (xuri.auth.user.ptr, xuri.auth.user.len, httpd->mmgr);
if (xuri.auth.pass.ptr) server_xtn->cfg[CFG_PASSWORD].ptr = qse_wcsntombsdup (xuri.auth.pass.ptr, xuri.auth.pass.len, httpd->mmgr);
if (xuri.frag.ptr) server_xtn->cfg[CFG_REALM].ptr = qse_wcsntombsdup (xuri.frag.ptr, xuri.frag.len, httpd->mmgr);
#endif
if ((xuri.path.ptr && !server_xtn->cfg[CFG_DOCROOT].ptr) ||
(xuri.auth.user.ptr && !server_xtn->cfg[CFG_USERNAME].ptr) ||
(xuri.auth.pass.ptr && !server_xtn->cfg[CFG_PASSWORD].ptr) ||
(xuri.frag.ptr && !server_xtn->cfg[CFG_REALM].ptr)) goto nomem_after_attach;
for (i = 0; i < QSE_COUNTOF(server_xtn->cfg); i++)
{
if (server_xtn->cfg[i].ptr)
server_xtn->cfg[i].len = qse_mbslen(server_xtn->cfg[i].ptr);
}
tmp[0].ptr = server_xtn->cfg[CFG_USERNAME].ptr? server_xtn->cfg[CFG_USERNAME].ptr: QSE_MT("");
tmp[0].len = server_xtn->cfg[CFG_USERNAME].len;
tmp[1].ptr = QSE_MT(":");
tmp[1].len = 1;
tmp[2].ptr = server_xtn->cfg[CFG_PASSWORD].ptr? server_xtn->cfg[CFG_PASSWORD].ptr: QSE_MT("");
tmp[2].len = server_xtn->cfg[CFG_PASSWORD].len;
tmp[3].ptr = QSE_NULL;
tmp[3].len = 0;
server_xtn->cfg[CFG_BASICAUTH].ptr = qse_mbsxadup (tmp, httpd->mmgr);
if (!server_xtn->cfg[CFG_BASICAUTH].ptr) goto nomem_after_attach;
server_xtn->cfg[CFG_BASICAUTH].len = qse_mbslen (server_xtn->cfg[CFG_BASICAUTH].ptr);
server_xtn->cfg[CFG_BASICAUTH_B64].len = ((server_xtn->cfg[CFG_BASICAUTH].len / 3) + 1) * 4;
server_xtn->cfg[CFG_BASICAUTH_B64].ptr = QSE_MMGR_ALLOC (
httpd->mmgr,
(server_xtn->cfg[CFG_BASICAUTH_B64].len + 1) * QSE_SIZEOF(qse_mchar_t));
if (!server_xtn->cfg[CFG_BASICAUTH_B64].ptr) goto nomem_after_attach;
qse_enbase64 (
server_xtn->cfg[CFG_BASICAUTH].ptr,
server_xtn->cfg[CFG_BASICAUTH].len,
server_xtn->cfg[CFG_BASICAUTH_B64].ptr,
server_xtn->cfg[CFG_BASICAUTH_B64].len,
&server_xtn->cfg[CFG_BASICAUTH_B64].len
);
server_xtn->cfg[CFG_BASICAUTH_B64].ptr[server_xtn->cfg[CFG_BASICAUTH_B64].len] = QSE_MT('\0');
return xserver; return xserver;
invalid:
httpd->errnum = QSE_HTTPD_EINVAL;
return QSE_NULL;
nomem_after_attach:
qse_httpd_detachserver (httpd, xserver);
httpd->errnum = QSE_HTTPD_ENOMEM;
return QSE_NULL;
} }
void* qse_httpd_getserverxtnstd (qse_httpd_t* httpd, qse_httpd_server_t* server)
{
server_xtn_t* xtn = qse_httpd_getserverxtn (httpd, server);
return (void*)(xtn + 1);
}
/* ------------------------------------------------------------------- */ /* ------------------------------------------------------------------- */
union sockaddr_t union sockaddr_t
@ -1589,36 +1608,6 @@ if (qse_htre_getcontentlen(req) > 0)
} }
if (task == QSE_NULL) goto oops; if (task == QSE_NULL) goto oops;
} }
#if 0
if (peek)
{
const qse_htre_hdrval_t* auth;
int authorized = 0;
auth = qse_htre_getheaderval (req, QSE_MT("Authorization"));
if (auth)
{
/* TODO: PERFORM authorization... */
/* BASE64 decode... */
while (auth->next) auth = auth->next;
authorized = 1;
}
if (authorized)
{
/* nph-cgi */
task = qse_httpd_entasknph (
httpd, client, QSE_NULL, qpath, req);
}
else
{
task = qse_httpd_entaskauth (
httpd, client, QSE_NULL, QSE_MT("Secure Area"), req);
}
if (task == QSE_NULL) goto oops;
}
#endif
} }
else else
{ {
@ -1654,27 +1643,6 @@ static int proxy_request (
{ {
qse_httpd_task_t* task; qse_httpd_task_t* task;
#if 0
const qse_mchar_t* qpath;
qpath = qse_htre_qpathptr (eq);
if (qpath[0] == QSE_MT('/'))
{
host = qse_htre_getheaderval (req, QSE_MT("Host"));
if (host == QSE_NULL)
{
qse_printf (QSE_T("Host not included....\n"));
goto oops;
}
}
else
{
const qse_mchar_t* host;
qse_parseuri ();
}
#endif
/* TODO: investigate if the proxy need to handle 100-continue */ /* TODO: investigate if the proxy need to handle 100-continue */
if (peek) if (peek)
@ -1866,12 +1834,33 @@ target->u.proxy.src.u.in4.port = 0;
return 0; return 0;
#endif #endif
if (server_xtn->docroot.ptr || qpath[0] != QSE_MT('/')) if (server_xtn->cfg[CFG_REALM].ptr && server_xtn->cfg[CFG_BASICAUTH_B64].ptr)
{
const qse_htre_hdrval_t* auth;
auth = qse_htre_getheaderval (req, QSE_MT("Authorization"));
if (auth)
{
while (auth->next) auth = auth->next;
if (qse_mbszcasecmp(auth->ptr, QSE_MT("Basic "), 6) == 0)
{
if (qse_mbscmp (&auth->ptr[6], server_xtn->cfg[CFG_BASICAUTH_B64].ptr) == 0) goto auth_ok;
}
}
target->type = QSE_HTTPD_RSRC_AUTH;
target->u.auth.realm = server_xtn->cfg[CFG_REALM].ptr;
return 0;
}
auth_ok:
if (server_xtn->cfg[CFG_DOCROOT].ptr || qpath[0] != QSE_MT('/'))
{ {
const qse_mchar_t* ta[4]; const qse_mchar_t* ta[4];
qse_size_t idx = 0; qse_size_t idx = 0;
if (server_xtn->docroot.ptr) ta[idx++] = server_xtn->docroot.ptr; if (server_xtn->cfg[CFG_DOCROOT].ptr) ta[idx++] = server_xtn->cfg[CFG_DOCROOT].ptr;
if (qpath[0] != QSE_MT('/')) ta[idx++] = QSE_MT("/"); if (qpath[0] != QSE_MT('/')) ta[idx++] = QSE_MT("/");
ta[idx++] = qpath; ta[idx++] = qpath;
ta[idx++] = QSE_NULL; ta[idx++] = QSE_NULL;
@ -1912,10 +1901,11 @@ return 0;
if (xpath != qpath) if (xpath != qpath)
QSE_MMGR_FREE (httpd->mmgr, xpath); QSE_MMGR_FREE (httpd->mmgr, xpath);
if (server_xtn->docroot.ptr) if (server_xtn->cfg[CFG_DOCROOT].ptr)
{ {
xpath = qse_mbsxdup2 ( xpath = qse_mbsxdup2 (
server_xtn->docroot.ptr, server_xtn->docroot.len, server_xtn->cfg[CFG_DOCROOT].ptr,
server_xtn->cfg[CFG_DOCROOT].len,
qpath, ext - qpath + extinfo[i].len, httpd->mmgr); qpath, ext - qpath + extinfo[i].len, httpd->mmgr);
} }
else else
@ -1935,7 +1925,7 @@ return 0;
return -1; return -1;
} }
docroot = server_xtn->docroot.ptr; docroot = server_xtn->cfg[CFG_DOCROOT].ptr;
} }
else else
{ {
@ -1992,5 +1982,7 @@ int qse_httpd_loopstd (qse_httpd_t* httpd, qse_httpd_cbstd_t* cbstd, qse_ntime_t
if (cbstd) xtn->cbstd = cbstd; if (cbstd) xtn->cbstd = cbstd;
else xtn->cbstd = &httpd_cbstd; else xtn->cbstd = &httpd_cbstd;
return qse_httpd_loop (httpd, &httpd_system_callbacks, &httpd_request_callbacks, timeout); return qse_httpd_loop (
httpd, &httpd_system_callbacks,
&httpd_request_callbacks, timeout);
} }

View File

@ -57,6 +57,7 @@ qse_httpd_t* qse_httpd_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
return QSE_NULL; return QSE_NULL;
} }
QSE_MEMSET (httpd + 1, 0, xtnsize);
return httpd; return httpd;
} }
@ -82,7 +83,6 @@ int qse_httpd_init (qse_httpd_t* httpd, qse_mmgr_t* mmgr)
void qse_httpd_fini (qse_httpd_t* httpd) void qse_httpd_fini (qse_httpd_t* httpd)
{ {
/* TODO */
free_server_list (httpd); free_server_list (httpd);
} }

View File

@ -39,6 +39,7 @@ bin_PROGRAMS = \
str01 \ str01 \
time \ time \
tre01 \ tre01 \
uri01 \
xma xma
LDFLAGS = -L../../lib/cmn LDFLAGS = -L../../lib/cmn

View File

@ -42,7 +42,7 @@ bin_PROGRAMS = chr01$(EXEEXT) env$(EXEEXT) dll$(EXEEXT) fio01$(EXEEXT) \
pio$(EXEEXT) pma$(EXEEXT) rex01$(EXEEXT) rbt$(EXEEXT) \ pio$(EXEEXT) pma$(EXEEXT) rex01$(EXEEXT) rbt$(EXEEXT) \
sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) sll$(EXEEXT) \ sio01$(EXEEXT) sio02$(EXEEXT) sio03$(EXEEXT) sll$(EXEEXT) \
slmb01$(EXEEXT) str01$(EXEEXT) time$(EXEEXT) tre01$(EXEEXT) \ slmb01$(EXEEXT) str01$(EXEEXT) time$(EXEEXT) tre01$(EXEEXT) \
xma$(EXEEXT) uri01$(EXEEXT) xma$(EXEEXT)
@WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS) @WCHAR_TRUE@@WIN32_TRUE@am__append_1 = $(UNICOWS_LIBS)
subdir = samples/cmn subdir = samples/cmn
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
@ -190,6 +190,10 @@ am_tre01_OBJECTS = tre01.$(OBJEXT)
tre01_OBJECTS = $(am_tre01_OBJECTS) tre01_OBJECTS = $(am_tre01_OBJECTS)
tre01_LDADD = $(LDADD) tre01_LDADD = $(LDADD)
tre01_DEPENDENCIES = $(am__DEPENDENCIES_2) tre01_DEPENDENCIES = $(am__DEPENDENCIES_2)
uri01_SOURCES = uri01.c
uri01_OBJECTS = uri01.$(OBJEXT)
uri01_LDADD = $(LDADD)
uri01_DEPENDENCIES = $(am__DEPENDENCIES_2)
am_xma_OBJECTS = xma.$(OBJEXT) am_xma_OBJECTS = xma.$(OBJEXT)
xma_OBJECTS = $(am_xma_OBJECTS) xma_OBJECTS = $(am_xma_OBJECTS)
xma_LDADD = $(LDADD) xma_LDADD = $(LDADD)
@ -217,7 +221,7 @@ SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \ $(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
$(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \ $(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \
$(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \ $(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \
$(tre01_SOURCES) $(xma_SOURCES) $(tre01_SOURCES) uri01.c $(xma_SOURCES)
DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \ DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \ $(fio01_SOURCES) $(fio02_SOURCES) $(fma_SOURCES) \
$(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \ $(fmt01_SOURCES) $(fmt02_SOURCES) $(fs01_SOURCES) \
@ -228,7 +232,7 @@ DIST_SOURCES = $(chr01_SOURCES) $(dll_SOURCES) $(env_SOURCES) \
$(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \ $(rbt_SOURCES) $(rex01_SOURCES) $(sio01_SOURCES) \
$(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \ $(sio02_SOURCES) $(sio03_SOURCES) $(sll_SOURCES) \
$(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \ $(slmb01_SOURCES) $(str01_SOURCES) $(time_SOURCES) \
$(tre01_SOURCES) $(xma_SOURCES) $(tre01_SOURCES) uri01.c $(xma_SOURCES)
ETAGS = etags ETAGS = etags
CTAGS = ctags CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -598,6 +602,9 @@ time$(EXEEXT): $(time_OBJECTS) $(time_DEPENDENCIES) $(EXTRA_time_DEPENDENCIES)
tre01$(EXEEXT): $(tre01_OBJECTS) $(tre01_DEPENDENCIES) $(EXTRA_tre01_DEPENDENCIES) tre01$(EXEEXT): $(tre01_OBJECTS) $(tre01_DEPENDENCIES) $(EXTRA_tre01_DEPENDENCIES)
@rm -f tre01$(EXEEXT) @rm -f tre01$(EXEEXT)
$(LINK) $(tre01_OBJECTS) $(tre01_LDADD) $(LIBS) $(LINK) $(tre01_OBJECTS) $(tre01_LDADD) $(LIBS)
uri01$(EXEEXT): $(uri01_OBJECTS) $(uri01_DEPENDENCIES) $(EXTRA_uri01_DEPENDENCIES)
@rm -f uri01$(EXEEXT)
$(LINK) $(uri01_OBJECTS) $(uri01_LDADD) $(LIBS)
xma$(EXEEXT): $(xma_OBJECTS) $(xma_DEPENDENCIES) $(EXTRA_xma_DEPENDENCIES) xma$(EXEEXT): $(xma_OBJECTS) $(xma_DEPENDENCIES) $(EXTRA_xma_DEPENDENCIES)
@rm -f xma$(EXEEXT) @rm -f xma$(EXEEXT)
$(LINK) $(xma_OBJECTS) $(xma_LDADD) $(LIBS) $(LINK) $(xma_OBJECTS) $(xma_LDADD) $(LIBS)
@ -640,6 +647,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/str01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre01.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tre01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/uri01.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xma.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xma.Po@am__quote@
.c.o: .c.o:

139
qse/samples/cmn/uri01.c Normal file
View File

@ -0,0 +1,139 @@
#include <qse/cmn/uri.h>
#include <qse/cmn/main.h>
#include <qse/cmn/mbwc.h>
#include <qse/cmn/stdio.h>
#include <locale.h>
#if defined(_WIN32)
# include <windows.h>
#endif
static void xxx (const qse_wchar_t* ptr, qse_size_t len)
{
if (ptr)
{
qse_size_t i;
qse_printf (QSE_T(" ["));
for (i = 0; i < len; i++)
qse_printf (QSE_T("%hc"), ptr[i]);
qse_printf (QSE_T("] "));
}
else
{
qse_printf (QSE_T(" (null) "));
}
}
static int test_main (int argc, qse_char_t* argv[], qse_char_t* envp[])
{
static const qse_wchar_t* wcs[] =
{
QSE_WT("http://www.google.com"),
QSE_WT("http://www.google.com:80"),
QSE_WT("http://abc@www.google.com:80"),
QSE_WT("http://abc:def@www.google.com:80"),
QSE_WT("http://abc:def@www.google.com:80/"),
QSE_WT("http://abc:def@www.google.com:80/?#"),
QSE_WT("http://abc:def@www.google.com:80/abcdef/ghi?kkk=23#fragment"),
QSE_WT("http://abc:def@www.google.com:80/abcdef/ghi#fragment#fragment"),
QSE_WT("http://abc:def@www@.google.com:80/abcdef/ghi#fragment#fragment"),
QSE_WT("http://@@@@@abc:def@www@.google.com:80/abcdef/ghi#fragment#fragment")
};
qse_size_t i;
qse_uri_t uri;
for (i = 0; i < QSE_COUNTOF(wcs); i++)
{
qse_printf (QSE_T("[%ls] => "), wcs[i]);
if (qse_wcstouri (wcs[i], &uri, 0) <= -1)
{
qse_printf (QSE_T("[ERROR]"));
}
else
{
xxx (uri.scheme.ptr, uri.scheme.len);
xxx (uri.auth.user.ptr, uri.auth.user.len);
xxx (uri.auth.pass.ptr, uri.auth.pass.len);
xxx (uri.host.ptr, uri.host.len);
xxx (uri.port.ptr, uri.port.len);
xxx (uri.path.ptr, uri.path.len);
xxx (uri.query.ptr, uri.query.len);
xxx (uri.frag.ptr, uri.frag.len);
}
qse_printf (QSE_T("\n"));
}
qse_printf (QSE_T("================================================\n"));
for (i = 0; i < QSE_COUNTOF(wcs); i++)
{
qse_printf (QSE_T("[%ls] => "), wcs[i]);
if (qse_wcstouri (wcs[i], &uri, QSE_WCSTOURI_NOQUERY | QSE_WCSTOURI_NOAUTH) <= -1)
{
qse_printf (QSE_T("[ERROR]"));
}
else
{
xxx (uri.scheme.ptr, uri.scheme.len);
xxx (uri.auth.user.ptr, uri.auth.user.len);
xxx (uri.auth.pass.ptr, uri.auth.pass.len);
xxx (uri.host.ptr, uri.host.len);
xxx (uri.port.ptr, uri.port.len);
xxx (uri.path.ptr, uri.path.len);
xxx (uri.query.ptr, uri.query.len);
xxx (uri.frag.ptr, uri.frag.len);
}
qse_printf (QSE_T("\n"));
}
qse_printf (QSE_T("================================================\n"));
for (i = 0; i < QSE_COUNTOF(wcs); i++)
{
qse_printf (QSE_T("[%ls] => "), wcs[i]);
if (qse_wcstouri (wcs[i], &uri, QSE_WCSTOURI_NOQUERY | QSE_WCSTOURI_NOAUTH | QSE_WCSTOURI_NOFRAG) <= -1)
{
qse_printf (QSE_T("[ERROR]"));
}
else
{
xxx (uri.scheme.ptr, uri.scheme.len);
xxx (uri.auth.user.ptr, uri.auth.user.len);
xxx (uri.auth.pass.ptr, uri.auth.pass.len);
xxx (uri.host.ptr, uri.host.len);
xxx (uri.port.ptr, uri.port.len);
xxx (uri.path.ptr, uri.path.len);
xxx (uri.query.ptr, uri.query.len);
xxx (uri.frag.ptr, uri.frag.len);
}
qse_printf (QSE_T("\n"));
}
qse_printf (QSE_T("================================================\n"));
return 0;
}
int qse_main (int argc, qse_achar_t* argv[], qse_achar_t* envp[])
{
#if defined(_WIN32)
char locale[100];
UINT codepage = GetConsoleOutputCP();
if (codepage == CP_UTF8)
{
/*SetConsoleOUtputCP (CP_UTF8);*/
qse_setdflcmgr (qse_utf8cmgr);
}
else
{
sprintf (locale, ".%u", (unsigned int)codepage);
setlocale (LC_ALL, locale);
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
}
#else
setlocale (LC_ALL, "");
qse_setdflcmgrbyid (QSE_CMGR_SLMB);
#endif
return qse_runmainwithenv (argc, argv, envp, test_main);
}

View File

@ -55,6 +55,7 @@ static void sigint (int sig)
} }
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
#if 0
static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, const qse_char_t* uri) static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, const qse_char_t* uri)
{ {
qse_httpd_server_t server, * xserver; qse_httpd_server_t server, * xserver;
@ -93,6 +94,7 @@ static qse_httpd_server_t* attach_server (qse_httpd_t* httpd, const qse_char_t*
return xserver; return xserver;
} }
#endif
/* --------------------------------------------------------------------- */ /* --------------------------------------------------------------------- */
static int httpd_main (int argc, qse_char_t* argv[]) static int httpd_main (int argc, qse_char_t* argv[])
@ -116,7 +118,7 @@ static int httpd_main (int argc, qse_char_t* argv[])
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
{ {
if (attach_server (httpd, argv[i]) == QSE_NULL) if (qse_httpd_attachserverstd (httpd, argv[i], 0) == QSE_NULL)
{ {
qse_fprintf (QSE_STDERR, qse_fprintf (QSE_STDERR,
QSE_T("Failed to add httpd listener - %s\n"), argv[i]); QSE_T("Failed to add httpd listener - %s\n"), argv[i]);