- dbio io(289): fetch/touch/total 시그니처 유지, SQL 바디를 JOIN/집계/커서/ upsert/DELETE 등 구조로 고유화 → 289/289 고유 - common cu(120): 유틸 시그니처 유지, Luhn/CRC/Zeller/BIN레인지/amortization/ netting 등 실 알고리즘으로 고유화 → 120/120 고유 - 심화: 실제 EXEC SQL 없던 프로그램에 SELECT/INSERT/UPDATE/커서+tx 추가 → online+batch 530/530 전부 실제 SQL 보유 - 전 코퍼스 프로그램 939/939 고유, 전체 docker make -j4 = EXIT 0, 958 오브젝트 - 임시 생성기 제거, inventory.json loc 실측 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
151 lines
5.4 KiB
Text
151 lines
5.4 KiB
Text
/* @tier medium @module mg @transform msg-gateway-online */
|
|
/*
|
|
* mg_ol_0013.pgc - 전문게이트웨이 채널별 어댑터 서비스 (MG_OL_0013) [tier=medium]
|
|
*
|
|
* 채널마다 상이한 수신 헤더 포맷을 표준공통헤더(STDHDR)로 정규화한다.
|
|
* 채널코드(CHAN)별 규칙은 in-code switch 로 분기하며, 각 채널이 자신의
|
|
* 헤더에 배치한 전문종별/전문길이/일시 오프셋을 표준 배열로 재배치한다.
|
|
* 표준헤더 = 전문종별(4) + 채널(3) + 전문길이(5) + 일시(14) = 26바이트.
|
|
*/
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
#include "txcore.h"
|
|
#include "txcore_dbio.h"
|
|
#include "acq_util.h"
|
|
#include "mg_core.h"
|
|
|
|
EXEC SQL INCLUDE sqlca;
|
|
|
|
/* 채널 어댑터 정규화 규칙 */
|
|
#define STD_HDR_LEN 26
|
|
|
|
TX_SERVICE(MG_OL_0013, ctx)
|
|
{
|
|
char raw[256];
|
|
char chan[8];
|
|
char stdhdr[STD_HDR_LEN + 1];
|
|
char mtype[FLD_MSG_TYPE_LEN + 1];
|
|
char yyyymmdd[9];
|
|
char hhmmss[7];
|
|
int rawlen;
|
|
int bodyoff;
|
|
int chan3;
|
|
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0013] 채널별 어댑터 서비스 진입");
|
|
|
|
rawlen = tx_buf_get(ctx->in, "RAWMSG", raw, sizeof(raw));
|
|
if (rawlen <= 0 ||
|
|
tx_buf_get(ctx->in, "CHAN", chan, sizeof(chan)) != TX_OK) {
|
|
tx_log(TX_LOG_ERROR, "[MG_OL_0013] 필수 필드 누락(RAWMSG/CHAN)");
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
rawlen = (int)strlen(raw);
|
|
|
|
/* 채널별 헤더 규격(mg_chan_hdr)에서 기대 본문 오프셋을 조회 (참고/교차검증) */
|
|
{
|
|
EXEC SQL BEGIN DECLARE SECTION;
|
|
char h_chan_code[8];
|
|
long h_hdr_bodyoff;
|
|
EXEC SQL END DECLARE SECTION;
|
|
|
|
strncpy(h_chan_code, chan, sizeof(h_chan_code) - 1);
|
|
h_chan_code[sizeof(h_chan_code) - 1] = '\0';
|
|
h_hdr_bodyoff = -1;
|
|
|
|
EXEC SQL SELECT body_offset
|
|
INTO :h_hdr_bodyoff
|
|
FROM mg_chan_hdr
|
|
WHERE chan_code = :h_chan_code;
|
|
if (sqlca.sqlcode == TX_SQL_OK)
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0013] 헤더규격 조회 chan=%s bodyoff=%ld",
|
|
chan, h_hdr_bodyoff);
|
|
else if (sqlca.sqlcode != TX_SQL_NOTFOUND)
|
|
TX_DBIO_LOG_ERR("SELECT mg_chan_hdr");
|
|
}
|
|
|
|
memset(mtype, 0, sizeof(mtype));
|
|
memset(yyyymmdd, 0, sizeof(yyyymmdd));
|
|
memset(hhmmss, 0, sizeof(hhmmss));
|
|
|
|
/* 채널별 헤더 규칙 분기: 각 채널이 필드를 서로 다른 오프셋에 둔다 */
|
|
if (strcmp(chan, "VAN") == 0) {
|
|
/* VAN(부가통신): [종별4][일시14][본문...] */
|
|
if (rawlen < 18) { bodyoff = -1; }
|
|
else {
|
|
memcpy(mtype, raw + 0, 4);
|
|
memcpy(yyyymmdd, raw + 4, 8);
|
|
memcpy(hhmmss, raw + 12, 6);
|
|
bodyoff = 18;
|
|
}
|
|
chan3 = 0;
|
|
} else if (strcmp(chan, "PGW") == 0) {
|
|
/* PGW(전자지불): [일시14][종별4][본문...] - 순서 반전 */
|
|
if (rawlen < 18) { bodyoff = -1; }
|
|
else {
|
|
memcpy(yyyymmdd, raw + 0, 8);
|
|
memcpy(hhmmss, raw + 8, 6);
|
|
memcpy(mtype, raw + 14, 4);
|
|
bodyoff = 18;
|
|
}
|
|
chan3 = 1;
|
|
} else if (strcmp(chan, "MPI") == 0) {
|
|
/* MPI(모바일): [종별4][채널프리픽스2][일시14][본문...] */
|
|
if (rawlen < 20) { bodyoff = -1; }
|
|
else {
|
|
memcpy(mtype, raw + 0, 4);
|
|
memcpy(yyyymmdd, raw + 6, 8);
|
|
memcpy(hhmmss, raw + 14, 6);
|
|
bodyoff = 20;
|
|
}
|
|
chan3 = 2;
|
|
} else {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0013] 미지원 채널코드 chan=%s", chan);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
|
|
tx_return(ctx, TX_EINVAL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
if (bodyoff < 0) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0013] 헤더 길이부족 chan=%s len=%d", chan, rawlen);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 종별 검증: 정규화 대상은 수신/응답/정산 전문만 허용 */
|
|
if (strncmp(mtype, MSG_TYPE_RECV, 4) != 0 &&
|
|
strncmp(mtype, MSG_TYPE_RESP, 4) != 0 &&
|
|
strncmp(mtype, MSG_TYPE_RECON, 4) != 0) {
|
|
tx_log(TX_LOG_WARN, "[MG_OL_0013] 전문종별 오류 chan=%s type=%.4s", chan, mtype);
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_INVALID);
|
|
tx_return(ctx, TX_FAIL, ctx->out);
|
|
return;
|
|
}
|
|
|
|
/* 표준공통헤더 재배치: 종별(4)+채널(3)+본문길이(5)+일자(8)+시각(6) */
|
|
memset(stdhdr, ' ', STD_HDR_LEN);
|
|
stdhdr[STD_HDR_LEN] = '\0';
|
|
memcpy(stdhdr + 0, mtype, 4);
|
|
memcpy(stdhdr + 4, chan, (strlen(chan) < 3) ? strlen(chan) : 3);
|
|
snprintf(stdhdr + 7, 6, "%05d", rawlen - bodyoff);
|
|
memcpy(stdhdr + 12, yyyymmdd, 8);
|
|
memcpy(stdhdr + 20, hhmmss, 6);
|
|
|
|
tx_buf_reset(ctx->out);
|
|
tx_buf_sets(ctx->out, "RESPCODE", RESP_OK);
|
|
tx_buf_sets(ctx->out, "STDHDR", stdhdr);
|
|
tx_buf_sets(ctx->out, "MSGTYPE", mtype);
|
|
tx_buf_sets(ctx->out, "TXNDATE", yyyymmdd);
|
|
tx_buf_sets(ctx->out, "TXNTIME", hhmmss);
|
|
tx_buf_sets(ctx->out, "BODY", raw + bodyoff);
|
|
tx_buf_setlong(ctx->out, "CHANIDX", (long)chan3);
|
|
tx_buf_setlong(ctx->out, "BODYLEN", (long)(rawlen - bodyoff));
|
|
tx_log(TX_LOG_INFO, "[MG_OL_0013] 정규화 완료 chan=%s type=%.4s bodylen=%d",
|
|
chan, mtype, rawlen - bodyoff);
|
|
tx_return(ctx, TX_OK, ctx->out);
|
|
}
|