reorganizing http functions

This commit is contained in:
2011-07-06 09:45:00 +00:00
parent 6fcd875403
commit 4d55ebbcce
26 changed files with 947 additions and 651 deletions

View File

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

View File

@ -254,7 +254,7 @@ target_alias = @target_alias@
top_build_prefix = @top_build_prefix@
top_builddir = @top_builddir@
top_srcdir = @top_srcdir@
SUBDIRS = cmn awk cut sed stx
SUBDIRS = cmn awk cut sed stx net
pkginclude_HEADERS = conf_msw.h conf_os2.h conf_dos.h conf_vms.h \
types.h macros.h pack1.h unpack.h $(am__append_1)
all: config.h

View File

@ -1,4 +0,0 @@
pkgincludedir= $(includedir)/qse/http
pkginclude_HEADERS = http.h

View File

@ -1,167 +0,0 @@
/*
* $Id: http.h 223 2008-06-26 06:44:41Z baconevi $
*
Copyright 2006-2011 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_HTTP_HTTP_H_
#define _QSE_HTTP_HTTP_H_
#include <qse/http/htre.h>
typedef struct qse_http_t qse_http_t;
enum qse_http_errnum_t
{
QSE_HTTP_ENOERR,
QSE_HTTP_ENOMEM,
QSE_HTTP_EBADRE,
QSE_HTTP_EBADHDR,
QSE_HTTP_EREQCBS
};
typedef enum qse_http_errnum_t qse_http_errnum_t;
enum qse_http_option_t
{
QSE_HTTP_LEADINGEMPTYLINES = (1 << 0)
};
typedef enum qse_http_option_t qse_http_option_t;
typedef struct qse_http_recbs_t qse_http_recbs_t;
struct qse_http_recbs_t
{
int (*request) (qse_http_t* http, qse_htre_t* req);
int (*response) (qse_http_t* http, qse_htre_t* res);
int (*expect_continue) (qse_http_t* http, qse_htre_t* req);
};
struct qse_http_t
{
QSE_DEFINE_COMMON_FIELDS (http)
qse_http_errnum_t errnum;
int option;
qse_http_recbs_t recbs;
struct
{
struct
{
int crlf; /* crlf status */
qse_size_t plen; /* raw request length excluding crlf */
qse_size_t need; /* number of octets needed for contents */
struct
{
qse_size_t len;
qse_size_t count;
int phase;
} chunk;
} s; /* state */
/* buffers needed to for processing a request */
struct
{
qse_htob_t raw; /* buffer to hold raw octets */
qse_htob_t tra; /* buffer for handling trailers */
qse_htob_t pen; /* buffer for raw octets during pending period */
} b;
/* points to the head of the combined header list */
void* chl;
} fed;
enum
{
QSE_HTTP_RETYPE_Q,
QSE_HTTP_RETYPE_S
} retype;
qse_htre_t re;
};
#ifdef __cplusplus
extern "C" {
#endif
QSE_DEFINE_COMMON_FUNCTIONS (http)
/**
* The qse_http_open() function creates a http processor.
*/
qse_http_t* qse_http_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
);
/**
* The qse_http_close() function destroys a http processor.
*/
void qse_http_close (
qse_http_t* http
);
qse_http_t* qse_http_init (
qse_http_t* http,
qse_mmgr_t* mmgr
);
void qse_http_fini (
qse_http_t* http
);
void qse_http_clear (
qse_http_t* http
);
int qse_http_getoption (
qse_http_t* http
);
void qse_http_setoption (
qse_http_t* http,
int opts
);
const qse_http_recbs_t* qse_http_getrecbs (
qse_http_t* http
);
void qse_http_setrecbs (
qse_http_t* http,
const qse_http_recbs_t* recbs
);
/**
* The qse_http_feed() function accepts http request octets and invokes a
* callback function if it has processed a proper http request.
*/
int qse_http_feed (
qse_http_t* http, /**< http */
const qse_htoc_t* req, /**< request octets */
qse_size_t len /**< number of octets */
);
#ifdef __cplusplus
}
#endif
#endif

View File

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

View File

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

179
qse/include/qse/net/htrd.h Normal file
View File

