revising httpd

This commit is contained in:
2013-02-18 13:45:50 +00:00
parent bbdf168ee8
commit 5bc774db3a
56 changed files with 1774 additions and 953 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS = cmn awk sed net
SUBDIRS = cmn awk sed http
pkgincludedir = $(includedir)/qse

View File

@ -306,7 +306,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = cmn awk sed net
SUBDIRS = cmn awk sed http
pkginclude_HEADERS = conf-msw.h conf-os2.h conf-dos.h conf-vms.h \
conf-mac.h conf-inf.h types.h macros.h pack1.h unpack.h \
$(am__append_1)

View File

@ -24,22 +24,37 @@
#include <qse/types.h>
#include <qse/macros.h>
typedef struct qse_muri_t qse_muri_t;
typedef struct qse_wuri_t qse_wuri_t;
typedef struct qse_uri_t qse_uri_t;
struct qse_uri_t
struct qse_muri_t
{
qse_cptl_t scheme;
qse_mcstr_t scheme;
struct
{
qse_cptl_t user;
qse_cptl_t pass;
qse_mcstr_t user;
qse_mcstr_t pass;
} auth;
qse_cptl_t host;
qse_cptl_t port;
qse_cptl_t path;
qse_cptl_t query;
qse_cptl_t frag;
qse_mcstr_t host;
qse_mcstr_t port;
qse_mcstr_t path;
qse_mcstr_t query;
qse_mcstr_t frag;
};
struct qse_wuri_t
{
qse_wcstr_t scheme;
struct
{
qse_wcstr_t user;
qse_wcstr_t pass;
} auth;
qse_wcstr_t host;
qse_wcstr_t port;
qse_wcstr_t path;
qse_wcstr_t query;
qse_wcstr_t frag;
};
enum qse_mbstouri_flag_t
@ -60,10 +75,12 @@ enum qse_wcstouri_flag_t
# define QSE_STRTOURI_NOAUTH QSE_MBSTOURI_NOAUTH
# define QSE_STRTOURI_NOQUERY QSE_MBSTOURI_NOQUERY
# define QSE_STRTOURI_NOFRAG QSE_MBSTOURI_NOFRAG
typedef qse_muri_t qse_uri_t;
#else
# define QSE_STRTOURI_NOAUTH QSE_WCSTOURI_NOAUTH
# define QSE_STRTOURI_NOQUERY QSE_WCSTOURI_NOQUERY
# define QSE_STRTOURI_NOFRAG QSE_WCSTOURI_NOFRAG
typedef qse_wuri_t qse_uri_t;
#endif
#ifdef __cplusplus
@ -72,13 +89,13 @@ extern "C" {
QSE_EXPORT int qse_mbstouri (
const qse_mchar_t* str,
qse_uri_t* uri,
qse_muri_t* uri,
int flags
);
QSE_EXPORT int qse_wcstouri (
const qse_wchar_t* str,
qse_uri_t* uri,
qse_wuri_t* uri,
int flags
);

View File

@ -0,0 +1,4 @@
pkgincludedir= $(includedir)/qse/http
pkginclude_HEADERS = http.h htre.h htrd.h httpd.h std.h upxd.h

View File

@ -33,7 +33,7 @@ PRE_UNINSTALL = :
POST_UNINSTALL = :
build_triplet = @build@
host_triplet = @host@
subdir = include/qse/net
subdir = include/qse/http
DIST_COMMON = $(pkginclude_HEADERS) $(srcdir)/Makefile.am \
$(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -89,7 +89,7 @@ HEADERS = $(pkginclude_HEADERS)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
pkgincludedir = $(includedir)/qse/net
pkgincludedir = $(includedir)/qse/http
ACLOCAL = @ACLOCAL@
AMTAR = @AMTAR@
AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@
@ -264,7 +264,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
pkginclude_HEADERS = http.h htre.h htrd.h httpd.h upxd.h
pkginclude_HEADERS = http.h htre.h htrd.h httpd.h std.h upxd.h
all: all-am
.SUFFIXES:
@ -277,9 +277,9 @@ $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
exit 1;; \
esac; \
done; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/qse/net/Makefile'; \
echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign include/qse/http/Makefile'; \
$(am__cd) $(top_srcdir) && \
$(AUTOMAKE) --foreign include/qse/net/Makefile
$(AUTOMAKE) --foreign include/qse/http/Makefile
.PRECIOUS: Makefile
Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
@case '$?' in \

View File

@ -18,11 +18,11 @@
License along with QSE. If not, see <htrd://www.gnu.org/licenses/>.
*/
#ifndef _QSE_NET_HTRD_H_
#define _QSE_NET_HTRD_H_
#ifndef _QSE_HTTP_HTRD_H_
#define _QSE_HTTP_HTRD_H_
#include <qse/net/http.h>
#include <qse/net/htre.h>
#include <qse/http/http.h>
#include <qse/http/htre.h>
typedef struct qse_htrd_t qse_htrd_t;

View File

@ -18,10 +18,10 @@
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _QSE_NET_HTRE_H_
#define _QSE_NET_HTRE_H_
#ifndef _QSE_HTTP_HTRE_H_
#define _QSE_HTTP_HTRE_H_
#include <qse/net/http.h>
#include <qse/http/http.h>
#include <qse/cmn/htb.h>
#include <qse/cmn/str.h>

View File

@ -18,8 +18,8 @@
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _QSE_NET_HTTP_H_
#define _QSE_NET_HTTP_H_
#ifndef _QSE_HTTP_HTTP_H_
#define _QSE_HTTP_HTTP_H_
/** @file
* This file provides basic data types and functions for the http protocol.

View File

@ -18,17 +18,18 @@
License along with QSE. If not, see <htrd://www.gnu.org/licenses/>.
*/
#ifndef _QSE_NET_HTTPD_H_
#define _QSE_NET_HTTPD_H_
#ifndef _QSE_HTTP_HTTPD_H_
#define _QSE_HTTP_HTTPD_H_
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/net/htre.h>
#include <qse/net/htrd.h>
#include <qse/http/htre.h>
#include <qse/http/htrd.h>
#include <qse/cmn/nwad.h>
#include <qse/cmn/time.h>
typedef struct qse_httpd_t qse_httpd_t;
typedef struct qse_httpd_mate_t qse_httpd_mate_t;
typedef struct qse_httpd_server_t qse_httpd_server_t;
typedef struct qse_httpd_client_t qse_httpd_client_t;
@ -300,17 +301,28 @@ struct qse_httpd_task_t
qse_httpd_task_t* next;
};
enum qse_httpd_sctype_t
enum qse_httpd_mate_type_t
{
QSE_HTTPD_SERVER,
QSE_HTTPD_CLIENT
};
typedef enum qse_httpd_sctype_t qse_httpd_sctype_t;
typedef enum qse_httpd_mate_type_t qse_httpd_mate_type_t;
/* it contains header fields common between
* qse_httpd_cleint_t and qse_httpd_server_t. */
#define QSE_HTTPD_MATE_HDR \
qse_httpd_mate_type_t type
struct qse_httpd_mate_t
{
/* == PRIVATE == */
QSE_HTTPD_MATE_HDR;
};
struct qse_httpd_client_t
{
/* == PRIVATE == */
qse_httpd_sctype_t type;
QSE_HTTPD_MATE_HDR;
/* == PUBLIC == */
qse_ubi_t handle;
@ -352,22 +364,36 @@ typedef void (*qse_httpd_server_predetach_t) (
qse_httpd_server_t* server
);
struct qse_httpd_server_t
{
qse_httpd_sctype_t type;
typedef void (*qse_httpd_server_reconfig_t) (
qse_httpd_t* httpd,
qse_httpd_server_t* server
);
/* ---------------------------------------------- */
int flags;
typedef struct qse_httpd_server_dope_t qse_httpd_server_dope_t;
struct qse_httpd_server_dope_t
{
int flags; /* bitwise-ORed of qse_httpd_server_flag_t */
qse_nwad_t nwad; /* binding address */
unsigned int nwif; /* interface number to bind to */
qse_httpd_server_predetach_t predetach; /* executed when the server is detached */
qse_httpd_server_reconfig_t reconfig; /* executed when reconfiguration is requested */
};
struct qse_httpd_server_t
{
/* == PRIVATE == */
QSE_HTTPD_MATE_HDR;
/* provided by a user for attaching */
qse_httpd_server_dope_t dope;
/* set by server.open callback */
qse_ubi_t handle;
/* private */
qse_httpd_server_predetach_t predetach;
qse_httpd_server_t* next;
qse_httpd_server_t* prev;
qse_httpd_server_t* next;
qse_httpd_server_t* prev;
};
/* -------------------------------------------------------------------------- */
@ -480,54 +506,6 @@ struct qse_httpd_ecb_t
qse_httpd_ecb_t* next;
};
typedef struct qse_httpd_server_cbstd_t qse_httpd_server_cbstd_t;
struct qse_httpd_server_cbstd_t
{
int (*makersrc) (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, qse_httpd_rsrc_t* rsrc); /* required */
void (*freersrc) (qse_httpd_t* httpd, qse_httpd_client_t* client, qse_htre_t* req, qse_httpd_rsrc_t* rsrc); /* optional */
};
typedef struct qse_httpd_server_cgistd_t qse_httpd_server_cgistd_t;
struct qse_httpd_server_cgistd_t
{
const qse_mchar_t* ext;
qse_size_t len;
int nph;
const qse_mchar_t* shebang; /* optional, can be #QSE_NULL */
};
typedef struct qse_httpd_server_mimestd_t qse_httpd_server_mimestd_t;
struct qse_httpd_server_mimestd_t
{
const qse_mchar_t* ext;
const qse_mchar_t* type;
};
/**
* The qse_httpd_server_idxstd_t type defines a structure to hold
* an index file name.
*/
typedef struct qse_httpd_server_idxstd_t qse_httpd_server_idxstd_t;
struct qse_httpd_server_idxstd_t
{
const qse_mchar_t* name;
};
enum qse_httpd_server_optstd_t
{
QSE_HTTPD_SERVER_DOCROOT = 0, /* const qse_mchar_t* */
QSE_HTTPD_SERVER_REALM, /* const qse_mchar_t* */
QSE_HTTPD_SERVER_AUTH, /* const qse_mchar_t* */
QSE_HTTPD_SERVER_DIRCSS, /* const qse_mchar_t* */
QSE_HTTPD_SERVER_ERRCSS, /* const qse_mchar_t* */
QSE_HTTPD_SERVER_CBSTD, /* qse_httpd_server_cbstd_t* */
QSE_HTTPD_SERVER_CGISTD, /* qse_httpd_server_cgistd_t[] */
QSE_HTTPD_SERVER_MIMESTD, /* qse_httpd_server_mimestd_t[] */
QSE_HTTPD_SERVER_IDXSTD /* qse_httpd_server_idxstd_t[] */
};
typedef enum qse_httpd_server_optstd_t qse_httpd_server_optstd_t;
#ifdef __cplusplus
extern "C" {
#endif
@ -610,13 +588,16 @@ QSE_EXPORT void qse_httpd_stop (
qse_httpd_t* httpd
);
QSE_EXPORT void qse_httpd_reconfig (
qse_httpd_t* httpd
);
#define qse_httpd_getserverxtn(httpd,server) ((void*)(server+1))
QSE_EXPORT qse_httpd_server_t* qse_httpd_attachserver (
qse_httpd_t* httpd,
const qse_httpd_server_t* tmpl,
qse_httpd_server_predetach_t predetach,
qse_size_t xtnsize
qse_httpd_t* httpd,
const qse_httpd_server_dope_t* dope,
qse_size_t xtnsize
);
QSE_EXPORT void qse_httpd_detachserver (
@ -804,6 +785,11 @@ QSE_EXPORT void* qse_httpd_allocmem (
qse_size_t size
);
QSE_EXPORT void* qse_httpd_callocmem (
qse_httpd_t* httpd,
qse_size_t size
);
QSE_EXPORT void* qse_httpd_reallocmem (
qse_httpd_t* httpd,
void* ptr,
@ -815,53 +801,17 @@ QSE_EXPORT void qse_httpd_freemem (
void* ptr
);
/* -------------------------------------------- */
QSE_EXPORT qse_httpd_t* qse_httpd_openstd (
qse_size_t xtnsize
QSE_EXPORT qse_mchar_t* qse_httpd_strtombsdup (
qse_httpd_t* httpd,
const qse_char_t* str
);
QSE_EXPORT qse_httpd_t* qse_httpd_openstdwithmmgr (
qse_mmgr_t* mmgr,
qse_size_t xtnsize
);
QSE_EXPORT void* qse_httpd_getxtnstd (
qse_httpd_t* httpd
);
QSE_EXPORT qse_httpd_server_t* qse_httpd_attachserverstd (
qse_httpd_t* httpd,
const qse_char_t* uri,
qse_httpd_server_predetach_t predetach,
qse_size_t xtnsize
);
QSE_EXPORT int qse_httpd_getserveroptstd (
qse_httpd_t* httpd,
qse_httpd_server_t* server,
qse_httpd_server_optstd_t id,
void* value
);
QSE_EXPORT int qse_httpd_setserveroptstd (
qse_httpd_t* httpd,
qse_httpd_server_t* server,
qse_httpd_server_optstd_t id,
const void* value
);
QSE_EXPORT void* qse_httpd_getserverxtnstd (
qse_httpd_t* httpd,
qse_httpd_server_t* server
);
QSE_EXPORT int qse_httpd_loopstd (
QSE_EXPORT qse_mchar_t* qse_httpd_strntombsdup (
qse_httpd_t* httpd,
const qse_ntime_t* tmout
const qse_char_t* str,
qse_size_t len
);
#ifdef __cplusplus
}
#endif

View File

@ -18,8 +18,8 @@
License along with QSE. If not, see <htrd://www.gnu.org/licenses/>.
*/
#ifndef _QSE_NET_UPXD_H_
#define _QSE_NET_UPXD_H_
#ifndef _QSE_HTTP_UPXD_H_
#define _QSE_HTTP_UPXD_H_
#include <qse/types.h>
#include <qse/macros.h>

View File

@ -1,4 +0,0 @@
pkgincludedir= $(includedir)/qse/net
pkginclude_HEADERS = http.h htre.h htrd.h httpd.h upxd.h

137
qse/include/qse/xli/std.h Normal file
View File

@ -0,0 +1,137 @@
/*
* $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/>.
*/
#ifndef _QSE_XLI_STD_H_
#define _QSE_XLI_STD_H_
#include <qse/xli/xli.h>
#include <qse/cmn/sio.h>
/** \file
* This file defines functions and data types that help you create
* an xli interpreter with less effort. It is designed to be as close
* to conventional xli implementations as possible.
*
* The source script handler does not evaluate a file name of the "var=val"
* form as an assignment expression. Instead, it just treats it as a
* normal file name.
*/
/**
* The qse_xli_iostd_type_t type defines standard source I/O types.
*/
enum qse_xli_iostd_type_t
{
QSE_XLI_IOSTD_NULL = 0, /**< pseudo-value to indicate no script */
QSE_XLI_IOSTD_FILE = 1, /**< file */
QSE_XLI_IOSTD_STR = 2 /**< length-bounded string */
};
typedef enum qse_xli_iostd_type_t qse_xli_iostd_type_t;
/**
* The qse_xli_iostd_t type defines a source I/O.
*/
struct qse_xli_iostd_t
{
qse_xli_iostd_type_t type;
union
{
struct
{
/** file path to open. #QSE_NULL or '-' for stdin/stdout. */
const qse_char_t* path;
/** a stream created with the file path is set with this
* cmgr if it is not #QSE_NULL. */
qse_cmgr_t* cmgr;
} file;
/**
* input string or dynamically allocated output string
*
* For input, the ptr and the len field of str indicates the
* pointer and the length of a string to read. You must set
* these fields before calling qse_xli_readstd().
*
* For output, the ptr and the len field of str indicates the
* pointer and the length of a dereadd source string. The output
* string is dynamically allocated. You don't need to set these
* fields before calling qse_xli_readstd() because they are set
* by qse_xli_readstd() and valid while the relevant xli object
* is alive. You must free the memory chunk pointed to by the
* ptr field with qse_xli_freemem() once you're done with it to
* avoid memory leaks.
*/
qse_xstr_t str;
} u;
};
typedef struct qse_xli_iostd_t qse_xli_iostd_t;
#ifdef __cplusplus
extern "C" {
#endif
/**
* The qse_xli_openstd() function creates an xli object using the default
* memory manager and primitive functions. Besides, it adds a set of
* standard intrinsic functions like atan, system, etc. Use this function
* over qse_xli_open() if you don't need finer-grained customization.
*/
QSE_EXPORT qse_xli_t* qse_xli_openstd (
qse_size_t xtnsize /**< extension size in bytes */
);
/**
* The qse_xli_openstdwithmmgr() function creates an xli object with a
* user-defined memory manager. It is equivalent to qse_xli_openstd(),
* except that you can specify your own memory manager.
*/
QSE_EXPORT qse_xli_t* qse_xli_openstdwithmmgr (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
);
/**
* The qse_xli_getxtnstd() gets the pointer to extension area created with
* qse_xli_openstd() or qse_xli_openstdwithmmgr(). You must not call
* qse_xli_getxtn() for sunch an object.
*/
QSE_EXPORT void* qse_xli_getxtnstd (
qse_xli_t* xli
);
QSE_EXPORT int qse_xli_readstd (
qse_xli_t* xli,
qse_xli_iostd_t* in
);
QSE_EXPORT int qse_xli_writestd (
qse_xli_t* xli,
qse_xli_iostd_t* out
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -39,10 +39,17 @@ enum qse_xli_errnum_t
QSE_XLI_EEXIST, /**< '${0}' already exists */
QSE_XLI_EIOFIL, /**< io error with file '${0}' */
QSE_XLI_EIOUSR, /**< i/o handler error */
QSE_XLI_ESYNTAX, /**< syntax error */
QSE_XLI_ESCOLON, /**< semicolon expected in place of '${0}' */
QSE_XLI_ELBREQ, /**< { or = expected in place of '${0}' */
QSE_XLI_ERBRCE, /**< } expected in place of '${0}' */
QSE_XLI_EPAVAL /**< pair value expected in place of '${0}' */
QSE_XLI_EPAVAL, /**< pair value expected in place of '${0}' */
QSE_XLI_ESTRNC, /**< string not closed */
QSE_XLI_EINCLSTR,/**< '@include' not followed by a string */
QSE_XLI_ELXCHR, /**< invalid character '${0} */
QSE_XLI_EXKWNR, /**< @word '${0}' not recognized */
QSE_XLI_EXKWEM /**< @ not followed by a valid word */
};
typedef enum qse_xli_errnum_t qse_xli_errnum_t;
@ -66,13 +73,14 @@ typedef enum qse_xli_opt_t qse_xli_opt_t;
enum qse_xli_trait_t
{
QSE_XLI_NAMEDKEY = (1 << 0),
QSE_XLI_NODUPKEY = (1 << 1),
QSE_XLI_KEYNODUP = (1 << 0),
QSE_XLI_KEYNAME = (1 << 1),
QSE_XLI_NOTEXT = (1 << 10)
};
typedef enum qse_xli_trait_t qse_xli_trait_t;
typedef struct qse_xli_val_t qse_xli_val_t;
typedef struct qse_xli_nil_t qse_xli_nil_t;
typedef struct qse_xli_str_t qse_xli_str_t;
typedef struct qse_xli_list_t qse_xli_list_t;
@ -83,6 +91,7 @@ typedef struct qse_xli_file_t qse_xli_file_t;
enum qse_xli_val_type_t
{
QSE_XLI_NIL,
QSE_XLI_STR,
QSE_XLI_LIST,
};
@ -104,6 +113,11 @@ struct qse_xli_val_t
QSE_XLI_VAL_HDR;
};
struct qse_xli_nil_t
{
QSE_XLI_VAL_HDR;
};
struct qse_xli_list_t
{
QSE_XLI_VAL_HDR;
@ -114,9 +128,8 @@ struct qse_xli_list_t
struct qse_xli_str_t
{
QSE_XLI_VAL_HDR;
int verbatim;
const qse_char_t* ptr;
qse_size_t len;
qse_size_t len; /* take note that qse_strlen(ptr) != len */
};
#define QSE_XLI_ATOM_HDR \
@ -142,7 +155,6 @@ struct qse_xli_text_t
{
QSE_XLI_ATOM_HDR;
const qse_char_t* ptr;
qse_size_t len;
};
struct qse_xli_file_t
@ -461,9 +473,18 @@ QSE_EXPORT void qse_xli_freemem (
void* ptr
);
QSE_EXPORT qse_xli_pair_t* qse_xli_insertpair (
qse_xli_t* xli,
qse_xli_list_t* list,
qse_xli_atom_t* peer,
const qse_char_t* key,
const qse_char_t* name,
qse_xli_val_t* val
);
QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithemptylist (
qse_xli_t* xli,
qse_xli_list_t* parent,
qse_xli_list_t* list,
qse_xli_atom_t* peer,
const qse_char_t* key,
const qse_char_t* name
@ -471,12 +492,18 @@ QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithemptylist (
QSE_EXPORT qse_xli_pair_t* qse_xli_insertpairwithstr (
qse_xli_t* xli,
qse_xli_list_t* parent,
qse_xli_list_t* list,
qse_xli_atom_t* peer,
const qse_char_t* key,
const qse_char_t* name,
const qse_char_t* value,
int verbatim
const qse_cstr_t* value
);
qse_xli_pair_t* qse_xli_findpairbyname (
qse_xli_t* xli,
const qse_xli_list_t* list,
const qse_char_t* name
);