2021-07-22 07:43:01 +00:00
|
|
|
/*
|
|
|
|
Copyright (c) 2016-2020 Chung, Hyung-Hwan. All rights reserved.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _HIO_HTTP_H_
|
|
|
|
#define _HIO_HTTP_H_
|
|
|
|
|
|
|
|
#include <hio-ecs.h>
|
|
|
|
#include <hio-sck.h>
|
|
|
|
#include <hio-htre.h>
|
|
|
|
#include <hio-thr.h>
|
2022-09-12 14:43:29 +00:00
|
|
|
#include <hio-fcgi.h>
|
2021-07-22 07:43:01 +00:00
|
|
|
|
|
|
|
/** \file
|
|
|
|
* This file provides basic data types and functions for the http protocol.
|
|
|
|
*/
|
|
|
|
|
|
|
|
enum hio_http_range_type_t
|
|
|
|
{
|
|
|
|
HIO_HTTP_RANGE_PROPER,
|
|
|
|
HIO_HTTP_RANGE_PREFIX,
|
|
|
|
HIO_HTTP_RANGE_SUFFIX
|
|
|
|
};
|
|
|
|
typedef enum hio_http_range_type_t hio_http_range_type_t;
|
|
|
|
/**
|
|
|
|
* The hio_http_range_t type defines a structure that can represent
|
2023-01-11 14:59:41 +00:00
|
|
|
* a value for the \b Range: http header.
|
2021-07-22 07:43:01 +00:00
|
|
|
*
|
2023-01-11 14:59:41 +00:00
|
|
|
* If type is #HIO_HTTP_RANGE_PREFIX, 'to' is meaningless and 'from' indicates
|
|
|
|
* the number of bytes from the start.
|
2021-07-22 07:43:01 +00:00
|
|
|
* - 500- => from the 501st bytes all the way to the back.
|
2023-01-11 14:59:41 +00:00
|
|
|
*
|
|
|
|
* If type is #HIO_HTTP_RANGE_SUFFIX, 'from' is meaningless and 'to' indicates
|
|
|
|
* the number of bytes from the back.
|
2021-07-22 07:43:01 +00:00
|
|
|
* - -500 => last 500 bytes
|
|
|
|
*
|
|
|
|
* If type is #HIO_HTTP_RANGE_PROPER, 'from' and 'to' represents a proper range
|
2023-01-11 14:59:41 +00:00
|
|
|
* where the value of 0 indicates the first byte. This doesn't require any
|
2021-07-22 07:43:01 +00:00
|
|
|
* adjustment.
|
|
|
|
* - 0-999 => first 1000 bytes
|
|
|
|
* - 99- => from the 100th bytes to the end.
|
|
|
|
*/
|
|
|
|
struct hio_http_range_t
|
|
|
|
{
|
|
|
|
hio_http_range_type_t type; /**< type indicator */
|
|
|
|
hio_foff_t from; /**< starting offset */
|
|
|
|
hio_foff_t to; /**< ending offset */
|
|
|
|
};
|
|
|
|
typedef struct hio_http_range_t hio_http_range_t;
|
|
|
|
|
2023-11-17 00:42:59 +00:00
|
|
|
enum hio_perenc_http_option_t
|
2021-07-22 07:43:01 +00:00
|
|
|
{
|
|
|
|
HIO_PERENC_HTTP_KEEP_SLASH = (1 << 0)
|
|
|
|
};
|
2023-11-17 00:42:59 +00:00
|
|
|
typedef enum hio_perenc_http_option_t hio_perenc_bcstr_option_t;
|
2021-07-22 07:43:01 +00:00
|
|
|
|
2023-11-17 00:42:59 +00:00
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
enum hio_svc_htts_option_t
|
|
|
|
{
|
|
|
|
HIO_SVC_HTTS_TASK_MAX,
|
|
|
|
HIO_SVC_HTTS_TASK_CGI_MAX,
|
|
|
|
HIO_SVC_HTTS_FCGI_TMOUT,
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef enum hio_svc_htts_option_t hio_svc_htts_option_t;
|
2021-07-22 07:43:01 +00:00
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
typedef struct hio_svc_htts_t hio_svc_htts_t;
|
|
|
|
typedef struct hio_svc_httc_t hio_svc_httc_t;
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
2023-01-11 15:41:01 +00:00
|
|
|
typedef struct hio_svc_htts_task_t hio_svc_htts_task_t;
|
2023-03-04 15:55:15 +00:00
|
|
|
typedef struct hio_svc_htts_cli_t hio_svc_htts_cli_t;
|
2021-07-22 07:43:01 +00:00
|
|
|
|
2023-01-11 15:41:01 +00:00
|
|
|
typedef void (*hio_svc_htts_task_on_kill_t) (
|
|
|
|
hio_svc_htts_task_t* task
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2023-01-11 15:41:01 +00:00
|
|
|
#define HIO_SVC_HTTS_TASK_HEADER \
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_svc_htts_t* htts; \
|
2023-01-11 15:41:01 +00:00
|
|
|
hio_oow_t task_size; \
|
|
|
|
hio_oow_t task_refcnt; \
|
|
|
|
hio_svc_htts_task_t* task_prev; \
|
|
|
|
hio_svc_htts_task_t* task_next; \
|
2023-03-04 11:26:38 +00:00
|
|
|
hio_svc_htts_task_on_kill_t task_on_kill; \
|
2023-03-09 16:27:08 +00:00
|
|
|
hio_dev_sck_t* task_csck; \
|
|
|
|
hio_svc_htts_cli_t* task_client; \
|
|
|
|
unsigned int task_keep_client_alive: 1; \
|
2023-03-04 15:55:15 +00:00
|
|
|
unsigned int task_req_qpath_ending_with_slash: 1; \
|
|
|
|
unsigned int task_req_qpath_is_root: 1; \
|
2023-03-18 20:04:32 +00:00
|
|
|
unsigned int task_req_conlen_unlimited: 1; \
|
2023-03-11 03:54:36 +00:00
|
|
|
unsigned int task_res_chunked: 1; \
|
2023-03-18 20:04:32 +00:00
|
|
|
unsigned int task_res_started: 1; \
|
2023-03-11 03:54:36 +00:00
|
|
|
unsigned int task_res_ended: 1; \
|
2023-03-18 20:04:32 +00:00
|
|
|
unsigned int task_res_ever_sent: 1; \
|
|
|
|
int task_req_flags; \
|
2023-03-09 16:27:08 +00:00
|
|
|
hio_http_version_t task_req_version; \
|
|
|
|
hio_http_method_t task_req_method; \
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_bch_t* task_req_qmth; \
|
|
|
|
hio_bch_t* task_req_qpath; \
|
2023-03-18 20:04:32 +00:00
|
|
|
hio_oow_t task_req_conlen; \
|
|
|
|
hio_http_status_t task_status_code; \
|
|
|
|
hio_ooi_t task_res_pending_writes;
|
2021-07-22 07:43:01 +00:00
|
|
|
|
2023-01-11 15:41:01 +00:00
|
|
|
struct hio_svc_htts_task_t
|
2021-07-22 07:43:01 +00:00
|
|
|
{
|
2023-01-11 15:41:01 +00:00
|
|
|
HIO_SVC_HTTS_TASK_HEADER;
|
2021-07-22 07:43:01 +00:00
|
|
|
};
|
|
|
|
|
2023-11-16 03:29:54 +00:00
|
|
|
#define HIO_SVC_HTTS_TASK_RC(task) ((task)->task_refcnt)
|
|
|
|
|
2023-02-06 13:30:56 +00:00
|
|
|
#define HIO_SVC_HTTS_TASK_RCUP(task) (++(task)->task_refcnt)
|
|
|
|
|
|
|
|
#define HIO_SVC_HTTS_TASK_RCDOWN(task_var) do { \
|
|
|
|
if (--(task_var)->task_refcnt == 0) hio_svc_htts_task_kill(task_var); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define HIO_SVC_HTTS_TASK_REF(task, var) do { \
|
|
|
|
(var) = (task); \
|
|
|
|
HIO_SVC_HTTS_TASK_RCUP(task); \
|
|
|
|
} while(0)
|
|
|
|
|
|
|
|
#define HIO_SVC_HTTS_TASK_UNREF(task_var) do { \
|
|
|
|
if (--(task_var)->task_refcnt == 0) { \
|
|
|
|
hio_svc_htts_task_t* __task_tmp = (hio_svc_htts_task_t*)(task_var); \
|
|
|
|
(task_var) = HIO_NULL; \
|
|
|
|
hio_svc_htts_task_kill(__task_tmp); \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
(task_var) = HIO_NULL; \
|
|
|
|
} \
|
|
|
|
} while(0)
|
2021-07-22 07:43:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
typedef int (*hio_svc_htts_proc_req_t) (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* sck,
|
|
|
|
hio_htre_t* req
|
|
|
|
);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
struct hio_svc_htts_thr_func_info_t
|
|
|
|
{
|
|
|
|
hio_http_method_t req_method;
|
|
|
|
hio_http_version_t req_version;
|
|
|
|
hio_bch_t* req_path;
|
|
|
|
hio_bch_t* req_param;
|
|
|
|
int req_x_http_method_override; /* -1 or hio_http_method_t */
|
|
|
|
|
|
|
|
/* TODO: header table */
|
|
|
|
|
|
|
|
hio_skad_t client_addr;
|
|
|
|
hio_skad_t server_addr;
|
|
|
|
};
|
|
|
|
typedef struct hio_svc_htts_thr_func_info_t hio_svc_htts_thr_func_info_t;
|
|
|
|
|
|
|
|
typedef void (*hio_svc_htts_thr_func_t) (
|
2023-01-11 14:59:41 +00:00
|
|
|
hio_svc_htts_t* htts,
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_dev_thr_iopair_t* iop,
|
2022-10-25 22:47:40 +00:00
|
|
|
hio_svc_htts_thr_func_info_t* tfi,
|
2021-07-22 07:43:01 +00:00
|
|
|
void* ctx
|
|
|
|
);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
2023-01-11 14:59:41 +00:00
|
|
|
struct hio_svc_htts_fun_func_info_t
|
|
|
|
{
|
|
|
|
hio_http_method_t req_method;
|
|
|
|
hio_http_version_t req_version;
|
|
|
|
hio_bch_t* req_path;
|
|
|
|
hio_bch_t* req_param;
|
|
|
|
int req_x_http_method_override; /* -1 or hio_http_method_t */
|
|
|
|
|
|
|
|
/* TODO: header table */
|
|
|
|
|
|
|
|
hio_skad_t client_addr;
|
|
|
|
hio_skad_t server_addr;
|
|
|
|
};
|
|
|
|
typedef struct hio_svc_htts_fun_func_info_t hio_svc_htts_fun_func_info_t;
|
|
|
|
|
|
|
|
typedef void (*hio_svc_htts_fun_func_t) (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
void* ctx
|
|
|
|
);
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------- */
|
|
|
|
|
2023-03-18 20:04:32 +00:00
|
|
|
#if 0
|
2022-10-09 16:41:07 +00:00
|
|
|
enum hio_svc_htts_cgi_option_t
|
|
|
|
{
|
2023-03-18 20:04:32 +00:00
|
|
|
/* no option yet */
|
2022-10-09 16:41:07 +00:00
|
|
|
};
|
|
|
|
|
2023-01-24 16:45:28 +00:00
|
|
|
enum hio_svc_htts_fcgi_option_t
|
|
|
|
{
|
2023-03-18 20:04:32 +00:00
|
|
|
/* no option yet */
|
2023-01-24 16:45:28 +00:00
|
|
|
};
|
2023-03-18 20:04:32 +00:00
|
|
|
#endif
|
2023-01-24 16:45:28 +00:00
|
|
|
|
2022-10-09 16:41:07 +00:00
|
|
|
enum hio_svc_htts_file_option_t
|
|
|
|
{
|
2023-03-18 20:04:32 +00:00
|
|
|
HIO_SVC_HTTS_FILE_READ_ONLY = (1 << 0)
|
2022-10-09 16:41:07 +00:00
|
|
|
};
|
|
|
|
|
2023-03-18 20:04:32 +00:00
|
|
|
#if 0
|
2022-10-09 16:41:07 +00:00
|
|
|
enum hio_svc_htts_thr_option_t
|
|
|
|
{
|
2023-03-18 20:04:32 +00:00
|
|
|
/* no option yet */
|
2022-10-09 16:41:07 +00:00
|
|
|
};
|
|
|
|
|
2023-03-18 20:04:32 +00:00
|
|
|
|
2022-10-09 16:41:07 +00:00
|
|
|
enum hio_svc_htts_txt_option_t
|
|
|
|
{
|
|
|
|
/* no option yet */
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2022-12-26 17:03:53 +00:00
|
|
|
enum hio_svc_htts_file_bfmt_dir_type_t
|
|
|
|
{
|
|
|
|
HIO_SVC_HTTS_FILE_BFMT_DIR_HEADER,
|
|
|
|
HIO_SVC_HTTS_FILE_BFMT_DIR_ENTRY,
|
|
|
|
HIO_SVC_HTTS_FILE_BFMT_DIR_FOOTER
|
|
|
|
};
|
|
|
|
typedef enum hio_svc_htts_file_bfmt_dir_type_t hio_svc_htts_file_bfmt_dir_type_t;
|
|
|
|
|
2022-12-21 14:57:52 +00:00
|
|
|
struct hio_svc_htts_file_cbs_t
|
|
|
|
{
|
2022-12-31 15:20:07 +00:00
|
|
|
const hio_bch_t* (*get_mime_type) (hio_svc_htts_t* htts, const hio_bch_t* qpath, const hio_bch_t* file_path, void* ctx);
|
|
|
|
int (*open_dir_list) (hio_svc_htts_t* htts, const hio_bch_t* qpath, const hio_bch_t* dir_path, const hio_bch_t** res_mime_type, void* ctx);
|
2022-12-23 14:44:55 +00:00
|
|
|
void *ctx;
|
2022-12-21 14:57:52 +00:00
|
|
|
};
|
|
|
|
typedef struct hio_svc_htts_file_cbs_t hio_svc_htts_file_cbs_t;
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_comp_http_versions (
|
|
|
|
const hio_http_version_t* v1,
|
|
|
|
const hio_http_version_t* v2
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_comp_http_version_numbers (
|
|
|
|
const hio_http_version_t* v1,
|
|
|
|
int v2_major,
|
|
|
|
int v2_minor
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT const hio_bch_t* hio_http_status_to_bcstr (
|
|
|
|
int code
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT const hio_bch_t* hio_http_method_to_bcstr (
|
|
|
|
hio_http_method_t type
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT hio_http_method_t hio_bcstr_to_http_method (
|
|
|
|
const hio_bch_t* name
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT hio_http_method_t hio_bchars_to_http_method (
|
|
|
|
const hio_bch_t* nameptr,
|
|
|
|
hio_oow_t namelen
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_parse_http_range_bcstr (
|
|
|
|
const hio_bch_t* str,
|
|
|
|
hio_http_range_t* range
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_parse_http_time_bcstr (
|
|
|
|
const hio_bch_t* str,
|
|
|
|
hio_ntime_t* nt
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT hio_bch_t* hio_fmt_http_time_to_bcstr (
|
|
|
|
const hio_ntime_t* nt,
|
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t bufsz
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The hio_is_perenced_http_bcstr() function determines if the given string
|
|
|
|
* contains a valid percent-encoded sequence.
|
|
|
|
*/
|
|
|
|
HIO_EXPORT int hio_is_perenced_http_bcstr (
|
|
|
|
const hio_bch_t* str
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The hio_perdec_http_bcstr() function performs percent-decoding over a string.
|
|
|
|
* The caller must ensure that the output buffer \a buf is large enough.
|
|
|
|
* If \a ndecs is not #HIO_NULL, it is set to the number of characters
|
2022-12-31 15:52:38 +00:00
|
|
|
* decoded. 0 means no characters in the input string required decoding
|
2021-07-22 07:43:01 +00:00
|
|
|
* \return the length of the output string.
|
|
|
|
*/
|
|
|
|
HIO_EXPORT hio_oow_t hio_perdec_http_bcstr (
|
2023-01-11 14:59:41 +00:00
|
|
|
const hio_bch_t* str,
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t* ndecs
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The hio_perdec_http_bcstr() function performs percent-decoding over a length-bound string.
|
|
|
|
* It doesn't insert the terminating null.
|
|
|
|
*/
|
|
|
|
HIO_EXPORT hio_oow_t hio_perdec_http_bcs (
|
2023-01-11 14:59:41 +00:00
|
|
|
const hio_bcs_t* str,
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t* ndecs
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The hio_perenc_http_bcstr() function performs percent-encoding over a string.
|
2023-01-02 15:36:14 +00:00
|
|
|
* It returns the length of the encoded string if \a len is long enough to hold
|
|
|
|
* the resulting string and the terminating null. If the return value is equal to
|
|
|
|
* or greater than \a len, the buffer pointed to by \a buf of the length \a len
|
|
|
|
* is not large enough.
|
|
|
|
* \return the length of the output string encoded on success or the number of encoded
|
|
|
|
* string that would have been written if the buffer has been large enough.
|
2021-07-22 07:43:01 +00:00
|
|
|
*/
|
|
|
|
HIO_EXPORT hio_oow_t hio_perenc_http_bcstr (
|
2023-01-11 14:59:41 +00:00
|
|
|
const hio_bch_t* str,
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_bch_t* buf,
|
2023-01-02 15:36:14 +00:00
|
|
|
hio_oow_t len,
|
|
|
|
int opt /**< 0 or bitwise-OR'ed of #hio_perenc_http_bcstr_opt_t */
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2023-01-02 15:36:14 +00:00
|
|
|
/**
|
|
|
|
* The hio_perenc_http_bchars() function performs percent-ending over a length-bound string.
|
|
|
|
* It doesn't null-terminate the result. The buffer requirement is less than hio_perenc_http_bcstr()
|
|
|
|
* by 1.
|
|
|
|
*/
|
|
|
|
HIO_EXPORT hio_oow_t hio_perenc_http_bchars (
|
|
|
|
const hio_bch_t* str,
|
|
|
|
hio_oow_t sln,
|
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t len,
|
|
|
|
int opt /**< 0 or bitwise-OR'ed of #hio_perenc_http_bcstr_opt_t */
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_scan_http_qparam (
|
|
|
|
hio_bch_t* qparam,
|
|
|
|
int (*qparamcb) (hio_bcs_t* key, hio_bcs_t* val, void* ctx),
|
|
|
|
void* ctx
|
|
|
|
);
|
|
|
|
|
2023-01-02 15:36:14 +00:00
|
|
|
HIO_EXPORT hio_oow_t hio_escape_html_bchars (
|
|
|
|
const hio_bch_t* str,
|
|
|
|
hio_oow_t sln,
|
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t len
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT hio_oow_t hio_escape_html_bcstr (
|
|
|
|
const hio_bch_t* str,
|
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t len
|
|
|
|
);
|
2023-01-11 14:59:41 +00:00
|
|
|
|
2023-03-05 15:40:29 +00:00
|
|
|
HIO_EXPORT int hio_parse_http_status_header_value (
|
|
|
|
const hio_bch_t* status_value, /* value of the Status header */
|
|
|
|
int* status_code, /* [OUT] parsed status code*/
|
|
|
|
const hio_bch_t** status_desc /* [OUT] parsed status description - HIO_NULL if omitted in the value */
|
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
/* HTTP SERVER SERVICE */
|
|
|
|
/* ------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
HIO_EXPORT hio_svc_htts_t* hio_svc_htts_start (
|
2023-02-20 08:08:41 +00:00
|
|
|
hio_t* hio,
|
|
|
|
hio_oow_t xtnsize,
|
|
|
|
hio_dev_sck_bind_t* binds,
|
|
|
|
hio_oow_t nbinds,
|
|
|
|
hio_svc_htts_proc_req_t proc_req,
|
|
|
|
const hio_svc_fcgic_tmout_t* fcgic_tmout
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT void hio_svc_htts_stop (
|
|
|
|
hio_svc_htts_t* htts
|
|
|
|
);
|
|
|
|
|
2023-11-17 00:42:59 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_getoption (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_svc_htts_option_t id,
|
|
|
|
void* value
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_setoption (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_svc_htts_option_t id,
|
|
|
|
const void* value
|
|
|
|
);
|
|
|
|
|
2022-10-07 05:08:40 +00:00
|
|
|
HIO_EXPORT void* hio_svc_htts_getxtn (
|
|
|
|
hio_svc_htts_t* htts
|
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
#if defined(HIO_HAVE_INLINE)
|
|
|
|
static HIO_INLINE hio_t* hio_svc_htts_gethio(hio_svc_htts_t* svc) { return hio_svc_gethio((hio_svc_t*)svc); }
|
|
|
|
#else
|
|
|
|
# define hio_svc_htts_gethio(svc) hio_svc_gethio(svc)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_writetosidechan (
|
|
|
|
hio_svc_htts_t* htts,
|
2021-08-06 03:23:48 +00:00
|
|
|
hio_oow_t idx, /* listener index */
|
2021-07-22 07:43:01 +00:00
|
|
|
const void* dptr,
|
|
|
|
hio_oow_t dlen
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_setservernamewithbcstr (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
const hio_bch_t* server_name
|
|
|
|
);
|
|
|
|
|
2021-08-06 03:23:48 +00:00
|
|
|
/* return the listening device at the given position.
|
|
|
|
* not all devices may be up and running */
|
|
|
|
HIO_EXPORT hio_dev_sck_t* hio_svc_htts_getlistendev (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_oow_t idx
|
|
|
|
);
|
|
|
|
|
|
|
|
/* return the total number of listening devices requested to start.
|
|
|
|
* not all devices may be up and running */
|
|
|
|
HIO_EXPORT hio_oow_t hio_sv_htts_getnlistendevs (
|
|
|
|
hio_svc_htts_t* htts
|
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_getsockaddr (
|
|
|
|
hio_svc_htts_t* htts,
|
2021-08-06 03:23:48 +00:00
|
|
|
hio_oow_t idx, /* listener index */
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_skad_t* skad
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_docgi (
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
const hio_bch_t* docroot,
|
|
|
|
const hio_bch_t* script,
|
|
|
|
int options,
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2022-09-12 14:43:29 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_dofcgi (
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
const hio_skad_t* fcgis_addr,
|
|
|
|
const hio_bch_t* docroot,
|
|
|
|
const hio_bch_t* script,
|
|
|
|
int options, /**< 0 or bitwise-Ored of #hio_svc_htts_file_option_t enumerators */
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill
|
2022-09-12 14:43:29 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_dofile (
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
const hio_bch_t* docroot,
|
|
|
|
const hio_bch_t* filepath,
|
|
|
|
const hio_bch_t* mime_type,
|
|
|
|
int options,
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill,
|
|
|
|
hio_svc_htts_file_cbs_t* cbs
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2023-03-30 06:34:32 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_dofcgi (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
const hio_skad_t* fcgis_addr,
|
|
|
|
const hio_bch_t* docroot,
|
|
|
|
const hio_bch_t* script,
|
|
|
|
int options, /**< 0 or bitwise-Ored of #hio_svc_htts_file_option_t enumerators */
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_doprxy (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
const hio_skad_t* tgt_addr,
|
|
|
|
int options,
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill
|
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_dothr (
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
hio_svc_htts_thr_func_t func,
|
|
|
|
void* ctx,
|
|
|
|
int options,
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_dotxt (
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
hio_dev_sck_t* csck,
|
|
|
|
hio_htre_t* req,
|
|
|
|
int status_code,
|
|
|
|
const hio_bch_t* content_type,
|
|
|
|
const hio_bch_t* content_text,
|
|
|
|
int options,
|
|
|
|
hio_svc_htts_task_on_kill_t on_kill
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2023-03-30 06:34:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-01-11 15:41:01 +00:00
|
|
|
HIO_EXPORT hio_svc_htts_task_t* hio_svc_htts_task_make (
|
2021-07-22 07:43:01 +00:00
|
|
|
hio_svc_htts_t* htts,
|
2023-01-11 15:41:01 +00:00
|
|
|
hio_oow_t task_size,
|
2023-03-04 11:26:38 +00:00
|
|
|
hio_svc_htts_task_on_kill_t on_kill,
|
2023-03-04 15:55:15 +00:00
|
|
|
hio_htre_t* req,
|
2023-03-05 18:27:42 +00:00
|
|
|
hio_dev_sck_t* csck
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2023-01-11 15:41:01 +00:00
|
|
|
HIO_EXPORT void hio_svc_htts_task_kill (
|
|
|
|
hio_svc_htts_task_t* task
|
2021-07-22 07:43:01 +00:00
|
|
|
);
|
|
|
|
|
2023-03-18 20:04:32 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_task_sendfinalres (
|
2023-03-09 16:27:08 +00:00
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
int status_code,
|
|
|
|
const hio_bch_t* content_type,
|
|
|
|
const hio_bch_t* content_text,
|
|
|
|
int force_close
|
|
|
|
);
|
|
|
|
|
2023-03-10 17:32:33 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_task_startreshdr (
|
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
int status_code,
|
|
|
|
const hio_bch_t* status_desc,
|
|
|
|
int chunked
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_task_addreshdrs (
|
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
const hio_bch_t* key,
|
|
|
|
const hio_htre_hdrval_t* value
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_task_addreshdr (
|
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
const hio_bch_t* key,
|
|
|
|
const hio_bch_t* value
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_task_addreshdrfmt (
|
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
const hio_bch_t* key,
|
|
|
|
const hio_bch_t* vfmt,
|
|
|
|
...
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_task_endreshdr (
|
|
|
|
hio_svc_htts_task_t* task
|
|
|
|
);
|
|
|
|
|
2023-03-25 18:01:40 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_task_addresbody (
|
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
const void* data,
|
|
|
|
hio_iolen_t dlen
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_task_addresbodyfromfile (
|
|
|
|
hio_svc_htts_task_t* task,
|
|
|
|
int fd,
|
|
|
|
hio_foff_t foff,
|
|
|
|
hio_iolen_t len
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT int hio_svc_htts_task_endbody (
|
|
|
|
hio_svc_htts_task_t* task
|
|
|
|
);
|
|
|
|
|
2023-03-18 20:04:32 +00:00
|
|
|
HIO_EXPORT int hio_svc_htts_task_handleexpect100 (
|
2023-03-28 16:24:20 +00:00
|
|
|
hio_svc_htts_task_t* task
|
2023-03-18 20:04:32 +00:00
|
|
|
);
|
|
|
|
|
2021-07-22 07:43:01 +00:00
|
|
|
HIO_EXPORT void hio_svc_htts_fmtgmtime (
|
2023-01-11 14:59:41 +00:00
|
|
|
hio_svc_htts_t* htts,
|
2021-07-22 07:43:01 +00:00
|
|
|
const hio_ntime_t* nt,
|
|
|
|
hio_bch_t* buf,
|
|
|
|
hio_oow_t len
|
|
|
|
);
|
|
|
|
|
|
|
|
HIO_EXPORT hio_bch_t* hio_svc_htts_dupmergepaths (
|
|
|
|
hio_svc_htts_t* htts,
|
|
|
|
const hio_bch_t* base,
|
|
|
|
const hio_bch_t* path
|
|
|
|
);
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|