added more functions to qse_http_t

This commit is contained in:
hyung-hwan 2010-12-01 05:35:28 +00:00
parent 4491055c84
commit ff21f8cd4a
3 changed files with 55 additions and 15 deletions

View File

@ -1,5 +1,5 @@
/* /*
* $Id: mem.h 348 2010-08-26 06:26:28Z hyunghwan.chung $ * $Id: mem.h 375 2010-11-30 11:35:28Z hyunghwan.chung $
* *
Copyright 2006-2009 Chung, Hyung-Hwan. Copyright 2006-2009 Chung, Hyung-Hwan.
This file is part of QSE. This file is part of QSE.
@ -38,18 +38,27 @@
*/ */
#define QSE_MMGR_SETDFL(m) ((qse_mmgr)=(m)) #define QSE_MMGR_SETDFL(m) ((qse_mmgr)=(m))
/* allocate a memory block */ /**
* The QSE_MMGR_ALLOC() macro allocates a memory block of the @a size bytes
* using the @a mmgr memory manager.
*/
#define QSE_MMGR_ALLOC(mmgr,size) \ #define QSE_MMGR_ALLOC(mmgr,size) \
((mmgr)->alloc((mmgr)->udd,size)) ((mmgr)->alloc((mmgr)->udd,size))
/* reallocate a memory block */ /**
* The QSE_MMGR_REALLOC() macro resizes a memory block pointed to by @a ptr
* to the @a size bytes using the @a mmgr memory manager.
*/
#define QSE_MMGR_REALLOC(mmgr,ptr,size) \ #define QSE_MMGR_REALLOC(mmgr,ptr,size) \
((mmgr)->realloc((mmgr)->udd,ptr,size)) ((mmgr)->realloc((mmgr)->udd,ptr,size))
/* free a memory block */ /**
* The QSE_MMGR_FREE() macro deallocates the memory block pointed to by @a ptr.
*/
#define QSE_MMGR_FREE(mmgr,ptr) \ #define QSE_MMGR_FREE(mmgr,ptr) \
((mmgr)->free((mmgr)->udd,ptr)) ((mmgr)->free((mmgr)->udd,ptr))
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
@ -86,7 +95,7 @@ void* qse_memmove (
qse_size_t n /**< number of bytes to copy */ qse_size_t n /**< number of bytes to copy */
); );
/* /**
* The qse_memset() function fills leading @a n bytes of the destination * The qse_memset() function fills leading @a n bytes of the destination
* memory block @a dst with the byte @a val. * memory block @a dst with the byte @a val.
* *
@ -130,7 +139,7 @@ void* qse_membyte (
qse_size_t n /**< number of bytes to scan */ qse_size_t n /**< number of bytes to scan */
); );
/* /**
* The qse_memrbyte() function scans the memory block @a s from the nth byte * The qse_memrbyte() function scans the memory block @a s from the nth byte
* backward to the first byte in search of the byte @a val. If it finds a match, * backward to the first byte in search of the byte @a val. If it finds a match,
* it aborts scanning the memory block and returns the pointer to the matching * it aborts scanning the memory block and returns the pointer to the matching
@ -162,7 +171,7 @@ void* qse_memmem (
qse_size_t nl /**< number of bytes in the block */ qse_size_t nl /**< number of bytes in the block */
); );
/* /**
* The qse_memrmem() functions scans the first @a hl bytes of the memory * The qse_memrmem() functions scans the first @a hl bytes of the memory
* block @a hs backward in search of the byte block @a nd of the length * block @a hs backward in search of the byte block @a nd of the length
* @a nl bytes. * @a nl bytes.

View File

@ -31,6 +31,12 @@ enum qse_http_errnum_t
typedef enum qse_http_errnum_t qse_http_errnum_t; 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_req_t qse_http_req_t; typedef struct qse_http_req_t qse_http_req_t;
@ -88,11 +94,11 @@ struct qse_http_reqcbs_t
int (*request) (qse_http_t* http, qse_http_req_t* req); int (*request) (qse_http_t* http, qse_http_req_t* req);
}; };
struct qse_http_t struct qse_http_t
{ {
QSE_DEFINE_COMMON_FIELDS (http) QSE_DEFINE_COMMON_FIELDS (http)
qse_http_errnum_t errnum; qse_http_errnum_t errnum;
int option;
const qse_http_reqcbs_t* reqcbs; const qse_http_reqcbs_t* reqcbs;
@ -161,6 +167,15 @@ void qse_http_clear (
qse_http_t* http 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_reqcbs_t* qse_http_getreqcbs ( const qse_http_reqcbs_t* qse_http_getreqcbs (
qse_http_t* http qse_http_t* http
); );

View File

@ -326,7 +326,7 @@ static qse_byte_t* parse_reqline (qse_http_t* http, qse_byte_t* line)
/* ? must be explicit to be a argument instroducer. /* ? must be explicit to be a argument instroducer.
* %3f is just a literal. */ * %3f is just a literal. */
http->req.path.len = tmp - http->req.path.ptr; http->req.path.len = tmp - http->req.path.ptr;
/**tmp++ = '\0';*/ *tmp++ = '\0';
http->req.args.ptr = tmp; http->req.args.ptr = tmp;
p++; p++;
} }
@ -342,7 +342,8 @@ static qse_byte_t* parse_reqline (qse_http_t* http, qse_byte_t* line)
http->req.args.len = tmp - http->req.args.ptr; http->req.args.len = tmp - http->req.args.ptr;
else else
http->req.path.len = tmp - http->req.path.ptr; http->req.path.len = tmp - http->req.path.ptr;
/* *tmp = '\0'; */ /* null-terminate the url part */ /* null-terminate the url part though we record the length */
*tmp = '\0';
/* skip spaces after the url part */ /* skip spaces after the url part */
do { p++; } while (is_space_octet(*p)); do { p++; } while (is_space_octet(*p));
@ -393,6 +394,16 @@ void qse_http_clear (qse_http_t* http)
clear_request (http); clear_request (http);
} }
int qse_http_getoption (qse_http_t* http)
{
return http->option;
}
void qse_http_setoption (qse_http_t* http, int opts)
{
http->option = opts;
}
const qse_http_reqcbs_t* qse_http_getreqcbs (qse_http_t* http) const qse_http_reqcbs_t* qse_http_getreqcbs (qse_http_t* http)
{ {
return http->reqcbs; return http->reqcbs;
@ -797,7 +808,11 @@ static QSE_INLINE int parse_request (
p = http->reqx.b.raw.data; p = http->reqx.b.raw.data;
while (is_whspace_octet(*p)) p++; if (http->option & QSE_HTTP_LEADINGEMPTYLINES)
while (is_whspace_octet(*p)) p++;
else
while (is_space_octet(*p)) p++;
QSE_ASSERT (*p != '\0'); QSE_ASSERT (*p != '\0');
/* parse the request line */ /* parse the request line */
@ -1001,7 +1016,8 @@ int qse_http_feed (qse_http_t* http, const qse_byte_t* req, qse_size_t len)
{ {
register qse_byte_t b = *ptr++; register qse_byte_t b = *ptr++;
if (http->reqx.s.plen <= 0 && is_whspace_octet(b)) if (http->option & QSE_HTTP_LEADINGEMPTYLINES &&
http->reqx.s.plen <= 0 && is_whspace_octet(b))
{ {
/* let's drop leading whitespaces across multiple /* let's drop leading whitespaces across multiple
* lines */ * lines */
@ -1160,9 +1176,8 @@ int qse_http_feed (qse_http_t* http, const qse_byte_t* req, qse_size_t len)
} }
} }
QSE_ASSERTX (http->reqcbs->request != QSE_NULL,
QSE_ASSERTX (http->reqcbs != QSE_NULL, "set request callbacks before feeding");
"Set the request callback before feeding data");
http->errnum = QSE_HTTP_ENOERR; http->errnum = QSE_HTTP_ENOERR;
if (http->reqcbs->request (http, &http->req) <= -1) if (http->reqcbs->request (http, &http->req) <= -1)
{ {
@ -1216,3 +1231,4 @@ feedme_more:
return 0; return 0;
} }