2011-07-23 07:53:31 +00:00
|
|
|
/*
|
|
|
|
* $Id$
|
|
|
|
*
|
2019-06-06 05:28:23 +00:00
|
|
|
Copyright (c) 2006-2019 Chung, Hyung-Hwan. All rights reserved.
|
2011-07-23 07:53:31 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions
|
|
|
|
are met:
|
|
|
|
1. Redistributions of source code must retain the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer.
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
notice, this list of conditions and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2011-07-23 07:53:31 +00:00
|
|
|
|
2014-11-19 14:42:24 +00:00
|
|
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
|
|
|
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2011-07-23 07:53:31 +00:00
|
|
|
*/
|
|
|
|
|
2013-02-18 13:45:50 +00:00
|
|
|
#ifndef _QSE_LIB_HTTP_HTTPD_H_
|
|
|
|
#define _QSE_LIB_HTTP_HTTPD_H_
|
2011-07-23 07:53:31 +00:00
|
|
|
|
|
|
|
/* private header file for httpd */
|
|
|
|
|
2013-02-18 13:45:50 +00:00
|
|
|
#include <qse/http/httpd.h>
|
2014-08-06 16:44:06 +00:00
|
|
|
|
2014-11-02 11:41:00 +00:00
|
|
|
#if defined(NDEBUG)
|
|
|
|
/* To include debugging messages while NDEBUG is set,
|
|
|
|
* you can define QSE_HTTPD_DEBUG externally in CFLAGS or something.
|
|
|
|
*/
|
|
|
|
#else
|
|
|
|
/* debugging mode */
|
|
|
|
# define QSE_HTTPD_DEBUG 1
|
|
|
|
#endif
|
2014-10-31 08:48:48 +00:00
|
|
|
|
2014-10-31 08:24:49 +00:00
|
|
|
#if defined(QSE_HTTPD_DEBUG)
|
2016-04-28 15:29:28 +00:00
|
|
|
# include <qse/si/sio.h>
|
2014-10-31 08:48:48 +00:00
|
|
|
# include <qse/cmn/path.h>
|
2019-09-10 08:53:59 +00:00
|
|
|
# define HTTPD_DBGOUT0(fmt) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__))
|
|
|
|
# define HTTPD_DBGOUT1(fmt,a1) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1))
|
|
|
|
# define HTTPD_DBGOUT2(fmt,a1,a2) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2))
|
|
|
|
# define HTTPD_DBGOUT3(fmt,a1,a2,a3) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3))
|
|
|
|
# define HTTPD_DBGOUT4(fmt,a1,a2,a3,a4) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3), (a4))
|
|
|
|
# define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5) qse_putmbsf("%06d %-20hs " fmt, (int)__LINE__, qse_mbsbasename(__FILE__), (a1), (a2), (a3), (a4), (a5))
|
2014-10-31 08:24:49 +00:00
|
|
|
#else
|
|
|
|
# define HTTPD_DBGOUT0(fmt)
|
|
|
|
# define HTTPD_DBGOUT1(fmt,a1)
|
|
|
|
# define HTTPD_DBGOUT2(fmt,a1,a2)
|
|
|
|
# define HTTPD_DBGOUT3(fmt,a1,a2,a3)
|
|
|
|
# define HTTPD_DBGOUT4(fmt,a1,a2,a3,a4)
|
|
|
|
# define HTTPD_DBGOUT5(fmt,a1,a2,a3,a4,a5)
|
|
|
|
#endif
|
|
|
|
|
2014-10-31 08:48:48 +00:00
|
|
|
#define QSE_HTTPD_DEFAULT_PORT 80
|
|
|
|
#define QSE_HTTPD_DEFAULT_SECURE_PORT 443
|
|
|
|
|
|
|
|
|
2011-07-23 07:53:31 +00:00
|
|
|
struct qse_httpd_t
|
|
|
|
{
|
2019-06-25 02:36:32 +00:00
|
|
|
QSE_HTTPD_HDR;
|
2011-07-23 07:53:31 +00:00
|
|
|
qse_httpd_errnum_t errnum;
|
2012-09-07 15:13:55 +00:00
|
|
|
qse_httpd_ecb_t* ecb; /* event callbacks */
|
2014-08-04 16:34:22 +00:00
|
|
|
qse_tmr_t* tmr;
|
2013-02-20 08:47:22 +00:00
|
|
|
|
2013-01-30 14:08:38 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
int trait;
|
2013-02-20 08:47:22 +00:00
|
|
|
qse_ntime_t tmout; /* poll timeout */
|
|
|
|
qse_ntime_t idle_limit;
|
2014-09-03 17:11:01 +00:00
|
|
|
qse_cstr_t mod[2]; /* module prefix and postfix */
|
|
|
|
qse_httpd_scb_t scb; /* system callbacks */
|
|
|
|
qse_httpd_rcb_t rcb; /* request callbacks */
|
2013-01-30 14:08:38 +00:00
|
|
|
} opt;
|
2013-02-20 08:47:22 +00:00
|
|
|
|
2013-02-18 13:45:50 +00:00
|
|
|
int stopreq: 1;
|
2013-02-20 08:47:22 +00:00
|
|
|
int impedereq: 1;
|
2014-07-17 16:11:02 +00:00
|
|
|
int dnsactive: 1;
|
2014-08-06 16:44:06 +00:00
|
|
|
int ursactive: 1;
|
2012-02-03 14:30:45 +00:00
|
|
|
|
2012-09-13 12:31:01 +00:00
|
|
|
qse_mchar_t sname[128]; /* server name for the server header */
|
|
|
|
qse_mchar_t gtbuf[10][64]; /* GMT time buffers */
|
|
|
|
|
2014-09-03 16:57:33 +00:00
|
|
|
qse_httpd_mod_t* modlist;
|
|
|
|
|
2011-07-23 07:53:31 +00:00
|
|
|
struct
|
|
|
|
{
|
2012-03-18 14:24:54 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
qse_httpd_client_t* head;
|
|
|
|
qse_httpd_client_t* tail;
|
2014-10-30 05:53:35 +00:00
|
|
|
qse_size_t count;
|
2012-03-18 14:24:54 +00:00
|
|
|
} list;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
|
|
|
qse_httpd_client_t* head;
|
|
|
|
qse_httpd_client_t* tail;
|
|
|
|
} tasked;
|
|
|
|
|
|
|
|
qse_httpd_client_t* bad;
|
2011-07-23 07:53:31 +00:00
|
|
|
} client;
|
|
|
|
|
|
|
|
struct
|
|
|
|
{
|
2012-09-25 02:47:25 +00:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
qse_httpd_server_t* head;
|
|
|
|
qse_httpd_server_t* tail;
|
|
|
|
} list;
|
2012-03-18 14:24:54 +00:00
|
|
|
qse_size_t navail;
|
|
|
|
qse_size_t nactive;
|
2012-02-28 09:41:01 +00:00
|
|
|
} server;
|
2012-03-18 14:24:54 +00:00
|
|
|
|
|
|
|
void* mux;
|
2014-07-16 15:31:04 +00:00
|
|
|
qse_httpd_dns_t dns;
|
2014-08-06 16:44:06 +00:00
|
|
|
qse_httpd_urs_t urs;
|
2011-07-23 07:53:31 +00:00
|
|
|
};
|
|
|
|
|
2013-08-24 15:16:20 +00:00
|
|
|
/* qse_httpd_real_task_t is a private type to hide some private fields
|
|
|
|
* from being exposed by qse_httpd_task_t.
|
|
|
|
*/
|
|
|
|
typedef struct qse_httpd_real_task_t qse_httpd_real_task_t;
|
|
|
|
|
|
|
|
struct qse_httpd_real_task_t
|
|
|
|
{
|
|
|
|
qse_httpd_task_t core;
|
|
|
|
qse_httpd_real_task_t* prev;
|
|
|
|
qse_httpd_real_task_t* next;
|
|
|
|
};
|
2012-05-31 10:18:50 +00:00
|
|
|
|
2014-10-15 15:33:37 +00:00
|
|
|
#define MAX_SEND_SIZE (4096 * 4)
|
|
|
|
#define MAX_RECV_SIZE (4096 * 2)
|
2012-09-15 14:27:14 +00:00
|
|
|
|
2014-09-06 04:08:31 +00:00
|
|
|
#define MAX_NWAD_TEXT_SIZE 96
|
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
#if defined(__cplusplus)
|
2011-07-23 07:53:31 +00:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2012-05-31 10:18:50 +00:00
|
|
|
extern qse_http_version_t qse_http_v11;
|
|
|
|
|
2011-09-01 09:43:46 +00:00
|
|
|
int qse_httpd_init (
|
2011-07-23 07:53:31 +00:00
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_mmgr_t* mmgr
|
|
|
|
);
|
|
|
|
|
|
|
|
void qse_httpd_fini (
|
|
|
|
qse_httpd_t* httpd
|
|
|
|
);
|
|
|
|
|
2014-08-08 18:53:04 +00:00
|
|
|
qse_httpd_task_t* qse_httpd_entask_status (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_httpd_client_t* client,
|
|
|
|
qse_httpd_task_t* pred,
|
|
|
|
int code,
|
|
|
|
void* extra,
|
|
|
|
qse_http_method_t method,
|
|
|
|
const qse_http_version_t* version,
|
|
|
|
int keepalive
|
|
|
|
);
|
|
|
|
|
2012-10-16 08:54:07 +00:00
|
|
|
qse_httpd_task_t* qse_httpd_entask_nomod (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_httpd_client_t* client,
|
2013-08-24 15:16:20 +00:00
|
|
|
qse_httpd_task_t* pred,
|
|
|
|
qse_http_method_t method,
|
|
|
|
const qse_http_version_t* version,
|
2012-10-16 08:54:07 +00:00
|
|
|
int keepalive
|
|
|
|
);
|
|
|
|
|
2014-07-22 17:58:11 +00:00
|
|
|
int qse_httpd_activatetasktrigger (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_httpd_client_t* client,
|
|
|
|
qse_httpd_task_t* task
|
|
|
|
);
|
|
|
|
|
|
|
|
int qse_httpd_inactivatetasktrigger (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_httpd_client_t* client,
|
|
|
|
qse_httpd_task_t* task
|
|
|
|
);
|
|
|
|
|
2014-11-01 15:27:56 +00:00
|
|
|
int qse_httpd_insert_timer_event (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
const qse_tmr_event_t* event,
|
|
|
|
qse_tmr_index_t* index
|
|
|
|
);
|
|
|
|
|
|
|
|
void qse_httpd_remove_timer_event (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_tmr_index_t index
|
|
|
|
);
|
|
|
|
|
2014-11-11 15:41:11 +00:00
|
|
|
qse_httpd_peer_t* qse_httpd_cacheproxypeer (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_httpd_client_t* client,
|
|
|
|
qse_httpd_peer_t* tmpl
|
|
|
|
);
|
|
|
|
|
|
|
|
qse_httpd_peer_t* qse_httpd_decacheproxypeer (
|
|
|
|
qse_httpd_t* httpd,
|
|
|
|
qse_httpd_client_t* client,
|
|
|
|
const qse_nwad_t* nwad,
|
|
|
|
const qse_nwad_t* local,
|
|
|
|
int secure
|
|
|
|
);
|
|
|
|
|
2014-11-13 10:15:53 +00:00
|
|
|
#if defined(__cplusplus)
|
2011-07-23 07:53:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|