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