source: trunk/FACT++/dim/src/webDid/webDid.c@ 19779

Last change on this file since 19779 was 19184, checked in by tbretz, 6 years ago
Updated to v20r23
File size: 65.6 KB
Line 
1#include <stdio.h>
2#include <ctype.h>
3#include <time.h>
4#include <dim.h>
5#include <dic.h>
6#include <dis.h>
7
8int WebDID_Debug = 1;
9int IsWebDID = 1;
10
11typedef struct item{
12 struct item *next;
13 int id;
14 /* must be here */
15 char *service_format_ptr;
16 DNS_SERVER_INFO server;
17 DNS_SERVICE_INFO *service_ptr;
18 char name[MAX_NAME];
19 int match;
20 int busy;
21 int isSMI;
22// char *servicelistp;
23 char **service_format_ptrp;
24}SERVER;
25
26typedef struct nitem{
27 struct nitem *next;
28 SERVER *server_head;
29 char name[MAX_NAME];
30 int match;
31 int busy;
32 int hasSMI;
33}NODE;
34NODE *Node_head = (NODE *)0;
35
36typedef 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
56typedef struct reqp_ent {
57 struct reqp_ent *next;
58 struct reqp_ent *prev;
59 REQUEST *reqp;
60} REQUEST_PTR;
61
62typedef struct sitem{
63 struct sitem *next;
64 char name[MAX_NAME];
65 int sid;
66 void *buffer;
67 int buffer_size;
68 int size;
69 time_t timestamp;
70 void *buffer_str;
71 int buffer_str_size;
72 int str_size;
73 int conn_id;
74 time_t last_subscribed;
75 time_t last_updated;
76 int n_browsers;
77 int formatted;
78// void *nolink;
79// int nolinksize;
80 REQUEST *request_head;
81 int is_nolink;
82}SERVICE;
83SERVICE *Curr_service_head = (SERVICE *)0;
84
85typedef struct objstate{
86 char name[MAX_NAME];
87 char state[512];
88 int sid;
89 int mode_index;
90 void *browserp;
91}OBJSTATE;
92/*
93typedef struct domainitem{
94 char name[MAX_NAME];
95 OBJSTATE objs[1];
96}CURR_SMIDOMAIN;
97*/
98typedef struct bitem{
99 struct bitem *next;
100 int id;
101 /* must be here */
102 char *service_format_ptr;
103 int subscribe;
104 time_t last_subscribed;
105 time_t last_updated;
106 time_t last_polled;
107 time_t last_changed;
108 int conn_id;
109 int n_services;
110 int n_servers;
111 int n_nodes;
112 SERVICE *servicep;
113 char *JSONBuffer;
114 int JSONBufferSize;
115 char *JSONSmiBuffer;
116 int JSONSmiBufferSize;
117 char pattern[256];
118 char curr_command[MAX_NAME];
119// char *service_format_ptr;
120 int isSMI;
121 int n_domains;
122 char curr_smidomain[MAX_NAME];
123 int curr_smidomain_size;
124 int curr_smidomain_nobjs;
125 OBJSTATE *smidomainp;
126 int formatted;
127 REQUEST_PTR *requestp_head;
128}BROWSER;
129BROWSER *Browser_head = (BROWSER *)0;
130
131char *JSONBuffer = 0;
132int JSONBufferSize = 0;
133char JSONHeader[256] = {'\0'};
134char JSONSmiHeader[256] = {'\0'};
135
136char *JSONSmiBuffer = 0;
137int JSONSmiBufferSize = 0;
138
139int First_time = 1;
140int Curr_view_opt = -1;
141char Curr_view_opt_par[80];
142char Curr_service_name[132];
143char Curr_service_format[256];
144int Curr_service_print_type = 0;
145int N_nodes = 0;
146int N_servers = 0;
147int N_services = 0;
148static char no_link = -1;
149//static char no_link_str[5] = "DEAD";
150static char no_link_str[26] = "__DIM_SERVICE_NOT_THERE__";
151int no_link_int = -1;
152FILE *fptr;
153
154char *Service_content_str;
155char *Curr_service_list = 0;
156char *Curr_client_list = 0;
157int Curr_service_id = 0;
158SERVER *Got_Service_List = 0;
159SERVER *Got_Client_List = 0;
160
161int Timer_q;
162char Title[128];
163
164int did_init(char *local_node, int dns_port)
165{
166 void update_servers();
167 char icon_title[128];
168 char dns_node[128];
169 int ret;
170
171 dim_init();
172 dic_disable_padding();
173 dis_disable_padding();
174
175 ret = dim_get_dns_node(dns_node);
176 if(!ret)
177 {
178 strcpy(dns_node, local_node);
179 dim_set_dns_node(dns_node);
180 }
181 dns_port = dic_get_dns_port();
182 if(dns_port != DNS_PORT)
183 {
184 sprintf(Title,"DIM DNS: %s:%d",dns_node,dns_port);
185 }
186 else
187 {
188 sprintf(Title,"DIM DNS: %s",dns_node);
189 }
190 sprintf(icon_title,"DID %s",dns_node);
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 }
201 Timer_q = dtq_create();
202 dic_info_service((const char *)"DIS_DNS/SERVER_INFO",MONITORED,0,0,0,(void (*)(int *,void *,int *))update_servers,0,
203 &no_link,1);
204 return 1;
205}
206
207SERVER *find_server(NODE *nodep, int pid)
208{
209 SERVER *servp;
210 DNS_SERVER_INFO *ptr;
211
212 servp = nodep->server_head;
213 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
214 {
215 ptr = &servp->server;
216 if(ptr->pid == pid)
217 {
218 return(servp);
219 }
220 }
221 return ((SERVER *)0);
222}
223
224NODE *find_node(char *node)
225{
226 NODE *nodep;
227
228 nodep = Node_head;
229 while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
230 {
231 if(!strcmp(nodep->name,node))
232 {
233 return(nodep);
234 }
235 }
236 return ((NODE *)0);
237}
238
239int find_server_service_pattern(SERVER *servp, char *pattern, char **bufptr)
240{
241 DNS_SERVICE_INFO *servicep;
242 int n_services, i;
243 int n_found = 0;
244 char *ptr, str[256], *sptr, *sformat, *stype;
245 int type;
246// int index;
247 char *addJSONChildStart();
248 char *addJSONChildEnd();
249 int doall = 0, doit = 0;
250
251 servicep = servp->service_ptr;
252 n_services = servp->server.n_services;
253 if (!strcmp(pattern, "*"))
254 {
255 doall = 1;
256 }
257 for (i = 0; i < n_services; i++)
258 {
259 sptr = (char *)servp->service_format_ptrp[i];
260 if (!sptr)
261 break;
262 if (!doall)
263 {
264 doit = 0;
265// if (strstr(servicep->name, pattern))
266// if (sptr)
267// {
268// if (strstr(servicep->name, pattern))
269 if (strstr(sptr, pattern))
270 {
271 doit = 1;
272 }
273// }
274 }
275 if (doall || doit)
276 {
277 n_found++;
278 if(bufptr)
279 {
280/*
281 type = servicep->type;
282 if (type < 0xff)
283 printf("problem %s %d", servicep->name, servicep->type);
284 index = type;
285 type &= 0x000000FF;
286 index = (index >> 16) & 0xFFFF;
287 index--;
288 sptr = (char *)servp->service_format_ptrp[index];
289 ptr = *bufptr;
290 sprintf(str, "name: \"%s\", format: \"%s\", type: %d", servicep->name,
291 (char *)sptr + strlen((const char *)sptr)+1, type);
292*/
293 ptr = *bufptr;
294 sformat = (char *)sptr + strlen((const char *)sptr) + 1;
295 stype = (char *)sformat + strlen((const char *)sformat) + 1;
296 if (*stype == '\n')
297 type = 0;
298 else if (*stype == 'C')
299 type = 1;
300 else if (*stype == 'R')
301 type = 2;
302 sprintf(str, "name: \"%s\", format: \"%s\", type: %d", sptr, sformat, type);
303 ptr = addJSONChildStart(ptr, str, 0);
304 ptr = addJSONChildEnd(ptr, 1);
305 *bufptr = ptr;
306 }
307 }
308 servicep++;
309 }
310 return(n_found);
311}
312
313int find_service_pattern(NODE *nodep, SERVER *servpp, char *pattern, int *n_servers, char **ptr)
314{
315 SERVER *servp;
316 int ret, n_found = 0;
317 int n_servers_found = 0;
318
319 if(!servpp)
320 {
321 servp = nodep->server_head;
322 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
323 {
324 if((ret = find_server_service_pattern(servp, pattern, ptr)))
325 {
326 n_found += ret;
327 n_servers_found++;
328 }
329 }
330 }
331 else
332 {
333 if((ret = find_server_service_pattern(servpp, pattern, ptr)))
334 {
335 n_found += ret;
336 }
337 }
338 if(n_servers != 0)
339 *n_servers = n_servers_found;
340 return(n_found);
341}
342
343SERVICE *find_curr_service(char *service)
344{
345 SERVICE *servicep;
346
347 servicep = Curr_service_head ;
348 while( (servicep = (SERVICE *)sll_get_next((SLL *)servicep)) )
349 {
350 if(!strcmp(servicep->name,service))
351 {
352 return(servicep);
353 }
354 }
355 return ((SERVICE *)0);
356}
357
358BROWSER *find_browser(int id)
359{
360 BROWSER *browserp;
361
362 browserp = Browser_head;
363 while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
364 {
365 if(browserp->id == id)
366 {
367 return(browserp);
368 }
369 }
370 return ((BROWSER *)0);
371}
372/*
373void set_browser_changes(int n_services, int n_servers, int n_nodes)
374{
375 BROWSER *browserp;
376
377 browserp = Browser_head;
378 while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
379 {
380 if(browserp->n_services != n_services)
381 browserp->n_services_changed = 1;
382 if(browserp->n_servers != n_servers)
383 browserp->n_servers_changed = 1;
384 if(browserp->n_nodes != n_nodes)
385 browserp->n_nodes_changed = 1;
386 }
387}
388*/
389void prepare_browser_tree()
390{
391 BROWSER *browserp;
392 int prepareJSONTree(char *, BROWSER *);
393
394 browserp = Browser_head;
395 while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
396 {
397 if(browserp->pattern[0] != '\0')
398 prepareJSONTree("",browserp);
399 }
400}
401/*
402void clear_browser_changes(BROWSER *browserp)
403{
404 browserp->n_services_changed = 0;
405 browserp->n_servers_changed = 0;
406 browserp->n_nodes_changed = 0;
407}
408*/
409void update_servers(int *tag, DNS_DID *buffer, int *size)
410{
411int n_services, service_size;
412SERVER *servp;
413NODE *nodep;
414int j;
415char str[MAX_NAME], sname[MAX_NAME], *ptr;
416int prepareJSONTree();
417int prepareJSONHeader();
418void got_update_services();
419
420 if(tag){}
421 if(!Node_head)
422 {
423 Node_head = (NODE *)malloc(sizeof(NODE));
424 sll_init((SLL *)Node_head);
425 }
426 if(First_time)
427 {
428 First_time = 0;
429 }
430
431 if(!*size)
432 return;
433 if(*(char *)buffer == -1)
434 {
435 N_servers = 0;
436 N_services = 0;
437 return;
438 }
439 buffer->server.n_services = vtohl(buffer->server.n_services);
440 buffer->server.pid = vtohl(buffer->server.pid);
441 n_services = buffer->server.n_services;
442
443 if(n_services == 1)
444 return;
445 strcpy(sname, buffer->server.task);
446 if(n_services > 1)
447 {
448 for(j = 0; j < n_services; j++)
449 {
450 buffer->services[j].type = vtohl(
451 buffer->services[j].type);
452 buffer->services[j].status = vtohl(
453 buffer->services[j].status);
454 buffer->services[j].n_clients = vtohl(
455 buffer->services[j].n_clients);
456 if((int)strlen(sname) == MAX_TASK_NAME-4-1)
457 {
458 strcpy(str,buffer->services[j].name);
459 if( (ptr = strstr(str,"/CLIENT_LIST")) )
460 {
461 *ptr = '\0';
462 strcpy(sname,str);
463 }
464 }
465 }
466 }
467 if (!(nodep = find_node(buffer->server.node)))
468 {
469 if(n_services)
470 {
471 N_nodes++;
472 nodep = (NODE *)malloc(sizeof(NODE));
473 strcpy(nodep->name,buffer->server.node);
474 nodep->hasSMI = 0;
475 nodep->server_head = (SERVER *)malloc(sizeof(SERVER));
476 sll_init((SLL *)nodep->server_head);
477 sll_insert_queue((SLL *)Node_head,(SLL *)nodep);
478 }
479 }
480 if (!(servp = find_server(nodep,buffer->server.pid)))
481 {
482 if(n_services)
483 {
484 servp = (SERVER *)malloc(sizeof(SERVER));
485 strcpy(servp->name,sname);
486 servp->next = 0;
487 servp->id = 0;
488 servp->busy = 0;
489 servp->server.n_services = 0;
490 servp->service_ptr = 0;
491 servp->service_format_ptr = 0;
492 servp->service_format_ptrp = 0;
493 servp->isSMI = 0;
494 if(strstr(sname,"_SMI"))
495 {
496 servp->isSMI = 1;
497 nodep->hasSMI = 1;
498 }
499 sll_insert_queue((SLL *)nodep->server_head,(SLL *)servp);
500 }
501 }
502 if(n_services != 0)
503 {
504 if(n_services == servp->server.n_services)
505 {
506 return;
507 }
508 if(servp->server.n_services == 0)
509 N_servers++;
510 if(servp->server.n_services != -1)
511 N_services -= servp->server.n_services;
512 memcpy(&servp->server,&buffer->server,sizeof(DNS_SERVER_INFO));
513 if(servp->service_ptr)
514 {
515 free(servp->service_ptr);
516 servp->service_ptr = 0;
517 }
518 if (servp->service_format_ptr)
519 {
520 free(servp->service_format_ptr);
521 servp->service_format_ptr = 0;
522 }
523 if (servp->service_format_ptrp)
524 {
525 free(servp->service_format_ptrp);
526 servp->service_format_ptrp = 0;
527 }
528 if (n_services != -1)
529 {
530 service_size = n_services*(int)sizeof(DNS_SERVICE_INFO);
531 servp->service_ptr = (DNS_SERVICE_INFO *)malloc((size_t)service_size);
532 memcpy(servp->service_ptr, buffer->services, (size_t)service_size);
533 N_services += n_services;
534 sprintf(str, "%s/SERVICE_LIST", sname);
535// printf("subscribe update_servers %s %d\n", sname, n_services);
536 dic_info_service(str, ONCE_ONLY, 20, 0, 0,
537 got_update_services, (dim_long)servp, "None", 5);
538 }
539 servp->busy = 1;
540 }
541 else
542 {
543 if(servp)
544 {
545 N_servers--;
546 if(servp->server.n_services != -1)
547 {
548 N_services -= servp->server.n_services;
549 }
550 servp->server.n_services = 0;
551 servp->busy = -1;
552 servp->isSMI = 0;
553 }
554 }
555 if(JSONHeader[0])
556 prepareJSONHeader();
557// printf("update_servers %d %d %d\n", N_nodes, N_servers, N_services);
558}
559
560void got_update_services(BROWSER **tag, char *buffer, int *size)
561{
562 BROWSER *browserp;
563 SERVER *servp;
564 DNS_SERVICE_INFO *servicep;
565 int i, n_services, index = 0;
566 char *ptr, *ptre, *ptr1;
567// char tmp[MAX_NAME], *sptr;
568// int j, type;
569
570 if(size){}
571 browserp = (BROWSER *)*tag;
572 if (browserp)
573 {
574 if (browserp->service_format_ptr)
575 free(browserp->service_format_ptr);
576 browserp->service_format_ptr = (char *)malloc(strlen(buffer) + 1);
577 strcpy(browserp->service_format_ptr, buffer);
578 }
579 if (browserp->id == 0)
580 {
581 servp = (SERVER *)browserp;
582 n_services = servp->server.n_services;
583 if (servp->service_format_ptrp)
584 free(servp->service_format_ptrp);
585 servp->service_format_ptrp = (char **)malloc(n_services*sizeof(char *));
586 memset(servp->service_format_ptrp, 0, (size_t)n_services*sizeof(char *));
587 ptr = servp->service_format_ptr;
588 servicep = servp->service_ptr;
589 for (i = 0; i < n_services; i++)
590 {
591 servicep->type &= 0x000000FF;
592 servicep++;
593 servp->service_format_ptrp[index++] = ptr;
594 ptre = strchr(ptr, '\n');
595 ptr1 = strchr(ptr, '|');
596 if(ptr1)
597 {
598 *ptr1 = '\0';
599 ptr1++;
600 ptr1 = strchr(ptr1, '|');
601 if (ptr1)
602 *ptr1 = '\0';
603 }
604 ptr = ptre;
605 if (!ptr)
606 {
607 break;
608 if (!(*ptr))
609 break;
610 }
611 ptr++;
612 if (!(*ptr))
613 break;
614 }
615/*
616 for (i = 0; i < n_services; i++)
617 {
618 if (!servp->service_format_ptrp[i])
619 break;
620 servicep = servp->service_ptr;
621 for (j = 0; j < n_services; j++)
622 {
623 if (servicep->type < 0xFF)
624 {
625 if ((strstr(servicep->name, "/RpcIn")) || (strstr(servicep->name, "/RpcOut")))
626 {
627 strcpy(tmp, servicep->name);
628 if ((ptr = strstr(tmp, "/RpcIn")))
629 *ptr = '\0';
630 if ((ptr = strstr(tmp, "/RpcOut")))
631 *ptr = '\0';
632 if (!strcmp(tmp, servp->service_format_ptrp[i]))
633 {
634 servicep->type |= ((i + 1) << 16);
635 break;
636 }
637 }
638 if (!strcmp(servicep->name, servp->service_format_ptrp[i]))
639 {
640 servicep->type |= ((i+1) << 16);
641 break;
642 }
643 }
644// printf("%s %08x\n",servicep->name, servicep->type);
645// if (servicep->type == 0)
646// break;
647 servicep++;
648 }
649 }
650*/
651/*
652 servicep = servp->service_ptr;
653 for (i = 0; i < n_services; i++)
654 {
655 for (j = 0; j < n_services; j++)
656 {
657 if (!servp->service_format_ptrp[j])
658 break;
659 if ((strstr(servicep->name, "/RpcIn")) || (strstr(servicep->name, "/RpcOut")))
660 {
661 strcpy(tmp, servicep->name);
662 if ((ptr = strstr(tmp, "/RpcIn")))
663 *ptr = '\0';
664 if ((ptr = strstr(tmp, "/RpcOut")))
665 *ptr = '\0';
666 if (!strcmp(tmp, servp->service_format_ptrp[j]))
667 {
668 servicep->type |= ((j + 1) << 16);
669 break;
670 }
671 }
672 if (!strcmp(servicep->name, servp->service_format_ptrp[j]))
673 {
674 servicep->type |= ((j + 1) << 16);
675 break;
676 }
677 }
678 // if (servicep->type == 0)
679 // break;
680 type = servicep->type;
681 index = type;
682 type &= 0x000000FF;
683 index = (index >> 16) & 0xFFFF;
684 index--;
685 sptr = (char *)servp->service_format_ptrp[index];
686 printf("%s %08x %s\n", servicep->name, servicep->type, (char *)sptr + strlen((const char *)sptr) + 1);
687 servicep++;
688 }
689*/
690 }
691// printf("got_update_services %s\n", buffer);
692}
693
694char *update_services(char *node, char *server, int pid, int browser)
695{
696 char str[MAX_NAME];
697 NODE *nodep;
698 SERVER *servp;
699 char *ptr = 0;
700 BROWSER *browserp;
701 char *prepareJSONServiceList();
702 BROWSER *create_browser(int);
703
704 if(!(browserp = find_browser(browser)))
705 browserp = create_browser(browser);
706
707 if(server){}
708 sprintf(str,"%s/SERVICE_LIST",server);
709 dic_info_service(str,ONCE_ONLY,20,0,0,
710 got_update_services,(dim_long)browserp,"None",5);
711 if((nodep = find_node(node)))
712 {
713 if((servp = find_server(nodep, pid)))
714 {
715 ptr = prepareJSONServiceList(servp, node, pid, browserp);
716 }
717 }
718 return ptr;
719}
720
721void got_update_smi_objects(BROWSER **tag, char *buffer, int *size)
722{
723 BROWSER *browserp;
724
725 if(size){}
726 browserp = (BROWSER *)*tag;
727 if(browserp->service_format_ptr)
728 free(browserp->service_format_ptr);
729 browserp->service_format_ptr = (char *)malloc(strlen(buffer)+1);
730 strcpy(browserp->service_format_ptr, buffer);
731}
732
733char *update_smi_objects(char *node, char *server, int pid, int browser)
734{
735 char str[MAX_NAME];
736 NODE *nodep;
737 SERVER *servp;
738 char *ptr = 0;
739 BROWSER *browserp;
740 char *prepareJSONSmiObjectList();
741 BROWSER *create_browser();
742
743 if(!(browserp = find_browser(browser)))
744 {
745 browserp = create_browser(browser);
746 browserp->isSMI = 1;
747 }
748 if(server){}
749 sprintf(str,"%s/SERVICE_LIST",server);
750 dic_info_service(str,ONCE_ONLY,20,0,0,
751 got_update_smi_objects,(dim_long)browserp,"None",5);
752 if((nodep = find_node(node)))
753 {
754 if((servp = find_server(nodep, pid)))
755 {
756 ptr = prepareJSONSmiObjectList(servp, node, pid, browserp);
757 }
758 }
759 return ptr;
760}
761
762void get_curr_service_format()
763{
764 char *format;
765 char *dic_get_format();
766/*
767 char str[256], *ptr, *ptr1;
768 int rpc_flag;
769
770 strcpy(str,Curr_service_name);
771 rpc_flag = 0;
772 if( (ptr = strstr(str,"/RpcIn")) )
773 {
774 *ptr = '\0';
775 rpc_flag = 1;
776 }
777 if( (ptr = strstr(str,"/RpcOut")) )
778 {
779 *ptr = '\0';
780 rpc_flag = 2;
781 }
782 strcat(str,"|");
783*/
784 format = dic_get_format(0);
785/*
786 if( (ptr = strstr(Curr_service_list,str)) )
787 {
788 if(!rpc_flag)
789 {
790 ptr += (int)strlen(str);
791 ptr1 = strchr(ptr,'|');
792 }
793 else if(rpc_flag == 1)
794 {
795 ptr += (int)strlen(str);
796 ptr1 = strchr(ptr,',');
797 }
798 else
799 {
800 ptr += (int)strlen(str);
801 ptr = strchr(ptr,',');
802 ptr++;
803 ptr1 = strchr(ptr,'|');
804 }
805 strncpy(Curr_service_format,ptr,(int)(ptr1 - ptr));
806 Curr_service_format[(int)(ptr1-ptr)] = '\0';
807 }
808*/
809 if(format)
810 strcpy(Curr_service_format,format);
811 else
812 Curr_service_format[0] = '\0';
813}
814
815void get_service_format(char *buffer, char *service, char *format)
816{
817 char str[256], *ptr, *ptr1;
818 int rpc_flag;
819
820 strcpy(str, service);
821 rpc_flag = 0;
822 *format = '\0';
823 if( (ptr = strstr(str,"/RpcIn")) )
824 {
825 *ptr = '\0';
826 rpc_flag = 1;
827 }
828 if( (ptr = strstr(str,"/RpcOut")) )
829 {
830 *ptr = '\0';
831 rpc_flag = 2;
832 }
833 strcat(str,"|");
834 if( (ptr = strstr(buffer, str)) )
835 {
836 if(!rpc_flag)
837 {
838 ptr += (int)strlen(str);
839 ptr1 = strchr(ptr,'|');
840 }
841 else if(rpc_flag == 1)
842 {
843 ptr += (int)strlen(str);
844 ptr1 = strchr(ptr,',');
845 }
846 else
847 {
848 ptr += (int)strlen(str);
849 ptr = strchr(ptr,',');
850 ptr++;
851 ptr1 = strchr(ptr,'|');
852 }
853 strncpy(format,ptr,(size_t)(ptr1 - ptr));
854 format[(int)(ptr1-ptr)] = '\0';
855 }
856}
857
858int delete_curr_service(SERVICE *servicep)
859{
860
861if(WebDID_Debug)
862printf("\nUnsubscribing %s\n\n",servicep->name);
863 dic_release_service(servicep->sid);
864 if(servicep->buffer_size)
865 free(servicep->buffer);
866 if(servicep->buffer_str_size)
867 free(servicep->buffer_str);
868// if (servicep->nolink)
869// free(servicep->nolink);
870 sll_remove((SLL *)Curr_service_head, (SLL *)servicep);
871 free(servicep);
872 return(1);
873}
874
875int close_browser(int browser)
876{
877 BROWSER *browserp;
878 int delete_browser();
879
880 if ((browserp = find_browser(browser)))
881 delete_browser(browserp);
882 return 1;
883}
884
885int delete_browser(BROWSER *browserp)
886{
887// SERVICE *servicep;
888 int release_all_requests();
889
890 release_all_requests(browserp);
891 if (browserp->requestp_head)
892 free(browserp->requestp_head);
893 /*
894 if((servicep = browserp->servicep))
895 {
896 servicep->n_browsers--;
897 if(!servicep->n_browsers)
898 delete_curr_service(servicep);
899 }
900*/
901 if(browserp->service_format_ptr)
902 free(browserp->service_format_ptr);
903 sll_remove((SLL *)Browser_head, (SLL *)browserp);
904 free(browserp);
905 return(1);
906}
907
908void check_browser( BROWSER *tag)
909{
910 BROWSER *browserp;
911 time_t tsecs;
912
913 browserp = (BROWSER *)tag;
914if(WebDID_Debug)
915printf("\nCheck_browser %d\n",browserp->id);
916 tsecs = time((time_t *)0);
917 if((tsecs - browserp->last_polled) > 20)
918 {
919if(WebDID_Debug)
920printf("\nDeleting browser %d\n\n",browserp->id);
921 delete_browser(browserp);
922 }
923 else
924 dtq_start_timer(10, check_browser, browserp);
925}
926
927BROWSER *create_browser(int id)
928{
929 BROWSER *browserp;
930
931 if(!Browser_head)
932 {
933 Browser_head = (BROWSER *)malloc(sizeof(BROWSER));
934 sll_init((SLL *)Browser_head);
935 }
936 browserp = (BROWSER *)malloc(sizeof(BROWSER));
937 browserp->id = id;
938 browserp->last_subscribed = 0;
939 browserp->last_updated = 0;
940 browserp->last_polled = 0;
941 browserp->last_changed = 0;
942 browserp->n_nodes = 0;
943 browserp->n_servers = 0;
944 browserp->n_services = 0;
945// browserp->servicep = 0;
946 browserp->JSONBuffer = 0;
947 browserp->JSONBufferSize = 0;
948 browserp->JSONSmiBuffer = 0;
949 browserp->JSONSmiBufferSize = 0;
950 browserp->pattern[0] = '\0';
951 browserp->service_format_ptr = 0;
952 browserp->curr_command[0] = '\0';
953 browserp->curr_smidomain[0] = '\0';
954 browserp->smidomainp = 0;
955 browserp->requestp_head = (REQUEST_PTR *)malloc(sizeof(REQUEST_PTR));
956 dll_init((DLL *)(browserp->requestp_head));
957 sll_insert_queue((SLL *)Browser_head, (SLL *)browserp);
958 if(IsWebDID)
959 dtq_start_timer(10, check_browser, browserp);
960 return browserp;
961}
962
963int update_command_data(char *service, int conn_id, BROWSER *browserp)
964{
965 char format[MAX_NAME];
966 char answer[MAX_NAME*3];
967 extern void sendData();
968
969 if(browserp->service_format_ptr)
970 {
971 get_service_format(browserp->service_format_ptr, service, format);
972if(WebDID_Debug)
973printf("CMD data %s %s\n",service,format);
974 }
975 else
976 {
977 strcpy(format,"?");
978 }
979 strcpy(browserp->curr_command, service);
980 sprintf(answer,"To %s (%s)",service, format);
981 sendData(conn_id, answer, 4);
982 return 1;
983}
984
985REQUEST *create_request(int conn_id, SERVICE *servicep, int timeout, void *nolink, int nolinksize)
986{
987 REQUEST *newp;
988
989 newp = (REQUEST *)malloc(sizeof(REQUEST));
990 newp->servicep = servicep;
991 newp->timeout = timeout;
992 newp->conn_id = conn_id;
993// newp->first_time = 1;
994// newp->delay_delete = 0;
995// newp->to_delete = 0;
996 newp->timr_ent = 0;
997 newp->reqpp = 0;
998 newp->nolink = 0;
999 newp->nolinksize = 0;
1000 if (nolinksize)
1001 {
1002 newp->nolink = malloc(nolinksize);
1003 newp->nolinksize = nolinksize;
1004 memcpy(newp->nolink, nolink, nolinksize);
1005 }
1006 dll_insert_queue((DLL *)servicep->request_head, (DLL *)newp);
1007 return newp;
1008}
1009
1010REQUEST_PTR *create_requestp(REQUEST *reqp, BROWSER *browserp)
1011{
1012 REQUEST_PTR *reqpp;
1013
1014 reqpp = (REQUEST_PTR *)malloc(sizeof(REQUEST_PTR));
1015 reqpp->reqp = reqp;
1016 reqp->reqpp = reqpp;
1017 dll_insert_queue((DLL *)browserp->requestp_head, (DLL *)reqpp);
1018 return reqpp;
1019}
1020
1021int release_request(REQUEST_PTR *reqpp)
1022{
1023 REQUEST *reqp;
1024 SERVICE *servicep;
1025
1026 reqp = reqpp->reqp;
1027 if (reqp)
1028 {
1029 servicep = reqp->servicep;
1030 dll_remove((DLL *)reqp);
1031 }
1032 if (reqpp)
1033 dll_remove((DLL *)reqpp);
1034 if (reqp->nolink)
1035 free(reqp->nolink);
1036 // if (reqp->timr_ent)
1037// dtq_rem_entry(Dis_timer_q, reqp->timr_ent);
1038// id_free(reqp->req_id, SRC_DIS);
1039 servicep->n_browsers--;
1040 if (dll_empty((DLL *)servicep->request_head))
1041 {
1042// if (!servicep->n_browsers)
1043// {
1044 free(servicep->request_head);
1045 delete_curr_service(servicep);
1046// }
1047 }
1048 if (reqp)
1049 free(reqp);
1050 if (reqpp)
1051 free(reqpp);
1052 return 1;
1053}
1054
1055int release_all_requests(BROWSER *browserp)
1056{
1057 REQUEST_PTR *reqpp, *auxp;
1058 int release_request();
1059
1060 if (browserp)
1061 {
1062 reqpp = browserp->requestp_head;
1063 while ((reqpp = (REQUEST_PTR *)dll_get_next((DLL *)browserp->requestp_head,
1064 (DLL *)reqpp)))
1065 {
1066 auxp = reqpp->prev;
1067 release_request(reqpp);
1068 reqpp = auxp;
1069 }
1070 }
1071 return 1;
1072}
1073
1074REQUEST_PTR *find_request(SERVICE* servicep, int conn_id)
1075{
1076// REQUEST_PTR *reqpp;
1077 REQUEST *reqp;
1078
1079 if (servicep)
1080 {
1081 reqp = servicep->request_head;
1082 while ((reqp = (REQUEST *)dll_get_next((DLL *)servicep->request_head,
1083 (DLL *)reqp)))
1084 {
1085 if (reqp->conn_id == conn_id)
1086 return reqp->reqpp;
1087 }
1088 }
1089 return (REQUEST_PTR *)0;
1090}
1091
1092int update_service_data(char *service, int conn_id, int subscribe, int req, int browser, int force,
1093 int formatted, void *nolink, int nolinksize)
1094{
1095 SERVICE *servicep;
1096 time_t tsecs;
1097 void recv_service_info();
1098 extern void sendData();
1099 BROWSER *browserp;
1100// int i;
1101 REQUEST *reqp;
1102 REQUEST_PTR *reqpp;
1103
1104 if(req){}
1105 if(!Curr_service_head)
1106 {
1107 Curr_service_head = (SERVICE *)malloc(sizeof(SERVICE));
1108 sll_init((SLL *)Curr_service_head);
1109 }
1110 if(!(browserp = find_browser(browser)))
1111 browserp = create_browser(browser);
1112 if(force == -1)
1113 {
1114 update_command_data(service, conn_id, browserp);
1115 return 1;
1116 }
1117 browserp->formatted = formatted;
1118 if(IsWebDID)
1119 {
1120/*
1121 if ((servicep = browserp->servicep))
1122 {
1123 servicep->n_browsers--;
1124 if (!servicep->n_browsers)
1125 delete_curr_service(servicep);
1126 }
1127*/
1128 release_all_requests(browserp);
1129 }
1130 if (subscribe == -2)
1131 {
1132 if ((servicep = find_curr_service(service)))
1133 {
1134 reqpp = find_request(servicep, conn_id);
1135 if (reqpp)
1136 release_request(reqpp);
1137 }
1138 return 1;
1139 }
1140 if(!(servicep = find_curr_service(service)))
1141 {
1142 servicep = (SERVICE *)malloc(sizeof(SERVICE));
1143 strcpy(servicep->name,service);
1144 servicep->conn_id = conn_id;
1145 servicep->buffer = 0;
1146 servicep->buffer_size = 0;
1147 servicep->size = 0;
1148 servicep->buffer_str = 0;
1149 servicep->buffer_str_size = 0;
1150 servicep->str_size = 0;
1151 servicep->last_updated = 0;
1152 tsecs = time((time_t *)0);
1153 browserp->last_subscribed = tsecs;
1154 browserp->last_updated = tsecs;
1155 servicep->last_subscribed = tsecs;
1156 servicep->n_browsers = 0;
1157 servicep->formatted = formatted;
1158 servicep->request_head = (REQUEST *)malloc(sizeof(REQUEST));
1159 servicep->is_nolink = 0;
1160 dll_init((DLL *)(servicep->request_head));
1161 reqp = create_request(conn_id, servicep, subscribe, nolink, nolinksize);
1162 reqpp = create_requestp(reqp, browserp);
1163 sll_insert_queue((SLL *)Curr_service_head,(SLL *)servicep);
1164 servicep->sid = (int)dic_info_service_stamped(service, MONITORED, 0, 0, 0,
1165 recv_service_info, servicep, no_link_str, strlen(no_link_str));
1166 }
1167 else
1168 {
1169 if(servicep->size)
1170 {
1171 reqp = create_request(conn_id, servicep, subscribe, nolink, nolinksize);
1172 reqpp = create_requestp(reqp, browserp);
1173 if ((servicep->timestamp > browserp->last_updated) || (force))
1174 {
1175 if(browserp->formatted)
1176 sendData(conn_id, servicep->buffer_str, 4);
1177 else
1178 {
1179 if (servicep->is_nolink)
1180 sendData(conn_id, reqp->nolink, 11);
1181 else
1182 sendData(conn_id, servicep->buffer, 11);
1183// sendData(conn_id, servicep->buffer, 11);
1184 }
1185 }
1186 else
1187 {
1188 sendData(conn_id, "", 4);
1189 }
1190 browserp->last_updated = servicep->timestamp;
1191 }
1192 }
1193 if(force)
1194 {
1195// browserp->servicep = servicep;
1196 servicep->n_browsers++;
1197 }
1198 return 1;
1199}
1200
1201int check_browser_changes(char *service, int conn_id, int subscribe, int req, int browser, int force)
1202{
1203 SERVICE *servicep;
1204 time_t tsecs;
1205 void recv_service_info();
1206 extern void sendData();
1207 BROWSER *browserp;
1208 char answer[256];
1209 int service_changed = 0;
1210
1211 if(req){}
1212 if(subscribe){}
1213 if(!(browserp = find_browser(browser)))
1214 browserp = create_browser(browser);
1215 if(!Curr_service_head)
1216 {
1217 Curr_service_head = (SERVICE *)malloc(sizeof(SERVICE));
1218 sll_init((SLL *)Curr_service_head);
1219 }
1220 if(service[0] != '\0')
1221 {
1222 if((servicep = find_curr_service(service)))
1223 {
1224 if(servicep->size)
1225 {
1226 if((servicep->timestamp > browserp->last_updated) || (force))
1227 {
1228 service_changed = 1;
1229 }
1230 }
1231 }
1232 }
1233 if(browserp->isSMI)
1234 {
1235 if((browserp->last_changed >= browserp->last_polled) || (force))
1236 {
1237 service_changed = 1;
1238 }
1239 }
1240/*
1241 sprintf(answer,"%d %d %d %d\n",
1242 browserp->n_services_changed, browserp->n_servers_changed,
1243 browserp->n_nodes_changed, service_changed);
1244*/
1245 sprintf(answer,"%d %d %d %d %d %d %d\n",
1246 N_services, N_servers, N_nodes, service_changed,
1247 browserp->n_services, browserp->n_servers, browserp->n_nodes);
1248 sendData(conn_id, answer, 4);
1249 tsecs = time((time_t *)0);
1250 browserp->last_polled = tsecs;
1251 return 1;
1252}
1253
1254int find_services(char *pattern, int conn_id, int browser, int force)
1255{
1256 void recv_service_info();
1257 extern void sendData();
1258 BROWSER *browserp;
1259 char format[MAX_NAME];
1260 int prepareJSONTree();
1261 void did_prepare_command();
1262
1263 if(conn_id){}
1264 if(!(browserp = find_browser(browser)))
1265 browserp = create_browser(browser);
1266 if(force == -1)
1267 {
1268 if(browserp->service_format_ptr)
1269 {
1270 get_service_format(browserp->service_format_ptr, browserp->curr_command, format);
1271 did_prepare_command(pattern, browserp->curr_command, format);
1272 }
1273 return 1;
1274 }
1275 if(conn_id){}
1276 if(!(browserp = find_browser(browser)))
1277 browserp = create_browser(browser);
1278 strcpy(browserp->pattern, pattern);
1279 return 1;
1280}
1281
1282void recv_service_info(void **tag, int *buffer, int *size)
1283{
1284 int conn_id;
1285 void print_service_formatted();
1286 extern void sendData();
1287 SERVICE *servicep;
1288 time_t tsecs;
1289 REQUEST *reqp, *auxp;
1290
1291 servicep = *tag;
1292 conn_id = servicep->conn_id;
1293 if (servicep->buffer_size < *size)
1294 {
1295 if(servicep->buffer_size)
1296 free(servicep->buffer);
1297 servicep->buffer = malloc((size_t)*size);
1298 servicep->buffer_size = *size;
1299 }
1300 memcpy(servicep->buffer, (char *)buffer, (size_t)*size);
1301 servicep->size = *size;
1302 if (servicep->buffer_str_size < (1024 + (*size)*16))
1303 {
1304 if(servicep->buffer_str_size)
1305 free(servicep->buffer_str);
1306 servicep->buffer_str = malloc((size_t)(1024 + (*size)*16));
1307 servicep->buffer_str_size = 1024 + (*size)*16;
1308 }
1309 Service_content_str = servicep->buffer_str;
1310 strcpy(Curr_service_name, servicep->name);
1311 get_curr_service_format();
1312// if ((*size == servicep->nolinksize) && (!memcmp(buffer, servicep->nolink, servicep->nolinksize)))
1313// if ((*size == 4) && (*buffer == -1))
1314 servicep->is_nolink = 0;
1315 if ((*size == (int)strlen(no_link_str)) && (!memcmp(buffer, no_link_str, strlen(no_link_str))))
1316 {
1317 servicep->is_nolink = 1;
1318 sprintf(Service_content_str,
1319 "Service %s Not Available", Curr_service_name);
1320 }
1321 else
1322 {
1323 print_service_formatted(servicep, buffer, *size);
1324 }
1325if(WebDID_Debug)
1326 printf("service updated - %s, conn_id %d\n", Curr_service_name, conn_id);
1327
1328 if (IsWebDID)
1329 {
1330 if (servicep->last_updated == 0)
1331 {
1332 if (servicep->formatted)
1333 sendData(conn_id, Service_content_str, 4);
1334 else
1335 sendData(conn_id, servicep->buffer, 11);
1336 tsecs = time((time_t *)0);
1337 servicep->last_updated = tsecs;
1338 }
1339 }
1340 else
1341 {
1342 tsecs = time((time_t *)0);
1343 servicep->last_updated = tsecs;
1344 reqp = servicep->request_head;
1345 while ((reqp = (REQUEST *)dll_get_next((DLL *)servicep->request_head,
1346 (DLL *)reqp)))
1347 {
1348/*
1349 if (servicep->buffer_size < reqp->nolinksize)
1350 {
1351 if (servicep->buffer_size)
1352 free(servicep->buffer);
1353 servicep->buffer = malloc((size_t)reqp->nolinksize);
1354 servicep->buffer_size = reqp->nolinksize;
1355 }
1356 memcpy(servicep->buffer, (char *)reqp->nolink, (size_t)reqp->nolinksize);
1357 servicep->size = *size;
1358*/
1359 if (servicep->is_nolink)
1360 sendData(reqp->conn_id, reqp->nolink, 11);
1361 else
1362 sendData(reqp->conn_id, servicep->buffer, 11);
1363 if (reqp->timeout == -1)
1364 {
1365// May delete servicep...
1366 auxp = reqp->prev;
1367 release_request(reqp->reqpp);
1368 reqp = auxp;
1369 }
1370 }
1371 }
1372}
1373
1374void print_service_formatted(SERVICE *servicep, void *buff, int size)
1375{
1376char type;
1377int num, ret;
1378char str[256];
1379char *ptr;
1380void *buffer_ptr;
1381char timestr[256], aux[64], sizestr[64];
1382int quality = 0, secs = 0, mili = 0;
1383int did_write_string(char, int, void **, int);
1384time_t tsecs;
1385
1386 if(size < 1024)
1387 sprintf(sizestr,"%d bytes",size);
1388 else if (size < 1024*1024)
1389 sprintf(sizestr,"%2.2f Kb",(float)size/1024);
1390 else
1391 sprintf(sizestr,"%2.2f Mb",(float)size/(1024*1024));
1392
1393 sprintf(Service_content_str,
1394 "<FONT FACE=\"consolas\">Service %s (%s) Contents :<br /> <br />", Curr_service_name,
1395 Curr_service_format);
1396 dic_get_timestamp(0, &secs, &mili);
1397 quality = dic_get_quality(0);
1398 tsecs = secs;
1399 servicep->timestamp = tsecs;
1400 my_ctime(&tsecs, timestr, 128);
1401 ptr = strrchr(timestr,' ');
1402 strcpy(aux, ptr);
1403 sprintf(ptr,".%03d",mili);
1404 strcat(timestr, aux);
1405 timestr[(int)strlen(timestr)-1] = '\0';
1406
1407 sprintf(str," Timestamp: %s&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Quality: %d&nbsp&nbsp&nbsp Size: %s<br /><br />",
1408 timestr, quality, sizestr);
1409
1410 strcat(Service_content_str,str);
1411 ptr = Curr_service_format;
1412 buffer_ptr = buff;
1413 while(*ptr)
1414 {
1415 type = *ptr++;
1416 if(*ptr == ':')
1417 {
1418 ptr++;
1419 sscanf(ptr, "%d", &num);
1420 ret = did_write_string(type, num, &buffer_ptr, size);
1421 size -= ret;
1422 if( (ptr = strchr(ptr,';')) )
1423 ptr++;
1424 else
1425 break;
1426 }
1427 else
1428 {
1429 ret = did_write_string(type, 0, &buffer_ptr, size);
1430 size -= ret;
1431 break;
1432 }
1433 }
1434 strcat(Service_content_str,"</FONT>");
1435}
1436
1437
1438int did_write_string(char type, int num, void **buffer_ptr, int ssize)
1439{
1440void *ptr;
1441int size, psize;
1442
1443 void print_service_standard();
1444 void print_service_char();
1445 void print_service_short();
1446 void print_service_float();
1447 void print_service_double();
1448
1449 ptr = *buffer_ptr;
1450 switch(type)
1451 {
1452 case 'L':
1453 case 'l':
1454 strcat(Service_content_str," L");
1455 if(!num)
1456 size = ssize/(int)sizeof(int);
1457 else
1458 size = num;
1459 psize = size * (int)sizeof(int);
1460 print_service_standard(ptr, size);
1461 break;
1462 case 'I':
1463 case 'i':
1464 strcat(Service_content_str," I");
1465 if(!num)
1466 size = ssize/(int)sizeof(int);
1467 else
1468 size = num;
1469 psize = size * (int)sizeof(int);
1470 print_service_standard(ptr, size);
1471 break;
1472 case 'S':
1473 case 's':
1474 strcat(Service_content_str," S");
1475 if(!num)
1476 size = ssize/(int)sizeof(short);
1477 else
1478 size = num;
1479 psize = size * (int)sizeof(short);
1480 print_service_short(ptr, size);
1481 break;
1482 case 'F':
1483 case 'f':
1484 strcat(Service_content_str," F");
1485 if(!num)
1486 size = ssize/(int)sizeof(float);
1487 else
1488 size = num;
1489 psize = size * (int)sizeof(float);
1490 print_service_float(ptr, size);
1491 break;
1492 case 'D':
1493 case 'd':
1494 strcat(Service_content_str," D");
1495 if(!num)
1496 size = ssize/(int)sizeof(double);
1497 else
1498 size = num;
1499 psize = size * (int)sizeof(double);
1500 print_service_double(ptr, size);
1501 break;
1502 case 'X':
1503 case 'x':
1504 strcat(Service_content_str," X");
1505 if(!num)
1506 size = ssize/(int)sizeof(longlong);
1507 else
1508 size = num;
1509 psize = size * (int)sizeof(longlong);
1510 print_service_standard(ptr, size*2);
1511 break;
1512 case 'C':
1513 case 'c':
1514 default:
1515 strcat(Service_content_str," C");
1516 if(!num)
1517 size = ssize;
1518 else
1519 size = num;
1520 psize = size;
1521 print_service_char(ptr, size);
1522 }
1523 ptr = (char *)ptr + psize;
1524 *buffer_ptr = ptr;
1525 return psize;
1526}
1527
1528void sprintf_html(char *str, int n, int value)
1529{
1530 char tmp[80];
1531 int min, i;
1532
1533 str[0] = '\0';
1534 min = sprintf(tmp,"%d",value);
1535 for(i = 0; i < (n-min); i++)
1536 {
1537 strcat(str,"&nbsp");
1538 }
1539 strcat(str, tmp);
1540}
1541
1542void print_service_standard(int *buff, int size)
1543{
1544int i,j;
1545char *ptr, str[80], tmp[256];
1546int last[4];
1547
1548 ptr = Service_content_str;
1549 ptr += (int)strlen(Service_content_str);
1550 for( i = 0; i < size; i++)
1551 {
1552 strcpy(tmp,"");
1553 if(i%4 == 0)
1554 {
1555 if(i != 0)
1556 {
1557 strcat(tmp,"&nbsp");
1558 }
1559 sprintf_html(str, 7, i);
1560 strcat(tmp,str);
1561 }
1562 if(!(i%4))
1563 strcat(tmp,"H: ");
1564 sprintf(str,"&nbsp&nbsp&nbsp %08X",buff[i]);
1565 strcat(tmp,str);
1566 last[i%4] = buff[i];
1567 if((i%4 == 3) || (i == (size-1)))
1568 {
1569 strcat(tmp,"<br />");
1570 for(j = 0; j <= (i%4); j++)
1571 {
1572 if(j == 0)
1573 strcat(tmp,"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp D: ");
1574 sprintf_html(str, 12, last[j]);
1575 strcat(tmp,str);
1576 }
1577 strcat(tmp,"<br />");
1578 }
1579 strcpy(ptr, tmp);
1580 ptr += (int)strlen(tmp);
1581 }
1582 strcpy(tmp,"<br />");
1583 strcpy(ptr, tmp);
1584}
1585
1586void print_service_longlong(longlong *buff, int size)
1587{
1588int i,j;
1589char *ptr, str[80], tmp[256];
1590longlong last[4];
1591
1592 ptr = Service_content_str;
1593 ptr += (int)strlen(Service_content_str);
1594 for( i = 0; i < size; i++)
1595 {
1596 strcpy(tmp,"");
1597 if(i%4 == 0)
1598 {
1599 if(i != 0)
1600 {
1601 strcat(tmp,"&nbsp");
1602 }
1603 sprintf_html(str, 7, i);
1604 strcat(tmp,str);
1605 }
1606 if(!(i%4))
1607 strcat(tmp,"H: ");
1608 sprintf(str,"&nbsp&nbsp&nbsp %08X",(unsigned)buff[i]);
1609 strcat(tmp,str);
1610 last[i%4] = buff[i];
1611 if((i%4 == 3) || (i == (size-1)))
1612 {
1613 strcat(tmp,"<br />");
1614 for(j = 0; j <= (i%4); j++)
1615 {
1616 if(j == 0)
1617 strcat(tmp,"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp D: ");
1618 sprintf_html(str, 12, (int)last[j]);
1619 strcat(tmp,str);
1620 }
1621 strcat(tmp,"<br />");
1622 }
1623 strcpy(ptr, tmp);
1624 ptr += (int)strlen(tmp);
1625 }
1626 strcpy(tmp,"<br />");
1627 strcpy(ptr, tmp);
1628}
1629
1630void print_service_short(short *buff, int size)
1631{
1632int i,j;
1633char *ptr, str[80], tmp[256];
1634short last[8];
1635
1636 ptr = Service_content_str;
1637 ptr += (int)strlen(Service_content_str);
1638 for( i = 0; i < size; i++)
1639 {
1640 strcpy(tmp,"");
1641 if(i%8 == 0)
1642 {
1643 if(i != 0)
1644 {
1645 strcat(tmp,"&nbsp");
1646 }
1647 sprintf_html(str, 7, i);
1648 strcat(tmp,str);
1649 }
1650 if(!(i%8))
1651 strcat(tmp,"H: ");
1652 sprintf(str,"&nbsp %04X",buff[i]);
1653 strcat(tmp,str);
1654 last[i%8] = buff[i];
1655 if((i%8 == 7) || (i == (size-1)))
1656 {
1657 strcat(tmp,"<br />");
1658 for(j = 0; j <= (i%8); j++)
1659 {
1660 if(j == 0)
1661 strcat(tmp,"&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp D: ");
1662 sprintf_html(str, 6, last[j]);
1663 strcat(tmp,str);
1664 }
1665 strcat(tmp,"<br />");
1666 }
1667 strcpy(ptr, tmp);
1668 ptr += (int)strlen(tmp);
1669 }
1670 strcpy(tmp,"<br />");
1671 strcpy(ptr, tmp);
1672}
1673
1674void print_service_char(char *buff, int size)
1675{
1676int i,j;
1677char *asc, *ptr, str[80], tmp[256];
1678
1679 asc = (char *)buff;
1680 ptr = Service_content_str;
1681 ptr += (int)strlen(Service_content_str);
1682 for( i = 0; i < size; i++)
1683 {
1684 strcpy(tmp,"");
1685 if(i%16 == 0)
1686 {
1687 if(i != 0)
1688 {
1689 strcat(tmp,"&nbsp");
1690 }
1691 sprintf_html(str, 7, i);
1692 strcat(tmp,str);
1693 }
1694 if(!(i%16))
1695 strcat(tmp,"H: ");
1696 sprintf(str,"%02X",buff[i]);
1697/* strcat(tmp,str);
1698*/
1699 strcat(tmp," ");
1700 strcat(tmp,&str[(int)strlen(str)-2]);
1701 /*
1702 if(i%4 == 3)
1703 strcat(tmp," ");
1704 */
1705 if((i%16 == 15) || (i == (size-1)))
1706 {
1707 if(i%16 != 15)
1708 {
1709 for(j = 1; j < 16 - (i%16); j++)
1710 strcat(tmp,"&nbsp&nbsp ");
1711 }
1712 strcat(tmp,"&nbsp&nbsp&nbsp '");
1713 for(j = 0; j <= (i%16) ; j++)
1714 {
1715 if(isprint(asc[j]))
1716 {
1717 if(asc[j] == ' ')
1718 sprintf(str,"&nbsp");
1719 else if(asc[j] == '<')
1720 sprintf(str,"&lt");
1721 else if(asc[j] == '>')
1722 sprintf(str,"&gt");
1723 else if(asc[j] == '&')
1724 sprintf(str,"&amp");
1725 else
1726 sprintf(str,"%c",asc[j]);
1727 strcat(tmp,str);
1728 }
1729 else
1730 {
1731 sprintf(str,".");
1732 strcat(tmp,str);
1733 }
1734 }
1735 strcat(tmp,"'<br />");
1736 asc = (char *)&buff[i+1];
1737 }
1738 strcpy(ptr, tmp);
1739 ptr += (int)strlen(tmp);
1740 }
1741 strcpy(tmp,"<br />");
1742 strcpy(ptr, tmp);
1743}
1744
1745void print_service_float(float *buff, int size)
1746{
1747int i;
1748char *ptr, str[80], tmp[256];
1749
1750 ptr = Service_content_str;
1751 ptr += (int)strlen(Service_content_str);
1752 for( i = 0; i < size; i++)
1753 {
1754 strcpy(tmp,"");
1755 if(i%4 == 0)
1756 {
1757 if(i != 0)
1758 {
1759 strcat(tmp,"&nbsp");
1760 }
1761 sprintf_html(str, 7, i);
1762 strcat(tmp,str);
1763 }
1764 sprintf(str,"%12.3G",*(buff++));
1765 strcat(tmp,str);
1766 if((i%4 == 3) || (i == size-1))
1767 {
1768 strcat(tmp,"<br />");
1769 }
1770 strcpy(ptr, tmp);
1771 ptr += (int)strlen(tmp);
1772 }
1773 strcpy(tmp,"<br />");
1774 strcpy(ptr, tmp);
1775 ptr += (int)strlen(tmp);
1776}
1777
1778void print_service_double(double *buff, int size)
1779{
1780int i;
1781char *ptr, str[80], tmp[256];
1782
1783 ptr = Service_content_str;
1784 ptr += (int)strlen(Service_content_str);
1785 for( i = 0; i < size; i++)
1786 {
1787 strcpy(tmp,"");
1788 if(i%4 == 0)
1789 {
1790 if(i != 0)
1791 {
1792 strcat(tmp,"&nbsp");
1793 }
1794 sprintf_html(str, 7, i);
1795 strcat(tmp,str);
1796 }
1797 sprintf(str,"%12.3G",*(buff++));
1798 strcat(tmp,str);
1799 if((i%4 == 3) || (i == size-1))
1800 {
1801 strcat(tmp,"<br />");
1802 }
1803 strcpy(ptr, tmp);
1804 ptr += (int)strlen(tmp);
1805 }
1806 strcpy(tmp,"<br />");
1807 strcpy(ptr, tmp);
1808 ptr += (int)strlen(tmp);
1809}
1810
1811char *addJSONStart(char *ptr)
1812{
1813 char *ptro;
1814
1815 strcat(ptr,"{\n");
1816 ptro = ptr + (int)strlen(ptr);
1817 return ptro;
1818}
1819
1820char *addJSONEnd(char *ptr)
1821{
1822 char *ptro;
1823
1824 strcat(ptr,"}\n");
1825 ptro = ptr + (int)strlen(ptr);
1826 return ptro;
1827}
1828
1829char *addJSONNodeStart(char *ptr, char *node)
1830{
1831 char *ptro;
1832
1833 sprintf(ptr,"%s: [\n", node);
1834 ptro = ptr + (int)strlen(ptr);
1835 return ptro;
1836}
1837
1838char *addJSONNodeEnd(char *ptr)
1839{
1840 char *ptro;
1841
1842 strcat(ptr,"]\n");
1843 ptro = ptr + (int)strlen(ptr);
1844 return ptro;
1845}
1846
1847char *addJSONChildStart(char *ptr, char *child, int sep)
1848{
1849 char *ptro;
1850
1851 if(sep)
1852 sprintf(ptr,"{ %s, ", child);
1853 else
1854 sprintf(ptr,"{ %s", child);
1855 ptro = ptr + (int)strlen(ptr);
1856 return ptro;
1857}
1858
1859char *addJSONChildEnd(char *ptr, int sep)
1860{
1861 char *ptro;
1862
1863 if(sep)
1864 strcat(ptr," },\n");
1865 else
1866 strcat(ptr," }\n");
1867 ptro = ptr + (int)strlen(ptr);
1868 return ptro;
1869}
1870
1871char *getJSONBuffer(char *node, int browser)
1872{
1873 BROWSER *browserp;
1874 int prepareJSONTree();
1875
1876 if(browser)
1877 {
1878 if((browserp = find_browser(browser)))
1879 {
1880 if(browserp->pattern[0] != '\0')
1881 {
1882 prepareJSONTree(node, browserp);
1883 return(browserp->JSONBuffer);
1884 }
1885 browserp->n_services = 0;
1886 browserp->n_servers = 0;
1887 browserp->n_nodes = 0;
1888 }
1889 }
1890 prepareJSONTree(node, 0);
1891 return(JSONBuffer);
1892}
1893
1894char *getJSONSmiBuffer(char *node, int browser)
1895{
1896 BROWSER *browserp;
1897 int prepareJSONSmiTree();
1898
1899 if(!(browserp = find_browser(browser)))
1900 {
1901 browserp = create_browser(browser);
1902 browserp->isSMI = 1;
1903 strcpy(browserp->pattern,"SMI/");
1904 }
1905 if(browser)
1906 {
1907 if((browserp = find_browser(browser)))
1908 {
1909 if(browserp->pattern[0] != '\0')
1910 {
1911 prepareJSONSmiTree(node, browserp);
1912 return(browserp->JSONSmiBuffer);
1913 }
1914// browserp->n_services = 0;
1915// browserp->n_servers = 0;
1916// browserp->n_nodes = 0;
1917 }
1918 }
1919 prepareJSONSmiTree(node, 0);
1920 return(JSONSmiBuffer);
1921}
1922
1923char *getJSONDimBuffer(char *node, int browser)
1924{
1925 BROWSER *browserp;
1926 int prepareJSONDimTree();
1927
1928 if (browser)
1929 {
1930 if ((browserp = find_browser(browser)))
1931 {
1932 if (browserp->pattern[0] != '\0')
1933 {
1934 prepareJSONDimTree(node, browserp);
1935 return(browserp->JSONBuffer);
1936 }
1937 browserp->n_services = 0;
1938 browserp->n_servers = 0;
1939 browserp->n_nodes = 0;
1940 }
1941 }
1942 prepareJSONDimTree(node, 0);
1943 return(JSONBuffer);
1944}
1945
1946char *getJSONHeader(int isSMI)
1947{
1948 int prepareJSONHeader();
1949
1950 if(isSMI){}
1951 if(JSONHeader[0] == '\0')
1952 prepareJSONHeader();
1953 return(JSONHeader);
1954}
1955
1956int getNodeLabel(char *name, char *label)
1957{
1958 int i;
1959 extern int web_get_node_name();
1960
1961 web_get_node_name(name, label);
1962 for(i = 0; i < ((int)strlen(label) + 1); i++)
1963 {
1964 label[i] = (char)tolower((int)label[i]);
1965 if(label[i] == '.')
1966 {
1967 label[i] = '\0';
1968 break;
1969 }
1970 }
1971 return 1;
1972}
1973
1974int prepareJSONTree(char *node, BROWSER *browserp)
1975{
1976 char *ptr;
1977 NODE *nodep;
1978 SERVER *servp;
1979 char str[256], aux[128];
1980 int selective = 0;
1981 int n_nodes, tot_n_nodes;
1982 int n_servers, tot_n_servers;
1983 int ret, n_found = 0;
1984
1985 if(browserp)
1986 {
1987 if(browserp->pattern[0] != '\0')
1988 selective = 1;
1989 else
1990 return(0);
1991 }
1992 if(!selective)
1993 {
1994 if(JSONBufferSize == 0)
1995 {
1996 JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
1997 }
1998 else if (JSONBufferSize < N_nodes*128+N_servers*128)
1999 {
2000 free(JSONBuffer);
2001 JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2002 }
2003 ptr = JSONBuffer;
2004 }
2005 else
2006 {
2007 if(browserp->JSONBufferSize == 0)
2008 {
2009 browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2010 }
2011 else if (browserp->JSONBufferSize < N_nodes*128+N_servers*128)
2012 {
2013 free(browserp->JSONBuffer);
2014 browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2015 }
2016 ptr = browserp->JSONBuffer;
2017 }
2018 *ptr = '\0';
2019 if(!strcmp(node, "src"))
2020 {
2021 ptr = addJSONStart(ptr);
2022 ptr = addJSONNodeStart(ptr,"children");
2023 sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
2024 ptr = addJSONChildStart(ptr,str,1);
2025 ptr = addJSONNodeStart(ptr,"children");
2026 nodep = Node_head;
2027 tot_n_nodes = 0;
2028 while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
2029 {
2030 nodep->match = 1;
2031 if(selective)
2032 {
2033 if(!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers, 0)))
2034 {
2035 nodep->match = 0;
2036 continue;
2037 }
2038 else
2039 {
2040 n_found += ret;
2041 }
2042 }
2043 tot_n_nodes++;
2044 }
2045 n_nodes = 0;
2046 nodep = Node_head;
2047 while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
2048 {
2049 if(!nodep->match)
2050 continue;
2051 getNodeLabel(nodep->name, aux);
2052 sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
2053 aux, nodep->name, nodep->name);
2054 ptr = addJSONChildStart(ptr,str,0);
2055 n_nodes++;
2056if(WebDID_Debug)
2057 printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
2058 if(n_nodes < tot_n_nodes)
2059 ptr = addJSONChildEnd(ptr,1);
2060 else
2061 ptr = addJSONChildEnd(ptr,0);
2062 }
2063 ptr = addJSONNodeEnd(ptr);
2064 ptr = addJSONChildEnd(ptr,0);
2065 ptr = addJSONNodeEnd(ptr);
2066 ptr = addJSONEnd(ptr);
2067 if(selective)
2068 {
2069 browserp->n_services = n_found;
2070 browserp->n_servers = tot_n_servers;
2071 browserp->n_nodes = tot_n_nodes;
2072 }
2073 }
2074 else
2075 {
2076 if((nodep = find_node(node)))
2077 {
2078 ptr = addJSONStart(ptr);
2079 ptr = addJSONNodeStart(ptr,"children");
2080 servp = nodep->server_head;
2081 tot_n_servers = 0;
2082 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2083 {
2084 servp->match = 1;
2085 if(servp->busy != 1)
2086 {
2087 servp->match = 0;
2088 continue;
2089 }
2090 if(selective)
2091 {
2092 if(!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0, 0)))
2093 {
2094 servp->match = 0;
2095 continue;
2096 }
2097 else
2098 {
2099 n_found += ret;
2100 }
2101 }
2102 tot_n_servers++;
2103 }
2104 n_servers = 0;
2105 servp = nodep->server_head;
2106 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2107 {
2108 if(!servp->match)
2109 continue;
2110 sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\"",servp->name, servp->server.pid);
2111 ptr = addJSONChildStart(ptr,str,0);
2112 n_servers++;
2113 if(n_servers < tot_n_servers)
2114 ptr = addJSONChildEnd(ptr,1);
2115 else
2116 ptr = addJSONChildEnd(ptr,0);
2117 }
2118 ptr = addJSONNodeEnd(ptr);
2119 ptr = addJSONEnd(ptr);
2120 }
2121 }
2122 /*
2123if(!selective)
2124printf(" Nodes&Servers %s\n",JSONBuffer);
2125else
2126printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
2127 */
2128 return(1);
2129}
2130
2131int prepareJSONSmiTree(char *node, BROWSER *browserp)
2132{
2133 char *ptr;
2134 NODE *nodep;
2135 SERVER *servp;
2136 char str[256], aux[128];
2137 int selective = 0;
2138 int n_nodes, tot_n_nodes;
2139 int n_servers, tot_n_servers;
2140 int ret, n_found = 0;
2141 char pattern[256] = {'\0'};
2142 char *sptr;
2143
2144 if(browserp)
2145 {
2146 if(browserp->pattern[0] != '\0')
2147 {
2148 selective = 1;
2149 strcpy(pattern, browserp->pattern);
2150 }
2151// else
2152// return(0);
2153 }
2154// selective = 1;
2155// strcpy(pattern,"SMI/*");
2156 if(!selective)
2157 {
2158 if(JSONSmiBufferSize == 0)
2159 {
2160 JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2161 }
2162 else if (JSONSmiBufferSize < N_nodes*128+N_servers*128)
2163 {
2164 free(JSONSmiBuffer);
2165 JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2166 }
2167 ptr = JSONSmiBuffer;
2168 }
2169 else
2170 {
2171 if(browserp->JSONSmiBufferSize == 0)
2172 {
2173 browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2174 }
2175 else if (browserp->JSONSmiBufferSize < N_nodes*128+N_servers*128)
2176 {
2177 free(browserp->JSONSmiBuffer);
2178 browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
2179 }
2180 ptr = browserp->JSONSmiBuffer;
2181 }
2182 *ptr = '\0';
2183 if(!strcmp(node, "src"))
2184 {
2185 ptr = addJSONStart(ptr);
2186 ptr = addJSONNodeStart(ptr,"children");
2187 sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
2188 ptr = addJSONChildStart(ptr,str,1);
2189 ptr = addJSONNodeStart(ptr,"children");
2190 nodep = Node_head;
2191 tot_n_nodes = 0;
2192 while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
2193 {
2194 nodep->match = 1;
2195 if(selective)
2196 {
2197 if(!(ret = find_service_pattern(nodep, 0, pattern, &tot_n_servers, 0)))
2198 {
2199 nodep->match = 0;
2200 continue;
2201 }
2202 else
2203 {
2204 n_found += ret;
2205 }
2206 }
2207 tot_n_nodes++;
2208 }
2209 n_nodes = 0;
2210 nodep = Node_head;
2211 while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
2212 {
2213 if(!nodep->match)
2214 continue;
2215 getNodeLabel(nodep->name, aux);
2216 sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
2217 aux, nodep->name, nodep->name);
2218 ptr = addJSONChildStart(ptr,str,0);
2219 n_nodes++;
2220if(WebDID_Debug)
2221 printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
2222 if(n_nodes < tot_n_nodes)
2223 ptr = addJSONChildEnd(ptr,1);
2224 else
2225 ptr = addJSONChildEnd(ptr,0);
2226 }
2227 ptr = addJSONNodeEnd(ptr);
2228 ptr = addJSONChildEnd(ptr,0);
2229 ptr = addJSONNodeEnd(ptr);
2230 ptr = addJSONEnd(ptr);
2231 if(selective)
2232 {
2233 browserp->n_services = n_found;
2234 browserp->n_servers = tot_n_servers;
2235 browserp->n_nodes = tot_n_nodes;
2236 }
2237 }
2238 else
2239 {
2240 if((nodep = find_node(node)))
2241 {
2242 ptr = addJSONStart(ptr);
2243 ptr = addJSONNodeStart(ptr,"children");
2244 servp = nodep->server_head;
2245 tot_n_servers = 0;
2246 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2247 {
2248 servp->match = 1;
2249 if(servp->busy != 1)
2250 {
2251 servp->match = 0;
2252 continue;
2253 }
2254 if(selective)
2255 {
2256 if(!(ret = find_service_pattern(nodep, servp, pattern, 0, 0)))
2257 {
2258 servp->match = 0;
2259 continue;
2260 }
2261 else
2262 {
2263 n_found += ret;
2264 }
2265 }
2266 tot_n_servers++;
2267 }
2268 n_servers = 0;
2269 servp = nodep->server_head;
2270 while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
2271 {
2272 if(!servp->match)
2273 continue;
2274 strcpy(aux, servp->name);
2275 sptr = strstr(aux,"_SMI");
2276 if(sptr)
2277 *sptr = '\0';
2278 sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\", name: \"%s\"",aux, servp->server.pid, servp->name);
2279 ptr = addJSONChildStart(ptr,str,0);
2280 n_servers++;
2281 if(n_servers < tot_n_servers)
2282 ptr = addJSONChildEnd(ptr,1);
2283 else
2284 ptr = addJSONChildEnd(ptr,0);
2285 }
2286 ptr = addJSONNodeEnd(ptr);
2287 ptr = addJSONEnd(ptr);
2288 }
2289 }
2290 /*
2291if(!selective)
2292printf(" Nodes&Servers %s\n",JSONBuffer);
2293else
2294printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
2295 */
2296printf("%s\n",browserp->JSONSmiBuffer);
2297 return(1);
2298}
2299
2300int prepareJSONDimTree(char *node, BROWSER *browserp)
2301{
2302 char *ptr;
2303 NODE *nodep;
2304 SERVER *servp;
2305 char str[256];
2306 int selective = 0;
2307 int tot_n_nodes;
2308 int n_servers, tot_n_servers;
2309 int ret, n_found = 0;
2310
2311 if (browserp)
2312 {
2313 if (browserp->pattern[0] != '\0')
2314 selective = 1;
2315 else
2316 return(0);
2317 }
2318 if (!selective)
2319 {
2320 if (JSONBufferSize == 0)
2321 {
2322 JSONBuffer = malloc((size_t)(N_nodes * 128 + N_servers * 128));
2323 }
2324 else if (JSONBufferSize < N_nodes * 128 + N_servers * 128)
2325 {
2326 free(JSONBuffer);
2327 JSONBuffer = malloc((size_t)(N_nodes * 128 + N_servers * 128));
2328 }
2329 ptr = JSONBuffer;
2330 }
2331 else
2332 {
2333 if (browserp->JSONBufferSize == 0)
2334 {
2335 browserp->JSONBuffer = malloc((size_t)(N_services * (128*2)));
2336 }
2337 else if (browserp->JSONBufferSize < (N_services * (128 * 2)))
2338 {
2339 free(browserp->JSONBuffer);
2340 browserp->JSONBuffer = malloc((size_t)(N_services * (128 * 2)));
2341 }
2342 ptr = browserp->JSONBuffer;
2343 }
2344 *ptr = '\0';
2345 if (!strcmp(node, "src"))
2346 {
2347 ptr = addJSONStart(ptr);
2348 ptr = addJSONNodeStart(ptr, "services");
2349// sprintf(str, "text: \"%s\", id: \"Nodes\", expanded: false", Title);
2350// ptr = addJSONChildStart(ptr, str, 1);
2351// ptr = addJSONNodeStart(ptr, "children");
2352 nodep = Node_head;
2353 tot_n_nodes = 0;
2354 while ((nodep = (NODE *)sll_get_next((SLL *)nodep)))
2355 {
2356// nodep->match = 1;
2357 if (selective)
2358 {
2359 if (!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers, &ptr)))
2360 {
2361// nodep->match = 0;
2362 continue;
2363 }
2364 else
2365 {
2366 n_found += ret;
2367 }
2368 }
2369 tot_n_nodes++;
2370 }
2371 if(n_found)
2372 {
2373 ptr--;
2374 *(ptr-1) = ' ';
2375 }
2376 /*
2377 n_nodes = 0;
2378 nodep = Node_head;
2379 while ((nodep = (NODE *)sll_get_next((SLL *)nodep)))
2380 {
2381 if (!nodep->match)
2382 continue;
2383 getNodeLabel(nodep->name, aux);
2384 sprintf(str, "text: \"%s\", id: \"%s\", qtip: \"%s\"",
2385 aux, nodep->name, nodep->name);
2386 ptr = addJSONChildStart(ptr, str, 0);
2387 n_nodes++;
2388 if (WebDID_Debug)
2389 printf("adding %s %d %d\n", nodep->name, n_nodes, tot_n_nodes);
2390 if (n_nodes < tot_n_nodes)
2391 ptr = addJSONChildEnd(ptr, 1);
2392 else
2393 ptr = addJSONChildEnd(ptr, 0);
2394 }
2395 */
2396// ptr = addJSONNodeEnd(ptr);
2397// ptr = addJSONChildEnd(ptr, 0);
2398 ptr = addJSONNodeEnd(ptr);
2399 ptr = addJSONEnd(ptr);
2400 if (selective)
2401 {
2402 browserp->n_services = n_found;
2403 browserp->n_servers = tot_n_servers;
2404 browserp->n_nodes = tot_n_nodes;
2405 }
2406 }
2407 else
2408 {
2409 if ((nodep = find_node(node)))
2410 {
2411 ptr = addJSONStart(ptr);
2412 ptr = addJSONNodeStart(ptr, "children");
2413 servp = nodep->server_head;
2414 tot_n_servers = 0;
2415 while ((servp = (SERVER *)sll_get_next((SLL *)servp)))
2416 {
2417 servp->match = 1;
2418 if (servp->busy != 1)
2419 {
2420 servp->match = 0;
2421 continue;
2422 }
2423 if (selective)
2424 {
2425 if (!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0, 0)))
2426 {
2427 servp->match = 0;
2428 continue;
2429 }
2430 else
2431 {
2432 n_found += ret;
2433 }
2434 }
2435 tot_n_servers++;
2436 }
2437 n_servers = 0;
2438 servp = nodep->server_head;
2439 while ((servp = (SERVER *)sll_get_next((SLL *)servp)))
2440 {
2441 if (!servp->match)
2442 continue;
2443 sprintf(str, "text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\"", servp->name, servp->server.pid);
2444 ptr = addJSONChildStart(ptr, str, 0);
2445 n_servers++;
2446 if (n_servers < tot_n_servers)
2447 ptr = addJSONChildEnd(ptr, 1);
2448 else
2449 ptr = addJSONChildEnd(ptr, 0);
2450 }
2451 ptr = addJSONNodeEnd(ptr);
2452 ptr = addJSONEnd(ptr);
2453 }
2454 }
2455 /*
2456 if(!selective)
2457 printf(" Nodes&Servers %s\n",JSONBuffer);
2458 else
2459 printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
2460 */
2461 return(1);
2462}
2463
2464int prepareJSONHeader()
2465{
2466 char *ptr;
2467 char str[128];
2468
2469 ptr = JSONHeader;
2470 *ptr = '\0';
2471 ptr = addJSONStart(ptr);
2472 ptr = addJSONNodeStart(ptr,"items");
2473 sprintf(str,"text: \"%s\"",Title);
2474 ptr = addJSONChildStart(ptr,str,0);
2475 ptr = addJSONChildEnd(ptr,1);
2476 sprintf(str,"text: \"%d Servers Known - %d Services Available\"",N_servers, N_services);
2477 ptr = addJSONChildStart(ptr,str,0);
2478 ptr = addJSONChildEnd(ptr,0);
2479 ptr = addJSONNodeEnd(ptr);
2480 ptr = addJSONEnd(ptr);
2481if(WebDID_Debug)
2482printf(" Header %s\n",JSONHeader);
2483 return(1);
2484}
2485
2486char *JSONServices = 0;
2487int JSONServicesSize = 0;
2488char *prepareJSONServiceList(SERVER *servp, char *node, int pid, BROWSER *browserp)
2489{
2490 DNS_SERVICE_INFO *servicep;
2491 char *ptr;
2492 int n_services, i;
2493 char str[256], type_str[256];
2494 int selective = 0;
2495 int n_found = 0, n;
2496
2497 servicep = servp->service_ptr;
2498 n_services = servp->server.n_services;
2499 if(JSONServicesSize == 0)
2500 {
2501 JSONServicesSize = n_services*256;
2502 JSONServices = malloc((size_t)JSONServicesSize);
2503 }
2504 else if (JSONServicesSize < n_services*256)
2505 {
2506 free(JSONServices);
2507 JSONServicesSize = n_services*256;
2508 JSONServices = malloc((size_t)JSONServicesSize);
2509 }
2510 if(browserp)
2511 {
2512 if(browserp->pattern[0] != '\0')
2513 selective = 1;
2514 }
2515 n_found = n_services;
2516 if(selective)
2517 {
2518 n_found = find_server_service_pattern(servp, browserp->pattern, 0);
2519 }
2520 ptr = JSONServices;
2521 *ptr = '\0';
2522 ptr = addJSONStart(ptr);
2523 ptr = addJSONNodeStart(ptr,"children");
2524 if(selective)
2525 sprintf(str,"text: \"%s (%d/%d services, pid %d)\"",servp->name, n_found, n_services, servp->server.pid);
2526 else
2527 sprintf(str,"text: \"%s (%d services, pid %d)\"",servp->name, n_services, servp->server.pid);
2528 ptr = addJSONChildStart(ptr,str,1);
2529 ptr = addJSONNodeStart(ptr,"children");
2530 servicep = servp->service_ptr;
2531 n = 0;
2532 for(i = 0; i < n_services; i++)
2533 {
2534/*
2535printf("Service type = %d\n",servicep->type);
2536*/
2537 if((!selective) || (strstr(servicep->name, browserp->pattern)))
2538 {
2539 if(servicep->type == 1)
2540 {
2541 sprintf(type_str,"%d@%s|%s|CMD", pid, node, servicep->name);
2542 sprintf(str,"text: \"%s\", id: \"%s\", leaf: true, icon: \"leaf_cmd.gif\"",servicep->name, type_str);
2543 }
2544 else
2545 {
2546 sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
2547 sprintf(str,"text: \"%s\", id: \"%s\", leaf: true",servicep->name, type_str);
2548 }
2549 ptr = addJSONChildStart(ptr,str,0);
2550 n++;
2551 if(n < n_found)
2552 ptr = addJSONChildEnd(ptr,1);
2553 else
2554 ptr = addJSONChildEnd(ptr,0);
2555 }
2556 servicep++;
2557 }
2558 ptr = addJSONNodeEnd(ptr);
2559 ptr = addJSONChildEnd(ptr,0);
2560 ptr = addJSONNodeEnd(ptr);
2561 ptr = addJSONEnd(ptr);
2562 return JSONServices;
2563}
2564
2565char *JSONSmiServices = 0;
2566int JSONSmiServicesSize = 0;
2567
2568char *prepareJSONSmiObjectList(SERVER *servp, char *node, int pid, BROWSER *browserp)
2569{
2570 DNS_SERVICE_INFO *servicep;
2571 char *ptr;
2572 int n_services, i;
2573 char str[512], type_str[512];
2574 int selective = 0;
2575 int n_found = 0, n, mode_index;
2576 char aux[512], *sptr, state[512], *stptr;
2577 OBJSTATE *smidomainp;
2578 int findSmiServices();
2579
2580printf("prepareJSONSmiObjectList name %s\n", servp->name);
2581 servicep = servp->service_ptr;
2582 n_services = servp->server.n_services;
2583 if(JSONSmiServicesSize == 0)
2584 {
2585 JSONSmiServicesSize = n_services*512;
2586 JSONSmiServices = malloc((size_t)JSONSmiServicesSize);
2587 }
2588 else if (JSONSmiServicesSize < n_services*512)
2589 {
2590 free(JSONSmiServices);
2591 JSONSmiServicesSize = n_services*512;
2592 JSONSmiServices = malloc((size_t)JSONSmiServicesSize);
2593 }
2594 if(browserp)
2595 {
2596 if(browserp->pattern[0] != '\0')
2597 selective = 1;
2598 }
2599 n_found = n_services;
2600 /*
2601 if(selective)
2602 {
2603 n_found = find_server_service_pattern(servp, browserp->pattern);
2604 }
2605 */
2606
2607 n_found = findSmiServices(browserp, servp);
2608 smidomainp = browserp->smidomainp;
2609
2610printf("prepareJSONSmiObjectList1 name %s\n", servp->name);
2611
2612
2613 ptr = JSONSmiServices;
2614 *ptr = '\0';
2615 ptr = addJSONStart(ptr);
2616 ptr = addJSONNodeStart(ptr,"children");
2617 /*
2618 if(selective)
2619 sprintf(str,"name: \"%s (%d/%d services, pid %d)\"",servp->name, n_found, n_services, servp->server.pid);
2620 else
2621 sprintf(str,"name: \"%s (%d services, pid %d)\"",servp->name, n_services, servp->server.pid);
2622 */
2623 sprintf(str,"name: \"%s (%d objects, pid %d)\"",servp->name, n_found, servp->server.pid);
2624 ptr = addJSONChildStart(ptr,str,1);
2625 ptr = addJSONNodeStart(ptr,"children");
2626 servicep = servp->service_ptr;
2627 n = 0;
2628 for(i = 0; i < n_services; i++)
2629 {
2630/*
2631printf("Service type = %d\n",servicep->type);
2632*/
2633printf("prepareJSONSmiObjectList2 obj name %s\n", servicep->name);
2634 if((!selective) || (strstr(servicep->name, browserp->pattern)))
2635 {
2636/*
2637 if(servicep->type == 1)
2638 {
2639 sprintf(type_str,"%d@%s|%s|CMD", pid, node, servicep->name);
2640 sprintf(str,"name: \"%s\", id: \"%s\", leaf: true, icon: \"leaf_cmd.gif\"",servicep->name, type_str);
2641 }
2642 else
2643 {
2644 sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
2645 sprintf(str,"name: \"%s\", state: \"RUNNING\", id: \"%s\", leaf: true",servicep->name, type_str);
2646 }
2647*/
2648 if(servicep->status == 2)
2649 {
2650 sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
2651 strcpy(aux, servicep->name);
2652 sptr = strchr(aux,'/');
2653 if(sptr)
2654 {
2655 sptr++;
2656 sptr = strchr(sptr,'/');
2657 if(sptr)
2658 sptr++;
2659 }
2660 strcpy(state, smidomainp[i].state);
2661 stptr = strchr(state,'/');
2662 if(stptr)
2663 {
2664 *stptr = '\0';
2665 }
2666 mode_index = smidomainp[i].mode_index;
2667// sprintf(str,"name: \"%s\", state: \"%s\", id: \"%s\", leaf: true, fname: \"%s\"",sptr, state, type_str, servicep->name);
2668 sprintf(str,"name: \"%s\", state: \"%s\", mode: \"%s\",id: \"%s\", leaf: true, fname: \"%s\"",
2669 sptr, state, smidomainp[mode_index].state, type_str, servicep->name);
2670
2671 ptr = addJSONChildStart(ptr,str,0);
2672 n++;
2673 if(n < n_found)
2674 ptr = addJSONChildEnd(ptr,1);
2675 else
2676 ptr = addJSONChildEnd(ptr,0);
2677 }
2678 }
2679 servicep++;
2680 }
2681 ptr = addJSONNodeEnd(ptr);
2682 ptr = addJSONChildEnd(ptr,0);
2683 ptr = addJSONNodeEnd(ptr);
2684 ptr = addJSONEnd(ptr);
2685printf("%s\n",JSONSmiServices);
2686 return JSONSmiServices;
2687}
2688
2689void update_smi_state(OBJSTATE **tag, char *data, int *size)
2690{
2691 OBJSTATE *servicep;
2692 time_t tsecs;
2693
2694 if(*size){}
2695 servicep = *tag;
2696
2697 if(strcmp(servicep->state, data))
2698 {
2699 strcpy(servicep->state, data);
2700 tsecs = time((time_t *)0);
2701 ((BROWSER *)(servicep->browserp))->last_changed = tsecs;
2702 }
2703//printf("SMI State %s %s %08x\n", servicep->name, servicep->state, (unsigned int)servicep);
2704}
2705
2706int findSmiServices(BROWSER *browserp, SERVER *servp)
2707{
2708 DNS_SERVICE_INFO *servicep;
2709 int n_services, i, index;
2710 int n_found = 0, sid;
2711 int checkSmiObjName();
2712 int findSmiModeObj();
2713
2714 n_services = servp->server.n_services;
2715 if(strcmp(browserp->curr_smidomain,servp->name))
2716 {
2717 if(browserp->curr_smidomain[0] != '\0')
2718 {
2719// unsubscribe; free
2720 for(i = 0; i < browserp->curr_smidomain_size; i++)
2721 {
2722 if(browserp->smidomainp[i].sid)
2723 dic_release_service(browserp->smidomainp[i].sid);
2724 }
2725 free(browserp->smidomainp);
2726 browserp->curr_smidomain[0] = '\0';
2727 browserp->curr_smidomain_size = 0;
2728 }
2729 strcpy(browserp->curr_smidomain, servp->name);
2730 browserp->smidomainp = malloc(n_services * sizeof(OBJSTATE));
2731 browserp->curr_smidomain_size = n_services;
2732 }
2733 else
2734 return browserp->curr_smidomain_nobjs;
2735 servicep = servp->service_ptr;
2736 for(i = 0; i < n_services; i++)
2737 {
2738 browserp->smidomainp[i].sid = 0;
2739 browserp->smidomainp[i].state[0] = '\0';
2740 if(checkSmiObjName(servicep))
2741 {
2742 strcpy(browserp->smidomainp[i].name, servicep->name);
2743// strcpy(browserp->smidomainp[i].state, "");
2744 browserp->smidomainp[i].browserp = browserp;
2745//printf("address %s %08x\n",browserp->smidomainp[i].name, (unsigned int)&(browserp->smidomainp[i]));
2746 sid = dic_info_service(servicep->name,MONITORED,0,0,0,update_smi_state, &(browserp->smidomainp[i]),
2747 no_link_str, 5);
2748 browserp->smidomainp[i].sid = sid;
2749 if(servicep->status == 2)
2750 n_found++;
2751 }
2752 servicep++;
2753 }
2754 servicep = servp->service_ptr;
2755 for(i = 0; i < n_services; i++)
2756 {
2757 if(servicep->status == 2)
2758 {
2759 index = findSmiModeObj(servp->service_ptr, n_services, servicep->name);
2760 browserp->smidomainp[i].mode_index = index;
2761 }
2762 servicep++;
2763 }
2764 browserp->curr_smidomain_nobjs = n_found;
2765 return n_found;
2766}
2767
2768int findSmiModeObj(DNS_SERVICE_INFO *serviceptr, int n_services, char *name)
2769{
2770 int i;
2771 DNS_SERVICE_INFO *servicep;
2772 char mode_name[256], *ptr, *ptr1, *ptr2;
2773
2774 servicep = serviceptr;
2775 strcpy(mode_name, name);
2776 ptr1 = mode_name;
2777 if((ptr = strstr(mode_name,"::")))
2778 {
2779 *ptr = '\0';
2780 ptr2 = ptr1;
2781 while((ptr1 = strchr(ptr1,'/')))
2782 {
2783 ptr1++;
2784 ptr2 = ptr1;
2785 }
2786 if(strcmp(ptr2, ptr+2))
2787 *ptr = ':';
2788 }
2789 strcat(mode_name,"_FWM");
2790printf("Find SMI Mode %s %s\n",name, mode_name);
2791 for(i = 0; i < n_services; i++)
2792 {
2793 if(servicep->status == 3)
2794 {
2795 if(!strcmp(servicep->name, mode_name))
2796 {
2797printf("Find SMI Mode index %s %s %d\n",mode_name, servicep->name, i);
2798 return i;
2799 }
2800 }
2801 servicep++;
2802 }
2803 return 0;
2804}
2805
2806int checkSmiObjName(DNS_SERVICE_INFO *servicep)
2807{
2808 int ismode = 0, ret = 0;
2809 char *name;
2810 int matchString();
2811
2812 name = servicep->name;
2813 if(matchString(name,"SMI/*"))
2814 {
2815 ret = 1;
2816 if(matchString(name,"*&ALLOC*"))
2817 ret = 0;
2818 else if(matchString(name,"*/ACTIONS&PARS"))
2819 ret = 0;
2820 else if(matchString(name,"*/BUSY"))
2821 ret = 0;
2822 else if(matchString(name,"*/CMD"))
2823 ret = 0;
2824 else if(matchString(name,"*/OBJECTSET_LIST"))
2825 ret = 0;
2826 else if(matchString(name,"*/OBJECT_LIST"))
2827 ret = 0;
2828 else if(matchString(name,"*/SMI_VERSION_NUMBER"))
2829 ret = 0;
2830 else if(matchString(name,"*/SET/*"))
2831 ret = 0;
2832// If JCOP framework
2833 else if(matchString(name,"*_FWDM"))
2834 ret = 0;
2835 else if(matchString(name,"*_FWCNM"))
2836 ret = 0;
2837 else if(matchString(name,"*_FWM"))
2838 {
2839 ismode = 1;
2840 if(matchString(name,"*::*"))
2841 ret = 0;
2842 }
2843 }
2844 if(ret)
2845 {
2846 if(ismode)
2847 servicep->status = 3;
2848 else
2849 servicep->status = 2;
2850 }
2851 return ret;
2852}
2853
2854int matchString( char *wzString, char *wzPattern )
2855{
2856 switch (*wzPattern){
2857 case '\0':
2858 return !*wzString;
2859 case '*':
2860 return matchString(wzString, wzPattern+1) ||
2861 ( *wzString && matchString(wzString+1, wzPattern) );
2862 case '?':
2863 return *wzString &&
2864 matchString(wzString+1, wzPattern+1);
2865 default:
2866 return (*wzPattern == *wzString) &&
2867 matchString(wzString+1, wzPattern+1);
2868 }
2869}
2870
2871int get_type_size(char type)
2872{
2873 int size;
2874
2875 switch(type)
2876 {
2877 case 'L':
2878 case 'l':
2879 size = sizeof(long);
2880 break;
2881 case 'I':
2882 case 'i':
2883 size = sizeof(int);
2884 break;
2885 case 'S':
2886 case 's':
2887 size = sizeof(short);
2888 break;
2889 case 'F':
2890 case 'f':
2891 size = sizeof(float);
2892 break;
2893 case 'D':
2894 case 'd':
2895 size = sizeof(double);
2896 break;
2897 case 'C':
2898 case 'c':
2899 default:
2900 size = 1;
2901 }
2902 return(size);
2903}
2904
2905void did_prepare_command(char *str, char *service, char *format)
2906{
2907char type;
2908int num;
2909int size, full_size = 0;
2910char *ptr;
2911static int last_size = 0;
2912static void *last_buffer = 0;
2913void *buffer_ptr;
2914char *str_ptr;
2915void did_read_string(char, int, void **, char **);
2916
2917 str_ptr = str;
2918 ptr = format;
2919 while(*ptr)
2920 {
2921 type = *ptr++;
2922 if(*ptr == ':')
2923 {
2924 ptr++;
2925 size = get_type_size(type);
2926 sscanf(ptr, "%d", &num);
2927 full_size += size * num;
2928 if( (ptr = strchr(ptr,';')) )
2929 ptr++;
2930 else
2931 break;
2932 }
2933 }
2934
2935 full_size += 256;
2936 if(full_size > last_size)
2937 {
2938 if(last_size)
2939 free(last_buffer);
2940 last_buffer = malloc((size_t)full_size);
2941 last_size = full_size;
2942 }
2943 memset(last_buffer, 0, (size_t)last_size);
2944 buffer_ptr = last_buffer;
2945 ptr = format;
2946 while(*ptr)
2947 {
2948 type = *ptr++;
2949 if(*ptr == ':')
2950 {
2951 ptr++;
2952 sscanf(ptr, "%d", &num);
2953 did_read_string(type, num, &buffer_ptr, &str_ptr);
2954 if(!str_ptr)
2955 break;
2956 if( (ptr = strchr(ptr,';')) )
2957 ptr++;
2958 else
2959 break;
2960 }
2961 else
2962 {
2963 did_read_string(type, 0, &buffer_ptr, &str_ptr);
2964 break;
2965 }
2966 }
2967 full_size = (int) ((char *)buffer_ptr - (char *)last_buffer);
2968 dic_cmnd_service(service,last_buffer,full_size);
2969}
2970
2971int read_str_int(char *str)
2972{
2973 int i;
2974 if((str[0] == '0') && (str[1] == 'x'))
2975 sscanf(str+2,"%x",&i);
2976 else
2977 sscanf(str,"%d",&i);
2978 return(i);
2979}
2980
2981int read_str_char(char *str, char *cc)
2982{
2983 int num;
2984
2985 if(str[0] == '\'')
2986 *cc = str[1];
2987 else if(str[0] == '\"')
2988 return(0);
2989 else if((str[0] == '0') && (str[1] == 'x'))
2990 {
2991 sscanf(str+2,"%x",&num);
2992 if(num <= 0xff)
2993 *cc = (char)num;
2994 else
2995 return(-1);
2996 }
2997 else if(isalpha(str[0]))
2998 return(-1);
2999 else
3000 {
3001 sscanf(str,"%d",&num);
3002 if(num <= 0xff)
3003 *cc = (char)num;
3004 else
3005 return(-1);
3006 }
3007 return(1);
3008}
3009
3010void did_read_string(char type, int num, void **buffer_ptr, char **str_ptr)
3011{
3012int i, ret = 0;
3013float ff;
3014double dd;
3015void *ptr;
3016char *strp, *ptr1;
3017char cc;
3018 short s;
3019
3020 strp = *str_ptr;
3021 ptr = *buffer_ptr;
3022 if(!num)
3023 num = 1000000;
3024 switch(type)
3025 {
3026 case 'L':
3027 case 'l':
3028 case 'I':
3029 case 'i':
3030 for(i = 0; i<num; i++)
3031 {
3032 *(int *)ptr = read_str_int(strp);
3033 ptr = (int *)ptr +1;
3034 if( (strp = strchr(strp,' ')) )
3035 strp++;
3036 else
3037 break;
3038 }
3039 break;
3040 case 'S':
3041 case 's':
3042 for(i = 0; i<num; i++)
3043 {
3044 s = (short)read_str_int(strp);
3045 *((short *)ptr) = s;
3046 ptr = (short *)ptr +1;
3047 if( (strp = strchr(strp,' ')) )
3048 strp++;
3049 else
3050 break;
3051 }
3052 break;
3053 case 'F':
3054 case 'f':
3055 for(i = 0; i<num; i++)
3056 {
3057 sscanf(strp,"%f",&ff);
3058 *(float *)ptr = ff;
3059 ptr = (float *)ptr +1;
3060 if( (strp = strchr(strp,' ')) )
3061 strp++;
3062 else
3063 break;
3064 }
3065 break;
3066 case 'D':
3067 case 'd':
3068 for(i = 0; i<num; i++)
3069 {
3070 sscanf(strp,"%f",&ff);
3071 dd = (double)ff;
3072 *(double *)ptr = dd;
3073 ptr = (double *)ptr +1;
3074 if( (strp = strchr(strp,' ')) )
3075 strp++;
3076 else
3077 break;
3078 }
3079 break;
3080 case 'C':
3081 case 'c':
3082 default:
3083 for(i = 0; i<num; i++)
3084 {
3085 if((ret = read_str_char(strp, &cc)) <= 0)
3086 break;
3087 *(char *)ptr = cc;
3088 ptr = (char *)ptr +1;
3089 if( (strp = strchr(strp,' ')) )
3090 strp++;
3091 else
3092 break;
3093 }
3094 if(ret <= 0)
3095 {
3096 if(!ret)
3097 {
3098 strp++;
3099 }
3100 num = (int)strlen(strp)+1;
3101 strncpy((char *)ptr,strp,(size_t)num);
3102 if( (ptr1 = (char *)strchr((char *)ptr,'\"')) )
3103 {
3104 num--;
3105 *ptr1 = '\0';
3106 }
3107 ptr = (char *)ptr + num;
3108 if( (strp = strchr(strp,' ')) )
3109 strp++;
3110 else
3111 break;
3112 }
3113 }
3114 *buffer_ptr = ptr;
3115 *str_ptr = strp;
3116}
Note: See TracBrowser for help on using the repository browser.