summaryrefslogtreecommitdiffstats
path: root/data/mnet/GP10/Host/ViperBase
diff options
context:
space:
mode:
Diffstat (limited to 'data/mnet/GP10/Host/ViperBase')
-rw-r--r--data/mnet/GP10/Host/ViperBase/admin.c2267
-rw-r--r--data/mnet/GP10/Host/ViperBase/admin.h210
-rw-r--r--data/mnet/GP10/Host/ViperBase/exchange.c240
-rw-r--r--data/mnet/GP10/Host/ViperBase/exchange.h144
-rw-r--r--data/mnet/GP10/Host/ViperBase/gateways.txt4
-rw-r--r--data/mnet/GP10/Host/ViperBase/hlr.txt17
-rw-r--r--data/mnet/GP10/Host/ViperBase/init.c203
-rw-r--r--data/mnet/GP10/Host/ViperBase/init.h26
-rw-r--r--data/mnet/GP10/Host/ViperBase/ipphones.txt11
-rw-r--r--data/mnet/GP10/Host/ViperBase/jccall.c246
-rw-r--r--data/mnet/GP10/Host/ViperBase/jccall.h45
-rw-r--r--data/mnet/GP10/Host/ViperBase/jcras.c523
-rw-r--r--data/mnet/GP10/Host/ViperBase/jcras.h45
-rw-r--r--data/mnet/GP10/Host/ViperBase/jcvbase.datbin0 -> 1444 bytes
-rw-r--r--data/mnet/GP10/Host/ViperBase/main.c46
-rw-r--r--data/mnet/GP10/Host/ViperBase/platform.c692
-rw-r--r--data/mnet/GP10/Host/ViperBase/support.c615
-rw-r--r--data/mnet/GP10/Host/ViperBase/support.h188
18 files changed, 5522 insertions, 0 deletions
diff --git a/data/mnet/GP10/Host/ViperBase/admin.c b/data/mnet/GP10/Host/ViperBase/admin.c
new file mode 100644
index 0000000..d445843
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/admin.c
@@ -0,0 +1,2267 @@
+/* admin.c
+ *
+ */
+
+#include <gkadd.h>
+#include <gkrgi.h>
+#include <gklrqi.h>
+#include <gkstorage.h>
+#include <cfgapi.h>
+#include <li.h>
+
+#include <SubscInfoType.h>
+
+#include "support.h"
+#include "exchange.h"
+#include "admin.h"
+#include "jcras.h"
+#include "init.h"
+
+static char pszEndpointPrintSpec[] = "%19s %6s %22s %22s %6s\n";
+
+PJCCONFIG pCfgTree;
+
+static char pszDelims[] = "\\/, ";
+static char pszFieldSeparator[] = ", ";
+static char pszLineSeparator[] = "\r\n";
+static char pszDefaultDataFile[] = "jcvbase.dat";
+static char pszDataFileHeader[] = "JetCell ViperBase Main Data File";
+
+/*
+ *
+ */
+BOOL EndpointsPrint( void )
+{
+ gkHREG hReg;
+ gkHAPPREG haReg;
+
+ StringPrint( "\n" );
+ StringPrint( pszEndpointPrintSpec,
+ "H323 ID", "Phone", "RAS Address", "Q.931 Address", "Online" );
+ StringPrint( " ------------------------------------------------------------------------------\n" );
+
+ switch( gkrgiGetFirstEntryHandle( &hReg, &haReg ) )
+ {
+ case GKRGI_OK:
+ break;
+
+ case GKRGI_NOT_FOUND:
+ StringPrint( "There are no endpoints to show...\n" );
+ return TRUE;
+
+ default:
+ DebugLog( "Error in gkrgiGetFirstEntryHandle()\n" );
+ return FALSE;
+ }
+
+ do
+ {
+ EndpointPrint( hReg );
+
+ }while( GKRGI_OK == gkrgiGetNextEntryHandle( hReg, &hReg, &haReg ) );
+
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL EndpointPrint( gkHREG hReg )
+{
+ gkrgiParameterStatus_t nRegStatus;
+ gkaddName_t Name; /* array */
+ gkaddPhone_t Phone; /* array */
+ gkaddTransport_t TransRAS, TransQ931;
+ char pszRAS[32], pszQ931[32];
+ int i, nPhones;
+
+ if( GKRGI_OK != gkrgiMsgPending( hReg ) && !RegIsDynamic( hReg ) && !RegIsStatic( hReg ) )
+ return TRUE;
+
+ nRegStatus = RegIsDynamic( hReg ) ? gkrgiSttsDynamic : gkrgiSttsStatic;
+
+ gkrgiGetParameter( hReg, gkrgiParamName, nRegStatus, 1, Name );
+
+ gkrgiGetNumberOfAddresses( hReg, gkrgiParamPhone, nRegStatus, &nPhones );
+
+ if( nPhones == 1 )
+ gkrgiGetParameter( hReg, gkrgiParamPhone, nRegStatus, 1, Phone );
+ else
+ strcpy( Phone, ( nPhones < 1 ) ? "none" : "many" );
+
+ gkrgiGetParameter( hReg, gkrgiParamCallSignal, nRegStatus, 1, &TransQ931 );
+ gkrgiGetParameter( hReg, gkrgiParamRAS, nRegStatus, 1, &TransRAS );
+
+ StringPrint( pszEndpointPrintSpec,
+ Name,
+ Phone,
+ TransAddrToString( &TransRAS, pszRAS ),
+ TransAddrToString( &TransQ931, pszQ931 ),
+ RegIsDynamic( hReg ) ? "yes" : "no" );
+
+ if( nPhones > 1 )
+ {
+ for( i = 1; i <= nPhones; i++ )
+ {
+ gkrgiGetParameter( hReg, gkrgiParamPhone, nRegStatus, i, Phone );
+ StringPrint( ( i % 15 == 0 ) ? " %s\n" : " %s", Phone );
+ }
+
+ StringPrint( "\n" );
+ }
+
+/*
+ nDataSize = 64;
+
+ if( GKRGI_OK == gkrgiGetAppMemblock( hReg, &nDataSize, pszMobileUserData ) )
+ StringPrint( "\t%s\n", pszMobileUserData );
+*/
+ return TRUE;
+}
+
+/*
+ *
+ */
+char* TransAddrToString( gkaddTransport_t* pTransAddr, char* Buffer )
+{
+ char buf[16];
+
+ sprintf( Buffer, "%s:%d", gkaddIp2String( pTransAddr->ip, buf ), pTransAddr->port );
+
+ return Buffer;
+}
+
+/*
+ *
+ */
+BOOL MobileAdd( char* pszIMSI, char* pszNumber, char* pszComment,
+ USHORT nProfileSize, void* ProfileData, char* pszResult )
+{
+ PJCMOBILE pMobile;
+
+ if( pszIMSI == NULL || pszNumber == NULL )
+ {
+ strcpy( pszResult, "Some parameters are not specified" );
+ return FALSE;
+ }
+
+ if( MobileFindByIMSI( pszIMSI, NULL ) )
+ {
+ strcpy( pszResult, "Another mobile exists with the same IMSI" );
+ return FALSE;
+ }
+
+ if( jcNumberExists( pszNumber ) )
+ {
+ strcpy( pszResult, "Another entity exists with the same number" );
+ return FALSE;
+ }
+
+ DebugLog( "Adding mobile '%s', extension '%s'\n", pszIMSI, pszNumber );
+
+ pMobile = New( JCMOBILE );
+ pMobile->pszIMSI = StringCreate( pszIMSI );
+ pMobile->pszNumber = StringCreate( pszNumber );
+ pMobile->pszComment = StringCreate( pszComment );
+
+ if( ( pMobile->nProfileSize = nProfileSize ) == 0 )
+ pMobile->ProfileData = NULL;
+ else
+ {
+ pMobile->ProfileData = SpecialAlloc( nProfileSize );
+ memcpy( pMobile->ProfileData, ProfileData, nProfileSize );
+ }
+
+ pMobile->hReg = NULL;
+ pMobile->hMobileCell = 0;
+
+ ListAddTail( pCfgTree->pListMobiles, pMobile );
+
+ sprintf( pszResult, "Mobile '%s' added", pszIMSI );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL MobileDelete( PJCMOBILE pMobile, PNODE pNode, char* pszResult )
+{
+
+ ListRemoveNode( pCfgTree->pListMobiles, pNode );
+
+ if( pMobile->hReg != NULL )
+ {
+ gkrgiDeleteAddress( pMobile->hReg, gkrgiParamPhone, gkrgiSttsDynamic, pMobile->pszNumber );
+ jcgkNonStdRasSendURQ( pMobile->hReg, pMobile );
+ }
+
+ StringDelete( pMobile->pszIMSI );
+ StringDelete( pMobile->pszNumber );
+ StringDelete( pMobile->pszComment );
+
+ SpecialFree( pMobile->ProfileData );
+
+ Delete( pMobile );
+
+ strcpy( pszResult, "Mobile deleted" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL IpPhoneDelete( PJCIPPHONE pIPPhone, PNODE pNode, char* pszResult )
+{
+
+ ListRemoveNode( pCfgTree->pListIPPhones, pNode );
+
+ StringDelete( pIPPhone->pszName );
+ StringDelete( pIPPhone->pszNumber );
+ StringDelete( pIPPhone->pszIPAddress );
+ StringDelete( pIPPhone->pszComment );
+ Delete( pIPPhone );
+
+ strcpy( pszResult, "IP phone deleted" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL MobilesImport( char* pszFile, char* pszResult )
+{
+ FILE* pfd;
+ char pszLine[80], pszIMSI[80], pszNumber[80];
+
+ if( NULL == pszFile )
+ {
+ strcpy( pszResult, "No filename specified" );
+ return FALSE;
+ }
+
+ if( NULL == ( pfd = fopen( pszFile, "rt" ) ) )
+ {
+ sprintf( pszResult, "Error opening file '%s'", pszFile );
+ return FALSE;
+ }
+
+ while( fgets( pszLine, 80, pfd ) )
+ if( 2 == sscanf( pszLine, " %s %s ", pszIMSI, pszNumber ) )
+ MobileAdd( pszIMSI, pszNumber, NULL, 0, NULL, pszResult );
+
+ fclose( pfd );
+
+ strcpy( pszResult, "Mobiles import completed" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+PJCMOBILE MobileFindByIMSI( char* pszIMSI, PNODE* ppNode )
+{
+ PNODE pNode;
+ PJCMOBILE pMobile;
+
+ ListForEachNode( pCfgTree->pListMobiles, pNode )
+ {
+ pMobile = (PJCMOBILE)NodeGetPtr( pNode );
+
+ if( 0 == StringCompare( pMobile->pszIMSI, pszIMSI ) )
+ {
+ if( ppNode ) *ppNode = pNode;
+ return pMobile;
+ }
+ }
+
+ if( ppNode ) *ppNode = NULL;
+ return NULL;
+}
+
+/*
+ *
+ */
+PJCIPPHONE IpPhoneFindByName( char* pszName, PNODE* ppNode )
+{
+ PNODE pNode;
+ PJCIPPHONE pIPPhone;
+
+ ListForEachNode( pCfgTree->pListIPPhones, pNode )
+ {
+ pIPPhone = (PJCIPPHONE)NodeGetPtr( pNode );
+
+ if( 0 == StringCompare( pIPPhone->pszName, pszName ) )
+ {
+ if( ppNode ) *ppNode = pNode;
+ return pIPPhone;
+ }
+ }
+
+ if( ppNode ) *ppNode = NULL;
+ return NULL;
+}
+
+/*
+ *
+ */
+PJCIPPHONE IpPhoneFindByNumber( char* pszNumber )
+{
+ PNODE pNode;
+ PJCIPPHONE pIPPhone;
+
+ ListForEachNode( pCfgTree->pListIPPhones, pNode )
+ {
+ pIPPhone = (PJCIPPHONE)NodeGetPtr( pNode );
+
+ if( 0 == StringCompare( pIPPhone->pszNumber, pszNumber ) )
+ return pIPPhone;
+ }
+
+ return NULL;
+}
+
+/*
+ *
+ */
+PJCGATEWAY jcGatewayFindByName( char* pszName, PNODE* ppNode )
+{
+ PNODE pNode;
+ PJCGATEWAY pGateway;
+
+ ListForEachNode( pCfgTree->pListGateways, pNode )
+ {
+ pGateway = (PJCGATEWAY)NodeGetPtr( pNode );
+
+ if( 0 == StringCompare( pGateway->pszName, pszName ) )
+ {
+ if( ppNode ) *ppNode = pNode;
+ return pGateway;
+ }
+ }
+
+ if( ppNode ) *ppNode = NULL;
+ return NULL;
+}
+
+/*
+ *
+ */
+PJCGATEWAY jcGatewayFindByAddress( UINT32 ip, PNODE* ppNode )
+{
+ PNODE pNode;
+ PJCGATEWAY pGateway;
+ char buf[16];
+
+ gkaddIp2String( ip, buf );
+
+ ListForEachNode( pCfgTree->pListGateways, pNode )
+ {
+ pGateway = (PJCGATEWAY)NodeGetPtr( pNode );
+
+ if( 0 == StringCompare( pGateway->pszIPAddress, buf ) )
+ {
+ if( ppNode ) *ppNode = pNode;
+ return pGateway;
+ }
+ }
+
+ if( ppNode ) *ppNode = NULL;
+ return NULL;
+}
+
+/*
+ *
+ */
+PJCGATEWAY jcGatewayFindByNumber( char* Number )
+{
+ PNODE pNode;
+ PJCGATEWAY pGateway;
+
+ if( NULL == Number || Number[0] == '\0' )
+ return NULL;
+
+ ListForEachNode( pCfgTree->pListGateways, pNode )
+ {
+ pGateway = (PJCGATEWAY)NodeGetPtr( pNode );
+
+ if( 0 == strncmp( Number, pGateway->pszPrefix, pGateway->nPrefixSize ) )
+ return pGateway;
+ }
+
+ return NULL;
+}
+
+/*
+ *
+ */
+PJCMOBILE MobileFindByNumber( char* pszNumber )
+{
+ PNODE pNode;
+ PJCMOBILE pMobile;
+
+ ListForEachNode( pCfgTree->pListMobiles, pNode )
+ {
+ pMobile = (PJCMOBILE)NodeGetPtr( pNode );
+
+ if( 0 == StringCompare( pMobile->pszNumber, pszNumber ) )
+ return pMobile;
+ }
+
+ return NULL;
+}
+
+/*
+ *
+ */
+BOOL IpPhonesImport( char* pszFile, char* pszResult )
+{
+ FILE* pfd;
+ char pszLine[80], pszName[80], pszNumber[80], pszQ931Address[80];
+
+ if( NULL == pszFile )
+ {
+ strcpy( pszResult, "No filename specified" );
+ return FALSE;
+ }
+
+ if( NULL == ( pfd = fopen( pszFile, "rt" ) ) )
+ {
+ sprintf( pszResult, "Error opening file '%s'", pszFile );
+ return FALSE;
+ }
+
+ while( fgets( pszLine, 80, pfd ) )
+ if( 3 == sscanf( pszLine, " %s %s %s ", pszName, pszNumber, pszQ931Address ) )
+ IpPhoneAdd( pszName, pszNumber, pszQ931Address, NULL, pszResult );
+
+ fclose( pfd );
+
+ strcpy( pszResult, "IP phones import completed" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcGatewaysImport( char* pszFile, char* pszResult )
+{
+ FILE* pfd;
+ char pszLine[80], pszName[80], pszPrefix[80], pszQ931Address[80];
+
+ if( NULL == pszFile )
+ {
+ strcpy( pszResult, "No filename specified" );
+ return FALSE;
+ }
+
+ if( NULL == ( pfd = fopen( pszFile, "rt" ) ) )
+ {
+ sprintf( pszResult, "Error opening file '%s'", pszFile );
+ return FALSE;
+ }
+
+ while( fgets( pszLine, 80, pfd ) )
+ if( 3 == sscanf( pszLine, " %s %s %s ", pszName, pszPrefix, pszQ931Address ) )
+ jcGatewayAdd( pszName, pszPrefix, pszQ931Address, FALSE, NULL, pszResult );
+
+ fclose( pfd );
+
+ strcpy( pszResult, "Gateways import completed" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL IpPhoneAdd( char* pszName, char* pszNumber, char* pszQ931Address,
+ char* pszComment, char* pszResult )
+{
+ PJCIPPHONE pIpPhone;
+
+ if( pszName == NULL || pszNumber == NULL || pszQ931Address == NULL )
+ {
+ strcpy( pszResult, "Some parameters are not specified" );
+ return FALSE;
+ }
+
+ if( IpPhoneFindByName( pszName, NULL ) )
+ {
+ strcpy( pszResult, "Another IP phone exists with the same name" );
+ return FALSE;
+ }
+
+ if( jcNumberExists( pszNumber ) )
+ {
+ strcpy( pszResult, "Another entity exists with the same number" );
+ return FALSE;
+ }
+
+ DebugLog( "Adding IP phone '%s', number '%s', address '%s'\n",
+ pszName, pszNumber, pszQ931Address );
+
+ pIpPhone = New( JCIPPHONE );
+ pIpPhone->pszName = StringCreate( pszName );
+ pIpPhone->pszNumber = StringCreate( pszNumber );
+ pIpPhone->pszIPAddress = StringCreate( pszQ931Address );
+ pIpPhone->pszComment = StringCreate( pszComment );
+
+ ListAddTail( pCfgTree->pListIPPhones, pIpPhone );
+
+ sprintf( pszResult, "IP phone '%s' added", pszName );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcGatewayAdd( char* pszName, char* pszPrefix, char* pszIPAddress,
+ BOOL bStripPrefix, char* pszComment, char* pszResult )
+{
+ PJCGATEWAY pGateway;
+
+ if( pszName == NULL || pszPrefix == NULL || pszIPAddress == NULL )
+ {
+ strcpy( pszResult, "Some parameters are not specified" );
+ return FALSE;
+ }
+
+ if( jcGatewayFindByName( pszName, NULL ) )
+ {
+ strcpy( pszResult, "Another gateway exists with the same name" );
+ return FALSE;
+ }
+
+ if( jcGatewayFindByNumber( pszPrefix ) )
+ {
+ strcpy( pszResult, "Another gateway exists with the same prefix" );
+ return FALSE;
+ }
+
+ DebugLog( "Adding gateway '%s', prefix '%s', address '%s'\n", pszName, pszPrefix, pszIPAddress );
+
+ pGateway = New( JCGATEWAY );
+ pGateway->pszName = StringCreate( pszName );
+ pGateway->pszPrefix = StringCreate( pszPrefix );
+ pGateway->nPrefixSize = strlen( pszPrefix );
+ pGateway->pszIPAddress = StringCreate( pszIPAddress );
+ pGateway->bStripPrefix = bStripPrefix;
+ pGateway->pszComment = StringCreate( pszComment );
+
+ ListAddTail( pCfgTree->pListGateways, pGateway );
+
+ sprintf( pszResult, "Gateway '%s' added", pszName );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcGatewayDelete( PJCGATEWAY pGateway, PNODE pNode, char* pszResult )
+{
+
+ ListRemoveNode( pCfgTree->pListGateways, pNode );
+
+ StringDelete( pGateway->pszName );
+ StringDelete( pGateway->pszPrefix );
+ StringDelete( pGateway->pszIPAddress );
+ StringDelete( pGateway->pszComment );
+
+ Delete( pGateway );
+
+ strcpy( pszResult, "Gateway deleted" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+void MngmCmdCallBack( pMngmCommandData_t pData )
+{
+ static JCNAMEDPROC Commands[] = {
+ "Add", MngmCmdAdd,
+ "Delete", MngmCmdDelete,
+ "Set", MngmCmdSet,
+ "Get", MngmCmdGet,
+ "Show", MngmCmdGet,
+ "Save", MngmCmdSave,
+ "Import", MngmCmdImport,
+ NULL, NULL
+ };
+
+ char *pszCommand, *pszParams;
+
+ if( NULL == ( pszCommand = StringToken( pData->pszInput, pszDelims, &pszParams ) ) )
+ {
+ strcpy( pData->pszOutput, "No command specified" );
+ pData->nOutput = FALSE;
+ return;
+ }
+
+ pData->nOutput = jcProcCallByName( pszCommand, Commands, 0, pszParams, NULL, pData->pszOutput );
+ return;
+}
+
+/*
+ *
+ */
+int jcProcCallByName( char* pszName, JCNAMEDPROC* pProcArray,
+ int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ for( ; pProcArray->pszProc; pProcArray++ )
+ {
+ if( 0 == StringICompare( pszName, pProcArray->pszProc ) )
+ return (*pProcArray->pfnProc)( nParam, pszParam, pParam, pszResult );
+ }
+
+ sprintf( pszResult, "Can't recognize '%s'", pszName );
+ return FALSE;
+}
+
+/*
+ *
+ */
+int MngmCmdNotImplemented( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ strcpy( pszResult, "This command is not implemented" );
+ return FALSE;
+}
+
+/*
+ *
+ */
+int MngmCmdNoValue( char* pszResult )
+{
+ strcpy( pszResult, "The value is not specified" );
+ return FALSE;
+}
+
+/*
+ *
+ */
+int MngmCmdValueSetOK( char* pszResult )
+{
+ strcpy( pszResult, "The value was changed" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+int MngmCmdAdd( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ return MngmCmdRootObjs( jcMngmCmdAdd, pszParam, pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdDelete( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ return MngmCmdRootObjs( jcMngmCmdDelete, pszParam, pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdSet( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ return MngmCmdRootObjs( jcMngmCmdSet, pszParam, pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdGet( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ return MngmCmdRootObjs( jcMngmCmdGet, pszParam, pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdImport( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ return MngmCmdRootObjs( jcMngmCmdImport, pszParam, pszResult );
+}
+
+/*
+ * finds the object in configuration tree by path, calls appropriate function
+ */
+int MngmCmdRootObjs( int nCommand, char* pszParam, char* pszResult )
+{
+ static JCNAMEDPROC RootObjs[] = {
+ "MaxCalls", MngmCmdMaxCalls,
+ "RASPort", MngmCmdRASPort,
+ "Q931Port", MngmCmdQ931Port,
+ "RASResponseTimeout", MngmCmdRASResponseTimeout,
+ "Q931ResponseTimeout", MngmCmdQ931ResponseTimeout,
+ "Q931ConnectTimeout", MngmCmdQ931ConnectTimeout,
+ "GatekeeperID", MngmCmdGatekeeperID,
+ "TelnetPort", MngmCmdTelnetPort,
+ "IVRNumber", MngmCmdIVRNumber,
+ "IPPhones", MngmCmdIpPhones,
+ "Gateways", MngmCmdGateways,
+ "Mobiles", MngmCmdMobiles,
+ "ViperCells", MngmCmdViperCells,
+ NULL, NULL };
+
+ char *pszObjName;
+
+ if( NULL == ( pszObjName = StringToken( NULL, pszDelims, &pszParam ) ) )
+ {
+ strcpy( pszResult, "No configuration object specified" );
+ return FALSE;
+ }
+ else
+ return jcProcCallByName( pszObjName, RootObjs, nCommand, pszParam, NULL, pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdMaxCalls( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->nMaxCalls, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->nMaxCalls, 1, 200, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdRASPort( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->RASPort, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->RASPort, 1025, 65535, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdQ931Port( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->Q931Port, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->Q931Port, 1025, 65535, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdRASResponseTimeout( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->RASResponseTO, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->RASResponseTO, 5, 360, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdQ931ResponseTimeout( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->Q931ResponseTO, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->Q931ResponseTO, 5, 360, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdQ931ConnectTimeout( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->Q931ConnectTO, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->Q931ConnectTO, 5, 360, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdTelnetPort( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdIntGet( pCfgTree->TelnetPort, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdIntSet( &pCfgTree->TelnetPort, 1025, 65535, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGatekeeperID( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pCfgTree->pszGatekeeperID, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdStringSet( &pCfgTree->pszGatekeeperID, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdIVRNumber( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pCfgTree->pszIVRNumber, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszNumber;
+
+ if( NULL != ( pszNumber = StringToken( NULL, pszDelims, &pszParam ) ) &&
+ jcNumberExists( pszNumber ) )
+ {
+ strcpy( pszResult, "Another entity exists with the same number" );
+ return FALSE;
+ }
+
+ StringReplace( &pCfgTree->pszIVRNumber, pszNumber ); /* NULL is OK */
+
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdIntGet( int nSource, char* pszResult )
+{
+ sprintf( pszResult, "%d", nSource );
+ return TRUE;
+}
+
+/*
+ *
+ */
+int MngmCmdIntSet( int* pnTarget, int nMin, int nMax, char* pszParam, char* pszResult )
+{
+ int nValue;
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ nValue = atoi( pszValue );
+
+ if( nValue < nMin || nValue > nMax )
+ {
+ sprintf( pszResult, "The value is out of valid range (%d...%d)", nMin, nMax );
+ return FALSE;
+ }
+
+ *pnTarget = nValue;
+
+ return MngmCmdValueSetOK( pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdStringGet( char* pszSource, char* pszResult )
+{
+ if( pszSource )
+ {
+ strcpy( pszResult, pszSource );
+ return TRUE;
+ }
+ else
+ {
+ strcpy( pszResult, "<no current value>" );
+ return FALSE;
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdStringSet( char** ppszTarget, char* pszParam, char* pszResult )
+{
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ StringReplace( ppszTarget, pszValue );
+
+ return MngmCmdValueSetOK( pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdMobiles( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ char *pszIMSI, *pszNumber, *pszComment;
+ PNODE pNode;
+ char buf[128];
+
+ pszIMSI = StringToken( NULL, pszDelims, &pszParam );
+
+ switch( nCommand )
+ {
+ case jcMngmCmdAdd:
+ pszNumber = StringToken( NULL, pszDelims, &pszParam );
+ pszComment = StringToken( NULL, pszDelims, &pszParam );
+ return MobileAdd( pszIMSI, pszNumber, pszComment, 0, NULL, pszResult );
+
+ case jcMngmCmdGet:
+ if( pszIMSI == NULL ) /* mobiles list */
+ {
+ pszResult[0] = '\0';
+
+ ListForEachNode( pCfgTree->pListMobiles, pNode )
+ {
+ MngmCmdMobileGetAllParams( (PJCMOBILE)NodeGetPtr( pNode ), buf );
+ strcat( pszResult, buf );
+ strcat( pszResult, pszLineSeparator );
+ }
+
+ return TRUE;
+ }
+ else
+ return MngmCmdMobile( pszIMSI, nCommand, pszParam, pszResult );
+
+ case jcMngmCmdDelete:
+ case jcMngmCmdSet:
+ if( pszIMSI == NULL )
+ {
+ strcpy( pszResult, "No IMSI specified for the mobile" );
+ return FALSE;
+ }
+ else
+ return MngmCmdMobile( pszIMSI, nCommand, pszParam, pszResult );
+
+ case jcMngmCmdImport:
+ return MobilesImport( pszIMSI /* pszIMSI has filename in this case */, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdMobile( char* pszIMSI, int nCommand, char* pszParam, char* pszResult )
+{
+ static JCNAMEDPROC MobileObjs[] = {
+ "IMSI", MngmCmdMobileIMSI,
+ /* "Number", MngmCmdMobileNumber, blocked to avoid inconsistency with profile */
+ "Comment", MngmCmdMobileComment,
+ NULL, NULL };
+
+ PJCMOBILE pMobile;
+ PNODE pNode;
+ char* pszObj;
+
+ if( NULL == ( pMobile = MobileFindByIMSI( pszIMSI, &pNode ) ) )
+ {
+ sprintf( pszResult, "Mobile '%s' not found", pszIMSI );
+ return FALSE;
+ }
+
+ pszObj = StringToken( NULL, pszDelims, &pszParam );
+
+ switch( nCommand )
+ {
+ case jcMngmCmdDelete:
+ return MobileDelete( pMobile, pNode, pszResult );
+
+ case jcMngmCmdGet:
+ if( pszObj == NULL ) /* get all parameters for this mobile */
+ return MngmCmdMobileGetAllParams( pMobile, pszResult );
+ else
+ return jcProcCallByName( pszObj, MobileObjs, nCommand, pszParam, pMobile, pszResult );
+
+ case jcMngmCmdSet:
+ if( pszObj == NULL )
+ {
+ strcpy( pszResult, "No configuration object specified for the mobile" );
+ return FALSE;
+ }
+ else
+ return jcProcCallByName( pszObj, MobileObjs, nCommand, pszParam, pMobile, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdMobileGetAllParams( PJCMOBILE pMobile, char* pszResult )
+{
+ char *pszCellID, *pszComment;
+
+ if( pMobile->hReg == NULL )
+ pszCellID = "<offline>";
+ else
+ pszCellID = jcRegGetNames( pMobile->hReg );
+
+ pszComment = pMobile->pszComment ? pMobile->pszComment : "<no comment>";
+
+ sprintf( pszResult, "%s%s%s%s%s%s%s",
+ pMobile->pszIMSI, pszFieldSeparator,
+ pMobile->pszNumber, pszFieldSeparator,
+ pszComment, pszFieldSeparator,
+ pszCellID );
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+int MngmCmdMobileIMSI( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCMOBILE pMobile = (PJCMOBILE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pMobile->pszIMSI, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ if( MobileFindByIMSI( pszValue, NULL ) )
+ {
+ strcpy( pszResult, "Another mobile exists with the same IMSI" );
+ return FALSE;
+ }
+
+ StringReplace( &pMobile->pszIMSI, pszValue );
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdMobileNumber( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCMOBILE pMobile = (PJCMOBILE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pMobile->pszNumber, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ if( jcNumberExists( pszValue ) )
+ {
+ strcpy( pszResult, "Another entity exists with the same number" );
+ return FALSE;
+ }
+
+ if( pMobile->hReg != NULL )
+ {
+ gkrgiDeleteAddress( pMobile->hReg, gkrgiParamPhone, gkrgiSttsDynamic,
+ pMobile->pszNumber );
+ gkrgiAddAddress( pMobile->hReg, gkrgiParamPhone, gkrgiSttsDynamic, pszValue );
+ }
+
+ StringReplace( &pMobile->pszNumber, pszValue );
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdMobileComment( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCMOBILE pMobile = (PJCMOBILE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pMobile->pszComment, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdStringSet( &pMobile->pszComment, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdSave( int nParam, char* pszParam, PVOID pParam, char* pszResult )
+{
+ char* pszFileName;
+ FILE* hFile;
+
+ if( NULL == ( pszFileName = StringToken( NULL, pszDelims, &pszParam ) ) )
+ pszFileName = pszDefaultDataFile;
+
+ if( NULL == ( hFile = fopen( pszFileName, "wb" ) ) )
+ {
+ sprintf( pszResult, "Unable to open file '%s'", pszFileName );
+ return FALSE;
+ }
+
+ if( FALSE == jcFileWriteString( hFile, pszDataFileHeader ) ||
+ FALSE == jcFileWriteUShort( hFile, JC_DATA_FILE_VERSION ) ||
+
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->nMaxCalls ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->RASPort ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->Q931Port ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->RASResponseTO ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->Q931ResponseTO ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->Q931ConnectTO ) ||
+ FALSE == jcFileWriteString( hFile, pCfgTree->pszGatekeeperID ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pCfgTree->TelnetPort ) ||
+ FALSE == jcFileWriteString( hFile, pCfgTree->pszIVRNumber ) ||
+
+ FALSE == jcSaveIpPhones( hFile ) ||
+ FALSE == jcSaveGateways( hFile ) ||
+ FALSE == jcSaveMobiles( hFile ) )
+ {
+ fclose( hFile );
+ sprintf( pszResult, "Error to write to file '%s'", pszFileName );
+ return FALSE;
+ }
+
+ fclose( hFile );
+ strcpy( pszResult, "Configuration saved" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcFileWriteBuf( FILE* hFile, UCHAR* buf, int nSize )
+{
+ return 1 == fwrite( buf, nSize, 1, hFile );
+}
+
+/*
+ *
+ */
+BOOL jcFileReadBuf( FILE* hFile, UCHAR* buf, int nSize )
+{
+ return 1 == fread( buf, nSize, 1, hFile );
+
+}
+
+/*
+ *
+ */
+BOOL jcFileWriteString( FILE* hFile, char* pszString )
+{
+ int nSize;
+
+ if( NULL == pszString )
+ nSize = 0;
+ else
+ nSize = strlen( pszString );
+
+ if( FALSE == jcFileWriteUShort( hFile, (USHORT)nSize ) )
+ return FALSE;
+
+ if( nSize > 0 )
+ return jcFileWriteBuf( hFile, (UCHAR*)pszString, nSize );
+ else
+ return TRUE;
+}
+
+/*
+ *
+ */
+char* jcFileReadString( FILE* hFile, char* pszString, int nMaxSize )
+{
+ int nSize;
+
+ if( 0 == ( nSize = jcFileReadUShort( hFile ) ) ||
+ nSize >= nMaxSize ||
+ FALSE == jcFileReadBuf( hFile, (UCHAR*)pszString, nSize ) )
+ {
+ pszString[0] = '\0';
+ return NULL;
+ }
+
+ pszString[nSize] = '\0';
+ return pszString;
+}
+
+/*
+ *
+ */
+BOOL jcFileWriteULong( FILE* hFile, ULONG uLong )
+{
+ UCHAR pszBuffer[4];
+
+ pszBuffer[0] = (UCHAR)( ( uLong >> 0 ) & 0xFF );
+ pszBuffer[1] = (UCHAR)( ( uLong >> 8 ) & 0xFF );
+ pszBuffer[2] = (UCHAR)( ( uLong >> 16 ) & 0xFF );
+ pszBuffer[3] = (UCHAR)( ( uLong >> 24 ) & 0xFF );
+
+ return jcFileWriteBuf( hFile, pszBuffer, 4 );
+}
+
+/*
+ *
+ */
+ULONG jcFileReadULong( FILE* hFile )
+{
+ UCHAR pszBuffer[4];
+
+ if( FALSE == jcFileReadBuf( hFile, pszBuffer, 4 ) )
+ return 0;
+ else
+ return ( (ULONG)pszBuffer[0] << 0 ) |
+ ( (ULONG)pszBuffer[1] << 8 ) |
+ ( (ULONG)pszBuffer[2] << 16 ) |
+ ( (ULONG)pszBuffer[3] << 24 );
+}
+
+/*
+ *
+ */
+BOOL jcFileWriteUShort( FILE* hFile, USHORT uShort )
+{
+ UCHAR pszBuffer[2];
+
+ pszBuffer[0] = (UCHAR)( ( uShort >> 0 ) & 0xFF );
+ pszBuffer[1] = (UCHAR)( ( uShort >> 8 ) & 0xFF );
+
+ return jcFileWriteBuf( hFile, pszBuffer, 2 );
+}
+
+/*
+ *
+ */
+USHORT jcFileReadUShort( FILE* hFile )
+{
+ UCHAR pszBuffer[2];
+
+ if( FALSE == jcFileReadBuf( hFile, pszBuffer, 2 ) )
+ return 0;
+ else
+ return ( (USHORT)pszBuffer[0] << 0 ) |
+ ( (USHORT)pszBuffer[1] << 8 );
+}
+
+/*
+ *
+ */
+BOOL jcSaveIpPhones( FILE* hFile )
+{
+ PNODE pNode;
+ PJCIPPHONE pIPPhone;
+
+ if( FALSE == jcFileWriteULong( hFile, ListGetCount( pCfgTree->pListIPPhones ) ) )
+ return FALSE;
+
+ ListForEachNode( pCfgTree->pListIPPhones, pNode )
+ {
+ pIPPhone = (PJCIPPHONE)NodeGetPtr( pNode );
+
+ if( FALSE == jcFileWriteString( hFile, pIPPhone->pszName ) ||
+ FALSE == jcFileWriteString( hFile, pIPPhone->pszNumber ) ||
+ FALSE == jcFileWriteString( hFile, pIPPhone->pszIPAddress ) ||
+ FALSE == jcFileWriteString( hFile, pIPPhone->pszComment ) )
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcSaveGateways( FILE* hFile )
+{
+ PNODE pNode;
+ PJCGATEWAY pGateway;
+
+ if( FALSE == jcFileWriteULong( hFile, ListGetCount( pCfgTree->pListGateways ) ) )
+ return FALSE;
+
+ ListForEachNode( pCfgTree->pListGateways, pNode )
+ {
+ pGateway = (PJCGATEWAY)NodeGetPtr( pNode );
+
+ if( FALSE == jcFileWriteString( hFile, pGateway->pszName ) ||
+ FALSE == jcFileWriteString( hFile, pGateway->pszPrefix ) ||
+ FALSE == jcFileWriteString( hFile, pGateway->pszIPAddress ) ||
+ FALSE == jcFileWriteUShort( hFile, (USHORT)pGateway->bStripPrefix ) ||
+ FALSE == jcFileWriteString( hFile, pGateway->pszComment ) )
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcSaveMobiles( FILE* hFile )
+{
+ PNODE pNode;
+ PJCMOBILE pMobile;
+
+ if( FALSE == jcFileWriteULong( hFile, ListGetCount( pCfgTree->pListMobiles ) ) )
+ return FALSE;
+
+ ListForEachNode( pCfgTree->pListMobiles, pNode )
+ {
+ pMobile = (PJCMOBILE)NodeGetPtr( pNode );
+
+ if( FALSE == jcFileWriteString( hFile, pMobile->pszIMSI ) ||
+ FALSE == jcFileWriteString( hFile, pMobile->pszNumber ) ||
+ FALSE == jcFileWriteString( hFile, pMobile->pszComment ) ||
+ FALSE == jcFileWriteUShort( hFile, pMobile->nProfileSize ) )
+ return FALSE;
+
+ if( pMobile->nProfileSize > 0 )
+ if( FALSE == jcFileWriteBuf( hFile, (UCHAR*)pMobile->ProfileData, pMobile->nProfileSize ) )
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+FILE* jcOpenConfigFile( char* pszFileName, USHORT* pnVersion )
+{
+ FILE* hFile;
+ char pszBuffer[128];
+
+ if( NULL == pszFileName ) pszFileName = pszDefaultDataFile;
+
+ if( NULL == ( hFile = fopen( pszFileName, "rb" ) ) )
+ {
+ StringPrint( "Unable to open file '%s'\n", pszFileName );
+ return NULL;
+ }
+
+ if( NULL == jcFileReadString( hFile, pszBuffer, 128 ) ||
+ 0 != StringCompare( pszBuffer, pszDataFileHeader ) )
+ {
+ fclose( hFile );
+ StringPrint( "The file '%s' is not %s\n", pszFileName, pszDataFileHeader );
+ return NULL;
+ }
+
+ if( ( *pnVersion = jcFileReadUShort( hFile ) ) > JC_DATA_FILE_VERSION )
+ {
+ fclose( hFile );
+ StringPrint( "Main Data File Version: %d, Supported: %d\n",
+ *pnVersion, JC_DATA_FILE_VERSION );
+ return NULL;
+ }
+ else
+ return hFile;
+}
+
+/*
+ *
+ */
+BOOL jcReadIpPhones( FILE* hFile, USHORT nVersion )
+{
+ char Name[256], Number[256], IPAddress[256], Comment[256], Result[256];
+ char *pszName, *pszNumber, *pszIPAddress, *pszComment;
+ ULONG nCount;
+
+ nCount = jcFileReadULong( hFile );
+
+ while( ( nCount-- ) > 0 )
+ {
+ pszName = jcFileReadString( hFile, Name, 256 );
+ pszNumber = jcFileReadString( hFile, Number, 256 );
+ pszIPAddress = jcFileReadString( hFile, IPAddress, 256 );
+ pszComment = jcFileReadString( hFile, Comment, 256 );
+
+ IpPhoneAdd( pszName, pszNumber, pszIPAddress, pszComment, Result );
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcReadGateways( FILE* hFile, USHORT nVersion )
+{
+ char Name[256], Prefix[256], IPAddress[256], Comment[256], Result[256];
+ char *pszName, *pszPrefix, *pszIPAddress, *pszComment;
+
+ BOOL bStripPrefix;
+ ULONG nCount;
+
+ nCount = jcFileReadULong( hFile );
+
+ while( ( nCount-- ) > 0 )
+ {
+ pszName = jcFileReadString( hFile, Name, 256 );
+ pszPrefix = jcFileReadString( hFile, Prefix, 256 );
+ pszIPAddress = jcFileReadString( hFile, IPAddress, 256 );
+ bStripPrefix = jcFileReadUShort( hFile );
+ pszComment = jcFileReadString( hFile, Comment, 256 );
+
+ jcGatewayAdd( pszName, pszPrefix, pszIPAddress, bStripPrefix, pszComment, Result );
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcReadMobiles( FILE* hFile, USHORT nVersion )
+{
+ char IMSI[256], Number[256], Comment[256], Result[256], Buffer[16*1024];
+ char *pszIMSI, *pszNumber, *pszComment;
+ ULONG nCount;
+ USHORT nProfileSize;
+
+ nCount = jcFileReadULong( hFile );
+
+ while( ( nCount-- ) > 0 )
+ {
+ pszIMSI = jcFileReadString( hFile, IMSI, 256 );
+ pszNumber = jcFileReadString( hFile, Number, 256 );
+ pszComment = jcFileReadString( hFile, Comment, 256 );
+
+ if( nVersion > 0 && ( nProfileSize = jcFileReadUShort( hFile ) ) > 0 )
+ {
+ jcFileReadBuf( hFile, (UCHAR*)Buffer, nProfileSize );
+ MobileAdd( pszIMSI, pszNumber, pszComment, nProfileSize, Buffer, Result );
+ }
+ else
+ {
+ MobileAdd( pszIMSI, pszNumber, pszComment, 0, NULL, Result );
+ }
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+int MngmCmdIpPhones( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ char *pszName, *pszNumber, *pszIPAddress, *pszComment;
+ PNODE pNode;
+ char buf[128];
+
+ pszName = StringToken( NULL, pszDelims, &pszParam );
+
+ switch( nCommand )
+ {
+ case jcMngmCmdAdd:
+ pszNumber = StringToken( NULL, pszDelims, &pszParam );
+ pszIPAddress = StringToken( NULL, pszDelims, &pszParam );
+ pszComment = StringToken( NULL, pszDelims, &pszParam );
+ return IpPhoneAdd( pszName, pszNumber, pszIPAddress, pszComment, pszResult );
+
+ case jcMngmCmdGet:
+ if( pszName == NULL ) /* IP Phones list */
+ {
+ pszResult[0] = '\0';
+
+ ListForEachNode( pCfgTree->pListIPPhones, pNode )
+ {
+ MngmCmdIpPhoneGetAllParams( (PJCIPPHONE)NodeGetPtr( pNode ), buf );
+ strcat( pszResult, buf );
+ strcat( pszResult, pszLineSeparator );
+ }
+
+ return TRUE;
+ }
+ else
+ return MngmCmdIpPhone( pszName, nCommand, pszParam, pszResult );
+
+ case jcMngmCmdDelete:
+ case jcMngmCmdSet:
+ if( pszName == NULL )
+ {
+ strcpy( pszResult, "No name specified for the IP phone" );
+ return FALSE;
+ }
+ else
+ return MngmCmdIpPhone( pszName, nCommand, pszParam, pszResult );
+
+ case jcMngmCmdImport:
+ return IpPhonesImport( pszName /* pszName has filename in this case */, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdIpPhoneGetAllParams( PJCIPPHONE pIPPhone, char* pszResult )
+{
+ sprintf( pszResult, "%s%s%s%s%s%s%s",
+ pIPPhone->pszName, pszFieldSeparator,
+ pIPPhone->pszNumber, pszFieldSeparator,
+ pIPPhone->pszIPAddress, pszFieldSeparator,
+ pIPPhone->pszComment ? pIPPhone->pszComment : "<no comment>" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+int MngmCmdIpPhone( char* pszName, int nCommand, char* pszParam, char* pszResult )
+{
+ static JCNAMEDPROC IpPhoneObjs[] = {
+ "Name", MngmCmdIpPhoneName,
+ "Number", MngmCmdIpPhoneNumber,
+ "IPAddress", MngmCmdIpPhoneIPAddress,
+ "Comment", MngmCmdIpPhoneComment,
+ NULL, NULL };
+
+ PJCIPPHONE pIPPhone;
+ PNODE pNode;
+ char* pszObj;
+
+ if( NULL == ( pIPPhone = IpPhoneFindByName( pszName, &pNode ) ) )
+ {
+ sprintf( pszResult, "IP phone '%s' not found", pszName );
+ return FALSE;
+ }
+
+ pszObj = StringToken( NULL, pszDelims, &pszParam );
+
+ switch( nCommand )
+ {
+ case jcMngmCmdDelete:
+ return IpPhoneDelete( pIPPhone, pNode, pszResult );
+
+ case jcMngmCmdGet:
+ if( pszObj == NULL ) /* get all parameters for this IP Phone */
+ return MngmCmdIpPhoneGetAllParams( pIPPhone, pszResult );
+ else
+ return jcProcCallByName( pszObj, IpPhoneObjs, nCommand, pszParam, pIPPhone, pszResult );
+
+ case jcMngmCmdSet:
+ if( pszObj == NULL )
+ {
+ strcpy( pszResult, "No configuration object specified for the IP phone" );
+ return FALSE;
+ }
+ else
+ return jcProcCallByName( pszObj, IpPhoneObjs, nCommand, pszParam, pIPPhone, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdIpPhoneName( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCIPPHONE pIPPhone = (PJCIPPHONE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pIPPhone->pszName, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ if( IpPhoneFindByName( pszValue, NULL ) )
+ {
+ strcpy( pszResult, "Another IP phone exists with the same name" );
+ return FALSE;
+ }
+
+ StringReplace( &pIPPhone->pszName, pszValue );
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdIpPhoneNumber( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCIPPHONE pIPPhone = (PJCIPPHONE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pIPPhone->pszNumber, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ if( jcNumberExists( pszValue ) )
+ {
+ strcpy( pszResult, "Another entity exists with the same number" );
+ return FALSE;
+ }
+
+ StringReplace( &pIPPhone->pszNumber, pszValue );
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+/*
+ *
+ */
+int MngmCmdIpPhoneIPAddress( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCIPPHONE pIPPhone = (PJCIPPHONE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pIPPhone->pszIPAddress, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdStringSet( &pIPPhone->pszIPAddress, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdIpPhoneComment( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCIPPHONE pIPPhone = (PJCIPPHONE)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pIPPhone->pszComment, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdStringSet( &pIPPhone->pszComment, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGateways( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ char *pszName, *pszPrefix, *pszIPAddress, *pszStripPrefix, *pszComment;
+ BOOL bStripPrefix;
+ PNODE pNode;
+ char buf[128];
+
+ pszName = StringToken( NULL, pszDelims, &pszParam );
+
+ switch( nCommand )
+ {
+ case jcMngmCmdAdd:
+ pszPrefix = StringToken( NULL, pszDelims, &pszParam );
+ pszIPAddress = StringToken( NULL, pszDelims, &pszParam );
+ pszStripPrefix = StringToken( NULL, pszDelims, &pszParam );
+ pszComment = StringToken( NULL, pszDelims, &pszParam );
+
+ bStripPrefix = ( 0 == StringICompare( pszStripPrefix, "yes" ) );
+
+ return jcGatewayAdd( pszName, pszPrefix, pszIPAddress,
+ bStripPrefix, pszComment, pszResult );
+
+ case jcMngmCmdGet:
+ if( pszName == NULL ) /* gateways list */
+ {
+ pszResult[0] = '\0';
+
+ ListForEachNode( pCfgTree->pListGateways, pNode )
+ {
+ MngmCmdGatewayGetAllParams( (PJCGATEWAY)NodeGetPtr( pNode ), buf );
+ strcat( pszResult, buf );
+ strcat( pszResult, pszLineSeparator );
+ }
+
+ return TRUE;
+ }
+ else
+ return MngmCmdGateway( pszName, nCommand, pszParam, pszResult );
+
+ case jcMngmCmdDelete:
+ case jcMngmCmdSet:
+ if( pszName == NULL )
+ {
+ strcpy( pszResult, "No name specified for the gateway" );
+ return FALSE;
+ }
+ else
+ return MngmCmdGateway( pszName, nCommand, pszParam, pszResult );
+
+ case jcMngmCmdImport:
+ return jcGatewaysImport( pszName /* pszName has filename in this case */, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGateway( char* pszName, int nCommand, char* pszParam, char* pszResult )
+{
+ static JCNAMEDPROC GatewayObjs[] = {
+ "Name", MngmCmdGatewayName,
+ "Prefix", MngmCmdGatewayPrefix,
+ "IPAddress", MngmCmdGatewayIPAddress,
+ "StripPrefix", MngmCmdGatewayStripPrefix,
+ "Comment", MngmCmdGatewayComment,
+ NULL, NULL };
+
+ PJCGATEWAY pGateway;
+ PNODE pNode;
+ char* pszObj;
+
+ if( NULL == ( pGateway = jcGatewayFindByName( pszName, &pNode ) ) )
+ {
+ sprintf( pszResult, "Gateway '%s' not found", pszName );
+ return FALSE;
+ }
+
+ pszObj = StringToken( NULL, pszDelims, &pszParam );
+
+ switch( nCommand )
+ {
+ case jcMngmCmdDelete:
+ return jcGatewayDelete( pGateway, pNode, pszResult );
+
+ case jcMngmCmdGet:
+ if( pszObj == NULL ) /* get all parameters for this gateway */
+ return MngmCmdGatewayGetAllParams( pGateway, pszResult );
+ else
+ return jcProcCallByName( pszObj, GatewayObjs, nCommand, pszParam, pGateway, pszResult );
+
+ case jcMngmCmdSet:
+ if( pszObj == NULL )
+ {
+ strcpy( pszResult, "No configuration object specified for the gateway" );
+ return FALSE;
+ }
+ else
+ return jcProcCallByName( pszObj, GatewayObjs, nCommand, pszParam, pGateway, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGatewayGetAllParams( PJCGATEWAY pGateway, char* pszResult )
+{
+ sprintf( pszResult, "%s%s%s%s%s%s%s%s%s",
+ pGateway->pszName, pszFieldSeparator,
+ pGateway->pszPrefix, pszFieldSeparator,
+ pGateway->pszIPAddress, pszFieldSeparator,
+ pGateway->bStripPrefix ? "yes" : "no", pszFieldSeparator,
+ pGateway->pszComment ? pGateway->pszComment : "<no comment>" );
+ return TRUE;
+}
+
+/*
+ *
+ */
+int MngmCmdGatewayName( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCGATEWAY pGateway = (PJCGATEWAY)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pGateway->pszName, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ if( jcGatewayFindByName( pszValue, NULL ) )
+ {
+ strcpy( pszResult, "Another gateway exists with the same name" );
+ return FALSE;
+ }
+
+ StringReplace( &pGateway->pszName, pszValue );
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGatewayPrefix( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCGATEWAY pGateway = (PJCGATEWAY)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pGateway->pszPrefix, pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ if( jcGatewayFindByNumber( pszValue ) )
+ {
+ strcpy( pszResult, "Another gateway exists with the same prefix" );
+ return FALSE;
+ }
+
+ StringReplace( &pGateway->pszPrefix, pszValue );
+ pGateway->nPrefixSize = strlen( pszValue );
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGatewayIPAddress( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCGATEWAY pGateway = (PJCGATEWAY)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pGateway->pszIPAddress, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdStringSet( &pGateway->pszIPAddress, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGatewayStripPrefix( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCGATEWAY pGateway = (PJCGATEWAY)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pGateway->bStripPrefix ? "yes" : "no", pszResult );
+
+ case jcMngmCmdSet:
+ {
+ char* pszValue;
+
+ if( NULL == ( pszValue = StringToken( NULL, pszDelims, &pszParam ) ) )
+ return MngmCmdNoValue( pszResult );
+
+ pGateway->bStripPrefix = ( 0 == StringICompare( pszValue, "yes" ) );
+
+ return MngmCmdValueSetOK( pszResult );
+ }
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdGatewayComment( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ PJCGATEWAY pGateway = (PJCGATEWAY)pParam;
+
+ switch( nCommand )
+ {
+ case jcMngmCmdGet:
+ return MngmCmdStringGet( pGateway->pszComment, pszResult );
+
+ case jcMngmCmdSet:
+ return MngmCmdStringSet( &pGateway->pszComment, pszParam, pszResult );
+
+ default:
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+ }
+}
+
+/*
+ *
+ */
+int MngmCmdViperCells( int nCommand, char* pszParam, PVOID pParam, char* pszResult )
+{
+ gkHREG hReg;
+ gkHAPPREG haReg;
+ char buf[128];
+
+ if( nCommand == jcMngmCmdGet )
+ {
+ pszResult[0] = '\0';
+
+ if( GKRGI_OK != gkrgiGetFirstEntryHandle( &hReg, &haReg ) )
+ return TRUE;
+
+ do
+ {
+ MngmCmdViperCellGetAllParams( hReg, buf );
+ strcat( pszResult, buf );
+ strcat( pszResult, pszLineSeparator );
+
+ }while( GKRGI_OK == gkrgiGetNextEntryHandle( hReg, &hReg, &haReg ) );
+
+ return TRUE;
+ }
+ else
+ return MngmCmdNotImplemented( nCommand, pszParam, NULL, pszResult );
+}
+
+/*
+ *
+ */
+int MngmCmdViperCellGetAllParams( gkHREG hReg, char* pszResult )
+{
+ char* pszNames;
+ gkaddTransport_t TransRAS;
+ int nMobiles;
+ char pszIP[16];
+
+ pszNames = jcRegGetNames( hReg );
+
+ if( GKRGI_OK == gkrgiGetParameter( hReg, gkrgiParamRAS, gkrgiSttsDynamic, 1, &TransRAS ) )
+ gkaddIp2String( TransRAS.ip, pszIP );
+ else
+ strcpy( pszIP, "<unknown>" );
+
+ if( GKRGI_OK != gkrgiGetNumberOfAddresses( hReg, gkrgiParamPhone, gkrgiSttsDynamic, &nMobiles ) )
+ nMobiles = 0;
+
+ sprintf( pszResult, "%s%s%s%s%d",
+ pszNames, pszFieldSeparator,
+ pszIP, pszFieldSeparator,
+ nMobiles );
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL jcNumberExists( char* pszNumber )
+{
+ if( MobileFindByNumber( pszNumber ) ||
+ IpPhoneFindByNumber( pszNumber ) ||
+ jcGatewayFindByNumber( pszNumber ) ||
+ 0 == StringCompare( pCfgTree->pszIVRNumber, pszNumber ) )
+ return TRUE;
+ else
+ return FALSE;
+}
+
+/*
+ *
+ */
+void MngmAPICallBack( pMngmCommandData_t pApiData )
+{
+ char *pszBuffer, *pszIMSI;
+ int nSize;
+ USHORT nProfileSize;
+ char IMSI[16], Number[32];
+ long nRequestID;
+ PJCMOBILE pMobile;
+ char Buffer[16*1024];
+
+ pszBuffer = pApiData->pszInput;
+
+ if( MNGM_API_VERSION != jcUShortUnpack( &pszBuffer ) )
+ {
+ DebugLog( "MngmAPICallBack(): wrong protocol or corrupted message\n" );
+ pApiData->nOutput = 0; /* error, no response will be sent */
+ return;
+ }
+
+ switch( jcUShortUnpack( &pszBuffer ) )
+ {
+ case MngmMsgRequestGeneric:
+ {
+ MngmCommandData_t CommandData;
+
+ nRequestID = jcULongUnpack( &pszBuffer );
+
+ CommandData.pszInput = pszBuffer;
+ CommandData.pszOutput = Buffer;
+ MngmCmdCallBack( &CommandData );
+
+ jcMngmResponseGenericPack( pApiData, nRequestID,
+ (short)CommandData.nOutput, CommandData.pszOutput );
+ return;
+ }
+
+ case MngmMsgRequestGetMobileProfile:
+ {
+ nRequestID = jcULongUnpack( &pszBuffer );
+ pszIMSI = jcStringUnpack( &pszBuffer );
+
+ pMobile = MobileFindByIMSI( pszIMSI, NULL );
+
+ pszBuffer = pApiData->pszOutput;
+ nSize = 0;
+ jcUShortPack( MNGM_API_VERSION, &pszBuffer, &nSize );
+ jcUShortPack( MngmMsgResponseGetMobileProfile, &pszBuffer, &nSize );
+ jcULongPack( nRequestID, &pszBuffer, &nSize );
+
+ if( pMobile == NULL || pMobile->nProfileSize == 0 )
+ {
+ jcUShortPack( 0, &pszBuffer, &nSize );
+ }
+ else
+ {
+ jcUShortPack( pMobile->nProfileSize, &pszBuffer, &nSize );
+ memcpy( pszBuffer, pMobile->ProfileData, pMobile->nProfileSize );
+ nSize += pMobile->nProfileSize;
+ }
+
+ pApiData->nOutput = nSize;
+ return;
+ }
+
+ case MngmMsgRequestSetMobileProfile:
+ {
+ nRequestID = jcULongUnpack( &pszBuffer );
+ nProfileSize = jcUShortUnpack( &pszBuffer );
+
+ if( nProfileSize <= 0 ||
+ FALSE == jcMobileProfileGetParams( pszBuffer, nProfileSize, IMSI, Number ) ||
+ NULL == ( pMobile = MobileFindByIMSI( IMSI, NULL ) ) )
+ {
+ jcMngmResponseGenericPack( pApiData, nRequestID, 0, "Wrong profile or unknown mobile" );
+ return;
+ }
+
+ if( 0 != StringCompare( pMobile->pszNumber, Number ) ) /* number has changed */
+ {
+ if( FALSE == MngmCmdMobileNumber( jcMngmCmdSet, Number, (PVOID)pMobile, Buffer ) )
+ {
+ jcMngmResponseGenericPack( pApiData, nRequestID, 0, Buffer );
+ return;
+ }
+ }
+
+ if( nProfileSize != pMobile->nProfileSize )
+ {
+ SpecialFree( pMobile->ProfileData );
+ pMobile->ProfileData = SpecialAlloc( nProfileSize );
+ pMobile->nProfileSize = nProfileSize;
+ }
+ memcpy( pMobile->ProfileData, pszBuffer, nProfileSize );
+ jcMngmResponseGenericPack( pApiData, nRequestID, 1, "The profile was changed" );
+
+ if( pMobile->hReg != NULL )
+ jcgkNonStdRasSendProfile( pMobile->hReg, (NSRASHANDLE)pMobile, pMobile->hMobileCell,
+ pMobile->nProfileSize, pMobile->ProfileData );
+ return;
+ }
+
+ case MngmMsgRequestAddMobileProfile:
+ {
+ nRequestID = jcULongUnpack( &pszBuffer );
+ nProfileSize = jcUShortUnpack( &pszBuffer );
+
+ if( nProfileSize <= 0 ||
+ FALSE == jcMobileProfileGetParams( pszBuffer, nProfileSize, IMSI, Number ) )
+ {
+ jcMngmResponseGenericPack( pApiData, nRequestID, 0, "Wrong profile" );
+ return;
+ }
+
+ jcMngmResponseGenericPack( pApiData, nRequestID,
+ (short)MobileAdd( IMSI, Number, NULL, nProfileSize, pszBuffer, Buffer ), Buffer );
+ return;
+ }
+
+ default:
+ {
+ DebugLog( "MngmAPICallBack(): unsupported message\n" );
+ pApiData->nOutput = 0; /* error, no response will be sent */
+ return;
+ }
+ }
+
+ return;
+}
+
+/*
+ *
+ */
+BOOL jcMobileProfileGetParams( char* pszProfile, USHORT nProfileSize,
+ char* pszIMSI, char* pszNumber )
+{
+ T_SUBSC_INFO SubscrInfo;
+
+ if( 0 != DecodeSubscInfo( pszProfile, nProfileSize, &SubscrInfo ) )
+ return FALSE;
+
+ memcpy( pszIMSI, SubscrInfo.imsi.mcc, 3 );
+ memcpy( pszIMSI + 3, SubscrInfo.imsi.mnc, 2 );
+ memcpy( pszIMSI + 5, SubscrInfo.imsi.msin, 10 );
+ pszIMSI[15] = '\0';
+
+ memcpy( pszNumber, SubscrInfo.msisdn.digits, SubscrInfo.msisdn.num_digit );
+ pszNumber[SubscrInfo.msisdn.num_digit] = '\0';
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+void jcMngmResponseGenericPack( pMngmCommandData_t pApiData,
+ long nRequestID, short nResult, char* pszTextData )
+{
+ char *pszBuffer;
+ int nSize;
+
+ pszBuffer = pApiData->pszOutput;
+ nSize = 0;
+
+ jcUShortPack( MNGM_API_VERSION, &pszBuffer, &nSize );
+ jcUShortPack( MngmMsgResponseGeneric, &pszBuffer, &nSize );
+ jcULongPack( nRequestID, &pszBuffer, &nSize );
+ jcUShortPack( nResult, &pszBuffer, &nSize );
+ jcStringPack( pszTextData, &pszBuffer, &nSize );
+
+ pApiData->nOutput = nSize;
+ return;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/admin.h b/data/mnet/GP10/Host/ViperBase/admin.h
new file mode 100644
index 0000000..960dff4
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/admin.h
@@ -0,0 +1,210 @@
+/* admin.h
+ *
+ */
+
+#define JC_DATA_FILE_VERSION 2
+/* 0 - initial version;
+ * 1 - mobile subscriber profile added;
+ * 2 - pszIVRNumber added
+ */
+
+typedef struct
+{
+ int nMaxCalls;
+ int RASPort;
+ int Q931Port;
+ int RASResponseTO;
+ int Q931ResponseTO;
+ int Q931ConnectTO;
+ PSTR pszGatekeeperID;
+ int TelnetPort;
+ PSTR pszIVRNumber;
+
+ PLIST pListIPPhones; /* JCIPPHONE */
+ PLIST pListGateways; /* JCGATEWAY */
+ PLIST pListMobiles; /* JCMOBILE */
+
+}JCCONFIG, *PJCCONFIG;
+
+typedef struct
+{
+ PSTR pszIMSI;
+ PSTR pszNumber;
+ PSTR pszComment;
+
+ USHORT nProfileSize;
+ void* ProfileData;
+
+ gkHREG hReg; /* has ViperCell the mobile currently belongs to */
+ NSRASHANDLE hMobileCell; /* ViperCell's mobile handle */
+
+}JCMOBILE, *PJCMOBILE;
+
+typedef struct
+{
+ PSTR pszName;
+ PSTR pszNumber;
+ PSTR pszIPAddress;
+ PSTR pszComment;
+
+}JCIPPHONE, *PJCIPPHONE;
+
+typedef struct
+{
+ PSTR pszName;
+ PSTR pszPrefix;
+ size_t nPrefixSize;
+ PSTR pszIPAddress;
+ BOOL bStripPrefix;
+ PSTR pszComment;
+
+}JCGATEWAY, *PJCGATEWAY;
+
+typedef enum
+{
+ jcMngmCmdAdd,
+ jcMngmCmdDelete,
+ jcMngmCmdSet,
+ jcMngmCmdGet,
+ jcMngmCmdSave,
+ jcMngmCmdImport
+
+}jcMngmCmd_t;
+
+/* "Named Proc" mechanism, calls function by name provided as text string */
+
+typedef int (*pfnCommand_t)( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+
+typedef struct
+{
+ char* pszProc;
+ pfnCommand_t pfnProc;
+
+}JCNAMEDPROC, *PJCNAMEDPROC;
+
+int jcProcCallByName( char* pszName, JCNAMEDPROC* pProcArray,
+ int nParam, char* pszParam, PVOID pParam, char* pszResult );
+
+BOOL EndpointsPrint( void );
+BOOL EndpointPrint( gkHREG );
+char* TransAddrToString( gkaddTransport_t*, char* Buffer ); /* returns Buffer */
+
+BOOL MobilesImport( char* pszFile, char* pszResult );
+BOOL IpPhonesImport( char* pszFile, char* pszResult );
+BOOL jcGatewaysImport( char* pszFile, char* pszResult );
+BOOL MobileAdd( char* pszIMSI, char* pszNumber, char* pszComment,
+ USHORT nProfileSize, void* ProfileData, char* pszResult );
+BOOL MobileDelete( PJCMOBILE, PNODE, char* pszResult );
+BOOL IpPhoneAdd( char* pszName, char* pszNumber, char* pszQ931Address,
+ char* pszComment, char* pszResult );
+BOOL IpPhoneDelete( PJCIPPHONE, PNODE pNode, char* pszResult );
+BOOL jcGatewayAdd( char* pszName, char* pszPrefix, char* pszIPAddress,
+ BOOL bStripPrefix, char* pszComment, char* pszResult );
+BOOL jcGatewayDelete( PJCGATEWAY, PNODE pNode, char* pszResult );
+PJCMOBILE MobileFindByIMSI( char* pszName, PNODE* );
+PJCMOBILE MobileFindByNumber( char* pszNumber );
+PJCIPPHONE IpPhoneFindByName( char* pszName, PNODE* );
+PJCIPPHONE IpPhoneFindByNumber( char* pszNumber );
+PJCGATEWAY jcGatewayFindByName( char* pszName, PNODE* );
+PJCGATEWAY jcGatewayFindByAddress( UINT32 ip, PNODE* );
+PJCGATEWAY jcGatewayFindByNumber( char* pszNumber );
+BOOL jcNumberExists( char* pszNumber );
+
+/* parsing mngm commands */
+void MngmCmdCallBack( pMngmCommandData_t );
+int MngmCmdNotImplemented( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdNoValue( char* pszResult );
+int MngmCmdValueSetOK( char* pszResult );
+int MngmCmdIntGet( int nSource, char* pszResult );
+int MngmCmdIntSet( int* pnTarget, int nMin, int nMax, char* pszParam, char* pszResult );
+int MngmCmdStringGet( char* pszSource, char* pszResult );
+int MngmCmdStringSet( char** ppszTarget, char* pszParam, char* pszResult );
+
+int MngmCmdAdd( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdDelete( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGet( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdSet( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdSave( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdImport( int nParam, char* pszParam, PVOID pParam, char* pszResult );
+
+int MngmCmdRootObjs( int nCommand, char* pszParam, char* pszResult );
+int MngmCmdMaxCalls( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdRASPort( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdQ931Port( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdRASResponseTimeout( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdQ931ResponseTimeout( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdQ931ConnectTimeout( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGatekeeperID( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdTelnetPort( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdIVRNumber( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+
+int MngmCmdMobiles( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdMobile( char* pszIMSI, int nCommand, char* pszParam, char* pszResult );
+int MngmCmdMobileIMSI( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdMobileNumber( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdMobileComment( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdMobileGetAllParams( PJCMOBILE, char* pszResult );
+
+int MngmCmdIpPhones( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdIpPhone( char* pszName, int nCommand, char* pszParam, char* pszResult );
+int MngmCmdIpPhoneName( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdIpPhoneNumber( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdIpPhoneIPAddress( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdIpPhoneComment( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdIpPhoneGetAllParams( PJCIPPHONE, char* pszResult );
+
+int MngmCmdGateways( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGateway( char* pszName, int nCommand, char* pszParam, char* pszResult );
+int MngmCmdGatewayName( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGatewayPrefix( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGatewayIPAddress( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGatewayStripPrefix( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGatewayComment( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdGatewayGetAllParams( PJCGATEWAY, char* pszResult );
+
+int MngmCmdViperCells( int nCommand, char* pszParam, PVOID pParam, char* pszResult );
+int MngmCmdViperCellGetAllParams( gkHREG, char* pszResult );
+
+/* Data File I/O */
+BOOL jcFileWriteBuf( FILE* hFile, UCHAR* buf, int nSize );
+BOOL jcFileReadBuf( FILE* hFile, UCHAR* buf, int nSize );
+BOOL jcFileWriteString( FILE* hFile, char* pszString );
+char* jcFileReadString( FILE* hFile, char* pszString, int nMaxSize );
+BOOL jcFileWriteULong( FILE* hFile, ULONG );
+ULONG jcFileReadULong( FILE* hFile );
+BOOL jcFileWriteUShort( FILE* hFile, USHORT );
+USHORT jcFileReadUShort( FILE* hFile );
+
+BOOL jcSaveIpPhones( FILE* hFile );
+BOOL jcSaveGateways( FILE* hFile );
+BOOL jcSaveMobiles( FILE* hFile );
+BOOL jcReadIpPhones( FILE* hFile, USHORT nVersion );
+BOOL jcReadGateways( FILE* hFile, USHORT nVersion );
+BOOL jcReadMobiles( FILE* hFile, USHORT nVersion );
+FILE* jcOpenConfigFile( char* pszFileName, USHORT* pnVersion );
+
+extern PJCCONFIG pCfgTree;
+
+/* Non-telnet management client API support */
+
+#define MNGM_API_VERSION 0
+
+typedef enum
+{
+ MngmMsgRequestGeneric = 0,
+ MngmMsgResponseGeneric = 1,
+
+ MngmMsgAlertGeneric = 100,
+
+ MngmMsgRequestGetMobileProfile = 200,
+ MngmMsgResponseGetMobileProfile = 201,
+ MngmMsgRequestSetMobileProfile = 202,
+ MngmMsgRequestAddMobileProfile = 203
+
+}MngmMsg_t;
+
+void MngmAPICallBack( pMngmCommandData_t );
+
+BOOL jcMobileProfileGetParams( char* pszProfile, USHORT nProfileSize,
+ char* pszIMSI, char* pszNumber );
+void jcMngmResponseGenericPack( pMngmCommandData_t, long nRequestID, short nResult, char* pszTextData );
diff --git a/data/mnet/GP10/Host/ViperBase/exchange.c b/data/mnet/GP10/Host/ViperBase/exchange.c
new file mode 100644
index 0000000..ffe641e
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/exchange.c
@@ -0,0 +1,240 @@
+/* exchange.c
+ * $Id: exchange.c,v 1.4 1999-07-30 10:38:38-07 olet Exp $
+ * Non Standard Interface between GK and H.323 task
+ */
+
+#include "support.h"
+#include "exchange.h"
+
+/*
+ *
+ */
+void jcNonStdRasMessageRRQPack( NonStdRasMessageRRQ_t* pMsgRRQ, UCHAR** ppszBuffer, int* pnSize )
+{
+ jcStringPack( pMsgRRQ->pszMobileID, ppszBuffer, pnSize );
+ jcULongPack( pMsgRRQ->hMobileCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageRRQUnpack( NonStdRasMessageRRQ_t* pMsgRRQ, UCHAR** ppszBuffer )
+{
+ pMsgRRQ->pszMobileID = jcStringUnpack( ppszBuffer );
+ pMsgRRQ->hMobileCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageRCFPack( NonStdRasMessageRCF_t* pMsgRCF, UCHAR** ppszBuffer, int* pnSize )
+{
+ jcULongPack( pMsgRCF->hMobileGK, ppszBuffer, pnSize );
+ jcULongPack( pMsgRCF->hMobileCell, ppszBuffer, pnSize );
+ jcStringPack( pMsgRCF->pszNumber, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageRCFUnpack( NonStdRasMessageRCF_t* pMsgRCF, UCHAR** ppszBuffer )
+{
+ pMsgRCF->hMobileGK = jcULongUnpack( ppszBuffer );
+ pMsgRCF->hMobileCell = jcULongUnpack( ppszBuffer );
+ pMsgRCF->pszNumber = jcStringUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageRRJPack( NonStdRasMessageRRJ_t* pMsgRRJ, UCHAR** ppszBuffer, int* pnSize )
+{
+ jcULongPack( pMsgRRJ->hMobileCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageRRJUnpack( NonStdRasMessageRRJ_t* pMsgRRJ, UCHAR** ppszBuffer )
+{
+ pMsgRRJ->hMobileCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageURQPack( NonStdRasMessageURQ_t* pMsgURQ, UCHAR** ppszBuffer, int* pnSize )
+{
+ jcULongPack( pMsgURQ->hMobileGK, ppszBuffer, pnSize );
+ jcULongPack( pMsgURQ->hMobileCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageURQUnpack( NonStdRasMessageURQ_t* pMsgURQ, UCHAR** ppszBuffer )
+{
+ pMsgURQ->hMobileGK = jcULongUnpack( ppszBuffer );
+ pMsgURQ->hMobileCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageUCFPack( NonStdRasMessageUCF_t* pMsgUCF, UCHAR** ppszBuffer, int* pnSize )
+{
+ jcULongPack( pMsgUCF->hMobileGK, ppszBuffer, pnSize );
+ jcULongPack( pMsgUCF->hMobileCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageUCFUnpack( NonStdRasMessageUCF_t* pMsgUCF, UCHAR** ppszBuffer )
+{
+ pMsgUCF->hMobileGK = jcULongUnpack( ppszBuffer );
+ pMsgUCF->hMobileCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageCellLRQPack( NonStdRasMessageCellLRQ_t* pMsgCellLRQ,
+ UCHAR** ppszBuffer, int* pnSize )
+{
+ jcStringPack( pMsgCellLRQ->pszCellID, ppszBuffer, pnSize );
+ jcULongPack( pMsgCellLRQ->hCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageCellLRQUnpack( NonStdRasMessageCellLRQ_t* pMsgCellLRQ, UCHAR** ppszBuffer )
+{
+ pMsgCellLRQ->pszCellID = jcStringUnpack( ppszBuffer );
+ pMsgCellLRQ->hCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageCellLCFPack( NonStdRasMessageCellLCF_t* pMsgCellLCF,
+ UCHAR** ppszBuffer, int* pnSize )
+{
+ jcStringPack( pMsgCellLCF->pszCellID, ppszBuffer, pnSize );
+ jcStringPack( pMsgCellLCF->pszIpAddress, ppszBuffer, pnSize );
+ jcULongPack( pMsgCellLCF->hCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageCellLCFUnpack( NonStdRasMessageCellLCF_t* pMsgCellLCF, UCHAR** ppszBuffer )
+{
+ pMsgCellLCF->pszCellID = jcStringUnpack( ppszBuffer );
+ pMsgCellLCF->pszIpAddress = jcStringUnpack( ppszBuffer );
+ pMsgCellLCF->hCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageCellLRJPack( NonStdRasMessageCellLRJ_t* pMsgCellLRJ,
+ UCHAR** ppszBuffer, int* pnSize )
+{
+ jcStringPack( pMsgCellLRJ->pszCellID, ppszBuffer, pnSize );
+ jcULongPack( pMsgCellLRJ->hCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageCellLRJUnpack( NonStdRasMessageCellLRJ_t* pMsgCellLRJ, UCHAR** ppszBuffer )
+{
+ pMsgCellLRJ->pszCellID = jcStringUnpack( ppszBuffer );
+ pMsgCellLRJ->hCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageMobileProfileRequestPack( NonStdRasMessageMobileProfileRequest_t* pMsg,
+ UCHAR** ppszBuffer, int* pnSize )
+{
+ jcULongPack( pMsg->hMobileGK, ppszBuffer, pnSize );
+ jcULongPack( pMsg->hMobileCell, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageMobileProfileRequestUnpack( NonStdRasMessageMobileProfileRequest_t* pMsg,
+ UCHAR** ppszBuffer )
+{
+ pMsg->hMobileGK = jcULongUnpack( ppszBuffer );
+ pMsg->hMobileCell = jcULongUnpack( ppszBuffer );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageMobileProfilePack( NonStdRasMessageMobileProfile_t* pMsg,
+ UCHAR** ppszBuffer, int* pnSize )
+{
+ jcULongPack( pMsg->hMobileGK, ppszBuffer, pnSize );
+ jcULongPack( pMsg->hMobileCell, ppszBuffer, pnSize );
+ jcUShortPack( pMsg->nProfileSize, ppszBuffer, pnSize );
+ jcBufferPack( pMsg->pProfileData, pMsg->nProfileSize, ppszBuffer, pnSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcNonStdRasMessageMobileProfileUnpack( NonStdRasMessageMobileProfile_t* pMsg,
+ UCHAR** ppszBuffer )
+{
+ pMsg->hMobileGK = jcULongUnpack( ppszBuffer );
+ pMsg->hMobileCell = jcULongUnpack( ppszBuffer );
+ pMsg->nProfileSize = jcUShortUnpack( ppszBuffer );
+ pMsg->pProfileData = jcBufferUnpack( pMsg->nProfileSize, ppszBuffer );
+
+ return;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/exchange.h b/data/mnet/GP10/Host/ViperBase/exchange.h
new file mode 100644
index 0000000..e26311c
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/exchange.h
@@ -0,0 +1,144 @@
+/* exchange.h
+ * $Id: exchange.h 1.4 1999/07/30 17:38:38 olet Exp $
+ * Non Standard Interface between GK and H.323 task
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define H323_MANUFACTURER_CODE_JETCELL 63846 /* !! have to get real one */
+#define H323_COUNTRY_CODE_USA 181
+
+#define NON_STD_MSG_MAX_LEN 1024
+#define NON_STD_RAS_PROTOCOL 1 /* to be cahnged when GK and H.323 task are no longer compatible */
+
+typedef ULONG NSRASHANDLE;
+
+typedef enum
+{
+ NonStdRasMessageTypeRRQ,
+ NonStdRasMessageTypeRCF,
+ NonStdRasMessageTypeRRJ,
+ NonStdRasMessageTypeURQ,
+ NonStdRasMessageTypeUCF,
+
+ NonStdRasMessageTypeCellLRQ,
+ NonStdRasMessageTypeCellLCF,
+ NonStdRasMessageTypeCellLRJ,
+
+ NonStdRasMessageTypeMobileProfileRequest,
+ NonStdRasMessageTypeMobileProfile,
+
+}NonStdRasMessageType;
+
+typedef struct
+{
+ char* pszMobileID;
+ NSRASHANDLE hMobileCell;
+
+}NonStdRasMessageRRQ_t;
+
+void jcNonStdRasMessageRRQPack( NonStdRasMessageRRQ_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageRRQUnpack( NonStdRasMessageRRQ_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ NSRASHANDLE hMobileGK;
+ NSRASHANDLE hMobileCell;
+ char* pszNumber;
+
+}NonStdRasMessageRCF_t;
+
+void jcNonStdRasMessageRCFPack( NonStdRasMessageRCF_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageRCFUnpack( NonStdRasMessageRCF_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ NSRASHANDLE hMobileCell;
+
+}NonStdRasMessageRRJ_t;
+
+void jcNonStdRasMessageRRJPack( NonStdRasMessageRRJ_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageRRJUnpack( NonStdRasMessageRRJ_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ NSRASHANDLE hMobileGK;
+ NSRASHANDLE hMobileCell;
+
+}NonStdRasMessageURQ_t; /* can be sent both ways */
+
+void jcNonStdRasMessageURQPack( NonStdRasMessageURQ_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageURQUnpack( NonStdRasMessageURQ_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ NSRASHANDLE hMobileGK;
+ NSRASHANDLE hMobileCell;
+
+}NonStdRasMessageUCF_t; /* can be sent both ways */
+
+void jcNonStdRasMessageUCFPack( NonStdRasMessageUCF_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageUCFUnpack( NonStdRasMessageUCF_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ char* pszCellID;
+ NSRASHANDLE hCell;
+
+}NonStdRasMessageCellLRQ_t;
+
+void jcNonStdRasMessageCellLRQPack( NonStdRasMessageCellLRQ_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageCellLRQUnpack( NonStdRasMessageCellLRQ_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ char* pszCellID;
+ char* pszIpAddress;
+ NSRASHANDLE hCell;
+
+}NonStdRasMessageCellLCF_t;
+
+void jcNonStdRasMessageCellLCFPack( NonStdRasMessageCellLCF_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageCellLCFUnpack( NonStdRasMessageCellLCF_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ char* pszCellID;
+ NSRASHANDLE hCell;
+
+}NonStdRasMessageCellLRJ_t;
+
+void jcNonStdRasMessageCellLRJPack( NonStdRasMessageCellLRJ_t*, UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageCellLRJUnpack( NonStdRasMessageCellLRJ_t*, UCHAR** ppszBuffer );
+
+typedef struct
+{
+ NSRASHANDLE hMobileGK;
+ NSRASHANDLE hMobileCell;
+
+}NonStdRasMessageMobileProfileRequest_t;
+
+void jcNonStdRasMessageMobileProfileRequestPack( NonStdRasMessageMobileProfileRequest_t*,
+ UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageMobileProfileRequestUnpack( NonStdRasMessageMobileProfileRequest_t*,
+ UCHAR** ppszBuffer );
+
+typedef struct
+{
+ NSRASHANDLE hMobileGK;
+ NSRASHANDLE hMobileCell;
+ USHORT nProfileSize;
+ PVOID pProfileData;
+
+}NonStdRasMessageMobileProfile_t;
+
+void jcNonStdRasMessageMobileProfilePack( NonStdRasMessageMobileProfile_t*,
+ UCHAR** ppszBuffer, int* pnSize );
+void jcNonStdRasMessageMobileProfileUnpack( NonStdRasMessageMobileProfile_t*, UCHAR** ppszBuffer );
+
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/data/mnet/GP10/Host/ViperBase/gateways.txt b/data/mnet/GP10/Host/ViperBase/gateways.txt
new file mode 100644
index 0000000..d07e6ea
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/gateways.txt
@@ -0,0 +1,4 @@
+
+StarGateInt 6 10.1.1.198
+StarGateOut 9 10.1.1.198
+Cisco 1 10.1.1.8 \ No newline at end of file
diff --git a/data/mnet/GP10/Host/ViperBase/hlr.txt b/data/mnet/GP10/Host/ViperBase/hlr.txt
new file mode 100644
index 0000000..ab596be
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/hlr.txt
@@ -0,0 +1,17 @@
+
+IMSI-1 2201
+IMSI-2 2202
+IMSI-3 2203
+
+310170107412222 2204 Nokia - Red
+310170107599992 2205 Motorola - 2
+310170107279472 2206 Nokia - Black
+310170107279488 2209 Motorola - 1
+310170107599993 2210 TEMS Mobile
+310170200164003 2211 Jan Long security code 9476
+001010000000001 2207 R&S
+001010123456789 2208 RACAL
+208014609514590 2299 Alcatel
+234305774004210 2212 Ericsson
+
+
diff --git a/data/mnet/GP10/Host/ViperBase/init.c b/data/mnet/GP10/Host/ViperBase/init.c
new file mode 100644
index 0000000..7b80d37
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/init.c
@@ -0,0 +1,203 @@
+/* init.c
+ *
+ */
+
+/* GKLib includes */
+#include <gkmain.h>
+#include <gkadd.h>
+#include <gkrgi.h>
+#include <gklrqi.h>
+#include <gkcci.h>
+#include <gkstorage.h>
+#include <cfgapi.h>
+#include <li.h>
+
+#include "support.h"
+#include "exchange.h"
+#include "init.h"
+#include "admin.h"
+#include "jcras.h"
+#include "jccall.h"
+
+void CALLCONV GKLibPrintRegular( const char* pszString, int nLevel );
+void CALLCONV GKLibPrintException( const char* pszString );
+
+/*
+ *
+ */
+BOOL MainInit( int argc, char** argv )
+{
+ FILE* hFile;
+ USHORT nVersion; /* config file version */
+ char pszBuffer[128];
+
+ DebugLevelInit( !ParamIsPresent( argc, argv, "-nolog" ) );
+
+ pCfgTree = New( JCCONFIG );
+ pCfgTree->pListIPPhones = ListCreate();
+ pCfgTree->pListGateways = ListCreate();
+ pCfgTree->pListMobiles = ListCreate();
+
+ if( NULL == ( hFile = jcOpenConfigFile( ParamGetValue( argc, argv, "-db", NULL ), &nVersion ) ) )
+ {
+ pCfgTree->nMaxCalls = JCGK_DEF_MAX_CALLS;
+ pCfgTree->RASPort = JCGK_DEF_RAS_PORT;
+ pCfgTree->Q931Port = JCGK_DEF_Q931_PORT;
+ pCfgTree->RASResponseTO = JCGK_DEF_RAS_RESPONSE_TO;
+ pCfgTree->Q931ResponseTO = JCGK_DEF_Q931_RESPONSE_TO;
+ pCfgTree->Q931ConnectTO = JCGK_DEF_Q931_CONNECT_TO;
+ pCfgTree->pszGatekeeperID = StringCreate( "ViperBase" );
+ pCfgTree->TelnetPort = JCGK_DEF_TELNET_PORT;
+ pCfgTree->pszIVRNumber = NULL;
+ }
+ else
+ {
+ pCfgTree->nMaxCalls = jcFileReadUShort( hFile );
+ pCfgTree->RASPort = jcFileReadUShort( hFile );
+ pCfgTree->Q931Port = jcFileReadUShort( hFile );
+ pCfgTree->RASResponseTO = jcFileReadUShort( hFile );
+ pCfgTree->Q931ResponseTO = jcFileReadUShort( hFile );
+ pCfgTree->Q931ConnectTO = jcFileReadUShort( hFile );
+ pCfgTree->pszGatekeeperID = StringCreate(
+ jcFileReadString( hFile, pszBuffer, ArraySize( pszBuffer ) ) );
+ pCfgTree->TelnetPort = jcFileReadUShort( hFile );
+
+ if( nVersion < 2 )
+ pCfgTree->pszIVRNumber = NULL;
+ else
+ pCfgTree->pszIVRNumber = StringCreate(
+ jcFileReadString( hFile, pszBuffer, ArraySize( pszBuffer ) ) );
+ }
+
+ if( FALSE == PlatformLayerInit() ||
+ FALSE == GKLibInit( argc, argv ) )
+ return FALSE;
+
+
+ if( NULL != hFile )
+ {
+ jcReadIpPhones( hFile, nVersion );
+ jcReadGateways( hFile, nVersion );
+ jcReadMobiles( hFile, nVersion );
+
+ fclose( hFile );
+ }
+
+ if( FALSE == MngmPortInit( JCGK_MNGM_CLIENT_PORT, (pfnCommonCallBack)MngmAPICallBack, FALSE ) ||
+ FALSE == MngmPortInit( pCfgTree->TelnetPort, (pfnCommonCallBack)MngmCmdCallBack, TRUE ) )
+ return FALSE;
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL GKLibInit( int argc, char** argv )
+{
+ int nMemSize;
+ gkmainRas_t RASParams;
+ gkmainQ931_t Q931Params;
+
+ static GKRGIEVENT regHandler = { jcRegHandler, NULL };
+ static GKNSMEVENT nsmHandler = { jcNonStdMsgHandler };
+ static GKLRQIEVENT lrqHandler = { jcLrqHandler, NULL };
+ static GKCCIEVENT callHandler = { jcStateHandler, jcCallMsgHandler, jcCallHookHandler, jcBandwidthHandler, jcFacilityHandler };
+ static GK_STORAGE_STRUCT storageHandler = { jcStorageInit, jcStorageAccess };
+
+ /* print function for library debug output */
+ gkmainSetNotify( GKLibPrintRegular );
+ gkmainSetException( GKLibPrintException );
+ gkmainSetDbgL( 0 );
+
+ if( gkmainConfigMaxRegistrations( JCGK_REGISTRATIONS, JCGK_CELLS_PER_REGISTRATION,
+ JCGK_REG_CELL_SIZE, &nMemSize ) < 0 )
+ {
+ DebugLog( "Error in gkmainConfigMaxRegistrations()\n" );
+ return FALSE;
+ }
+
+ if( gkmainConfigMaxCalls( pCfgTree->nMaxCalls, NULL ) < 0 )
+ {
+ DebugLog( "Error in gkmainConfigMaxCalls()\n" );
+ return FALSE;
+ }
+
+ RASParams.responseTO = pCfgTree->RASResponseTO;
+ RASParams.port = pCfgTree->RASPort;
+ strcpy( RASParams.multicastIp, GKMAIN_DEFAULT_multicastIp );
+ RASParams.multicastPort = GKMAIN_DEFAULT_multicastPort;
+
+ Q931Params.responseTO = pCfgTree->Q931ResponseTO;
+ Q931Params.connectTO = pCfgTree->Q931ConnectTO;
+ Q931Params.port = pCfgTree->Q931Port;
+
+ if( gkmainConfigStack( &RASParams, &Q931Params ) < 0 )
+ {
+ DebugLog( "Error in gkmainConfigStack()\n" );
+ return FALSE;
+ }
+
+ gkrgiSetEventHandler( &regHandler, sizeof( GKRGIEVENT ) );
+ gkrgiSetNSMHandler( &nsmHandler, sizeof( GKNSMEVENT ) );
+ gklrqiSetEventHandler( &lrqHandler, sizeof( GKLRQIEVENT ) );
+ gkcciSetEventHandler( &callHandler, sizeof( GKCCIEVENT ) );
+ gkstorageSetStorageFunctions( &storageHandler, sizeof( GK_STORAGE_STRUCT ) );
+
+ if( 0 != gkmainInit() )
+ {
+ DebugLog( "Error in gkmainInit()\n" );
+ return FALSE;
+ }
+
+ gkcfgiSetGKID( pCfgTree->pszGatekeeperID );
+ gkcfgiZonePropertiesSet( GKCFGI_DHCP, TRUE );
+ gkcfgiZonePropertiesSet( GKCFGI_ROUTED_CALLING_MODE, TRUE );
+ gkcfgiZonePropertiesSet( GKCFGI_OPEN_ZONE, TRUE );
+ gkcfgiZonePropertiesSet( GKCFGI_IRQ_INTERVAL, 25 /* minimal allowed */ );
+ gkcfgiZonePropertiesSet( GKCFGI_ENABLE_MULTICAST, 0 );
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+void CALLCONV GKLibPrintRegular( const char* pszString, int nLevel )
+{
+ if( NULL == pszString ) return;
+
+ DebugLog( "GKL: %s\n", pszString + 11 /* to cut off timestamp */ );
+
+ return;
+}
+
+/*
+ *
+ */
+void CALLCONV GKLibPrintException( const char* pszString )
+{
+ if( NULL == pszString ) return;
+
+ DebugLog( "GKL(!): %s\n", pszString + 11 /* to cut off timestamp */ );
+
+ return;
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcStorageInit( void )
+{
+ return GKSTORAGE_OK;
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcStorageAccess( IN gkstorageAccessMode_t mode, IN OUT UINT8* gkBuffer,
+ IN UINT32 bufferSize, IN gkstorageIdentifier_t appStorageID,
+ IN UINT32 offsetInStorage )
+{
+ return GKSTORAGE_OK;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/init.h b/data/mnet/GP10/Host/ViperBase/init.h
new file mode 100644
index 0000000..1158c29
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/init.h
@@ -0,0 +1,26 @@
+/* init.h
+ *
+ */
+
+#define JCGK_REGISTRATIONS 20
+#define JCGK_CELLS_PER_REGISTRATION 100
+#define JCGK_REG_CELL_SIZE 8
+
+/* default values for configurable parameters */
+#define JCGK_DEF_MAX_CALLS 100
+#define JCGK_DEF_RAS_PORT 1719
+#define JCGK_DEF_RAS_RESPONSE_TO 30
+#define JCGK_DEF_Q931_PORT 1720
+#define JCGK_DEF_Q931_RESPONSE_TO 30
+#define JCGK_DEF_Q931_CONNECT_TO 180
+#define JCGK_DEF_TELNET_PORT 11785
+#define JCGK_MNGM_CLIENT_PORT 11786
+ /* this is hardcoded on a client side, not for modifications */
+
+BOOL MainInit( int argc, char** argv );
+BOOL GKLibInit( int argc, char** argv );
+
+INT32 CALLCONV jcStorageInit( void );
+INT32 CALLCONV jcStorageAccess( IN gkstorageAccessMode_t mode, IN OUT UINT8* gkBuffer,
+ IN UINT32 bufferSize, IN gkstorageIdentifier_t appStorageID,
+ IN UINT32 offsetInStorage );
diff --git a/data/mnet/GP10/Host/ViperBase/ipphones.txt b/data/mnet/GP10/Host/ViperBase/ipphones.txt
new file mode 100644
index 0000000..b407736
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/ipphones.txt
@@ -0,0 +1,11 @@
+
+olet 8825 10.1.1.33
+adergun 8826 10.1.1.25
+winfield 8821 10.1.1.22
+xxu 8824 10.1.1.27
+target1 8809 10.1.1.24
+bhavaAtHome 8899 10.1.1.226
+bhava 8827 10.1.1.37
+rvandyke 8828 10.1.1.21
+
+
diff --git a/data/mnet/GP10/Host/ViperBase/jccall.c b/data/mnet/GP10/Host/ViperBase/jccall.c
new file mode 100644
index 0000000..8588166
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/jccall.c
@@ -0,0 +1,246 @@
+/* jccall.c
+ *
+ */
+
+#include <gkadd.h>
+#include <gktypes.h>
+#include <gkrgi.h>
+#include <gkcci.h>
+
+#include "support.h"
+#include "exchange.h"
+#include "jccall.h"
+#include "admin.h"
+
+/*
+ *
+ */
+INT32 CALLCONV jcStateHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* phaCall,
+ IN gkcciState_t State,
+ IN gkcciReason_t Reason )
+{
+
+ DebugLog( "Call %u, State '%s', Reason '%s'\n", hCall,
+ gkcciStateName( State ), gkcciReasonName( Reason ) );
+
+ switch( State )
+ {
+ case gkcciSttCannotComplete:
+ {
+ switch( Reason )
+ {
+ case gkcciRsnCannotSendLRQ:
+ return jcMainRouting( hCall, phaCall );
+
+ case gkcciRsnOutOfService:
+ case gkcciRsnNoAnswer:
+ case gkcciRsnAppTO:
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeUnreachableDestination );
+
+ case gkcciRsnLinesBusy:
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeCalledPartyNotRegistered );
+
+ case gkcciRsnDestBusy:
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeAdaptiveBusy );
+
+ case gkcciRsnDestReject:
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeDestinationRejection );
+
+ case gkcciRsnUndefined:
+ default:
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeUndefinedReason );
+ }
+ }
+
+ default:
+ break;
+ }
+
+ return gkcciDefaultStateEventHandler( hCall, phaCall, State, Reason );
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcBandwidthHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN gkcciBandwidthEvent_t Event,
+ IN gkcciSide_t Side,
+ IN gkcciBandwidthReason_t Reason,
+ IN gktypeBw_t RequestedBWInBPS )
+{
+
+ /* DebugLog( "jcBandwidthHandler(), Event = %d, Reason = %d\n", Event, Reason ); */
+
+ switch( Event )
+ {
+
+ default:
+ break;
+ }
+
+ return gkcciDefaultBandwidthEventHandler( hCall, haCall, Event, Side, Reason, RequestedBWInBPS );
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcFacilityHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN INT32 FacilityHandle,
+ IN gkcciFacilityEvent_t Event,
+ IN gkcciSide_t Side,
+ IN gkcciFacilityReason_t Reason )
+{
+
+ /* DebugLog( "jcFacilityHandler(), Event = %d, Reason = %d\n", Event, Reason ); */
+
+ switch( Event )
+ {
+
+ default:
+ break;
+ }
+
+ return gkcciDefaultFacilityEventHandler( hCall, haCall, FacilityHandle, Event, Side, Reason );
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcCallMsgHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN gkcciMsg_t Msg,
+ IN gkcciSide_t Side )
+{
+
+ /* DebugLog( "jcCallMsgHandler(): %s\n", gkcciMsgName( Msg ) ); */
+
+ switch( Msg )
+ {
+ case gkcciMsgSendSetup:
+ default:
+ break;
+ }
+
+ return gkcciOK;
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcCallHookHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN HCALL hsCall,
+ IN HRAS hsRas,
+ IN gkcciMsg_t Msg,
+ IN gkcciSide_t Side )
+{
+
+ switch( Msg )
+ {
+ case gkcciMsgSendSetup:
+ {
+ char buf[16];
+ sprintf( buf, "%d", (int)*haCall ); /* disconnect reason for IVR */
+ cmCallSetParam( hsCall, cmParamUserUser, 0, strlen( buf ) + 1, buf );
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return gkcciOK;
+}
+
+/*
+ *
+ */
+int jcMainRouting( gkHCALL hCall, gkHAPPCALL* phaCall )
+{
+ gkaddAlias_t Alias;
+ gkaddTransport_t Transport;
+ PJCGATEWAY pGateway;
+ PJCIPPHONE pIPPhone;
+ char *pszIPAddress, *pszName;
+
+ if( gkcciOK != gkcciGetParameter( hCall, gkcciParamAlias, gkcciSideDest, 0, 0, &Alias ) )
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeBadFormatAddress );
+
+ if( NULL != ( pIPPhone = IpPhoneFindByNumber( Alias.aliasStr ) ) )
+ {
+ pszName = pIPPhone->pszName;
+ pszIPAddress = pIPPhone->pszIPAddress;
+ }
+ else if( NULL != ( pGateway = jcGatewayFindByNumber( Alias.aliasStr ) ) )
+ {
+ pszName = pGateway->pszName;
+ pszIPAddress = pGateway->pszIPAddress;
+
+ if( pGateway->bStripPrefix )
+ {
+ char *pszSrc, *pszDst;
+
+ pszDst = Alias.aliasStr;
+ pszSrc = Alias.aliasStr + pGateway->nPrefixSize;
+
+ while( *pszDst++ = *pszSrc++ )
+ ;
+ }
+ }
+ else
+ {
+ DebugLog( "Number '%s' not found!\n", Alias.aliasStr );
+ return jcCallSendToIVR( hCall, phaCall, cmReasonTypeCalledPartyNotRegistered );
+ }
+
+ Transport.ip = gkaddString2Ip( pszIPAddress );
+ Transport.port = 1720;
+ Transport.routeType = gkaddIpNoRoute;
+ Transport.routeLength = 0;
+
+ DebugLog( "Sending SETUP to %s, %s, %s\n", pszName, pszIPAddress, Alias.aliasStr );
+
+ gkcciSetParameter( hCall, gkcciParamCallSignal, gkcciSideDest, 0, 0, &Transport );
+ gkcciDeleteAlias( hCall, gkcciParamAlias, gkcciSideDest, 0, 0 );
+ gkcciSetParameter( hCall, gkcciParamAlias, gkcciSideDest, 0, 0, &Alias );
+
+ gkcciReply( hCall, gkcciDontDisconnectStartAddressResolution, gkcciReplyRsnAddressFinal );
+ return gkcciOK;
+}
+
+/*
+ *
+ */
+int jcCallSendToIVR( gkHCALL hCall, gkHAPPCALL* phaCall, int Reason )
+{
+ gkaddAlias_t Alias;
+ char* pszIVRNumber;
+ char UserInfo[16];
+
+ sprintf( UserInfo, "%d", Reason );
+
+ if( NULL == ( pszIVRNumber = pCfgTree->pszIVRNumber ) ||
+ gkcciOK != gkcciGetParameter( hCall, gkcciParamAlias, gkcciSideDest, 0, 0, &Alias ) ||
+ 0 == StringCompare( pszIVRNumber, Alias.aliasStr ) )
+ {
+ gkcciReply( hCall, gkcciConfirmDisconnect, gkcciReplyRsnUndefined );
+ return gkcciOK;
+ }
+
+ *phaCall = (gkHAPPCALL)Reason; /* disconnect reason for IVR */
+
+ strcpy( Alias.aliasStr, pszIVRNumber );
+ gkcciDeleteAlias( hCall, gkcciParamAlias, gkcciSideDest, 0, 0 );
+ gkcciSetParameter( hCall, gkcciParamAlias, gkcciSideDest, 0, 0, &Alias );
+ gkcciReply( hCall, gkcciDontDisconnectStartAddressResolution, gkcciReplyRsnAliasChange );
+
+ return gkcciOK;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/jccall.h b/data/mnet/GP10/Host/ViperBase/jccall.h
new file mode 100644
index 0000000..5425529
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/jccall.h
@@ -0,0 +1,45 @@
+/* jccall.h
+ *
+ */
+
+INT32 CALLCONV jcStateHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN gkcciState_t State,
+ IN gkcciReason_t Reason );
+
+INT32 CALLCONV jcCallMsgHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN gkcciMsg_t Msg,
+ IN gkcciSide_t Side );
+
+INT32 CALLCONV jcBandwidthHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN gkcciBandwidthEvent_t Event,
+ IN gkcciSide_t Side,
+ IN gkcciBandwidthReason_t Reason,
+ IN gktypeBw_t RequestedBWInBPS );
+
+INT32 CALLCONV jcFacilityHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN INT32 FacilityHandle,
+ IN gkcciFacilityEvent_t Event,
+ IN gkcciSide_t Side,
+ IN gkcciFacilityReason_t Reason );
+
+INT32 CALLCONV jcCallHookHandler(
+ IN gkHCALL hCall,
+ IN OUT gkHAPPCALL* haCall,
+ IN HCALL hsCall,
+ IN HRAS hsRas,
+ IN gkcciMsg_t Msg,
+ IN gkcciSide_t Side );
+
+BOOL RegIsDynamic( IN gkHREG hReg );
+BOOL RegIsStatic( IN gkHREG hReg );
+
+int jcMainRouting( gkHCALL, gkHAPPCALL* );
+int jcCallSendToIVR( gkHCALL, gkHAPPCALL*, int Reason );
diff --git a/data/mnet/GP10/Host/ViperBase/jcras.c b/data/mnet/GP10/Host/ViperBase/jcras.c
new file mode 100644
index 0000000..36b442a
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/jcras.c
@@ -0,0 +1,523 @@
+/* jcras.c
+ *
+ */
+
+#include <gkadd.h>
+#include <gkrgi.h>
+#include <gklrqi.h>
+#include <li.h>
+
+#include "support.h"
+#include "exchange.h"
+#include "admin.h"
+#include "jcras.h"
+
+/*
+ *
+ */
+INT32 CALLCONV jcRegHandler(
+ IN gkHREG hReg,
+ IN OUT gkHAPPREG* phaReg,
+ IN gkrgiEvent_t Event,
+ IN gkrgiReason_t Reason )
+{
+ PNODE pNode;
+ PJCMOBILE pMobile;
+
+ DebugLog( "'%s', Event '%s', Reason '%s'\n", jcRegGetNames( hReg ),
+ gkrgiEventName( Event ), gkrgiReasonName( Reason ) );
+
+ switch( Event )
+ {
+ case gkrgiEvApprovedRRQ:
+ gkrgiReply( hReg, gkrgiRplyConfirm, gkrgiRplyRsnUndefined );
+ return GKRGI_OK;
+
+ case gkrgiEvSendingMessage:
+
+ if( Reason != gkrgiRsnSendingGKURQ && Reason != gkrgiRsnSendingApplicationURQ )
+ break;
+
+ /* going through! */
+
+ case gkrgiEvApprovedURQ:
+
+ ListForEachNode( pCfgTree->pListMobiles, pNode )
+ {
+ pMobile = (PJCMOBILE)NodeGetPtr( pNode );
+
+ if( pMobile->hReg == hReg )
+ {
+ pMobile->hReg = NULL;
+ pMobile->hMobileCell = 0;
+ }
+ }
+
+ break;
+
+ default:
+ break;
+ }
+
+ return gkrgiDefaultRegHandler( hReg, phaReg, Event, Reason );
+}
+
+/*
+ *
+ */
+INT32 CALLCONV jcNonStdMsgHandler(
+ IN gkHREG hReg,
+ IN OUT gkHAPPREG* phaReg,
+ IN HRAS hsRas,
+ IN gktypeNonStandardParam* appParam )
+{
+ PJCMOBILE pMobile;
+ UCHAR* pszBuffer;
+
+ if( NULL == ( pszBuffer = (UCHAR*)appParam->data ) ||
+ appParam->dataLength <= 0 ||
+ appParam->t35CountryCode != H323_COUNTRY_CODE_USA ||
+ appParam->manufacturerCode != H323_MANUFACTURER_CODE_JETCELL ||
+ NON_STD_RAS_PROTOCOL != jcUShortUnpack( &pszBuffer ) )
+ {
+ DebugLog( "jcNonStdMsgHandler() error: unrecognized non standard message\n" );
+ return 0;
+ }
+
+ switch( jcUShortUnpack( &pszBuffer ) ) /* message type */
+ {
+ case NonStdRasMessageTypeRRQ:
+ {
+ NonStdRasMessageRRQ_t MsgRRQ;
+
+ jcNonStdRasMessageRRQUnpack( &MsgRRQ, &pszBuffer );
+
+ if( NULL == ( pMobile = MobileFindByIMSI( MsgRRQ.pszMobileID, NULL ) ) )
+ {
+ jcgkNonStdRasSendRRJ( hReg, MsgRRQ.hMobileCell );
+ }
+ else
+ {
+ if( pMobile->hReg != NULL && pMobile->hReg != hReg ) /* old registration */
+ {
+ gkrgiDeleteAddress( pMobile->hReg, gkrgiParamPhone, gkrgiSttsDynamic, pMobile->pszNumber );
+ jcgkNonStdRasSendURQ( pMobile->hReg, pMobile );
+ }
+
+ gkrgiAddAddress( hReg, gkrgiParamPhone, gkrgiSttsDynamic, pMobile->pszNumber );
+ jcgkNonStdRasSendRCF( hReg, pMobile, MsgRRQ.hMobileCell );
+
+ pMobile->hReg = hReg;
+ pMobile->hMobileCell = MsgRRQ.hMobileCell;
+ }
+ break;
+ }
+
+ case NonStdRasMessageTypeURQ:
+ {
+ NonStdRasMessageURQ_t MsgURQ;
+
+ jcNonStdRasMessageURQUnpack( &MsgURQ, &pszBuffer );
+
+ pMobile = (PJCMOBILE)MsgURQ.hMobileGK;
+
+ if( NULL == ListFindByPtr( pCfgTree->pListMobiles, pMobile ) )
+ /* only to make sure pMobile is valid */
+ {
+ DebugLog( "jcNonStdMsgHandler(): invalid mobile handle in URQ\n" );
+ }
+ else
+ {
+ gkrgiDeleteAddress( hReg, gkrgiParamPhone, gkrgiSttsDynamic, pMobile->pszNumber );
+ pMobile->hReg = NULL;
+ pMobile->hMobileCell = 0;
+ }
+
+ jcgkNonStdRasSendUCF( hReg, MsgURQ.hMobileGK, MsgURQ.hMobileCell );
+
+ break;
+ }
+
+ case NonStdRasMessageTypeUCF:
+ break; /* nothing to do */
+
+ case NonStdRasMessageTypeCellLRQ:
+ {
+ NonStdRasMessageCellLRQ_t MsgCellLRQ;
+ char* pszIpAddr;
+
+ jcNonStdRasMessageCellLRQUnpack( &MsgCellLRQ, &pszBuffer );
+
+ if( NULL == ( pszIpAddr = jcRegGetIpByName( MsgCellLRQ.pszCellID ) ) )
+ jcgkNonStdRasSendCellLRJ( hReg, MsgCellLRQ.pszCellID, MsgCellLRQ.hCell );
+ else
+ jcgkNonStdRasSendCellLCF( hReg, MsgCellLRQ.pszCellID, pszIpAddr, MsgCellLRQ.hCell );
+
+ break;
+ }
+
+ case NonStdRasMessageTypeMobileProfileRequest:
+ {
+ NonStdRasMessageMobileProfileRequest_t MsgReq;
+
+ jcNonStdRasMessageMobileProfileRequestUnpack( &MsgReq, &pszBuffer );
+
+ pMobile = (PJCMOBILE)MsgReq.hMobileGK;
+
+ if( NULL == ListFindByPtr( pCfgTree->pListMobiles, pMobile ) )
+ /* only to make sure pMobile is valid */
+ {
+ DebugLog( "jcNonStdMsgHandler(): invalid mobile handle in MobileProfileRequest\n" );
+ jcgkNonStdRasSendProfile( hReg, MsgReq.hMobileGK, MsgReq.hMobileCell, 0, NULL );
+ }
+ else
+ jcgkNonStdRasSendProfile( hReg, MsgReq.hMobileGK, MsgReq.hMobileCell,
+ pMobile->nProfileSize, pMobile->ProfileData );
+ break;
+ }
+
+ default:
+ DebugLog( "jcNonStdMsgHandler() error: unrecognized message\n" );
+ return 0;
+ }
+
+ return 0;
+}
+
+
+/*
+ *
+ */
+/*
+INT32 CALLCONV jcRegHook(
+ IN gkHREG hReg,
+ IN OUT gkHAPPREG* phaReg,
+ IN HRAS hsRas,
+ IN gkrgiMessage_t Msg )
+{
+
+ DebugLog( "jcRegHook(), Msg = %d\n", Msg );
+
+ return TRUE;
+}
+*/
+/*
+ *
+ */
+INT32 CALLCONV jcLrqHandler(
+ IN gkHLRQ hLRQ,
+ IN OUT gkHAPPLRQ* haLRQ,
+ IN gklrqiEvent_t Event,
+ IN gklrqiReason_t Reason )
+{
+
+ DebugLog( "jcLrqHandler(), Event = %d\n", Event );
+
+ switch( Event )
+ {
+ default:
+ break;
+ }
+
+ return gklrqiDefaultLRQHandler( hLRQ, haLRQ, Event, Reason );
+}
+
+/*
+ *
+ */
+BOOL RegIsDynamic( IN gkHREG hReg )
+{
+ BOOL isDynamic;
+
+ if( gkrgiIsDynamic( hReg, &isDynamic ) < 0 )
+ return FALSE;
+
+ return isDynamic;
+}
+
+/*
+ *
+ */
+BOOL RegIsStatic( IN gkHREG hReg )
+{
+ BOOL isStatic;
+
+ if( gkrgiIsStatic( hReg, &isStatic ) < 0 )
+ return FALSE;
+
+ return isStatic;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendRCF( gkHREG hReg, PJCMOBILE pMobile, NSRASHANDLE hMobileCell )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageRCF_t MsgRCF;
+
+ MsgRCF.hMobileGK = (NSRASHANDLE)pMobile;
+ MsgRCF.hMobileCell = hMobileCell;
+ MsgRCF.pszNumber = pMobile->pszNumber;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeRCF, &pszBuffer, &nSize );
+ jcNonStdRasMessageRCFPack( &MsgRCF, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendRRJ( gkHREG hReg, NSRASHANDLE hMobileCell )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageRRJ_t MsgRRJ;
+
+ MsgRRJ.hMobileCell = hMobileCell;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeRRJ, &pszBuffer, &nSize );
+ jcNonStdRasMessageRRJPack( &MsgRRJ, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendUCF( gkHREG hReg, NSRASHANDLE hMobileGK, NSRASHANDLE hMobileCell )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageUCF_t MsgUCF;
+
+ MsgUCF.hMobileGK = hMobileGK;
+ MsgUCF.hMobileCell = hMobileCell;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeUCF, &pszBuffer, &nSize );
+ jcNonStdRasMessageUCFPack( &MsgUCF, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendURQ( gkHREG hReg, PJCMOBILE pMobile )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageURQ_t MsgURQ;
+
+ MsgURQ.hMobileGK = (NSRASHANDLE)pMobile;
+ MsgURQ.hMobileCell = pMobile->hMobileCell;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeURQ, &pszBuffer, &nSize );
+ jcNonStdRasMessageURQPack( &MsgURQ, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendCellLRJ( gkHREG hReg, char* pszCellID, NSRASHANDLE hCell )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageCellLRJ_t MsgCellLRJ;
+
+ MsgCellLRJ.pszCellID = pszCellID;
+ MsgCellLRJ.hCell = hCell;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeCellLRJ, &pszBuffer, &nSize );
+ jcNonStdRasMessageCellLRJPack( &MsgCellLRJ, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendCellLCF( gkHREG hReg, char* pszCellID, char* pszIpAddress, NSRASHANDLE hCell )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageCellLCF_t MsgCellLCF;
+
+ MsgCellLCF.pszCellID = pszCellID;
+ MsgCellLCF.pszIpAddress = pszIpAddress;
+ MsgCellLCF.hCell = hCell;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeCellLCF, &pszBuffer, &nSize );
+ jcNonStdRasMessageCellLCFPack( &MsgCellLCF, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+void jcgkNonStdRasSendProfile( gkHREG hReg, NSRASHANDLE hMobileGK, NSRASHANDLE hMobileCell,
+ USHORT nProfileSize, PVOID pProfileData )
+{
+ int nSize;
+ UCHAR buffer[NON_STD_MSG_MAX_LEN];
+ UCHAR* pszBuffer;
+ NonStdRasMessageMobileProfile_t Msg;
+
+ Msg.hMobileGK = hMobileGK;
+ Msg.hMobileCell = hMobileCell;
+ Msg.nProfileSize = nProfileSize;
+ Msg.pProfileData = pProfileData;
+
+ pszBuffer = buffer;
+ nSize = 0;
+
+ jcUShortPack( NON_STD_RAS_PROTOCOL, &pszBuffer, &nSize );
+ jcUShortPack( NonStdRasMessageTypeMobileProfile, &pszBuffer, &nSize );
+ jcNonStdRasMessageMobileProfilePack( &Msg, &pszBuffer, &nSize );
+
+ jcgkNonStdMsgSend( hReg, buffer, nSize );
+
+ return;
+}
+
+/*
+ *
+ */
+BOOL jcgkNonStdMsgSend( gkHREG hReg, UCHAR* msg, int size )
+{
+ gktypeNonStandardParam NSP;
+
+ if( size > NON_STD_MSG_MAX_LEN )
+ {
+ DebugLog( "jcgkNonStdMsgSend() error: message size is too big (%d > %d)\n",
+ size, NON_STD_MSG_MAX_LEN );
+ return FALSE;
+ }
+
+ NSP.data = (char*)msg;
+ NSP.dataLength = size;
+ NSP.objectLength = 0;
+ NSP.t35CountryCode = H323_COUNTRY_CODE_USA;
+ NSP.t35Extension = 0;
+ NSP.manufacturerCode = H323_MANUFACTURER_CODE_JETCELL;
+
+ if( GKRGI_OK != gkrgiSendNonStandardMsg( hReg, &NSP ) )
+ {
+ DebugLog( "Error in gkrgiSendNonStandardMsg()\n" );
+ return FALSE;
+ }
+ else
+ return TRUE;
+}
+
+/*
+ *
+ */
+char* jcRegGetNames( gkHREG hReg )
+{
+ static char Buffer[512];
+ gkaddName_t Name;
+ int i, nNames;
+
+ if( GKRGI_OK != gkrgiGetNumberOfAddresses( hReg, gkrgiParamName, gkrgiSttsDynamic, &nNames ) ||
+ nNames <= 0 )
+ return strcpy( Buffer, "<unknown>" );
+
+ Buffer[0] = '\0';
+
+ for( i = nNames; i > 0; i-- )
+ {
+ if( GKRGI_OK == gkrgiGetParameter( hReg, gkrgiParamName, gkrgiSttsDynamic, i, Name ) )
+ {
+ strcat( Buffer, Name );
+ if( i > 1 ) strcat( Buffer, "/" );
+ }
+ }
+
+ return Buffer;
+}
+
+/*
+ *
+ */
+char* jcRegGetIpByName( char* pszName )
+{
+ gkHREG hReg;
+ gkHAPPREG haReg;
+ gkaddName_t Name;
+ gkaddTransport_t TransRAS;
+ int i, nNames;
+ static char pszRAS[32];
+
+ if( GKRGI_OK != gkrgiGetFirstEntryHandle( &hReg, &haReg ) )
+ return NULL;
+
+ do
+ {
+ if( GKRGI_OK != gkrgiGetNumberOfAddresses( hReg, gkrgiParamName, gkrgiSttsDynamic, &nNames ) ||
+ nNames <= 0 )
+ continue;
+
+ for( i = 1; i <= nNames; i++ )
+ {
+ if( GKRGI_OK == gkrgiGetParameter( hReg, gkrgiParamName, gkrgiSttsDynamic, i, Name ) &&
+ 0 == StringCompare( pszName, Name ) )
+ {
+ if( GKRGI_OK == gkrgiGetParameter( hReg, gkrgiParamRAS, gkrgiSttsDynamic, 1, &TransRAS ) )
+ return gkaddIp2String( TransRAS.ip, pszRAS );
+ else
+ return NULL;
+ }
+ }
+
+ }while( GKRGI_OK == gkrgiGetNextEntryHandle( hReg, &hReg, &haReg ) );
+
+ return NULL;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/jcras.h b/data/mnet/GP10/Host/ViperBase/jcras.h
new file mode 100644
index 0000000..d120565
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/jcras.h
@@ -0,0 +1,45 @@
+/* jcras.h
+ *
+ */
+
+INT32 CALLCONV jcRegHandler(
+ IN gkHREG hReg,
+ IN OUT gkHAPPREG* phaReg,
+ IN gkrgiEvent_t Event,
+ IN gkrgiReason_t Reason );
+
+INT32 CALLCONV jcNonStdMsgHandler(
+ IN gkHREG hReg,
+ IN OUT gkHAPPREG* phaReg,
+ IN HRAS hsRas,
+ IN gktypeNonStandardParam* appParam );
+
+/*
+INT32 CALLCONV jcRegHook(
+ IN gkHREG hReg,
+ IN OUT gkHAPPREG* haReg,
+ IN HRAS hsRas,
+ IN gkrgiMessage_t Msg );
+*/
+INT32 CALLCONV jcLrqHandler(
+ IN gkHLRQ hLRQ,
+ IN OUT gkHAPPLRQ* haLRQ,
+ IN gklrqiEvent_t Event,
+ IN gklrqiReason_t Reason );
+
+BOOL RegIsDynamic( IN gkHREG );
+BOOL RegIsStatic( IN gkHREG );
+
+BOOL jcgkNonStdMsgSend( gkHREG, UCHAR* msg, int size );
+
+void jcgkNonStdRasSendRCF( gkHREG, PJCMOBILE, NSRASHANDLE hMobileCell );
+void jcgkNonStdRasSendRRJ( gkHREG, NSRASHANDLE hMobileCell );
+void jcgkNonStdRasSendUCF( gkHREG, NSRASHANDLE hMobileGK, NSRASHANDLE hMobileCell );
+void jcgkNonStdRasSendURQ( gkHREG, PJCMOBILE );
+void jcgkNonStdRasSendCellLCF( gkHREG hReg, char* pszCellID, char* pszIpAddress, NSRASHANDLE hCell );
+void jcgkNonStdRasSendCellLRJ( gkHREG, char* pszCellID, NSRASHANDLE hCell );
+void jcgkNonStdRasSendProfile( gkHREG, NSRASHANDLE hMobileGK, NSRASHANDLE hMobileCell,
+ USHORT nProfileSize, PVOID pProfileData );
+
+char* jcRegGetNames( gkHREG );
+char* jcRegGetIpByName( char* pszName );
diff --git a/data/mnet/GP10/Host/ViperBase/jcvbase.dat b/data/mnet/GP10/Host/ViperBase/jcvbase.dat
new file mode 100644
index 0000000..a5d95aa
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/jcvbase.dat
Binary files differ
diff --git a/data/mnet/GP10/Host/ViperBase/main.c b/data/mnet/GP10/Host/ViperBase/main.c
new file mode 100644
index 0000000..d514bfb
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/main.c
@@ -0,0 +1,46 @@
+/*
+ * main.c
+ */
+
+/* GKLib includes */
+#include <gkadd.h>
+#include <gkrgi.h>
+#include <gkstorage.h>
+#include <li.h>
+
+#include "support.h"
+#include "exchange.h"
+#include "init.h"
+#include "admin.h"
+
+void EndpointsPrintTimer( PVOID );
+
+/*
+ *
+ */
+int main( int argc, char** argv )
+{
+
+ if( FALSE == MainInit( argc, argv ) )
+ {
+ StringPrint( "Initialization Error\n" );
+ return FALSE;
+ }
+
+ StringPrint( "Initialization Successful\n\n" );
+
+ /* TimerCreate( 30, EndpointsPrintTimer, NULL, TRUE ); */
+
+ MainLoop();
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+void EndpointsPrintTimer( PVOID pVoid )
+{
+ EndpointsPrint();
+ return;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/platform.c b/data/mnet/GP10/Host/ViperBase/platform.c
new file mode 100644
index 0000000..302504d
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/platform.c
@@ -0,0 +1,692 @@
+/* platform.c
+ * $Id: platform.c,v 1.4 1999-07-30 10:38:42-07 olet Exp $
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "support.h"
+
+#if defined( WIN32 )
+
+# include <windows.h>
+
+static HWND hMainWnd;
+LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
+#define MNGM_TELNET_ACCEPT ( WM_USER + 1 )
+#define MNGM_TELNET_READ ( WM_USER + 2 )
+#define MNGM_CLIENT_ACCEPT ( WM_USER + 3 )
+#define MNGM_CLIENT_READ ( WM_USER + 4 )
+
+#elif defined( __VXWORKS__ )
+
+/* VxWorks */
+# include <taskLib.h>
+# include <ioLib.h>
+
+/* Rad */
+# include <mti.h>
+# include <seli.h>
+# include <pi.h>
+
+#define RAD_MAX_TIMERS 100
+static HSTIMER hsTimer;
+static TIMER jcTimersArray[RAD_MAX_TIMERS];
+void VxWorksTimerCallBack( void* pData );
+
+void RadPipeCallBack( int hPipe, piEvents Event, BOOL Error, void* pData );
+
+#else
+
+# include <signal.h>
+# include <unistd.h>
+# include <sys/types.h>
+# include <sys/socket.h>
+
+#endif
+
+/* Telnet Support */
+
+#define JC_MAX_TELNET_IN_STRING 256
+#define JC_MAX_TELNET_OUT_STRING 16384
+#define JCTELNETPROMPT "\r\nViperBase> "
+
+typedef struct
+{
+ SOCKET hSocket;
+ char Command[JC_MAX_TELNET_IN_STRING]; /* current command */
+ unsigned short nBytesInCommand;
+
+}JCTELNET, *PJCTELNET;
+
+static PLIST pListTelnets;
+static pfnCommonCallBack pfnCommandCallBack;
+static pfnCommonCallBack pfnMngmAPICallBack;
+/*
+ *
+ */
+BOOL PlatformLayerInit( void )
+{
+
+# if defined( WIN32 )
+
+ static char szAppName[] = "ViperBase";
+ WNDCLASS wc;
+ HANDLE hInstance = GetModuleHandle(NULL);
+
+ /* increasing process priority */
+ SetPriorityClass( GetCurrentProcess(), HIGH_PRIORITY_CLASS );
+
+ /* increasing scrolling buffer */
+/*
+ {
+ HANDLE hStdout;
+ COORD coord;
+
+ coord.X = 80;
+ coord.Y = 1000;
+
+ hStdout = GetStdHandle( STD_OUTPUT_HANDLE );
+
+ SetConsoleScreenBufferSize( hStdout, coord );
+ }
+*/
+ /* creating invisible main window */
+ wc.style = CS_HREDRAW | CS_VREDRAW;
+ wc.lpfnWndProc = WndProc;
+ wc.cbClsExtra = 0;
+ wc.cbWndExtra = 0;
+ wc.hInstance = hInstance;
+ wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
+ wc.hCursor = LoadCursor( NULL, IDC_ARROW );
+ wc.hbrBackground = GetStockObject( WHITE_BRUSH );
+ wc.lpszMenuName = "";
+ wc.lpszClassName = szAppName;
+
+ RegisterClass( &wc ) ;
+
+ hMainWnd = CreateWindow( szAppName, szAppName, WS_OVERLAPPEDWINDOW,
+ CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
+ NULL, NULL, hInstance, NULL );
+
+# elif defined( __VXWORKS__ )
+
+ int i, hShell;
+
+ if( ERROR != ( hShell = open( "/vio/0", O_CREAT | O_RDWR, 0 ) ) )
+ {
+ ioGlobalStdSet( STD_OUT, hShell );
+ ioGlobalStdSet( STD_ERR, hShell );
+ }
+
+
+ if( 0 == ( hsTimer = mtimerInit( RAD_MAX_TIMERS, NULL ) ) )
+ {
+ StringPrint( "Error in mtimerInit()\n" );
+ return FALSE;
+ }
+
+ for( i = 0; i < RAD_MAX_TIMERS; i++ )
+ jcTimersArray[i].pfnCallBack = NULL; /* indicates it is available */
+
+# else
+
+ signal( SIGPIPE, SIG_IGN );
+
+# endif
+
+ pListTelnets = ListCreate();
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL PlatformLayerDown( void )
+{
+
+#if defined( __VXWORKS__ )
+
+ mtimerEnd( hsTimer );
+
+#else
+
+#endif
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+void SpecialSleep( int nSeconds )
+{
+# if defined( WIN32 )
+
+ Sleep( nSeconds * 1000 );
+
+# elif defined( __VXWORKS__ )
+
+ taskDelay( nSeconds * 100 ); /* not a precise timeout! */
+
+# else
+
+ sleep( nSeconds );
+
+# endif
+
+ return;
+}
+
+/*
+ *
+ */
+void SpecialDebugBreak( void )
+{
+# ifdef WIN32
+ DebugBreak();
+
+# else
+ abort();
+
+# endif
+
+ return;
+}
+
+#if defined( __VXWORKS__ )
+
+/*
+ *
+ */
+BOOL MainLoop( void )
+{
+ while( 1 ) seliSelect();
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+PRADPIPE RadPipeOpen( char* Name, int nMsgSize, int nMaxMsgs, pfnCommonCallBack pfnUserCallBack )
+{
+ int hPipe;
+ PRADPIPE pPipe;
+/*
+ DebugLog( "Creating Pipe '%s', MsgSize = %d, MaxMsgs = %d\n", Name, nMsgSize, nMaxMsgs );
+*/
+ if( ERROR == piInit() )
+ {
+ StringPrint( "Error in piInit()\n" );
+ return FALSE;
+ }
+
+ if( ERROR == ( hPipe = piOpen( Name, nMsgSize, nMaxMsgs ) ) &&
+ 0 > ( hPipe = open( Name, O_RDWR, 644 ) ) )
+ {
+ StringPrint( "Error in piOpen()\n" );
+ return FALSE;
+ }
+
+ pPipe = New( RADPIPE );
+ pPipe->hPipe = hPipe;
+ pPipe->pfnUserCallBack = pfnUserCallBack;
+ pPipe->nMsgSize = nMsgSize;
+ pPipe->pMsg = SpecialAlloc( nMsgSize );
+
+ piCallOn( hPipe, piEvRead, (piCallback)RadPipeCallBack, pPipe );
+
+ return pPipe;
+}
+
+/*
+ *
+ */
+BOOL RadPipeWrite( PRADPIPE pPipe, PVOID pMessage )
+{
+
+ if( pPipe->nMsgSize != piWrite( pPipe->hPipe, (UINT8*)pMessage, pPipe->nMsgSize ) )
+ {
+ DebugLog( "Error in piWrite()\n" );
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+void RadPipeCallBack( int hPipe, piEvents Event, BOOL Error, void* pData )
+{
+ PRADPIPE pPipe;
+ int i, nPipeMsgs;
+
+ pPipe = (PRADPIPE)pData;
+
+ if( Error || pPipe->hPipe != hPipe )
+ {
+ DebugLog( "Error in RadPipeCallBack()\n" );
+ return;
+ }
+
+ ioctl( hPipe, FIONMSGS, (int)&nPipeMsgs );
+
+ for( i = 0; i < nPipeMsgs; i++ )
+ {
+ if( pPipe->nMsgSize != piRead( hPipe, (UINT8*)pPipe->pMsg, pPipe->nMsgSize ) )
+ {
+ DebugLog( "Error in piRead()\n" );
+ return;
+ }
+
+ (*pPipe->pfnUserCallBack)( pPipe->pMsg );
+ }
+
+ return;
+}
+
+/*
+ *
+ */
+BOOL RadPipeClose( PRADPIPE pPipe )
+{
+ piClose( pPipe->hPipe );
+ piEnd();
+
+ SpecialFree( pPipe->pMsg );
+ Delete( pPipe );
+
+ return TRUE;
+}
+
+
+#elif defined( WIN32 )
+
+/*
+ *
+ */
+BOOL MainLoop( void )
+{
+ MSG msg;
+
+ while( GetMessage( &msg, NULL, 0, 0 ) )
+ {
+ TranslateMessage( &msg );
+ DispatchMessage( &msg );
+ }
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+char* toHex(BYTE* data, int len)
+{
+ static char buf[100];
+ char* digits="0123456789ABCDEF";
+ unsigned i;
+ for (i=0;i<min(len,sizeof(buf)/2-1);i++)
+ {
+ buf[i*2]=digits[data[i]>>4];
+ buf[i*2+1]=digits[data[i]&0xf];
+ }
+ buf[i*2]=0;
+ return buf;
+}
+
+/*
+ *
+ */
+LRESULT CALLBACK WndProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
+{
+ switch( uMsg )
+ {
+ case WM_TIMER:
+ {
+ PTIMER pTimer = (PTIMER)wParam;
+
+ (*pTimer->pfnCallBack)( pTimer->pData );
+
+ if( FALSE == pTimer->bMultiple )
+ TimerDelete( pTimer );
+
+ return 0;
+ }
+
+ case MNGM_TELNET_ACCEPT:
+ {
+ SOCKET hSocket;
+ PJCTELNET pTelnet;
+
+ if( WSAGETSELECTERROR( lParam ) != 0 ||
+ INVALID_SOCKET == ( hSocket = accept( (SOCKET)wParam, NULL, NULL ) ) ||
+ SOCKET_ERROR == WSAAsyncSelect( hSocket, hMainWnd, MNGM_TELNET_READ,
+ FD_READ | FD_CLOSE ) )
+ {
+ DebugLog( "Error accepting telnet client\n" );
+ break;
+ }
+
+ MngmTelnetSendString( hSocket, "\r\nJetCell ViperBase Telnet Management Interface"
+ "\r\nPlease see ViperBase manual for commands syntax\r\n" );
+
+ MngmTelnetSendString( hSocket, JCTELNETPROMPT );
+
+ pTelnet = New( JCTELNET );
+ pTelnet->hSocket = hSocket;
+ pTelnet->nBytesInCommand = 0;
+
+ ListAddTail( pListTelnets, pTelnet );
+
+ DebugLog( "Telnet client connected\n" );
+
+ break;
+ }
+
+ case MNGM_CLIENT_ACCEPT:
+ {
+ SOCKET hSocket;
+
+ if( WSAGETSELECTERROR( lParam ) != 0 ||
+ INVALID_SOCKET == ( hSocket = accept( (SOCKET)wParam, NULL, NULL ) ) ||
+ SOCKET_ERROR == WSAAsyncSelect( hSocket, hMainWnd, MNGM_CLIENT_READ,
+ FD_READ | FD_CLOSE ) )
+ {
+ DebugLog( "Error accepting management client\n" );
+ break;
+ }
+
+ DebugLog( "Management client connected\n" );
+
+ break;
+ }
+
+ case MNGM_TELNET_READ:
+ {
+ char BufferIn[JC_MAX_TELNET_IN_STRING], BufferOut[JC_MAX_TELNET_OUT_STRING];
+ int nBytes;
+ PNODE pNode;
+ PJCTELNET pTelnet;
+ SOCKET hSocket = (SOCKET)wParam;
+ MngmCommandData_t CommandData;
+
+ ListForEachNode( pListTelnets, pNode )
+ {
+ pTelnet = (PJCTELNET)NodeGetPtr( pNode );
+
+ if( hSocket == pTelnet->hSocket )
+ break; /* found */
+ }
+
+ if( WSAGETSELECTEVENT( lParam ) == FD_CLOSE )
+ {
+ ListRemoveNode( pListTelnets, pNode );
+ Delete( pTelnet );
+ DebugLog( "Telnet client disconnected\n" );
+ break;
+ }
+
+ if( SOCKET_ERROR == ( nBytes = recv( hSocket, BufferIn, JC_MAX_TELNET_IN_STRING, 0 ) ) )
+ {
+ DebugLog( "MNGM_TELNET_READ: error in recv()\n" );
+ break;
+ }
+
+ if( BufferIn[0] >= 32 && BufferIn[0] <= 126 ) /* printable ASCII character */
+ {
+ if( pTelnet->nBytesInCommand + nBytes < JC_MAX_TELNET_IN_STRING - 1 )
+ {
+ memcpy( pTelnet->Command + pTelnet->nBytesInCommand, BufferIn, nBytes );
+ pTelnet->nBytesInCommand += nBytes;
+ send( hSocket, BufferIn, nBytes, 0 ); /* echo back */
+ }
+ else
+ MngmTelnetSendString( hSocket, "\a" ); /* beep */
+ }
+ else
+ {
+ switch( BufferIn[0] )
+ {
+ case 0x0D: /* end of line */
+
+ if( pTelnet->nBytesInCommand > 0 )
+ {
+ MngmTelnetSendString( hSocket, "\r\n" );
+
+ pTelnet->Command[pTelnet->nBytesInCommand] = '\0';
+ CommandData.pszInput = pTelnet->Command;
+ CommandData.pszOutput = BufferOut;
+
+ (*pfnCommandCallBack)( (PVOID)&CommandData );
+
+ MngmTelnetSendString( hSocket, BufferOut );
+
+ pTelnet->nBytesInCommand = 0; /* reset */
+ }
+
+ MngmTelnetSendString( hSocket, JCTELNETPROMPT );
+
+ break;
+
+ case 0x08: /* back space */
+ case 0x7F: /* delete */
+ if( pTelnet->nBytesInCommand > 0 )
+ {
+ pTelnet->nBytesInCommand--;
+ MngmTelnetSendString( hSocket, "\b \b" ); /* erase last character */
+ }
+ else
+ MngmTelnetSendString( hSocket, "\a" ); /* beep */
+
+ break;
+
+ default: /* for now ignoring everything else */
+ MngmTelnetSendString( hSocket, "\a" ); /* beep */
+ break;
+ }
+ }
+
+ break;
+ }
+
+ case MNGM_CLIENT_READ:
+ {
+ char BufferIn[1024], BufferOut[JC_MAX_TELNET_OUT_STRING];
+ SOCKET hSocket = (SOCKET)wParam;
+ MngmCommandData_t RequestData;
+
+ if( WSAGETSELECTEVENT( lParam ) == FD_CLOSE )
+ {
+ DebugLog( "Management client disconnected\n" );
+ break;
+ }
+
+ if( SOCKET_ERROR == recv( hSocket, BufferIn, 1024, 0 ) )
+ {
+ DebugLog( "MNGM_CLIENT_READ: error in recv()\n" );
+ break;
+ }
+
+ RequestData.pszInput = BufferIn;
+ RequestData.pszOutput = BufferOut;
+
+ (*pfnMngmAPICallBack)( (PVOID)&RequestData );
+
+ if( RequestData.nOutput > 0 )
+ send( hSocket, BufferOut, RequestData.nOutput, 0 );
+
+ break;
+ }
+
+ default:
+ break;
+ }
+
+ return DefWindowProc( hwnd, uMsg, wParam, lParam );
+}
+
+#endif
+
+
+#if defined( WIN32 )
+
+/*
+ *
+ */
+PTIMER TimerCreate( time_t tmInterval, pfnCommonCallBack pfnCallBack, PVOID pData, BOOL bMultiple )
+{
+ PTIMER pTimer;
+
+ ExecBreakIf( tmInterval <= 0, "Incorrect interval" );
+
+ pTimer = New( TIMER );
+
+ pTimer->pData = pData;
+ pTimer->pfnCallBack = pfnCallBack;
+ pTimer->bMultiple = bMultiple;
+
+ if( FALSE == SetTimer( hMainWnd, (UINT)pTimer, 1000 * tmInterval, NULL ) )
+ {
+ Delete( pTimer );
+ DebugLog( "Error in SetTimer()\n" );
+ return NULL;
+ }
+
+ return pTimer;
+}
+
+/*
+ *
+ */
+BOOL TimerDelete( PTIMER pTimer )
+{
+ if( NULL == pTimer )
+ return FALSE;
+
+ if( FALSE == KillTimer( hMainWnd, (UINT)pTimer ) )
+ DebugLog( "Error in KillTimer()\n" );
+
+ Delete( pTimer );
+
+ return TRUE;
+}
+
+
+#elif defined( __VXWORKS__ )
+
+/*
+ *
+ */
+PTIMER TimerCreate( time_t tmInterval, pfnCommonCallBack pfnCallBack, PVOID pData, BOOL bMultiple )
+{
+ int i;
+ PTIMER pTimer;
+
+ ExecBreakIf( tmInterval <= 0, "Incorrect interval" );
+
+ for( i = 0, pTimer = jcTimersArray; i < RAD_MAX_TIMERS; i++, pTimer++ )
+ if( pTimer->pfnCallBack == NULL )
+ goto Found;
+
+ DebugLog( "Error in TimerCreate(): can't find available jcTimersArray slot\n" );
+ return NULL;
+
+Found:
+
+ if( 0 > mtimerSet( hsTimer, (LPMTIMEREVENTHANDLER)VxWorksTimerCallBack,
+ (PVOID)pTimer, 1000 * tmInterval ) )
+ {
+ DebugLog( "Error in mtimerSet()\n" );
+ return NULL;
+ }
+
+ pTimer->pData = pData;
+ pTimer->pfnCallBack = pfnCallBack;
+ pTimer->bMultiple = bMultiple;
+
+ return pTimer;
+}
+
+/*
+ *
+ */
+void VxWorksTimerCallBack( PVOID pData )
+{
+ PTIMER pTimer = (PTIMER)pData;
+
+ (*pTimer->pfnCallBack)( pTimer->pData );
+
+ if( FALSE == pTimer->bMultiple )
+ TimerDelete( pTimer );
+
+ return;
+}
+
+/*
+ *
+ */
+BOOL TimerDelete( PTIMER pTimer )
+{
+ if( NULL == pTimer )
+ return FALSE;
+
+ mtimerResetByValue( hsTimer, (LPMTIMEREVENTHANDLER)VxWorksTimerCallBack, (PVOID)pTimer );
+
+ pTimer->pfnCallBack = NULL; /* indicates it is available */
+
+ return TRUE;
+}
+
+#endif
+
+#if defined( WIN32 )
+
+/*
+ *
+ */
+BOOL MngmPortInit( int MngmPort, pfnCommonCallBack pfnMngmCallBack, BOOL bTelnet )
+{
+ struct sockaddr_in SockAddr;
+ SOCKET hSocket;
+ int nWinMsgType;
+
+ SockAddr.sin_family = AF_INET;
+ SockAddr.sin_addr.s_addr = INADDR_ANY;
+ SockAddr.sin_port = htons( (u_short)MngmPort );
+
+ nWinMsgType = bTelnet ? MNGM_TELNET_ACCEPT : MNGM_CLIENT_ACCEPT;
+
+ if( INVALID_SOCKET == ( hSocket = socket( AF_INET, SOCK_STREAM, 0 ) ) ||
+ SOCKET_ERROR == bind( hSocket, (LPSOCKADDR)&SockAddr, sizeof( SockAddr ) ) ||
+ SOCKET_ERROR == listen( hSocket, 1 ) ||
+ SOCKET_ERROR == WSAAsyncSelect( hSocket, hMainWnd, nWinMsgType, FD_ACCEPT ) )
+ {
+ DebugLog( "MngmPortInit(): error while initializing the socket\n" );
+ return FALSE;
+ }
+
+ if( bTelnet )
+ pfnCommandCallBack = pfnMngmCallBack;
+ else
+ pfnMngmAPICallBack = pfnMngmCallBack;
+
+ return TRUE;
+}
+
+/*
+ *
+ */
+BOOL MngmTelnetSendString( int hSocket, char* pszString )
+{
+ send( hSocket, pszString, strlen( pszString ), 0 );
+ return TRUE;
+}
+
+#elif defined( __VXWORKS__ )
+
+#endif
+
diff --git a/data/mnet/GP10/Host/ViperBase/support.c b/data/mnet/GP10/Host/ViperBase/support.c
new file mode 100644
index 0000000..7b53954
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/support.c
@@ -0,0 +1,615 @@
+/* support.c
+ * $Id: support.c,v 1.3 1999-07-30 10:38:43-07 olet Exp $
+ *
+ * miscellaneous general purpose functions
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#include <time.h>
+
+#include "support.h"
+
+static ULONG nMemoryChunks = 0;
+static ULONG szMemoryChunks = 0;
+
+static BOOL bDebugLog = FALSE;
+
+/*
+ *
+ */
+PVOID SpecialAlloc( size_t szBytes )
+{
+ PVOID pvoid;
+ size_t szTotalBytes;
+
+# if defined( _DEBUG )
+ szTotalBytes = szBytes + 2 * sizeof( ULONG );
+# else
+ szTotalBytes = szBytes;
+# endif /* _DEBUG */
+
+ ExecBreakIf( NULL == ( pvoid = malloc( szTotalBytes ) ), "Not enough memory" );
+
+# if defined( _DEBUG )
+
+ nMemoryChunks++;
+ szMemoryChunks += szBytes;
+
+ *(ULONG*)pvoid = (ULONG)szBytes;
+ pvoid = (ULONG*)pvoid + 1;
+
+ *(ULONG*)pvoid = (ULONG)0xFEDCABCD; /* tag */
+ pvoid = (ULONG*)pvoid + 1;
+
+# endif /* _DEBUG */
+
+ return pvoid;
+}
+
+/*
+ *
+ */
+void SpecialFree( PVOID pvoid )
+{
+ if( pvoid == NULL )
+ return;
+
+# if defined( _DEBUG )
+ {
+ ULONG szThisChunk;
+
+ pvoid = (ULONG*)pvoid - 1;
+
+ ExecBreakIf( *(ULONG*)pvoid != (ULONG)0xFEDCABCD, "Invalid pointer" );
+
+ pvoid = (ULONG*)pvoid - 1;
+ szThisChunk = *(ULONG*)pvoid;
+
+ nMemoryChunks--;
+ szMemoryChunks -= szThisChunk;
+
+ memset( pvoid, 0x00, szThisChunk + 2 * sizeof( ULONG ) );
+ }
+# endif /* _DEBUG */
+
+ free( pvoid );
+
+ return;
+}
+
+/*
+ *
+ */
+ULONG MemoryGetTotalBlocks( void )
+{
+ return nMemoryChunks;
+}
+
+/*
+ *
+ */
+ULONG MemoryGetTotalSize( void )
+{
+ return szMemoryChunks;
+}
+
+/*
+ *
+ */
+PSTR StringCreate( char* psz )
+{
+ PSTR pszNew;
+ if( psz == NULL ) return NULL;
+ pszNew = (PSTR)SpecialAlloc( strlen( psz ) + 1 );
+ strcpy( pszNew, psz );
+ return pszNew;
+}
+
+/*
+ *
+ */
+void StringDelete( PSTR psz )
+{
+ if( psz != NULL )
+ Delete( psz );
+}
+
+/*
+ *
+ */
+size_t StringLength( char* psz )
+{
+ if( psz == NULL )
+ return 0;
+ else
+ return strlen( psz );
+}
+
+/*
+ *
+ */
+int StringICompare( char* psz1, char* psz2 )
+{
+
+# if defined( WIN32 )
+# define stricmp _stricmp
+# elif defined( __VXWORKS__ )
+# define stricmp strcoll
+# else
+# define stricmp strcasecmp
+# endif
+
+ if( psz1 == NULL || psz2 == NULL )
+ return ~0;
+ else
+ return stricmp( psz1, psz2 );
+}
+
+/*
+ *
+ */
+PSTR StringReplace( PSTR* ppszOld, char* psz )
+{
+ if( 0 == StringCompare( *ppszOld, psz ) )
+ return *ppszOld;
+ else
+ {
+ StringDelete( *ppszOld );
+ return *ppszOld = StringCreate( psz );
+ }
+}
+
+/*
+ *
+ */
+char* StringSplit( char* psz, char SplitChar )
+{
+ char c;
+
+ for( ; c = *psz; psz++ )
+ {
+ if( c == SplitChar )
+ {
+ *psz = '\0';
+ return psz + 1;
+ }
+ }
+
+ return psz;
+}
+
+/*
+ *
+ */
+char* StringToken( char* pszThis, char* pszDelims, char** ppszNext )
+{
+ size_t szToken;
+
+ if( pszThis == NULL )
+ pszThis = *ppszNext;
+
+ while( *pszThis != '\0' && 0 == ( szToken = strcspn( pszThis, pszDelims ) ) )
+ pszThis++; /* skipping leading delimiters */
+
+ switch( *pszThis )
+ {
+ case '\0':
+ return NULL;
+
+ case '"': /* remove this case if there's no need to treat quotation marks specially */
+ return StringToken( pszThis + 1, "\"", ppszNext );
+
+ default:
+ if( *( *ppszNext = pszThis + szToken ) != '\0' )
+ *(*ppszNext)++ = '\0';
+
+ return pszThis;
+ }
+}
+
+/*
+ *
+ */
+void StringPrint( char* pszFormat, ... )
+{
+ va_list pArg;
+ va_start( pArg, pszFormat );
+ vfprintf( stderr, pszFormat, pArg );
+ va_end( pArg );
+}
+
+/*
+ *
+ */
+void StringIndent( int nSpaces )
+{
+ char pszBuf[128];
+ int i;
+
+ for( i = 0; i < nSpaces; i++ )
+ pszBuf[i] = ' ';
+
+ pszBuf[nSpaces] = '\0';
+
+ StringPrint( pszBuf );
+
+ return;
+}
+
+/*
+ *
+ */
+int DivideInts( int nDivident, int nDivisor )
+{
+ int nQuotient;
+
+ if( nDivisor == 0 )
+ return ~0;
+
+ nQuotient = nDivident / nDivisor;
+
+ if( nDivident - nQuotient * nDivisor >= ( nQuotient + 1 ) * nDivisor - nDivident )
+ nQuotient++;
+
+ return nQuotient;
+}
+
+/*
+ *
+ */
+PLIST ListCreate( void )
+{
+ PLIST pList;
+
+ pList = New( LIST );
+
+ pList->pNodeHead = pList->pNodeTail = NULL;
+ pList->nObjectsCount = 0;
+
+ return pList;
+}
+
+/*
+ *
+ */
+void ListDelete( PLIST pList )
+{
+ ListRemoveAllNodes( pList );
+ Delete( pList );
+ return;
+}
+
+/*
+ *
+ */
+PNODE ListAddHead( PLIST pList, PVOID pObj )
+{
+ PNODE pNode = New( NODE );
+
+ pNode->pObject = pObj;
+
+ pList->nObjectsCount++;
+
+ if( NULL != ( pNode->pNodeNext = pList->pNodeHead ) )
+ pNode->pNodeNext->pNodePrev = pNode;
+ else
+ pList->pNodeTail = pNode;
+
+ pNode->pNodePrev = NULL;
+
+ pList->pNodeHead = pNode;
+
+ return pNode;
+}
+
+/*
+ *
+ */
+PNODE ListAddTail( PLIST pList, PVOID pObj )
+{
+ PNODE pNode = New( NODE );
+
+ pNode->pObject = pObj;
+
+ pList->nObjectsCount++;
+
+ if( NULL != ( pNode->pNodePrev = pList->pNodeTail ) )
+ pNode->pNodePrev->pNodeNext = pNode;
+ else
+ pList->pNodeHead = pNode;
+
+ pNode->pNodeNext = NULL;
+
+ pList->pNodeTail = pNode;
+
+ return pNode;
+}
+
+/*
+ *
+ */
+void ListRemoveAllNodes( PLIST pList )
+{
+ PNODE pNode, pNodeNext;
+
+ for( pNode = pList->pNodeHead; pNode; pNode = pNodeNext )
+ {
+ pNodeNext = pNode->pNodeNext;
+ Delete( pNode );
+ }
+
+ pList->pNodeHead = pList->pNodeTail = NULL;
+ pList->nObjectsCount = 0;
+
+ return;
+}
+
+/*
+ *
+ */
+void ListRemoveNode( PLIST pList, PNODE pNode )
+{
+ if( pNode == pList->pNodeHead )
+ pList->pNodeHead = pNode->pNodeNext;
+ else
+ pNode->pNodePrev->pNodeNext = pNode->pNodeNext;
+
+ if( pNode == pList->pNodeTail )
+ pList->pNodeTail = pNode->pNodePrev;
+ else
+ pNode->pNodeNext->pNodePrev = pNode->pNodePrev;
+
+ pList->nObjectsCount--;
+
+ Delete( pNode );
+
+ return;
+}
+
+/*
+ *
+ */
+PNODE ListFindByPtr( PLIST pList, PVOID pObj )
+{
+ PNODE pNode;
+
+ for( pNode = pList->pNodeHead; pNode; pNode = pNode->pNodeNext )
+ if( pNode->pObject == pObj )
+ return pNode;
+
+ return NULL;
+}
+
+/*
+ *
+ */
+PNODE ListFindByData( PLIST pList, PVOID pObjPattern, ObjectCompareProc pfnObjectCompare )
+{
+ PNODE pNode;
+
+ for( pNode = pList->pNodeHead; pNode; pNode = pNode->pNodeNext )
+ if( 0 == (*pfnObjectCompare)( pObjPattern, pNode->pObject ) )
+ return pNode;
+
+ return NULL;
+}
+
+/*
+ *
+ */
+char* GetDateTimeString( time_t tm )
+{
+ static char szBuf[32];
+
+ strftime( szBuf, 32, "[%m/%d/%y %H:%M:%S]", localtime( &tm ) );
+
+ return szBuf;
+}
+
+
+/*
+ *
+ */
+char* GetOption( char* pszSection, char* pszOption, char* pszDefaultValue )
+{
+ char* pszValue;
+
+ pszValue = pszDefaultValue; /* !! */
+
+ return pszValue;
+}
+
+
+/*
+ *
+ */
+char* ParamGetValue( int argc, char** argv, char* pszParam, char* pszDefaultValue )
+{
+ int i;
+
+ for( i = 1; i < argc; i++ )
+ if( 0 == StringCompare( argv[i], pszParam ) && ++i < argc )
+ return argv[i];
+
+ return pszDefaultValue;
+}
+
+/*
+ *
+ */
+BOOL ParamIsPresent( int argc, char** argv, char* pszParam )
+{
+ int i;
+
+ for( i = 1; i < argc; i++ )
+ if( 0 == StringCompare( argv[i], pszParam ) )
+ return TRUE;
+
+ return FALSE;
+}
+
+/*
+ *
+ */
+void DebugFatalErrorBreak( char* pszText, char* pszFile, int nLine )
+{
+ StringPrint( "\nFatal Error: %s, File: %s, Line: %d\n", pszText, pszFile, nLine );
+
+ SpecialDebugBreak();
+
+ return;
+}
+
+/*
+ *
+ */
+BOOL DebugLevelInit( BOOL bLogEnabled )
+{
+ bDebugLog = bLogEnabled;
+ return TRUE;
+}
+
+/*
+ *
+ */
+void DebugLog( char* pszFormat, ... )
+{
+ va_list pArg;
+
+ if( FALSE == bDebugLog )
+ return;
+
+ va_start( pArg, pszFormat );
+ vfprintf( stderr, pszFormat, pArg );
+ va_end( pArg );
+ return;
+}
+
+/*
+ *
+ */
+void jcStringPack( char* pszString, UCHAR** ppszBuffer, int* pnSize )
+{
+ size_t nSize;
+
+ nSize = strlen( pszString ) + 1;
+ strcpy( *ppszBuffer, pszString );
+
+ *ppszBuffer += nSize;
+ *pnSize += nSize;
+
+ return;
+}
+
+/*
+ *
+ */
+char* jcStringUnpack( UCHAR** ppszBuffer )
+{
+ char* pszString = *ppszBuffer;
+
+ *ppszBuffer += strlen( pszString ) + 1;
+
+ return pszString;
+}
+
+/*
+ *
+ */
+void jcBufferPack( PVOID pData, USHORT nDataSize, UCHAR** ppszBuffer, int* pnSize )
+{
+ if( nDataSize == 0 ) return;
+
+ memcpy( *ppszBuffer, pData, nDataSize );
+
+ *ppszBuffer += nDataSize;
+ *pnSize += nDataSize;
+
+ return;
+}
+
+/*
+ *
+ */
+PVOID jcBufferUnpack( USHORT nDataSize, UCHAR** ppszBuffer )
+{
+ PVOID pData;
+
+ if( nDataSize == 0 ) return NULL;
+
+ pData = *ppszBuffer;
+ *ppszBuffer += nDataSize;
+
+ return pData;
+}
+
+/*
+ *
+ */
+void jcULongPack( ULONG uLong, UCHAR** ppszBuffer, int* pnSize )
+{
+ UCHAR* pszBuffer = *ppszBuffer;
+
+ pszBuffer[0] = (UCHAR)( ( uLong >> 0 ) & 0xFF );
+ pszBuffer[1] = (UCHAR)( ( uLong >> 8 ) & 0xFF );
+ pszBuffer[2] = (UCHAR)( ( uLong >> 16 ) & 0xFF );
+ pszBuffer[3] = (UCHAR)( ( uLong >> 24 ) & 0xFF );
+
+ *ppszBuffer += 4;
+ *pnSize += 4;
+
+ return;
+}
+
+/*
+ *
+ */
+ULONG jcULongUnpack( UCHAR** ppszBuffer )
+{
+ ULONG uLong;
+ UCHAR* pszBuffer = *ppszBuffer;
+
+ uLong = ( (ULONG)pszBuffer[0] << 0 ) |
+ ( (ULONG)pszBuffer[1] << 8 ) |
+ ( (ULONG)pszBuffer[2] << 16 ) |
+ ( (ULONG)pszBuffer[3] << 24 );
+
+ *ppszBuffer += 4;
+
+ return uLong;
+}
+
+/*
+ *
+ */
+void jcUShortPack( USHORT uShort, UCHAR** ppszBuffer, int* pnSize )
+{
+ UCHAR* pszBuffer = *ppszBuffer;
+
+ pszBuffer[0] = (UCHAR)( ( uShort >> 0 ) & 0xFF );
+ pszBuffer[1] = (UCHAR)( ( uShort >> 8 ) & 0xFF );
+
+ *ppszBuffer += 2;
+ *pnSize += 2;
+
+ return;
+}
+
+/*
+ *
+ */
+USHORT jcUShortUnpack( UCHAR** ppszBuffer )
+{
+ USHORT uShort;
+ UCHAR* pszBuffer = *ppszBuffer;
+
+ uShort = ( (USHORT)pszBuffer[0] << 0 ) |
+ ( (USHORT)pszBuffer[1] << 8 );
+
+ *ppszBuffer += 2;
+
+ return uShort;
+}
diff --git a/data/mnet/GP10/Host/ViperBase/support.h b/data/mnet/GP10/Host/ViperBase/support.h
new file mode 100644
index 0000000..7765f4f
--- /dev/null
+++ b/data/mnet/GP10/Host/ViperBase/support.h
@@ -0,0 +1,188 @@
+/* support.h
+ * $Id: support.h,v 1.4 1999-07-30 10:38:44-07 olet Exp $
+ *
+ * miscellaneous general purpose functions
+ */
+
+#ifndef _INC_SUPPORT
+#define _INC_SUPPORT
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <stddef.h>
+#include <time.h>
+#include <string.h>
+
+#define FALSE 0
+#define TRUE 1
+
+#if !defined( __RVCOMMON_H ) && !defined( __INCvxTypesOldh )
+typedef int BOOL;
+#endif
+
+#if !defined( __INCvxTypesOldh )
+typedef unsigned long ULONG;
+typedef unsigned short USHORT;
+typedef unsigned char UCHAR;
+#endif
+
+typedef void* PVOID;
+typedef char* PSTR;
+
+#define ArraySize( Array ) ( sizeof( Array ) / sizeof( Array[0] ) )
+
+#define New( OBJECT ) ( (OBJECT*)SpecialAlloc( sizeof( OBJECT ) ) )
+#define Delete( pObject ) ( SpecialFree( (PVOID)( pObject ) ) )
+
+typedef int (*ObjectCompareProc)( void* pObjPattern, void* pObjFromList );
+
+typedef struct _NODE* PNODE;
+
+typedef struct _NODE
+{
+ PNODE pNodeNext;
+ PNODE pNodePrev;
+ PVOID pObject;
+}NODE;
+
+typedef struct _LIST
+{
+ PNODE pNodeHead;
+ PNODE pNodeTail;
+ unsigned nObjectsCount;
+}LIST, *PLIST;
+
+
+typedef void ( *pfnCommonCallBack )( PVOID );
+
+typedef struct _TIMER
+{
+ pfnCommonCallBack pfnCallBack;
+ PVOID pData;
+ BOOL bMultiple;
+
+}TIMER, *PTIMER;
+
+
+#define ListGetHead( pList ) ( pList->pNodeHead )
+#define ListGetTail( pList ) ( pList->pNodeTail )
+#define ListGetCount( pList ) ( pList->nObjectsCount )
+
+#define NodeGetNext( pNode ) ( pNode->pNodeNext )
+#define NodeGetPrev( pNode ) ( pNode->pNodePrev )
+#define NodeGetPtr( pNode ) ( pNode->pObject )
+
+#define ListForEachNode( pList, pNode ) \
+ for( pNode = ListGetHead( pList ); \
+ pNode; \
+ pNode = NodeGetNext( pNode ) )
+
+#define ListForEachNodeSafe( pList, pNode, pNodeNext ) \
+ for( pNodeNext = ( pNode = ListGetHead( pList ) ) ? NodeGetNext( pNode ) : NULL ; \
+ pNode; \
+ pNodeNext = ( pNode = pNodeNext ) ? NodeGetNext( pNode ) : NULL )
+
+/* memory */
+PVOID SpecialAlloc( size_t );
+void SpecialFree( PVOID );
+ULONG MemoryGetTotalBlocks( void );
+ULONG MemoryGetTotalSize( void );
+
+/* list */
+PLIST ListCreate( void );
+void ListDelete( PLIST );
+void ListRemoveAllNodes( PLIST ); /* doesn't remove objects itself! */
+void ListRemoveNode( PLIST, PNODE );
+PNODE ListAddHead( PLIST, PVOID );
+PNODE ListAddTail( PLIST, PVOID );
+PNODE ListFindByPtr( PLIST, PVOID );
+PNODE ListFindByData( PLIST, PVOID pObjPattern, ObjectCompareProc );
+
+/* strings */
+PSTR StringCreate( char* psz );
+void StringDelete( PSTR );
+PSTR StringReplace( PSTR* ppszOld, char* psz );
+size_t StringLength( char* psz );
+int StringICompare( char* psz1, char* psz2 );
+char* StringSplit( char* psz, char SplitChar );
+void StringPrint( char* pszFormat, ... );
+void StringIndent( int nSpaces );
+char* StringToken( char* pszThis, char* pszDelims, char** ppszNext );
+
+#define StringCompare( psz1, psz2 ) \
+ ( ( psz1 == NULL || psz2 == NULL ) ? ~0 : strcmp( psz1, psz2 ) )
+
+/* log control */
+BOOL DebugLevelInit( BOOL bLogEnabled );
+void DebugLog( char* pszFormat, ... );
+
+/* math */
+int DivideInts( int nDivident, int nDivisor );
+
+/* timer */
+PTIMER TimerCreate( time_t tmInterval, pfnCommonCallBack, PVOID pData, BOOL bMultiple );
+BOOL TimerDelete( PTIMER );
+
+/* message loop */
+BOOL MainLoop( void );
+
+/* RAD input pipe */
+typedef struct
+{
+ int hPipe;
+ pfnCommonCallBack pfnUserCallBack;
+ int nMsgSize;
+ PVOID pMsg; /* place to read received message */
+
+}RADPIPE, *PRADPIPE;
+
+PRADPIPE RadPipeOpen( char* Name, int nMsgSize, int nMaxMsgs, pfnCommonCallBack );
+BOOL RadPipeWrite( PRADPIPE, PVOID pMessage );
+BOOL RadPipeClose( PRADPIPE );
+
+/* debug */
+#define ExecBreak( Text ) DebugFatalErrorBreak( Text, __FILE__, __LINE__ )
+#define ExecBreakIf( Cond, Text ) if( Cond ) ExecBreak( Text )
+void DebugFatalErrorBreak( char* pszText, char* pszFile, int nLine );
+void SpecialDebugBreak( void );
+
+/* misc */
+char* GetDateTimeString( time_t );
+char* GetOption( char* pszSection, char* pszOption, char* pszDefaultValue );
+char* ParamGetValue( int argc, char** argv, char* pszParam, char* pszDefaultValue );
+BOOL ParamIsPresent( int argc, char** argv, char* pszParam );
+void SpecialSleep( int nSeconds );
+BOOL SocketKeepAlive( int hSocket, BOOL );
+BOOL PlatformLayerInit( void );
+BOOL PlatformLayerDown( void );
+
+/* management */
+
+typedef struct
+{
+ char* pszInput;
+ char* pszOutput;
+ int nOutput;
+
+}MngmCommandData_t, *pMngmCommandData_t;
+
+BOOL MngmPortInit( int MngmPort, pfnCommonCallBack pfnMngmCallBack, BOOL bTelent );
+BOOL MngmTelnetSendString( int hSocket, char* pszString );
+
+/* packing / unpacking for network messages */
+void jcStringPack( char* pszString, UCHAR** ppszBuffer, int* pnSize );
+char* jcStringUnpack( UCHAR** ppszBuffer );
+void jcULongPack( ULONG uLong, UCHAR** ppszBuffer, int* pnSize );
+ULONG jcULongUnpack( UCHAR** ppszBuffer );
+void jcUShortPack( USHORT uShort, UCHAR** ppszBuffer, int* pnSize );
+USHORT jcUShortUnpack( UCHAR** ppszBuffer );
+void jcBufferPack( PVOID pData, USHORT nDataSize, UCHAR** ppszBuffer, int* pnSize );
+PVOID jcBufferUnpack( USHORT nDataSize, UCHAR** ppszBuffer );
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _INC_SUPPORT */