📄 main.cpp
字号:
///////////////////////////////////////////////////////////////////////////////// IT24 SISTEMAS S.A.// Mapeo de Dialogo Princiapl//// Tarea Fecha Autor Observaciones// (Alfa) 2003.07.21 mdc Sistema BANCO INDUSTRIAL// (Beta) 2003.08.15 mdc Simulacion Prehomologador// (Beta) 2004.05.07 mdc Homologacion RED LINK// (Beta) 2004.07.02 mdc Argumentos obligatorios//#ifdef HAVE_CONFIG_H#include <config.h>#endif// Data Processing Center#include <qusrinc/dpciso.h>// Type definitions#include <qusrinc/typedefs.h>// Std Library#include <stdlib.h>#include <stdio.h>#include <string.h>// Header Local Settings#include <locale.h>// Header UNIX standard#include <unistd.h>// TimeOuts de norma ISO, segun configuracion propietaria#define _ISO8583_ECHO_TIMEOUT_ (71)// TimeOut general del DPC (ACCEPT - WRITE)// Se elije un TIMEOUT que es numero primo para no provocar// una secuencia que se superponga y a su vez sobrecargue los// ECHO - LOGON del HOST administrador, RED LINK#define _DPC_COMM_TIMEOUT_ (73)// Maximo de intentos de apertura fallidos ante los cuales debe enviarse un ALERTA#define _DPC_OPEN_RETRY_LIMIT_ (5)int main(int argc, char *argv[] ){ short m_checkLOGIN = TRUE; char *m_dpcSystem = NULL; char *m_hostFormat = NULL; long m_nTrxCounter = 0; short m_ReversalToSAF = FALSE; short m_checkINITCALL = TRUE; short shPortFSwitch = 0; char szAddressFSwitch[256] = { 0x00 }; short shPortBEnd = 0; char szAddressBEnd[256] = { 0x00 }; short shLen = 0; int iRetval = 0; time_t tCurrentTime = time( NULL ) , tLastEchoLogon = 0L; unsigned short nOpenRetries = 0; boolean_t bAlertMailSent = is_false; char szMailHost24User[] = "HOST24-PROCESS@nbia.com.ar"; char szMailAlertTo[] = "postmaster@nbia.com.ar"; char szMailUnavailMessage[] ="\r\nALERTA\r\n\r\n" "HOST24 SE HA CAIDO"; char szMailReadyMessage[] ="\r\nAVISO INFORMATIVO\r\n\r\n" "HOST24 YA ESTA DISPONIBLE"; char szMailSysFailureMessage[]="\r\nALERTA\r\n\r\n" "HOST24 DETECTO 'FALLA DEL SISTEMA' EN EL AUTORIZADOR" ; char szMailSmtpHost[] = "127.0.0.1"; BOOL bUseTCPPP = TRUE ; printf("HOST24-INDUSTRIAL: Host-2-Host con Red Link\r\n"); // Argumentos? if(argc <= 1) { printf("Uso : host24 <PORT-backend> <PORT-backend> <IP-interfase-ISO> <PORT-interfase>\r\n"); printf("Ejemplo : 'host24 S90test1 1234 10.2.0.94 10870'\r\n"); printf("donde : 'S90test1 1234' es el nombre y port del sistema interno\r\n"); printf(" : '10.2.0.94 10870' es la direccion y port de Red Link.\r\n"); exit(-1); } ////////////////////////////////////////////////////////////////////////////////////////////////// // Local Settings USA : decimal_point "." - thousand_point "," const char *szLocale = setlocale( LC_ALL, "LC_MONETARY=US;LC_NUMERIC=US;" ); const struct lconv *pstConv = localeconv(); if(pstConv && (strcmp(pstConv->decimal_point,".")!=0 || strcmp(pstConv->thousands_sep,",")!=0)) { printf("La configuracion local deberia ser DecimmalPoint:','\r\n"); } ////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////// // Carga de parametros por DEFAULT : PORT y ADDRESS, desde el dialogo de interface // FINANCIAL SWITCH (RED LINK, BANELCO, POSNET....) /////////////////////////////////////////////////////////////////////////////////// strcpy( szAddressBEnd , "S01desa1"); // AMBIENTE DE DESARROLLO BANCO INDUSTRIAL shPortBEnd = 1234; strcpy( szAddressBEnd , "S90test1"); // AMBIENTE DE TEST BANCO INDUSTRIAL shPortBEnd = 1234; strcpy( szAddressBEnd , "S00nbia1"); // AMBIENTE DE PRODUCCION BANCO INDUSTRIAL shPortBEnd = 1234; // AMBIENTE PARAMETRIZADO, IP y PORT? if(argc >= 3) { strcpy( szAddressBEnd, argv[1] ); // AMBIENTE PARAMETRIZADO, IP y PORT shPortBEnd = atoi( argv[2] ); } if( m_checkINITCALL) { strcpy( szAddressFSwitch, "127.0.0.1"); // SIMULACION LOCAL DESAROLLO-PREHOMO shPortFSwitch = 9999; strcpy( szAddressFSwitch, "10.2.0.94"); // CONEXION RED LINK TES1/CER1/PRO1 shPortFSwitch = 10870; // AMBIENTE PARAMETRIZADO, IP y PORT? if(argc == 5) { strcpy( szAddressFSwitch, argv[3] ); // AMBIENTE PARAMETRIZADO, IP y PORT shPortFSwitch = atoi( argv[4] ); } } else { strcpy( szAddressFSwitch, "127.0.0.1"); // SIMULACION LOCAL DESAROLLO-PREHOMO shPortFSwitch = 9999; }; ////////////////////////////////////////////////////////////////////////////////////////// // Desconectarse , aunque no este conectado... DPCDISCONNECT(); // Formato ISO8583 INDUSTRIAL (DEBUG, SIN IMPLEMENTAR EN PRODUCCION) DPCSETFORMAT( CNTL_FORMAT_ISO8583_INDUS ); // Mostrar el formato en el dialogo de la aplicacion m_hostFormat = "ISO8583_INDUSTRIAL"; // Mostrar Sistema compilado para esta aplicacion m_dpcSystem = (char *)DPCGETSYSTEMDEFINED(); printf("Formato de interface %s %s\r\n",m_hostFormat, m_dpcSystem); /////////////////////////////////////////////////////////// // Configurar direcciones IP y PORTS del Switch y Backend DPCSETCONFIG( szAddressFSwitch, shPortFSwitch, 0, bUseTCPPP, /* PP-protocol : 2-bytes-length */ _DPC_COMM_TIMEOUT_ , szAddressBEnd, shPortBEnd ); /////////////////////////////////////////////////////////// // Segun opcion de conexion INIT_CALL o WAIT_FOR_CALL printf("Conectando a %s:%i...\r\n",szAddressFSwitch,shPortFSwitch); if(m_checkINITCALL) // Conectar al Host-to-Host ISO8583, modo CLIENTE, con punto de conexion b.datos iRetval = DPCCONNECT( szAddressFSwitch, shPortFSwitch, /* open remote port */ 0, bUseTCPPP , /* PP-protocol : 2-bytes-length */ _DPC_COMM_TIMEOUT_ , NULL ); /* RPC connectivity data point */ else // Conectar al Host-to-Host ISO8583, modo CLIENTE, con punto de conexion b.datos iRetval = DPCCONNECT( szAddressFSwitch, 0, shPortFSwitch, /* wait in port */ bUseTCPPP , /* PP-protocol : 2-bytes-length */ _DPC_COMM_TIMEOUT_ * 2, NULL ); /* RPC connectivity data point */ /* READY OR UNAVAILABLE ? SHOW STATUS */ if(DPCGETSTATUS()==_HOST_UNAVAILABLE_) { printf("Sin poder conectarse\r\n"); /* UNAVAILABLE */ nOpenRetries++; if( nOpenRetries % _DPC_OPEN_RETRY_LIMIT_ == 0 || 1 == nOpenRetries) { bAlertMailSent = is_true; /* Notify */ DPCSMTPSENDMAIL(szMailHost24User, szMailAlertTo, szMailUnavailMessage, szMailSmtpHost, szMailSmtpHost ); }; } else { printf("Conectado OK\r\n"); /* READY */ DPCSETSTATUS( _HOST_READY_ ); /* Notify */ bAlertMailSent = is_false; DPCSMTPSENDMAIL(szMailHost24User, szMailAlertTo, szMailReadyMessage, szMailSmtpHost, szMailSmtpHost ); }; // Ciclo hasta que se haga logoff while ( m_checkLOGIN ) { // Timeout default N seg DPCSETTIMEOUT( _DPC_COMM_TIMEOUT_ ); // Mientras haya mensajes entrantes, procesarlos if( TCP4U_SUCCESS == iRetval || TCP4U_TIMEOUT == iRetval ) iRetval = DPCSTARTPROCESSING( is_false, is_true, ( m_ReversalToSAF ) ? is_true : is_false ); // Segun errores recibidos if( TCP4U_SOCKETCLOSED == iRetval || TCP4U_CONNECTFAILED == iRetval || TCP4U_ERROR == iRetval || TCP4U_HOSTUNKNOWN == iRetval || TCP4U_NOMORESOCKET == iRetval || TCP4U_NOMORERESOURCE == iRetval || TCP4U_BINDERROR == iRetval || TCP4U_CANCELLED == iRetval || TCP4U_INSMEMORY == iRetval || TCP4U_BADPORT == iRetval ) { iRetval = DPCDISCONNECT(); /* UNAVAILABLE - STOPPED */ DPCSETSTATUS( _HOST_UNAVAILABLE_ ); // Segun opcion de conexion INIT_CALL o WAIT_FOR_CALL if(m_checkINITCALL) // Conectar al Host-to-Host ISO8583, modo CLIENTE iRetval = DPCCONNECT( szAddressFSwitch, shPortFSwitch, /* direct port */ 0, bUseTCPPP, /* PP-protocol : 2-bytes-length */ _DPC_COMM_TIMEOUT_ , NULL ); /* RPC connectivity data point */ else // Conectar al Host-to-Host ISO8583, modo CLIENTE iRetval = DPCCONNECT( szAddressFSwitch, 0, shPortFSwitch, /* wait in port */ bUseTCPPP, /* PP-protocol : 2-bytes-length */ _DPC_COMM_TIMEOUT_ * 2, NULL ); /* RPC connectivity data point */ /* READY OR UNAVAILABLE ? SHOW STATUS */ if(DPCGETSTATUS()==_HOST_UNAVAILABLE_) { /* UNAVAILABLE */ nOpenRetries++; /* SEND ALERT MAIL ? */ if( nOpenRetries % _DPC_OPEN_RETRY_LIMIT_ == 0 ) { bAlertMailSent = is_true; DPCSMTPSENDMAIL(szMailHost24User, szMailAlertTo, szMailUnavailMessage, szMailSmtpHost, szMailSmtpHost ); }; } else { /* READY */ DPCSETSTATUS( _HOST_READY_ ); /* SEND OK MAIL ? */ if( is_true == bAlertMailSent ) { bAlertMailSent = is_false; DPCSMTPSENDMAIL(szMailHost24User, szMailAlertTo, szMailReadyMessage, szMailSmtpHost, szMailSmtpHost ); }; }; // End-READY-UNAVAIL }; // End-Segun errores recibidos.... //////////////////////////////////////////////////////////////////////// /* Verificar ultimos N segundos de inactividad */ if(time( NULL ) > (tLastEchoLogon+_ISO8583_ECHO_TIMEOUT_)) { tLastEchoLogon = time( NULL ); DPCSENDLOGON( CNTL_LOGON_REQUERIMENT ); } //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// // Contador de transacciones if(DPCGETTRXCOUNTER() != m_nTrxCounter) m_nTrxCounter = DPCGETTRXCOUNTER(); //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////// // Verificar estado del AUTORIZADOR y notificar ante SYSTEM FAILURE if ( DPCGETSTATUSBACKEND() != _HOST_READY_ ) { DPCSMTPSENDMAIL(szMailHost24User, szMailAlertTo, szMailSysFailureMessage, szMailSmtpHost, szMailSmtpHost ); DPCSETSTATUSBACKEND( _HOST_READY_ ) ; } else { }; //////////////////////////////////////////////////////////////////// }; /* end-while */ // Logoff final iRetval = DPCSENDLOGOFF() ; // Desconectarse DPCDISCONNECT(); // UNAVAILABLE - STOPPED DPCSETSTATUS( _HOST_STOPPED_ ); // OK return 0;};///////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -