- 템플릿 클론(정규화 후 0줄 상이) → 전 코퍼스 530/530 고유 바디 - 11개 모듈(mg/au/ac/rc/vl/st/py/lg/mm/cm/cl) 각 파일이 distinct한 매입·대사·정산·수수료·지급·원장·마감·마스터·정합성·전문게이트웨이·공통 업무 - TxCore(ATMI 유사) + ECPG(EXEC SQL) 관용구, 프레임워크/헤더/DBIO API/파일ID·경로 유지 - 전체 docker make -j4 = EXIT 0, 958 오브젝트, 데모 바이너리 링크 - inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
101 lines
3.2 KiB
Text
101 lines
3.2 KiB
Text
/* @tier medium @module mg @transform msg-gateway-online */
|
|
/*
|
|
* mg_ol_0028.pgc - 전문게이트웨이 BCD 인코딩 유틸 서비스 (MG_OL_0028) [tier=medium]
|
|
*
|
|
* 숫자 문자열(NUM)을 BCD(4bit packed, 2자리/1바이트)로 인코딩한다.
|
|
* 홀수 길이는 하위 니블을 0으로 패딩한다. 인코딩된 패킹길이와 hex 표현을
|
|
* 계산하여 응답한다. (순수 인코딩 로직 - DB 접근 없음)
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "txcore.h"
|
|
#include "acq_util.h"
|
|
#include "mg_core.h"
|
|
|
|
EXEC SQL INCLUDE sqlca;
|
|
|
|
#define MG_BCD_MAX 32
|
|
|
|
/* 숫자문자열 -> BCD packed. 성공 시 패킹 바이트수, 실패 시 -1 */
|
|
static int bcd_encode(const char *digits, int ndigit, unsigned char *out, int cap)
|
|
{
|
|
int i, packed = (ndigit + 1) / 2;
|
|
|
|
if (packed > cap)
|
|
return -1;
|
|
memset(out, 0, packed);
|
|
for (i = 0; i < ndigit; i++) {
|
|
unsigned char nib;
|
|
if (digits[i] < '0' || digits[i] > '9')
|
|
return -1;
|
|
nib = (unsigned char)(digits[i] - '0');
|
|
if ((i & 1) == 0)
|
|
out[i / 2] |= (unsigned char)(nib << 4); /* 상위 니블 */
|
|
else
|
|
out[i / 2] |= nib; /* 하위 니블 */
|
|
}
|
|
return packed;
|
|
}
|
|
|
|
/* packed 바이트열 -> hex 문자열 */
|
|
static void bcd_to_hex(const unsigned char *buf, int n, char *hex, int cap)
|
|
{
|
|
static const char HX[] = "0123456789ABCDEF";
|
|
int i, j = 0;
|
|
|
|
for (i = 0; i < n && j + 2 < cap; i++) {
|
|
hex[j++] = HX[(buf[i] >> 4) & 0x0f];
|
|
hex[j++] = HX[buf[i] & 0x0f];
|
|
}
|
|
hex[j] = '\0';
|
|
}
|
|
|
|
TX_SERVICE(MG_OL_0028, ctx)
|
|
{
|
|
char num[MG_BCD_MAX + 1];
|
|
char hex[MG_BCD_MAX * 2 + 1];
|
|
unsigned char packed[MG_BCD_MAX];
|
|
int ndigit, plen;
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0028] BCD 인코딩 유틸 서비스 진입");
|
|
|
|
/* 1) 인코딩 대상 숫자문자열 수신 */
|
|
if (tx_buf_get(ctx->in, "NUM", num, sizeof(num)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0028] 인코딩 대상(NUM) 누락");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
ndigit = (int)strlen(num);
|
|
if (ndigit == 0 || ndigit > MG_BCD_MAX * 2) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0028] 길이 범위 오류 len=%d", ndigit);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_INVALID);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 2) BCD 인코딩 */
|
|
plen = bcd_encode(num, ndigit, packed, sizeof(packed));
|
|
if (plen < 0) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0028] 비숫자 포함 인코딩 실패 num=%s", num);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_INVALID);
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 3) hex 표현 변환 */
|
|
bcd_to_hex(packed, plen, hex, sizeof(hex));
|
|
|
|
/* 4) 인코딩 결과 응답 */
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESP", RESP_OK);
|
|
tx_buf_setlong(ctx->out, "DIGITS", (long)ndigit);
|
|
tx_buf_setlong(ctx->out, "PACKLEN", (long)plen);
|
|
tx_buf_sets(ctx->out, "BCDHEX", hex);
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0028] 인코딩완료 자릿수=%d 패킹=%dbyte hex=%s",
|
|
ndigit, plen, hex);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|