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

/* 11. MG_CHANAUTH - 채널 인증: UP/SIGNON 상태만 통과. */
void MG_CHANAUTH(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char chan[16], st[16];
    gets_(b, T_CHANNEL, chan, sizeof(chan)); if (chan[0] == 0) strcpy(chan, "CH01");
    if (mgdb_get_channel_status(chan, st) < 0) { setl(b, T_RC, 2); FAIL(b); }
    if (strcmp(st, "UP") == 0 || strcmp(st, "SIGNON") == 0) {
        setl(b, T_RC, 0);
        sets_(b, T_STATUS, st);
        OK(b);
    }
    userlog("MG_CHANAUTH 거부 chan=%s status=%s", chan, st);
    setl(b, T_RC, 1);
    sets_(b, T_STATUS, st);
    FAIL(b);
}
