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

/* 17. MG_SIGNON - 채널 사인온 + 세션키 설정. */
void MG_SIGNON(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char chan[16], key[64];
    long stan;
    gets_(b, T_CHANNEL, chan, sizeof(chan)); if (chan[0] == 0) strcpy(chan, "CH01");
    gets_(b, T_KEY1, key, sizeof(key));      if (key[0] == 0) strcpy(key, "SESSION-KEY-DFLT");
    stan = mgdb_next_stan(); if (stan < 0) FAIL(b);
    if (mgdb_set_channel_session(chan, key, stan) < 0) FAIL(b);
    sets_(b, T_STATUS, "SIGNON");
    userlog("MG_SIGNON chan=%s stan=%ld", chan, stan);
    OK(b);
}
