added qse_mbstouri()/qse_wcstouri()/qse_strtouri().
added qse_enbase64()/qse_debase64(). enhanced basic authorization to httpd-std
This commit is contained in:
@ -22,6 +22,7 @@ noinst_HEADERS = \
|
||||
tre-stack.h
|
||||
|
||||
libqsecmn_la_SOURCES = \
|
||||
alg-base64.c \
|
||||
alg-rand.c \
|
||||
alg-search.c \
|
||||
alg-sort.c \
|
||||
@ -100,6 +101,7 @@ libqsecmn_la_SOURCES = \
|
||||
tre-match-parallel.c \
|
||||
tre-parse.c \
|
||||
tre-stack.c \
|
||||
uri.c \
|
||||
utf8.c \
|
||||
xma.c
|
||||
|
||||
|
@ -82,11 +82,11 @@ am__installdirs = "$(DESTDIR)$(libdir)"
|
||||
LTLIBRARIES = $(lib_LTLIBRARIES)
|
||||
am__DEPENDENCIES_1 =
|
||||
libqsecmn_la_DEPENDENCIES = $(am__DEPENDENCIES_1)
|
||||
am_libqsecmn_la_OBJECTS = alg-rand.lo alg-search.lo alg-sort.lo \
|
||||
assert.lo chr.lo cp949.lo cp950.lo dll.lo env.lo gdl.lo htb.lo \
|
||||
fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo glob.lo \
|
||||
hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.lo mem.lo \
|
||||
nwad.lo nwif.lo nwio.lo oht.lo opt.lo path-basename.lo \
|
||||
am_libqsecmn_la_OBJECTS = alg-base64.lo alg-rand.lo alg-search.lo \
|
||||
alg-sort.lo assert.lo chr.lo cp949.lo cp950.lo dll.lo env.lo \
|
||||
gdl.lo htb.lo fio.lo fma.lo fmt.lo fs.lo fs-err.lo fs-move.lo \
|
||||
glob.lo hton.lo ipad.lo lda.lo main.lo mbwc.lo mbwc-str.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 \
|
||||
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 \
|
||||
@ -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 \
|
||||
time.lo tio.lo tre.lo tre-ast.lo tre-compile.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_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) \
|
||||
$(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
|
||||
@ -312,6 +312,7 @@ noinst_HEADERS = \
|
||||
tre-stack.h
|
||||
|
||||
libqsecmn_la_SOURCES = \
|
||||
alg-base64.c \
|
||||
alg-rand.c \
|
||||
alg-search.c \
|
||||
alg-sort.c \
|
||||
@ -390,6 +391,7 @@ libqsecmn_la_SOURCES = \
|
||||
tre-match-parallel.c \
|
||||
tre-parse.c \
|
||||
tre-stack.c \
|
||||
uri.c \
|
||||
utf8.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)/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-search.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-stack.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)/xma.Plo@am__quote@
|
||||
|
||||
|
109
qse/lib/cmn/alg-base64.c
Normal file
109
qse/lib/cmn/alg-base64.c
Normal 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;
|
||||
}
|
@ -60,6 +60,7 @@ qse_dll_t* qse_dll_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (dll + 1, 0, xtnsize);
|
||||
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)
|
||||
{
|
||||
/* do not zero out the xtnsizeension */
|
||||
/* do not zero out the extension */
|
||||
QSE_MEMSET (dll, 0, QSE_SIZEOF(*dll));
|
||||
|
||||
dll->mmgr = mmgr;
|
||||
|
@ -50,6 +50,7 @@ qse_env_t* qse_env_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, int fromcurenv)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (env + 1, 0, xtnsize);
|
||||
return env;
|
||||
}
|
||||
|
||||
|
@ -38,6 +38,7 @@ qse_fma_t* qse_fma_open (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (fma + 1, 0, xtnsize);
|
||||
return fma;
|
||||
}
|
||||
|
||||
|
@ -67,6 +67,7 @@ qse_fs_t* qse_fs_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (fs + 1, 0, xtnsize);
|
||||
return fs;
|
||||
}
|
||||
|
||||
|
@ -274,6 +274,7 @@ htb_t* qse_htb_open (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (htb + 1, 0, xtnsize);
|
||||
return htb;
|
||||
}
|
||||
|
||||
|
@ -489,6 +489,21 @@ qse_mchar_t* qse_wcstombsdupwithcmgr (const qse_wchar_t* wcs, qse_mmgr_t* mmgr,
|
||||
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* buf, * ptr;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
return qse_wcsatombsdupwithcmgr (wcs, mmgr, dfl_cmgr);
|
||||
|
@ -343,6 +343,7 @@ qse_nwio_t* qse_nwio_open (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (nwio + 1, 0, xtnsize);
|
||||
return nwio;
|
||||
}
|
||||
|
||||
|
@ -57,6 +57,7 @@ qse_oht_t* qse_oht_open (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (oht + 1, 0, xtnsize);
|
||||
return oht;
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,7 @@ qse_pma_t* qse_pma_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (pma + 1, 0, xtnsize);
|
||||
return pma;
|
||||
}
|
||||
|
||||
|
@ -210,6 +210,7 @@ rbt_t* qse_rbt_open (mmgr_t* mmgr, size_t xtnsize, int kscale, int vscale)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (rbt + 1, 0, xtnsize);
|
||||
return rbt;
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,7 @@ qse_sio_t* qse_sio_open (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (sio + 1, 0, xtnsize);
|
||||
return sio;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -91,6 +91,25 @@ qse_mchar_t* qse_mbsadup (const qse_mchar_t* str[], qse_mmgr_t* mmgr)
|
||||
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)
|
||||
@ -165,3 +184,21 @@ qse_wchar_t* qse_wcsadup (const qse_wchar_t* str[], qse_mmgr_t* mmgr)
|
||||
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;
|
||||
}
|
||||
|
@ -45,6 +45,7 @@ qse_tio_t* qse_tio_open (qse_mmgr_t* mmgr, qse_size_t xtnsize, int flags)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (tio + 1, 0, xtnsize);
|
||||
return tio;
|
||||
}
|
||||
|
||||
|
@ -37,6 +37,7 @@ qse_tre_t* qse_tre_open (qse_mmgr_t* mmgr, qse_size_t xtnsize)
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (tre + 1, 0, xtnsize);
|
||||
return tre;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
qse_size_t len;
|
||||
const qse_mchar_t* ptr, * colon;
|
||||
qse_uri_t xuri;
|
||||
|
||||
QSE_MEMSET (xuri, 0, QSE_SIZEOF(xuri));
|
||||
QSE_MEMSET (&xuri, 0, QSE_SIZEOF(xuri));
|
||||
|
||||
/* scheme */
|
||||
xuri.scheme.ptr = ptr;
|
||||
while (*uri != QSE_T(':'))
|
||||
xuri.scheme.ptr = str;
|
||||
while (*str != QSE_MT(':'))
|
||||
{
|
||||
if (*uri == QSE_T('\0')) return -1;
|
||||
uri++;
|
||||
if (*str == QSE_MT('\0')) return -1;
|
||||
str++;
|
||||
}
|
||||
xuri.scheme.len = uri - xuri.scheme.ptr;
|
||||
xuri.scheme.len = str - (const qse_mchar_t*)xuri.scheme.ptr;
|
||||
|
||||
uri++; /* skip : */
|
||||
if (*uri != QSE_T('/')) return -1;
|
||||
uri++; /* skip / */
|
||||
if (*uri != QSE_T('/')) return -1;
|
||||
uri++; /* skip / */
|
||||
str++; /* skip : */
|
||||
if (*str != QSE_MT('/')) return -1;
|
||||
str++; /* skip / */
|
||||
if (*str != QSE_MT('/')) return -1;
|
||||
str++; /* skip / */
|
||||
|
||||
/* 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;
|
||||
else if (*uri == QSE_T('@'))
|
||||
{
|
||||
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 == QSE_NULL && *str == QSE_MT(':')) colon = str;
|
||||
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 = uri - colon - 1;
|
||||
xuri.port.len = str - colon - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
xuri.host.ptr = ptr;
|
||||
xuri.host.len = uri - ptr;
|
||||
xuri.host.len = str - ptr;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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('#'))
|
||||
else
|
||||
{
|
||||
xuri.query.ptr = ++uri;
|
||||
while (*uri != QSE_T('\0') && *uri != QSE_T('#')) uri++;
|
||||
xuri.query.len = uri - xuri.query.ptr;
|
||||
|
||||
if (uri == QSE_T('#'))
|
||||
if (colon == QSE_NULL && *str == QSE_MT(':')) colon = str;
|
||||
else if (xuri.auth.user.ptr == QSE_NULL && *str == QSE_MT('@'))
|
||||
{
|
||||
xuri.query.ptr = ++uri;
|
||||
while (*uri != QSE_T('\0')) uri++;
|
||||
xuri.fragment.len = uri - xuri.fragment.ptr;
|
||||
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_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;
|
||||
}
|
||||
|
@ -118,6 +118,7 @@ qse_xma_t* qse_xma_open (
|
||||
return QSE_NULL;
|
||||
}
|
||||
|
||||
QSE_MEMSET (xma + 1, 0, xtnsize);
|
||||
return xma;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user