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

/* 24. MG_QUEUE - 송신 큐 적재. */
void MG_QUEUE(TPSVCINFO *p)
{
    UBFH *b = (UBFH *)p->data;
    char chan[16], mti[8], raw[512], bizdate[16];
    long stan, qid;
    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");
    gets_(b, T_STR3, raw, sizeof(raw));
    gets_(b, T_BIZDATE, bizdate, sizeof(bizdate));
    stan = getl(b, T_ARG1);
    if (stan <= 0) { stan = mgdb_next_stan(); if (stan < 0) FAIL(b); }
    qid = mgdb_next_queue_id(); if (qid < 0) FAIL(b);
    if (mgdb_enqueue(qid, stan, chan, mti, raw, bizdate) < 0) FAIL(b);
    setl(b, T_ID2, qid);
    setl(b, T_ARG1, stan);
    OK(b);
}
