From 39ab9d03204281c4ac1dde8843cdec7958a1690b Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Sat, 27 Sep 2014 15:22:08 +0000 Subject: [PATCH] * changed the QSE_NWAD_LOCAL address format. it must be prefixed with @. * fixed conversion error of a QSE_NWAD_LOCAL address to a string --- qse/cmd/http/ursd.c | 6 ++++ qse/include/qse/cmn/nwad.h | 4 ++- qse/lib/cmn/nwad.c | 57 ++++++++++++++++++++++++-------------- 3 files changed, 45 insertions(+), 22 deletions(-) diff --git a/qse/cmd/http/ursd.c b/qse/cmd/http/ursd.c index cd92b25b..343fa940 100644 --- a/qse/cmd/http/ursd.c +++ b/qse/cmd/http/ursd.c @@ -229,6 +229,12 @@ static qse_sck_hnd_t open_server_socket (int proto, const qse_nwad_t* bindnwad) goto oops; } + else + { + qse_char_t buf[512]; + qse_nwadtostr (bindnwad, buf, QSE_COUNTOF(buf), QSE_NWADTOSTR_ALL); + qse_printf (QSE_T("binding address: %s\n"), buf); + } bind_ok: #if defined(IPPROTO_SCTP) diff --git a/qse/include/qse/cmn/nwad.h b/qse/include/qse/cmn/nwad.h index 6966ce70..6aa5c834 100644 --- a/qse/include/qse/cmn/nwad.h +++ b/qse/include/qse/cmn/nwad.h @@ -36,6 +36,8 @@ typedef enum qse_nwad_type_t qse_nwad_type_t; typedef struct qse_nwad_t qse_nwad_t; +#define QSE_NWAD_LOCAL_MAX_PATH 128 + struct qse_nwad_t { qse_nwad_type_t type; @@ -61,7 +63,7 @@ struct qse_nwad_t /* note: 128 is chosen based on common path length in existing * systems. most systems have different sizes. some * trailers may get truncated, when itconverted to skad. */ - qse_char_t path[128]; + qse_char_t path[QSE_NWAD_LOCAL_MAX_PATH]; } local; } u; }; diff --git a/qse/lib/cmn/nwad.c b/qse/lib/cmn/nwad.c index 82ae5109..16276a15 100644 --- a/qse/lib/cmn/nwad.c +++ b/qse/lib/cmn/nwad.c @@ -109,15 +109,15 @@ int qse_mbsntonwad (const qse_mchar_t* str, qse_size_t len, qse_nwad_t* nwad) if (p >= end) return -1; - if (*p == QSE_MT('/')) + if (*p == QSE_MT('@') && len >= 2) { - /* support the absolute path only */ + /* the string begins with @. it's a local name */ #if defined(QSE_CHAR_IS_MCHAR) - qse_mbsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), str, len); + qse_mbsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), p + 1, len - 1); #else - qse_size_t mbslen = len; + qse_size_t mbslen = len - 1; qse_size_t wcslen = QSE_COUNTOF(tmpad.u.local.path) - 1; - if (qse_mbsntowcsn (str, &mbslen, tmpad.u.local.path, &wcslen) <= -1) return -1; + if (qse_mbsntowcsn (p + 1, &mbslen, tmpad.u.local.path, &wcslen) <= -1) return -1; tmpad.u.local.path[wcslen] = QSE_WT('\0'); #endif @@ -291,20 +291,19 @@ int qse_wcsntonwad (const qse_wchar_t* str, qse_size_t len, qse_nwad_t* nwad) if (p >= end) return -1; - if (*p == QSE_WT('/')) + if (*p == QSE_WT('@') && len >= 2) { - /* support the absolute path only */ + /* the string begins with @. it's a local name */ #if defined(QSE_CHAR_IS_MCHAR) - qse_size_t wcslen = len; + qse_size_t wcslen = len - 1; qse_size_t mbslen = QSE_COUNTOF(tmpad.u.local.path) - 1; - if (qse_wcsntombsn (str, &wcslen, tmpad.u.local.path, &mbslen) <= -1) return -1; + if (qse_wcsntombsn (p + 1, &wcslen, tmpad.u.local.path, &mbslen) <= -1) return -1; tmpad.u.local.path[mbslen] = QSE_MT('\0'); #else - qse_wcsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), str, len); + qse_wcsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), p + 1, len - 1); #endif tmpad.type = QSE_NWAD_LOCAL; - qse_wcsxncpy (tmpad.u.local.path, QSE_COUNTOF(tmpad.u.local.path), str, len); goto done; } @@ -558,13 +557,21 @@ qse_size_t qse_nwadtombs ( case QSE_NWAD_LOCAL: if (flags & QSE_NWADTOMBS_ADDR) { + if (xlen + 1 >= len) goto done; + buf[xlen++] = QSE_MT('@'); + #if defined(QSE_CHAR_IS_MCHAR) - xlen = qse_mbsxcpy (buf, len, nwad->u.local.path) + if (xlen + 1 >= len) goto done; + xlen += qse_mbsxcpy (&buf[xlen], len - xlen, nwad->u.local.path) #else - qse_size_t wcslen, mbslen = len; - qse_wcstombs (nwad->u.local.path, &wcslen, buf, &mbslen); - /* i don't care about conversion errors */ - xlen = mbslen; + if (xlen + 1 >= len) goto done; + else + { + qse_size_t wcslen, mbslen = len - xlen; + qse_wcstombs (nwad->u.local.path, &wcslen, &buf[xlen], &mbslen); + /* i don't care about conversion errors */ + xlen += mbslen; + } #endif } @@ -679,13 +686,21 @@ qse_size_t qse_nwadtowcs ( case QSE_NWAD_LOCAL: if (flags & QSE_NWADTOMBS_ADDR) { + if (xlen + 1 >= len) goto done; + buf[xlen++] = QSE_WT('@'); + #if defined(QSE_CHAR_IS_MCHAR) - qse_size_t wcslen = len, mbslen; - qse_mbstowcs (nwad->u.local.path, &mbslen, buf, &wcslen); - /* i don't care about conversion errors */ - xlen = wcslen; + if (xlen + 1 >= len) goto done; + else + { + qse_size_t wcslen = len - xlen, mbslen; + qse_mbstowcs (nwad->u.local.path, &mbslen, &buf[xlen], &wcslen); + /* i don't care about conversion errors */ + xlen += wcslen; + } #else - xlen = qse_wcsxcpy (buf, len, nwad->u.local.path); + if (xlen + 1 >= len) goto done; + xlen += qse_wcsxcpy (&buf[xlen], len - xlen, nwad->u.local.path); #endif } }