Changeset 19184 for trunk/FACT++/dim
- Timestamp:
- 08/19/18 17:51:19 (6 years ago)
- Location:
- trunk/FACT++/dim
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/dim/README_v20.txt
r18920 r19184 1 1 2 DIM version 20r2 0Release Notes2 DIM version 20r23 Release Notes 3 3 4 4 Notes 1 and 2 for Unix Users only … … 17 17 Dns </dev/null >& dns.log & 18 18 19 NOTE 3: The Version Number service provided by servers is now set to 2020. 19 NOTE 3: The Version Number service provided by servers is now set to 2023. 20 21 12/06/2018 22 Changes for version 2023: 23 - Fixed the new BimBridge: 24 - A bug had been introduced parsing the command line that made the DimBridge crash when providing 25 the domain name with the dns node name, fixed. 26 27 28 08/06/2018 29 Changes for version 2022: 30 - Fixed and improved the new BimBridge: 31 - Implemented a -e <services> option to exclude services from the bridge list. 32 New signature: 33 Usage: DimBridge [-f(rom) <from_node>[:<port_number>]] -t(o) <to_node>[:<port_number>] 34 -s <services> [-e <services>] [-i(nterval) <time_interval>] [-c(opy)] 35 ([-r(replace) <search_string> <replace_string>])* 36 - Optimized the behaviour when the DNS (source or target) restarts or changes from one machine to another. 37 - A memory leak had been introduced, fixed now. 38 39 40 07/06/2018 41 Changes for version 2021: 42 - Changed slightly the Windows include files, to include Winsock2.h instead of windows.h (and Winsock.h). 43 - Added a socket shutdown, for linux, when closing sockets, to make sure the connection is gone. 44 - Added some protections for very long names, for example IP names. 45 - got rid of some warnings for gcc 4.8.5 46 - Modified DimBridge (but should stay backward compatible): 47 - To add new command line options, signature now: 48 DimBridge [-f(rom) <from_node>[:<port_number>]] -t(o) <to_node>[:<port_number] -s <services> 49 [-i(nterval) <time_interval>] [-c(opy)] 50 ([-r(replace) <search_string> <replace_string>])* 51 - Novelties are: 52 - the possibility to specify port_numbers (along with the dns node names) 53 - the possibility to specify replacement strings for the bridged service names 54 - the possibility to give comma separated patterns fot the service parameter 55 20 56 21 57 06/07/2017 -
trunk/FACT++/dim/dim/dim.h
r18920 r19184 14 14 #include "dim_common.h" 15 15 16 #define DIM_VERSION_NUMBER 202 016 #define DIM_VERSION_NUMBER 2023 17 17 18 18 #ifdef LABVIEWGSI … … 84 84 85 85 #ifdef WIN32 86 #include <windows.h>86 //#include <windows.h> 87 87 #include <process.h> 88 88 #include <io.h> 89 89 #include <fcntl.h> 90 #include <Winsock .h>90 #include <Winsock2.h> 91 91 #include <stddef.h> 92 92 #include <stdlib.h> -
trunk/FACT++/dim/src/dim_jni.c
r15282 r19184 1054 1054 { 1055 1055 jobject callback_param; 1056 int ret;1056 // int ret; 1057 1057 1058 1058 if(env){} … … 1062 1062 1063 1063 //printf("Stopping timer %08x %08X\n", callback_param, aDimTimer); 1064 ret =dtq_stop_timer((dim_long)callback_param);1064 dtq_stop_timer((dim_long)callback_param); 1065 1065 //printf("ret = %d\n", ret); 1066 1066 -
trunk/FACT++/dim/src/dis.c
r18920 r19184 3493 3493 int n = 0; 3494 3494 3495 if(dnsid){} 3495 3496 dnsp = (DIS_DNS_CONN *) DNS_head; 3496 3497 while ( (dnsp = (DIS_DNS_CONN *) dll_get_next( (DLL *) DNS_head, (DLL *) dnsp))) -
trunk/FACT++/dim/src/dns.c
r18920 r19184 375 375 (size_t)(MAX_TASK_NAME-4) ); 376 376 strcpy(Dns_conns[conn_id].long_task_name, packet->task_name); 377 Dns_conns[conn_id].task_name[MAX_TASK_NAME-4-1] = '\0'; 377 Dns_conns[conn_id].node_name[MAX_NODE_NAME - 1] = '\0'; 378 Dns_conns[conn_id].task_name[MAX_TASK_NAME - 4 - 1] = '\0'; 378 379 for(i = 0; i < 4; i++) 379 380 Dns_conns[conn_id].node_addr[i] = packet->node_addr[i]; … … 1442 1443 } 1443 1444 } 1445 /* 1444 1446 max_size = ((int)sizeof(DNS_SERVER_INFO) + MAX_TASK_NAME) * n_server; 1447 */ 1448 max_size = MAX_NAME * n_server; 1445 1449 max_pid_size = (int)sizeof(int) * n_server; 1446 1450 if(!curr_allocated_size) -
trunk/FACT++/dim/src/tcpip.c
r18920 r19184 890 890 pfds = &rfds; 891 891 #endif 892 if (pfds){} /* to avoid a warning */ 892 893 MY_FD_SET( DIM_IO_path[0], pfds ); 893 894 #ifdef __linux__ … … 1037 1038 int host_number = 0; 1038 1039 int tcpip_would_block(); 1040 int set_non_blocking(); 1041 int set_blocking(); 1042 1039 1043 #ifdef __linux__ 1040 1044 struct pollfd pollitem; … … 1044 1048 #endif 1045 1049 int so_error = ETIMEDOUT; 1046 int so_error_len = sizeof(so_error);1050 unsigned int so_error_len = sizeof(so_error); 1047 1051 1048 1052 dim_tcpip_init(0); … … 1501 1505 int wrote, ret, selret; 1502 1506 int tcpip_would_block(); 1507 int set_non_blocking(); 1508 int set_blocking(); 1509 1503 1510 #ifdef __linux__ 1504 1511 struct pollfd pollitem; … … 1590 1597 { 1591 1598 Net_conns[conn_id].write_timedout = 0; 1599 //#if defined(__linux__) && !defined (darwin) 1600 // shutdown(channel, 2); 1601 //#endif 1602 } 1592 1603 #if defined(__linux__) && !defined (darwin) 1593 shutdown(channel, 2); 1594 #endif 1595 } 1604 shutdown(channel, 2); 1605 #endif 1596 1606 closesock(channel); 1597 1607 } -
trunk/FACT++/dim/src/util/dimbridge.cxx
r11071 r19184 6 6 7 7 static int no_link = 0xdeaddead; 8 static char from_node[64], to_node[64], bridge_name[64]; 9 10 class BridgeService: public DimInfo, public SLLItem 8 static char from_node[128], to_node[128], bridge_name[128]; 9 static int from_port, to_port; 10 static char *services = 0, *eservices = 0; 11 static char *sstrings = 0, *rstrings = 0, *myown = 0; 12 int n_replaces = 0; 13 int max_replaces = 10; 14 int poll_interval = 30; 15 16 void get_srv_name_pub(char *srv_name, char *srv_name_pub) 17 { 18 char *p1, *p2, *ptrs, *ptrr; 19 int i; 20 21 strcpy(srv_name_pub, srv_name); 22 if (n_replaces) 23 { 24 ptrs = sstrings; 25 ptrr = rstrings; 26 for (i = 0; i < n_replaces; i++) 27 { 28 p1 = strstr(srv_name_pub, ptrs); 29 if (p1) 30 { 31 p2 = srv_name + (p1 - srv_name_pub); 32 p2 += strlen(ptrs); 33 *p1 = '\0'; 34 strcat(p1, ptrr); 35 strcat(p1, p2); 36 } 37 ptrs += strlen(ptrs) + 1; 38 ptrr += strlen(ptrr) + 1; 39 } 40 } 41 } 42 43 class BridgeService: public DimStampedInfo 11 44 { 12 45 char srv_name[256]; 46 char srv_name_pub[256]; 13 47 char srv_format[256]; 14 48 int declared; … … 19 53 int found; 20 54 int copyFlag; 55 time_t timestamp; 56 int milliseconds; 57 int quality; 21 58 22 59 void infoHandler() { 23 60 char *server; 24 data = DimInfo::getData(); 25 srv_size = DimInfo::getSize(); 26 61 data = DimStampedInfo::getData(); 62 srv_size = DimStampedInfo::getSize(); 63 timestamp = getTimestamp(); 64 milliseconds = getTimestampMillisecs(); 65 quality = getQuality(); 27 66 // Sometimes gets a packet from DIS_DNS not understood why!!!" 28 67 server = DimClient::getServerName(); 29 68 if(strstr(server,"DIS_DNS") != 0) 30 69 { 31 dim_print_date_time();32 cout << "received from " << server << " size = " << srv_size << endl;70 //dim_print_date_time(); 71 //cout << "received from " << server << " size = " << srv_size << endl; 33 72 if(strstr(srv_name,"DIS_DNS") == 0) 34 73 return; … … 39 78 if(srv) 40 79 { 80 // dim_print_date_time(); 81 // cout << "Deleting Service (no link)" << srv_name << endl; 41 82 delete(srv); 42 83 srv = 0; … … 44 85 declared = 0; 45 86 // cout << "Disconnecting bridge for: " << srv_name << endl; 87 poll_interval = 5; 46 88 } 47 89 else if(!declared) 48 90 { 49 91 // DimServer::setDnsNode(to_node); 50 srv = new DimService(srv_name , srv_format, srv_data, srv_size);92 srv = new DimService(srv_name_pub, srv_format, srv_data, srv_size); 51 93 if(copyFlag) 52 94 srv->setData(srv_data, srv_size); 95 srv->setQuality(quality); 96 srv->setTimestamp(timestamp, milliseconds); 53 97 DimServer::start(bridge_name); 54 98 declared = 1; … … 59 103 if(srv) 60 104 { 61 if(copyFlag) 105 srv->setQuality(quality); 106 srv->setTimestamp(timestamp, milliseconds); 107 if (copyFlag) 62 108 { 63 109 srv->setData(srv_data, srv_size); … … 74 120 public: 75 121 BridgeService(char *name, char *format, int copy): 76 Dim Info(name, &no_link, sizeof(no_link)), declared(0), srv(0), copyFlag(copy)122 DimStampedInfo(name, &no_link, sizeof(no_link)), declared(0), srv(0), copyFlag(copy) 77 123 { 78 124 strcpy(srv_format, format); 79 125 strcpy(srv_name, name); 126 get_srv_name_pub(srv_name, srv_name_pub); 80 127 cmnd = 0; 81 128 found = 1; … … 83 130 } 84 131 BridgeService(char *name, char *format, int rate, int copy): 85 Dim Info(name, rate, &no_link, sizeof(no_link)), declared(0), srv(0), copyFlag(copy)132 DimStampedInfo(name, rate, &no_link, sizeof(no_link)), declared(0), srv(0), copyFlag(copy) 86 133 { 87 134 strcpy(srv_format, format); 88 135 strcpy(srv_name, name); 136 get_srv_name_pub(srv_name, srv_name_pub); 89 137 cmnd = 0; 90 138 found = 1; … … 97 145 if(srv) 98 146 { 99 147 delete(srv); 100 148 srv = 0; 101 149 } … … 105 153 } 106 154 char *getName() { return srv_name; }; 107 void clear() { found = 0;}; 155 char *getNamePub() { return srv_name_pub; }; 156 void clear() { found = 0; }; 108 157 void set() {found = 1;}; 109 158 int find() {return found;}; … … 111 160 }; 112 161 113 class BridgeCommand: public DimCommand , public SLLItem162 class BridgeCommand: public DimCommandHandler 114 163 { 115 164 char srv_name[256]; 165 char srv_name_pub[256]; 116 166 char srv_format[256]; 117 167 int declared; 118 DimService *srv; 168 // DimService *srv; 169 DimCommand *srv; 119 170 void *srv_data; 120 171 int srv_size; … … 123 174 124 175 void commandHandler() { 125 srv_data = DimCommand::getData(); 126 srv_size = DimCommand::getSize(); 127 DimClient::sendCommandNB(srv_name, srv_data, srv_size); 176 // srv_data = DimCommand::getData(); 177 // srv_size = DimCommand::getSize(); 178 srv_data = srv->getData(); 179 srv_size = srv->getSize(); 180 DimClient::sendCommandNB(srv_name, srv_data, srv_size); 128 181 } 129 182 130 183 public: 131 BridgeCommand(char *name, char *format) :132 DimCommand(name, format)184 BridgeCommand(char *name, char *format)/*:*/ 185 // DimCommand(name, format) 133 186 { 134 DimServer::start(bridge_name);135 187 cmnd = 1; 136 188 found = 1; 137 189 strcpy(srv_name, name); 138 // cout << "Bridging Command: " << name << endl; 139 } 140 char *getName() { return srv_name; }; 141 void clear() { found = 0;}; 190 get_srv_name_pub(srv_name, srv_name_pub); 191 srv = new DimCommand(srv_name_pub, format, this); 192 DimServer::start(bridge_name); 193 // cout << "Bridging Command: " << name << endl; 194 } 195 ~BridgeCommand() 196 { 197 // if (declared) 198 // { 199 if (srv) 200 { 201 // dim_print_date_time(); 202 // cout << "Deleting Command " << srv_name << endl; 203 delete(srv); 204 srv = 0; 205 } 206 // } 207 // declared = 0; 208 // cout << "Stopped bridge for: " << srv_name << endl; 209 } 210 char *getName() { return srv_name; }; 211 char *getNamePub() { return srv_name_pub; }; 212 void clear() { found = 0; }; 142 213 void set() {found = 1;}; 143 214 int find() {return found;}; … … 145 216 }; 146 217 147 void print_usage ()218 void print_usage_old() 148 219 { 149 220 cout << "Usage: DimBridge [from_node] to_node services [time_interval] [-copy]" << endl; … … 155 226 } 156 227 228 void print_usage() 229 { 230 cout << "Usage: DimBridge [-f(rom) <from_node>[:<port_number>]] -t(o) <to_node>[:<port_number>] -s <services> [-e <services>] [-i(nterval) <time_interval>] [-c(opy)] ([-r(replace) <search_string> <replace_string>])* " << endl; 231 cout << " -f, -from\t\tfrom_node - the DNS node name (optionally a port number), by default DIM_DNS_NODE (DIM_DNS_PORT)" << endl; 232 cout << " -t, -to\t\tto_node - the complete node name of the new DNS (optionally a port number)" << endl; 233 cout << " -s, -services\tservices - the list of service names to bridge as a comma separated list of patterns" << endl; 234 cout << " -e, -exclude\tservices - a list of service names to be excluded as a comma separated list of patterns" << endl; 235 cout << " -i, -interval\ttime_interval - the interval in seconds to be used for updating the services" << endl; 236 cout << " -c, -copy\t\tcopy internally the service data" << endl; 237 cout << " -r, -replace\tsearch_string, replace_string - replace a part of the service name when bridging, can be repeated" << endl; 238 } 239 240 int parse_cmd_line(int argc, char **argv, int *rate, int *copyFlag) 241 { 242 int index = 1; 243 char *ptrs, *ptrr; 244 int size; 245 char *ptr, *ptr1; 246 int i; 247 248 strcpy(from_node, DimClient::getDnsNode()); 249 strcpy(to_node, ""); 250 n_replaces = 0; 251 *rate = 0; 252 *copyFlag = 0; 253 if (argc < 2) 254 return 0; 255 if (argv[1][0] != '-') // old style command line 256 return -1; 257 while (index < argc) 258 { 259 //cout << "arg" << index << " " << argv[index] << endl; 260 if (argv[index][0] != '-') // bad command line 261 return 0; 262 if (argv[index][1] == 'f') 263 { 264 index++; 265 if (index >= argc) 266 return 0; 267 strcpy(from_node, argv[index]); 268 } 269 else if (argv[index][1] == 't') 270 { 271 index++; 272 if (index >= argc) 273 return 0; 274 strcpy(to_node, argv[index]); 275 } 276 else if (argv[index][1] == 's') 277 { 278 index++; 279 if (index >= argc) 280 return 0; 281 services = (char *)malloc(strlen(argv[index])+1); 282 strcpy(services, argv[index]); 283 } 284 else if (argv[index][1] == 'e') 285 { 286 index++; 287 if (index >= argc) 288 return 0; 289 eservices = (char *)malloc(strlen(argv[index]) + 1); 290 strcpy(eservices, argv[index]); 291 } 292 else if (argv[index][1] == 'i') 293 { 294 index++; 295 if (index >= argc) 296 return 0; 297 sscanf(argv[index], "%d", rate); 298 } 299 else if (argv[index][1] == 'c') 300 { 301 *copyFlag = 1; 302 } 303 else if (argv[index][1] == 'r') 304 { 305 if (n_replaces == 0) 306 { 307 sstrings = (char *)malloc(max_replaces * MAX_NAME); 308 rstrings = (char *)malloc(max_replaces * MAX_NAME); 309 strcpy(sstrings, ""); 310 strcpy(rstrings, ""); 311 ptrs = sstrings; 312 ptrr = rstrings; 313 } 314 index++; 315 if (index >= argc) 316 return 0; 317 strcpy(ptrs, argv[index]); 318 index++; 319 if (index >= argc) 320 return 0; 321 strcpy(ptrr, argv[index]); 322 ptrs += strlen(ptrs) + 1; 323 ptrr += strlen(ptrr) + 1; 324 n_replaces++; 325 if (n_replaces == max_replaces) 326 { 327 max_replaces += 10; 328 sstrings = (char *)realloc(sstrings, max_replaces * MAX_NAME); 329 rstrings = (char *)realloc(rstrings, max_replaces * MAX_NAME); 330 } 331 } 332 index++; 333 } 334 if (n_replaces) 335 { 336 size = n_replaces * MAX_NAME; 337 myown = (char *)malloc(size); 338 ptr = myown; 339 ptr1 = rstrings; 340 for (i = 0; i < (n_replaces - 1); i++) 341 { 342 strcpy(ptr, "*"); 343 strcat(ptr, ptr1); 344 strcat(ptr, "*,"); 345 ptr += strlen(ptr); 346 ptr1 += strlen(ptr1) + 1; 347 } 348 strcpy(ptr, "*"); 349 strcat(ptr, ptr1); 350 strcat(ptr, "*"); 351 } 352 if (!services) 353 return 0; 354 if ((to_node[0] == '\0') || (services[0] == '\0')) 355 return 0; 356 return 1; 357 } 358 359 int parse_cmd_line_old(int argc, char **argv, int *rate, int *copyFlag) 360 { 361 if (argc < 3) 362 { 363 return 0; 364 } 365 else if (argc == 3) 366 { 367 strcpy(from_node, DimClient::getDnsNode()); 368 strcpy(to_node, argv[1]); 369 services = (char *)malloc(strlen(argv[2]) + 1); 370 strcpy(services, argv[2]); 371 } 372 else if (argc == 4) 373 { 374 // if(sscanf(argv[3],"%d", &rate)) 375 if (isdigit(argv[3][0])) 376 { 377 sscanf(argv[3], "%d", rate); 378 strcpy(from_node, DimClient::getDnsNode()); 379 strcpy(to_node, argv[1]); 380 services = (char *)malloc(strlen(argv[2]) + 1); 381 strcpy(services, argv[2]); 382 } 383 else if (argv[3][0] == '-') 384 { 385 *rate = 0; 386 strcpy(from_node, DimClient::getDnsNode()); 387 strcpy(to_node, argv[1]); 388 services = (char *)malloc(strlen(argv[2]) + 1); 389 strcpy(services, argv[2]); 390 *copyFlag = 1; 391 } 392 else 393 { 394 *rate = 0; 395 strcpy(from_node, argv[1]); 396 strcpy(to_node, argv[2]); 397 services = (char *)malloc(strlen(argv[3]) + 1); 398 strcpy(services, argv[3]); 399 } 400 } 401 else if (argc == 5) 402 { 403 // if(sscanf(argv[4],"%d", &rate)) 404 if (isdigit(argv[4][0])) 405 { 406 sscanf(argv[4], "%d", rate); 407 strcpy(from_node, argv[1]); 408 strcpy(to_node, argv[2]); 409 services = (char *)malloc(strlen(argv[3]) + 1); 410 strcpy(services, argv[3]); 411 } 412 else if (argv[4][0] == '-') 413 { 414 *copyFlag = 1; 415 // if(sscanf(argv[3],"%d", &rate)) 416 if (isdigit(argv[3][0])) 417 { 418 sscanf(argv[3], "%d", rate); 419 strcpy(from_node, DimClient::getDnsNode()); 420 strcpy(to_node, argv[1]); 421 services = (char *)malloc(strlen(argv[2]) + 1); 422 strcpy(services, argv[2]); 423 } 424 else 425 { 426 *rate = 0; 427 strcpy(from_node, argv[1]); 428 strcpy(to_node, argv[2]); 429 services = (char *)malloc(strlen(argv[3]) + 1); 430 strcpy(services, argv[3]); 431 } 432 } 433 } 434 else if (argc == 6) 435 { 436 strcpy(from_node, argv[1]); 437 strcpy(to_node, argv[2]); 438 services = (char *)malloc(strlen(argv[3]) + 1); 439 strcpy(services, argv[3]); 440 sscanf(argv[4], "%d", rate); 441 *copyFlag = 1; 442 } 443 else 444 { 445 return 0; 446 } 447 return 1; 448 } 449 450 char ServerList_no_link[10] = ""; 451 char ServiceList_no_link[10] = ""; 452 453 typedef struct serv { 454 struct serv *next; 455 struct serv *prev; 456 char name[MAX_NAME]; 457 int type; 458 char format[MAX_NAME]; 459 int registered; 460 void *serverPtr; 461 void *browserServicePtr; 462 } SERVICE; 463 464 int multiple_match(const char*, const char*, int case_sensitive); 465 int bridge_hash_service_init(); 466 int bridge_hash_service_insert(SERVICE *); 467 int bridge_hash_service_registered(int, SERVICE *); 468 int bridge_hash_service_remove(SERVICE *); 469 SERVICE *bridge_hash_service_exists(char *); 470 SERVICE *bridge_hash_service_get_next(int *, SERVICE *, int); 471 int bridge_hash_service_remove_many(int); 472 /* 473 class ServerInfo : public DimInfo, public SLLItem 474 { 475 char name[256]; 476 477 void infoHandler() { 478 char *data, *list, *format; 479 char *ptr, *ptr1, *ptr2, *ptr3; 480 int mode = 0, type; 481 SERVICE *servp; 482 483 data = DimInfo::getString(); 484 // cout << "***** Received from Server : " << data << endl; 485 list = new char[(int)strlen(data) + 1]; 486 strcpy(list, data); 487 ptr = list; 488 if (*ptr == '\0') 489 { 490 } 491 else if (*ptr == '+') 492 { 493 mode = 1; 494 ptr++; 495 } 496 else if (*ptr == '-') 497 { 498 mode = -1; 499 ptr++; 500 } 501 else 502 { 503 mode = 1; 504 } 505 while (*ptr) 506 { 507 if ((ptr1 = strchr(ptr, '\n'))) 508 { 509 *ptr1 = '\0'; 510 ptr1++; 511 } 512 else 513 { 514 ptr1 = ptr; 515 ptr1 += strlen(ptr); 516 } 517 if ((ptr2 = strchr(ptr, '|'))) 518 { 519 *ptr2 = '\0'; 520 ptr2++; 521 if ((ptr3 = strchr(ptr2, '|'))) 522 { 523 *ptr3 = '\0'; 524 format = ptr2; 525 ptr3++; 526 if (*ptr3 == '\0') 527 type = DimSERVICE; 528 else if (*ptr3 == 'C') 529 type = DimCOMMAND; 530 else if (*ptr3 == 'R') 531 type = DimRPC; 532 } 533 // cout << "***** Checking Service " << ptr << endl; 534 if (!strcmp(ptr, bridge_name)) 535 { 536 ptr = ptr1; 537 continue; 538 } 539 if (!strcmp(ptr, "DIS_DNS")) 540 { 541 ptr = ptr1; 542 continue; 543 } 544 if (mode == 1) 545 { 546 if (type != DimRPC) 547 { 548 if (multiple_match(ptr, services, 1)) 549 { 550 poll_interval = 3; 551 servp = (SERVICE *)malloc(sizeof(SERVICE)); 552 strncpy(servp->name, ptr, (size_t)MAX_NAME); 553 servp->type = type; 554 strcpy(servp->format, format); 555 servp->serverPtr = (void *)this; 556 servp->registered = 0; 557 bridge_hash_service_insert(servp); 558 } 559 } 560 } 561 else if (mode == -1) 562 { 563 poll_interval = 3; 564 servp = bridge_hash_service_exists(ptr); 565 if (servp) 566 { 567 // bridge_hash_service_remove(servp); 568 // free(servp); 569 servp->registered = -1; 570 } 571 } 572 } 573 ptr = ptr1; 574 } 575 } 576 public: 577 ServerInfo(char *server_name, char *service_name) : 578 DimInfo(service_name, ServiceList_no_link) 579 { 580 strcpy(name, server_name); 581 } 582 ~ServerInfo() 583 { 584 SERVICE *servp; 585 int hash_index; 586 587 hash_index = -1; 588 servp = 0; 589 while ((servp = bridge_hash_service_get_next(&hash_index, servp, 0))) 590 { 591 if (servp->serverPtr == (void *)this) 592 { 593 servp->registered = -1; 594 } 595 } 596 } 597 char *getName(){ return name; } 598 }; 599 */ 600 //int GotInitialList = 0; 601 602 603 class ServerList : public DimInfo 604 { 605 // ServerInfo *srv, *aux_srv; 606 char name[256], srv_name[256]; 607 SLList servers; 608 // char *serverList; 609 // int serverListSize; 610 611 void infoHandler() { 612 char *data; 613 // int size; 614 // char *ptr; 615 616 data = DimInfo::getString(); 617 // dim_print_date_time(); 618 // cout << "***** Received from DNS " << data << endl; 619 /* 620 size = (int)strlen(data) + 1; 621 if (!serverListSize) 622 { 623 serverList = new char[size]; 624 } 625 else if (size > serverListSize) 626 { 627 delete serverList; 628 serverList = new char[size]; 629 serverListSize = size; 630 } 631 strcpy(serverList, data); 632 if ((serverList[0] == '+') || (serverList[0] == '-')) 633 */ 634 if ((data[0] == '+') || (data[0] == '-')) 635 { 636 poll_interval = 3; 637 // parseServerList(); 638 } 639 else if (data[0] == '\0') 640 { 641 poll_interval = 0; 642 dim_print_date_time(); 643 cout << "Disconnected from " << DimClient::getServerName() << endl; 644 } 645 else 646 { 647 poll_interval = 30; 648 dim_print_date_time(); 649 cout << "Connected to " << DimClient::getServerName() << endl; 650 } 651 // GotInitialList = 1; 652 } 653 654 public: 655 ServerList(char *name) : 656 DimInfo(name, ServerList_no_link) 657 { 658 } 659 ~ServerList() 660 { 661 } 662 // int parseServerList(); 663 }; 664 /* 665 int ServerList::parseServerList() 666 { 667 char *ptr, *ptr1, *ptr2; 668 int mode = 0; 669 670 ptr = serverList; 671 if (*ptr == '\0') 672 { 673 } 674 else if (*ptr == '+') 675 { 676 mode = 1; 677 ptr++; 678 } 679 else if (*ptr == '-') 680 { 681 mode = -1; 682 ptr++; 683 } 684 else 685 { 686 mode = 1; 687 } 688 while (*ptr) 689 { 690 if ((ptr1 = strchr(ptr, '|'))) 691 { 692 *ptr1 = '\0'; 693 ptr1++; 694 } 695 else 696 { 697 ptr1 = ptr; 698 ptr1 += strlen(ptr); 699 } 700 if ((ptr2 = strchr(ptr, '@'))) 701 { 702 *ptr2 = '\0'; 703 // dim_print_date_time(); 704 // cout << "***** Checking Server " << ptr << endl; 705 if (!strcmp(ptr, bridge_name)) 706 { 707 ptr = ptr1; 708 continue; 709 } 710 if (!strcmp(ptr, "DIS_DNS")) 711 { 712 ptr = ptr1; 713 continue; 714 } 715 if (mode == 1) 716 { 717 strcpy(srv_name, ptr); 718 strcat(srv_name, "/SERVICE_LIST"); 719 strcpy(name, ptr); 720 dim_print_date_time(); 721 cout << "***** Subscribing Server " << ptr << " " << srv_name << endl; 722 srv = new ServerInfo(name, srv_name); 723 servers.add(srv); 724 } 725 else if (mode == -1) 726 { 727 srv = (ServerInfo *)servers.getHead(); 728 while (srv) 729 { 730 aux_srv = 0; 731 // cout << "Checking remove " << ptr << " " << srv->getName() << endl; 732 if (!(strcmp(srv->getName(), ptr))) 733 { 734 dim_print_date_time(); 735 cout << "***** Removing Server " << srv->getName() << endl; 736 servers.remove(srv); 737 aux_srv = srv; 738 break; 739 } 740 srv = (ServerInfo *)servers.getNext(); 741 } 742 if (aux_srv) 743 { 744 delete aux_srv; 745 } 746 } 747 } 748 ptr = ptr1; 749 } 750 return 1; 751 } 752 */ 753 int checkBridgeServices() 754 { 755 SERVICE *servp; 756 int hash_index; 757 758 servp = 0; 759 hash_index = -1; 760 // dbr.getServices(services); 761 // while ((type = dbr.getNextService(service, format))) 762 while ((servp = bridge_hash_service_get_next(&hash_index, servp, 0))) 763 { 764 // if (servp->registered == 2) 765 servp->registered = 1; 766 } 767 return 1; 768 } 769 770 int doBridgeService(char *service, char *format, int type) 771 { 772 SERVICE *servp; 773 int ret = 0; 774 775 if (!(servp = bridge_hash_service_exists(service))) 776 { 777 if (multiple_match(service, services, 1)) 778 { 779 if ((multiple_match(service, myown, 1)) || 780 (multiple_match(service, eservices, 1))) 781 { 782 // poll_interval = 3; 783 servp = (SERVICE *)malloc(sizeof(SERVICE)); 784 strncpy(servp->name, service, (size_t)MAX_NAME); 785 servp->type = type; 786 strcpy(servp->format, format); 787 // servp->serverPtr = (void *)this; 788 servp->registered = 2; 789 servp->browserServicePtr = (void *)0; 790 bridge_hash_service_insert(servp); 791 // cout << "Scanning " << service << "registered " << servp->registered << endl; 792 ret = 1; 793 } 794 else 795 { 796 poll_interval = 3; 797 servp = (SERVICE *)malloc(sizeof(SERVICE)); 798 strncpy(servp->name, service, (size_t)MAX_NAME); 799 servp->type = type; 800 strcpy(servp->format, format); 801 servp->browserServicePtr = (void *)0; 802 servp->registered = 0; 803 bridge_hash_service_insert(servp); 804 // cout << "Scanning " << service << " registered " << servp->registered << endl; 805 ret = 1; 806 } 807 } 808 } 809 else 810 { 811 servp->registered = 2; 812 // cout << "Scanning " << service << "registered " << servp->registered << endl; 813 ret = 2; 814 } 815 return ret; 816 } 817 818 int dontBridgeServices() 819 { 820 SERVICE *servp; 821 int hash_index; 822 823 servp = 0; 824 hash_index = -1; 825 // dbr.getServices(services); 826 // while ((type = dbr.getNextService(service, format))) 827 while ((servp = bridge_hash_service_get_next(&hash_index, servp, 0))) 828 { 829 if (servp->registered == 1) 830 servp->registered = -1; 831 } 832 return 1; 833 } 834 157 835 int main(int argc, char **argv) 158 836 { 159 char services[132];160 837 DimBrowser dbr; 161 838 char *service, *format, *p; 162 839 int type, known; 163 BridgeService *ptrs, *aux_ptrs; 164 BridgeCommand *ptrc, *aux_ptrc; 165 SLList lists, listc; 840 BridgeService *ptrs; 841 BridgeCommand *ptrc; 166 842 int rate = 0; 167 843 int copyFlag = 0; 844 int i, ret, done; 845 ServerList *serverList; 846 SERVICE *servp; 847 int hash_index; 848 char *sptr, *rptr; 168 849 169 850 //dic_set_debug_on(); 170 if(argc < 3) 171 { 851 // cout << "n pars " << argc << endl; 852 // for (i = 0; i < argc; i++) 853 // cout << "arg " << i << " " << argv[i] << endl; 854 bridge_hash_service_init(); 855 ret = parse_cmd_line(argc, argv, &rate, ©Flag); 856 if (ret == -1) 857 { 858 ret = parse_cmd_line_old(argc, argv, &rate, ©Flag); 859 if (!ret) 860 { 861 print_usage_old(); 862 return 0; 863 } 864 } 865 else if (!ret) 866 { 172 867 print_usage(); 173 868 return 0; 174 } 175 else if( argc == 3) 176 { 177 strcpy(from_node, DimClient::getDnsNode()); 178 strcpy(to_node, argv[1]); 179 strcpy(services, argv[2]); 180 } 181 else if (argc == 4) 182 { 183 if(sscanf(argv[3],"%d", &rate)) 184 { 185 strcpy(from_node, DimClient::getDnsNode()); 186 strcpy(to_node, argv[1]); 187 strcpy(services, argv[2]); 188 } 189 else if(argv[3][0] == '-') 190 { 191 rate = 0; 192 strcpy(from_node, DimClient::getDnsNode()); 193 strcpy(to_node, argv[1]); 194 strcpy(services, argv[2]); 195 copyFlag = 1; 196 } 197 else 198 { 199 rate = 0; 200 strcpy(from_node, argv[1]); 201 strcpy(to_node, argv[2]); 202 strcpy(services, argv[3]); 203 } 204 } 205 else if(argc == 5) 206 { 207 if(sscanf(argv[4],"%d", &rate)) 208 { 209 strcpy(from_node, argv[1]); 210 strcpy(to_node, argv[2]); 211 strcpy(services, argv[3]); 212 } 213 else if(argv[4][0] == '-') 214 { 215 copyFlag = 1; 216 if(sscanf(argv[3],"%d", &rate)) 217 { 218 strcpy(from_node, DimClient::getDnsNode()); 219 strcpy(to_node, argv[1]); 220 strcpy(services, argv[2]); 221 } 222 else 223 { 224 rate = 0; 225 strcpy(from_node, argv[1]); 226 strcpy(to_node, argv[2]); 227 strcpy(services, argv[3]); 228 } 229 } 230 } 231 else if(argc == 6) 232 { 233 strcpy(from_node, argv[1]); 234 strcpy(to_node, argv[2]); 235 strcpy(services, argv[3]); 236 sscanf(argv[4],"%d", &rate); 237 copyFlag = 1; 238 } 239 else 240 { 241 cout << "Bad parameters" << endl; 242 return 0; 243 } 244 245 cout << "Starting DimBridge from "<<from_node<<" to "<<to_node<<" for "<< services; 246 if(rate) 247 cout << " interval=" << rate; 248 if(copyFlag) 249 cout << " (internal data copy)"; 250 cout << endl; 869 } 870 cout << "Starting DimBridge from " << from_node << " to " << to_node << endl; 871 cout << "for " << services << endl; 872 if (eservices) 873 { 874 cout << "excluding " << eservices << endl; 875 } 876 if (n_replaces) 877 { 878 sptr = sstrings; 879 rptr = rstrings; 880 for (i = 0; i < n_replaces; i++) 881 { 882 cout << "replacing " << sptr << " by " << rptr << endl; 883 sptr += strlen(sptr) + 1; 884 rptr += strlen(rptr) + 1; 885 } 886 } 887 if ((rate) || (copyFlag)) 888 cout << "option(s):"; 889 if (rate) 890 cout << " update interval=" << rate; 891 if ((rate) && (copyFlag)) 892 cout << ","; 893 if (copyFlag) 894 cout << " internal data copy"; 895 if ((rate) || (copyFlag)) 896 cout << endl; 251 897 252 898 strcpy(bridge_name,"Bridge_"); 253 899 strcat(bridge_name, from_node); 254 if ( (p = strchr(bridge_name,'.')))900 if ((p = strchr(bridge_name, ':'))) 255 901 *p = '\0'; 902 if ((p = strchr(bridge_name, ','))) 903 *p = '\0'; 904 if ((p = strchr(bridge_name, '.'))) 905 *p = '\0'; 906 /* 907 strcat(bridge_name, "_"); 908 strcat(bridge_name, to_node); 909 if ((p = strchr(bridge_name, ':'))) 910 *p = '\0'; 911 if ((p = strchr(bridge_name, ','))) 912 *p = '\0'; 913 if ((p = strchr(bridge_name, '.'))) 914 *p = '\0'; 915 */ 916 p = bridge_name + strlen(bridge_name); 256 917 #ifndef WIN32 257 918 sprintf(p,"_%d",getpid()); … … 259 920 sprintf(p,"_%d",_getpid()); 260 921 #endif 261 DimClient::setDnsNode(from_node); 262 DimServer::setDnsNode(to_node); 263 while(1) 264 { 265 ptrs = (BridgeService *)lists.getHead(); 266 while(ptrs) 267 { 268 ptrs->clear(); 269 ptrs = (BridgeService *)lists.getNext(); 270 } 271 ptrc = (BridgeCommand *)listc.getHead(); 272 while(ptrc) 273 { 274 ptrc->clear(); 275 ptrc = (BridgeCommand *)listc.getNext(); 276 } 277 dbr.getServices(services); 278 while( (type = dbr.getNextService(service, format)) ) 279 { 280 known = 0; 281 ptrs = (BridgeService *)lists.getHead(); 282 while(ptrs) 283 { 284 if(!strcmp(ptrs->getName(), service)) 285 { 286 known = 1; 287 ptrs->set(); 288 break; 289 } 290 ptrs = (BridgeService *)lists.getNext(); 291 } 292 ptrc = (BridgeCommand *)listc.getHead(); 293 while(ptrc) 294 { 295 if(!strcmp(ptrc->getName(), service)) 296 { 297 known = 1; 298 ptrc->set(); 299 break; 300 } 301 ptrc = (BridgeCommand *)listc.getNext(); 302 } 303 if(strstr(service,"DIS_DNS")) 304 known = 1; 305 if(!known) 306 { 922 from_port = 0; 923 to_port = 0; 924 if ((p = strchr(from_node, ':'))) 925 { 926 *p = '\0'; 927 p++; 928 sscanf(p, "%d", &from_port); 929 } 930 if ((p = strchr(to_node, ':'))) 931 { 932 *p = '\0'; 933 p++; 934 sscanf(p, "%d", &to_port); 935 } 936 // cout << "Starting1 DimBridge from " << from_node << ":" << from_port <<" to " << to_node << ":" << to_port <<" for " << services << endl; 937 if (!from_port) 938 DimClient::setDnsNode(from_node); 939 else 940 DimClient::setDnsNode(from_node, from_port); 941 if(!to_port) 942 DimServer::setDnsNode(to_node); 943 else 944 DimServer::setDnsNode(to_node, to_port); 945 serverList = new ServerList((char *)"DIS_DNS/SERVER_LIST"); 946 if (serverList){} // to avoid a warning 947 // while (!GotInitialList) 948 // sleep(1); 949 // serverList->parseServerList(); 950 951 while (1) 952 { 953 done = 0; 954 checkBridgeServices(); 955 dbr.getServices("*"); 956 while ((type = dbr.getNextService(service, format))) 957 { 958 doBridgeService(service, format, type); 959 } 960 dontBridgeServices(); 961 servp = 0; 962 hash_index = -1; 963 while ((servp = bridge_hash_service_get_next(&hash_index, servp, 0))) 964 { 965 service = servp->name; 966 type = servp->type; 967 format = servp->format; 968 // dim_print_date_time(); 969 // cout << "Checking " << service << " reg "<< servp->registered << " type " << type << endl; 970 known = servp->registered; 971 if (known == 0) 972 { 973 done = 1; 307 974 if(type == DimSERVICE) 308 975 { 309 if(!rate) 310 ptrs = new BridgeService(service, format, copyFlag); 311 else 312 ptrs = new BridgeService(service, format, rate, copyFlag); 313 lists.add(ptrs); 976 dim_print_date_time(); 977 cout << "Start Bridging Service: " << service << endl; 978 if (!rate) 979 ptrs = new BridgeService(service, format, copyFlag); 980 else 981 ptrs = new BridgeService(service, format, rate, copyFlag); 982 servp->browserServicePtr = (void *)ptrs; 314 983 } 315 984 else if (type == DimCOMMAND) 316 985 { 317 // DimClient::setDnsNode(to_node); 986 dim_print_date_time(); 987 cout << "Start Bridging Command: " << service << endl; 988 // DimClient::setDnsNode(to_node); 318 989 ptrc = new BridgeCommand(service, format); 319 listc.add(ptrc);990 servp->browserServicePtr = (void *)ptrc; 320 991 // DimClient::setDnsNode(from_node); 321 992 } 322 } 323 } 324 ptrs = (BridgeService *)lists.getHead(); 325 while(ptrs) 326 { 327 aux_ptrs = 0; 328 if(!ptrs->find()) 329 { 330 lists.remove(ptrs); 331 aux_ptrs = ptrs; 332 } 333 ptrs = (BridgeService *)lists.getNext(); 334 if(aux_ptrs) 335 { 336 delete aux_ptrs; 337 } 338 } 339 ptrc = (BridgeCommand *)listc.getHead(); 340 while(ptrc) 341 { 342 aux_ptrc = 0; 343 if(!ptrc->find()) 344 { 345 listc.remove(ptrc); 346 aux_ptrc = ptrc; 347 } 348 ptrc = (BridgeCommand *)listc.getNext(); 349 if(aux_ptrc) 350 { 351 delete aux_ptrc; 352 } 353 } 354 sleep(5); 993 servp->registered = 1; 994 } 995 else if (known == -1) 996 { 997 done = -1; 998 if (type == DimSERVICE) 999 { 1000 ptrs = (BridgeService *)servp->browserServicePtr; 1001 if (ptrs) 1002 { 1003 dim_print_date_time(); 1004 cout << "Stop Bridging Service: " << ptrs->getName() << endl; 1005 delete ptrs; 1006 } 1007 } 1008 else if (type == DimCOMMAND) 1009 { 1010 ptrc = (BridgeCommand *)servp->browserServicePtr; 1011 if (ptrc) 1012 { 1013 dim_print_date_time(); 1014 cout << "Stop Bridging Command: " << ptrc->getName() << endl; 1015 delete ptrc; 1016 } 1017 } 1018 servp->registered = -2; 1019 } 1020 } 1021 if (poll_interval == 2) 1022 { 1023 // sleep(2); 1024 // dbr.getServices("*"); 1025 poll_interval = 5; 1026 // continue; 1027 } 1028 if (!done) 1029 { 1030 poll_interval = 30; 1031 } 1032 else if (done < 0) 1033 { 1034 bridge_hash_service_remove_many(-2); 1035 poll_interval = 2; 1036 } 1037 else 1038 { 1039 poll_interval = 5; 1040 } 1041 // cout << "done " << done << ", poll_interval " << poll_interval << endl; 1042 for (i = 0; i < poll_interval; i++) 1043 { 1044 sleep(1); 1045 if (poll_interval == 0) 1046 i = -2; 1047 } 1048 // cout << "out of sleep, poll_interval " << poll_interval << endl; 355 1049 } 356 1050 return 1; 357 1051 } 1052 1053 1054 1055 1056 1057 1058 ///////////////////////////// 1059 //////// Function for glob pattern matching. See http://www.cse.yorku.ca/~oz/ 1060 /* 1061 * robust glob pattern matcher 1062 * ozan s. yigit/dec 1994 1063 * public domain 1064 * 1065 * glob patterns: 1066 * * matches zero or more characters 1067 * ? matches any single character 1068 * [set] matches any character in the set 1069 * [^set] matches any character NOT in the set 1070 * where a set is a group of characters or ranges. a range 1071 * is written as two characters seperated with a hyphen: a-z denotes 1072 * all characters between a to z inclusive. 1073 * [-set] set matches a literal hypen and any character in the set 1074 * []set] matches a literal close bracket and any character in the set 1075 * 1076 * char matches itself except where char is '*' or '?' or '[' 1077 * \char matches char, including any pattern character 1078 * 1079 * examples: 1080 * a*c ac abc abbc ... 1081 * a?c acc abc aXc ... 1082 * a[a-z]c aac abc acc ... 1083 * a[-a-z]c a-c aac abc ... 1084 * 1085 * $Log: glob.c,v $ 1086 * Revision 1.3 1995/09/14 23:24:23 oz 1087 * removed boring test/main code. 1088 * 1089 * Revision 1.2 94/12/11 10:38:15 oz 1090 * cset code fixed. it is now robust and interprets all 1091 * variations of cset [i think] correctly, including [z-a] etc. 1092 * 1093 * Revision 1.1 94/12/08 12:45:23 oz 1094 * Initial revision 1095 */ 1096 1097 #ifndef NEGATE 1098 #define NEGATE '^' /* std cset negation char */ 1099 #endif 1100 1101 #define TRUE 1 1102 #define FALSE 0 1103 1104 int 1105 amatch(char *str, char *p) 1106 { 1107 int negate; 1108 int match; 1109 int c; 1110 1111 while (*p) { 1112 if (!*str && *p != '*') 1113 return FALSE; 1114 1115 switch (c = *p++) { 1116 1117 case '*': 1118 while (*p == '*') 1119 p++; 1120 1121 if (!*p) 1122 return TRUE; 1123 1124 if (*p != '?' && *p != '[' && *p != '\\') 1125 while (*str && *p != *str) 1126 str++; 1127 1128 while (*str) { 1129 if (amatch(str, p)) 1130 return TRUE; 1131 str++; 1132 } 1133 return FALSE; 1134 1135 case '?': 1136 if (*str) 1137 break; 1138 return FALSE; 1139 /* 1140 * set specification is inclusive, that is [a-z] is a, z and 1141 * everything in between. this means [z-a] may be interpreted 1142 * as a set that contains z, a and nothing in between. 1143 */ 1144 case '[': 1145 if (*p != NEGATE) 1146 negate = FALSE; 1147 else { 1148 negate = TRUE; 1149 p++; 1150 } 1151 1152 match = FALSE; 1153 1154 while (!match && (c = *p++)) { 1155 if (!*p) 1156 return FALSE; 1157 if (*p == '-') { /* c-c */ 1158 if (!*++p) 1159 return FALSE; 1160 if (*p != ']') { 1161 if (*str == c || *str == *p || 1162 (*str > c && *str < *p)) 1163 match = TRUE; 1164 } 1165 else { /* c-] */ 1166 if (*str >= c) 1167 match = TRUE; 1168 break; 1169 } 1170 } 1171 else { /* cc or c] */ 1172 if (c == *str) 1173 match = TRUE; 1174 if (*p != ']') { 1175 if (*p == *str) 1176 match = TRUE; 1177 } 1178 else 1179 break; 1180 } 1181 } 1182 1183 if (negate == match) 1184 return FALSE; 1185 /* 1186 * if there is a match, skip past the cset and continue on 1187 */ 1188 while (*p && *p != ']') 1189 p++; 1190 if (!*p++) /* oops! */ 1191 return FALSE; 1192 break; 1193 1194 case '\\': 1195 if (*p) 1196 c = *p++; 1197 default: 1198 if (c != *str) 1199 return FALSE; 1200 break; 1201 1202 } 1203 str++; 1204 } 1205 1206 return !*str; 1207 } 1208 1209 1210 1211 /////////////////////////////// END OF CODE FROM http://www.cse.yorku.ca/~oz/ 1212 1213 char *strlwr(char *str) 1214 { 1215 unsigned char *p = (unsigned char *)str; 1216 1217 while (*p) { 1218 *p = tolower((unsigned char)*p); 1219 p++; 1220 } 1221 1222 return str; 1223 } 1224 1225 // ps is a comma separated list of patterns. The function returns 1 as soon as one pattern matches 1226 int multiple_match(const char* str, const char* ps, int case_sensitive) { 1227 if (ps == 0) return 0; 1228 if (strlen(ps) == 0) return 0; 1229 char* str2 = new char[strlen(str) + 1]; 1230 strcpy(str2, str); 1231 1232 char* p; 1233 // the pattern must be copied in new memory because strtok modifies the string 1234 char* p2 = new char[strlen(ps) + 1]; 1235 strcpy(p2, ps); 1236 1237 if (case_sensitive == 0) { 1238 strlwr(str2); 1239 strlwr(p2); 1240 } 1241 1242 p = strtok(p2, ","); 1243 int result = 0; 1244 while (p != NULL) 1245 { 1246 if (amatch(str2, p) == 1) { 1247 result = 1; 1248 break; 1249 } 1250 p = strtok(NULL, ","); 1251 } 1252 delete(p2); 1253 p2 = NULL; 1254 delete(str2); 1255 str2 = NULL; 1256 return result; 1257 } 1258 1259 #define MAX_HASH_ENTRIES 5000 1260 1261 static SERVICE *BridgeService_hash_table[MAX_HASH_ENTRIES]; 1262 static int Service_new_entries[MAX_HASH_ENTRIES]; 1263 1264 int bridge_hash_service_init() 1265 { 1266 1267 int i; 1268 static int done = 0; 1269 1270 dim_lock(); 1271 if (!done) 1272 { 1273 for (i = 0; i < MAX_HASH_ENTRIES; i++) 1274 { 1275 /* 1276 BridgeService_hash_table[i] = (SERVICE *) malloc(sizeof(SERVICE)); 1277 dll_init((DLL *) BridgeService_hash_table[i]); 1278 */ 1279 BridgeService_hash_table[i] = 0; 1280 Service_new_entries[i] = 0; 1281 } 1282 done = 1; 1283 } 1284 dim_unlock(); 1285 return(1); 1286 } 1287 1288 int bridge_hash_service_insert(SERVICE *servp) 1289 { 1290 int index; 1291 1292 dim_lock(); 1293 index = HashFunction(servp->name, MAX_HASH_ENTRIES); 1294 if (!BridgeService_hash_table[index]) 1295 { 1296 BridgeService_hash_table[index] = (SERVICE *)malloc(sizeof(SERVICE)); 1297 dll_init((DLL *)BridgeService_hash_table[index]); 1298 } 1299 Service_new_entries[index]++; 1300 dll_insert_queue((DLL *)BridgeService_hash_table[index], 1301 (DLL *)servp); 1302 dim_unlock(); 1303 return(1); 1304 } 1305 1306 int bridge_hash_service_registered(int index, SERVICE *servp) 1307 { 1308 dim_lock(); 1309 servp->registered = 1; 1310 Service_new_entries[index]--; 1311 if (Service_new_entries[index] < 0) 1312 Service_new_entries[index] = 0; 1313 dim_unlock(); 1314 return 1; 1315 } 1316 1317 int bridge_hash_service_remove(SERVICE *servp) 1318 { 1319 int index; 1320 1321 dim_lock(); 1322 index = HashFunction(servp->name, MAX_HASH_ENTRIES); 1323 if (!BridgeService_hash_table[index]) 1324 { 1325 dim_unlock(); 1326 return(0); 1327 } 1328 dll_remove((DLL *)servp); 1329 dim_unlock(); 1330 return(1); 1331 } 1332 1333 1334 SERVICE *bridge_hash_service_exists(char *name) 1335 { 1336 int index; 1337 SERVICE *servp; 1338 1339 dim_lock(); 1340 index = HashFunction(name, MAX_HASH_ENTRIES); 1341 if (!BridgeService_hash_table[index]) 1342 { 1343 dim_unlock(); 1344 return((SERVICE *)0); 1345 } 1346 if ((servp = (SERVICE *)dll_search( 1347 (DLL *)BridgeService_hash_table[index], 1348 name, (int)strlen(name) + 1))) 1349 { 1350 dim_unlock(); 1351 return(servp); 1352 } 1353 dim_unlock(); 1354 return((SERVICE *)0); 1355 } 1356 1357 SERVICE *bridge_hash_service_get_next(int *curr_index, SERVICE *prevp, int new_entries) 1358 { 1359 int index; 1360 SERVICE *servp = 0; 1361 /* 1362 if(!prevp) 1363 { 1364 index = -1; 1365 } 1366 */ 1367 dim_lock(); 1368 index = *curr_index; 1369 if (index == -1) 1370 { 1371 index++; 1372 prevp = BridgeService_hash_table[index]; 1373 } 1374 if (!prevp) 1375 { 1376 prevp = BridgeService_hash_table[index]; 1377 } 1378 do 1379 { 1380 if (prevp) 1381 { 1382 if ((!new_entries) || (Service_new_entries[index] > 0)) 1383 { 1384 servp = (SERVICE *)dll_get_next( 1385 (DLL *)BridgeService_hash_table[index], 1386 (DLL *)prevp); 1387 if (servp) 1388 break; 1389 } 1390 } 1391 index++; 1392 if (index == MAX_HASH_ENTRIES) 1393 { 1394 *curr_index = -1; 1395 dim_unlock(); 1396 return((SERVICE *)0); 1397 } 1398 prevp = BridgeService_hash_table[index]; 1399 } while (!servp); 1400 *curr_index = index; 1401 dim_unlock(); 1402 return(servp); 1403 } 1404 1405 int bridge_hash_service_remove_many(int registered) 1406 { 1407 SERVICE *servp, *prevp; 1408 int hash_index, old_index; 1409 int n = 0; 1410 1411 dim_lock(); 1412 prevp = 0; 1413 hash_index = -1; 1414 old_index = -1; 1415 while ((servp = bridge_hash_service_get_next(&hash_index, prevp, 0))) 1416 { 1417 if (servp->registered == registered) 1418 { 1419 servp->registered = 0; 1420 bridge_hash_service_remove(servp); 1421 free(servp); 1422 n++; 1423 if (old_index != hash_index) 1424 prevp = 0; 1425 } 1426 else 1427 { 1428 prevp = servp; 1429 old_index = hash_index; 1430 } 1431 } 1432 dim_unlock(); 1433 return(n); 1434 } -
trunk/FACT++/dim/src/utilities.c
r18920 r19184 60 60 extern void init_sock(); 61 61 #endif 62 int ret; 62 63 63 64 DISABLE_AST … … 65 66 init_sock(); 66 67 #endif 68 node_name[0] = '\0'; 67 69 if( (p = getenv("DIM_HOST_NODE")) != NULL ) 68 70 { 69 strcpy( node_name, p ); 71 strncpy(node_name, p, (size_t)MAX_NODE_NAME); 72 node_name[MAX_NODE_NAME - 1] = '\0'; 70 73 ENABLE_AST 71 74 return(1); 72 75 } 73 if((gethostname(node_name, MAX_NODE_NAME)) == -1) 76 ret = gethostname(node_name, MAX_NODE_NAME); 77 node_name[MAX_NODE_NAME - 1] = '\0'; 78 if (ret == -1) 74 79 { 75 80 ENABLE_AST … … 78 83 #ifndef VxWorks 79 84 #ifndef RAID 80 if (!strchr(node_name,'.'))85 if (!strchr(node_name, '.')) 81 86 { 82 87 if ((host = gethostbyname(node_name)) != (struct hostent *)0) 83 88 { 84 strcpy(node_name,host->h_name); 85 if(!strchr(node_name,'.')) 89 strncpy(node_name, host->h_name, MAX_NODE_NAME); 90 node_name[MAX_NODE_NAME - 1] = '\0'; 91 if (!strchr(node_name, '.')) 86 92 { 87 93 if(host->h_aliases) … … 94 100 if(strchr(p,'.')) 95 101 { 96 strcpy(node_name,p); 102 strncpy(node_name, p, MAX_NODE_NAME); 103 node_name[MAX_NODE_NAME - 1] = '\0'; 97 104 break; 98 105 } … … 120 127 struct hostent *host; 121 128 #endif 122 char node_name[MAX_N ODE_NAME];129 char node_name[MAX_NAME]; 123 130 char *ptr; 124 131 … … 126 133 init_sock(); 127 134 #endif 128 gethostname(node_name, MAX_NODE_NAME); 135 gethostname(node_name, MAX_NAME); 136 node_name[MAX_NAME - 1] = '\0'; 129 137 #ifndef VxWorks 130 138 if ((host = (struct hostent *)gethostbyname(node_name)) == (struct hostent *)0) -
trunk/FACT++/dim/src/webDid/webDid.c
r18920 r19184 243 243 int n_found = 0; 244 244 char *ptr, str[256], *sptr, *sformat, *stype; 245 int type, index; 245 int type; 246 // int index; 246 247 char *addJSONChildStart(); 247 248 char *addJSONChildEnd(); … … 293 294 sformat = (char *)sptr + strlen((const char *)sptr) + 1; 294 295 stype = (char *)sformat + strlen((const char *)sformat) + 1; 295 if (*stype = '\n')296 if (*stype == '\n') 296 297 type = 0; 297 298 else if (*stype == 'C') … … 562 563 SERVER *servp; 563 564 DNS_SERVICE_INFO *servicep; 564 int i, j, n_services, index = 0, type; 565 char *ptr, *ptre, *ptr1, tmp[MAX_NAME], *sptr; 565 int i, n_services, index = 0; 566 char *ptr, *ptre, *ptr1; 567 // char tmp[MAX_NAME], *sptr; 568 // int j, type; 566 569 567 570 if(size){} … … 873 876 { 874 877 BROWSER *browserp; 878 int delete_browser(); 875 879 876 880 if ((browserp = find_browser(browser))) … … 878 882 return 1; 879 883 } 884 880 885 int delete_browser(BROWSER *browserp) 881 886 { 882 SERVICE *servicep;883 int i;887 // SERVICE *servicep; 888 int release_all_requests(); 884 889 885 890 release_all_requests(browserp); … … 1069 1074 REQUEST_PTR *find_request(SERVICE* servicep, int conn_id) 1070 1075 { 1071 REQUEST_PTR *reqpp;1076 // REQUEST_PTR *reqpp; 1072 1077 REQUEST *reqp; 1073 1078 … … 1093 1098 extern void sendData(); 1094 1099 BROWSER *browserp; 1095 int i;1100 // int i; 1096 1101 REQUEST *reqp; 1097 1102 REQUEST_PTR *reqpp; … … 1308 1313 // if ((*size == 4) && (*buffer == -1)) 1309 1314 servicep->is_nolink = 0; 1310 if ((*size == strlen(no_link_str)) && (!memcmp(buffer, no_link_str, strlen(no_link_str))))1315 if ((*size == (int)strlen(no_link_str)) && (!memcmp(buffer, no_link_str, strlen(no_link_str)))) 1311 1316 { 1312 1317 servicep->is_nolink = 1; … … 2298 2303 NODE *nodep; 2299 2304 SERVER *servp; 2300 char str[256] , aux[128];2305 char str[256]; 2301 2306 int selective = 0; 2302 int n_nodes,tot_n_nodes;2307 int tot_n_nodes; 2303 2308 int n_servers, tot_n_servers; 2304 2309 int ret, n_found = 0; -
trunk/FACT++/dim/src/webDid/webServer.c
r18920 r19184 326 326 char datatype[128]; 327 327 char *conv_buffer; 328 int conv_size = 0;329 328 char nolink[MAX_NAME]; 330 329 int nolinksize;
Note:
See TracChangeset
for help on using the changeset viewer.