/*
 * au_svr.pgc - au (승인/한도) MODULE SERVER (thin dispatcher).
 *
 * The legacy "one module server, many services" pattern: this binary owns NO
 * business logic. Each of au's ~30 online services now lives in its own file
 * (app/src/au/svc/<SVCNAME>.pgc) with its own copybook header
 * (app/src/au/svc/<SVCNAME>.h); those objects are archived into libausvc.a and
 * linked into this server. Here we only:
 *   - include every service copybook (for the extern prototypes),
 *   - tpopen() the ECPG XA RM,
 *   - tpadvertise() all services from a {name, fn} table,
 *   - tpclose() at shutdown.
 *
 * XA: the connection is opened once by tpopen() (ECPG XA switch libndrxxaecpg.so);
 * there is NO EXEC SQL CONNECT. Each tpcall runs on this process's XA branch.
 */
#include <atmi.h>
#include <ubf.h>
#include <userlog.h>

/* every au service's copybook header (declares its record struct + prototype) */
#include "AUTH.h"
#include "AUTH_CANCEL.h"
#include "AUTH_PARTCXL.h"
#include "LIMIT_CHK.h"
#include "LIMIT_DEC.h"
#include "LIMIT_RST.h"
#include "LIMIT_INQ.h"
#include "STANDIN.h"
#include "FRAUD_DETECT.h"
#include "AUTH_RETRY.h"
#include "INSTALL_AUTH.h"
#include "AUTH_STATUS.h"
#include "AUTH_REVERSE.h"
#include "AUTH_APPROVE.h"
#include "AUTH_DECLINE.h"
#include "CARD_VALIDATE.h"
#include "VELOCITY_CHK.h"
#include "BLACKLIST_CHK.h"
#include "AUTH_HOLD.h"
#include "AUTH_RELEASE.h"
#include "AUTH_HISTORY.h"
#include "LIMIT_SET.h"
#include "LIMIT_TEMP.h"
#include "AUTH_SUMMARY.h"
#include "AUTH_ROUTE.h"
#include "DCC_QUOTE.h"
#include "AUTH_CAPTURE.h"
#include "PREAUTH.h"
#include "PREAUTH_COMPLETE.h"
#include "AUTH_VOID.h"
#include "LIMIT_HIST.h"
#include "LIMIT_RESTORE.h"
#include "LIMIT_REMAIN.h"
#include "LIMIT_USAGE.h"
#include "LIMIT_RAISE_REQ.h"
#include "CARD_SUSPEND.h"
#include "CARD_RESUME.h"
#include "CARD_REISSUE.h"
#include "CARD_STATE_INQ.h"
#include "AUTH_PARTIAL.h"
#include "AUTH_RESEND.h"
#include "TOKEN_VERIFY.h"
#include "BIN_ROUTE_INQ.h"
#include "CANCEL_REPROC.h"
#include "CANCEL_STATUS.h"
#include "NOAUTH_CAPTURE.h"
#include "NIGHT_POLICY.h"
#include "OVERSEAS_POLICY.h"
#include "VELOCITY_HOUR.h"
#include "VELOCITY_WEEK.h"
#include "VELOCITY_MERCH.h"
#include "BLACKLIST_ADD.h"
#include "BLACKLIST_DEL.h"
#include "BLACKLIST_INQ.h"
#include "FRAUD_RULE_AMT.h"
#include "FRAUD_RULE_FREQ.h"
#include "FRAUD_RULE_DUP.h"
#include "FRAUD_CASE_INQ.h"
#include "AUTH_DELAY_MON.h"
#include "STANDIN_SETTLE.h"
#include "STANDIN_INQ.h"
#include "PREAUTH_EXTEND.h"
#include "PREAUTH_CANCEL.h"
#include "PREAUTH_INQ.h"
#include "STAT_HOURLY.h"
#include "STAT_BYTYPE.h"
#include "STAT_ISSUER.h"
#include "DECLINE_ANALYZE.h"
#include "AUTH_AMT_ADJUST.h"
#include "AUTH_EXPIRE_CHK.h"
#include "MERCH_AUTH_RANK.h"
#include "CARD_DAILY_RPT.h"
#include "RISK_SCORE_INQ.h"
#include "APPROVAL_RATE.h"
#include "AUTH_DUP_CHK.h"
/* --- scale-out services (승인/한도 심화) --- */
#include "LIMIT_MONTH_CHK.h"
#include "LIMIT_MONTH_INQ.h"
#include "LIMIT_PERTX_CHK.h"
#include "LIMIT_CUMUL_INQ.h"
#include "LIMIT_DAILY_INQ.h"
#include "LIMIT_ADJUST.h"
#include "LIMIT_FREEZE.h"
#include "LIMIT_UNFREEZE.h"
#include "LIMIT_TIER_INQ.h"
#include "LIMIT_OVER_ALERT.h"
#include "CARD_LOST_REG.h"
#include "CARD_STOLEN_REG.h"
#include "CARD_REACTIVATE.h"
#include "CARD_STATE_HIST.h"
#include "CARD_EXPIRE_CHK.h"
#include "CARD_ACTIVATE.h"
#include "CHANNEL_POLICY.h"
#include "BRAND_POLICY.h"
#include "MCC_POLICY.h"
#include "CHANNEL_STAT.h"
#include "BRAND_AUTH_STAT.h"
#include "MCC_AUTH_STAT.h"
#include "AUTH_PARTAPPR.h"
#include "PREAUTH_PARTUSE.h"
#include "CANCEL_AMT_INQ.h"
#include "CANCEL_FULL.h"
#include "CANCEL_HISTORY.h"
#include "CANCEL_SUMMARY.h"
#include "VELOCITY_DAY.h"
#include "VELOCITY_AMT.h"
#include "VELOCITY_MCC.h"
#include "VELOCITY_CHAN.h"
#include "VELOCITY_RESET.h"
#include "FRAUD_RULE_NIGHT.h"
#include "FRAUD_RULE_INTL.h"
#include "FRAUD_RULE_MCC.h"
#include "FRAUD_SCORE_SUM.h"
#include "FRAUD_CASE_CLOSE.h"
#include "FRAUD_CASE_LIST.h"
#include "WHITELIST_ADD.h"
#include "WHITELIST_DEL.h"
#include "WHITELIST_CHK.h"
#include "BLACKLIST_COUNT.h"
#include "BLACKLIST_PROMO.h"
#include "TOKEN_ISSUE.h"
#include "TOKEN_REVOKE.h"
#include "TOKEN_INQ.h"
#include "KEY_ROTATE_LOG.h"
#include "STANDIN_STAT.h"
#include "STANDIN_RECON.h"
#include "STANDIN_LIMIT.h"
#include "STAT_DECLINE.h"
#include "STAT_DAILY_SUM.h"
#include "STAT_AMT_BAND.h"
#include "STAT_APPROVE_TR.h"
#include "AUTH_REPROC_REQ.h"
#include "AUTH_REPROC_STAT.h"
#include "LIMIT_EXHAUST_LST.h"

