moved becbuf from hio to htts

This commit is contained in:
hyung-hwan 2023-02-21 01:07:20 +09:00
parent 2ecfc9be39
commit ce4edd3f0e
9 changed files with 42 additions and 57 deletions

View File

@ -549,6 +549,8 @@ void hio_svc_fcgic_untie (hio_svc_fcgic_sess_t* sess)
int hio_svc_fcgic_beginrequest (hio_svc_fcgic_sess_t* sess) int hio_svc_fcgic_beginrequest (hio_svc_fcgic_sess_t* sess)
{ {
hio_svc_fcgic_conn_t* conn = sess->conn;
hio_t* hio = conn->hio;
hio_iovec_t iov[2]; hio_iovec_t iov[2];
hio_fcgi_record_header_t h; hio_fcgi_record_header_t h;
hio_fcgi_begin_request_body_t b; hio_fcgi_begin_request_body_t b;
@ -556,7 +558,7 @@ int hio_svc_fcgic_beginrequest (hio_svc_fcgic_sess_t* sess)
if (!sess->conn->dev) if (!sess->conn->dev)
{ {
/* TODO: set error **/ hio_seterrbfmt (hio, HIO_EPERM, "fcgi not connected");
return -1; return -1;
} }
@ -586,33 +588,28 @@ int hio_svc_fcgic_beginrequest (hio_svc_fcgic_sess_t* sess)
int hio_svc_fcgic_writeparam (hio_svc_fcgic_sess_t* sess, const void* key, hio_iolen_t ksz, const void* val, hio_iolen_t vsz) int hio_svc_fcgic_writeparam (hio_svc_fcgic_sess_t* sess, const void* key, hio_iolen_t ksz, const void* val, hio_iolen_t vsz)
{ {
hio_svc_fcgic_conn_t* conn = sess->conn;
hio_t* hio = conn->hio;
hio_iovec_t iov[4]; hio_iovec_t iov[4];
hio_fcgi_record_header_t h; hio_fcgi_record_header_t h;
hio_uint8_t sz[8]; hio_uint8_t sz[8];
hio_oow_t szc = 0; hio_oow_t szc = 0;
hio_oow_t plen = 0;
void* wrctx; void* wrctx;
if (!sess->conn->dev) if (!conn->dev)
{ {
/* TODO: set error **/ hio_seterrbfmt (hio, HIO_EPERM, "fcgi not connected");
return -1; return -1;
} }
/* TODO: buffer key value pairs. flush on the end of param of buffer full.
* can merge multipl key values pairs in one FCGI_PARAMS packets....
*/
HIO_MEMSET (&h, 0, HIO_SIZEOF(h));
h.version = HIO_FCGI_VERSION;
h.type = HIO_FCGI_PARAMS;
h.id = hio_hton16(sess->sid + 1);
h.content_len = 0;
/* TODO: check ksz and vsz can't exceed max 32bit value. */ /* TODO: check ksz and vsz can't exceed max 32bit value. */
/* limit sizes to the max of the signed 32-bit interger /* limit sizes to the max of the signed 32-bit interger
* the high-order bit is used as encoding marker (1-byte or 4-byte encoding). * the high-order bit is used as encoding marker (1-byte or 4-byte encoding).
* so a size can't hit the unsigned max. */ * so a size can't hit the unsigned max. */
ksz &= HIO_TYPE_MAX(hio_int32_t); ksz &= HIO_TYPE_MAX(hio_int32_t);
vsz &= HIO_TYPE_MAX(hio_int32_t); vsz &= HIO_TYPE_MAX(hio_int32_t);
if (ksz > 0) if (ksz > 0)
{ {
if (ksz > 0x7F) if (ksz > 0x7F)
@ -639,14 +636,21 @@ int hio_svc_fcgic_writeparam (hio_svc_fcgic_sess_t* sess, const void* key, hio_i
sz[szc++] = vsz; sz[szc++] = vsz;
} }
h.content_len = szc + ksz + vsz; plen = szc + ksz + vsz;
/* TODO: check content_len overflows... */ if (plen > 0xFFFF)
{
hio_seterrbfmt (hio, HIO_EINVAL, "fcgi parameter too large");
return -1;
}
} }
h.content_len = hio_hton16(h.content_len); HIO_MEMSET (&h, 0, HIO_SIZEOF(h));
h.version = HIO_FCGI_VERSION;
h.type = HIO_FCGI_PARAMS;
h.id = hio_hton16(sess->sid + 1);
h.content_len = hio_hton16(plen);
h.padding_len = 0; h.padding_len = 0;
/* TODO: some buffering of parameters??? if the key/value isn't long enough, it may trigger many system calls*/
iov[0].iov_ptr = &h; iov[0].iov_ptr = &h;
iov[0].iov_len = HIO_SIZEOF(h); iov[0].iov_len = HIO_SIZEOF(h);
if (ksz > 0) if (ksz > 0)
@ -666,13 +670,15 @@ int hio_svc_fcgic_writeparam (hio_svc_fcgic_sess_t* sess, const void* key, hio_i
int hio_svc_fcgic_writestdin (hio_svc_fcgic_sess_t* sess, const void* data, hio_iolen_t size) int hio_svc_fcgic_writestdin (hio_svc_fcgic_sess_t* sess, const void* data, hio_iolen_t size)
{ {
hio_svc_fcgic_conn_t* conn = sess->conn;
hio_t* hio = conn->hio;
hio_iovec_t iov[2]; hio_iovec_t iov[2];
hio_fcgi_record_header_t h; hio_fcgi_record_header_t h;
void* wrctx; void* wrctx;
if (!sess->conn->dev) if (!sess->conn->dev)
{ {
/* TODO: set error **/ hio_seterrbfmt (hio, HIO_EPERM, "fcgi not connected");
return -1; return -1;
} }

View File

@ -1038,12 +1038,4 @@ struct hio_cmgr_t
((c) >= 'A' && (c) <= 'Z')? ((c) - 'A' + 10): \ ((c) >= 'A' && (c) <= 'Z')? ((c) - 'A' + 10): \
((c) >= 'a' && (c) <= 'Z')? ((c) - 'a' + 10): base) ((c) >= 'a' && (c) <= 'Z')? ((c) - 'a' + 10): base)
/* =========================================================================
* PRE-DEFINITION OF FOUNDATIONAL COMPOSITE TYPES
* =========================================================================*/
typedef struct hio_t hio_t;
typedef struct hio_becs_t hio_becs_t;
typedef struct hio_uecs_t hio_uecs_t;
#endif #endif

View File

@ -60,11 +60,8 @@
/**< last character. unsafe if length <= 0 */ /**< last character. unsafe if length <= 0 */
#define HIO_UECS_LASTCHAR(s) ((s)->val.ptr[(s)->val.len-1]) #define HIO_UECS_LASTCHAR(s) ((s)->val.ptr[(s)->val.len-1])
/*
* defined in hio-cmn.h
typedef struct hio_becs_t hio_becs_t; typedef struct hio_becs_t hio_becs_t;
typedef struct hio_uecs_t hio_uecs_t; typedef struct hio_uecs_t hio_uecs_t;
*/
typedef hio_oow_t (*hio_becs_sizer_t) ( typedef hio_oow_t (*hio_becs_sizer_t) (
hio_becs_t* data, hio_becs_t* data,

View File

@ -61,7 +61,6 @@ enum hio_fcgi_role_t
}; };
typedef enum hio_fcgi_role_t hio_fcgi_role_t; typedef enum hio_fcgi_role_t hio_fcgi_role_t;
/* flag in fcgi_begin_request_body */ /* flag in fcgi_begin_request_body */
#define HIO_FCGI_KEEP_CONN 1 #define HIO_FCGI_KEEP_CONN 1

View File

@ -24,7 +24,6 @@
#include "hio-prv.h" #include "hio-prv.h"
#include <hio-fmt.h> #include <hio-fmt.h>
#include <hio-ecs.h>
#include <stdlib.h> /* malloc, free, etc */ #include <stdlib.h> /* malloc, free, etc */
#define DEV_CAP_ALL_WATCHED (HIO_DEV_CAP_IN_WATCHED | HIO_DEV_CAP_OUT_WATCHED | HIO_DEV_CAP_PRI_WATCHED) #define DEV_CAP_ALL_WATCHED (HIO_DEV_CAP_IN_WATCHED | HIO_DEV_CAP_OUT_WATCHED | HIO_DEV_CAP_PRI_WATCHED)
@ -124,9 +123,6 @@ int hio_init (hio_t* hio, hio_mmgr_t* mmgr, hio_cmgr_t* cmgr, hio_bitmask_t feat
hio->log.ptr = hio_allocmem(hio, (hio->log.capa + 1) * HIO_SIZEOF(*hio->log.ptr)); hio->log.ptr = hio_allocmem(hio, (hio->log.capa + 1) * HIO_SIZEOF(*hio->log.ptr));
if (HIO_UNLIKELY(!hio->log.ptr)) goto oops; if (HIO_UNLIKELY(!hio->log.ptr)) goto oops;
hio->becbuf = hio_becs_open(hio, 0, 256);
if (HIO_UNLIKELY(!hio->becbuf)) goto oops;
/* inititalize the system-side logging */ /* inititalize the system-side logging */
if (HIO_UNLIKELY(hio_sys_init(hio) <= -1)) goto oops; if (HIO_UNLIKELY(hio_sys_init(hio) <= -1)) goto oops;
sys_inited = 1; sys_inited = 1;
@ -153,7 +149,6 @@ oops:
if (sys_inited) hio_sys_fini (hio); if (sys_inited) hio_sys_fini (hio);
if (hio->becbuf) hio_freemem (hio, hio->becbuf);
if (hio->log.ptr) hio_freemem (hio, hio->log.ptr); if (hio->log.ptr) hio_freemem (hio, hio->log.ptr);
hio->log.capa = 0; hio->log.capa = 0;
return -1; return -1;
@ -250,12 +245,6 @@ void hio_fini (hio_t* hio)
hio_sys_fini (hio); /* finalize the system dependent data */ hio_sys_fini (hio); /* finalize the system dependent data */
if (hio->becbuf)
{
hio_becs_close (hio->becbuf);
hio->becbuf = HIO_NULL;
}
if (hio->log.ptr) if (hio->log.ptr)
{ {
hio_freemem (hio, hio->log.ptr); hio_freemem (hio, hio->log.ptr);

View File

@ -54,10 +54,7 @@ struct hio_devaddr_t
/* ========================================================================= */ /* ========================================================================= */
/* typedef struct hio_t hio_t;
* defined in hio-cmn.h
*typedef struct hio_t hio_t;
*/
typedef struct hio_dev_t hio_dev_t; typedef struct hio_dev_t hio_dev_t;
typedef struct hio_dev_mth_t hio_dev_mth_t; typedef struct hio_dev_mth_t hio_dev_mth_t;
typedef struct hio_dev_evcb_t hio_dev_evcb_t; typedef struct hio_dev_evcb_t hio_dev_evcb_t;
@ -770,7 +767,6 @@ struct hio_t
} xbuf; /* buffer to support sprintf */ } xbuf; /* buffer to support sprintf */
} sprintf; } sprintf;
hio_becs_t* becbuf; /* temporary buffer for some string manipulation */
hio_uint8_t bigbuf[65535]; /* TODO: make this dynamic depending on devices added. device may indicate a buffer size required??? */ hio_uint8_t bigbuf[65535]; /* TODO: make this dynamic depending on devices added. device may indicate a buffer size required??? */
hio_cfmb_t cfmb; /* list head of cfmbs */ hio_cfmb_t cfmb; /* list head of cfmbs */

View File

@ -732,8 +732,7 @@ static int fcgi_client_on_write (hio_dev_sck_t* sck, hio_iolen_t wrlen, void* wr
if (fcgi->peer && fcgi->num_pending_writes_to_client == FCGI_PENDING_IO_THRESHOLD_TO_CLIENT) if (fcgi->peer && fcgi->num_pending_writes_to_client == FCGI_PENDING_IO_THRESHOLD_TO_CLIENT)
{ {
#if 0 // TODO #if 0 // TODO
if (!(fcgi->over & FCGI_OVER_READ_FROM_PEER) && if (!(fcgi->over & FCGI_OVER_READ_FROM_PEER) && hio_svc_fcgic_read(fcgi->peer, 1) <= -1) goto oops;
hio_svc_fcgic_read(fcgi->peer, 1) <= -1) goto oops;
#endif #endif
} }
@ -767,33 +766,33 @@ static int peer_capture_request_header (hio_htre_t* req, const hio_bch_t* key, c
if (hio_comp_bcstr(key, "Content-Type", 1) == 0) if (hio_comp_bcstr(key, "Content-Type", 1) == 0)
{ {
/* don't prefix CONTENT_TYPE with HTTP_ */ /* don't prefix CONTENT_TYPE with HTTP_ */
hio_becs_clear (hio->becbuf); hio_becs_clear (htts->becbuf);
} }
else else
{ {
if (hio_becs_cpy(hio->becbuf, "HTTP_") == (hio_oow_t)-1) return -1; if (hio_becs_cpy(htts->becbuf, "HTTP_") == (hio_oow_t)-1) return -1;
} }
if (hio_becs_cat(hio->becbuf, key) == (hio_oow_t)-1 || if (hio_becs_cat(htts->becbuf, key) == (hio_oow_t)-1 ||
hio_becs_ccat(hio->becbuf, '\0') == (hio_oow_t)-1) return -1; hio_becs_ccat(htts->becbuf, '\0') == (hio_oow_t)-1) return -1;
for (ptr = HIO_BECS_PTR(hio->becbuf); *ptr; ptr++) for (ptr = HIO_BECS_PTR(htts->becbuf); *ptr; ptr++)
{ {
*ptr = hio_to_bch_upper(*ptr); *ptr = hio_to_bch_upper(*ptr);
if (*ptr =='-') *ptr = '_'; if (*ptr =='-') *ptr = '_';
} }
val_offset = HIO_BECS_LEN(hio->becbuf); val_offset = HIO_BECS_LEN(htts->becbuf);
if (hio_becs_cat(hio->becbuf, val->ptr) == (hio_oow_t)-1) return -1; if (hio_becs_cat(htts->becbuf, val->ptr) == (hio_oow_t)-1) return -1;
val = val->next; val = val->next;
while (val) while (val)
{ {
if (hio_becs_cat(hio->becbuf, ",") == (hio_oow_t)-1 || if (hio_becs_cat(htts->becbuf, ",") == (hio_oow_t)-1 ||
hio_becs_cat(hio->becbuf, val->ptr) == (hio_oow_t)-1) return -1; hio_becs_cat(htts->becbuf, val->ptr) == (hio_oow_t)-1) return -1;
val = val->next; val = val->next;
} }
hio_svc_fcgic_writeparam(fcgi->peer, HIO_BECS_PTR(hio->becbuf), val_offset - 1, HIO_BECS_CPTR(hio->becbuf, val_offset), HIO_BECS_LEN(hio->becbuf) - val_offset); hio_svc_fcgic_writeparam(fcgi->peer, HIO_BECS_PTR(htts->becbuf), val_offset - 1, HIO_BECS_CPTR(htts->becbuf, val_offset), HIO_BECS_LEN(htts->becbuf) - val_offset);
/* TODO: error handling? */ /* TODO: error handling? */
} }

View File

@ -78,6 +78,8 @@ struct hio_svc_htts_t
hio_bch_t* server_name; hio_bch_t* server_name;
hio_bch_t server_name_buf[64]; hio_bch_t server_name_buf[64];
hio_becs_t* becbuf; /* temporary buffer for any work */
int fcgic_tmout_set; int fcgic_tmout_set;
hio_svc_fcgic_tmout_t fcgic_tmout; hio_svc_fcgic_tmout_t fcgic_tmout;
}; };

View File

@ -364,6 +364,9 @@ hio_svc_htts_t* hio_svc_htts_start (hio_t* hio, hio_oow_t xtnsize, hio_dev_sck_b
htts->fcgic_tmout = *fcgic_tmout; htts->fcgic_tmout = *fcgic_tmout;
} }
htts->becbuf = hio_becs_open(hio, 0, 256);
if (HIO_UNLIKELY(!htts->becbuf)) goto oops;
htts->l.sck = (hio_dev_sck_t**)hio_callocmem(hio, HIO_SIZEOF(*htts->l.sck) * nbinds); htts->l.sck = (hio_dev_sck_t**)hio_callocmem(hio, HIO_SIZEOF(*htts->l.sck) * nbinds);
if (HIO_UNLIKELY(!htts->l.sck)) goto oops; if (HIO_UNLIKELY(!htts->l.sck)) goto oops;
htts->l.count = nbinds; htts->l.count = nbinds;
@ -515,6 +518,7 @@ oops:
hio_freemem (hio, htts->l.sck); hio_freemem (hio, htts->l.sck);
} }
if (htts->becbuf) hio_becs_close (htts->becbuf);
hio_freemem (hio, htts); hio_freemem (hio, htts);
} }
return HIO_NULL; return HIO_NULL;
@ -560,6 +564,7 @@ void hio_svc_htts_stop (hio_svc_htts_t* htts)
if (htts->l.sck) hio_freemem (hio, htts->l.sck); if (htts->l.sck) hio_freemem (hio, htts->l.sck);
if (htts->becbuf) hio_becs_close (htts->becbuf);
hio_freemem (hio, htts); hio_freemem (hio, htts);
HIO_DEBUG1 (hio, "HTTS - STOPPED SERVICE %p\n", htts); HIO_DEBUG1 (hio, "HTTS - STOPPED SERVICE %p\n", htts);