@ -0,0 +1,179 @@
/*
* $Id: htrd.h 223 2008-06-26 06:44:41Z baconevi $
*
Copyright 2006-2011 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 <htrd://www.gnu.org/licenses/>.
*/
#ifndef _QSE_NET_HTRD_H_
#define _QSE_NET_HTRD_H_
#include <qse/net/http.h>
#include <qse/net/htre.h>
typedef struct qse_htrd_t qse_htrd_t;
enum qse_htrd_errnum_t
{
QSE_HTRD_ENOERR,
QSE_HTRD_ENOMEM,
QSE_HTRD_EDISCON,
QSE_HTRD_EREADER,
QSE_HTRD_EBADRE,
QSE_HTRD_EBADHDR,
QSE_HTRD_EREQCBS
};
typedef enum qse_htrd_errnum_t qse_htrd_errnum_t;
enum qse_htrd_option_t
{
QSE_HTRD_LEADINGEMPTYLINES = (1 << 0)
};
typedef enum qse_htrd_option_t qse_htrd_option_t;
typedef struct qse_htrd_recbs_t qse_htrd_recbs_t;
struct qse_htrd_recbs_t
{
/* octet reader and writer */
qse_ssize_t (*reader) (qse_htrd_t* htrd, qse_htoc_t* buf, qse_size_t len);
int (*request) (qse_htrd_t* htrd, qse_htre_t* req);
int (*response) (qse_htrd_t* htrd, qse_htre_t* res);
int (*expect_continue) (qse_htrd_t* htrd, qse_htre_t* req);
};
struct qse_htrd_t
{
QSE_DEFINE_COMMON_FIELDS (htrd)
qse_htrd_errnum_t errnum;
int option;
qse_htrd_recbs_t recbs;
struct
{
struct
{
int crlf; /* crlf status */
qse_size_t plen; /* raw request length excluding crlf */
qse_size_t need; /* number of octets needed for contents */
struct
{
qse_size_t len;
qse_size_t count;
int phase;
} chunk;
} s; /* state */
/* buffers needed to for processing a request */
struct
{
qse_htob_t raw; /* buffer to hold raw octets */
qse_htob_t tra; /* buffer for handling trailers */
} b;
/* points to the head of the combined header list */
void* chl;
} fed;
enum
{
QSE_HTRD_RETYPE_Q,
QSE_HTRD_RETYPE_S
} retype;
qse_htre_t re;
qse_htoc_t rbuf[4096];
};
#ifdef __cplusplus
extern "C" {
#endif
QSE_DEFINE_COMMON_FUNCTIONS (htrd)
/**
* The qse_htrd_open() function creates a htrd processor.
*/
qse_htrd_t* qse_htrd_open (
qse_mmgr_t* mmgr, /**< memory manager */
qse_size_t xtnsize /**< extension size in bytes */
);
/**
* The qse_htrd_close() function destroys a htrd processor.
*/
void qse_htrd_close (
qse_htrd_t* htrd
);
qse_htrd_t* qse_htrd_init (
qse_htrd_t* htrd,
qse_mmgr_t* mmgr
);
void qse_htrd_fini (
qse_htrd_t* htrd
);
void qse_htrd_clear (
qse_htrd_t* htrd
);
int qse_htrd_getoption (
qse_htrd_t* htrd
);
void qse_htrd_setoption (
qse_htrd_t* htrd,
int opts
);
const qse_htrd_recbs_t* qse_htrd_getrecbs (
qse_htrd_t* htrd
);
void qse_htrd_setrecbs (
qse_htrd_t* htrd,
const qse_htrd_recbs_t* recbs
);
/**
* The qse_htrd_feed() function accepts htrd request octets and invokes a
* callback function if it has processed a proper htrd request.
*/
int qse_htrd_feed (
qse_htrd_t* htrd, /**< htrd */
const qse_htoc_t* req, /**< request octets */
qse_size_t len /**< number of octets */
);
int qse_htrd_read (
qse_htrd_t* htrd /**< htrd */
);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -18,30 +18,13 @@
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _QSE_HTTP_HTRE_H_
#define _QSE_HTTP_HTRE_H_
#ifndef _QSE_NET_HTRE_H_
#define _QSE_NET_HTRE_H_
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/net/http.h>
#include <qse/cmn/htb.h>
#include <qse/cmn/str.h>
/*typedef qse_byte_t qse_htoc_t;*/
typedef qse_mchar_t qse_htoc_t;
/* octet buffer */
typedef qse_mbs_t qse_htob_t;
/* octet string */
typedef qse_mxstr_t qse_htos_t;
typedef struct qse_htvr_t qse_htvr_t;
struct qse_htvr_t
{
short major;
short minor;
};
/* header and contents of request/response */
typedef struct qse_htre_t qse_htre_t;
struct qse_htre_t
@ -49,34 +32,11 @@ struct qse_htre_t
qse_mmgr_t* mmgr;
/* version */
qse_htvr_t version;
qse_http_version_t version;
union
{
struct
{
enum
{
QSE_HTTP_REQ_GET,
QSE_HTTP_REQ_HEAD,
QSE_HTTP_REQ_POST,
QSE_HTTP_REQ_PUT,
QSE_HTTP_REQ_DELETE,
QSE_HTTP_REQ_TRACE,
QSE_HTTP_REQ_OPTIONS,
QSE_HTTP_REQ_CONNECT
} method;
qse_htos_t path;
/* qse_htos_t args; */
} quest;
struct
{
int code;
qse_htos_t message;
} sponse;
} re;
int qmethod_or_sstatus;
qse_htob_t qpath_or_smesg;
qse_htob_t qparamstr;
/* special attributes derived from the header */
struct
@ -84,8 +44,6 @@ struct qse_htre_t
int chunked;
int content_length;
int connection_close;
qse_htos_t content_type;
qse_htos_t host;
int expect_continue;
} attr;
@ -99,8 +57,27 @@ struct qse_htre_t
int discard;
};
#define qse_htre_getversion(re) &((re)->version)
#define qse_htre_getversion(re) (&((re)->version))
#define qse_htre_getmajorversion(re) ((re)->version.major)
#define qse_htre_getminorversion(re) ((re)->version.minor)
#define qse_htre_setversion(re,v) QSE_BLOCK((re)->version = *(v);)
#define qse_htre_getqmethod(re) ((re)->qmethod_or_sstatus)
#define qse_htre_setqmethod(re,v) QSE_BLOCK((re)->qmethod_or_sstatus=(v);)
#define qse_htre_getsstatus(re) ((re)->qmethod_or_sstatus)
#define qse_htre_setsstatus(re,v) QSE_BLOCK((re)->qmethod_or_sstatus=(v);)
#define qse_htre_setqpath(re,v) qse_htre_setbuf((re),&(re)->qpath_or_smesg,(v))
#define qse_htre_setsmessage(re,v) qse_htre_setbuf((re),&(re)->qpath_or_smesg,(v))
#define qse_htre_getqpathptr(re) QSE_MBS_PTR(&(re)->qpath_or_smesg)
#define qse_htre_getqpathlen(re) QSE_MBS_LEN(&(re)->qpath_or_smesg)
#define qse_htre_getqparamsptr(re) QSE_MBS_PTR(&(re)->qparamstr)
#define qse_htre_getqparamslen(re) QSE_MBS_LEN(&(re)->qparamstr)
#define qse_htre_getsmessageptr(re) QSE_MBS_PTR(&(re)->qpath_or_smesg)
#define qse_htre_getsmessagelen(re) QSE_MBS_LEN(&(re)->qpath_or_smesg)
#define qse_htre_setdiscard(re,v) QSE_BLOCK((re)->discard = (v);)
#ifdef __cplusplus
@ -120,6 +97,23 @@ void qse_htre_clear (
qse_htre_t* re
);
int qse_htre_setbuf (
qse_htre_t* re,
qse_htob_t* buf,
const qse_htos_t* str
);
void qse_htre_getbuf (
qse_htre_t* re,
const qse_htob_t* buf,
qse_htos_t* str
);
int qse_htre_setqparamstr (
qse_htre_t* re,
const qse_htoc_t* str
);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,94 @@
/*
* $Id: http.h 223 2008-06-26 06:44:41Z baconevi $
*
Copyright 2006-2011 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_NET_HTTP_H_
#define _QSE_NET_HTTP_H_
#include <qse/types.h>
#include <qse/macros.h>
#include <qse/cmn/str.h>
#include <qse/cmn/htb.h>
/*typedef qse_byte_t qse_htoc_t;*/
typedef qse_mchar_t qse_htoc_t;
/* octet buffer */
typedef qse_mbs_t qse_htob_t;
/* octet string */
typedef qse_mxstr_t qse_htos_t;
typedef struct qse_http_version_t qse_http_version_t;
struct qse_http_version_t
{
short major;
short minor;
};
enum qse_http_method_t
{
QSE_HTTP_GET,
QSE_HTTP_HEAD,
QSE_HTTP_POST,
QSE_HTTP_PUT,
QSE_HTTP_DELETE,
QSE_HTTP_TRACE,
QSE_HTTP_OPTIONS,
QSE_HTTP_CONNECT
};
typedef enum qse_http_method_t qse_http_method_t;
typedef int (*qse_scanhttpparamstr_callback_t) (
void* ctx,
const qse_mcstr_t* key,
const qse_mcstr_t* val
);
#ifdef __cplusplus
extern "C" {
#endif
const qse_htoc_t* qse_gethttpmethodname (
qse_http_method_t type
);
int qse_gethttpmethodtype (
const qse_htoc_t* name,
qse_http_method_t* method
);
int qse_gethttpmethodtypefromstr (
const qse_htos_t* name,
qse_http_method_t* type
);
int qse_scanhttpparamstr (
const qse_htoc_t* paramstr,
qse_scanhttpparamstr_callback_t callback,
void* ctx
);
#ifdef __cplusplus
}
#endif
#endif