From f73bd64bc7226b3d1dfce1bd3655eada5bd57b9d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 9 Apr 2018 02:42:05 +0000 Subject: [PATCH] fixed missing short-form reply handling in lib/main-c.c --- lib/hcl-c.c | 4 ++++ lib/main-c.c | 32 +++++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/lib/hcl-c.c b/lib/hcl-c.c index 3524548..4a1c8a4 100644 --- a/lib/hcl-c.c +++ b/lib/hcl-c.c @@ -233,6 +233,7 @@ static HCL_INLINE int is_token_integer (hcl_client_t* client, hcl_oow_t* value) static HCL_INLINE hcl_ooch_t unescape (hcl_ooch_t c) { +#if 0 /* as of this writing, the server side only escapes \ and ". * i don't know if n, r, f, t, v should be supported here */ switch (c) @@ -244,6 +245,9 @@ static HCL_INLINE hcl_ooch_t unescape (hcl_ooch_t c) case 'v': return '\v'; default: return c; } +#else + return c; +#endif } static int handle_char (hcl_client_t* client, hcl_ooci_t c, hcl_oow_t nbytes) diff --git a/lib/main-c.c b/lib/main-c.c index 15a7b0e..08874d1 100644 --- a/lib/main-c.c +++ b/lib/main-c.c @@ -462,6 +462,8 @@ static int start_reply (hcl_client_t* client, hcl_client_reply_type_t type, cons hcl_bch_t bcs[256]; hcl_oow_t bcslen; + /* NOTE: the error may get truncated without looping */ + bcslen = HCL_COUNTOF(bcs); hcl_conv_uchars_to_bchars_with_cmgr (dptr, &dlen, bcs, &bcslen, hcl_client_getcmgr(client)); printf ("\nERROR - [%.*s]\n", (int)bcslen, bcs); #else @@ -470,8 +472,36 @@ static int start_reply (hcl_client_t* client, hcl_client_reply_type_t type, cons } else { - printf ("\nTOTAL DATA %lu bytes\n", (unsigned long int)client_xtn->data_length); + #if defined(HCL_OOCH_IS_UCH) + hcl_oow_t drem = dlen; + while (drem > 0) + { + hcl_bch_t bcs[256]; + hcl_oow_t ucslen, bcslen; + + ucslen = drem; + bcslen = HCL_COUNTOF(bcs); + hcl_conv_uchars_to_bchars_with_cmgr(dptr, &ucslen, bcs, &bcslen, hcl_client_getcmgr(client)); + client_xtn->data_length += bcslen; + if (write_all(0, bcs, bcslen) <= -1) + { + hcl_client_seterrbfmt (client, HCL_EIOERR, "unable to write data"); + return -1; + } + + drem -= ucslen; + dptr += ucslen; + } + #else + client_xtn->data_length += dlen; + if (write_all(0, dptr, dlen) <= -1) + { + hcl_client_seterrbfmt (client, HCL_EIOERR, "unable to write data"); + return -1; + } + #endif } + printf ("\nTOTAL DATA %lu bytes\n", (unsigned long int)client_xtn->data_length); /*fflush (stdout);*/ client_xtn->reply_count++;