/* @tier easy @module mg @transform msg-gateway-online */ /* * mg_ol_0027.pgc - 전문게이트웨이 전문 길이 검증 서비스 (MG_OL_0027) [tier=easy] * * LLLL(선두 4자리 길이 prefix) 프레이밍 규약에 따라, 전문 앞 4바이트에 * 선언된 길이와 실제 본문 길이가 일치하는지 검증한다. 길이 prefix가 * 숫자가 아니거나 선언길이 != 실제길이면 반려한다. * (순수 검증 로직 - DB 접근 없음) */ #include #include #include "txcore.h" #include "txcore_dbio.h" #include "acq_util.h" #include "mg_core.h" EXEC SQL INCLUDE sqlca; #define MG_LEN_PREFIX 4 TX_SERVICE(MG_OL_0027, ctx) { char raw[512]; int rawlen, declared, actual, i; tx_log(TX_LOG_INFO, "[MG_OL_0027] 전문 길이 검증 서비스 진입"); /* 1) 원시전문 수신 (LLLL + 본문) */ rawlen = tx_buf_get(ctx->in, "RAWMSG", raw, sizeof(raw)); if (rawlen <= 0) { tx_log(TX_LOG_ERROR, "[MG_OL_0027] 원시전문(RAWMSG) 누락"); tx_return(ctx, TX_EINVAL, ctx->out); return; } /* 2) 최소 길이(프레임 헤더) 확인 */ actual = (int)strlen(raw); if (actual < MG_LEN_PREFIX) { tx_log(TX_LOG_WARN, "[MG_OL_0027] 프레임 헤더 부족 len=%d", actual); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESP", RESP_INVALID); tx_return(ctx, TX_EINVAL, ctx->out); return; } /* 3) 길이 prefix 숫자 검증 */ for (i = 0; i < MG_LEN_PREFIX; i++) { if (raw[i] < '0' || raw[i] > '9') { tx_log(TX_LOG_WARN, "[MG_OL_0027] 길이 prefix 비숫자 pos=%d", i); tx_buf_reset(ctx->out); tx_buf_sets(ctx->out, "RESP", RESP_INVALID); tx_return(ctx, TX_FAIL, ctx->out); return; } } /* 4) 선언길이 vs 실제 본문길이 비교 */ declared = (raw[0] - '0') * 1000 + (raw[1] - '0') * 100 + (raw[2] - '0') * 10 + (raw[3] - '0'); actual -= MG_LEN_PREFIX; /* 본문 실제 길이 */ tx_buf_reset(ctx->out); tx_buf_setlong(ctx->out, "DECLARED", (long)declared); tx_buf_setlong(ctx->out, "ACTUAL", (long)actual); if (declared != actual) { tx_log(TX_LOG_WARN, "[MG_OL_0027] 길이 불일치 선언=%d 실제=%d", declared, actual); tx_buf_sets(ctx->out, "RESP", RESP_INVALID); tx_buf_sets(ctx->out, "MATCH", "N"); tx_return(ctx, TX_FAIL, ctx->out); return; } tx_buf_sets(ctx->out, "RESP", RESP_OK); tx_buf_sets(ctx->out, "MATCH", "Y"); /* 프레이밍 길이검증 통과 이력(mg_frame_log)을 임베디드 SQL 로 적재 */ { EXEC SQL BEGIN DECLARE SECTION; long h_fr_decl; long h_fr_actual; EXEC SQL END DECLARE SECTION; h_fr_decl = (long)declared; h_fr_actual = (long)actual; if (tx_begin() == TX_OK) { EXEC SQL INSERT INTO mg_frame_log (decl_len, actual_len, match_yn) VALUES (:h_fr_decl, :h_fr_actual, 'Y'); if (sqlca.sqlcode != TX_SQL_OK) { TX_DBIO_LOG_ERR("INSERT mg_frame_log"); tx_abort(); } else { tx_commit(); } } } tx_log(TX_LOG_INFO, "[MG_OL_0027] 길이 일치 len=%d", declared); tx_return(ctx, TX_OK, ctx->out); }