/*
 * MG_ROUTE.pgc - mg 모듈 서비스 MG_ROUTE (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_ROUTE.h"

/* 6. MG_ROUTE - 채널+전문유형 -> 목적지 라우팅 조회. */
void MG_ROUTE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char chan[16], mti[8], dest[64];
    gets_(b, T_CHANNEL, chan, sizeof(chan)); if (chan[0] == 0) strcpy(chan, "CH01");
    gets_(b, T_STR1, mti, sizeof(mti));      if (mti[0] == 0) strcpy(mti, "0200");
    if (mgdb_lookup_route(chan, mti, dest) < 0) {
        userlog("MG_ROUTE 라우팅 없음 chan=%s mti=%s", chan, mti);
        setl(b, T_RC, 1);
        FAIL(b);
    }
    sets_(b, T_STR3, dest);
    setl(b, T_RC, 0);
    OK(b);
}
