Changeset 18920 for trunk/FACT++/dim/src/webDid
- Timestamp:
- 10/18/17 13:54:41 (7 years ago)
- Location:
- trunk/FACT++/dim/src/webDid
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
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.