renamed hcl to hak

This commit is contained in:
2025-09-02 23:58:15 +09:00
parent be77ac8ad2
commit 20d2db0e27
129 changed files with 43690 additions and 43689 deletions

View File

@ -22,37 +22,37 @@
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <hcl-x.h>
#include "hcl-prv.h"
#include <hak-x.h>
#include "hak-prv.h"
enum hcl_xproto_rcv_state_t
enum hak_xproto_rcv_state_t
{
HCL_XPROTO_RCV_HDR,
HCL_XPROTO_RCV_PLD
HAK_XPROTO_RCV_HDR,
HAK_XPROTO_RCV_PLD
};
typedef enum hcl_xproto_rcv_state_t hcl_xproto_rcv_state_t;
typedef enum hak_xproto_rcv_state_t hak_xproto_rcv_state_t;
struct hcl_xproto_t
struct hak_xproto_t
{
hcl_oow_t _instsize;
hcl_mmgr_t* _mmgr;
hcl_xproto_cb_t _cb;
hak_oow_t _instsize;
hak_mmgr_t* _mmgr;
hak_xproto_cb_t _cb;
struct
{
hcl_xproto_rcv_state_t state;
hcl_oow_t len_needed;
hak_xproto_rcv_state_t state;
hak_oow_t len_needed;
unsigned int eof: 1;
hcl_oow_t len;
hcl_uint8_t buf[HCL_XPKT_MAX_PLD_LEN];
hak_oow_t len;
hak_uint8_t buf[HAK_XPKT_MAX_PLD_LEN];
/* normalize header of hcl_xpkt_hdr_t with combined bits into separate placeholders */
/* normalize header of hak_xpkt_hdr_t with combined bits into separate placeholders */
struct
{
hcl_uint8_t id;
hcl_uint8_t type;
hcl_uint16_t len; /* this is wider than the len field of hcl_xpkt_hdr_t */
hak_uint8_t id;
hak_uint8_t type;
hak_uint16_t len; /* this is wider than the len field of hak_xpkt_hdr_t */
} hdr;
} rcv;
@ -62,84 +62,84 @@ struct hcl_xproto_t
} snd;
};
hcl_xproto_t* hcl_xproto_open (hcl_mmgr_t* mmgr, hcl_xproto_cb_t* cb, hcl_oow_t xtnsize)
hak_xproto_t* hak_xproto_open (hak_mmgr_t* mmgr, hak_xproto_cb_t* cb, hak_oow_t xtnsize)
{
hcl_xproto_t* proto;
hak_xproto_t* proto;
proto = (hcl_xproto_t*)HCL_MMGR_ALLOC(mmgr, HCL_SIZEOF(*proto) + xtnsize);
if (HCL_UNLIKELY(!proto)) return HCL_NULL;
proto = (hak_xproto_t*)HAK_MMGR_ALLOC(mmgr, HAK_SIZEOF(*proto) + xtnsize);
if (HAK_UNLIKELY(!proto)) return HAK_NULL;
HCL_MEMSET (proto, 0, HCL_SIZEOF(*proto));
proto->_instsize = HCL_SIZEOF(*proto);
HAK_MEMSET (proto, 0, HAK_SIZEOF(*proto));
proto->_instsize = HAK_SIZEOF(*proto);
proto->_mmgr = mmgr;
proto->_cb = *cb;
proto->rcv.state = HCL_XPROTO_RCV_HDR;
proto->rcv.len_needed = HCL_XPKT_HDR_LEN;
proto->rcv.state = HAK_XPROTO_RCV_HDR;
proto->rcv.len_needed = HAK_XPKT_HDR_LEN;
proto->rcv.eof = 0;
return proto;
}
void hcl_xproto_close (hcl_xproto_t* proto)
void hak_xproto_close (hak_xproto_t* proto)
{
HCL_MMGR_FREE (proto->_mmgr, proto);
HAK_MMGR_FREE (proto->_mmgr, proto);
}
void* hcl_xproto_getxtn (hcl_xproto_t* proto)
void* hak_xproto_getxtn (hak_xproto_t* proto)
{
return (proto + 1);
}
hcl_uint8_t* hcl_xproto_getbuf (hcl_xproto_t* proto, hcl_oow_t* capa)
hak_uint8_t* hak_xproto_getbuf (hak_xproto_t* proto, hak_oow_t* capa)
{
*capa = HCL_COUNTOF(proto->rcv.buf) - proto->rcv.len;
*capa = HAK_COUNTOF(proto->rcv.buf) - proto->rcv.len;
return &proto->rcv.buf[proto->rcv.len];
}
int hcl_xproto_geteof (hcl_xproto_t* proto)
int hak_xproto_geteof (hak_xproto_t* proto)
{
return proto->rcv.eof;
}
void hcl_xproto_seteof (hcl_xproto_t* proto, int v)
void hak_xproto_seteof (hak_xproto_t* proto, int v)
{
proto->rcv.eof = v;
}
void hcl_xproto_advbuf (hcl_xproto_t* proto, hcl_oow_t inc)
void hak_xproto_advbuf (hak_xproto_t* proto, hak_oow_t inc)
{
proto->rcv.len += inc;
}
int hcl_xproto_ready (hcl_xproto_t* proto)
int hak_xproto_ready (hak_xproto_t* proto)
{
/* has it received suffient data for processing? */
return proto->rcv.len >= proto->rcv.len_needed;
}
int hcl_xproto_process (hcl_xproto_t* proto)
int hak_xproto_process (hak_xproto_t* proto)
{
int n;
hcl_xpkt_hdr_t* hdr;
hak_xpkt_hdr_t* hdr;
switch (proto->rcv.state)
{
case HCL_XPROTO_RCV_HDR:
if (proto->rcv.len < HCL_XPKT_HDR_LEN) goto carry_on; /* need more data */
case HAK_XPROTO_RCV_HDR:
if (proto->rcv.len < HAK_XPKT_HDR_LEN) goto carry_on; /* need more data */
hdr = (hcl_xpkt_hdr_t*)proto->rcv.buf;
hdr = (hak_xpkt_hdr_t*)proto->rcv.buf;
proto->rcv.hdr.id = hdr->id;
proto->rcv.hdr.type = hdr->type & 0x0F;
proto->rcv.hdr.len = (hcl_uint16_t)hdr->len | ((hcl_uint16_t)(hdr->type >> 4) << 8);
proto->rcv.hdr.len = (hak_uint16_t)hdr->len | ((hak_uint16_t)(hdr->type >> 4) << 8);
/* consume the header */
HCL_MEMMOVE (proto->rcv.buf, &proto->rcv.buf[HCL_XPKT_HDR_LEN], proto->rcv.len - HCL_XPKT_HDR_LEN);
proto->rcv.len -= HCL_XPKT_HDR_LEN;
HAK_MEMMOVE (proto->rcv.buf, &proto->rcv.buf[HAK_XPKT_HDR_LEN], proto->rcv.len - HAK_XPKT_HDR_LEN);
proto->rcv.len -= HAK_XPKT_HDR_LEN;
/* switch to the payload mode */
if (proto->rcv.hdr.len > 0)
{
proto->rcv.state = HCL_XPROTO_RCV_PLD;
proto->rcv.state = HAK_XPROTO_RCV_PLD;
proto->rcv.len_needed = proto->rcv.hdr.len;
}
else
@ -153,7 +153,7 @@ int hcl_xproto_process (hcl_xproto_t* proto)
break;
case HCL_XPROTO_RCV_PLD:
case HAK_XPROTO_RCV_PLD:
if (proto->rcv.len < proto->rcv.hdr.len) goto carry_on; /* need more payload data */
n = proto->_cb.on_packet(proto, proto->rcv.hdr.type, proto->rcv.buf, proto->rcv.hdr.len);
@ -161,12 +161,12 @@ int hcl_xproto_process (hcl_xproto_t* proto)
/* switch to the header mode */
if (proto->rcv.hdr.len > 0)
{
/* TODO: minimize the use of HCL_MEMOVE... use the buffer */
HCL_MEMMOVE (proto->rcv.buf, &proto->rcv.buf[proto->rcv.hdr.len], proto->rcv.len - proto->rcv.hdr.len);
/* TODO: minimize the use of HAK_MEMOVE... use the buffer */
HAK_MEMMOVE (proto->rcv.buf, &proto->rcv.buf[proto->rcv.hdr.len], proto->rcv.len - proto->rcv.hdr.len);
proto->rcv.len -= proto->rcv.hdr.len;
}
proto->rcv.state = HCL_XPROTO_RCV_HDR;
proto->rcv.len_needed = HCL_XPKT_HDR_LEN;
proto->rcv.state = HAK_XPROTO_RCV_HDR;
proto->rcv.len_needed = HAK_XPKT_HDR_LEN;
if (n <= -1) goto fail_with_errmsg;
if (n == 0) return 0;
@ -175,7 +175,7 @@ int hcl_xproto_process (hcl_xproto_t* proto)
default:
/*
hcl_seterrbfmt (hcl, HCL_EINTERN, "invalid request state %d", (int)proto->rcv.state);
hak_seterrbfmt (hak, HAK_EINTERN, "invalid request state %d", (int)proto->rcv.state);
*/
/* TODO: call back */
goto fail_with_errmsg;
@ -186,8 +186,8 @@ carry_on:
fail_with_errmsg:
// TODO: proper error handling
//send_proto_hcl_error (proto);
//HCL_LOG1 (hcl, SERVER_LOGMASK_ERROR, "Unable to compile .SCRIPT contents - %js\n", hcl_geterrmsg(worker->hcl));
//send_proto_hak_error (proto);
//HAK_LOG1 (hak, SERVER_LOGMASK_ERROR, "Unable to compile .SCRIPT contents - %js\n", hak_geterrmsg(worker->hak));
return -1;
}