added more code for httpd
This commit is contained in:
parent
ec02be14e5
commit
fb574aa147
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: fio.h 452 2011-05-04 15:11:23Z hyunghwan.chung $
|
* $Id: fio.h 504 2011-07-11 16:31:33Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||||
This file is part of QSE.
|
This file is part of QSE.
|
||||||
@ -55,7 +55,7 @@ enum qse_fio_open_flag_t
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* seek origin */
|
/* seek origin */
|
||||||
enum qse_fio_seek_origin_t
|
enum qse_fio_ori_t
|
||||||
{
|
{
|
||||||
QSE_FIO_BEGIN = 0,
|
QSE_FIO_BEGIN = 0,
|
||||||
QSE_FIO_CURRENT = 1,
|
QSE_FIO_CURRENT = 1,
|
||||||
@ -92,19 +92,10 @@ enum qse_fio_mode_t
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* file offset */
|
/* file offset */
|
||||||
#if defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_OFF64_T==8)
|
typedef qse_foff_t qse_fio_off_t;
|
||||||
typedef qse_int64_t qse_fio_off_t;
|
|
||||||
#elif defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_OFF_T==8)
|
|
||||||
typedef qse_int64_t qse_fio_off_t;
|
|
||||||
#elif defined(QSE_HAVE_INT32_T) && (QSE_SIZEOF_OFF_T==4)
|
|
||||||
typedef qse_int32_t qse_fio_off_t;
|
|
||||||
#elif defined(QSE_HAVE_INT16_T) && (QSE_SIZEOF_OFF_T==2)
|
|
||||||
typedef qse_int16_t qse_fio_off_t;
|
|
||||||
#else
|
|
||||||
# error Unsupported platform
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum qse_fio_seek_origin_t qse_fio_ori_t;
|
/* file origin for seek */
|
||||||
|
typedef enum qse_fio_ori_t qse_fio_ori_t;
|
||||||
|
|
||||||
typedef struct qse_fio_t qse_fio_t;
|
typedef struct qse_fio_t qse_fio_t;
|
||||||
typedef struct qse_fio_lck_t qse_fio_lck_t;
|
typedef struct qse_fio_lck_t qse_fio_lck_t;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: str.h 500 2011-06-29 15:12:36Z hyunghwan.chung $
|
* $Id: str.h 504 2011-07-11 16:31:33Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||||
This file is part of QSE.
|
This file is part of QSE.
|
||||||
@ -2129,6 +2129,17 @@ int qse_wcstombs_strict (
|
|||||||
qse_size_t mbslen
|
qse_size_t mbslen
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
qse_wchar_t* qse_mbstowcsdup (
|
||||||
|
const qse_mchar_t* mbs,
|
||||||
|
qse_mmgr_t* mmgr
|
||||||
|
);
|
||||||
|
|
||||||
|
qse_mchar_t* qse_wcstombsdup (
|
||||||
|
const qse_wchar_t* wcs,
|
||||||
|
qse_mmgr_t* mmgr
|
||||||
|
);
|
||||||
|
|
||||||
QSE_DEFINE_COMMON_FUNCTIONS (mbs)
|
QSE_DEFINE_COMMON_FUNCTIONS (mbs)
|
||||||
|
|
||||||
qse_mbs_t* qse_mbs_open (
|
qse_mbs_t* qse_mbs_open (
|
||||||
|
@ -66,7 +66,7 @@ struct qse_htrd_t
|
|||||||
qse_htrd_errnum_t errnum;
|
qse_htrd_errnum_t errnum;
|
||||||
int option;
|
int option;
|
||||||
|
|
||||||
qse_htrd_recbs_t recbs;
|
const qse_htrd_recbs_t* recbs;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
|
@ -25,11 +25,23 @@
|
|||||||
#include <qse/macros.h>
|
#include <qse/macros.h>
|
||||||
|
|
||||||
typedef struct qse_httpd_t qse_httpd_t;
|
typedef struct qse_httpd_t qse_httpd_t;
|
||||||
struct qse_httpd_t
|
|
||||||
{
|
|
||||||
QSE_DEFINE_COMMON_FIELDS (httpd)
|
|
||||||
|
|
||||||
int stopreq;
|
enum qse_httpd_errnum_t
|
||||||
|
{
|
||||||
|
QSE_HTTPD_ENOERR,
|
||||||
|
QSE_HTTPD_ENOMEM,
|
||||||
|
QSE_HTTPD_EINVAL,
|
||||||
|
QSE_HTTPD_ESOCKET,
|
||||||
|
QSE_HTTPD_EINTERN,
|
||||||
|
QSE_HTTPD_ECOMCBS
|
||||||
|
};
|
||||||
|
typedef enum qse_httpd_errnum_t qse_httpd_errnum_t;
|
||||||
|
|
||||||
|
typedef struct qse_httpd_comcbs_t qse_httpd_comcbs_t;
|
||||||
|
struct qse_httpd_comcbs_t
|
||||||
|
{
|
||||||
|
int (*open_listeners) (qse_httpd_t* httpd);
|
||||||
|
int (*close_listeners) (qse_httpd_t* httpd);
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
@ -53,15 +65,28 @@ void qse_httpd_close (
|
|||||||
qse_httpd_t* httpd
|
qse_httpd_t* httpd
|
||||||
);
|
);
|
||||||
|
|
||||||
qse_httpd_t* qse_httpd_init (
|
void qse_httpd_setcomcbs (
|
||||||
qse_httpd_t* httpd,
|
qse_httpd_t* httpd,
|
||||||
qse_mmgr_t* mmgr
|
qse_httpd_comcbs_t* comcbs
|
||||||
);
|
);
|
||||||
|
|
||||||
void qse_httpd_fini (
|
int qse_httpd_loop (
|
||||||
qse_httpd_t* httpd
|
qse_httpd_t* httpd
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The qse_httpd_stop() function requests to stop qse_httpd_loop()
|
||||||
|
*/
|
||||||
|
void qse_httpd_stop (
|
||||||
|
qse_httpd_t* httpd
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
int qse_httpd_addlisteners (
|
||||||
|
qse_httpd_t* httpd,
|
||||||
|
const qse_char_t* uri
|
||||||
|
);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: types.h 487 2011-06-04 16:22:20Z hyunghwan.chung $
|
* $Id: types.h 504 2011-07-11 16:31:33Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||||
This file is part of QSE.
|
This file is part of QSE.
|
||||||
@ -336,6 +336,7 @@ typedef qse_int_t qse_intptr_t;
|
|||||||
typedef double qse_real_t;
|
typedef double qse_real_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The qse_mchar_t type defines a multi-byte character type.
|
* The qse_mchar_t type defines a multi-byte character type.
|
||||||
*/
|
*/
|
||||||
@ -561,4 +562,17 @@ struct qse_mmgr_t
|
|||||||
};
|
};
|
||||||
typedef struct qse_mmgr_t qse_mmgr_t;
|
typedef struct qse_mmgr_t qse_mmgr_t;
|
||||||
|
|
||||||
|
/* file offset */
|
||||||
|
#if defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_OFF64_T==8)
|
||||||
|
typedef qse_int64_t qse_foff_t;
|
||||||
|
#elif defined(QSE_HAVE_INT64_T) && (QSE_SIZEOF_OFF_T==8)
|
||||||
|
typedef qse_int64_t qse_foff_t;
|
||||||
|
#elif defined(QSE_HAVE_INT32_T) && (QSE_SIZEOF_OFF_T==4)
|
||||||
|
typedef qse_int32_t qse_foff_t;
|
||||||
|
#elif defined(QSE_HAVE_INT16_T) && (QSE_SIZEOF_OFF_T==2)
|
||||||
|
typedef qse_int16_t qse_foff_t;
|
||||||
|
#else
|
||||||
|
# error Unsupported platform
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* $Id: str_cnv.c 441 2011-04-22 14:28:43Z hyunghwan.chung $
|
* $Id: str_cnv.c 504 2011-07-11 16:31:33Z hyunghwan.chung $
|
||||||
*
|
*
|
||||||
Copyright 2006-2011 Chung, Hyung-Hwan.
|
Copyright 2006-2011 Chung, Hyung-Hwan.
|
||||||
This file is part of QSE.
|
This file is part of QSE.
|
||||||
@ -20,6 +20,7 @@
|
|||||||
|
|
||||||
#include <qse/cmn/str.h>
|
#include <qse/cmn/str.h>
|
||||||
#include <qse/cmn/chr.h>
|
#include <qse/cmn/chr.h>
|
||||||
|
#include "mem.h"
|
||||||
|
|
||||||
int qse_strtoi (const qse_char_t* str)
|
int qse_strtoi (const qse_char_t* str)
|
||||||
{
|
{
|
||||||
@ -397,6 +398,41 @@ int qse_wcstombs_strict (
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qse_wchar_t* qse_mbstowcsdup (
|
||||||
|
const qse_mchar_t* mbs, qse_mmgr_t* mmgr)
|
||||||
|
{
|
||||||
|
qse_size_t n, req;
|
||||||
|
qse_wchar_t* wcs;
|
||||||
|
|
||||||
|
n = qse_mbstowcslen (mbs, &req);
|
||||||
|
if (mbs[n] != QSE_WT('\0')) return QSE_NULL;
|
||||||
|
|
||||||
|
req++;
|
||||||
|
|
||||||
|
wcs = QSE_MMGR_ALLOC (mmgr, req * QSE_SIZEOF(*wcs));
|
||||||
|
if (wcs == QSE_NULL) return QSE_NULL;
|
||||||
|
|
||||||
|
qse_mbstowcs (mbs, wcs, &req);
|
||||||
|
return wcs;
|
||||||
|
}
|
||||||
|
|
||||||
|
qse_mchar_t* qse_wcstombsdup (
|
||||||
|
const qse_wchar_t* wcs, qse_mmgr_t* mmgr)
|
||||||
|
{
|
||||||
|
qse_size_t n, req;
|
||||||
|
qse_mchar_t* mbs;
|
||||||
|
|
||||||
|
n = qse_wcstombslen (wcs, &req);
|
||||||
|
if (wcs[n] != QSE_WT('\0')) return QSE_NULL;
|
||||||
|
|
||||||
|
req++;
|
||||||
|
|
||||||
|
mbs = QSE_MMGR_ALLOC (mmgr, req * QSE_SIZEOF(*mbs));
|
||||||
|
if (mbs == QSE_NULL) return QSE_NULL;
|
||||||
|
|
||||||
|
qse_wcstombs (wcs, mbs, &req);
|
||||||
|
return mbs;
|
||||||
|
}
|
||||||
|
|
||||||
/* case conversion */
|
/* case conversion */
|
||||||
|
|
||||||
|
@ -422,12 +422,12 @@ void qse_htrd_setoption (qse_htrd_t* http, int opts)
|
|||||||
|
|
||||||
const qse_htrd_recbs_t* qse_htrd_getrecbs (qse_htrd_t* http)
|
const qse_htrd_recbs_t* qse_htrd_getrecbs (qse_htrd_t* http)
|
||||||
{
|
{
|
||||||
return &http->recbs;
|
return http->recbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
void qse_htrd_setrecbs (qse_htrd_t* http, const qse_htrd_recbs_t* recbs)
|
void qse_htrd_setrecbs (qse_htrd_t* http, const qse_htrd_recbs_t* recbs)
|
||||||
{
|
{
|
||||||
http->recbs = *recbs;
|
http->recbs = recbs;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define octet_tolower(c) (((c) >= 'A' && (c) <= 'Z') ? ((c) | 0x20) : (c))
|
#define octet_tolower(c) (((c) >= 'A' && (c) <= 'Z') ? ((c) | 0x20) : (c))
|
||||||
@ -1091,7 +1091,7 @@ int qse_htrd_feed (qse_htrd_t* http, const qse_htoc_t* req, qse_size_t len)
|
|||||||
|
|
||||||
if (http->retype == QSE_HTRD_RETYPE_Q &&
|
if (http->retype == QSE_HTRD_RETYPE_Q &&
|
||||||
http->re.attr.expect_continue &&
|
http->re.attr.expect_continue &&
|
||||||
http->recbs.expect_continue && ptr >= end)
|
http->recbs->expect_continue && ptr >= end)
|
||||||
{
|
{
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
@ -1102,7 +1102,7 @@ int qse_htrd_feed (qse_htrd_t* http, const qse_htoc_t* req, qse_size_t len)
|
|||||||
* not fed here?
|
* not fed here?
|
||||||
*/
|
*/
|
||||||
|
|
||||||
n = http->recbs.expect_continue (http, &http->re);
|
n = http->recbs->expect_continue (http, &http->re);
|
||||||
|
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
{
|
{
|
||||||
@ -1243,20 +1243,20 @@ int qse_htrd_feed (qse_htrd_t* http, const qse_htoc_t* req, qse_size_t len)
|
|||||||
if (http->retype == QSE_HTRD_RETYPE_S)
|
if (http->retype == QSE_HTRD_RETYPE_S)
|
||||||
{
|
{
|
||||||
QSE_ASSERTX (
|
QSE_ASSERTX (
|
||||||
http->recbs.response != QSE_NULL,
|
http->recbs->response != QSE_NULL,
|
||||||
"set response callback before feeding"
|
"set response callback before feeding"
|
||||||
);
|
);
|
||||||
|
|
||||||
n = http->recbs.response (http, &http->re);
|
n = http->recbs->response (http, &http->re);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QSE_ASSERTX (
|
QSE_ASSERTX (
|
||||||
http->recbs.request != QSE_NULL,
|
http->recbs->request != QSE_NULL,
|
||||||
"set request callback before feeding"
|
"set request callback before feeding"
|
||||||
);
|
);
|
||||||
|
|
||||||
n = http->recbs.request (http, &http->re);
|
n = http->recbs->request (http, &http->re);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
@ -1309,12 +1309,12 @@ int qse_htrd_read (qse_htrd_t* http)
|
|||||||
qse_ssize_t n;
|
qse_ssize_t n;
|
||||||
|
|
||||||
QSE_ASSERTX (
|
QSE_ASSERTX (
|
||||||
http->recbs.reader != QSE_NULL,
|
http->recbs->reader != QSE_NULL,
|
||||||
"You must set the octet reader to be able to call qse_htrd_read()"
|
"You must set the octet reader to be able to call qse_htrd_read()"
|
||||||
);
|
);
|
||||||
|
|
||||||
http->errnum = QSE_HTRD_ENOERR;
|
http->errnum = QSE_HTRD_ENOERR;
|
||||||
n = http->recbs.reader (http, http->rbuf, QSE_SIZEOF(http->rbuf));
|
n = http->recbs->reader (http, http->rbuf, QSE_SIZEOF(http->rbuf));
|
||||||
if (n <= -1)
|
if (n <= -1)
|
||||||
{
|
{
|
||||||
if (http->errnum == QSE_HTRD_ENOERR) http->errnum = QSE_HTRD_ERECBS;
|
if (http->errnum == QSE_HTRD_ENOERR) http->errnum = QSE_HTRD_ERECBS;
|
||||||
@ -1376,12 +1376,12 @@ int qse_htrd_scanqparam (qse_htrd_t* http, const qse_mcstr_t* cstr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
QSE_ASSERTX (
|
QSE_ASSERTX (
|
||||||
http->recbs.qparamstr != QSE_NULL,
|
http->recbs->qparamstr != QSE_NULL,
|
||||||
"set request parameter string callback before scanning"
|
"set request parameter string callback before scanning"
|
||||||
);
|
);
|
||||||
|
|
||||||
http->errnum = QSE_HTRD_ENOERR;
|
http->errnum = QSE_HTRD_ENOERR;
|
||||||
if (http->recbs.qparamstr (http, &key, &val) <= -1)
|
if (http->recbs->qparamstr (http, &key, &val) <= -1)
|
||||||
{
|
{
|
||||||
if (http->errnum == QSE_HTRD_ENOERR)
|
if (http->errnum == QSE_HTRD_ENOERR)
|
||||||
http->errnum = QSE_HTRD_ERECBS;
|
http->errnum = QSE_HTRD_ERECBS;
|
||||||
|
@ -146,3 +146,4 @@ int qse_gethttpdatetimefromstr (const qse_mcstr_t* str, qse_ntime_t* t)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
1476
qse/lib/net/httpd.c
1476
qse/lib/net/httpd.c
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user