/*
 * MG_ECHO.pgc - mg 모듈 서비스 MG_ECHO (one service = one file).
 * Split out of the former inline mg_svr.pgc; runs on the caller's XA
 * branch (no EXEC SQL CONNECT). Advertised by mg_svr at tpsvrinit.
 */
#include "MG_ECHO.h"

/* 15. MG_ECHO - 에코 전문(0800) 처리 + 채널 UP 표시. */
void MG_ECHO(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char chan[16], bizdate[16];
    long stan, msg_id;
    gets_(b, T_CHANNEL, chan, sizeof(chan)); if (chan[0] == 0) strcpy(chan, "CH01");
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));

    stan = mgdb_next_stan();       if (stan < 0) FAIL(b);
    msg_id = mgdb_next_msg_id();   if (msg_id < 0) FAIL(b);
    if (mgdb_insert_msg(msg_id, stan, "0800", chan, "IN", "990000", "", 0,
                        "", "00", "ECHO-TEST", "A", bizdate) < 0) FAIL(b);
    if (mgdb_set_channel_status(chan, "UP") < 0) FAIL(b);
    setl(b, T_ID1, msg_id);
    sets_(b, T_STATUS, "UP");
    OK(b);
}
