Changeset 18920 for trunk/FACT++/dim
- Timestamp:
- 10/18/17 13:54:41 (7 years ago)
- Location:
- trunk/FACT++/dim
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/dim/README_v20.txt
r18349 r18920 1 1 2 DIM version 20r 15Release Notes2 DIM version 20r20 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 2015. 19 NOTE 3: The Version Number service provided by servers is now set to 2020. 20 21 06/07/2017 22 Changes for version 2020: 23 - All DIM log messages can now be caught by declaring an error_hlandler. 24 - Connect calls now use a non-blocking socket to avoit blocking for a long time (particularly in Windows). 25 - New re-designed version of webDid. 26 - Added conditional compilation settings for LABVIEWGSI/PHARLAP. 27 28 29 20/01/2017 30 Changes for version 2019: 31 - Changed slightly the definition of DIM constants in C++, they clashed with LHCb/ROOT software. 32 - A server didn't work properly when declaring the same server name to two different dnss. 33 Although this is still not allowed, because it would mean several services with the same name 34 in the same server (and couldn't resolve which one should be sent to which client), now 35 if the user declares the same server name a "-n" (where n is the dns instance number) will 36 be appended to the server name. 37 - Fixed a bug reported by Alice, whereby if a tcpip error (broken pipe) got received when 38 updating a service following a client request, the server would crash. 39 - Fixed a deadlock in C++ 40 41 42 30/06/2016 43 Changes for version 2018: 44 - Removed the function do_dis_add_cmnd(), had became obsolete by do_dis_add_cmnd_dns(). 45 - DIM now accepts servers to keep running even though they publish duplicated services: 46 - If all services are duplicated the server will exit like before 47 - If the server name is duplicated the server will also exit like before 48 - Otherwise the server will keep running providing only the non-duplicated services 49 - The server will print the name of each duplicated service to the logfile/stdout 50 - A DIM error handler can be installed by the user to detect or change this behaviour 51 - This new feature can only be used if both the Server and the DNS are using this new version 52 (otherwise the old behaviour will occur) 53 - The DimBrowser class now accepts to browse over DIM Servers with no name 54 55 56 24/03/2016 57 Changes for version 2017: 58 - Removed the function do_dis_add_service(), became obsolete by do_dis_add_service_dns(). 59 - On Windows servers might not reconnect after DNS restart. Bug introduced in version v20r14 60 (when the keepalive mechanism was introduced for TCPIP client connections). Fixed. 61 62 63 04/12/2015 64 Changes for version 2016: 65 - DIM had stopped working on MAC OS X, since v20r12 and the replacement of select() by poll(). 66 This is now fixed. 67 20 68 21 69 01/09/2015 22 70 Changes for version 2015: 23 71 - A DIM Server did not properly accept a DimServer::stop(), folowed by a DimServer::start(), 24 also DID didn't cope with the above, in particular if the server changed name - Fixed.25 72 26 73 -
trunk/FACT++/dim/WebDID/did.js
r18058 r18920 386 386 { 387 387 serviceInfoArea.update("Updating - state "+HTTPPacket.readyState+"..."); 388 console.log("receiveing", HTTPPacket.readyState); 388 389 if ( HTTPPacket.readyState != 4 ) 389 390 return; … … 399 400 // { 400 401 serviceInfoArea.update(HTTPPacket.responseText); 402 console.log("received answer", HTTPPacket.responseText); 401 403 serviceInfoArea.setVisible(1); 402 404 commandInfoArea.setVisible(0); -
trunk/FACT++/dim/dim/dim.h
r18349 r18920 14 14 #include "dim_common.h" 15 15 16 #define DIM_VERSION_NUMBER 2015 17 18 16 #define DIM_VERSION_NUMBER 2020 17 18 #ifdef LABVIEWGSI 19 /*this is a hack, but we have to overcome the problem that LabVIEW uses Motorola endian on an Intel machine*/ 20 #define MY_LITTLE_ENDIAN 0x2 21 #define MY_BIG_ENDIAN 0x1 22 #else 19 23 #define MY_LITTLE_ENDIAN 0x1 20 24 #define MY_BIG_ENDIAN 0x2 25 #endif 21 26 22 27 #define VAX_FLOAT 0x10 … … 163 168 #define MAX_CONNS 1024 164 169 #define ID_BLOCK 512 170 #ifdef LABVIEWGSI 171 /*changed buffer size to allow LabVIEW to connect to itself*/ 172 #define TCP_RCV_BUF_SIZE /*16384*//*32768*//*65536*/262144 173 #else 165 174 #define TCP_RCV_BUF_SIZE /*16384*//*32768*/65536 175 #endif 166 176 #define TCP_SND_BUF_SIZE /*16384*//*32768*/65536 167 177 #endif … … 205 215 #define TEST_WRITE_TAG 25 /* DTQ tag for test writes */ 206 216 #define WRITE_TMOUT 5 /* Interval to wait while writing. */ 217 #ifndef WIN32 218 #define CONNECT_TMOUT 1 /* Interval to wait while connecting. */ 219 #else 220 #define CONNECT_TMOUT 2 /* Interval to wait while connecting. */ 221 #endif 207 222 208 223 #define OPN_MAGIC 0xc0dec0de /* Magic value 1st packet */ … … 287 302 int size; 288 303 int type; 304 char dup_info[1]; 289 305 } DNS_DIS_PACKET; 290 306 -
trunk/FACT++/dim/dim/dim_common.h
r18058 r18920 1 #ifndef __ COMMONDEFS2 #define __ COMMONDEFS1 #ifndef __DIM_COMMONDEFS 2 #define __DIM_COMMONDEFS 3 3 4 4 /* Service type definition */ 5 5 6 #ifndef ONCE_ONLY 6 #ifndef DIM_DEFINITIONS_DECLARED 7 #define DIM_DEFINITIONS_DECLARED 8 9 #ifdef __cplusplus 10 static const int ONCE_ONLY= 0x01; 11 static const int TIMED= 0x02; 12 static const int MONITORED= 0x04; 13 static const int COMMAND= 0x08; 14 static const int DIM_DELETE= 0x10; 15 static const int MONIT_ONLY= 0x20; 16 static const int UPDATE= 0x40; 17 static const int TIMED_ONLY= 0x80; 18 static const int MONIT_FIRST= 0x100; 19 static const int MAX_TYPE_DEF= 0x100; 20 static const int STAMPED= 0x1000; 21 #else 7 22 #define ONCE_ONLY 0x01 8 23 #define TIMED 0x02 … … 16 31 #define MAX_TYPE_DEF 0x100 17 32 #define STAMPED 0x1000 33 #endif 18 34 19 35 typedef enum { SRC_NONE, SRC_DIS, SRC_DIC, SRC_DNS, SRC_DNA, SRC_USR }SRC_TYPES; -
trunk/FACT++/dim/src/dic.c
r18349 r18920 520 520 int once_only, size = 0; 521 521 register DIC_SERVICE *servp; 522 522 char str[512]; 523 523 524 /* 524 525 dim_print_date_time(); … … 554 555 if((servp->pending == WAITING_DNS_UP) || (servp->pending == WAITING_DNS_ANSWER)) 555 556 { 557 sprintf(str, "Client Sending Command: Command %s discarded, no DNS answer\n", servp->serv_name); 558 error_handler(0, DIM_ERROR, DIMDNSCNERR, str); 559 /* 556 560 dim_print_date_time(); 557 printf(" 561 printf("Client Sending Command: Command %s discarded, no DNS answer\n", servp->serv_name); 558 562 fflush(stdout); 563 */ 559 564 } 560 565 /* … … 1894 1899 static int serv_packet_size = 0; 1895 1900 int type, ret; 1901 char str[256]; 1896 1902 1897 1903 if( !serv_packet_size ) { … … 1912 1918 if(!ret) 1913 1919 { 1914 dim_print_date_time(); 1915 printf(" Client Sending Service Request: Couldn't write to Conn %3d : Server %s@%s service %s\n", 1920 sprintf(str, "Client Sending Service Request: Couldn't write to Conn %3d : Server %s@%s service %s\n", 1916 1921 conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node, servp->serv_name); 1917 fflush(stdout);1922 error_handler(0, DIM_ERROR, DIMTCPWRTMO, str); 1918 1923 } 1919 1924 return(ret); … … 1961 1966 int ret; 1962 1967 CMNDCB_ITEM *itemp; 1968 char str[256]; 1963 1969 1964 1970 size = servp->fill_size; … … 2033 2039 if(!ret) 2034 2040 { 2035 dim_print_date_time(); 2036 printf(" Client Sending Command: Couldn't write to Conn %3d : Server %s@%s\n",conn_id, 2041 sprintf(str, "Client Sending Command: Couldn't write to Conn %3d : Server %s@%s\n", conn_id, 2037 2042 Net_conns[conn_id].task, Net_conns[conn_id].node); 2038 fflush(stdout);2043 error_handler(0, DIM_ERROR, DIMTCPWRTMO, str); 2039 2044 } 2040 2045 return(ret); -
trunk/FACT++/dim/src/diccpp.cxx
r15282 r18920 987 987 ret = itsData[1]->getToken(currToken); 988 988 if(!ret) return 0; 989 server = currToken; 990 ret = itsData[1]->getToken(currToken); 989 if(!itsData[1]->cmpToken((char *)"@")) 990 { 991 server = currToken; 992 ret = itsData[1]->getToken(currToken); 993 } 991 994 if(!itsData[1]->cmpToken((char *)"@")) 992 995 return 0; -
trunk/FACT++/dim/src/dim_thr.c
r15282 r18920 736 736 else if(pclass == 2) 737 737 p = REALTIME_PRIORITY_CLASS; 738 /*added by dietrich beck, GSI*/ 739 #ifdef PHARLAP 740 ret = 1; 741 #else 738 742 ret = SetPriorityClass(hProc, p); 743 #endif 739 744 if(ret) 740 745 return 1; … … 755 760 hProc = GetCurrentProcess(); 756 761 762 /*added by dietrich beck, GSI*/ 763 #ifdef PHARLAP 764 ret = NORMAL_PRIORITY_CLASS; 765 #else 757 766 ret = GetPriorityClass(hProc); 758 if(ret == 0) 767 #endif 768 if (ret == 0) 759 769 return 0; 760 770 if(ret == IDLE_PRIORITY_CLASS) -
trunk/FACT++/dim/src/dis.c
r18349 r18920 178 178 void (*user_routine)(), dim_long tag, dim_long dnsid ) ); 179 179 _DIM_PROTO( static DIS_DNS_CONN *create_dns, (dim_long dnsid) ); 180 /* 181 _DIM_PROTO( int do_dis_remove_service, (unsigned service_id, int do_stop_serving, void **dnsp ) ); 182 _DIM_PROTO( void do_dis_stop_serving_dns, (DIS_DNS_CONN *dnsp ) ); 183 */ 180 184 181 185 void dis_set_debug_on() … … 324 328 } 325 329 326 static unsigned do_dis_add_service( char *name, char *type, void *address, int size,327 void (*user_routine)(), dim_long tag )328 {329 return do_dis_add_service_dns( name, type, address, size,330 user_routine, tag, 0 );331 }332 333 330 #ifdef VxWorks 334 331 void dis_destroy(int tid) … … 379 376 DISABLE_AST 380 377 */ 381 ret = do_dis_add_service ( name, type, address, size, user_routine, tag);378 ret = do_dis_add_service_dns( name, type, address, size, user_routine, tag, 0); 382 379 #ifdef VxWorks 383 380 servp = (SERVICE *)id_get_ptr(ret, SRC_DIS); … … 489 486 } 490 487 491 static unsigned do_dis_add_cmnd( char *name, char *type, void (*user_routine)(), dim_long tag)492 {493 return do_dis_add_cmnd_dns(name, type, user_routine, tag, 0);494 }495 496 488 unsigned dis_add_cmnd( char *name, char *type, void (*user_routine)(), dim_long tag ) 497 489 { … … 501 493 DISABLE_AST 502 494 */ 503 ret = do_dis_add_cmnd ( name, type, user_routine, tag);495 ret = do_dis_add_cmnd_dns( name, type, user_routine, tag, 0 ); 504 496 /* 505 497 ENABLE_AST … … 639 631 } 640 632 633 int decode_duplicated_info(char *info, char *sname) 634 { 635 int n_dupl; 636 /* 637 int first_service = 1; 638 */ 639 unsigned service_id; 640 char *ptr; 641 SERVICE *servp; 642 char str[256]; 643 644 ptr = strchr(info,' '); 645 if(ptr) 646 { 647 *ptr = '\0'; 648 strcpy(sname, info); 649 ptr++; 650 sscanf(ptr,"%d",&n_dupl); 651 } 652 ptr = strchr(ptr,' '); 653 while(ptr) 654 { 655 ptr++; 656 sscanf(ptr,"%x",&service_id); 657 if(service_id) 658 { 659 service_id &= 0x0FFFFFFF; 660 servp = (SERVICE *)id_get_ptr(service_id, SRC_DIS); 661 if(servp) 662 { 663 if((unsigned)servp->id == service_id) 664 { 665 servp->registered = -1; 666 /* 667 if(first_service) 668 { 669 strcat(sname, " (ex: "); 670 strcat(sname, servp->name); 671 strcat(sname, ")"); 672 first_service = 0; 673 } 674 */ 675 /* 676 if(Debug_on) 677 { 678 */ 679 sprintf(str, "Service %s already declared\n", servp->name); 680 error_handler(0, DIM_WARNING, DIMDNSDUPLC, str, -1); 681 /* 682 } 683 */ 684 } 685 } 686 } 687 ptr = strchr(ptr,' '); 688 } 689 return(n_dupl); 690 } 691 641 692 void recv_dns_dis_rout( int conn_id, DNS_DIS_PACKET *packet, int size, int status ) 642 693 { 643 char str[ 128];694 char str[MAX_NAME*2], dupl_server[MAX_NAME*2]; 644 695 int dns_timr_time; 645 696 extern int rand_tmout(int, int); … … 649 700 extern void do_dis_stop_serving_dns(DIS_DNS_CONN *); 650 701 DIS_DNS_CONN *dnsp; 651 int type, exit_code ;702 int type, exit_code, severity, n_dupl; 652 703 653 704 if(size){} … … 709 760 break; 710 761 case DNS_DIS_KILL : 711 sprintf(str,712 "%s: Some Services already known to DNS",713 dnsp->task_name);714 762 /* 715 763 exit(2); 716 764 */ 717 Serving = -1; 718 error_handler(0, DIM_FATAL, DIMDNSDUPLC, str, -1); 765 severity = DIM_FATAL; 766 if(size > DNS_DIS_HEADER) 767 { 768 n_dupl = decode_duplicated_info(packet->dup_info, dupl_server); 769 if(exit_code == 1) 770 { 771 Serving = -1; 772 sprintf(str, "%s: Server already declared by %s", dnsp->task_name, dupl_server); 773 } 774 else 775 { 776 severity = DIM_WARNING; 777 sprintf(str, "%s: %d Services already declared by %s", dnsp->task_name, 778 n_dupl, dupl_server); 779 } 780 } 781 else 782 { 783 Serving = -1; 784 sprintf(str, "%s: Some Services already known to DNS", 785 dnsp->task_name); 786 } 787 error_handler(0, severity, DIMDNSDUPLC, str, -1); 719 788 /* 720 789 do_dis_stop_serving_dns(dnsp); … … 850 919 n_services = 0; 851 920 tot_n_services = 0; 852 if( flag == NONE ) { 921 if( flag == NONE ) 922 { 853 923 dis_dns_p->n_services = htovl(n_services); 854 924 dis_dns_p->size = htovl( DIS_DNS_HEADER + … … 878 948 { 879 949 if(servp->dnsp == dnsp) 880 servp->registered = 0; 950 { 951 if(servp->registered >= 0) 952 servp->registered = 0; 953 } 881 954 } 882 955 } … … 890 963 if( flag == MORE ) 891 964 { 892 if( servp->registered ) 965 if( servp->registered != 0) 966 { 967 continue; 968 } 969 } 970 else if( flag == ALL ) 971 { 972 if( servp->registered < 0) 893 973 { 894 974 continue; … … 1095 1175 char str0[MAX_NAME], str1[MAX_NAME],str2[MAX_NAME], 1096 1176 str3[MAX_NAME],str4[MAX_NAME]; 1097 char task_name_aux[MAX_TASK_NAME] ;1177 char task_name_aux[MAX_TASK_NAME], task_name[MAX_NAME]; 1098 1178 extern int open_dns(); 1099 1179 extern DIS_DNS_CONN *dis_find_dns(dim_long); 1180 extern int dis_find_dns_task(dim_long, char *); 1100 1181 DIS_DNS_CONN *dnsp; 1101 1182 unsigned int more_ids[10] = {0}; 1183 int n; 1102 1184 1103 1185 dis_init(); … … 1121 1203 dll_init( (DLL *) Client_head ); 1122 1204 } 1205 strncpy( task_name, task, (size_t)MAX_NAME ); 1206 task_name[MAX_NAME-1] = '\0'; 1123 1207 if(dnsid == 0) 1124 1208 { … … 1127 1211 else if(!(dnsp = dis_find_dns(dnsid))) 1128 1212 { 1213 if((n = dis_find_dns_task(dnsid, task)) > 0) 1214 { 1215 sprintf(task_name, "%s-%i", task, n); 1216 } 1129 1217 dnsp = create_dns(dnsid); 1130 1218 } … … 1133 1221 if(Dis_first_time) 1134 1222 { 1135 strncpy( task_name_aux, task , (size_t)MAX_TASK_NAME );1223 strncpy( task_name_aux, task_name, (size_t)MAX_TASK_NAME ); 1136 1224 task_name_aux[MAX_TASK_NAME-1] = '\0'; 1137 1225 Port_number = SEEK_PORT; … … 1153 1241 dnsp->dis_first_time = 0; 1154 1242 1155 sprintf(str0, "%s/VERSION_NUMBER", task); 1156 sprintf(str1, "%s/CLIENT_LIST", task); 1157 sprintf(str2, "%s/SERVICE_LIST", task); 1158 sprintf(str3, "%s/SET_EXIT_HANDLER", task); 1159 sprintf(str4, "%s/EXIT", task); 1160 1161 more_ids[0] = do_dis_add_service_dns( str0, "L", &Version_number, 1243 sprintf(str0, "%s/VERSION_NUMBER", task_name); 1244 sprintf(str1, "%s/CLIENT_LIST", task_name); 1245 sprintf(str2, "%s/SERVICE_LIST", task_name); 1246 sprintf(str3, "%s/SET_EXIT_HANDLER", task_name); 1247 sprintf(str4, "%s/EXIT", task_name); 1248 1249 /*added by dietrich beck, GSI*/ 1250 #ifdef LABVIEWGSI 1251 Version_number = _swapl(Version_number); //need to swap this number, since we hacked MY_LITTLE_ENDIAN 1252 #endif 1253 more_ids[0] = do_dis_add_service_dns(str0, "L", &Version_number, 1162 1254 sizeof(Version_number), 0, 0, dnsid ); 1163 1255 … … 1169 1261 more_ids[4] = do_dis_add_cmnd_dns( str4, "L:1", exit_handler, 0, dnsid ); 1170 1262 more_ids[5] = 0; 1171 strcpy( dnsp->task_name, task );1263 strcpy( dnsp->task_name, task_name ); 1172 1264 if(Debug_on) 1173 1265 { 1174 1266 dim_print_date_time(); 1175 printf("start serving %s\n",task );1267 printf("start serving %s\n",task_name); 1176 1268 } 1177 1269 } … … 1258 1350 int find_release_request(); 1259 1351 DIS_DNS_CONN *dnsp; 1352 int ret = 1; 1260 1353 1261 1354 if(size){} … … 1371 1464 if((type != MONIT_ONLY) && (type != UPDATE)) 1372 1465 { 1373 execute_service(newp->req_id);1466 ret = execute_service(newp->req_id); 1374 1467 } 1375 1468 if((type != MONIT_ONLY) && (type != MONIT_FIRST)) … … 1383 1476 } 1384 1477 } 1385 if( new_client)1478 if((new_client) && (ret != -1)) 1386 1479 { 1387 1480 Last_client = conn_id; … … 1400 1493 register REQUEST *reqp; 1401 1494 register SERVICE *servp; 1402 char str[ 80], def[MAX_NAME];1495 char str[256], def[MAX_NAME]; 1403 1496 int conn_id, last_conn_id; 1404 1497 int *pkt_buffer, header_size, aux; … … 1410 1503 #endif 1411 1504 FORMAT_STR format_data_cp[MAX_NAME/4]; 1505 int ret = 1; 1412 1506 1413 1507 reqp = (REQUEST *)id_get_ptr(req_id, SRC_DIS); … … 1519 1613 if(reqp->delay_delete > 1) 1520 1614 { 1521 printf("Server (Explicitly) Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",1615 sprintf(str, "Server (Explicitly) Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n", 1522 1616 servp->name, conn_id, 1523 1617 Net_conns[conn_id].task, Net_conns[conn_id].node); … … 1525 1619 else 1526 1620 { 1527 printf("Server Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",1621 sprintf(str, "Server Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n", 1528 1622 servp->name, conn_id, 1529 1623 Net_conns[conn_id].task, Net_conns[conn_id].node); 1530 1624 } 1531 fflush(stdout);1625 error_handler(0, DIM_WARNING, DIMTCPWRTMO, str, -1); 1532 1626 } 1533 1627 if(reqp->delay_delete > 1) … … 1539 1633 reqp->delay_delete = 0; 1540 1634 release_conn(conn_id, 1, 0); 1635 ret = -1; 1541 1636 } 1542 1637 } … … 1553 1648 if(reqp->delay_delete > 0) 1554 1649 reqp->delay_delete--; 1555 return( 1);1650 return(ret); 1556 1651 } 1557 1652 … … 1562 1657 static int packet_size = 0; 1563 1658 int service_id; 1659 char str[256]; 1564 1660 1565 1661 reqp = (REQUEST *)id_get_ptr(req_id, SRC_DIS); … … 1579 1675 if( !dna_write(reqp->conn_id, dis_packet, DIS_HEADER) ) 1580 1676 { 1581 dim_print_date_time(); 1582 printf(" Server Removing Service: Couldn't write to Conn %3d : Client %s@%s\n", 1677 sprintf(str, "Server Removing Service: Couldn't write to Conn %3d : Client %s@%s\n", 1583 1678 reqp->conn_id, Net_conns[reqp->conn_id].task, Net_conns[reqp->conn_id].node); 1584 fflush(stdout);1679 error_handler(0, DIM_WARNING, DIMTCPWRTMO, str, -1); 1585 1680 release_conn(reqp->conn_id, 0, 0); 1586 1681 } … … 2058 2153 static int packet_size = 0; 2059 2154 int conn_id; 2060 char str[ 128];2155 char str[256]; 2061 2156 2062 2157 DISABLE_AST … … 2098 2193 if( !dna_write_nowait(conn_id, dis_packet, size + DIS_HEADER) ) 2099 2194 { 2100 dim_print_date_time(); 2101 printf(" Server Sending Service: Couldn't write to Conn %3d : Client %s@%s\n",conn_id, 2195 sprintf(str, "Server Sending Service: Couldn't write to Conn %3d : Client %s@%s\n",conn_id, 2102 2196 Net_conns[conn_id].task, Net_conns[conn_id].node); 2103 fflush(stdout);2197 error_handler(0, DIM_WARNING, DIMTCPWRTMO, str, -1); 2104 2198 release_conn(conn_id, 1, 0); 2105 2199 } … … 2111 2205 2112 2206 int dis_remove_service(unsigned service_id) 2207 { 2208 int ret; 2209 void *dnsp; 2210 int do_dis_remove_service(unsigned, int , void **); 2211 2212 ret = do_dis_remove_service(service_id, 1, &dnsp); 2213 return ret; 2214 } 2215 2216 int do_dis_remove_service(unsigned service_id, int do_stop_serving, void **thednsp) 2113 2217 { 2114 2218 register REQUEST *reqp, *auxp; … … 2197 2301 if(n_services == 5) 2198 2302 { 2199 if(Dis_conn_id) 2200 { 2201 dna_close(Dis_conn_id); 2202 Dis_conn_id = 0; 2203 } 2204 ENABLE_AST 2303 if(do_stop_serving) 2304 { 2305 if(Dis_conn_id) 2306 { 2307 dna_close(Dis_conn_id); 2308 Dis_conn_id = 0; 2309 } 2310 ENABLE_AST 2311 } 2312 else 2313 { 2314 *thednsp = dnsp; 2315 ENABLE_AST 2316 return -1; 2317 } 2318 2205 2319 /* 2206 2320 dis_stop_serving(); … … 2338 2452 2339 2453 dnsp = dis_find_dns(dnsid); 2340 do_dis_stop_serving_dns(dnsp); 2454 if(dnsp) 2455 do_dis_stop_serving_dns(dnsp); 2341 2456 } 2342 2457 … … 2701 2816 dim_print_date_time(); 2702 2817 dna_get_node_task(conn_id, node, task); 2703 printf(" 2818 printf("Couldn't write to client %s@%s, releasing connection %d\n", 2704 2819 task, node, conn_id); 2705 2820 fflush(stdout); … … 2987 3102 if(servp->dnsp != dnsp) 2988 3103 continue; 2989 if(servp->registered )3104 if(servp->registered > 0) 2990 3105 { 2991 3106 /* … … 3017 3132 buff_ptr += (int)strlen(buff_ptr); 3018 3133 } 3019 else if( servp->registered < (Last_n_clients+1))3134 else if((servp->registered > 0) && (servp->registered < (Last_n_clients+1))) 3020 3135 { 3021 3136 if(!done) … … 3371 3486 */ 3372 3487 return dnsp; 3488 } 3489 3490 int dis_find_dns_task(dim_long dnsid, char *task) 3491 { 3492 DIS_DNS_CONN *dnsp; 3493 int n = 0; 3494 3495 dnsp = (DIS_DNS_CONN *) DNS_head; 3496 while ( (dnsp = (DIS_DNS_CONN *) dll_get_next( (DLL *) DNS_head, (DLL *) dnsp))) 3497 { 3498 if(!strcmp(dnsp->task_name, task)) 3499 n++; 3500 } 3501 return n; 3373 3502 } 3374 3503 -
trunk/FACT++/dim/src/discpp.cxx
r18058 r18920 18 18 extern "C" { 19 19 extern void dis_init(); 20 extern int do_dis_remove_service(unsigned service_id, int do_stop_serving, void **dnsp ); 21 extern void do_dis_stop_serving_dns(void *dnsp); 20 22 21 23 static void user_routine( void *tagp, void **buf, int *size, int *first_time) … … 1001 1003 DimService::~DimService() 1002 1004 { 1005 int ret = 0; 1006 void *dnsp; 1007 1003 1008 DISABLE_AST 1004 1009 if(itsName) … … 1009 1014 // id_free(itsTagId, SRC_DIS); 1010 1015 if(itsId) 1011 dis_remove_service( itsId);1016 ret = do_dis_remove_service( itsId, 0, &dnsp ); 1012 1017 itsId = 0; 1013 1018 ENABLE_AST 1019 if(ret == -1) 1020 { 1021 do_dis_stop_serving_dns(dnsp); 1022 } 1014 1023 } 1015 1024 … … 1487 1496 DimCommand::~DimCommand() 1488 1497 { 1498 int ret; 1499 void *dnsp; 1500 1489 1501 DISABLE_AST 1490 1502 delete[] itsName; … … 1493 1505 // id_free(itsTagId, SRC_DIS); 1494 1506 if(itsId) 1495 dis_remove_service( itsId);1507 ret = do_dis_remove_service( itsId, 0, &dnsp ); 1496 1508 itsId = 0; 1497 1509 ENABLE_AST 1510 if(ret == -1) 1511 { 1512 do_dis_stop_serving_dns(dnsp); 1513 } 1498 1514 } 1499 1515 … … 1514 1530 DimRpc::~DimRpc() 1515 1531 { 1532 int ret; 1533 void *dnsp; 1534 1516 1535 DISABLE_AST 1517 1536 delete[] itsName; … … 1521 1540 // id_free(itsTagId, SRC_DIS); 1522 1541 if(itsIdIn) 1523 dis_remove_service( itsIdIn);1542 ret = do_dis_remove_service( itsIdIn, 0, &dnsp ); 1524 1543 if(itsIdOut) 1525 dis_remove_service( itsIdOut);1544 ret = do_dis_remove_service( itsIdOut, 0, &dnsp ); 1526 1545 itsIdIn = 0; 1527 1546 itsIdOut = 0; 1528 1547 ENABLE_AST 1548 if(ret == -1) 1549 { 1550 do_dis_stop_serving_dns(dnsp); 1551 } 1529 1552 } 1530 1553 -
trunk/FACT++/dim/src/dna.c
r15282 r18920 16 16 #define DNA 17 17 #include <dim.h> 18 #include <time.h> 18 19 19 20 /* global definitions */ … … 353 354 tcpip_code = dna_write_bytes(conn_id, &test_pkt, READ_HEADER_SIZE,0); 354 355 if(tcpip_failure(tcpip_code)) { 355 /* Connection lost. Signal upper layer ? */ 356 /* Connection lost. Signal upper layer ? No -> creates a deadlock in the Timer Thread*/ 357 /* 356 358 if(dna_connp->read_ast) 357 359 dna_connp->read_ast(conn_id, NULL, 0, STA_DISC); 360 */ 358 361 return; 359 362 } … … 624 627 time_t oldest; 625 628 int oldesti = 0; 629 /* 626 630 extern time_t time(); 631 */ 627 632 628 633 if(type == 0) … … 822 827 if (tcpip_failure(tcpip_code)) 823 828 { 829 if(src_type == SRC_DIS) 830 strcpy(src_type_str,"Server"); 831 else if(src_type == SRC_DIC) 832 strcpy(src_type_str,"Client"); 833 else 834 strcpy(src_type_str,"Unknown type"); 824 835 dim_print_date_time(); 825 printf(" Client Establishing Connection: Couldn't write to Conn %3d : Server %s@%s\n",conn_id, 826 Net_conns[conn_id].task, Net_conns[conn_id].node); 827 fflush(stdout); 836 sprintf(str," %s Establishing Connection: Couldn't write to Conn %3d : Server %s@%s\n", 837 src_type_str, conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node); 838 if (!strcmp(server_task, "DIM_DNS")) 839 dna_report_error(conn_id, tcpip_code, str, DIM_ERROR, DIMDNSCNERR); 840 else 841 dna_report_error(conn_id, tcpip_code, str, DIM_ERROR, DIMTCPCNERR); 828 842 dna_close(conn_id); 829 843 return(0); … … 841 855 dna_report_error(conn_id, -1, 842 856 "Write timeout, disconnecting from", DIM_ERROR, DIMTCPWRTMO); 843 if(!find_pend_conn(Net_conns[conn_id].node, Net_conns[conn_id].task, 0, 0, 1)) 857 if (!find_pend_conn(Net_conns[conn_id].node, Net_conns[conn_id].task, 0, 0, 1)) 858 { 844 859 ins_pend_conn(Net_conns[conn_id].node, Net_conns[conn_id].task, 0, 0, 1, time(NULL)); 860 } 845 861 } 846 862 release_conn(conn_id); -
trunk/FACT++/dim/src/dns.c
r18097 r18920 116 116 { 117 117 dim_print_date_time(); 118 printf(" 118 printf("Disconnect received - conn: %d to %s@%s\n", conn_id, 119 119 Net_conns[conn_id].task,Net_conns[conn_id].node ); 120 120 } … … 126 126 { 127 127 dim_print_date_time(); 128 printf(" 128 printf("Connection request received - conn: %d\n", conn_id); 129 129 } 130 130 /* handle_conn( conn_id ); */ … … 141 141 default: 142 142 dim_print_date_time(); 143 printf(" 143 printf("conn: %d to %s@%s, Bad packet\n", conn_id, 144 144 Net_conns[conn_id].task,Net_conns[conn_id].node ); 145 145 printf("packet->size = %d\n", vtohl(packet->size)); … … 155 155 default: 156 156 dim_print_date_time(); 157 printf( " 157 printf( "- DIM panic: recv_rout(): Bad switch, exiting...\n"); 158 158 abort(); 159 159 } … … 172 172 } 173 173 */ 174 } 175 176 void create_service_entry( int conn_id, DIS_DNS_PACKET *packet, int i, int state) 177 { 178 DNS_SERVICE *servp; 179 int name_too_long = 0; 180 char *ptrt; 181 void service_insert(); 182 183 if((int)strlen(Dns_conns[conn_id].task_name) == MAX_TASK_NAME-4-1) 184 name_too_long = 1; 185 servp = (DNS_SERVICE *)malloc(sizeof(DNS_SERVICE)); 186 if(name_too_long) 187 { 188 if(strstr(packet->services[i].service_name,"/CLIENT_LIST")) 189 { 190 strncpy(Dns_conns[conn_id].long_task_name, packet->services[i].service_name, 191 (size_t)MAX_NAME); 192 ptrt = strstr(Dns_conns[conn_id].long_task_name,"/CLIENT_LIST"); 193 *ptrt = '\0'; 194 } 195 } 196 strncpy( servp->serv_name, 197 packet->services[i].service_name, 198 (size_t)MAX_NAME ); 199 strncpy( servp->serv_def, 200 packet->services[i].service_def, 201 (size_t)MAX_NAME ); 202 servp->state = state; 203 servp->conn_id = conn_id; 204 servp->server_format = vtohl(packet->format); 205 servp->serv_id = vtohl(packet->services[i].service_id); 206 dll_insert_queue( (DLL *) 207 Dns_conns[conn_id].service_head, 208 (DLL *) servp ); 209 servp->node_head = (RED_NODE *) malloc(sizeof(NODE)); 210 dll_init( (DLL *) servp->node_head ); 211 servp->next = 0; 212 if(state == 1) 213 { 214 service_insert( &(servp->next) ); 215 Dns_conns[conn_id].n_services++; 216 } 217 } 218 219 int warn_server(int conn_id) 220 { 221 DNS_SERVICE *servp; 222 DNS_DIS_PACKET *dis_packet; 223 int n_dupl, dupl_conn_id; 224 char vname[MAX_NAME], dupl_server[MAX_NAME]; 225 int type, size, dupl_id, kill_anyway, ret; 226 char *ptr; 227 228 ret = 1; 229 type = DNS_DIS_KILL; 230 n_dupl = 0; 231 strcpy(vname, Dns_conns[conn_id].task_name); 232 strcat(vname, "/VERSION_NUMBER"); 233 dupl_id = 0; 234 kill_anyway = 0; 235 dupl_conn_id = Dns_conns[conn_id].already; 236 servp = (DNS_SERVICE *)Dns_conns[conn_id].service_head; 237 while( (servp = (DNS_SERVICE *) dll_get_next( 238 (DLL *) Dns_conns[conn_id].service_head, 239 (DLL *) servp)) ) 240 { 241 if(servp->state == -2) 242 { 243 if(!dupl_id) 244 { 245 dupl_id = servp->serv_id; 246 sprintf(dupl_server,"%s(%d)@%s:%d", 247 Dns_conns[dupl_conn_id].task_name, 248 Dns_conns[dupl_conn_id].pid, 249 Dns_conns[dupl_conn_id].node_name, 250 Dns_conns[dupl_conn_id].port); 251 } 252 if(!strcmp(servp->serv_name, vname)) 253 kill_anyway = 1; 254 n_dupl++; 255 } 256 } 257 /* allocate Header + space for <server_name>:<pid>@<node_name>:<port_number> + n duplicated + duplicated ids */ 258 dis_packet = (DNS_DIS_PACKET *)malloc(DNS_DIS_HEADER + MAX_NAME*2 + (n_dupl+1)*10); 259 sprintf(dis_packet->dup_info, "%s %d", dupl_server, n_dupl); 260 ptr = dis_packet->dup_info + strlen(dis_packet->dup_info); 261 if(kill_anyway) 262 { 263 type |= (0x01 << (int)16) & (int)0xFFFF0000; 264 dim_print_date_time(); 265 printf("Server already declared by conn %d - %s@%s:%d (PID %d), Killing server conn %d - %s@%s:%d (PID %d) \n", 266 dupl_conn_id, 267 Dns_conns[dupl_conn_id].task_name, 268 Dns_conns[dupl_conn_id].node_name, 269 Dns_conns[dupl_conn_id].port, 270 Dns_conns[dupl_conn_id].pid, 271 conn_id, 272 Dns_conns[conn_id].task_name, 273 Dns_conns[conn_id].node_name, 274 Dns_conns[conn_id].port, 275 Dns_conns[conn_id].pid); 276 fflush(stdout); 277 } 278 else 279 { 280 servp = (DNS_SERVICE *)Dns_conns[conn_id].service_head; 281 while( (servp = (DNS_SERVICE *) dll_get_next( 282 (DLL *) Dns_conns[conn_id].service_head, 283 (DLL *) servp)) ) 284 { 285 if(servp->state == -2) 286 { 287 dupl_id = servp->serv_id; 288 sprintf(ptr," %08X", dupl_id); 289 ptr += 9; 290 } 291 } 292 } 293 dis_packet->type = htovl(type); 294 size = DNS_DIS_HEADER + strlen(dis_packet->dup_info); 295 /* Unfortunatelly the size is wrong, this is for backward compatibility on the server side (it tested the size)*/ 296 dis_packet->size = htovl(DNS_DIS_HEADER); 297 /* 298 printf("Sendig packet %s\n", dis_packet->dup_info); 299 */ 300 if( !dna_write_nowait(conn_id, dis_packet, size) ) 301 { 302 dim_print_date_time(); 303 printf("Kill Server: Couldn't write, releasing %d\n",conn_id); 304 fflush(stdout); 305 ret = 0; 306 } 307 free(dis_packet); 308 return ret; 174 309 } 175 310 … … 180 315 int i, service_id; 181 316 int n_services; 182 char *ptr, *ptr1 , *ptrt;317 char *ptr, *ptr1; 183 318 int found; 184 319 void do_update_did(); … … 195 330 #endif 196 331 int update_did = 0; 332 /* 197 333 int name_too_long = 0; 334 */ 198 335 int rem_only = 0; 336 int all_services_registered = -1; 199 337 200 338 Dns_conns[conn_id].validity = (int)time(NULL); 201 339 if( !Dns_conns[conn_id].service_head ) 202 340 { 203 341 all_services_registered = 0; 204 342 if(vtohl(packet->n_services) > 0) 205 343 { … … 212 350 { 213 351 dim_print_date_time(); 214 printf( " 352 printf( "!!!! New Conn %3d : Server %s@%s (PID %d) registering %d services, to delete %d\n", 215 353 conn_id, packet->task_name, 216 354 packet->node_name, … … 246 384 { 247 385 dim_print_date_time(); 248 printf( " 386 printf( "!!!! New Conn %3d : Server %s@%s (PID %d) registered %d services\n", 249 387 conn_id, Dns_conns[conn_id].task_name, 250 388 Dns_conns[conn_id].node_name, … … 293 431 { 294 432 dim_print_date_time(); 295 printf(" 433 printf("Stop Server: Couldn't write, releasing %d\n",conn_id); 296 434 fflush(stdout); 297 435 } 298 436 dim_print_date_time(); 299 printf(" 437 printf("Connection from %s refused, stopping server %s\n", 300 438 Dns_conns[conn_id].node_name, 301 439 Dns_conns[conn_id].task_name); … … 332 470 dna_set_test_write(conn_id, dim_get_keepalive_timeout()); 333 471 dim_print_date_time(); 334 printf( " 472 printf( "Server %s out of error\n", 335 473 Dns_conns[conn_id].task_name ); 336 474 fflush(stdout); … … 339 477 } 340 478 n_services = vtohl(packet->n_services); 479 /* 341 480 if((int)strlen(Dns_conns[conn_id].task_name) == MAX_TASK_NAME-4-1) 342 481 name_too_long = 1; 482 */ 343 483 for( i = 0; i < n_services; i++ ) 344 484 { … … 347 487 { 348 488 dim_print_date_time(); 349 printf( " 489 printf( "Conn %3d : Server %s@%s (PID %d) registered %s\n", 350 490 conn_id, Dns_conns[conn_id].task_name, 351 491 Dns_conns[conn_id].node_name, … … 359 499 if(!strcmp(packet->services[i].service_name, "DUMMY_UPDATE_PACKET")) 360 500 { 501 all_services_registered = 1; 361 502 do_inform_clients(conn_id); 362 503 break; … … 378 519 { 379 520 dim_print_date_time(); 380 printf(" 521 printf("Couldn't write, releasing %d\n",servp->conn_id); 381 522 fflush(stdout); 382 523 } 383 524 dim_print_date_time(); 384 printf(" 525 printf("Service %s already declared, killing server %s\n", 385 526 servp->serv_name, Dns_conns[servp->conn_id].task_name); 386 527 fflush(stdout); … … 395 536 { 396 537 dim_print_date_time(); 397 printf(" 538 printf("Service %s already declared by conn %d - %s@%s:%d (PID %d), Redeclared by conn %d - %s@%s:%d (PID %d)(same server) - Closing both conns %d %d\n", 398 539 servp->serv_name, servp->conn_id, 399 540 Dns_conns[servp->conn_id].task_name, … … 418 559 else 419 560 { 420 Dns_conns[conn_id].already = 1; 421 561 Dns_conns[conn_id].already = servp->conn_id; 562 create_service_entry( conn_id, packet, i, -2); 563 /*DUPL 422 564 if( !dna_write_nowait(conn_id, &dis_packet, DNS_DIS_HEADER) ) 423 565 { … … 426 568 fflush(stdout); 427 569 } 570 */ 428 571 dim_print_date_time(); 429 printf(" Service %s already declared by conn %d - %s@%s:%d (PID %d), killing server conn %d - %s@%s:%d (PID %d) \n",572 printf("Service %s already declared by conn %d - %s@%s:%d (PID %d), Warning server conn %d - %s@%s:%d (PID %d) \n", 430 573 servp->serv_name, servp->conn_id, 431 574 Dns_conns[servp->conn_id].task_name, … … 439 582 Dns_conns[conn_id].pid); 440 583 fflush(stdout); 441 584 /*DUPL 442 585 release_conn(conn_id); 443 444 586 return(0); 587 */ 588 if((!all_services_registered) && (n_services < MAX_REGISTRATION_UNIT)) 589 all_services_registered = 1; 445 590 } 446 591 #ifdef VMS … … 481 626 dll_remove((DLL *) servp); 482 627 service_remove(&(servp->next)); 483 Curr_n_services--;484 628 free(servp); 485 629 Dns_conns[conn_id].n_services--; … … 489 633 { 490 634 dim_print_date_time(); 491 printf( "Conn %3d : Server %s@%s unregistered All services, releasing it.\n",635 printf("Conn %3d : Server %s@%s unregistered All services, releasing it.\n", 492 636 conn_id, Dns_conns[conn_id].task_name, 493 637 Dns_conns[conn_id].node_name ); … … 521 665 if(!(servp = service_exists(packet->services[i].service_name))) 522 666 { 523 servp = (DNS_SERVICE *)malloc(sizeof(DNS_SERVICE)); 524 if(name_too_long) 525 { 526 if(strstr(packet->services[i].service_name,"/CLIENT_LIST")) 527 { 528 strncpy(Dns_conns[conn_id].long_task_name, packet->services[i].service_name, 529 (size_t)MAX_NAME); 530 ptrt = strstr(Dns_conns[conn_id].long_task_name,"/CLIENT_LIST"); 531 *ptrt = '\0'; 532 } 533 } 534 strncpy( servp->serv_name, 535 packet->services[i].service_name, 536 (size_t)MAX_NAME ); 537 strncpy( servp->serv_def, 538 packet->services[i].service_def, 539 (size_t)MAX_NAME ); 540 servp->state = 1; 541 servp->conn_id = conn_id; 542 servp->server_format = vtohl(packet->format); 543 servp->serv_id = vtohl(packet->services[i].service_id); 544 dll_insert_queue( (DLL *) 545 Dns_conns[conn_id].service_head, 546 (DLL *) servp ); 547 Dns_conns[conn_id].n_services++; 548 service_insert( &(servp->next) ); 549 servp->node_head = (RED_NODE *) malloc(sizeof(NODE)); 550 dll_init( (DLL *) servp->node_head ); 551 Curr_n_services++; 667 create_service_entry( conn_id, packet, i, 1); 552 668 } 669 } 670 if((vtohl(packet->n_services) != 0) && Dns_conns[conn_id].already && all_services_registered) 671 { 672 /* 673 dim_print_date_time(); 674 printf("Services already declared Warning server\n"); 675 */ 676 warn_server(conn_id); 553 677 } 554 678 if(update_did) … … 559 683 { 560 684 dim_print_date_time(); 561 printf( "Conn %3d : Server %s@%s (PID %d) registered %d services\n",685 printf("Conn %3d : Server %s@%s (PID %d) registered %d services\n", 562 686 conn_id, Dns_conns[conn_id].task_name, 563 687 Dns_conns[conn_id].node_name, … … 620 744 { 621 745 dim_print_date_time(); 622 printf(" 746 printf("Server %s (%s@%s) has been set in error\n", 623 747 Dns_conns[conn_id].task_name, Net_conns[conn_id].task, Net_conns[conn_id].node); 624 748 fflush(stdout); … … 639 763 { 640 764 dim_print_date_time(); 641 printf(" 765 printf("Conn %3d : Server %s@%s Registration Requested\n", 642 766 conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node); 643 767 fflush(stdout); … … 647 771 { 648 772 dim_print_date_time(); 649 printf(" 773 printf("Server Validity: Couldn't write, releasing Conn %3d : Server %s@%s\n",conn_id, 650 774 Net_conns[conn_id].task, Net_conns[conn_id].node); 651 775 fflush(stdout); … … 676 800 { 677 801 dim_print_date_time(); 678 printf(" 802 printf("Conn %3d : Client %s@%s requested %s\n", 679 803 conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node, 680 804 serv_regp->service_name); … … 720 844 dic_packet.size = htovl(DNS_DIC_HEADER); 721 845 dim_print_date_time(); 722 printf(" 846 printf("Connection from %s refused, stopping client pid=%s\n", 723 847 Net_conns[conn_id].node, 724 848 Net_conns[conn_id].task); … … 727 851 { 728 852 dim_print_date_time(); 729 printf(" 853 printf("Stop Client: Couldn't write, releasing Conn %3d : Client %s@%s\n",conn_id, 730 854 Net_conns[conn_id].task, 731 855 Net_conns[conn_id].node); … … 773 897 } 774 898 service_remove(&(servp->next)); 775 Curr_n_services--;776 899 free(servp); 777 900 } … … 815 938 } 816 939 service_remove(&(servp->next)); 817 Curr_n_services--;818 940 free(servp); 819 941 } … … 850 972 servp->conn_id = 0; 851 973 service_insert(&(servp->next)); 852 Curr_n_services++;853 974 servp->node_head = (RED_NODE *)malloc(sizeof(NODE)); 854 975 dll_init( (DLL *) servp->node_head ); … … 930 1051 { 931 1052 dim_print_date_time(); 932 printf(" 1053 printf("Client Request: Couldn't write, releasing Conn %3d : Client %s@%s\n",conn_id, 933 1054 Net_conns[conn_id].task, 934 1055 Net_conns[conn_id].node); … … 962 1083 (DLL *) servp)) ) 963 1084 { 1085 /* DUPL 964 1086 if( servp->state != -1 ) 1087 */ 1088 if( servp->state > -1 ) 965 1089 { 966 1090 if( !dll_empty((DLL *) servp->node_head)) … … 1014 1138 { 1015 1139 dim_print_date_time(); 1016 printf(" 1140 printf("Inform Client: Couldn't write, releasing Conn %3d : Client %s@%s\n",nodep->conn_id, 1017 1141 Net_conns[nodep->conn_id].task, 1018 1142 Net_conns[nodep->conn_id].node); … … 1063 1187 { 1064 1188 dim_print_date_time(); 1065 printf(" 1189 printf("Releasing client on conn %d - %s@%s\n", 1066 1190 i, Net_conns[i].task, Net_conns[i].node); 1067 1191 fflush(stdout); … … 1088 1212 { 1089 1213 dim_print_date_time(); 1090 printf( "Conn %3d : Server %s@%s died\n",1214 printf("Conn %3d : Server %s@%s died\n", 1091 1215 conn_id, Dns_conns[conn_id].task_name, 1092 1216 Dns_conns[conn_id].node_name); … … 1098 1222 { 1099 1223 dim_print_date_time(); 1100 printf( "Conn %3d : Server %s@%s died\n",1224 printf("Conn %3d : Server %s@%s died\n", 1101 1225 conn_id, Dns_conns[conn_id].task_name, 1102 1226 Dns_conns[conn_id].node_name); … … 1119 1243 { 1120 1244 service_remove(&(servp->next)); 1121 Curr_n_services--;1122 1245 old_servp = servp; 1123 1246 servp = servp->server_prev; … … 1152 1275 { 1153 1276 dim_print_date_time(); 1154 printf(" 1277 printf("Conn %3d : Client %s@%s died\n", 1155 1278 conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node); 1156 1279 fflush(stdout); … … 1172 1295 { 1173 1296 service_remove(&(servp->next)); 1174 Curr_n_services--;1175 1297 free( servp ); 1176 1298 } … … 1187 1309 { 1188 1310 dim_print_date_time(); 1189 printf(" 1311 printf("Conn %3d : Undefined Type %s@%s died\n", 1190 1312 conn_id, Net_conns[conn_id].task, 1191 1313 Net_conns[conn_id].node); … … 1281 1403 (DLL *) servp)) ) 1282 1404 { 1405 if(servp->state == -2) 1406 continue; 1283 1407 strncpy(dns_service_info->name, servp->serv_name, (size_t)MAX_NAME); 1284 1408 dns_service_info->status = htovl(1); … … 1448 1572 get_node_name(node); 1449 1573 dim_print_date_time(); 1450 printf(" 1574 printf("DNS version %d starting up on %s\n",DIM_VERSION_NUMBER, node); 1451 1575 fflush(stdout); 1452 1576 … … 1506 1630 1507 1631 dim_print_date_time(); 1508 printf(" 1632 printf("Connection Statistics :\n"); 1509 1633 for(i = 0; i< Curr_N_Conns; i++) 1510 1634 { … … 1595 1719 type |= (soft_code << (int)16) & (int)0xFFFF0000; 1596 1720 dim_print_date_time(); 1597 printf(" 1721 printf("Killing server %s@%s with exit code %d\n", 1598 1722 Dns_conns[i].task_name, Dns_conns[i].node_name, soft_code); 1599 1723 } … … 1601 1725 { 1602 1726 dim_print_date_time(); 1603 printf(" 1727 printf("Killing server %s@%s\n", 1604 1728 Dns_conns[i].task_name, Dns_conns[i].node_name); 1605 1729 } … … 1609 1733 { 1610 1734 dim_print_date_time(); 1611 printf(" 1735 printf("Kill Server: Couldn't write, releasing %d\n",i); 1612 1736 fflush(stdout); 1613 1737 release_conn(i); … … 1636 1760 dll_insert_queue((DLL *) Service_hash_table[index], 1637 1761 (DLL *) servp); 1762 Curr_n_services++; 1638 1763 } 1639 1764 … … 1642 1767 { 1643 1768 if( servp->node_head ) 1769 { 1644 1770 free( servp->node_head ); 1645 dll_remove( (DLL *) servp ); 1771 } 1772 if(servp->next) 1773 { 1774 dll_remove( (DLL *) servp ); 1775 Curr_n_services--; 1776 } 1646 1777 } 1647 1778 … … 1834 1965 dim_print_date_time(); 1835 1966 conn_id = dis_get_conn_id(); 1836 printf(" 1967 printf("Got Browse Request <%s> from conn: %d %s@%s\n", buffer, conn_id, 1837 1968 Net_conns[conn_id].task,Net_conns[conn_id].node); 1838 1969 } … … 1842 1973 dim_print_date_time(); 1843 1974 conn_id = dis_get_conn_id(); 1844 printf(" 1975 printf("Browse Request <%s> found %d services\n", buffer, n); 1845 1976 } 1846 1977 if(!Rpc_info_size) -
trunk/FACT++/dim/src/examples/test_server.c
r15282 r18920 67 67 char aux[80]; 68 68 char name[84]/*, name1[132]*/; 69 char srvname[64]; 69 70 /* 70 71 int on = 0; … … 93 94 printf("result = %d\n", status); 94 95 */ 96 dim_print_date_time(); 97 printf("Dim Server Starting up...\n"); 98 fflush(stdout); 95 99 if(argc){} 96 100 new_dns = dim_get_env_var("EXTRA_DNS_NODE", extra_dns, sizeof(extra_dns)); … … 107 111 dis_add_client_exit_handler(client_exited); 108 112 113 strcpy(srvname, argv[1]); 114 if(!strcmp(srvname,"xx1")) 115 strcpy(srvname,"xx"); 109 116 for(i = 0; i< 10; i++) 110 117 { 111 sprintf(str[i],"%s/Service_%03d", argv[1],i);118 sprintf(str[i],"%s/Service_%03d",srvname,i); 112 119 dis_add_service( str[i], "C", str[i], (int)strlen(str[i])+1, 113 120 (void *)0, 0 ); … … 123 130 strcpy(t.str,"hello world"); 124 131 125 sprintf(aux,"%s/TEST_SWAP", argv[1]);132 sprintf(aux,"%s/TEST_SWAP",srvname); 126 133 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t), 127 134 (void *)0, 0 ); 135 if(!strcmp(argv[1],"xx1")) 136 { 137 sprintf(aux,"%s/TEST_SWAP1",srvname); 138 id = dis_add_service( aux, "l:3;d:1;s:1;c:1;s:1;f:1;c:20", &t, sizeof(t), 139 (void *)0, 0 ); 140 } 128 141 if(id){} 129 sprintf(aux,"%s/TEST_CMD", argv[1]);142 sprintf(aux,"%s/TEST_CMD",srvname); 130 143 dis_add_cmnd(aux,"l:3;d:1;s:1;c:1;s:1;f:1;c:20",cmnd_rout, 0); 131 144 -
trunk/FACT++/dim/src/examples/test_server.cxx
r18349 r18920 137 137 // delete dim; 138 138 139 dis_set_debug_on(); 139 140 DimServer::start("TEST"); 140 141 extraDns = DimUtil::getEnvVar((char *)"EXTRA_DNS_NODE"); 141 142 if(extraDns) 142 newDns = new DimServerDns(extraDns, 0, (char *)"new_TEST"); 143 newDns = new DimServerDns(extraDns, 0, (char *)"TEST"); 144 // newDns = new DimServerDns(extraDns, 0, (char *)"new_TEST"); 143 145 144 146 // int i, arr[15000]; … … 156 158 if(extraDns) 157 159 { 158 new_servint = new DimService(newDns, "new_TEST/INTVAL",ival); 160 // new_servint = new DimService(newDns, "new_TEST/INTVAL",ival); 161 new_servint = new DimService(newDns, "TEST/new_INTVAL",ival); 159 162 } 160 163 -
trunk/FACT++/dim/src/tcpip.c
r18097 r18920 16 16 #ifdef WIN32 17 17 #define FD_SETSIZE 16384 18 #define poll(pfd,nfds,timeout) WSAPoll(pfd,nfds,timeout) 18 #endif 19 20 #include <stdio.h> 21 #include <time.h> 22 #define DIMLIB 23 #include <dim.h> 24 25 #ifdef WIN32 26 //#define poll(pfd,nfds,timeout) WSAPoll(pfd,nfds,timeout) 19 27 #define ioctl ioctlsocket 20 28 … … 26 34 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 27 35 #define EWOULDBLOCK WSAEWOULDBLOCK 36 #define EINPROGRESS WSAEINPROGRESS 28 37 #define ECONNREFUSED WSAECONNREFUSED 38 #define ETIMEDOUT WSAETIMEDOUT 29 39 #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 30 40 #define NO_DATA WSANO_DATA … … 80 90 #define MY_FD_ISSET(fd, set) FD_ISSET(fd, set) 81 91 #endif 82 83 #include <stdio.h>84 #include <time.h>85 #define DIMLIB86 #include <dim.h>87 92 88 93 #define ushort unsigned short … … 813 818 fd_set rfds; 814 819 int conn_id, ret, selret, count; 820 #ifndef __linux__ 815 821 struct timeval timeout; 822 #endif 816 823 817 824 if(num){} 818 825 do 819 826 { 820 timeout.tv_sec = 0; /* Don't wait, just poll */821 timeout.tv_usec = 0;822 827 list_to_fds( &rfds ); 823 828 #ifdef __linux__ 824 829 selret = poll(Pollfds, Pollfd_size, 0); 825 830 #else 831 timeout.tv_sec = 0; /* Don't wait, just poll */ 832 timeout.tv_usec = 0; 826 833 selret = select(FD_SETSIZE, &rfds, NULL, NULL, &timeout); 827 834 #endif … … 890 897 #endif 891 898 if(ret <= 0) 892 893 printf("poll returned %d, errno %d\n", ret, errno);894 899 { 900 printf("poll/select returned %d, errno %d\n", ret, errno); 901 } 895 902 if(ret > 0) 896 903 { … … 1023 1030 int host_addr; 1024 1031 #endif 1025 int path, val, ret_code, ret ;1032 int path, val, ret_code, ret, retcon, selret; 1026 1033 int a,b,c,d; 1027 1034 /* Fix for gcc 4.6 "dereferencing type-punned pointer will break strict-aliasing rules"?!*/ … … 1029 1036 unsigned char *ipaddr = ipaddr_buff; 1030 1037 int host_number = 0; 1038 int tcpip_would_block(); 1039 #ifdef __linux__ 1040 struct pollfd pollitem; 1041 #else 1042 struct timeval timeout; 1043 fd_set rfds, wfds, efds; 1044 #endif 1045 int so_error = ETIMEDOUT; 1046 int so_error_len = sizeof(so_error); 1031 1047 1032 1048 dim_tcpip_init(0); … … 1161 1177 #endif 1162 1178 sockname.sin_port = htons((ushort) port); /* port number to send to */ 1163 while((ret = connect(path, (struct sockaddr*)&sockname, sizeof(sockname))) == -1 ) 1164 { 1165 if(errno != EINTR) 1179 /* 1180 while ((ret = connect(path, (struct sockaddr*)&sockname, sizeof(sockname))) == -1) 1181 { 1182 if (errno != EINTR) 1166 1183 { 1167 1184 closesock(path); … … 1169 1186 } 1170 1187 } 1171 strcpy( Net_conns[conn_id].node, node ); 1188 */ 1189 set_non_blocking(path); 1190 retcon = connect(path, (struct sockaddr*)&sockname, sizeof(sockname)); 1191 #ifndef WIN32 1192 ret = errno; 1193 #else 1194 ret = WSAGetLastError(); 1195 #endif 1196 set_blocking(path); 1197 if (retcon == -1) 1198 { 1199 if (tcpip_would_block(ret)) 1200 { 1201 #ifdef __linux__ 1202 pollitem.fd = path; 1203 pollitem.events = POLLIN | POLLOUT | POLLERR; 1204 pollitem.revents = 0; 1205 selret = poll(&pollitem, 1, CONNECT_TMOUT * 1000); 1206 #else 1207 timeout.tv_sec = CONNECT_TMOUT; 1208 timeout.tv_usec = 0; 1209 FD_ZERO(&wfds); 1210 FD_SET(path, &wfds); 1211 FD_ZERO(&rfds); 1212 FD_SET(path, &rfds); 1213 FD_ZERO(&efds); 1214 FD_SET(path, &efds); 1215 selret = select(FD_SETSIZE, &rfds, &wfds, &efds, &timeout); 1216 #endif 1217 if (selret > 0) 1218 { 1219 getsockopt(path, SOL_SOCKET, SO_ERROR, (void *)&so_error, &so_error_len); 1220 } 1221 } 1222 if (so_error != 0) 1223 { 1224 #ifndef WIN32 1225 errno = so_error; 1226 #else 1227 WSASetLastError(so_error); 1228 #endif 1229 closesock(path); 1230 return(0); 1231 } 1232 } 1233 strcpy(Net_conns[conn_id].node, node); 1172 1234 strcpy( Net_conns[conn_id].task, task ); 1173 1235 Net_conns[conn_id].channel = path; … … 1547 1609 if(code == EWOULDBLOCK) 1548 1610 return(1); 1549 return(0); 1611 else if (code == EINPROGRESS) 1612 return(1); 1613 return(0); 1550 1614 } 1551 1615 -
trunk/FACT++/dim/src/utilities.c
r15282 r18920 19 19 #define DIMLIB 20 20 #include <dim.h> 21 22 /*added by dietrich beck, GSI*/ 23 #ifdef PHARLAP 24 #define getenv(x) getenv2(x) 25 char* getenv2(envname) 26 char* envname; 27 { 28 char* buff; 29 int ml; 30 31 buff = (char*)malloc(200); 32 ml = GetEnvironmentVariable(envname, buff, 200); 33 34 if (ml == 0){ 35 buff = NULL; 36 } 37 return buff; 38 } 39 #endif 21 40 22 41 int get_proc_name(char *proc_name) -
trunk/FACT++/dim/src/webDid/webDid.c
r18058 r18920 6 6 #include <dis.h> 7 7 8 extern int WebDID_Debug; 8 int WebDID_Debug = 1; 9 int IsWebDID = 1; 9 10 10 11 typedef struct item{ 11 12 struct item *next; 13 int id; 14 /* must be here */ 15 char *service_format_ptr; 12 16 DNS_SERVER_INFO server; 13 17 DNS_SERVICE_INFO *service_ptr; … … 16 20 int busy; 17 21 int isSMI; 22 // char *servicelistp; 23 char **service_format_ptrp; 18 24 }SERVER; 19 25 … … 27 33 }NODE; 28 34 NODE *Node_head = (NODE *)0; 35 36 typedef struct req_ent { 37 struct req_ent *next; 38 struct req_ent *prev; 39 int conn_id; 40 // int service_id; 41 // int req_id; 42 // int type; 43 // struct serv *service_ptr; 44 int timeout; 45 // int format; 46 // int first_time; 47 // int delay_delete; 48 // int to_delete; 49 TIMR_ENT *timr_ent; 50 void *nolink; 51 int nolinksize; 52 struct reqp_ent *reqpp; 53 struct sitem *servicep; 54 } REQUEST; 55 56 typedef struct reqp_ent { 57 struct reqp_ent *next; 58 struct reqp_ent *prev; 59 REQUEST *reqp; 60 } REQUEST_PTR; 29 61 30 62 typedef struct sitem{ … … 43 75 time_t last_updated; 44 76 int n_browsers; 45 }CURR_SERVICE; 46 CURR_SERVICE *Curr_service_head = (CURR_SERVICE *)0; 77 int formatted; 78 // void *nolink; 79 // int nolinksize; 80 REQUEST *request_head; 81 int is_nolink; 82 }SERVICE; 83 SERVICE *Curr_service_head = (SERVICE *)0; 47 84 48 85 typedef struct objstate{ … … 62 99 struct bitem *next; 63 100 int id; 101 /* must be here */ 102 char *service_format_ptr; 64 103 int subscribe; 65 104 time_t last_subscribed; … … 71 110 int n_servers; 72 111 int n_nodes; 73 CURR_SERVICE *servicep;112 SERVICE *servicep; 74 113 char *JSONBuffer; 75 114 int JSONBufferSize; … … 78 117 char pattern[256]; 79 118 char curr_command[MAX_NAME]; 80 char *service_format_ptr;119 // char *service_format_ptr; 81 120 int isSMI; 82 121 int n_domains; … … 85 124 int curr_smidomain_nobjs; 86 125 OBJSTATE *smidomainp; 126 int formatted; 127 REQUEST_PTR *requestp_head; 87 128 }BROWSER; 88 129 BROWSER *Browser_head = (BROWSER *)0; … … 106 147 int N_services = 0; 107 148 static char no_link = -1; 108 static char no_link_str[5] = "DEAD"; 149 //static char no_link_str[5] = "DEAD"; 150 static char no_link_str[26] = "__DIM_SERVICE_NOT_THERE__"; 109 151 int no_link_int = -1; 110 152 FILE *fptr; … … 147 189 } 148 190 sprintf(icon_title,"DID %s",dns_node); 149 dim_print_date_time(); 150 printf("webDid Starting up on %s\n\t serving %s\n", local_node, Title); 191 if (IsWebDID) 192 { 193 dim_print_date_time(); 194 printf("webDid Starting up on %s\n\t serving %s\n", local_node, Title); 195 } 196 else 197 { 198 dim_print_date_time(); 199 printf("webDim Starting up on %s\n\t serving %s\n", local_node, Title); 200 } 151 201 Timer_q = dtq_create(); 152 dic_info_service( "DIS_DNS/SERVER_INFO",MONITORED,0,0,0,update_servers,0,202 dic_info_service((const char *)"DIS_DNS/SERVER_INFO",MONITORED,0,0,0,(void (*)(int *,void *,int *))update_servers,0, 153 203 &no_link,1); 154 204 return 1; … … 187 237 } 188 238 189 int find_server_service_pattern(SERVER *servp, char *pattern )239 int find_server_service_pattern(SERVER *servp, char *pattern, char **bufptr) 190 240 { 191 241 DNS_SERVICE_INFO *servicep; 192 242 int n_services, i; 193 243 int n_found = 0; 244 char *ptr, str[256], *sptr, *sformat, *stype; 245 int type, index; 246 char *addJSONChildStart(); 247 char *addJSONChildEnd(); 248 int doall = 0, doit = 0; 194 249 195 250 servicep = servp->service_ptr; 196 251 n_services = servp->server.n_services; 197 for(i = 0; i < n_services; i++) 198 { 199 if(strstr(servicep->name, pattern)) 252 if (!strcmp(pattern, "*")) 253 { 254 doall = 1; 255 } 256 for (i = 0; i < n_services; i++) 257 { 258 sptr = (char *)servp->service_format_ptrp[i]; 259 if (!sptr) 260 break; 261 if (!doall) 262 { 263 doit = 0; 264 // if (strstr(servicep->name, pattern)) 265 // if (sptr) 266 // { 267 // if (strstr(servicep->name, pattern)) 268 if (strstr(sptr, pattern)) 269 { 270 doit = 1; 271 } 272 // } 273 } 274 if (doall || doit) 200 275 { 201 276 n_found++; 277 if(bufptr) 278 { 279 /* 280 type = servicep->type; 281 if (type < 0xff) 282 printf("problem %s %d", servicep->name, servicep->type); 283 index = type; 284 type &= 0x000000FF; 285 index = (index >> 16) & 0xFFFF; 286 index--; 287 sptr = (char *)servp->service_format_ptrp[index]; 288 ptr = *bufptr; 289 sprintf(str, "name: \"%s\", format: \"%s\", type: %d", servicep->name, 290 (char *)sptr + strlen((const char *)sptr)+1, type); 291 */ 292 ptr = *bufptr; 293 sformat = (char *)sptr + strlen((const char *)sptr) + 1; 294 stype = (char *)sformat + strlen((const char *)sformat) + 1; 295 if (*stype = '\n') 296 type = 0; 297 else if (*stype == 'C') 298 type = 1; 299 else if (*stype == 'R') 300 type = 2; 301 sprintf(str, "name: \"%s\", format: \"%s\", type: %d", sptr, sformat, type); 302 ptr = addJSONChildStart(ptr, str, 0); 303 ptr = addJSONChildEnd(ptr, 1); 304 *bufptr = ptr; 305 } 202 306 } 203 307 servicep++; … … 206 310 } 207 311 208 int find_service_pattern(NODE *nodep, SERVER *servpp, char *pattern, int *n_servers )312 int find_service_pattern(NODE *nodep, SERVER *servpp, char *pattern, int *n_servers, char **ptr) 209 313 { 210 314 SERVER *servp; … … 217 321 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) ) 218 322 { 219 if((ret = find_server_service_pattern(servp, pattern )))323 if((ret = find_server_service_pattern(servp, pattern, ptr))) 220 324 { 221 325 n_found += ret; … … 226 330 else 227 331 { 228 if((ret = find_server_service_pattern(servpp, pattern )))332 if((ret = find_server_service_pattern(servpp, pattern, ptr))) 229 333 { 230 334 n_found += ret; … … 236 340 } 237 341 238 CURR_SERVICE *find_curr_service(char *service)239 { 240 CURR_SERVICE *servicep;342 SERVICE *find_curr_service(char *service) 343 { 344 SERVICE *servicep; 241 345 242 346 servicep = Curr_service_head ; 243 while( (servicep = ( CURR_SERVICE *)sll_get_next((SLL *)servicep)) )347 while( (servicep = (SERVICE *)sll_get_next((SLL *)servicep)) ) 244 348 { 245 349 if(!strcmp(servicep->name,service)) … … 248 352 } 249 353 } 250 return (( CURR_SERVICE *)0);354 return ((SERVICE *)0); 251 355 } 252 356 … … 285 389 { 286 390 BROWSER *browserp; 287 int prepareJSONTree( );391 int prepareJSONTree(char *, BROWSER *); 288 392 289 393 browserp = Browser_head; … … 291 395 { 292 396 if(browserp->pattern[0] != '\0') 293 prepareJSONTree( browserp);397 prepareJSONTree("",browserp); 294 398 } 295 399 } … … 311 415 int prepareJSONTree(); 312 416 int prepareJSONHeader(); 417 void got_update_services(); 313 418 314 419 if(tag){} … … 379 484 strcpy(servp->name,sname); 380 485 servp->next = 0; 486 servp->id = 0; 381 487 servp->busy = 0; 382 488 servp->server.n_services = 0; 383 489 servp->service_ptr = 0; 490 servp->service_format_ptr = 0; 491 servp->service_format_ptrp = 0; 384 492 servp->isSMI = 0; 385 493 if(strstr(sname,"_SMI")) … … 407 515 servp->service_ptr = 0; 408 516 } 409 if(n_services != -1) 517 if (servp->service_format_ptr) 518 { 519 free(servp->service_format_ptr); 520 servp->service_format_ptr = 0; 521 } 522 if (servp->service_format_ptrp) 523 { 524 free(servp->service_format_ptrp); 525 servp->service_format_ptrp = 0; 526 } 527 if (n_services != -1) 410 528 { 411 529 service_size = n_services*(int)sizeof(DNS_SERVICE_INFO); … … 413 531 memcpy(servp->service_ptr, buffer->services, (size_t)service_size); 414 532 N_services += n_services; 533 sprintf(str, "%s/SERVICE_LIST", sname); 534 // printf("subscribe update_servers %s %d\n", sname, n_services); 535 dic_info_service(str, ONCE_ONLY, 20, 0, 0, 536 got_update_services, (dim_long)servp, "None", 5); 415 537 } 416 538 servp->busy = 1; … … 419 541 { 420 542 if(servp) 421 543 { 422 544 N_servers--; 423 545 if(servp->server.n_services != -1) 424 425 426 546 { 547 N_services -= servp->server.n_services; 548 } 427 549 servp->server.n_services = 0; 428 550 servp->busy = -1; 429 551 servp->isSMI = 0; 430 552 } 431 553 } 432 554 if(JSONHeader[0]) 433 555 prepareJSONHeader(); 556 // printf("update_servers %d %d %d\n", N_nodes, N_servers, N_services); 434 557 } 435 558 … … 437 560 { 438 561 BROWSER *browserp; 562 SERVER *servp; 563 DNS_SERVICE_INFO *servicep; 564 int i, j, n_services, index = 0, type; 565 char *ptr, *ptre, *ptr1, tmp[MAX_NAME], *sptr; 439 566 440 567 if(size){} 441 568 browserp = (BROWSER *)*tag; 442 if(browserp->service_format_ptr) 443 free(browserp->service_format_ptr); 444 browserp->service_format_ptr = (char *)malloc(strlen(buffer)+1); 445 strcpy(browserp->service_format_ptr, buffer); 569 if (browserp) 570 { 571 if (browserp->service_format_ptr) 572 free(browserp->service_format_ptr); 573 browserp->service_format_ptr = (char *)malloc(strlen(buffer) + 1); 574 strcpy(browserp->service_format_ptr, buffer); 575 } 576 if (browserp->id == 0) 577 { 578 servp = (SERVER *)browserp; 579 n_services = servp->server.n_services; 580 if (servp->service_format_ptrp) 581 free(servp->service_format_ptrp); 582 servp->service_format_ptrp = (char **)malloc(n_services*sizeof(char *)); 583 memset(servp->service_format_ptrp, 0, (size_t)n_services*sizeof(char *)); 584 ptr = servp->service_format_ptr; 585 servicep = servp->service_ptr; 586 for (i = 0; i < n_services; i++) 587 { 588 servicep->type &= 0x000000FF; 589 servicep++; 590 servp->service_format_ptrp[index++] = ptr; 591 ptre = strchr(ptr, '\n'); 592 ptr1 = strchr(ptr, '|'); 593 if(ptr1) 594 { 595 *ptr1 = '\0'; 596 ptr1++; 597 ptr1 = strchr(ptr1, '|'); 598 if (ptr1) 599 *ptr1 = '\0'; 600 } 601 ptr = ptre; 602 if (!ptr) 603 { 604 break; 605 if (!(*ptr)) 606 break; 607 } 608 ptr++; 609 if (!(*ptr)) 610 break; 611 } 612 /* 613 for (i = 0; i < n_services; i++) 614 { 615 if (!servp->service_format_ptrp[i]) 616 break; 617 servicep = servp->service_ptr; 618 for (j = 0; j < n_services; j++) 619 { 620 if (servicep->type < 0xFF) 621 { 622 if ((strstr(servicep->name, "/RpcIn")) || (strstr(servicep->name, "/RpcOut"))) 623 { 624 strcpy(tmp, servicep->name); 625 if ((ptr = strstr(tmp, "/RpcIn"))) 626 *ptr = '\0'; 627 if ((ptr = strstr(tmp, "/RpcOut"))) 628 *ptr = '\0'; 629 if (!strcmp(tmp, servp->service_format_ptrp[i])) 630 { 631 servicep->type |= ((i + 1) << 16); 632 break; 633 } 634 } 635 if (!strcmp(servicep->name, servp->service_format_ptrp[i])) 636 { 637 servicep->type |= ((i+1) << 16); 638 break; 639 } 640 } 641 // printf("%s %08x\n",servicep->name, servicep->type); 642 // if (servicep->type == 0) 643 // break; 644 servicep++; 645 } 646 } 647 */ 648 /* 649 servicep = servp->service_ptr; 650 for (i = 0; i < n_services; i++) 651 { 652 for (j = 0; j < n_services; j++) 653 { 654 if (!servp->service_format_ptrp[j]) 655 break; 656 if ((strstr(servicep->name, "/RpcIn")) || (strstr(servicep->name, "/RpcOut"))) 657 { 658 strcpy(tmp, servicep->name); 659 if ((ptr = strstr(tmp, "/RpcIn"))) 660 *ptr = '\0'; 661 if ((ptr = strstr(tmp, "/RpcOut"))) 662 *ptr = '\0'; 663 if (!strcmp(tmp, servp->service_format_ptrp[j])) 664 { 665 servicep->type |= ((j + 1) << 16); 666 break; 667 } 668 } 669 if (!strcmp(servicep->name, servp->service_format_ptrp[j])) 670 { 671 servicep->type |= ((j + 1) << 16); 672 break; 673 } 674 } 675 // if (servicep->type == 0) 676 // break; 677 type = servicep->type; 678 index = type; 679 type &= 0x000000FF; 680 index = (index >> 16) & 0xFFFF; 681 index--; 682 sptr = (char *)servp->service_format_ptrp[index]; 683 printf("%s %08x %s\n", servicep->name, servicep->type, (char *)sptr + strlen((const char *)sptr) + 1); 684 servicep++; 685 } 686 */ 687 } 688 // printf("got_update_services %s\n", buffer); 446 689 } 447 690 … … 454 697 BROWSER *browserp; 455 698 char *prepareJSONServiceList(); 456 BROWSER *create_browser( );699 BROWSER *create_browser(int); 457 700 458 701 if(!(browserp = find_browser(browser))) … … 610 853 } 611 854 612 int delete_curr_service( CURR_SERVICE *servicep)855 int delete_curr_service(SERVICE *servicep) 613 856 { 614 857 … … 620 863 if(servicep->buffer_str_size) 621 864 free(servicep->buffer_str); 865 // if (servicep->nolink) 866 // free(servicep->nolink); 622 867 sll_remove((SLL *)Curr_service_head, (SLL *)servicep); 623 868 free(servicep); … … 625 870 } 626 871 872 int close_browser(int browser) 873 { 874 BROWSER *browserp; 875 876 if ((browserp = find_browser(browser))) 877 delete_browser(browserp); 878 return 1; 879 } 627 880 int delete_browser(BROWSER *browserp) 628 881 { 629 CURR_SERVICE *servicep; 630 882 SERVICE *servicep; 883 int i; 884 885 release_all_requests(browserp); 886 if (browserp->requestp_head) 887 free(browserp->requestp_head); 888 /* 631 889 if((servicep = browserp->servicep)) 632 890 { … … 635 893 delete_curr_service(servicep); 636 894 } 895 */ 637 896 if(browserp->service_format_ptr) 638 897 free(browserp->service_format_ptr); … … 679 938 browserp->n_servers = 0; 680 939 browserp->n_services = 0; 681 browserp->servicep = 0;940 // browserp->servicep = 0; 682 941 browserp->JSONBuffer = 0; 683 942 browserp->JSONBufferSize = 0; … … 689 948 browserp->curr_smidomain[0] = '\0'; 690 949 browserp->smidomainp = 0; 691 sll_insert_queue((SLL *)Browser_head,(SLL *)browserp); 692 dtq_start_timer(10, check_browser, browserp); 950 browserp->requestp_head = (REQUEST_PTR *)malloc(sizeof(REQUEST_PTR)); 951 dll_init((DLL *)(browserp->requestp_head)); 952 sll_insert_queue((SLL *)Browser_head, (SLL *)browserp); 953 if(IsWebDID) 954 dtq_start_timer(10, check_browser, browserp); 693 955 return browserp; 694 956 } … … 716 978 } 717 979 718 int update_service_data(char *service, int conn_id, int subscribe, int req, int browser, int force) 719 { 720 CURR_SERVICE *servicep; 980 REQUEST *create_request(int conn_id, SERVICE *servicep, int timeout, void *nolink, int nolinksize) 981 { 982 REQUEST *newp; 983 984 newp = (REQUEST *)malloc(sizeof(REQUEST)); 985 newp->servicep = servicep; 986 newp->timeout = timeout; 987 newp->conn_id = conn_id; 988 // newp->first_time = 1; 989 // newp->delay_delete = 0; 990 // newp->to_delete = 0; 991 newp->timr_ent = 0; 992 newp->reqpp = 0; 993 newp->nolink = 0; 994 newp->nolinksize = 0; 995 if (nolinksize) 996 { 997 newp->nolink = malloc(nolinksize); 998 newp->nolinksize = nolinksize; 999 memcpy(newp->nolink, nolink, nolinksize); 1000 } 1001 dll_insert_queue((DLL *)servicep->request_head, (DLL *)newp); 1002 return newp; 1003 } 1004 1005 REQUEST_PTR *create_requestp(REQUEST *reqp, BROWSER *browserp) 1006 { 1007 REQUEST_PTR *reqpp; 1008 1009 reqpp = (REQUEST_PTR *)malloc(sizeof(REQUEST_PTR)); 1010 reqpp->reqp = reqp; 1011 reqp->reqpp = reqpp; 1012 dll_insert_queue((DLL *)browserp->requestp_head, (DLL *)reqpp); 1013 return reqpp; 1014 } 1015 1016 int release_request(REQUEST_PTR *reqpp) 1017 { 1018 REQUEST *reqp; 1019 SERVICE *servicep; 1020 1021 reqp = reqpp->reqp; 1022 if (reqp) 1023 { 1024 servicep = reqp->servicep; 1025 dll_remove((DLL *)reqp); 1026 } 1027 if (reqpp) 1028 dll_remove((DLL *)reqpp); 1029 if (reqp->nolink) 1030 free(reqp->nolink); 1031 // if (reqp->timr_ent) 1032 // dtq_rem_entry(Dis_timer_q, reqp->timr_ent); 1033 // id_free(reqp->req_id, SRC_DIS); 1034 servicep->n_browsers--; 1035 if (dll_empty((DLL *)servicep->request_head)) 1036 { 1037 // if (!servicep->n_browsers) 1038 // { 1039 free(servicep->request_head); 1040 delete_curr_service(servicep); 1041 // } 1042 } 1043 if (reqp) 1044 free(reqp); 1045 if (reqpp) 1046 free(reqpp); 1047 return 1; 1048 } 1049 1050 int release_all_requests(BROWSER *browserp) 1051 { 1052 REQUEST_PTR *reqpp, *auxp; 1053 int release_request(); 1054 1055 if (browserp) 1056 { 1057 reqpp = browserp->requestp_head; 1058 while ((reqpp = (REQUEST_PTR *)dll_get_next((DLL *)browserp->requestp_head, 1059 (DLL *)reqpp))) 1060 { 1061 auxp = reqpp->prev; 1062 release_request(reqpp); 1063 reqpp = auxp; 1064 } 1065 } 1066 return 1; 1067 } 1068 1069 REQUEST_PTR *find_request(SERVICE* servicep, int conn_id) 1070 { 1071 REQUEST_PTR *reqpp; 1072 REQUEST *reqp; 1073 1074 if (servicep) 1075 { 1076 reqp = servicep->request_head; 1077 while ((reqp = (REQUEST *)dll_get_next((DLL *)servicep->request_head, 1078 (DLL *)reqp))) 1079 { 1080 if (reqp->conn_id == conn_id) 1081 return reqp->reqpp; 1082 } 1083 } 1084 return (REQUEST_PTR *)0; 1085 } 1086 1087 int update_service_data(char *service, int conn_id, int subscribe, int req, int browser, int force, 1088 int formatted, void *nolink, int nolinksize) 1089 { 1090 SERVICE *servicep; 721 1091 time_t tsecs; 722 1092 void recv_service_info(); 723 1093 extern void sendData(); 724 1094 BROWSER *browserp; 1095 int i; 1096 REQUEST *reqp; 1097 REQUEST_PTR *reqpp; 725 1098 726 1099 if(req){} 727 1100 if(!Curr_service_head) 728 1101 { 729 Curr_service_head = ( CURR_SERVICE *)malloc(sizeof(CURR_SERVICE));1102 Curr_service_head = (SERVICE *)malloc(sizeof(SERVICE)); 730 1103 sll_init((SLL *)Curr_service_head); 731 1104 } … … 737 1110 return 1; 738 1111 } 739 if((servicep = browserp->servicep)) 740 { 741 servicep->n_browsers--; 742 if(!servicep->n_browsers) 743 delete_curr_service(servicep); 1112 browserp->formatted = formatted; 1113 if(IsWebDID) 1114 { 1115 /* 1116 if ((servicep = browserp->servicep)) 1117 { 1118 servicep->n_browsers--; 1119 if (!servicep->n_browsers) 1120 delete_curr_service(servicep); 1121 } 1122 */ 1123 release_all_requests(browserp); 1124 } 1125 if (subscribe == -2) 1126 { 1127 if ((servicep = find_curr_service(service))) 1128 { 1129 reqpp = find_request(servicep, conn_id); 1130 if (reqpp) 1131 release_request(reqpp); 1132 } 1133 return 1; 744 1134 } 745 1135 if(!(servicep = find_curr_service(service))) 746 1136 { 747 servicep = ( CURR_SERVICE *)malloc(sizeof(CURR_SERVICE));1137 servicep = (SERVICE *)malloc(sizeof(SERVICE)); 748 1138 strcpy(servicep->name,service); 749 1139 servicep->conn_id = conn_id; … … 760 1150 servicep->last_subscribed = tsecs; 761 1151 servicep->n_browsers = 0; 1152 servicep->formatted = formatted; 1153 servicep->request_head = (REQUEST *)malloc(sizeof(REQUEST)); 1154 servicep->is_nolink = 0; 1155 dll_init((DLL *)(servicep->request_head)); 1156 reqp = create_request(conn_id, servicep, subscribe, nolink, nolinksize); 1157 reqpp = create_requestp(reqp, browserp); 762 1158 sll_insert_queue((SLL *)Curr_service_head,(SLL *)servicep); 763 servicep->sid = (int)dic_info_service_stamped( service, MONITORED, subscribe, 0, 0,764 recv_service_info, servicep, &no_link_int, 4);1159 servicep->sid = (int)dic_info_service_stamped(service, MONITORED, 0, 0, 0, 1160 recv_service_info, servicep, no_link_str, strlen(no_link_str)); 765 1161 } 766 1162 else … … 768 1164 if(servicep->size) 769 1165 { 770 if((servicep->timestamp > browserp->last_updated) || (force)) 771 { 772 sendData(conn_id, servicep->buffer_str, 4); 1166 reqp = create_request(conn_id, servicep, subscribe, nolink, nolinksize); 1167 reqpp = create_requestp(reqp, browserp); 1168 if ((servicep->timestamp > browserp->last_updated) || (force)) 1169 { 1170 if(browserp->formatted) 1171 sendData(conn_id, servicep->buffer_str, 4); 1172 else 1173 { 1174 if (servicep->is_nolink) 1175 sendData(conn_id, reqp->nolink, 11); 1176 else 1177 sendData(conn_id, servicep->buffer, 11); 1178 // sendData(conn_id, servicep->buffer, 11); 1179 } 773 1180 } 774 1181 else 775 1182 { 776 1183 sendData(conn_id, "", 4); 777 1184 } 778 1185 browserp->last_updated = servicep->timestamp; … … 781 1188 if(force) 782 1189 { 783 browserp->servicep = servicep;1190 // browserp->servicep = servicep; 784 1191 servicep->n_browsers++; 785 1192 } … … 789 1196 int check_browser_changes(char *service, int conn_id, int subscribe, int req, int browser, int force) 790 1197 { 791 CURR_SERVICE *servicep;1198 SERVICE *servicep; 792 1199 time_t tsecs; 793 1200 void recv_service_info(); … … 803 1210 if(!Curr_service_head) 804 1211 { 805 Curr_service_head = ( CURR_SERVICE *)malloc(sizeof(CURR_SERVICE));1212 Curr_service_head = (SERVICE *)malloc(sizeof(SERVICE)); 806 1213 sll_init((SLL *)Curr_service_head); 807 1214 } … … 873 1280 void print_service_formatted(); 874 1281 extern void sendData(); 875 CURR_SERVICE *servicep;1282 SERVICE *servicep; 876 1283 time_t tsecs; 1284 REQUEST *reqp, *auxp; 877 1285 878 1286 servicep = *tag; … … 897 1305 strcpy(Curr_service_name, servicep->name); 898 1306 get_curr_service_format(); 899 if((*size == 4 ) && (*buffer == -1)) 900 { 1307 // if ((*size == servicep->nolinksize) && (!memcmp(buffer, servicep->nolink, servicep->nolinksize))) 1308 // if ((*size == 4) && (*buffer == -1)) 1309 servicep->is_nolink = 0; 1310 if ((*size == strlen(no_link_str)) && (!memcmp(buffer, no_link_str, strlen(no_link_str)))) 1311 { 1312 servicep->is_nolink = 1; 901 1313 sprintf(Service_content_str, 902 1314 "Service %s Not Available", Curr_service_name); … … 906 1318 print_service_formatted(servicep, buffer, *size); 907 1319 } 908 if(servicep->last_updated == 0) 909 { 910 sendData(conn_id, Service_content_str, 4); 1320 if(WebDID_Debug) 1321 printf("service updated - %s, conn_id %d\n", Curr_service_name, conn_id); 1322 1323 if (IsWebDID) 1324 { 1325 if (servicep->last_updated == 0) 1326 { 1327 if (servicep->formatted) 1328 sendData(conn_id, Service_content_str, 4); 1329 else 1330 sendData(conn_id, servicep->buffer, 11); 1331 tsecs = time((time_t *)0); 1332 servicep->last_updated = tsecs; 1333 } 1334 } 1335 else 1336 { 911 1337 tsecs = time((time_t *)0); 912 1338 servicep->last_updated = tsecs; 913 } 914 } 915 916 void print_service_formatted(CURR_SERVICE *servicep, void *buff, int size) 1339 reqp = servicep->request_head; 1340 while ((reqp = (REQUEST *)dll_get_next((DLL *)servicep->request_head, 1341 (DLL *)reqp))) 1342 { 1343 /* 1344 if (servicep->buffer_size < reqp->nolinksize) 1345 { 1346 if (servicep->buffer_size) 1347 free(servicep->buffer); 1348 servicep->buffer = malloc((size_t)reqp->nolinksize); 1349 servicep->buffer_size = reqp->nolinksize; 1350 } 1351 memcpy(servicep->buffer, (char *)reqp->nolink, (size_t)reqp->nolinksize); 1352 servicep->size = *size; 1353 */ 1354 if (servicep->is_nolink) 1355 sendData(reqp->conn_id, reqp->nolink, 11); 1356 else 1357 sendData(reqp->conn_id, servicep->buffer, 11); 1358 if (reqp->timeout == -1) 1359 { 1360 // May delete servicep... 1361 auxp = reqp->prev; 1362 release_request(reqp->reqpp); 1363 reqp = auxp; 1364 } 1365 } 1366 } 1367 } 1368 1369 void print_service_formatted(SERVICE *servicep, void *buff, int size) 917 1370 { 918 1371 char type; … … 1463 1916 } 1464 1917 1918 char *getJSONDimBuffer(char *node, int browser) 1919 { 1920 BROWSER *browserp; 1921 int prepareJSONDimTree(); 1922 1923 if (browser) 1924 { 1925 if ((browserp = find_browser(browser))) 1926 { 1927 if (browserp->pattern[0] != '\0') 1928 { 1929 prepareJSONDimTree(node, browserp); 1930 return(browserp->JSONBuffer); 1931 } 1932 browserp->n_services = 0; 1933 browserp->n_servers = 0; 1934 browserp->n_nodes = 0; 1935 } 1936 } 1937 prepareJSONDimTree(node, 0); 1938 return(JSONBuffer); 1939 } 1940 1465 1941 char *getJSONHeader(int isSMI) 1466 1942 { … … 1550 2026 if(selective) 1551 2027 { 1552 if(!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers )))2028 if(!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers, 0))) 1553 2029 { 1554 2030 nodep->match = 0; … … 1609 2085 if(selective) 1610 2086 { 1611 if(!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0 )))2087 if(!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0, 0))) 1612 2088 { 1613 2089 servp->match = 0; … … 1714 2190 if(selective) 1715 2191 { 1716 if(!(ret = find_service_pattern(nodep, 0, pattern, &tot_n_servers )))2192 if(!(ret = find_service_pattern(nodep, 0, pattern, &tot_n_servers, 0))) 1717 2193 { 1718 2194 nodep->match = 0; … … 1773 2249 if(selective) 1774 2250 { 1775 if(!(ret = find_service_pattern(nodep, servp, pattern, 0 )))2251 if(!(ret = find_service_pattern(nodep, servp, pattern, 0, 0))) 1776 2252 { 1777 2253 servp->match = 0; … … 1814 2290 */ 1815 2291 printf("%s\n",browserp->JSONSmiBuffer); 2292 return(1); 2293 } 2294 2295 int prepareJSONDimTree(char *node, BROWSER *browserp) 2296 { 2297 char *ptr; 2298 NODE *nodep; 2299 SERVER *servp; 2300 char str[256], aux[128]; 2301 int selective = 0; 2302 int n_nodes, tot_n_nodes; 2303 int n_servers, tot_n_servers; 2304 int ret, n_found = 0; 2305 2306 if (browserp) 2307 { 2308 if (browserp->pattern[0] != '\0') 2309 selective = 1; 2310 else 2311 return(0); 2312 } 2313 if (!selective) 2314 { 2315 if (JSONBufferSize == 0) 2316 { 2317 JSONBuffer = malloc((size_t)(N_nodes * 128 + N_servers * 128)); 2318 } 2319 else if (JSONBufferSize < N_nodes * 128 + N_servers * 128) 2320 { 2321 free(JSONBuffer); 2322 JSONBuffer = malloc((size_t)(N_nodes * 128 + N_servers * 128)); 2323 } 2324 ptr = JSONBuffer; 2325 } 2326 else 2327 { 2328 if (browserp->JSONBufferSize == 0) 2329 { 2330 browserp->JSONBuffer = malloc((size_t)(N_services * (128*2))); 2331 } 2332 else if (browserp->JSONBufferSize < (N_services * (128 * 2))) 2333 { 2334 free(browserp->JSONBuffer); 2335 browserp->JSONBuffer = malloc((size_t)(N_services * (128 * 2))); 2336 } 2337 ptr = browserp->JSONBuffer; 2338 } 2339 *ptr = '\0'; 2340 if (!strcmp(node, "src")) 2341 { 2342 ptr = addJSONStart(ptr); 2343 ptr = addJSONNodeStart(ptr, "services"); 2344 // sprintf(str, "text: \"%s\", id: \"Nodes\", expanded: false", Title); 2345 // ptr = addJSONChildStart(ptr, str, 1); 2346 // ptr = addJSONNodeStart(ptr, "children"); 2347 nodep = Node_head; 2348 tot_n_nodes = 0; 2349 while ((nodep = (NODE *)sll_get_next((SLL *)nodep))) 2350 { 2351 // nodep->match = 1; 2352 if (selective) 2353 { 2354 if (!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers, &ptr))) 2355 { 2356 // nodep->match = 0; 2357 continue; 2358 } 2359 else 2360 { 2361 n_found += ret; 2362 } 2363 } 2364 tot_n_nodes++; 2365 } 2366 if(n_found) 2367 { 2368 ptr--; 2369 *(ptr-1) = ' '; 2370 } 2371 /* 2372 n_nodes = 0; 2373 nodep = Node_head; 2374 while ((nodep = (NODE *)sll_get_next((SLL *)nodep))) 2375 { 2376 if (!nodep->match) 2377 continue; 2378 getNodeLabel(nodep->name, aux); 2379 sprintf(str, "text: \"%s\", id: \"%s\", qtip: \"%s\"", 2380 aux, nodep->name, nodep->name); 2381 ptr = addJSONChildStart(ptr, str, 0); 2382 n_nodes++; 2383 if (WebDID_Debug) 2384 printf("adding %s %d %d\n", nodep->name, n_nodes, tot_n_nodes); 2385 if (n_nodes < tot_n_nodes) 2386 ptr = addJSONChildEnd(ptr, 1); 2387 else 2388 ptr = addJSONChildEnd(ptr, 0); 2389 } 2390 */ 2391 // ptr = addJSONNodeEnd(ptr); 2392 // ptr = addJSONChildEnd(ptr, 0); 2393 ptr = addJSONNodeEnd(ptr); 2394 ptr = addJSONEnd(ptr); 2395 if (selective) 2396 { 2397 browserp->n_services = n_found; 2398 browserp->n_servers = tot_n_servers; 2399 browserp->n_nodes = tot_n_nodes; 2400 } 2401 } 2402 else 2403 { 2404 if ((nodep = find_node(node))) 2405 { 2406 ptr = addJSONStart(ptr); 2407 ptr = addJSONNodeStart(ptr, "children"); 2408 servp = nodep->server_head; 2409 tot_n_servers = 0; 2410 while ((servp = (SERVER *)sll_get_next((SLL *)servp))) 2411 { 2412 servp->match = 1; 2413 if (servp->busy != 1) 2414 { 2415 servp->match = 0; 2416 continue; 2417 } 2418 if (selective) 2419 { 2420 if (!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0, 0))) 2421 { 2422 servp->match = 0; 2423 continue; 2424 } 2425 else 2426 { 2427 n_found += ret; 2428 } 2429 } 2430 tot_n_servers++; 2431 } 2432 n_servers = 0; 2433 servp = nodep->server_head; 2434 while ((servp = (SERVER *)sll_get_next((SLL *)servp))) 2435 { 2436 if (!servp->match) 2437 continue; 2438 sprintf(str, "text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\"", servp->name, servp->server.pid); 2439 ptr = addJSONChildStart(ptr, str, 0); 2440 n_servers++; 2441 if (n_servers < tot_n_servers) 2442 ptr = addJSONChildEnd(ptr, 1); 2443 else 2444 ptr = addJSONChildEnd(ptr, 0); 2445 } 2446 ptr = addJSONNodeEnd(ptr); 2447 ptr = addJSONEnd(ptr); 2448 } 2449 } 2450 /* 2451 if(!selective) 2452 printf(" Nodes&Servers %s\n",JSONBuffer); 2453 else 2454 printf(" Nodes&Servers %s\n",browserp->JSONBuffer); 2455 */ 1816 2456 return(1); 1817 2457 } … … 1871 2511 if(selective) 1872 2512 { 1873 n_found = find_server_service_pattern(servp, browserp->pattern );2513 n_found = find_server_service_pattern(servp, browserp->pattern, 0); 1874 2514 } 1875 2515 ptr = JSONServices; -
trunk/FACT++/dim/src/webDid/webServer.c
r18058 r18920 5 5 #include <fcntl.h> 6 6 7 int WebDID_Debug = 0; 7 extern int WebDID_Debug; 8 extern int IsWebDID; 8 9 9 10 #define BUFSIZE 8096 … … 83 84 } 84 85 85 int getParameters(char *buffer, char (*pars)[], char *ptrs[] )86 int getParameters(char *buffer, char (*pars)[], char *ptrs[], int nmandatory) 86 87 { 87 88 char *ptr, *parptr; … … 106 107 for(i = 0; ptrs[i]; i++) 107 108 { 108 109 if((ptr = strchr(ptrs[i],'&'))) 109 110 *ptr = '\0'; 110 111 while((ptr = strchr(ptrs[i],'%'))) … … 121 122 } 122 123 } 123 if(found == n) 124 return 1; 125 else 126 return 0; 124 if(nmandatory == -1) 125 { 126 if(found == n) 127 return 1; 128 } 129 else if(found >= nmandatory) 130 { 131 return found; 132 } 133 return 0; 127 134 } 128 135 … … 136 143 strcpy(pars[1],"browser="); 137 144 pars[2][0] = '\0'; 138 ret = getParameters(buffer, pars, ptrs );145 ret = getParameters(buffer, pars, ptrs, -1); 139 146 if(!ret) 140 147 return 0; … … 158 165 strcpy(pars[3],"browser="); 159 166 pars[4][0] = '\0'; 160 ret = getParameters(buffer, pars, ptrs );167 ret = getParameters(buffer, pars, ptrs, -1); 161 168 if(!ret) 162 169 return 0; … … 181 188 strcpy(pars[3],"force="); 182 189 pars[4][0] = '\0'; 183 ret = getParameters(buffer, pars, ptrs );190 ret = getParameters(buffer, pars, ptrs, -1); 184 191 if(!ret) 185 192 return 0; … … 190 197 if(WebDID_Debug) 191 198 printf("\nparse service pars - service %s %d %d %d\n\n",service, *req, *browser, *force); 199 return 1; 200 } 201 202 int getServiceParametersDim(char *buffer, char *service, void *nolink, int *nolinksize, int *update) 203 { 204 char pars[10][32]; 205 char *ptrs[10]; 206 int ret; 207 char nolinkstr[MAX_NAME] = { '\0' }, updatestr[10] = { '\0' }; 208 char servicestr[MAX_NAME]; 209 210 strcpy(pars[0], "service="); 211 strcpy(pars[1], "nolink="); 212 strcpy(pars[2], "update="); 213 pars[3][0] = '\0'; 214 ret = getParameters(buffer, pars, ptrs, 1); 215 if (!ret) 216 return 0; 217 strcpy(servicestr, ptrs[0]); 218 if (ptrs[1]) 219 strcpy(nolinkstr, ptrs[1]); 220 if (ptrs[2]) 221 strcpy(updatestr, ptrs[2]); 222 // sscanf(ptrs[1], "%d", req); 223 // sscanf(ptrs[2], "%d", browser); 224 // sscanf(ptrs[3], "%d", force); 225 if (servicestr[0] == '"') 226 { 227 strcpy((char *)service, &servicestr[1]); 228 ((char *)service)[strlen(servicestr) - 2] = '\0'; 229 } 230 else 231 { 232 strcpy(service, ptrs[0]); 233 } 234 if ((nolink) && (nolinksize)) 235 { 236 if(nolinkstr[0] != '\0') 237 { 238 if (nolinkstr[0] == '"') 239 { 240 strcpy((char *)nolink, &nolinkstr[1]); 241 ((char *)nolink)[strlen(nolinkstr) - 2] = '\0'; 242 *nolinksize = strlen(nolinkstr) - 2 + 1; 243 } 244 else 245 { 246 sscanf(nolinkstr, "%d", (int *)nolink); 247 *nolinksize = sizeof(int); 248 } 249 } 250 else 251 { 252 *((int *)nolink) = -1; 253 *nolinksize = sizeof(int); 254 } 255 } 256 if (update) 257 { 258 if (updatestr[0] != '\0') 259 { 260 sscanf(updatestr, "%d", (int *)update); 261 } 262 } 263 if (WebDID_Debug) 264 printf("\nparse service pars - service %s %s %s\n\n", service, nolinkstr, updatestr); 192 265 return 1; 193 266 } … … 238 311 } 239 312 240 void sendData(int conn_id, char *buffer, int type )313 void sendData(int conn_id, char *buffer, int type, int oper) 241 314 { 242 315 static char date_buffer[128]; … … 250 323 extern char *getJSONHeader(); 251 324 extern char *getJSONBuffer(); 325 extern char *getJSONDimBuffer(); 252 326 char datatype[128]; 253 327 char *conv_buffer; 328 int conv_size = 0; 329 char nolink[MAX_NAME]; 330 int nolinksize; 331 int update; 254 332 255 333 conv_buffer = buffer; … … 287 365 else 288 366 { 289 update_service_data(service, conn_id, 0, req, browser, force );367 update_service_data(service, conn_id, 0, req, browser, force, 1, 0, 0); 290 368 return; 291 369 } … … 296 374 if(WebDID_Debug) 297 375 printf("%s\n",ptr); 376 strcpy(datatype,"text/html"); 377 } 378 else if(type == 10) 379 { 380 ret = getServiceParametersDim(conv_buffer, service, nolink, &nolinksize, &update); 381 if(!ret) 382 { 383 strcpy(snd_data_buffer,"{}"); 384 ptr = snd_data_buffer; 385 } 386 else 387 { 388 if (oper == 0) 389 update = -1; 390 else if (oper == -1) 391 update = -2; 392 update_service_data(service, conn_id, update, 0, conn_id, 1, 0, nolink, nolinksize); 393 return; 394 } 395 } 396 else if(type == 11) 397 { 398 ptr = conv_buffer; 399 if(WebDID_Debug) 400 printf("%s\n",ptr); 401 // strcpy(datatype,"application/octet-stream"); 298 402 strcpy(datatype,"text/html"); 299 403 } … … 330 434 } 331 435 } 332 getTime(date_buffer); 333 (void)sprintf(snd_buffer,"HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n", 334 date_buffer, (int)strlen(ptr), datatype); 335 (void)web_write(conn_id,snd_buffer,(int)strlen(snd_buffer)); 436 else if (type == 12) 437 { 438 ret = getServiceParametersDim(conv_buffer, service, 0, 0, 0); 439 if (!ret) 440 { 441 strcpy(snd_data_buffer, "{}"); 442 ptr = snd_data_buffer; 443 } 444 else 445 { 446 find_services(service, conn_id, conn_id, 1); 447 ptr = getJSONDimBuffer("src", conn_id); 448 } 449 } 450 if (IsWebDID) 451 { 452 getTime(date_buffer); 453 /* 454 (void)sprintf(snd_buffer, "HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nKeep-Alive: timeout=1000\r\nConnection: keep-alive\r\n\r\n", 455 date_buffer, (int)strlen(ptr), datatype); 456 */ 457 (void)sprintf(snd_buffer, "HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n", 458 date_buffer, (int)strlen(ptr), datatype); 459 (void)web_write(conn_id, snd_buffer, (int)strlen(snd_buffer)); 460 } 336 461 if(WebDID_Debug) 337 462 printf("SENDING DATA to conn %d:\n%s\n",conn_id, snd_buffer); … … 391 516 else 392 517 { 393 update_service_data(service, conn_id, 0, req, browser, force );518 update_service_data(service, conn_id, 0, req, browser, force, 0, 0); 394 519 return; 395 520 } … … 434 559 } 435 560 } 436 getTime(date_buffer); 437 (void)sprintf(snd_buffer,"HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n", 438 date_buffer, (int)strlen(ptr), datatype); 439 (void)web_write(conn_id,snd_buffer,(int)strlen(snd_buffer)); 561 if (IsWebDID) 562 { 563 getTime(date_buffer); 564 (void)sprintf(snd_buffer, "HTTP/1.1 200 OK\r\nDate: %s\r\nServer: DID/19.7\r\nContent-Length: %d\r\nContent-Type: %s\r\nConnection: close\r\n\r\n", 565 date_buffer, (int)strlen(ptr), datatype); 566 (void)web_write(conn_id, snd_buffer, (int)strlen(snd_buffer)); 567 } 440 568 if(WebDID_Debug) 441 569 printf("SENDING DATA to conn %d:\n%s\n",conn_id, snd_buffer); … … 453 581 static char snd_buffer[BUFSIZE+1]; /* static so zero filled */ 454 582 static char date_buffer[128]; 583 char *ptr; 584 int operation = 0; 455 585 456 586 … … 462 592 if(WebDID_Debug) 463 593 printf("Got %s\n", buffer); 464 if( strncmp(buffer,"GET ",4) && strncmp(buffer,"get ",4) ) 465 { 466 log_it(SORRY,"Only simple GET operation supported",buffer,conn_id); 467 return; 468 } 469 594 if (IsWebDID) 595 { 596 if (strncmp(buffer, "GET ", 4) && strncmp(buffer, "get ", 4)) 597 { 598 log_it(SORRY, "Only simple GET operation supported", buffer, conn_id); 599 return; 600 } 601 } 470 602 for(i=4;i<BUFSIZE;i++) 471 603 { /* null terminate after the second space to ignore extra stuff */ … … 479 611 if(WebDID_Debug) 480 612 printf("Got 1 %s\n", buffer); 481 for(j=0;j<i-1;j++) /* check for illegal parent directory use .. */613 for(j=0;j<i-1;j++) /* check for illegal parent directory use .. */ 482 614 { 483 615 if(buffer[j] == '.' && buffer[j+1] == '.') … … 516 648 printf("SENDING to conn %d:\n%s\n",conn_id, snd_buffer); 517 649 */ 650 ptr = &buffer[5]; 651 if (!IsWebDID) 652 { 653 if (!strncmp(&buffer[0], "GET", 3) || !strncmp(&buffer[0], "get", 3)) 654 { 655 operation = 0; 656 } 657 if (!strncmp(&buffer[0], "SUBSCRIBE", 9) || !strncmp(&buffer[0], "subscribe", 9)) 658 { 659 operation = 1; 660 ptr = &buffer[11]; 661 } 662 if (!strncmp(&buffer[0], "UNSUBSCRIBE", 11) || !strncmp(&buffer[0], "unsubscribe", 11)) 663 { 664 operation = -1; 665 ptr = &buffer[13]; 666 } 667 } 518 668 if(fstr == 0) 519 669 { 520 670 if(WebDID_Debug) 521 671 printf("Got %s\n", buffer); 522 if(!strncmp(&buffer[5],"didHeader",9)) 523 { 524 sendData(conn_id, &buffer[5], 0); 525 return; 526 } 527 else if(!strncmp(&buffer[5],"didData",7)) 528 { 529 sendData(conn_id, &buffer[5], 1); 530 return; 531 } 532 else if(!strncmp(&buffer[5],"didServices",11)) 533 { 534 sendData(conn_id, &buffer[5], 2); 535 return; 536 } 537 else if(!strncmp(&buffer[5],"didServiceData",14)) 538 { 539 sendData(conn_id, &buffer[5], 3); 540 return; 541 } 542 else if(!strncmp(&buffer[5],"didPoll",7)) 543 { 544 sendData(conn_id, &buffer[5], 5); 545 return; 546 } 547 else if(!strncmp(&buffer[5],"didQuery",8)) 548 { 549 sendData(conn_id, &buffer[5], 6); 550 return; 551 } 552 else if(!strncmp(&buffer[5],"smiData",7)) 553 { 554 sendSmiData(conn_id, &buffer[5], 1); 555 return; 556 } 557 else if(!strncmp(&buffer[5],"smiObjects",10)) 558 { 559 sendSmiData(conn_id, &buffer[5], 2); 672 if (!strncmp(ptr, "didHeader", 9)) 673 { 674 sendData(conn_id, ptr, 0, 0); 675 return; 676 } 677 else if (!strncmp(ptr, "didData", 7)) 678 { 679 sendData(conn_id, ptr, 1, 0); 680 return; 681 } 682 else if (!strncmp(ptr, "didServices", 11)) 683 { 684 sendData(conn_id, ptr, 2, 0); 685 return; 686 } 687 else if (!strncmp(ptr, "didServiceData", 14)) 688 { 689 sendData(conn_id, ptr, 3, 0); 690 return; 691 } 692 else if (!strncmp(ptr, "dimService", 10)) 693 { 694 sendData(conn_id, ptr, 10, operation); 695 return; 696 } 697 else if (!strncmp(ptr, "didPoll", 7)) 698 { 699 sendData(conn_id, ptr, 5, 0); 700 return; 701 } 702 else if (!strncmp(ptr, "didQuery", 8)) 703 { 704 sendData(conn_id, ptr, 6, 0); 705 return; 706 } 707 else if (!strncmp(ptr, "dimBrowser", 10)) 708 { 709 sendData(conn_id, ptr, 12, 0); 710 return; 711 } 712 else if (!strncmp(ptr, "smiData", 7)) 713 { 714 sendSmiData(conn_id, ptr, 1); 715 return; 716 } 717 else if (!strncmp(ptr, "smiObjects", 10)) 718 { 719 sendSmiData(conn_id, ptr, 2); 560 720 return; 561 721 } … … 635 795 static void handler( int conn_id, char *packet, int size, int status ) 636 796 { 797 int close_browser(); 798 637 799 switch(status) 638 800 { … … 644 806 Net_conns[conn_id].task,Net_conns[conn_id].node ); 645 807 } 646 web_close(conn_id); 808 close_browser(conn_id); 809 web_close(conn_id); 647 810 break; 648 811 case STA_CONN: /* connection received */ … … 707 870 *ptr = '\0'; 708 871 } 709 chdir(currwd);710 log_it(LOG,"webDi dstarting",argv[1],getpid());872 // chdir(currwd); 873 log_it(LOG,"webDim starting",argv[1],getpid()); 711 874 /* setup the network socket */ 712 875 proto = 1; … … 714 877 get_node_name(dns_node); 715 878 did_init(dns_node, DNS_PORT); 716 if(!web_open_server("DID",handler, &proto, &port, error_handler)) 717 return(0); 879 if(IsWebDID) 880 { 881 if (!web_open_server("DID", handler, &proto, &port, error_handler)) 882 return(0); 883 } 884 else 885 { 886 if (!web_open_server("DimClient", handler, &proto, &port, error_handler)) 887 return(0); 888 } 718 889 /* 719 890 ret = matchString("hello world","*ll*");
Note:
See TracChangeset
for help on using the changeset viewer.