/* ----- advertise table: {service name, function} (fn is extern from its file) */
static struct { const char *name; void (*fn)(TPSVCINFO *); } SVCS[] = {
    {"AUTH", AUTH},                 {"AUTH_CANCEL", AUTH_CANCEL},
    {"AUTH_PARTCXL", AUTH_PARTCXL}, {"LIMIT_CHK", LIMIT_CHK},
    {"LIMIT_DEC", LIMIT_DEC},       {"LIMIT_RST", LIMIT_RST},
    {"LIMIT_INQ", LIMIT_INQ},       {"STANDIN", STANDIN},
    {"FRAUD_DETECT", FRAUD_DETECT}, {"AUTH_RETRY", AUTH_RETRY},
    {"INSTALL_AUTH", INSTALL_AUTH}, {"AUTH_STATUS", AUTH_STATUS},
    {"AUTH_REVERSE", AUTH_REVERSE}, {"AUTH_APPROVE", AUTH_APPROVE},
    {"AUTH_DECLINE", AUTH_DECLINE}, {"CARD_VALIDATE", CARD_VALIDATE},
    {"VELOCITY_CHK", VELOCITY_CHK}, {"BLACKLIST_CHK", BLACKLIST_CHK},
    {"AUTH_HOLD", AUTH_HOLD},       {"AUTH_RELEASE", AUTH_RELEASE},
    {"AUTH_HISTORY", AUTH_HISTORY}, {"LIMIT_SET", LIMIT_SET},
    {"LIMIT_TEMP", LIMIT_TEMP},     {"AUTH_SUMMARY", AUTH_SUMMARY},
    {"AUTH_ROUTE", AUTH_ROUTE},     {"DCC_QUOTE", DCC_QUOTE},
    {"AUTH_CAPTURE", AUTH_CAPTURE}, {"PREAUTH", PREAUTH},
    {"PREAUTH_COMPLETE", PREAUTH_COMPLETE}, {"AUTH_VOID", AUTH_VOID},
    {"LIMIT_HIST", LIMIT_HIST},         {"LIMIT_RESTORE", LIMIT_RESTORE},
    {"LIMIT_REMAIN", LIMIT_REMAIN},     {"LIMIT_USAGE", LIMIT_USAGE},
    {"LIMIT_RAISE_REQ", LIMIT_RAISE_REQ}, {"CARD_SUSPEND", CARD_SUSPEND},
    {"CARD_RESUME", CARD_RESUME},       {"CARD_REISSUE", CARD_REISSUE},
    {"CARD_STATE_INQ", CARD_STATE_INQ}, {"AUTH_PARTIAL", AUTH_PARTIAL},
    {"AUTH_RESEND", AUTH_RESEND},       {"TOKEN_VERIFY", TOKEN_VERIFY},
    {"BIN_ROUTE_INQ", BIN_ROUTE_INQ},   {"CANCEL_REPROC", CANCEL_REPROC},
    {"CANCEL_STATUS", CANCEL_STATUS},   {"NOAUTH_CAPTURE", NOAUTH_CAPTURE},
    {"NIGHT_POLICY", NIGHT_POLICY},     {"OVERSEAS_POLICY", OVERSEAS_POLICY},
    {"VELOCITY_HOUR", VELOCITY_HOUR},   {"VELOCITY_WEEK", VELOCITY_WEEK},
    {"VELOCITY_MERCH", VELOCITY_MERCH}, {"BLACKLIST_ADD", BLACKLIST_ADD},
    {"BLACKLIST_DEL", BLACKLIST_DEL},   {"BLACKLIST_INQ", BLACKLIST_INQ},
    {"FRAUD_RULE_AMT", FRAUD_RULE_AMT}, {"FRAUD_RULE_FREQ", FRAUD_RULE_FREQ},
    {"FRAUD_RULE_DUP", FRAUD_RULE_DUP}, {"FRAUD_CASE_INQ", FRAUD_CASE_INQ},
    {"AUTH_DELAY_MON", AUTH_DELAY_MON}, {"STANDIN_SETTLE", STANDIN_SETTLE},
    {"STANDIN_INQ", STANDIN_INQ},       {"PREAUTH_EXTEND", PREAUTH_EXTEND},
    {"PREAUTH_CANCEL", PREAUTH_CANCEL}, {"PREAUTH_INQ", PREAUTH_INQ},
    {"STAT_HOURLY", STAT_HOURLY},       {"STAT_BYTYPE", STAT_BYTYPE},
    {"STAT_ISSUER", STAT_ISSUER},       {"DECLINE_ANALYZE", DECLINE_ANALYZE},
    {"AUTH_AMT_ADJUST", AUTH_AMT_ADJUST}, {"AUTH_EXPIRE_CHK", AUTH_EXPIRE_CHK},
    {"MERCH_AUTH_RANK", MERCH_AUTH_RANK}, {"CARD_DAILY_RPT", CARD_DAILY_RPT},
    {"RISK_SCORE_INQ", RISK_SCORE_INQ}, {"APPROVAL_RATE", APPROVAL_RATE},
    {"AUTH_DUP_CHK", AUTH_DUP_CHK},
    /* --- scale-out services (승인/한도 심화) --- */
    {"LIMIT_MONTH_CHK", LIMIT_MONTH_CHK}, {"LIMIT_MONTH_INQ", LIMIT_MONTH_INQ},
    {"LIMIT_PERTX_CHK", LIMIT_PERTX_CHK}, {"LIMIT_CUMUL_INQ", LIMIT_CUMUL_INQ},
    {"LIMIT_DAILY_INQ", LIMIT_DAILY_INQ}, {"LIMIT_ADJUST", LIMIT_ADJUST},
    {"LIMIT_FREEZE", LIMIT_FREEZE},       {"LIMIT_UNFREEZE", LIMIT_UNFREEZE},
    {"LIMIT_TIER_INQ", LIMIT_TIER_INQ},   {"LIMIT_OVER_ALERT", LIMIT_OVER_ALERT},
    {"CARD_LOST_REG", CARD_LOST_REG},     {"CARD_STOLEN_REG", CARD_STOLEN_REG},
    {"CARD_REACTIVATE", CARD_REACTIVATE}, {"CARD_STATE_HIST", CARD_STATE_HIST},
    {"CARD_EXPIRE_CHK", CARD_EXPIRE_CHK}, {"CARD_ACTIVATE", CARD_ACTIVATE},
    {"CHANNEL_POLICY", CHANNEL_POLICY},   {"BRAND_POLICY", BRAND_POLICY},
    {"MCC_POLICY", MCC_POLICY},           {"CHANNEL_STAT", CHANNEL_STAT},
    {"BRAND_AUTH_STAT", BRAND_AUTH_STAT}, {"MCC_AUTH_STAT", MCC_AUTH_STAT},
    {"AUTH_PARTAPPR", AUTH_PARTAPPR},     {"PREAUTH_PARTUSE", PREAUTH_PARTUSE},
    {"CANCEL_AMT_INQ", CANCEL_AMT_INQ},   {"CANCEL_FULL", CANCEL_FULL},
    {"CANCEL_HISTORY", CANCEL_HISTORY},   {"CANCEL_SUMMARY", CANCEL_SUMMARY},
    {"VELOCITY_DAY", VELOCITY_DAY},       {"VELOCITY_AMT", VELOCITY_AMT},
    {"VELOCITY_MCC", VELOCITY_MCC},       {"VELOCITY_CHAN", VELOCITY_CHAN},
    {"VELOCITY_RESET", VELOCITY_RESET},   {"FRAUD_RULE_NIGHT", FRAUD_RULE_NIGHT},
    {"FRAUD_RULE_INTL", FRAUD_RULE_INTL}, {"FRAUD_RULE_MCC", FRAUD_RULE_MCC},
    {"FRAUD_SCORE_SUM", FRAUD_SCORE_SUM}, {"FRAUD_CASE_CLOSE", FRAUD_CASE_CLOSE},
    {"FRAUD_CASE_LIST", FRAUD_CASE_LIST}, {"WHITELIST_ADD", WHITELIST_ADD},
    {"WHITELIST_DEL", WHITELIST_DEL},     {"WHITELIST_CHK", WHITELIST_CHK},
    {"BLACKLIST_COUNT", BLACKLIST_COUNT}, {"BLACKLIST_PROMO", BLACKLIST_PROMO},
    {"TOKEN_ISSUE", TOKEN_ISSUE},         {"TOKEN_REVOKE", TOKEN_REVOKE},
    {"TOKEN_INQ", TOKEN_INQ},             {"KEY_ROTATE_LOG", KEY_ROTATE_LOG},
    {"STANDIN_STAT", STANDIN_STAT},       {"STANDIN_RECON", STANDIN_RECON},
    {"STANDIN_LIMIT", STANDIN_LIMIT},     {"STAT_DECLINE", STAT_DECLINE},
    {"STAT_DAILY_SUM", STAT_DAILY_SUM},   {"STAT_AMT_BAND", STAT_AMT_BAND},
    {"STAT_APPROVE_TR", STAT_APPROVE_TR}, {"AUTH_REPROC_REQ", AUTH_REPROC_REQ},
    {"AUTH_REPROC_STAT", AUTH_REPROC_STAT}, {"LIMIT_EXHAUST_LST", LIMIT_EXHAUST_LST},
    {NULL, NULL}
};

int tpsvrinit(int argc, char **argv)
{
    int i;
    if (tpopen() < 0) {
        userlog("au_svr: tpopen FAIL: %s", tpstrerror(tperrno));
        return -1;
    }
    for (i = 0; SVCS[i].name != NULL; i++) {
        if (tpadvertise((char *)SVCS[i].name, SVCS[i].fn) < 0) {
            userlog("au_svr: tpadvertise(%s) FAIL: %s", SVCS[i].name, tpstrerror(tperrno));
            return -1;
        }
    }
    userlog("au_svr: %d au(승인/한도) 서비스 광고 완료, RM 오픈", i);
    return 0;
}

void tpsvrdone(void)
{
    tpclose();
    userlog("au_svr: tpsvrdone");
}

/* vim: set ts=4 sw=4 et smartindent: */
