⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swi.c

📁 电信数字交换机用户数据联机下载入磁带程序
💻 C
📖 第 1 页 / 共 5 页
字号:
/* SWI.C : 用户数据管理系统交换机接口
   Jason Chen, 97.11.18
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <time.h>
#include "commsdms.h"
#include "swi.h"

/*=================== INI file variables ==================
   In order to convert string to value,
   all numeric INI variables must be long */
char   HostName[INI_LEN];
char   SWIPort[INI_LEN];                /* SWI service name */
char   OfficeFileName[INI_LEN];
char   NECG30UserName[INI_LEN];
long   TimeOut;                         /* Time out */
long   LOG;
long   TIDLen;
long   NECG30AutoConnTime;

struct SwitchStru *Switch;
struct SwitchStru *Sw;      // Current switch pointer
struct ExkStru    *Exk;
int    SwitchNum, SwPtr;
int    ExkNum, ExkPtr;

char   WarnHost[64];        // Warnning center client host name

char   SndBuff[512];
char   RcvBuff[MAX_TCP_STREAM_BUFFER+256];
char   LogBuff[MAX_TCP_STREAM_BUFFER+256];

time_t systime;

int    QUIT = 0;

void main(void)
{
char   Copywrite[]="SWI v1.0, Switch interface of Subscriber's Data Management System, Copywrite by Jason Chen, 1997.11";
int    i;
char   TcpNodeName[24], tmp[128];


/* 1. Initialize */
signal(SIGHUP,  SIG_IGN);
signal(SIGQUIT, Quit);
signal(SIGPIPE, SIG_IGN);
signal(SIGINT,  SIG_IGN);
signal(SIGTERM, SIG_IGN);

ReadINIFile();
ReadExkFile();
SetupTcp();

time(&systime);                     /* use for timer() */

while (!QUIT) {

    timer();

    /* Read tcp packet */
    if (SelectTcpStream(RcvBuff, TcpNodeName) == 1) {
       if (strlen(TcpNodeName) > 8) { /* >2 is request source */
            sprintf(LogBuff, "Rcv : %s\n", RcvBuff);
            LogInfo(LogBuff);
            AcceptRequestPacket(TcpNodeName);
            }
         else {
            sscanf(TcpNodeName, "%d", &SwPtr);
            if (Switch[SwPtr].Busy == 1) {
                strcat(Switch[SwPtr].RcvBuff, RcvBuff);
                Switch[SwPtr].Step[Switch[SwPtr].SP] ++;
                Switch[SwPtr].timer = 0;
                }
            }
       }

    /* Switch */
    /* step = SwitchType * 1000,000 + FunctionCode * 1000 */
    for (SwPtr=0; SwPtr<SwitchNum; SwPtr++) {
        Sw = Switch + SwPtr;

        // NECG30 Auto connect
        // if NECG30AutoConnTime == 0 then disable auto connect
        if (Sw->Busy == 0 && Sw->SwitchType == NECG30) {
            if (NECG30AutoConnTime != 0 && Sw->timer > NECG30AutoConnTime) {
                Sw->SP = 0;
                Go(3000000);
                Sw->Busy = 1;
                break;
                }
            }

        // 移机时, NewSw第一步为0
        if (Sw->Busy == 0 || Sw->Step[Sw->SP] < 10) continue;

        switch (Sw->Step[Sw->SP]) {
/* ======== Return result ======== */
            case 100:
                ReturnResult(Sw->ReqSrc, Sw->TID, Sw->ReturnCode, Sw->Para);
                if (Sw->Func == 7 && Sw->ReturnCode != 0) {
                    if (Sw->NewSw != NULL)
                        Sw->NewSw->Busy = 0;
                    }
                if (Sw->Connect == 0) {
                    if (Sw->ReturnCode != 4) {
                        Sw->DisconnectTimes = 0;
                        Sw->Connect = 1;
                        Send2Warn();
                        LogWarn();
                        }
                    }
                else {
                    if (Sw->ReturnCode == 4)
                        Sw->DisconnectTimes ++;
                    else
                        Sw->DisconnectTimes = 0;
                    if (Sw->DisconnectTimes >= 1) {
                        Sw->DisconnectTimes = 0;
                        Sw->Connect = 0;
                        Send2Warn();
                        LogWarn();
                        }
                    }
                Sw->Busy = 0;
                if (Sw->ReturnCode == 4) {
                    if (Sw->SwitchType == NECG30) {
                        Sw->SP = 0;
                        Go(3000000);
                        Sw->Busy = 1;
                        }
                    if (Sw->SwitchType == _5ESS) {
                        Sw->SP = 0;
                        Go(9000000);
                        Sw->Busy = 1;
                        }
                    }
                break;

/* ======== Wait switch return ======== */
/* When rcv data, the step will be +1 automaticly
   and timer = 0 */
            case 2000002:   //Login
            case 2000052:   //PSD
            case 2001002:   //New Line
            case 2002003:   //Remove
            case 2003002:   //Stop
            case 2005002:   //Restore
            case 2008002:   //ChangeDN
            case 2008005:
            case 2010004:   //NewSrv
            case 2010008:

            case 3001002:   //NewLine
            case 3002002:   //Remove
            case 3002005:
            case 3003002:   //Stop
            case 3004002:   //Pause
            case 3005002:   //Restore
            case 3005005:
            case 3006002:   //复活
            case 3008002:   //ChangeDN
            case 3008005:
            case 3010002:   //双音频
            case 3010012:   //长途
            case 3010022:   //热线服务
            case 3010032:   //呼叫等待
            case 3010042:   //三方通话
            case 3010052:   //呼叫转移
            case 3010062:   //闹钟
            case 3010072:   //遇忙转移
            case 3010082:   //遇忙回叫
            case 3010092:   //免打扰
            case 3010102:   //缺席
            case 3010112:   //缩位拨号
            case 3010122:   //追查恶意
            case 3010132:   //呼出限制
            case 3010142:   //反极性

            case 5000002:   //Login
            case 5000005:
            case 5000051:   //CHA SUB
            case 5001003:   //New Line
            case 5002003:   //Remove
            case 5003003:   //Stop
            case 5004003:   //Pause
            case 5005003:   //Restore
            case 5008002:   //Change DN
                            //New Srv
            case 5010003:   //0-双音频
            case 5010013:   //1-国际长途
            case 5010017:   //  国际长途PRI
            case 5010023:   //2-国内长途
            case 5010033:   //3-热线服务A
            case 5010043:   //4-热线服务B
            case 5010053:   //5-呼叫等待
            case 5010063:   //6-三方通话
            case 5010073:   //7-呼叫转移
            case 5010083:   //8-闹钟
            case 5010103:   //10-遇忙回叫
            case 5010113:   //11-免打扰
            case 5010123:   //12-缺席
            case 5010133:   //13-缩位拨号
            case 5010142:   //14-追查恶意
            case 5010153:   //15-呼出限制

            case 6000002:   //Login
            case 6000005:
            case 6000051:   //CHA SBS
            case 6001003:   //New Line
            case 6002003:   //Remove
            case 6003003:   //Stop
            case 6004003:   //Pause
            case 6005003:   //Restore
            case 6008002:   //ChangeDN
                            //NewSrv
            case 6010003:   //0-双音频
            case 6010013:   //1-国内长途
            case 6010023:   //2-国际长途
            case 6010033:   //3-热线服务A
            case 6010043:   //4-热线服务B
            case 6010053:   //5-呼叫等待
            case 6010063:   //6-三方通话
            case 6010073:   //7-呼叫转移
            case 6010083:   //8-闹钟
            case 6010093:   //9-遇忙转移
            case 6010103:   //10-遇忙回叫
            case 6010113:   //11-免打扰
            case 6010123:   //12-缺席
            case 6010133:   //13-缩位拨号
            case 6010142:   //14-追查恶意
            case 6010153:   //15-呼出限制
            case 6010157:
            case 6010902:   //DIS TIP

            case 9001001:   //NewLine
            case 9001100:
            case 9002001:   //Remove
            case 9002002:
            case 9002005:
            case 9002100:
            case 9003001:   //Stop
            case 9003100:
            case 9005001:   //Restore
            case 9005100:
            case 9008001:   //ChangeDN
            case 9008002:
            case 9008100:
            case 9010001:   //NewSrv1
            case 9010100:
            case 9010011:   //Read Newsrv, read 1st '<'
            case 9010013:   // read 2nd '<'
            case 9010014:   // read 3rd '<'
            case 9010016:   //NewSrv2
            case 9010102:
            case 9010018:   //Call restrict command2
            case 9010104:
            case 9200100:   //CIL
            case 9200003:
                if (Sw->timer > TimeOut) {
                    Sw->ReturnCode = 4;
                    strcpy(Sw->Para, "");
                    Go(100);
                    }
                break;


/* ======== NEC Login ======== */
            case 2000000:   // Delay
                if (Sw->timer >= NECDELAY) Go(2000001);
                break;

            case 2000001:
                strcpy(SndBuff, "<");
                Send2Switch();
                ChangeETX(Sw->TcpNodeName, "<  ");
                strcpy(Sw->RcvBuff, "");
                Go(2000002);
                break;

            case 2000003:
                sprintf(LogBuff, "Rcv from %s: %s\n", Sw->Office, Sw->RcvBuff);
                LogInfo(LogBuff);
                Sw->ReturnCode = 0;
                ChangeETX(Sw->TcpNodeName, "");
                Go(2000004);
                break;

            case 2000004:   // Delay
                if (Sw->timer >= NECDELAY) Rtn();
                break;

/* ======== NEC PSD ======== */
            case 2000050:
                GoSub(2000000);
                break;

            case 2000051:
                sprintf(SndBuff, "PSD:N=%s;", Sw->Tel);
                Send2Switch();
                strcpy(Sw->RcvBuff, "");
                Go(2000052);
                break;

            case 2000053:
                if (GetPacketNEC() == 1) {
                    sprintf(LogBuff, "Rcv from %s: %s\n", Sw->Office, Sw->RcvBuff);
                    LogInfo(LogBuff);
                    NECMapErrCommon();
                    if (Sw->ReturnCode == 0 && Sw->SP > 0)
                        Rtn();
                    else {
                        strcpy(Sw->Para, "");
                        Go(100);
                        }
                    }
                else
                    Go(2000052);
                break;

/* ======== NEC New Line ======== */
            case 2001000:
                GoSub(2000000);
                break;

            case 2001001:
                GetPara(Sw->Para, "LL=", tmp, 30);
                sprintf(SndBuff, "SOD:NEW,N=%s,EL=%s,LC=101010,", Sw->Tel, tmp);
                if (Sw->NewSrv[TOLL_CALL] == '1')
                    strcat(SndBuff, "RC=003;");
                else
                    strcat(SndBuff, "RC=002;");
                Send2Switch();
                strcpy(Sw->RcvBuff, "");
                Go(2001002);
                break;

            case 2001003:
                if (GetPacketNEC() == 1) {
                    sprintf(LogBuff, "Rcv from %s: %s\n", Sw->Office, Sw->RcvBuff);
                    LogInfo(LogBuff);
                    NECMapErrNEW();
                    if (Sw->ReturnCode == 0) {
                    	Sw->NewSrv[DTMF] = '-';
                    	//Sw->NewSrv[INT_CALL] = '-';
                    	Sw->NewSrv[TOLL_CALL] = '-';
                        GoSub(2010002);     // Go NewSrv
                        }
                    else {
                        strcpy(Sw->Para, "");
                        Go(100);
                        }
                    }
                else
                    Go(2001002);
                break;

            case 2001004:
                Sw->ReturnCode = 0;
                if (Sw->SP > 0)
                    Rtn();
                else {
                    strcpy(Sw->Para, "");
                    Go(100);
                    }
                break;

/* ======== NEC Remove ======== */
            case 2002000:
                GoSub(2000050);     //PSD, get EL
                break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -