added the hio-webs command

added the extension size parameter to hio_svc_htts_start()
added the docker build step
This commit is contained in:
2022-10-07 14:08:40 +09:00
parent 384925992c
commit 913bb7e0b7
15 changed files with 343 additions and 31 deletions

View File

@ -251,6 +251,7 @@ HIO_EXPORT int hio_scan_http_qparam (
HIO_EXPORT hio_svc_htts_t* hio_svc_htts_start (
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
@ -260,6 +261,10 @@ HIO_EXPORT void hio_svc_htts_stop (
hio_svc_htts_t* htts
);
HIO_EXPORT void* hio_svc_htts_getxtn (
hio_svc_htts_t* htts
);
#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

View File

@ -429,6 +429,22 @@ HIO_EXPORT void hio_sub_ntime (
const hio_ntime_t* y
);
/* =========================================================================
* PATH STRING
* ========================================================================= */
HIO_EXPORT const hio_uch_t* hio_get_base_name_ucstr (
const hio_uch_t* path
);
HIO_EXPORT const hio_bch_t* hio_get_base_name_bcstr (
const hio_bch_t* path
);
#if defined(HIO_OOCH_IS_UCH)
# define hio_get_base_name_oocstr hio_get_base_name_ucstr
#else
# define hio_get_base_name_oocstr hio_get_base_name_bcstr
#endif
/* =========================================================================
* BIT SWAP

View File

@ -145,15 +145,18 @@ static int file_send_final_status_to_client (file_t* file, int status_code, int
{
hio_svc_htts_cli_t* cli = file->client;
hio_bch_t dtbuf[64];
const hio_bch_t* status_msg;
hio_svc_htts_fmtgmtime (cli->htts, HIO_NULL, dtbuf, HIO_COUNTOF(dtbuf));
status_msg = hio_http_status_to_bcstr(status_code);
if (!force_close) force_close = !file->keep_alive;
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %s\r\nConnection: %hs\r\nContent-Length: 0\r\n\r\n",
if (hio_becs_fmt(cli->sbuf, "HTTP/%d.%d %d %hs\r\nServer: %hs\r\nDate: %s\r\nConnection: %hs\r\nContent-Length: %zu\r\n\r\n%s",
file->req_version.major, file->req_version.minor,
status_code, hio_http_status_to_bcstr(status_code),
status_code, status_msg,
cli->htts->server_name, dtbuf,
(force_close? "close": "keep-alive")) == (hio_oow_t)-1) return -1;
(force_close? "close": "keep-alive"),
hio_count_bcstr(status_msg), status_msg) == (hio_oow_t)-1) return -1;
return (file_write_to_client(file, HIO_BECS_PTR(cli->sbuf), HIO_BECS_LEN(cli->sbuf)) <= -1 ||
(force_close && file_write_to_client(file, HIO_NULL, 0) <= -1))? -1: 0;

View File

@ -329,8 +329,7 @@ static void halt_idle_clients (hio_t* hio, const hio_ntime_t* now, hio_tmrjob_t*
}
/* ------------------------------------------------------------------------ */
hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_oow_t nbinds, hio_svc_htts_proc_req_t proc_req)
hio_svc_htts_t* hio_svc_htts_start (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)
{
hio_svc_htts_t* htts = HIO_NULL;
union
@ -347,7 +346,7 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_dev_sck_bind_t* binds, hio_o
goto oops;
}
htts = (hio_svc_htts_t*)hio_callocmem(hio, HIO_SIZEOF(*htts));
htts = (hio_svc_htts_t*)hio_callocmem(hio, HIO_SIZEOF(*htts) + xtnsize);
if (HIO_UNLIKELY(!htts)) goto oops;
HIO_DEBUG1 (hio, "HTTS - STARTING SERVICE %p\n", htts);
@ -543,6 +542,11 @@ void hio_svc_htts_stop (hio_svc_htts_t* htts)
hio_freemem (hio, htts);
}
void* hio_svc_htts_getxtn (hio_svc_htts_t* htts)
{
return (void*)(htts + 1);
}
int hio_svc_htts_setservernamewithbcstr (hio_svc_htts_t* htts, const hio_bch_t* name)
{
hio_t* hio = htts->hio;
@ -608,6 +612,19 @@ int hio_svc_htts_getsockaddr (hio_svc_htts_t* htts, hio_oow_t idx, hio_skad_t* s
/* ----------------------------------------------------------------- */
/* rsrc_size must be the total size to allocate including the header.
*
* For instance, if you define a resource like below,
*
* struct my_rsrc_t
* {
* HIO_SVC_HTTS_RSRC_HEADER;
* int a;
* int b;
* };
*
* you can pass sizeof(my_rsrc_t) to hio_svc_htts_rsrc_make()
*/
hio_svc_htts_rsrc_t* hio_svc_htts_rsrc_make (hio_svc_htts_t* htts, hio_oow_t rsrc_size, hio_svc_htts_rsrc_on_kill_t on_kill)
{
hio_t* hio = htts->hio;
@ -631,12 +648,6 @@ void hio_svc_htts_rsrc_kill (hio_svc_htts_rsrc_t* rsrc)
hio_freemem (hio, rsrc);
}
#if defined(HIO_HAVE_INLINE)
static HIO_INLINE void* hio_svc_htts_rsrc_getxtn (hio_svc_htts_rsrc_t* rsrc) { return rsrc + 1; }
#else
#define hio_svc_htts_rsrc_getxtn(rsrc) ((void*)((hio_svc_htts_rsrc_t*)rsrc + 1))
#endif
/* ----------------------------------------------------------------- */

View File

@ -927,3 +927,33 @@ void hio_sub_ntime (hio_ntime_t* z, const hio_ntime_t* x, const hio_ntime_t* y)
}
/* ========================================================================= */
#if defined(_WIN32) || defined(__OS2__) || defined(__DOS__)
# define IS_PATH_SEP(c) ((c) == '/' || (c) == '\\')
#else
# define IS_PATH_SEP(c) ((c) == '/')
#endif
const hio_uch_t* hio_get_base_name_ucstr (const hio_uch_t* path)
{
const hio_uch_t* p, * last = HIO_NULL;
for (p = path; *p != '\0'; p++)
{
if (IS_PATH_SEP(*p)) last = p;
}
return last? (last +1): path;
}
const hio_bch_t* hio_get_base_name_bcstr (const hio_bch_t* path)
{
const hio_bch_t* p, * last = HIO_NULL;
for (p = path; *p != '\0'; p++)
{
if (IS_PATH_SEP(*p)) last = p;
}
return last? (last +1): path;
}