cdrserver.cpp
上传用户:romrleung
上传日期:2022-05-23
资源大小:18897k
文件大小:70k
源码类别:

MySQL数据库

开发平台:

Visual C++

  1. /* Copyright (C) 2003 MySQL AB
  2.    This program is free software; you can redistribute it and/or modify
  3.    it under the terms of the GNU General Public License as published by
  4.    the Free Software Foundation; either version 2 of the License, or
  5.    (at your option) any later version.
  6.    This program is distributed in the hope that it will be useful,
  7.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  8.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  9.    GNU General Public License for more details.
  10.    You should have received a copy of the GNU General Public License
  11.    along with this program; if not, write to the Free Software
  12.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
  13. /* **************************************************************** */
  14. /*                                                                  */
  15. /*  S E R V . T C P                                                 */
  16. /*  * This is an example program that demonstrates the use of       */
  17. /*    stream sockets as an IPC mechanism. This contains the server, */
  18. /*    and is intended to operate in conjunction with the client     */
  19. /*    program found in client.tcp. Together, these two programs     */
  20. /*    demonstrate many of the features of sockets, as well as good  */
  21. /*    conventions for using these features.                         */
  22. /*  * This program provides a service called "example". In order for*/
  23. /*    it to function, an entry for it needs to exist in the         */
  24. /*    ./etc/services file. The port address for this service can be */
  25. /*    any port number that is likely to be unused, such as 22375,   */
  26. /*    for example. The host on which the client will be running     */
  27. /*    must also have the same entry (same port number) in its       */
  28. /*    ./etc/services file.                                          */
  29. /* **************************************************************** */
  30. #include <ndb_global.h>
  31. /******** NDB INCLUDE ******/
  32. #include <NdbApi.hpp>
  33. /***************************/
  34. /*#include <sys/shm.h>*/
  35. #include <pthread.h>
  36. #include <sys/sem.h>
  37. #include <sys/shm.h>
  38. #include <netinet/in.h>
  39. #include <signal.h>
  40. #include <netdb.h>
  41. #include <time.h>
  42. #include <synch.h>
  43. #include <sched.h>
  44. extern "C" {
  45. #include "utv.h"
  46. #include "vcdrfunc.h"
  47. #include "bcd.h"
  48. }
  49. #ifndef TESTLEV
  50. #define TESTLEV
  51. #endif
  52. //#define DEBUG
  53. //#define MYDEBUG
  54. //#define SETDBG
  55. //#define ops_before_exe 64
  56. #define MAXOPSEXEC 1024
  57. /* Used in nanosleep */
  58. /**** NDB ********/
  59. static  int bTestPassed;
  60. void create_table(Ndb* pMyNdb);
  61. void error_handler(const char* errorText);
  62. /*****************/
  63. static struct timespec tmspec1;
  64. static int server(long int);
  65. /* Function for initiating the cdr-area and make it clean for ongoing calls */
  66. static int s;                          /* connected socket descriptor */
  67. static int ls;                         /* listen socket descriptor */
  68. static struct hostent *hp;             /* pointer to host info for remote host */
  69. static struct servent *sp;             /* pointer to service information */
  70. struct linger linger;           /* allow a lingering, graceful close; */
  71.                                 /* used when setting SO_LINGER */
  72. static struct sockaddr_in myaddr_in;   /* for local socket address */
  73. static struct sockaddr_in peeraddr_in; /* for peer socket address */
  74. static FILE *fi;                       /* Log output */
  75. static char temp[600]="";
  76. static int ops_before_exe = 1;  /* Number of operations per execute, default is 1,
  77.    but it can be changed with the -o parameter. */
  78. /*----------------------------------------------------------------------
  79.      M A I N
  80.      * This routine starts the server. It forks, leaving the child
  81.      to do all the work, so it does not have to be run in the
  82.      background. It sets up the listen socket, and for each incoming
  83.      connection, it forks a child process to process the data. It
  84.      will loop forever, until killed by a signal.
  85.   ----------------------------------------------------------------------*/
  86. /****** NDB *******/
  87. static char *tableName = "VWTABLE";
  88. /******************/
  89. #include <iostream>
  90. using namespace std;
  91. int main(int argc, const char** argv)
  92. {
  93.   ndb_init();
  94.         /******** NDB ***********/
  95. /*
  96.         Ndb                   MyNdb( "TEST_DB" );
  97.         int                   tTableId;
  98. */
  99.         /************************/
  100. char  tmpbuf[400];
  101. /* Loop and status variables */
  102. int  i,j,found;
  103. /* Used by the server */
  104.         int  addrlen;
  105. /* return code used with functions */
  106. int  rc;
  107.   i = 1;
  108.   while (argc > 1)
  109.   {
  110.     if (strcmp(argv[i], "-o") == 0)
  111.     {
  112.       ops_before_exe = atoi(argv[i+1]);
  113.       if ((ops_before_exe < 1) || (ops_before_exe > MAXOPSEXEC))
  114.       {
  115. cout << "Number of operations per execute must be at least 1, and at most " << MAXOPSEXEC << endl;
  116. exit(1);
  117.       }
  118.     }
  119.     else
  120.     {
  121.       cout << "Invalid parameter!" << endl << "Look in cdrserver.C for more info." << endl;
  122.       exit(1);
  123.     }
  124.     argc -= 2;
  125.     i = i + 2;
  126.   }
  127.         /* Setup log handling */
  128.         logname(temp,"Cdrserver","Mother","");
  129. puts(temp);
  130.         fi=fopen(temp,"w");
  131. if (fi == NULL)
  132. {
  133. perror(argv[0]);
  134. exit(EXIT_FAILURE);
  135. }
  136.         m2log(fi,"Initiation of program");
  137.         /***** NDB ******/
  138. /*
  139.         MyNdb.init();
  140.         if (MyNdb.waitUntilReady(30) != 0)
  141.         {
  142.                 puts("Not ready");
  143.                 exit(-1);
  144.         }
  145.         tTableId = MyNdb.getTable()->openTable(tableName);
  146.         if (tTableId == -1)
  147.         {
  148.                 printf("%d: Creating table",getpid());
  149.                 create_table(&MyNdb);
  150.         }
  151. else printf("%d: Table already create",getpid());
  152. */
  153.         /****************/
  154.         /* clear out address structures */
  155.         memset ((char *)&myaddr_in, 0, sizeof(struct sockaddr_in));
  156.         memset ((char *)&peeraddr_in, 0, sizeof(struct sockaddr_in));
  157.         m2log(fi,"Socket setup starting");
  158.         /* Set up address structure for the listen socket. */
  159.         myaddr_in.sin_family = AF_INET;
  160.         /* The server should listen on the wildcard address,            */
  161.         /*   rather than its own internet address. This is              */
  162.         /*   generally good practice for servers, because on            */
  163.         /*   systems which are connected to more than one               */
  164.         /*   network at once will be able to have one server            */
  165.         /*   listening on all networks at once. Even when the           */
  166.         /*   host is connected to only one network, this is good        */
  167.         /*   practice, because it makes the server program more         */
  168.         /*   portable.                                                  */
  169.         myaddr_in.sin_addr.s_addr = INADDR_ANY;
  170.         /* Find the information for the "cdrserver" server              */
  171.         /*   in order to get the needed port number.                    */
  172.         sp = getservbyname ("cdrserver", "tcp");
  173.         if (sp == NULL) {
  174.                 m2log(fi,"Service cdrserver not found in /etc/services");
  175.                 m2log(fi,"Terminating.");
  176.                 exit(EXIT_FAILURE);
  177.         }
  178.         myaddr_in.sin_port = sp->s_port;
  179.         /* Create the listen socket.i                                   */
  180.         ls = socket (AF_INET, SOCK_STREAM, 0);
  181.         if (ls == -1) {
  182.                 m2log(fi,"Unable to create socket");
  183.                 m2log(fi,"Terminating.");
  184.                 exit(EXIT_FAILURE);
  185.         }
  186.         printf("Socket createdn");
  187.         printf("Wait..........n");
  188.         /* Bind the listen address to the socket.                       */
  189.         if (bind(ls,(struct sockaddr*)&myaddr_in, sizeof(struct sockaddr_in)) == -1) {
  190.                 m2log(fi,"Unable to bind address");
  191.                 m2log(fi,"Terminating.");
  192.                 exit(EXIT_FAILURE);
  193.         }
  194.         /* Initiate the listen on the socket so remote users            */
  195.         /*   can connect. The listen backlog is set to 5, which         */
  196.         /*   is the largest currently supported.                        */
  197.         if (listen(ls, 5) == -1) {
  198.                 m2log(fi,"Unable to listen on socket");
  199.                 m2log(fi,"Terminating.");
  200.                 exit(EXIT_FAILURE);
  201.         }
  202.         /* Now, all the initialization of the server is                 */
  203.         /*   complete, and any user errors will have already            */
  204.         /*   been detected. Now we can fork the daemon and              */
  205.         /*   return to the user. We need to do a setpgrp                */
  206.         /*   so that the daemon will no longer be associated            */
  207.         /*   with the user's control terminal. This is done             */
  208.         /*   before the fork, so that the child will not be             */
  209.         /*   a process group leader. Otherwise, if the child            */
  210.         /*   were to open a terminal, it would become associated        */
  211.         /*   with that terminal as its control terminal. It is          */
  212.         /*   always best for the parent to do the setpgrp.              */
  213.         m2log(fi,"Socket setup completed");
  214.         m2log(fi,"Start server");
  215.         setpgrp();
  216. /* Initiate the tmspec struct for use with nanosleep() */
  217.         tmspec1.tv_sec = 0;
  218.         tmspec1.tv_nsec = 1;
  219. printf("Waiting for client to connect.........n");
  220. printf("Donen");
  221.         switch (fork()) {
  222.            case -1: /* Unable to fork, for some reason. */
  223.                 m2log(fi,"Failed to start server");
  224.                 m2log(fi,"Terminating.");
  225.                 fclose(fi);
  226.                 perror(argv[0]);
  227.                 fprintf(stderr, "%s: unable to fork daemonn", argv[0]);
  228.                 exit(EXIT_FAILURE);
  229.    break;
  230.            case 0: /* The child process (daemon) comes here.            */
  231.                 m2log(fi,"Server started");
  232.                /* Close stdin and stderr so that they will not          */
  233.                /*   be kept open. Stdout is assumed to have been        */
  234.                /*   redirected to some logging file, or /dev/null.      */
  235.                /*   From now on, the daemon will not report any         */
  236.                /*   error messages. This daemon will loop forever,      */
  237.                /*   waiting for connections and forking a child         */
  238.                /*   server to handle each one.                          */
  239.                close((int)stdin);
  240.                close((int)stderr);
  241.                /* Set SIGCLD to SIG_IGN, in order to prevent            */
  242.                /*   the accumulation of zombies as each child           */
  243.                /*   terminates. This means the daemon does not          */
  244.                /*   have to make wait calls to clean them up.           */
  245.                signal(SIGCLD, SIG_IGN);
  246.                for(EVER) {
  247. if ((checkchangelog(fi,temp))==0)
  248.                           m2log(fi,"Waiting for connection");
  249.                        /* Note that addrlen is passed as a pointer      */
  250.                        /*  so that the accept call can return the       */
  251.                        /*  size of the returned address.                */
  252.                        addrlen = sizeof(struct sockaddr_in);
  253.                        /* This call will block until a new              */
  254.                        /*   connection arrives. Then, it will           */
  255.                        /*   return the address of the connecting        */
  256.                        /*   peer, and a new socket descriptor, s,       */
  257.                        /*   for that connection.                        */
  258.                         s = accept(ls,(struct sockaddr*) &peeraddr_in, &addrlen);
  259.        #ifdef MYDEBUG
  260.    puts("accepted");
  261.        #endif
  262. if ((checkchangelog(fi,temp))==0)
  263.                           m2log(fi,"Connection attempt from a client");
  264. if ((checkchangelog(fi,temp))==0)
  265.                           m2log(fi,"Start communication server");
  266.                         if ( s == -1) exit(EXIT_FAILURE);
  267.                         switch (fork()) {
  268.                            case -1: /* Can't fork, just exit. */
  269. if ((checkchangelog(fi,temp))==0)
  270.                                   m2log(fi,"Start communication server failed.");
  271.                                 exit(EXIT_FAILURE);
  272.    break;
  273.                            case 0: /* Child process comes here. */
  274. /* Get clients adress and save it in the info area */
  275. /* Keep track of how many times the client connects to the server */
  276. printf("Connect attempt from client %un",peeraddr_in.sin_addr.s_addr);
  277.                                 server(peeraddr_in.sin_addr.s_addr);
  278.                                 exit(EXIT_FAILURE);
  279.    break;
  280.                            default: /* Daemon process comes here. */
  281.                                 /* The daemon needs to remember         */
  282.                                 /*     to close the new accept socket   */
  283.                                 /*     after forking the child. This    */
  284.                                 /*     prevents the daemon from running */
  285.                                 /*     out of file descriptor space. It */
  286.                                 /*     also means that when the server  */
  287.                                 /*     closes the socket, that it will  */
  288.                                 /*     allow the socket to be destroyed */
  289.                                 /*     since it will be the last close. */
  290.                                 close(s);
  291.    break;
  292.                         }
  293.                }
  294.            default: /* Parent process comes here. */
  295.                exit(EXIT_FAILURE);
  296.        }
  297.   return EXIT_SUCCESS;
  298. }
  299. /*----------------------------------------------------------------------
  300.     S E R V E R
  301.     * This is the actual server routine that the daemon forks to
  302.       handle each individual connection. Its purpose is to receive
  303.       the request packets from the remote client, process them,
  304.       and return the results to the client. It will also write some
  305.       logging information to stdout.
  306.   ----------------------------------------------------------------------*/
  307. server(long int servernum)
  308. {
  309. /******** NDB ***********/
  310.    Ndb                   MyNdb( "TEST_DB" );
  311.    int                   tTableId;
  312. NdbConnection *MyTransaction;
  313. NdbOperation *MyOperation;
  314. int check;
  315. int c1 = 0;
  316. int c2 = 0;
  317. int c3 = 0;
  318. int c4 = 0;
  319. int act_index = 0;
  320. /************************/
  321.         register unsigned int   reqcnt;         /* keeps count of number of requests */
  322.         register unsigned int   i;           /* Loop counters */
  323. register int x;
  324.         register short          done;           /* Loop variable */
  325. short int found;
  326. /* The server index number */
  327. int  thisServer;
  328. /* Variables used to keep track of some statistics */
  329. time_t ourtime;
  330. time_t tmptime;
  331. int  tmpvalue;
  332. long int tmptransfer;
  333. long int transfer;
  334. int ops = 0;
  335. /* Variables used by the server */
  336.         char     buf[400];       /* This example uses 10 byte messages. */
  337.         char     *inet_ntoa();
  338.         char     *hostname;      /* points to the remote host's name string */
  339.         int      len;
  340.         int      rcvbuf_size;
  341. long ctid;
  342.         unsigned char  uc;
  343. /* Variables used by the logging facilitiy */
  344.         char     msg[600];
  345.         char     crap[600];
  346.         char     lognamn[600];
  347.         FILE     *log;
  348. /* scheduling parameter for pthread */
  349. struct sched_param  param1,param2,param3;
  350.         /* Header information */
  351. /* cdrtype not used */
  352.         /*short            cdrtype;   */   /* 1 CDR Typ                                            */
  353.         short            cdrlen;         /* 2 CDR recored length in bytes excluding CDR type     */
  354.         short            cdrsubtype;     /* 1 CDR subtype                                        */
  355.         unsigned int     cdrid;          /* 8 CDR unique number of each call                     */
  356.         unsigned int     cdrtime;        /* 4 CDR Time in seconds                                */
  357.         short            cdrmillisec;    /* 2 CDR Milliseconds                                   */
  358.         short            cdrstatus;      /* 1 CDR For future use                                 */
  359.         short            cdrequipeid;    /* 1 CDR Equipment id                                   */
  360.         int              cdrreserved1;   /* 4 CDR For future use                                 */
  361.         /* Defined or calculated for each record */
  362.         int              cdrrestlen;     /*   Unprocessed data left in record in bytes   */
  363.         /* Gemensamma datatyper */
  364.         unsigned short   parmtype_prev;  /* 1 Parameter type                                     */
  365.         unsigned short   parmtype;       /* 1 Parameter type                                     */
  366.         unsigned short   parmlen;        /* 1 Parameter type                                     */
  367. int rc; /* return code for functions */
  368. /* Attribute object used with threads */
  369. pthread_attr_t  attr1;
  370. pthread_attr_t  attr2;
  371. pthread_attr_t  attr3;
  372. struct cdr_record *tmpcdrptr,*ftest;
  373. void *dat;
  374. int error_from_client = 0;
  375.         /* Konstanter           */
  376.         const int        headerlen = 24;         /*   Length of header record                    */
  377.         parmtype_prev = 99;
  378. reqcnt = 0;
  379.         /* Close the listen socket inherited from the daemon. */
  380.         close(ls);
  381. printf("Use the readinfo program to get information about server statusnn");
  382. if((checkchangelog(fi,temp))==0)
  383.           c2log(fi,"Communication server started");
  384.         /* Look up the host information for the remote host     */
  385.         /* that we have connected with. Its internet address    */
  386.         /* was returned by the accept call, in the main         */
  387.         /* daemon loop above.                                   */
  388.         hp=gethostbyaddr((char *) &peeraddr_in.sin_addr,sizeof(struct in_addr),peeraddr_in.sin_family);
  389.         if (hp == NULL) {
  390.                 /* The information is unavailable for the remote        */
  391.                 /* host. Just format its internet address to be         */
  392.                 /* printed out in the logging information. The          */
  393.                 /* address will be shown in "internet dot format".      */
  394. /*
  395.                 hostname = inet_ntoa(peeraddr_in.sin_addr);
  396. */
  397. sprintf(hostname,"Test");
  398.                 logname(lognamn,"Cdrserver","Child",hostname);
  399.         }
  400.         else {
  401.                 hostname = hp->h_name; /* point to host's name */
  402.                 logname(lognamn,"Cdrserver","Child",hostname);
  403.         }
  404.         log=fopen(lognamn,"w");
  405. if (log == NULL)
  406. {
  407. perror(hostname);
  408. exit(EXIT_FAILURE);
  409. }
  410.         n2log(log,"Setup in progress");
  411.         /* Log a startup message. */
  412.         /* The port number must be converted first to host byte */
  413.         /* order before printing. On most hosts, this is not    */
  414.         /* necessary, but the ntohs() call is included here so  */
  415.         /* that this program could easily be ported to a host   */
  416.         /* that does require it.                                */
  417.         BaseString::snprintf(msg,sizeof(msg),"Startup from %s port %u",hostname,ntohs(peeraddr_in.sin_port));
  418. if ((checkchangelog(fi,temp))==0)
  419.           c2log(fi,msg);
  420.         n2log(log,msg);
  421.         BaseString::snprintf(msg,sizeof(msg),"For further information, see log(%s)",lognamn);
  422. if ((checkchangelog(fi,temp))==0)
  423.           c2log(fi,msg);
  424.         /* Set the socket for a lingering, graceful close.              */
  425.         /* This will cause a final close of this socket to wait until   */
  426.         /* all * data sent on it has been received by the remote host.  */
  427.         linger.l_onoff  =1;
  428.         linger.l_linger =0;
  429.         if (setsockopt(s, SOL_SOCKET, SO_LINGER,(const char*)&linger,sizeof(linger)) == -1) {
  430.                 BaseString::snprintf(msg,sizeof(msg),"Setting SO_LINGER, l_onoff=%d, l_linger=%d",linger.l_onoff,linger.l_linger);
  431. if ((checkchangelog(log,lognamn))==0)
  432.            n2log(log,msg);
  433.                 goto errout;
  434.         }
  435.         /* Set the socket for a lingering, graceful close.                              */
  436.         /* This will cause a final close of this socket to wait until all * data sent   */
  437.         /* on it has been received by the remote host.                                  */
  438.         rcvbuf_size=64*1024;
  439.         if (setsockopt(s, SOL_SOCKET, SO_RCVBUF,(const char*) &rcvbuf_size,sizeof(rcvbuf_size)) == -1) {
  440.                 BaseString::snprintf(msg,sizeof(msg),"Setting SO_RCVBUF = %d",rcvbuf_size);
  441. if ((checkchangelog(log,lognamn))==0)
  442.            n2log(log,msg);
  443.                 goto errout;
  444.         }
  445.         /* Set nodelay on socket */
  446.         n2log(log,"Port setup complete");
  447.         /* Go into a loop, receiving requests from the remote           */
  448.         /* client. After the client has sent the last request,          */
  449.         /* it will do a shutdown for sending, which will cause          */
  450.         /* an end-of-file condition to appear on this end of the        */
  451.         /* connection. After all of the client's requests have          */
  452.         /* been received, the next recv call will return zero           */
  453.         /* bytes, signalling an end-of-file condition. This is          */
  454.         /* how the server will know that no more requests will          */
  455.         /* follow, and the loop will be exited.                         */
  456.         n2log(log,"Setup completed");
  457. /* Fetch the process id for the server */
  458. /* Inititate the variables used for counting transfer rates and rec/sec */
  459. tmpvalue    = 0;
  460. tmptime     = 0;
  461. tmptransfer = 0;
  462. transfer = 0;
  463. printf("Client %s connectednStarting to process the datann",hostname);
  464. tmpcdrptr = (struct cdr_record*)malloc(sizeof(struct cdr_record));
  465. /***** NDB ******/
  466. MyNdb.init();
  467. if (MyNdb.waitUntilReady(30) != 0)
  468. {
  469. puts("Not ready");
  470. exit(-1);
  471. }
  472. tTableId = MyNdb.getTable()->openTable(tableName);
  473.        if (tTableId == -1) 
  474. {
  475. printf("%d: Creating table",getpid());
  476.          create_table(&MyNdb);
  477. }
  478. else printf("%d: Table already created",getpid());
  479.       
  480. /****************/
  481.         while (len = recv(s,buf,headerlen,MSG_WAITALL)) {
  482.                 if (len == -1) {
  483.          snprintf(msg,sizeof(msg),"Error from recv");
  484. if ((checkchangelog(log,lognamn))==0)
  485.            n2log(log,msg);
  486.                         goto errout; /* error from recv */
  487.                 }
  488.                 /* The reason this while loop exists is that there              */
  489.                 /* is a remote possibility of the above recv returning          */
  490.                 /* less than 10 bytes. This is because a recv returns           */
  491.                 /* as soon as there is some data, and will not wait for         */
  492.                 /* all of the requested data to arrive. Since 10 bytes          */
  493.                 /* is relatively small compared to the allowed TCP              */
  494.                 /* packet sizes, a partial receive is unlikely. If              */
  495.                 /* this example had used 2048 bytes requests instead,           */
  496.                 /* a partial receive would be far more likely.                  */
  497.                 /* This loop will keep receiving until all 10 bytes             */
  498.                 /* have been received, thus guaranteeing that the               */
  499.                 /* next recv at the top of the loop will start at               */
  500.                 /* the begining of the next request.                            */
  501.                 for (;len < headerlen;) {
  502.                         x = recv(s,buf,(headerlen-len),0);
  503.                         if (x == -1) {
  504.          snprintf(msg,sizeof(msg),"Error from recv");
  505. if ((checkchangelog(log,lognamn))==0)
  506.            n2log(log,msg);
  507.                                 goto errout; /* error from recv */
  508.                         }
  509.                         len=len+x;
  510.                 }
  511.                 if (ops == 0) {
  512.                MyTransaction = MyNdb.startTransaction();
  513.            if (MyTransaction == NULL)
  514.          error_handler(MyNdb.getNdbErrorString());
  515.                 }//if
  516.        MyOperation = MyTransaction->getNdbOperation(tableName);
  517.        if (MyOperation == NULL)
  518.          error_handler(MyTransaction->getNdbErrorString());
  519.                 /*------------------------------------------------------*/
  520.                 /* Parse header of CDR records                          */
  521.                 /*------------------------------------------------------*/
  522.                 /*------------------------------------------------------*/
  523.                 /* 1. Type of cdr                                       */
  524.                 /*------------------------------------------------------*/
  525. /* Not used for the moment
  526.                 cdrtype=(char)buf[0];
  527. */
  528.                 /*------------------------------------------------------*/
  529.                 /* 2. Total length of CDR                               */
  530.                 /*------------------------------------------------------*/
  531.                 swab(buf+1,buf+1,2);
  532.                 memcpy(&cdrlen,buf+1,2);
  533.                 /*------------------------------------------------------*/
  534.                 /* 3. Partial type of CDR                               */
  535.                 /*------------------------------------------------------*/
  536.                 cdrsubtype=(char)buf[3];
  537. switch (cdrsubtype)
  538. {
  539. case 0:
  540. c1++;
  541. tmpcdrptr->CallAttemptState = 1;
  542. check = MyOperation->insertTuple();
  543. break;
  544. case 1:
  545. c2++;
  546. tmpcdrptr->CallAttemptState = 2;
  547. check = MyOperation->updateTuple();
  548. break;
  549. case 2:
  550. c3++;
  551. tmpcdrptr->CallAttemptState = 3;
  552. check = MyOperation->deleteTuple();
  553. break;
  554. case 3:
  555. c4++;
  556. tmpcdrptr->CallAttemptState = 4;
  557. check = MyOperation->deleteTuple();
  558. break;
  559. if (check == -1)
  560. error_handler(MyTransaction->getNdbErrorString());
  561. }
  562.                 /*cdrsubtype=(cdrsubtype << 24) >> 24;*/
  563.                 /*------------------------------------------------------*/
  564.                 /* 4. ID number                                         */
  565.                 /*------------------------------------------------------*/
  566.                 /*swab(buf+4,buf+4,4);*/ /* ABCD -> BADC */
  567. /*
  568.                 swab(buf+4,buf+4,4);
  569.                 swab(buf+5,buf+5,2);
  570.                 swab(buf+6,buf+6,2);
  571.                 swab(buf+4,buf+4,2);
  572.                 swab(buf+5,buf+5,2);
  573. */
  574.                 memcpy(&cdrid,buf+4,4);
  575. tmpcdrptr->CallIdentificationNumber = cdrid;
  576. #ifdef SETDBG
  577. puts("CIN");
  578. #endif
  579. check = MyOperation->equal("CIN",(char*)&cdrid);
  580. if (check == -1)
  581. error_handler(MyTransaction->getNdbErrorString());
  582. #ifdef SETDBG
  583. puts("CAS");
  584. #endif
  585. if (cdrsubtype < 2)
  586. {
  587. check = MyOperation->setValue("CAS",(char*)&cdrsubtype);
  588. if (check == -1)
  589. error_handler(MyTransaction->getNdbErrorString());
  590. }
  591.                 /*------------------------------------------------------*/
  592.                 /* 5. Time stamp                                        */
  593.                 /*------------------------------------------------------*/
  594.                 swab(buf+12,buf+12,4);
  595.                 swab(buf+13,buf+13,2);
  596.                 swab(buf+14,buf+14,2);
  597.                 swab(buf+12,buf+12,2);
  598.                 swab(buf+13,buf+13,2);
  599.                 memcpy(&cdrtime,buf+12,4);
  600. switch (cdrsubtype)
  601. {
  602. case 0:
  603. #ifdef SETDBG
  604. puts("START_TIME");
  605. #endif
  606. check = MyOperation->setValue("START_TIME",(char*)&cdrtime);
  607. break;
  608. case 1:
  609. #ifdef SETDBG
  610. puts("Start1");
  611. #endif
  612. check = MyOperation->setValue("StartOfCharge",(char*)&cdrtime);
  613. break;
  614. case 2:
  615. #ifdef SETDBG
  616. puts("Start2");
  617. #endif
  618. /*
  619. check = MyOperation->setValue("StopOfCharge",(char*)&cdrtime);
  620. */
  621. check = 0;
  622. break;
  623. if (check == -1)
  624. error_handler(MyTransaction->getNdbErrorString());
  625. }
  626.                 /*------------------------------------------------------*/
  627.                 /* 6. Milliseconds                                      */
  628.                 /*------------------------------------------------------*/
  629. /* Not used by application
  630.                 swab(buf+16,buf+16,2);
  631.                 memcpy(&cdrmillisec,buf+16,2);
  632. */
  633.                 /*------------------------------------------------------*/
  634.                 /* 7. CDR status reserverd for future use               */
  635.                 /*------------------------------------------------------*/
  636. /* Not used by application
  637.                 memcpy(&cdrstatus,buf+18,1);
  638. */
  639.                 /*------------------------------------------------------*/
  640.                 /* 8. CDR equipe id, number of sending equipement       */
  641.                 /*------------------------------------------------------*/
  642. /* Not used by application
  643.                 memcpy(&cdrequipeid,buf+19,1);
  644. */
  645.                 /*cdrequipeid=(cdrequipeid << 24) >> 24;*/
  646.                 /*------------------------------------------------------*/
  647.                 /* 9. CDR reserverd for furter use                      */
  648.                 /*------------------------------------------------------*/
  649. /* Not used by applikation
  650.                 swab(buf+20,buf+20,4);
  651.                 swab(buf+21,buf+21,2);
  652.                 swab(buf+22,buf+22,2);
  653.                 swab(buf+20,buf+20,2);
  654.                 swab(buf+21,buf+21,2);
  655.                 memcpy(&cdrreserved1,buf+20,4);
  656. */
  657.                 /*------------------------------------------------------*/
  658.                 /* calculate length of datapart in record               */
  659.                 /* Formula recordlength-headerlen-1                     */
  660.                 /*------------------------------------------------------*/
  661.                 cdrrestlen=cdrlen-(headerlen-1);
  662.                 /*------------------------------------------------------*/
  663.                 /* Finished with header                                 */
  664.                 /*------------------------------------------------------*/
  665.                 /* Read remaining cdr data into buffer for furter       */
  666.                 /* handling.                                            */
  667.                 /*------------------------------------------------------*/
  668.                 len = recv(s,buf,cdrrestlen,MSG_WAITALL);
  669.                 if (len == -1) {
  670.          snprintf(msg,sizeof(msg),"Error from recv");
  671. if ((checkchangelog(log,lognamn))==0)
  672.            n2log(log,msg);
  673.                         goto errout; /* error from recv */
  674.                 }
  675.                 for (;len<cdrrestlen;) {
  676.                         x = recv(s,buf,len-cdrrestlen,0);
  677.                         if (x == -1) {
  678.          snprintf(msg,sizeof(msg),"Error from recv");
  679. if ((checkchangelog(log,lognamn))==0)
  680.            n2log(log,msg);
  681.                                 goto errout; /* error from recv */
  682.                         }
  683.                         len=len+x;
  684.                 }
  685.                 done=FALSE;
  686. /* Count the transfer/sec */
  687. tmptransfer += cdrlen;
  688. if (cdrsubtype > 1) 
  689. {
  690. #ifdef SETDBG
  691. puts("Going to execute");
  692. #endif
  693.                                 ops++;
  694.                                 if (ops == ops_before_exe) {
  695.                                   ops = 0;
  696.                    check = MyTransaction->execute(Commit, CommitAsMuchAsPossible);
  697.                    if ((check == -1) && (MyTransaction->getNdbError() != 0))
  698.                          error_handler(MyTransaction->getNdbErrorString());
  699.                    MyNdb.closeTransaction(MyTransaction);
  700.   #ifdef SETDBG
  701. puts("Transaction closed");
  702.   #endif
  703.                                 }//if
  704. reqcnt++;
  705. continue;
  706. }
  707.                 for (x=0;x<=cdrrestlen && !done && cdrrestlen > 1;) {
  708.                         uc=buf[x];
  709.                         parmtype=uc;
  710.                         /*parmtype=(parmtype << 24) >> 24;*/ /* Modified in sun worked in hp */
  711.                         parmlen = buf[x+1];
  712.                         /*parmlen =(parmlen << 24) >> 24;*/
  713.                         x+=2;
  714.                         switch (parmtype) {
  715.                                 case 4:         /* Called party number */
  716.                                         bcd_decode2(parmlen,&buf[x],crap);
  717. tmpcdrptr->BSubscriberNumberLength = (char)parmlen;
  718.                                         strcpy(tmpcdrptr->BSubscriberNumber,crap);
  719. tmpcdrptr->BSubscriberNumber[parmlen] = '';
  720.                                         x=x+(parmlen/2);
  721.                                         if (parmlen % 2) x++;
  722.                                         tmpcdrptr->USED_FIELDS |=  B_BSubscriberNumber;
  723. #ifdef SETDBG
  724. puts("BNumber");
  725. #endif
  726. check = MyOperation->setValue("BNumber",(char*)&tmpcdrptr->BSubscriberNumber);
  727. if (check == -1)
  728. error_handler(MyTransaction->getNdbErrorString());
  729.                                 break;
  730.                                 case 9:         /* Calling Partys cataegory */
  731.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  732.                                         else tmpcdrptr->ACategory=(char)buf[x];
  733.                                         x+=parmlen;
  734.                                         tmpcdrptr->USED_FIELDS |= B_ACategory;
  735. #ifdef SETDBG
  736. puts("ACategory");
  737. #endif
  738. check = MyOperation->setValue("ACategory",(char*)&tmpcdrptr->ACategory);
  739. if (check == -1)
  740. error_handler(MyTransaction->getNdbErrorString());
  741.                                 break;
  742.                                 case 10:        /* Calling Party Number */
  743.                                         bcd_decode2(parmlen,&buf[x],crap);
  744. tmpcdrptr->ASubscriberNumberLength = (char)parmlen;
  745.                                         strcpy(tmpcdrptr->ASubscriberNumber,crap);
  746. tmpcdrptr->ASubscriberNumber[parmlen] = '';
  747.                                         x=x+(parmlen/2);
  748.                                         if (parmlen % 2) x++;
  749.                                         tmpcdrptr->USED_FIELDS |= B_ASubscriberNumber;
  750. #ifdef SETDBG
  751. puts("ANumber");
  752. #endif
  753. check = MyOperation->setValue("ANumber",(char*)&tmpcdrptr->ASubscriberNumber);
  754. if (check == -1)
  755. error_handler(MyTransaction->getNdbErrorString());
  756.                                 break;
  757.                                 case 11:        /* Redirecting number */
  758.                                         bcd_decode2(parmlen,&buf[x],crap);
  759.                                         strcpy(tmpcdrptr->RedirectingNumber,crap);
  760.                                         x=x+(parmlen/2);
  761.                                         if (parmlen % 2) x++;
  762.                                         tmpcdrptr->USED_FIELDS |= B_RedirectingNumber;
  763. #ifdef SETDBG
  764. puts("RNumber");
  765. #endif
  766. check = MyOperation->setValue("RNumber",(char*)&tmpcdrptr->RedirectingNumber);
  767. if (check == -1)
  768. error_handler(MyTransaction->getNdbErrorString());
  769.                                 break;
  770.                                 case 17:        /* Called partys category */
  771.                                         if (parmlen != 1) printf("ERROR: Called partys category has wrong length %dn",parmlen);
  772.                                         else tmpcdrptr->EndOfSelectionInformation=(char)buf[x];
  773.                                         x+=parmlen;
  774.                                         tmpcdrptr->USED_FIELDS |= B_EndOfSelectionInformation;
  775. #ifdef SETDBG
  776. puts("EndOfSelInf");
  777. #endif
  778. check = MyOperation->setValue("EndOfSelInf",(char*)&tmpcdrptr->EndOfSelectionInformation);
  779. if (check == -1)
  780. error_handler(MyTransaction->getNdbErrorString());
  781.                                 break;
  782.                                 case 18:        /* Release reason */
  783.                                         if (parmlen != 1) printf("ERROR: Release reason has wrong length %dn",parmlen);
  784.                                         else tmpcdrptr->CauseCode=(char)buf[x];
  785.                                         x+=parmlen;
  786.                                         tmpcdrptr->USED_FIELDS |= B_CauseCode;
  787. #ifdef SETDBG
  788. puts("CauseCode");
  789. #endif
  790. check = MyOperation->setValue("CauseCode",(char*)&tmpcdrptr->CauseCode);
  791. if (check == -1)
  792. error_handler(MyTransaction->getNdbErrorString());
  793.                                 break;
  794.                                 case 19:        /* Redirection information */
  795.                                         switch (parmlen) {
  796.                                                 case 1:
  797.                                                         tmpcdrptr->ReroutingIndicator= (char)buf[x];
  798.                                                         tmpcdrptr->USED_FIELDS |= B_ReroutingIndicator;
  799.                                                 break;
  800.                                                 case 2:
  801.                                                         swab(buf+x,buf+x,2);
  802.                                                         tmpcdrptr->ReroutingIndicator= buf[x];
  803.                                                         tmpcdrptr->USED_FIELDS |= B_ReroutingIndicator;
  804.                                                 break;
  805.                                                 default :
  806.                                                         BaseString::snprintf(msg,sizeof(msg),"ERROR: Redirection information has wrong length %dn",parmlen);
  807.    if ((checkchangelog(log,lognamn))==0)
  808.                                                           n2log(log,msg);
  809.                                                 break;
  810. #ifdef SETDBG
  811. puts("RI");
  812. #endif
  813. check = MyOperation->setValue("RI",(char*)&tmpcdrptr->ReroutingIndicator);
  814. if (check == -1)
  815. error_handler(MyTransaction->getNdbErrorString());
  816.                                         }
  817.                                         x+=parmlen;
  818.                                 break;
  819.                                 case 32:        /* User to user information */
  820.                                         if (parmlen != 1) printf("ERROR: User to User information has wrong length %dn",parmlen);
  821.                                         else tmpcdrptr->UserToUserInformation=(char)buf[x];
  822.                                         x+=parmlen;
  823.                                         tmpcdrptr->USED_FIELDS |= B_UserToUserInformation;
  824. #ifdef SETDBG
  825. puts("UserToUserInf");
  826. #endif
  827. check = MyOperation->setValue("UserToUserInf",(char*)&tmpcdrptr->UserToUserInformation);
  828. if (check == -1)
  829. error_handler(MyTransaction->getNdbErrorString());
  830.                                 break;
  831.                                 case 40:        /* Original called number */
  832.                                         bcd_decode2(parmlen,&buf[x],crap);
  833.                                         strcpy(tmpcdrptr->OriginalCalledNumber,crap);
  834.                                         x=x+(parmlen/2);
  835.                                         if (parmlen % 2) x++;
  836.                                         tmpcdrptr->USED_FIELDS |= B_OriginalCalledNumber;
  837. #ifdef SETDBG
  838. puts("ONumber");
  839. #endif
  840. check = MyOperation->setValue("ONumber",(char*)&tmpcdrptr->OriginalCalledNumber);
  841. if (check == -1)
  842. error_handler(MyTransaction->getNdbErrorString());
  843.                                 break;
  844.                                 case 42:        /* User to user indicator */
  845.                                         if (parmlen != 1) printf("ERROR: User to User indicator has wrong length %dn",parmlen);
  846.                                         else tmpcdrptr->UserToUserIndicatior=(char)buf[x];
  847.                                         x+=parmlen;
  848.                                         tmpcdrptr->USED_FIELDS |= B_UserToUserIndicatior;
  849. #ifdef SETDBG
  850. puts("UserToUserInd");
  851. #endif
  852. check = MyOperation->setValue("UserToUserInd",(char*)&tmpcdrptr->UserToUserIndicatior);
  853. if (check == -1)
  854. error_handler(MyTransaction->getNdbErrorString());
  855.                                 break;
  856.                                 case 63:        /* Location number */
  857.                                         bcd_decode2(parmlen,&buf[x],crap);
  858.                                         strcpy(tmpcdrptr->LocationCode,crap);
  859.                                         x=x+(parmlen/2);
  860.                                         if (parmlen % 2) x++;
  861.                                         tmpcdrptr->USED_FIELDS |= B_LocationCode;
  862. #ifdef SETDBG
  863. puts("LocationCode");
  864. #endif
  865. check = MyOperation->setValue("LocationCode",(char*)&tmpcdrptr->LocationCode);
  866. if (check == -1)
  867. error_handler(MyTransaction->getNdbErrorString());
  868.                                 break;
  869.                                 case 240:       /* Calling Partys cataegory */
  870.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  871.                                         else tmpcdrptr->NetworkIndicator=(char)buf[x];
  872.                                         x+=parmlen;
  873.                                         tmpcdrptr->USED_FIELDS |= B_NetworkIndicator;
  874. #ifdef SETDBG
  875. puts("NIndicator");
  876. #endif
  877. check = MyOperation->setValue("NIndicator",(char*)&tmpcdrptr->NetworkIndicator);
  878. if (check == -1)
  879. error_handler(MyTransaction->getNdbErrorString());
  880.                                 break;
  881.                                 case 241:       /* Calling Partys cataegory */
  882.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  883.                                         else tmpcdrptr->TonASubscriberNumber=(char)buf[x];
  884.                                         x+=parmlen;
  885.                                         tmpcdrptr->USED_FIELDS |= B_TonASubscriberNumber;
  886. #ifdef SETDBG
  887. puts("TonANumber");
  888. #endif
  889. check = MyOperation->setValue("TonANumber",(char*)&tmpcdrptr->TonASubscriberNumber);
  890. if (check == -1)
  891. error_handler(MyTransaction->getNdbErrorString());
  892.                                 break;
  893.                                 case 242:       /* Calling Partys cataegory */
  894.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  895.                                         else tmpcdrptr->TonBSubscriberNumber=(char)buf[x];
  896.                                         x+=parmlen;
  897.                                         tmpcdrptr->USED_FIELDS |= B_TonBSubscriberNumber;
  898. #ifdef SETDBG
  899. puts("TonBNumber");
  900. #endif
  901. check = MyOperation->setValue("TonBNumber",(char*)&tmpcdrptr->TonBSubscriberNumber);
  902. if (check == -1)
  903. error_handler(MyTransaction->getNdbErrorString());
  904.                                 break;
  905.                                 case 243:       /* Calling Partys cataegory */
  906.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  907.                                         else tmpcdrptr->TonRedirectingNumber=(char)buf[x];
  908.                                         x+=parmlen;
  909.                                         tmpcdrptr->USED_FIELDS |= B_TonRedirectingNumber;
  910. #ifdef SETDBG
  911. puts("TonRNumber");
  912. #endif
  913. check = MyOperation->setValue("TonRNumber",(char*)&tmpcdrptr->TonRedirectingNumber);
  914. if (check == -1)
  915. error_handler(MyTransaction->getNdbErrorString());
  916.                                 break;
  917.                                 case 244:       /* Calling Partys cataegory */
  918.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  919.                                         else tmpcdrptr->TonOriginalCalledNumber=(char)buf[x];
  920.                                         x+=parmlen;
  921.                                         tmpcdrptr->USED_FIELDS |= B_TonOriginalCalledNumber;
  922. #ifdef SETDBG
  923. puts("TonONumber");
  924. #endif
  925. check = MyOperation->setValue("TonONumber",(char*)&tmpcdrptr->TonOriginalCalledNumber);
  926. if (check == -1)
  927. error_handler(MyTransaction->getNdbErrorString());
  928.                                 break;
  929.                                 case 245:       /* Calling Partys cataegory */
  930.                                         if (parmlen != 1) printf("ERROR: Calling partys category has wrong length %dn",parmlen);
  931.                                         else tmpcdrptr->TonLocationCode=(char)buf[x];
  932.                                         x+=parmlen;
  933.                                         tmpcdrptr->USED_FIELDS |= B_TonLocationCode;
  934. #ifdef SETDBG
  935. puts("TonLocationCode");
  936. #endif
  937. check = MyOperation->setValue("TonLocationCode",(char*)&tmpcdrptr->TonLocationCode);
  938. if (check == -1)
  939. error_handler(MyTransaction->getNdbErrorString());
  940.                                 break;
  941.                                 case 252:       /* RINParameter Parameter */
  942.                                         switch (parmlen) {
  943.                                                 case 1:
  944.                                                         tmpcdrptr->RINParameter=buf[x];
  945.                                                         tmpcdrptr->USED_FIELDS |= B_RINParameter;
  946.                                                 break;
  947.                                                 case 2:
  948.                                                         swab(buf+x,buf+x,2);
  949.                                                         tmpcdrptr->RINParameter = buf[x] << 8;
  950.                                                         tmpcdrptr->USED_FIELDS |= B_RINParameter;
  951.                                                 break;
  952.                                                 default :
  953.                                                         BaseString::snprintf(msg,sizeof(msg),"ERROR: Rin parameter has wrong length %dn",parmlen);
  954.    if ((checkchangelog(log,lognamn))==0)
  955.                                                           n2log(log,msg);
  956.                                                 break;
  957.                                         }
  958.                                         x+=parmlen;
  959. #ifdef SETDBG
  960. puts("RINParameter");
  961. #endif
  962. check = MyOperation->setValue("RINParameter",(char*)&tmpcdrptr->RINParameter);
  963. if (check == -1)
  964. error_handler(MyTransaction->getNdbErrorString());
  965.                                 break;
  966.                                 case 253:       /* OriginatingPointCode */
  967.                                         switch (parmlen) {
  968.                                                 case 2:
  969.                                                         swab(buf+x,buf+x,2);
  970.                                                         memcpy(&tmpcdrptr->OriginatingPointCode,(buf+x),2);
  971.                                                         tmpcdrptr->USED_FIELDS |= B_OriginatingPointCode;
  972.                                                 break;
  973.                                                 case 3:
  974.                                                         swab(buf+x,buf+x,2);
  975.                                                         swab(buf+(x+1),buf+(x+1),2);
  976.                                                         swab(buf+x,buf+x,2);
  977.                                                         memcpy(&tmpcdrptr->OriginatingPointCode,(buf+x),3);
  978.                                                         tmpcdrptr->USED_FIELDS |= B_OriginatingPointCode;
  979.                                                 break;
  980.                                                 default :
  981.                                                         BaseString::snprintf(msg,sizeof(msg),"ERROR: OriginatingPointCode parameter has wrong length %dn",parmlen);
  982.    if ((checkchangelog(log,lognamn))==0)
  983.                                                           n2log(log,msg);
  984.                                                 break;
  985.                                         }
  986.                                         x+=parmlen;
  987. #ifdef SETDBG
  988. puts("OPC");
  989. #endif
  990. check = MyOperation->setValue("OPC",(char*)&tmpcdrptr->OriginatingPointCode);
  991. if (check == -1)
  992. error_handler(MyTransaction->getNdbErrorString());
  993.                                 break;
  994.                                 case 254:       /* DestinationPointCode */
  995.                                         switch (parmlen) {
  996.                                                 case 2:
  997.                                                         swab(buf+x,buf+x,2);
  998.                                                         memcpy(&tmpcdrptr->DestinationPointCode,(buf+x),2);
  999. /*
  1000.                                                         tmpcdrptr->DestinationPointCode = buf[x] << 8;
  1001. */
  1002.                                                         tmpcdrptr->USED_FIELDS |= B_DestinationPointCode;
  1003.                                                 break;
  1004.                                                 case 3:
  1005.                                                         swab(buf+x,buf+x,2);
  1006.                                                         swab(buf+(x+1),buf+(x+1),2);
  1007.                                                         swab(buf+x,buf+x,2);
  1008.                                                         memcpy(&tmpcdrptr->DestinationPointCode,(buf+x),3);
  1009.                                                         tmpcdrptr->USED_FIELDS |= B_DestinationPointCode;
  1010.                                                 break;
  1011.                                                 default :
  1012.                                                         BaseString::snprintf(msg,sizeof(msg),"ERROR: DestinationPointCode parameter has wrong length %dn",parmlen);
  1013.    if ((checkchangelog(log,lognamn))==0)
  1014.                                                           n2log(log,msg);
  1015.                                                 break;
  1016.                                         }
  1017.                                         x+=parmlen;
  1018. #ifdef SETDBG
  1019. puts("DPC");
  1020. #endif
  1021. check = MyOperation->setValue("DPC",(char*)&tmpcdrptr->DestinationPointCode);
  1022. if (check == -1)
  1023. error_handler(MyTransaction->getNdbErrorString());
  1024.                                 break;
  1025.                                 case 255:       /* CircuitIdentificationCode */
  1026.                                         swab(buf+x,buf+x,2);
  1027.                                         memcpy(&tmpcdrptr->CircuitIdentificationCode,(buf+x),2);
  1028.                                         tmpcdrptr->USED_FIELDS |= B_CircuitIdentificationCode;
  1029.                                         x+=parmlen;
  1030. #ifdef SETDBG
  1031. puts("CIC");
  1032. #endif
  1033. check = MyOperation->setValue("CIC",(char*)&tmpcdrptr->CircuitIdentificationCode);
  1034. if (check == -1)
  1035. error_handler(MyTransaction->getNdbErrorString());
  1036.                                 break;
  1037.                                 default:
  1038.                                         printf("ERROR: Undefined parmtype %d , previous %d, length %dn",parmtype,parmtype_prev,parmlen);
  1039.                                         BaseString::snprintf(msg,sizeof(msg),"ERROR: Undefined parmtype %d , previous %d, length %dn",parmtype,parmtype_prev,parmlen);
  1040.    if ((checkchangelog(log,lognamn))==0)
  1041.                                           n2log(log,msg);
  1042.                                         if (parmlen == 0) {
  1043.                                                 x++;
  1044.                                         }
  1045.                                         x+=parmlen;
  1046.                                 break;
  1047.                         }
  1048.                         parmtype_prev=parmtype;
  1049.                         if ((cdrrestlen-x) == 1) {
  1050.                                 done=TRUE;
  1051.                         }
  1052.                 }
  1053. time(&ourtime);
  1054. if (ourtime != tmptime)
  1055. {
  1056. transfer = tmptransfer;
  1057. tmptransfer = 0;
  1058. if (++act_index == 30)
  1059. {
  1060. act_index = 0;
  1061. printf("Transfer=%dn",transfer);
  1062. printf("Total operations=%dn",reqcnt);
  1063. printf("CAS1=%dn",c1/30);
  1064. printf("CAS2=%dn",c2/30);
  1065. printf("CAS3=%dn",c3/30);
  1066. c1=0;
  1067. c2=0;
  1068. c3=0;
  1069. }
  1070. tmptime = ourtime;
  1071. }
  1072.                 switch (cdrsubtype) {
  1073.                         case 0:
  1074.                                 tmpcdrptr->ClientId = servernum;
  1075. #ifdef SETDBG
  1076. puts("ClientId");
  1077. #endif
  1078. check = MyOperation->setValue("ClientId",(char*)&tmpcdrptr->ClientId);
  1079. if (check == -1)
  1080. error_handler(MyTransaction->getNdbErrorString());
  1081.                                 tmpcdrptr->OurSTART_TIME = ourtime;
  1082. #ifdef SETDBG
  1083. puts("OurSTART_TIME");
  1084. #endif
  1085. check = MyOperation->setValue("OurSTART_TIME",(char*)&tmpcdrptr->OurSTART_TIME);
  1086. if (check == -1)
  1087. error_handler(MyTransaction->getNdbErrorString());
  1088.                                 tmpcdrptr->USED_FIELDS |= B_START_TIME;
  1089. #ifdef SETDBG
  1090. puts("USED_FIELDS");
  1091. #endif
  1092. check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);
  1093. if (check == -1)
  1094. error_handler(MyTransaction->getNdbErrorString());
  1095.                         break;
  1096.                         case 1:
  1097.                                 tmpcdrptr->OurTimeForStartOfCharge = ourtime;
  1098. #ifdef SETDBG
  1099. puts("OurStartOfCharge");
  1100. #endif
  1101. check = MyOperation->setValue("OurStartOfCharge",(char*)&tmpcdrptr->OurTimeForStartOfCharge);
  1102. if (check == -1)
  1103. error_handler(MyTransaction->getNdbErrorString());
  1104.                                 tmpcdrptr->USED_FIELDS |= B_TimeForStartOfCharge;
  1105. #ifdef SETDBG
  1106. puts("USED_FIELDS");
  1107. #endif
  1108. check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);
  1109. if (check == -1)
  1110. error_handler(MyTransaction->getNdbErrorString());
  1111.                         break;
  1112.                         case 2:
  1113.                                 tmpcdrptr->OurTimeForStopOfCharge = ourtime;
  1114. #ifdef SETDBG
  1115. puts("OurStopOfCharge");
  1116. #endif
  1117. check = MyOperation->setValue("OurStopOfCharge",(char*)&tmpcdrptr->OurTimeForStopOfCharge);
  1118. if (check == -1)
  1119. error_handler(MyTransaction->getNdbErrorString());
  1120.                                 tmpcdrptr->USED_FIELDS |= B_TimeForStopOfCharge;
  1121. #ifdef SETDBG
  1122. puts("USED_FIELDS");
  1123. #endif
  1124. check = MyOperation->setValue("USED_FIELDS",(char*)&tmpcdrptr->USED_FIELDS);
  1125. if (check == -1)
  1126. error_handler(MyTransaction->getNdbErrorString());
  1127.                         break;
  1128.                         case 3:
  1129.                                 tmpcdrptr->CallAttemptState  = 4;
  1130.                         break;
  1131. default:
  1132.          snprintf(msg,sizeof(msg),"cdrtype %d unknown",cdrsubtype);
  1133. if ((checkchangelog(log,lognamn))==0)
  1134.            n2log(log,msg);
  1135.                                 goto errout;
  1136.                         break;
  1137.                 }
  1138.                                 ops++;
  1139.                                 if (ops == ops_before_exe) {
  1140.                                   ops = 0;
  1141.                                   #ifdef SETDBG
  1142.                                         puts("Going to execute");
  1143.                                   #endif
  1144.                                   check = MyTransaction->execute(Commit, CommitAsMuchAsPossible);
  1145.                    if ((check == -1) && (MyTransaction->getNdbError() != 0))
  1146.                                         error_handler(MyTransaction->getNdbErrorString());
  1147.                                   MyNdb.closeTransaction(MyTransaction);
  1148.                                   #ifdef SETDBG
  1149.                                         puts("Transaction closed");
  1150.                                   #endif
  1151.                                   #ifdef SETDBG
  1152.                                         puts("New transaction initiated");
  1153.                                   #endif
  1154.                                 }//if
  1155.                 /* Increment the request count. */
  1156.                 reqcnt++;
  1157.                 /* Send a response back to the client. */
  1158.                 /* if (send(s, buf, 10, 0) != 10) goto errout;  */
  1159.         }
  1160.         /* The loop has terminated, because there are no                */
  1161.         /* more requests to be serviced. As mentioned above,            */
  1162.         /* this close will block until all of the sent replies          */
  1163.         /* have been received by the remote host. The reason            */
  1164.         /* for lingering on the close is so that the server will        */
  1165.         /* have a better idea of when the remote has picked up          */
  1166.         /* all of the data. This will allow the start and finish        */
  1167.         /* times printed in the log file to reflect more accurately     */
  1168.         /* the length of time this connection was                       */
  1169.         /* The port number must be converted first to host byte         */
  1170.         /* order before printing. On most hosts, this is not            */
  1171.         /* necessary, but the ntohs() call is included here so          */
  1172.         /* that this program could easily be ported to a host           */
  1173.         /* that does require it.                                        */
  1174.         BaseString::snprintf(msg,sizeof(msg),"Completed %s port %u, %d requests",hostname,ntohs(peeraddr_in.sin_port), reqcnt);
  1175. if ((checkchangelog(fi,temp))==0)
  1176.           c2log(fi,msg);
  1177. error_from_client = 1;
  1178.         BaseString::snprintf(msg,sizeof(msg),"Communicate with threads");
  1179. if ((checkchangelog(log,lognamn))==0)
  1180.           n2log(log,msg);
  1181.         BaseString::snprintf(msg,sizeof(msg),"Waiting for threads to return from work");
  1182. if ((checkchangelog(log,lognamn))==0)
  1183.           n2log(log,msg);
  1184.         BaseString::snprintf(msg,sizeof(msg),"Closing down");
  1185. if ((checkchangelog(log,lognamn))==0)
  1186.           n2log(log,msg);
  1187.         close(s);
  1188.         fclose(log);
  1189.         return EXIT_SUCCESS;
  1190. errout:
  1191.         BaseString::snprintf(msg,sizeof(msg),"Connection with %s aborted on errorn", hostname);
  1192. if ((checkchangelog(log,lognamn))==0)
  1193.           n2log(log,msg);
  1194. if ((checkchangelog(fi,temp))==0)
  1195.           c2log(fi,msg);
  1196. error_from_client = 1;
  1197.         BaseString::snprintf(msg,sizeof(msg),"Communicate with threads");
  1198. if ((checkchangelog(log,lognamn))==0)
  1199.           n2log(log,msg);
  1200.         BaseString::snprintf(msg,sizeof(msg),"Waiting for threads to return from work");
  1201. if ((checkchangelog(log,lognamn))==0)
  1202.           n2log(log,msg);
  1203.         BaseString::snprintf(msg,sizeof(msg),"Closing down");
  1204. if ((checkchangelog(log,lognamn))==0)
  1205.           n2log(log,msg);
  1206.         close(s);
  1207.         fclose(log);
  1208. return EXIT_FAILURE;
  1209. }
  1210. void
  1211. create_table(Ndb* pMyNdb)
  1212. {
  1213.  /****************************************************************
  1214.    *    Create table and attributes.
  1215.    *
  1216.    *    create table basictab1(
  1217.    *        col1 int,
  1218.    *        col2 int not null,
  1219.    *        col3 int not null,
  1220.    *        col4 int not null
  1221.    *     )
  1222.    * 
  1223.    ***************************************************************/
  1224.   int                   check;
  1225.   int                   i;
  1226.   NdbSchemaCon          *MySchemaTransaction;
  1227.   NdbSchemaOp           *MySchemaOp;
  1228.   int tAttributeSize;
  1229.   tAttributeSize = 1;
  1230.   cout << "Creating " << tableName << "..." << endl;
  1231.    MySchemaTransaction = pMyNdb->startSchemaTransaction();
  1232.    if( MySchemaTransaction == NULL )
  1233.       error_handler(MySchemaTransaction->getNdbErrorString());
  1234.    MySchemaOp = MySchemaTransaction->getNdbSchemaOp();
  1235.    if( MySchemaOp == NULL )
  1236.       error_handler(MySchemaTransaction->getNdbErrorString());
  1237.    // Createtable
  1238.    check = MySchemaOp->createTable( tableName,
  1239.                                      8,         // Table Size
  1240.                                      TupleKey,  // Key Type
  1241.                                      40         // Nr of Pages
  1242.                                    );
  1243.    if( check == -1 )
  1244.       error_handler(MySchemaTransaction->getNdbErrorString());
  1245.    // CallIdentificationNumber Create first column, primary key 
  1246.    check = MySchemaOp->createAttribute( "CIN", 
  1247. TupleKey, 
  1248. 32,
  1249.                                         tAttributeSize,
  1250. UnSigned, MMBased,
  1251.                                         NotNullAttribute 
  1252. );
  1253.    if( check == -1 )
  1254.       error_handler(MySchemaTransaction->getNdbErrorString());
  1255.   
  1256.    // USED_FIELDS Create attributes
  1257.    check = MySchemaOp->createAttribute( "USED_FIELDS", NoKey, 32,
  1258.                                          tAttributeSize, UnSigned, MMBased,
  1259.                                          NullAttribute );
  1260.    if( check == -1 )
  1261.       error_handler(MySchemaTransaction->getNdbErrorString());
  1262.  
  1263.    // ClientId Create attributes
  1264.    check = MySchemaOp->createAttribute( "ClientId", NoKey, 32,
  1265.                                          tAttributeSize, UnSigned, MMBased,
  1266.                                          NullAttribute );
  1267.    if( check == -1 )
  1268.       error_handler(MySchemaTransaction->getNdbErrorString());
  1269.  
  1270.    // START_TIME Create attributes
  1271.    check = MySchemaOp->createAttribute( "START_TIME", NoKey, 32,
  1272.                                          tAttributeSize, UnSigned, MMBased,
  1273.                                          NullAttribute );
  1274.    if( check == -1 )
  1275.       error_handler(MySchemaTransaction->getNdbErrorString());
  1276.  
  1277.    // OurSTART_TIME Create attributes
  1278.    check = MySchemaOp->createAttribute( "OurSTART_TIME", NoKey, 32,
  1279.                                          tAttributeSize, UnSigned, MMBased,
  1280.                                          NullAttribute );
  1281.    if( check == -1 )
  1282.       error_handler(MySchemaTransaction->getNdbErrorString());
  1283.  
  1284.    // TimeForStartOfCharge Create attributes
  1285.    check = MySchemaOp->createAttribute( "StartOfCharge", NoKey, 32,
  1286.                                          tAttributeSize, UnSigned, MMBased,
  1287.                                          NullAttribute );
  1288.    if( check == -1 )
  1289.       error_handler(MySchemaTransaction->getNdbErrorString());
  1290.  
  1291.    // TimeForStopOfCharge Create attributes
  1292.    check = MySchemaOp->createAttribute( "StopOfCharge", NoKey, 32,
  1293.                                          tAttributeSize, UnSigned, MMBased,
  1294.                                          NullAttribute );
  1295.    if( check == -1 )
  1296.       error_handler(MySchemaTransaction->getNdbErrorString());
  1297.  
  1298.    // OurTimeForStartOfCharge Create attributes
  1299.    check = MySchemaOp->createAttribute( "OurStartOfCharge", NoKey, 32,
  1300.                                          tAttributeSize, UnSigned, MMBased,
  1301.                                          NullAttribute );
  1302.    if( check == -1 )
  1303.       error_handler(MySchemaTransaction->getNdbErrorString());
  1304.  
  1305.    // OurTimeForStopOfCharge Create attributes
  1306.    check = MySchemaOp->createAttribute( "OurStopOfCharge", NoKey, 32,
  1307.                                          tAttributeSize, UnSigned, MMBased,
  1308.                                          NullAttribute );
  1309.    if( check == -1 )
  1310.       error_handler(MySchemaTransaction->getNdbErrorString());
  1311.  
  1312.    // DestinationPointCode Create attributes
  1313.    check = MySchemaOp->createAttribute( "DPC", NoKey, 16,
  1314.                                          tAttributeSize, UnSigned, MMBased,
  1315.                                          NullAttribute );
  1316.    if( check == -1 )
  1317.       error_handler(MySchemaTransaction->getNdbErrorString());
  1318.  
  1319.    // OriginatingPointCode Create attributes
  1320.    check = MySchemaOp->createAttribute( "OPC", NoKey, 16,
  1321.                                          tAttributeSize, UnSigned, MMBased,
  1322.                                          NullAttribute );
  1323.    if( check == -1 )
  1324.       error_handler(MySchemaTransaction->getNdbErrorString());
  1325.  
  1326.    // CircuitIdentificationCode Create attributes
  1327.    check = MySchemaOp->createAttribute( "CIC", NoKey, 16,
  1328.                                          tAttributeSize, UnSigned, MMBased,
  1329.                                          NullAttribute );
  1330.    if( check == -1 )
  1331.       error_handler(MySchemaTransaction->getNdbErrorString());
  1332.  
  1333.    // ReroutingIndicator Create attributes
  1334.    check = MySchemaOp->createAttribute( "RI", NoKey, 16,
  1335.                                          tAttributeSize, UnSigned, MMBased,
  1336.                                          NullAttribute );
  1337.    if( check == -1 )
  1338.       error_handler(MySchemaTransaction->getNdbErrorString());
  1339.  
  1340.    // RINParameter Create attributes
  1341.    check = MySchemaOp->createAttribute( "RINParameter", NoKey, 16,
  1342.                                          tAttributeSize, UnSigned, MMBased,
  1343.                                          NullAttribute );
  1344.    if( check == -1 )
  1345.       error_handler(MySchemaTransaction->getNdbErrorString());
  1346.  
  1347.    // NetworkIndicator Create attributes
  1348.    check = MySchemaOp->createAttribute( "NIndicator", NoKey, 8,
  1349.                                          tAttributeSize, Signed, MMBased,
  1350.                                          NullAttribute );
  1351.    if( check == -1 )
  1352.       error_handler(MySchemaTransaction->getNdbErrorString());
  1353.  
  1354.    // CallAttemptState Create attributes
  1355.    check = MySchemaOp->createAttribute( "CAS", NoKey, 8,
  1356.                                          tAttributeSize, Signed, MMBased,
  1357.                                          NullAttribute );
  1358.    if( check == -1 )
  1359.       error_handler(MySchemaTransaction->getNdbErrorString());
  1360.  
  1361.    // ACategory Create attributes
  1362.    check = MySchemaOp->createAttribute( "ACategory", NoKey, 8,
  1363.                                          tAttributeSize, Signed, MMBased,
  1364.                                          NullAttribute );
  1365.    if( check == -1 )
  1366.       error_handler(MySchemaTransaction->getNdbErrorString());
  1367.  
  1368.    // EndOfSelectionInformation Create attributes
  1369.    check = MySchemaOp->createAttribute( "EndOfSelInf", NoKey, 8,
  1370.                                          tAttributeSize, Signed, MMBased,
  1371.                                          NullAttribute );
  1372.    if( check == -1 )
  1373.       error_handler(MySchemaTransaction->getNdbErrorString());
  1374.  
  1375.    // UserToUserInformation Create attributes
  1376.    check = MySchemaOp->createAttribute( "UserToUserInf", NoKey, 8,
  1377.                                          tAttributeSize, Signed, MMBased,
  1378.                                          NullAttribute );
  1379.    if( check == -1 )
  1380.       error_handler(MySchemaTransaction->getNdbErrorString());
  1381.  
  1382.    // UserToUserIndicator Create attributes
  1383.    check = MySchemaOp->createAttribute( "UserToUserInd", NoKey, 8,
  1384.                                          tAttributeSize, Signed, MMBased,
  1385.                                          NullAttribute );
  1386.    if( check == -1 )
  1387.       error_handler(MySchemaTransaction->getNdbErrorString());
  1388.  
  1389.    // CauseCode Create attributes
  1390.    check = MySchemaOp->createAttribute( "CauseCode", NoKey, 8,
  1391.                                          tAttributeSize, Signed, MMBased,
  1392.                                          NullAttribute );
  1393.    if( check == -1 )
  1394.       error_handler(MySchemaTransaction->getNdbErrorString());
  1395.  
  1396.    // ASubscriberNumber attributes
  1397.    check = MySchemaOp->createAttribute( "ANumber", NoKey, 8,
  1398.                                          ASubscriberNumber_SIZE, Signed, MMBased,
  1399.                                          NullAttribute );
  1400.    if( check == -1 )
  1401.       error_handler(MySchemaTransaction->getNdbErrorString());
  1402.  
  1403.    // ASubscriberNumberLenght attributes
  1404.    check = MySchemaOp->createAttribute( "ANumberLength", NoKey, 8,
  1405.                                          tAttributeSize, Signed, MMBased,
  1406.                                          NullAttribute );
  1407.    if( check == -1 )
  1408.       error_handler(MySchemaTransaction->getNdbErrorString());
  1409.  
  1410.    // TonASubscriberNumber attributes
  1411.    check = MySchemaOp->createAttribute( "TonANumber", NoKey, 8,
  1412.                                          tAttributeSize, Signed, MMBased,
  1413.                                          NullAttribute );
  1414.    if( check == -1 )
  1415.       error_handler(MySchemaTransaction->getNdbErrorString());
  1416.  
  1417.    // BSubscriberNumber attributes
  1418.    check = MySchemaOp->createAttribute( "BNumber", NoKey, 8,
  1419.                                          BSubscriberNumber_SIZE, Signed, MMBased,
  1420.                                          NullAttribute );
  1421.    if( check == -1 )
  1422.       error_handler(MySchemaTransaction->getNdbErrorString());
  1423.  
  1424.    // BSubscriberNumberLength attributes
  1425.    check = MySchemaOp->createAttribute( "BNumberLength", NoKey, 8,
  1426.                                          tAttributeSize, Signed, MMBased,
  1427.                                          NullAttribute );
  1428.    if( check == -1 )
  1429.       error_handler(MySchemaTransaction->getNdbErrorString());
  1430.  
  1431.    // TonBSubscriberNumber attributes
  1432.    check = MySchemaOp->createAttribute( "TonBNumber", NoKey, 8,
  1433.                                          tAttributeSize, Signed, MMBased,
  1434.                                          NullAttribute );
  1435.    if( check == -1 )
  1436.       error_handler(MySchemaTransaction->getNdbErrorString());
  1437.  
  1438.    // RedirectingNumber attributes
  1439.    check = MySchemaOp->createAttribute( "RNumber", NoKey, 8,
  1440.                                          ASubscriberNumber_SIZE, Signed, MMBased,
  1441.                                          NullAttribute );
  1442.    if( check == -1 )
  1443.       error_handler(MySchemaTransaction->getNdbErrorString());
  1444.  
  1445.    // TonRedirectingNumber attributes
  1446.    check = MySchemaOp->createAttribute( "TonRNumber", NoKey, 8,
  1447.                                          tAttributeSize, Signed, MMBased,
  1448.                                          NullAttribute );
  1449.    if( check == -1 )
  1450.       error_handler(MySchemaTransaction->getNdbErrorString());
  1451.  
  1452.    // OriginalCalledNumber attributes
  1453.    check = MySchemaOp->createAttribute( "ONumber", NoKey, 8,
  1454.                                          ASubscriberNumber_SIZE, Signed, MMBased,
  1455.                                          NullAttribute );
  1456.    if( check == -1 )
  1457.       error_handler(MySchemaTransaction->getNdbErrorString());
  1458.  
  1459.    // TonOriginalCalledNumber attributes
  1460.    check = MySchemaOp->createAttribute( "TonONumber", NoKey, 8,
  1461.                                          tAttributeSize, Signed, MMBased,
  1462.                                          NullAttribute );
  1463.    if( check == -1 )
  1464.       error_handler(MySchemaTransaction->getNdbErrorString());
  1465.  
  1466.    // LocationCode attributes
  1467.    check = MySchemaOp->createAttribute( "LocationCode", NoKey, 8,
  1468.                                          ASubscriberNumber_SIZE, Signed, MMBased,
  1469.                                          NullAttribute );
  1470.    if( check == -1 )
  1471.       error_handler(MySchemaTransaction->getNdbErrorString());
  1472.  
  1473.    // TonLocationCode attributes
  1474.    check = MySchemaOp->createAttribute( "TonLocationCode", NoKey, 8,
  1475.                                          tAttributeSize, Signed, MMBased,
  1476.                                          NullAttribute );
  1477.    if( check == -1 )
  1478.       error_handler(MySchemaTransaction->getNdbErrorString());
  1479.  
  1480.    if( MySchemaTransaction->execute() == -1 ) {
  1481.        cout << tableName << " already exist" << endl;
  1482.        cout << "Message: " << MySchemaTransaction->getNdbErrorString() << endl;
  1483.    }
  1484.    else
  1485.    {
  1486.      cout << tableName << " created" << endl;
  1487.    }
  1488.    pMyNdb->closeSchemaTransaction(MySchemaTransaction);
  1489.   
  1490.    return;
  1491. }
  1492. void
  1493. error_handler(const char* errorText)
  1494. {
  1495.   // Test failed
  1496.   cout << endl << "ErrorMessage: " << errorText << endl;
  1497.   bTestPassed = -1;
  1498. }