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 |
|
---|
8 | int WebDID_Debug = 1;
|
---|
9 | int IsWebDID = 1;
|
---|
10 |
|
---|
11 | typedef 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 |
|
---|
26 | typedef 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;
|
---|
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;
|
---|
61 |
|
---|
62 | typedef 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;
|
---|
83 | SERVICE *Curr_service_head = (SERVICE *)0;
|
---|
84 |
|
---|
85 | typedef struct objstate{
|
---|
86 | char name[MAX_NAME];
|
---|
87 | char state[512];
|
---|
88 | int sid;
|
---|
89 | int mode_index;
|
---|
90 | void *browserp;
|
---|
91 | }OBJSTATE;
|
---|
92 | /*
|
---|
93 | typedef struct domainitem{
|
---|
94 | char name[MAX_NAME];
|
---|
95 | OBJSTATE objs[1];
|
---|
96 | }CURR_SMIDOMAIN;
|
---|
97 | */
|
---|
98 | typedef 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;
|
---|
129 | BROWSER *Browser_head = (BROWSER *)0;
|
---|
130 |
|
---|
131 | char *JSONBuffer = 0;
|
---|
132 | int JSONBufferSize = 0;
|
---|
133 | char JSONHeader[256] = {'\0'};
|
---|
134 | char JSONSmiHeader[256] = {'\0'};
|
---|
135 |
|
---|
136 | char *JSONSmiBuffer = 0;
|
---|
137 | int JSONSmiBufferSize = 0;
|
---|
138 |
|
---|
139 | int First_time = 1;
|
---|
140 | int Curr_view_opt = -1;
|
---|
141 | char Curr_view_opt_par[80];
|
---|
142 | char Curr_service_name[132];
|
---|
143 | char Curr_service_format[256];
|
---|
144 | int Curr_service_print_type = 0;
|
---|
145 | int N_nodes = 0;
|
---|
146 | int N_servers = 0;
|
---|
147 | int N_services = 0;
|
---|
148 | static char no_link = -1;
|
---|
149 | //static char no_link_str[5] = "DEAD";
|
---|
150 | static char no_link_str[26] = "__DIM_SERVICE_NOT_THERE__";
|
---|
151 | int no_link_int = -1;
|
---|
152 | FILE *fptr;
|
---|
153 |
|
---|
154 | char *Service_content_str;
|
---|
155 | char *Curr_service_list = 0;
|
---|
156 | char *Curr_client_list = 0;
|
---|
157 | int Curr_service_id = 0;
|
---|
158 | SERVER *Got_Service_List = 0;
|
---|
159 | SERVER *Got_Client_List = 0;
|
---|
160 |
|
---|
161 | int Timer_q;
|
---|
162 | char Title[128];
|
---|
163 |
|
---|
164 | int 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 |
|
---|
207 | SERVER *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 |
|
---|
224 | NODE *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 |
|
---|
239 | int 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, index;
|
---|
246 | char *addJSONChildStart();
|
---|
247 | char *addJSONChildEnd();
|
---|
248 | int doall = 0, doit = 0;
|
---|
249 |
|
---|
250 | servicep = servp->service_ptr;
|
---|
251 | n_services = servp->server.n_services;
|
---|
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)
|
---|
275 | {
|
---|
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 | }
|
---|
306 | }
|
---|
307 | servicep++;
|
---|
308 | }
|
---|
309 | return(n_found);
|
---|
310 | }
|
---|
311 |
|
---|
312 | int find_service_pattern(NODE *nodep, SERVER *servpp, char *pattern, int *n_servers, char **ptr)
|
---|
313 | {
|
---|
314 | SERVER *servp;
|
---|
315 | int ret, n_found = 0;
|
---|
316 | int n_servers_found = 0;
|
---|
317 |
|
---|
318 | if(!servpp)
|
---|
319 | {
|
---|
320 | servp = nodep->server_head;
|
---|
321 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
322 | {
|
---|
323 | if((ret = find_server_service_pattern(servp, pattern, ptr)))
|
---|
324 | {
|
---|
325 | n_found += ret;
|
---|
326 | n_servers_found++;
|
---|
327 | }
|
---|
328 | }
|
---|
329 | }
|
---|
330 | else
|
---|
331 | {
|
---|
332 | if((ret = find_server_service_pattern(servpp, pattern, ptr)))
|
---|
333 | {
|
---|
334 | n_found += ret;
|
---|
335 | }
|
---|
336 | }
|
---|
337 | if(n_servers != 0)
|
---|
338 | *n_servers = n_servers_found;
|
---|
339 | return(n_found);
|
---|
340 | }
|
---|
341 |
|
---|
342 | SERVICE *find_curr_service(char *service)
|
---|
343 | {
|
---|
344 | SERVICE *servicep;
|
---|
345 |
|
---|
346 | servicep = Curr_service_head ;
|
---|
347 | while( (servicep = (SERVICE *)sll_get_next((SLL *)servicep)) )
|
---|
348 | {
|
---|
349 | if(!strcmp(servicep->name,service))
|
---|
350 | {
|
---|
351 | return(servicep);
|
---|
352 | }
|
---|
353 | }
|
---|
354 | return ((SERVICE *)0);
|
---|
355 | }
|
---|
356 |
|
---|
357 | BROWSER *find_browser(int id)
|
---|
358 | {
|
---|
359 | BROWSER *browserp;
|
---|
360 |
|
---|
361 | browserp = Browser_head;
|
---|
362 | while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
|
---|
363 | {
|
---|
364 | if(browserp->id == id)
|
---|
365 | {
|
---|
366 | return(browserp);
|
---|
367 | }
|
---|
368 | }
|
---|
369 | return ((BROWSER *)0);
|
---|
370 | }
|
---|
371 | /*
|
---|
372 | void set_browser_changes(int n_services, int n_servers, int n_nodes)
|
---|
373 | {
|
---|
374 | BROWSER *browserp;
|
---|
375 |
|
---|
376 | browserp = Browser_head;
|
---|
377 | while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
|
---|
378 | {
|
---|
379 | if(browserp->n_services != n_services)
|
---|
380 | browserp->n_services_changed = 1;
|
---|
381 | if(browserp->n_servers != n_servers)
|
---|
382 | browserp->n_servers_changed = 1;
|
---|
383 | if(browserp->n_nodes != n_nodes)
|
---|
384 | browserp->n_nodes_changed = 1;
|
---|
385 | }
|
---|
386 | }
|
---|
387 | */
|
---|
388 | void prepare_browser_tree()
|
---|
389 | {
|
---|
390 | BROWSER *browserp;
|
---|
391 | int prepareJSONTree(char *, BROWSER *);
|
---|
392 |
|
---|
393 | browserp = Browser_head;
|
---|
394 | while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
|
---|
395 | {
|
---|
396 | if(browserp->pattern[0] != '\0')
|
---|
397 | prepareJSONTree("",browserp);
|
---|
398 | }
|
---|
399 | }
|
---|
400 | /*
|
---|
401 | void clear_browser_changes(BROWSER *browserp)
|
---|
402 | {
|
---|
403 | browserp->n_services_changed = 0;
|
---|
404 | browserp->n_servers_changed = 0;
|
---|
405 | browserp->n_nodes_changed = 0;
|
---|
406 | }
|
---|
407 | */
|
---|
408 | void update_servers(int *tag, DNS_DID *buffer, int *size)
|
---|
409 | {
|
---|
410 | int n_services, service_size;
|
---|
411 | SERVER *servp;
|
---|
412 | NODE *nodep;
|
---|
413 | int j;
|
---|
414 | char str[MAX_NAME], sname[MAX_NAME], *ptr;
|
---|
415 | int prepareJSONTree();
|
---|
416 | int prepareJSONHeader();
|
---|
417 | void got_update_services();
|
---|
418 |
|
---|
419 | if(tag){}
|
---|
420 | if(!Node_head)
|
---|
421 | {
|
---|
422 | Node_head = (NODE *)malloc(sizeof(NODE));
|
---|
423 | sll_init((SLL *)Node_head);
|
---|
424 | }
|
---|
425 | if(First_time)
|
---|
426 | {
|
---|
427 | First_time = 0;
|
---|
428 | }
|
---|
429 |
|
---|
430 | if(!*size)
|
---|
431 | return;
|
---|
432 | if(*(char *)buffer == -1)
|
---|
433 | {
|
---|
434 | N_servers = 0;
|
---|
435 | N_services = 0;
|
---|
436 | return;
|
---|
437 | }
|
---|
438 | buffer->server.n_services = vtohl(buffer->server.n_services);
|
---|
439 | buffer->server.pid = vtohl(buffer->server.pid);
|
---|
440 | n_services = buffer->server.n_services;
|
---|
441 |
|
---|
442 | if(n_services == 1)
|
---|
443 | return;
|
---|
444 | strcpy(sname, buffer->server.task);
|
---|
445 | if(n_services > 1)
|
---|
446 | {
|
---|
447 | for(j = 0; j < n_services; j++)
|
---|
448 | {
|
---|
449 | buffer->services[j].type = vtohl(
|
---|
450 | buffer->services[j].type);
|
---|
451 | buffer->services[j].status = vtohl(
|
---|
452 | buffer->services[j].status);
|
---|
453 | buffer->services[j].n_clients = vtohl(
|
---|
454 | buffer->services[j].n_clients);
|
---|
455 | if((int)strlen(sname) == MAX_TASK_NAME-4-1)
|
---|
456 | {
|
---|
457 | strcpy(str,buffer->services[j].name);
|
---|
458 | if( (ptr = strstr(str,"/CLIENT_LIST")) )
|
---|
459 | {
|
---|
460 | *ptr = '\0';
|
---|
461 | strcpy(sname,str);
|
---|
462 | }
|
---|
463 | }
|
---|
464 | }
|
---|
465 | }
|
---|
466 | if (!(nodep = find_node(buffer->server.node)))
|
---|
467 | {
|
---|
468 | if(n_services)
|
---|
469 | {
|
---|
470 | N_nodes++;
|
---|
471 | nodep = (NODE *)malloc(sizeof(NODE));
|
---|
472 | strcpy(nodep->name,buffer->server.node);
|
---|
473 | nodep->hasSMI = 0;
|
---|
474 | nodep->server_head = (SERVER *)malloc(sizeof(SERVER));
|
---|
475 | sll_init((SLL *)nodep->server_head);
|
---|
476 | sll_insert_queue((SLL *)Node_head,(SLL *)nodep);
|
---|
477 | }
|
---|
478 | }
|
---|
479 | if (!(servp = find_server(nodep,buffer->server.pid)))
|
---|
480 | {
|
---|
481 | if(n_services)
|
---|
482 | {
|
---|
483 | servp = (SERVER *)malloc(sizeof(SERVER));
|
---|
484 | strcpy(servp->name,sname);
|
---|
485 | servp->next = 0;
|
---|
486 | servp->id = 0;
|
---|
487 | servp->busy = 0;
|
---|
488 | servp->server.n_services = 0;
|
---|
489 | servp->service_ptr = 0;
|
---|
490 | servp->service_format_ptr = 0;
|
---|
491 | servp->service_format_ptrp = 0;
|
---|
492 | servp->isSMI = 0;
|
---|
493 | if(strstr(sname,"_SMI"))
|
---|
494 | {
|
---|
495 | servp->isSMI = 1;
|
---|
496 | nodep->hasSMI = 1;
|
---|
497 | }
|
---|
498 | sll_insert_queue((SLL *)nodep->server_head,(SLL *)servp);
|
---|
499 | }
|
---|
500 | }
|
---|
501 | if(n_services != 0)
|
---|
502 | {
|
---|
503 | if(n_services == servp->server.n_services)
|
---|
504 | {
|
---|
505 | return;
|
---|
506 | }
|
---|
507 | if(servp->server.n_services == 0)
|
---|
508 | N_servers++;
|
---|
509 | if(servp->server.n_services != -1)
|
---|
510 | N_services -= servp->server.n_services;
|
---|
511 | memcpy(&servp->server,&buffer->server,sizeof(DNS_SERVER_INFO));
|
---|
512 | if(servp->service_ptr)
|
---|
513 | {
|
---|
514 | free(servp->service_ptr);
|
---|
515 | servp->service_ptr = 0;
|
---|
516 | }
|
---|
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)
|
---|
528 | {
|
---|
529 | service_size = n_services*(int)sizeof(DNS_SERVICE_INFO);
|
---|
530 | servp->service_ptr = (DNS_SERVICE_INFO *)malloc((size_t)service_size);
|
---|
531 | memcpy(servp->service_ptr, buffer->services, (size_t)service_size);
|
---|
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);
|
---|
537 | }
|
---|
538 | servp->busy = 1;
|
---|
539 | }
|
---|
540 | else
|
---|
541 | {
|
---|
542 | if(servp)
|
---|
543 | {
|
---|
544 | N_servers--;
|
---|
545 | if(servp->server.n_services != -1)
|
---|
546 | {
|
---|
547 | N_services -= servp->server.n_services;
|
---|
548 | }
|
---|
549 | servp->server.n_services = 0;
|
---|
550 | servp->busy = -1;
|
---|
551 | servp->isSMI = 0;
|
---|
552 | }
|
---|
553 | }
|
---|
554 | if(JSONHeader[0])
|
---|
555 | prepareJSONHeader();
|
---|
556 | // printf("update_servers %d %d %d\n", N_nodes, N_servers, N_services);
|
---|
557 | }
|
---|
558 |
|
---|
559 | void got_update_services(BROWSER **tag, char *buffer, int *size)
|
---|
560 | {
|
---|
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;
|
---|
566 |
|
---|
567 | if(size){}
|
---|
568 | browserp = (BROWSER *)*tag;
|
---|
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);
|
---|
689 | }
|
---|
690 |
|
---|
691 | char *update_services(char *node, char *server, int pid, int browser)
|
---|
692 | {
|
---|
693 | char str[MAX_NAME];
|
---|
694 | NODE *nodep;
|
---|
695 | SERVER *servp;
|
---|
696 | char *ptr = 0;
|
---|
697 | BROWSER *browserp;
|
---|
698 | char *prepareJSONServiceList();
|
---|
699 | BROWSER *create_browser(int);
|
---|
700 |
|
---|
701 | if(!(browserp = find_browser(browser)))
|
---|
702 | browserp = create_browser(browser);
|
---|
703 |
|
---|
704 | if(server){}
|
---|
705 | sprintf(str,"%s/SERVICE_LIST",server);
|
---|
706 | dic_info_service(str,ONCE_ONLY,20,0,0,
|
---|
707 | got_update_services,(dim_long)browserp,"None",5);
|
---|
708 | if((nodep = find_node(node)))
|
---|
709 | {
|
---|
710 | if((servp = find_server(nodep, pid)))
|
---|
711 | {
|
---|
712 | ptr = prepareJSONServiceList(servp, node, pid, browserp);
|
---|
713 | }
|
---|
714 | }
|
---|
715 | return ptr;
|
---|
716 | }
|
---|
717 |
|
---|
718 | void got_update_smi_objects(BROWSER **tag, char *buffer, int *size)
|
---|
719 | {
|
---|
720 | BROWSER *browserp;
|
---|
721 |
|
---|
722 | if(size){}
|
---|
723 | browserp = (BROWSER *)*tag;
|
---|
724 | if(browserp->service_format_ptr)
|
---|
725 | free(browserp->service_format_ptr);
|
---|
726 | browserp->service_format_ptr = (char *)malloc(strlen(buffer)+1);
|
---|
727 | strcpy(browserp->service_format_ptr, buffer);
|
---|
728 | }
|
---|
729 |
|
---|
730 | char *update_smi_objects(char *node, char *server, int pid, int browser)
|
---|
731 | {
|
---|
732 | char str[MAX_NAME];
|
---|
733 | NODE *nodep;
|
---|
734 | SERVER *servp;
|
---|
735 | char *ptr = 0;
|
---|
736 | BROWSER *browserp;
|
---|
737 | char *prepareJSONSmiObjectList();
|
---|
738 | BROWSER *create_browser();
|
---|
739 |
|
---|
740 | if(!(browserp = find_browser(browser)))
|
---|
741 | {
|
---|
742 | browserp = create_browser(browser);
|
---|
743 | browserp->isSMI = 1;
|
---|
744 | }
|
---|
745 | if(server){}
|
---|
746 | sprintf(str,"%s/SERVICE_LIST",server);
|
---|
747 | dic_info_service(str,ONCE_ONLY,20,0,0,
|
---|
748 | got_update_smi_objects,(dim_long)browserp,"None",5);
|
---|
749 | if((nodep = find_node(node)))
|
---|
750 | {
|
---|
751 | if((servp = find_server(nodep, pid)))
|
---|
752 | {
|
---|
753 | ptr = prepareJSONSmiObjectList(servp, node, pid, browserp);
|
---|
754 | }
|
---|
755 | }
|
---|
756 | return ptr;
|
---|
757 | }
|
---|
758 |
|
---|
759 | void get_curr_service_format()
|
---|
760 | {
|
---|
761 | char *format;
|
---|
762 | char *dic_get_format();
|
---|
763 | /*
|
---|
764 | char str[256], *ptr, *ptr1;
|
---|
765 | int rpc_flag;
|
---|
766 |
|
---|
767 | strcpy(str,Curr_service_name);
|
---|
768 | rpc_flag = 0;
|
---|
769 | if( (ptr = strstr(str,"/RpcIn")) )
|
---|
770 | {
|
---|
771 | *ptr = '\0';
|
---|
772 | rpc_flag = 1;
|
---|
773 | }
|
---|
774 | if( (ptr = strstr(str,"/RpcOut")) )
|
---|
775 | {
|
---|
776 | *ptr = '\0';
|
---|
777 | rpc_flag = 2;
|
---|
778 | }
|
---|
779 | strcat(str,"|");
|
---|
780 | */
|
---|
781 | format = dic_get_format(0);
|
---|
782 | /*
|
---|
783 | if( (ptr = strstr(Curr_service_list,str)) )
|
---|
784 | {
|
---|
785 | if(!rpc_flag)
|
---|
786 | {
|
---|
787 | ptr += (int)strlen(str);
|
---|
788 | ptr1 = strchr(ptr,'|');
|
---|
789 | }
|
---|
790 | else if(rpc_flag == 1)
|
---|
791 | {
|
---|
792 | ptr += (int)strlen(str);
|
---|
793 | ptr1 = strchr(ptr,',');
|
---|
794 | }
|
---|
795 | else
|
---|
796 | {
|
---|
797 | ptr += (int)strlen(str);
|
---|
798 | ptr = strchr(ptr,',');
|
---|
799 | ptr++;
|
---|
800 | ptr1 = strchr(ptr,'|');
|
---|
801 | }
|
---|
802 | strncpy(Curr_service_format,ptr,(int)(ptr1 - ptr));
|
---|
803 | Curr_service_format[(int)(ptr1-ptr)] = '\0';
|
---|
804 | }
|
---|
805 | */
|
---|
806 | if(format)
|
---|
807 | strcpy(Curr_service_format,format);
|
---|
808 | else
|
---|
809 | Curr_service_format[0] = '\0';
|
---|
810 | }
|
---|
811 |
|
---|
812 | void get_service_format(char *buffer, char *service, char *format)
|
---|
813 | {
|
---|
814 | char str[256], *ptr, *ptr1;
|
---|
815 | int rpc_flag;
|
---|
816 |
|
---|
817 | strcpy(str, service);
|
---|
818 | rpc_flag = 0;
|
---|
819 | *format = '\0';
|
---|
820 | if( (ptr = strstr(str,"/RpcIn")) )
|
---|
821 | {
|
---|
822 | *ptr = '\0';
|
---|
823 | rpc_flag = 1;
|
---|
824 | }
|
---|
825 | if( (ptr = strstr(str,"/RpcOut")) )
|
---|
826 | {
|
---|
827 | *ptr = '\0';
|
---|
828 | rpc_flag = 2;
|
---|
829 | }
|
---|
830 | strcat(str,"|");
|
---|
831 | if( (ptr = strstr(buffer, str)) )
|
---|
832 | {
|
---|
833 | if(!rpc_flag)
|
---|
834 | {
|
---|
835 | ptr += (int)strlen(str);
|
---|
836 | ptr1 = strchr(ptr,'|');
|
---|
837 | }
|
---|
838 | else if(rpc_flag == 1)
|
---|
839 | {
|
---|
840 | ptr += (int)strlen(str);
|
---|
841 | ptr1 = strchr(ptr,',');
|
---|
842 | }
|
---|
843 | else
|
---|
844 | {
|
---|
845 | ptr += (int)strlen(str);
|
---|
846 | ptr = strchr(ptr,',');
|
---|
847 | ptr++;
|
---|
848 | ptr1 = strchr(ptr,'|');
|
---|
849 | }
|
---|
850 | strncpy(format,ptr,(size_t)(ptr1 - ptr));
|
---|
851 | format[(int)(ptr1-ptr)] = '\0';
|
---|
852 | }
|
---|
853 | }
|
---|
854 |
|
---|
855 | int delete_curr_service(SERVICE *servicep)
|
---|
856 | {
|
---|
857 |
|
---|
858 | if(WebDID_Debug)
|
---|
859 | printf("\nUnsubscribing %s\n\n",servicep->name);
|
---|
860 | dic_release_service(servicep->sid);
|
---|
861 | if(servicep->buffer_size)
|
---|
862 | free(servicep->buffer);
|
---|
863 | if(servicep->buffer_str_size)
|
---|
864 | free(servicep->buffer_str);
|
---|
865 | // if (servicep->nolink)
|
---|
866 | // free(servicep->nolink);
|
---|
867 | sll_remove((SLL *)Curr_service_head, (SLL *)servicep);
|
---|
868 | free(servicep);
|
---|
869 | return(1);
|
---|
870 | }
|
---|
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 | }
|
---|
880 | int delete_browser(BROWSER *browserp)
|
---|
881 | {
|
---|
882 | SERVICE *servicep;
|
---|
883 | int i;
|
---|
884 |
|
---|
885 | release_all_requests(browserp);
|
---|
886 | if (browserp->requestp_head)
|
---|
887 | free(browserp->requestp_head);
|
---|
888 | /*
|
---|
889 | if((servicep = browserp->servicep))
|
---|
890 | {
|
---|
891 | servicep->n_browsers--;
|
---|
892 | if(!servicep->n_browsers)
|
---|
893 | delete_curr_service(servicep);
|
---|
894 | }
|
---|
895 | */
|
---|
896 | if(browserp->service_format_ptr)
|
---|
897 | free(browserp->service_format_ptr);
|
---|
898 | sll_remove((SLL *)Browser_head, (SLL *)browserp);
|
---|
899 | free(browserp);
|
---|
900 | return(1);
|
---|
901 | }
|
---|
902 |
|
---|
903 | void check_browser( BROWSER *tag)
|
---|
904 | {
|
---|
905 | BROWSER *browserp;
|
---|
906 | time_t tsecs;
|
---|
907 |
|
---|
908 | browserp = (BROWSER *)tag;
|
---|
909 | if(WebDID_Debug)
|
---|
910 | printf("\nCheck_browser %d\n",browserp->id);
|
---|
911 | tsecs = time((time_t *)0);
|
---|
912 | if((tsecs - browserp->last_polled) > 20)
|
---|
913 | {
|
---|
914 | if(WebDID_Debug)
|
---|
915 | printf("\nDeleting browser %d\n\n",browserp->id);
|
---|
916 | delete_browser(browserp);
|
---|
917 | }
|
---|
918 | else
|
---|
919 | dtq_start_timer(10, check_browser, browserp);
|
---|
920 | }
|
---|
921 |
|
---|
922 | BROWSER *create_browser(int id)
|
---|
923 | {
|
---|
924 | BROWSER *browserp;
|
---|
925 |
|
---|
926 | if(!Browser_head)
|
---|
927 | {
|
---|
928 | Browser_head = (BROWSER *)malloc(sizeof(BROWSER));
|
---|
929 | sll_init((SLL *)Browser_head);
|
---|
930 | }
|
---|
931 | browserp = (BROWSER *)malloc(sizeof(BROWSER));
|
---|
932 | browserp->id = id;
|
---|
933 | browserp->last_subscribed = 0;
|
---|
934 | browserp->last_updated = 0;
|
---|
935 | browserp->last_polled = 0;
|
---|
936 | browserp->last_changed = 0;
|
---|
937 | browserp->n_nodes = 0;
|
---|
938 | browserp->n_servers = 0;
|
---|
939 | browserp->n_services = 0;
|
---|
940 | // browserp->servicep = 0;
|
---|
941 | browserp->JSONBuffer = 0;
|
---|
942 | browserp->JSONBufferSize = 0;
|
---|
943 | browserp->JSONSmiBuffer = 0;
|
---|
944 | browserp->JSONSmiBufferSize = 0;
|
---|
945 | browserp->pattern[0] = '\0';
|
---|
946 | browserp->service_format_ptr = 0;
|
---|
947 | browserp->curr_command[0] = '\0';
|
---|
948 | browserp->curr_smidomain[0] = '\0';
|
---|
949 | browserp->smidomainp = 0;
|
---|
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);
|
---|
955 | return browserp;
|
---|
956 | }
|
---|
957 |
|
---|
958 | int update_command_data(char *service, int conn_id, BROWSER *browserp)
|
---|
959 | {
|
---|
960 | char format[MAX_NAME];
|
---|
961 | char answer[MAX_NAME*3];
|
---|
962 | extern void sendData();
|
---|
963 |
|
---|
964 | if(browserp->service_format_ptr)
|
---|
965 | {
|
---|
966 | get_service_format(browserp->service_format_ptr, service, format);
|
---|
967 | if(WebDID_Debug)
|
---|
968 | printf("CMD data %s %s\n",service,format);
|
---|
969 | }
|
---|
970 | else
|
---|
971 | {
|
---|
972 | strcpy(format,"?");
|
---|
973 | }
|
---|
974 | strcpy(browserp->curr_command, service);
|
---|
975 | sprintf(answer,"To %s (%s)",service, format);
|
---|
976 | sendData(conn_id, answer, 4);
|
---|
977 | return 1;
|
---|
978 | }
|
---|
979 |
|
---|
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;
|
---|
1091 | time_t tsecs;
|
---|
1092 | void recv_service_info();
|
---|
1093 | extern void sendData();
|
---|
1094 | BROWSER *browserp;
|
---|
1095 | int i;
|
---|
1096 | REQUEST *reqp;
|
---|
1097 | REQUEST_PTR *reqpp;
|
---|
1098 |
|
---|
1099 | if(req){}
|
---|
1100 | if(!Curr_service_head)
|
---|
1101 | {
|
---|
1102 | Curr_service_head = (SERVICE *)malloc(sizeof(SERVICE));
|
---|
1103 | sll_init((SLL *)Curr_service_head);
|
---|
1104 | }
|
---|
1105 | if(!(browserp = find_browser(browser)))
|
---|
1106 | browserp = create_browser(browser);
|
---|
1107 | if(force == -1)
|
---|
1108 | {
|
---|
1109 | update_command_data(service, conn_id, browserp);
|
---|
1110 | return 1;
|
---|
1111 | }
|
---|
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;
|
---|
1134 | }
|
---|
1135 | if(!(servicep = find_curr_service(service)))
|
---|
1136 | {
|
---|
1137 | servicep = (SERVICE *)malloc(sizeof(SERVICE));
|
---|
1138 | strcpy(servicep->name,service);
|
---|
1139 | servicep->conn_id = conn_id;
|
---|
1140 | servicep->buffer = 0;
|
---|
1141 | servicep->buffer_size = 0;
|
---|
1142 | servicep->size = 0;
|
---|
1143 | servicep->buffer_str = 0;
|
---|
1144 | servicep->buffer_str_size = 0;
|
---|
1145 | servicep->str_size = 0;
|
---|
1146 | servicep->last_updated = 0;
|
---|
1147 | tsecs = time((time_t *)0);
|
---|
1148 | browserp->last_subscribed = tsecs;
|
---|
1149 | browserp->last_updated = tsecs;
|
---|
1150 | servicep->last_subscribed = tsecs;
|
---|
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);
|
---|
1158 | sll_insert_queue((SLL *)Curr_service_head,(SLL *)servicep);
|
---|
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));
|
---|
1161 | }
|
---|
1162 | else
|
---|
1163 | {
|
---|
1164 | if(servicep->size)
|
---|
1165 | {
|
---|
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 | }
|
---|
1180 | }
|
---|
1181 | else
|
---|
1182 | {
|
---|
1183 | sendData(conn_id, "", 4);
|
---|
1184 | }
|
---|
1185 | browserp->last_updated = servicep->timestamp;
|
---|
1186 | }
|
---|
1187 | }
|
---|
1188 | if(force)
|
---|
1189 | {
|
---|
1190 | // browserp->servicep = servicep;
|
---|
1191 | servicep->n_browsers++;
|
---|
1192 | }
|
---|
1193 | return 1;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | int check_browser_changes(char *service, int conn_id, int subscribe, int req, int browser, int force)
|
---|
1197 | {
|
---|
1198 | SERVICE *servicep;
|
---|
1199 | time_t tsecs;
|
---|
1200 | void recv_service_info();
|
---|
1201 | extern void sendData();
|
---|
1202 | BROWSER *browserp;
|
---|
1203 | char answer[256];
|
---|
1204 | int service_changed = 0;
|
---|
1205 |
|
---|
1206 | if(req){}
|
---|
1207 | if(subscribe){}
|
---|
1208 | if(!(browserp = find_browser(browser)))
|
---|
1209 | browserp = create_browser(browser);
|
---|
1210 | if(!Curr_service_head)
|
---|
1211 | {
|
---|
1212 | Curr_service_head = (SERVICE *)malloc(sizeof(SERVICE));
|
---|
1213 | sll_init((SLL *)Curr_service_head);
|
---|
1214 | }
|
---|
1215 | if(service[0] != '\0')
|
---|
1216 | {
|
---|
1217 | if((servicep = find_curr_service(service)))
|
---|
1218 | {
|
---|
1219 | if(servicep->size)
|
---|
1220 | {
|
---|
1221 | if((servicep->timestamp > browserp->last_updated) || (force))
|
---|
1222 | {
|
---|
1223 | service_changed = 1;
|
---|
1224 | }
|
---|
1225 | }
|
---|
1226 | }
|
---|
1227 | }
|
---|
1228 | if(browserp->isSMI)
|
---|
1229 | {
|
---|
1230 | if((browserp->last_changed >= browserp->last_polled) || (force))
|
---|
1231 | {
|
---|
1232 | service_changed = 1;
|
---|
1233 | }
|
---|
1234 | }
|
---|
1235 | /*
|
---|
1236 | sprintf(answer,"%d %d %d %d\n",
|
---|
1237 | browserp->n_services_changed, browserp->n_servers_changed,
|
---|
1238 | browserp->n_nodes_changed, service_changed);
|
---|
1239 | */
|
---|
1240 | sprintf(answer,"%d %d %d %d %d %d %d\n",
|
---|
1241 | N_services, N_servers, N_nodes, service_changed,
|
---|
1242 | browserp->n_services, browserp->n_servers, browserp->n_nodes);
|
---|
1243 | sendData(conn_id, answer, 4);
|
---|
1244 | tsecs = time((time_t *)0);
|
---|
1245 | browserp->last_polled = tsecs;
|
---|
1246 | return 1;
|
---|
1247 | }
|
---|
1248 |
|
---|
1249 | int find_services(char *pattern, int conn_id, int browser, int force)
|
---|
1250 | {
|
---|
1251 | void recv_service_info();
|
---|
1252 | extern void sendData();
|
---|
1253 | BROWSER *browserp;
|
---|
1254 | char format[MAX_NAME];
|
---|
1255 | int prepareJSONTree();
|
---|
1256 | void did_prepare_command();
|
---|
1257 |
|
---|
1258 | if(conn_id){}
|
---|
1259 | if(!(browserp = find_browser(browser)))
|
---|
1260 | browserp = create_browser(browser);
|
---|
1261 | if(force == -1)
|
---|
1262 | {
|
---|
1263 | if(browserp->service_format_ptr)
|
---|
1264 | {
|
---|
1265 | get_service_format(browserp->service_format_ptr, browserp->curr_command, format);
|
---|
1266 | did_prepare_command(pattern, browserp->curr_command, format);
|
---|
1267 | }
|
---|
1268 | return 1;
|
---|
1269 | }
|
---|
1270 | if(conn_id){}
|
---|
1271 | if(!(browserp = find_browser(browser)))
|
---|
1272 | browserp = create_browser(browser);
|
---|
1273 | strcpy(browserp->pattern, pattern);
|
---|
1274 | return 1;
|
---|
1275 | }
|
---|
1276 |
|
---|
1277 | void recv_service_info(void **tag, int *buffer, int *size)
|
---|
1278 | {
|
---|
1279 | int conn_id;
|
---|
1280 | void print_service_formatted();
|
---|
1281 | extern void sendData();
|
---|
1282 | SERVICE *servicep;
|
---|
1283 | time_t tsecs;
|
---|
1284 | REQUEST *reqp, *auxp;
|
---|
1285 |
|
---|
1286 | servicep = *tag;
|
---|
1287 | conn_id = servicep->conn_id;
|
---|
1288 | if (servicep->buffer_size < *size)
|
---|
1289 | {
|
---|
1290 | if(servicep->buffer_size)
|
---|
1291 | free(servicep->buffer);
|
---|
1292 | servicep->buffer = malloc((size_t)*size);
|
---|
1293 | servicep->buffer_size = *size;
|
---|
1294 | }
|
---|
1295 | memcpy(servicep->buffer, (char *)buffer, (size_t)*size);
|
---|
1296 | servicep->size = *size;
|
---|
1297 | if (servicep->buffer_str_size < (1024 + (*size)*16))
|
---|
1298 | {
|
---|
1299 | if(servicep->buffer_str_size)
|
---|
1300 | free(servicep->buffer_str);
|
---|
1301 | servicep->buffer_str = malloc((size_t)(1024 + (*size)*16));
|
---|
1302 | servicep->buffer_str_size = 1024 + (*size)*16;
|
---|
1303 | }
|
---|
1304 | Service_content_str = servicep->buffer_str;
|
---|
1305 | strcpy(Curr_service_name, servicep->name);
|
---|
1306 | get_curr_service_format();
|
---|
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;
|
---|
1313 | sprintf(Service_content_str,
|
---|
1314 | "Service %s Not Available", Curr_service_name);
|
---|
1315 | }
|
---|
1316 | else
|
---|
1317 | {
|
---|
1318 | print_service_formatted(servicep, buffer, *size);
|
---|
1319 | }
|
---|
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 | {
|
---|
1337 | tsecs = time((time_t *)0);
|
---|
1338 | servicep->last_updated = tsecs;
|
---|
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)
|
---|
1370 | {
|
---|
1371 | char type;
|
---|
1372 | int num, ret;
|
---|
1373 | char str[256];
|
---|
1374 | char *ptr;
|
---|
1375 | void *buffer_ptr;
|
---|
1376 | char timestr[256], aux[64], sizestr[64];
|
---|
1377 | int quality = 0, secs = 0, mili = 0;
|
---|
1378 | int did_write_string(char, int, void **, int);
|
---|
1379 | time_t tsecs;
|
---|
1380 |
|
---|
1381 | if(size < 1024)
|
---|
1382 | sprintf(sizestr,"%d bytes",size);
|
---|
1383 | else if (size < 1024*1024)
|
---|
1384 | sprintf(sizestr,"%2.2f Kb",(float)size/1024);
|
---|
1385 | else
|
---|
1386 | sprintf(sizestr,"%2.2f Mb",(float)size/(1024*1024));
|
---|
1387 |
|
---|
1388 | sprintf(Service_content_str,
|
---|
1389 | "<FONT FACE=\"consolas\">Service %s (%s) Contents :<br /> <br />", Curr_service_name,
|
---|
1390 | Curr_service_format);
|
---|
1391 | dic_get_timestamp(0, &secs, &mili);
|
---|
1392 | quality = dic_get_quality(0);
|
---|
1393 | tsecs = secs;
|
---|
1394 | servicep->timestamp = tsecs;
|
---|
1395 | my_ctime(&tsecs, timestr, 128);
|
---|
1396 | ptr = strrchr(timestr,' ');
|
---|
1397 | strcpy(aux, ptr);
|
---|
1398 | sprintf(ptr,".%03d",mili);
|
---|
1399 | strcat(timestr, aux);
|
---|
1400 | timestr[(int)strlen(timestr)-1] = '\0';
|
---|
1401 |
|
---|
1402 | sprintf(str," Timestamp: %s         Quality: %d    Size: %s<br /><br />",
|
---|
1403 | timestr, quality, sizestr);
|
---|
1404 |
|
---|
1405 | strcat(Service_content_str,str);
|
---|
1406 | ptr = Curr_service_format;
|
---|
1407 | buffer_ptr = buff;
|
---|
1408 | while(*ptr)
|
---|
1409 | {
|
---|
1410 | type = *ptr++;
|
---|
1411 | if(*ptr == ':')
|
---|
1412 | {
|
---|
1413 | ptr++;
|
---|
1414 | sscanf(ptr, "%d", &num);
|
---|
1415 | ret = did_write_string(type, num, &buffer_ptr, size);
|
---|
1416 | size -= ret;
|
---|
1417 | if( (ptr = strchr(ptr,';')) )
|
---|
1418 | ptr++;
|
---|
1419 | else
|
---|
1420 | break;
|
---|
1421 | }
|
---|
1422 | else
|
---|
1423 | {
|
---|
1424 | ret = did_write_string(type, 0, &buffer_ptr, size);
|
---|
1425 | size -= ret;
|
---|
1426 | break;
|
---|
1427 | }
|
---|
1428 | }
|
---|
1429 | strcat(Service_content_str,"</FONT>");
|
---|
1430 | }
|
---|
1431 |
|
---|
1432 |
|
---|
1433 | int did_write_string(char type, int num, void **buffer_ptr, int ssize)
|
---|
1434 | {
|
---|
1435 | void *ptr;
|
---|
1436 | int size, psize;
|
---|
1437 |
|
---|
1438 | void print_service_standard();
|
---|
1439 | void print_service_char();
|
---|
1440 | void print_service_short();
|
---|
1441 | void print_service_float();
|
---|
1442 | void print_service_double();
|
---|
1443 |
|
---|
1444 | ptr = *buffer_ptr;
|
---|
1445 | switch(type)
|
---|
1446 | {
|
---|
1447 | case 'L':
|
---|
1448 | case 'l':
|
---|
1449 | strcat(Service_content_str," L");
|
---|
1450 | if(!num)
|
---|
1451 | size = ssize/(int)sizeof(int);
|
---|
1452 | else
|
---|
1453 | size = num;
|
---|
1454 | psize = size * (int)sizeof(int);
|
---|
1455 | print_service_standard(ptr, size);
|
---|
1456 | break;
|
---|
1457 | case 'I':
|
---|
1458 | case 'i':
|
---|
1459 | strcat(Service_content_str," I");
|
---|
1460 | if(!num)
|
---|
1461 | size = ssize/(int)sizeof(int);
|
---|
1462 | else
|
---|
1463 | size = num;
|
---|
1464 | psize = size * (int)sizeof(int);
|
---|
1465 | print_service_standard(ptr, size);
|
---|
1466 | break;
|
---|
1467 | case 'S':
|
---|
1468 | case 's':
|
---|
1469 | strcat(Service_content_str," S");
|
---|
1470 | if(!num)
|
---|
1471 | size = ssize/(int)sizeof(short);
|
---|
1472 | else
|
---|
1473 | size = num;
|
---|
1474 | psize = size * (int)sizeof(short);
|
---|
1475 | print_service_short(ptr, size);
|
---|
1476 | break;
|
---|
1477 | case 'F':
|
---|
1478 | case 'f':
|
---|
1479 | strcat(Service_content_str," F");
|
---|
1480 | if(!num)
|
---|
1481 | size = ssize/(int)sizeof(float);
|
---|
1482 | else
|
---|
1483 | size = num;
|
---|
1484 | psize = size * (int)sizeof(float);
|
---|
1485 | print_service_float(ptr, size);
|
---|
1486 | break;
|
---|
1487 | case 'D':
|
---|
1488 | case 'd':
|
---|
1489 | strcat(Service_content_str," D");
|
---|
1490 | if(!num)
|
---|
1491 | size = ssize/(int)sizeof(double);
|
---|
1492 | else
|
---|
1493 | size = num;
|
---|
1494 | psize = size * (int)sizeof(double);
|
---|
1495 | print_service_double(ptr, size);
|
---|
1496 | break;
|
---|
1497 | case 'X':
|
---|
1498 | case 'x':
|
---|
1499 | strcat(Service_content_str," X");
|
---|
1500 | if(!num)
|
---|
1501 | size = ssize/(int)sizeof(longlong);
|
---|
1502 | else
|
---|
1503 | size = num;
|
---|
1504 | psize = size * (int)sizeof(longlong);
|
---|
1505 | print_service_standard(ptr, size*2);
|
---|
1506 | break;
|
---|
1507 | case 'C':
|
---|
1508 | case 'c':
|
---|
1509 | default:
|
---|
1510 | strcat(Service_content_str," C");
|
---|
1511 | if(!num)
|
---|
1512 | size = ssize;
|
---|
1513 | else
|
---|
1514 | size = num;
|
---|
1515 | psize = size;
|
---|
1516 | print_service_char(ptr, size);
|
---|
1517 | }
|
---|
1518 | ptr = (char *)ptr + psize;
|
---|
1519 | *buffer_ptr = ptr;
|
---|
1520 | return psize;
|
---|
1521 | }
|
---|
1522 |
|
---|
1523 | void sprintf_html(char *str, int n, int value)
|
---|
1524 | {
|
---|
1525 | char tmp[80];
|
---|
1526 | int min, i;
|
---|
1527 |
|
---|
1528 | str[0] = '\0';
|
---|
1529 | min = sprintf(tmp,"%d",value);
|
---|
1530 | for(i = 0; i < (n-min); i++)
|
---|
1531 | {
|
---|
1532 | strcat(str," ");
|
---|
1533 | }
|
---|
1534 | strcat(str, tmp);
|
---|
1535 | }
|
---|
1536 |
|
---|
1537 | void print_service_standard(int *buff, int size)
|
---|
1538 | {
|
---|
1539 | int i,j;
|
---|
1540 | char *ptr, str[80], tmp[256];
|
---|
1541 | int last[4];
|
---|
1542 |
|
---|
1543 | ptr = Service_content_str;
|
---|
1544 | ptr += (int)strlen(Service_content_str);
|
---|
1545 | for( i = 0; i < size; i++)
|
---|
1546 | {
|
---|
1547 | strcpy(tmp,"");
|
---|
1548 | if(i%4 == 0)
|
---|
1549 | {
|
---|
1550 | if(i != 0)
|
---|
1551 | {
|
---|
1552 | strcat(tmp," ");
|
---|
1553 | }
|
---|
1554 | sprintf_html(str, 7, i);
|
---|
1555 | strcat(tmp,str);
|
---|
1556 | }
|
---|
1557 | if(!(i%4))
|
---|
1558 | strcat(tmp,"H: ");
|
---|
1559 | sprintf(str,"    %08X",buff[i]);
|
---|
1560 | strcat(tmp,str);
|
---|
1561 | last[i%4] = buff[i];
|
---|
1562 | if((i%4 == 3) || (i == (size-1)))
|
---|
1563 | {
|
---|
1564 | strcat(tmp,"<br />");
|
---|
1565 | for(j = 0; j <= (i%4); j++)
|
---|
1566 | {
|
---|
1567 | if(j == 0)
|
---|
1568 | strcat(tmp,"        D: ");
|
---|
1569 | sprintf_html(str, 12, last[j]);
|
---|
1570 | strcat(tmp,str);
|
---|
1571 | }
|
---|
1572 | strcat(tmp,"<br />");
|
---|
1573 | }
|
---|
1574 | strcpy(ptr, tmp);
|
---|
1575 | ptr += (int)strlen(tmp);
|
---|
1576 | }
|
---|
1577 | strcpy(tmp,"<br />");
|
---|
1578 | strcpy(ptr, tmp);
|
---|
1579 | }
|
---|
1580 |
|
---|
1581 | void print_service_longlong(longlong *buff, int size)
|
---|
1582 | {
|
---|
1583 | int i,j;
|
---|
1584 | char *ptr, str[80], tmp[256];
|
---|
1585 | longlong last[4];
|
---|
1586 |
|
---|
1587 | ptr = Service_content_str;
|
---|
1588 | ptr += (int)strlen(Service_content_str);
|
---|
1589 | for( i = 0; i < size; i++)
|
---|
1590 | {
|
---|
1591 | strcpy(tmp,"");
|
---|
1592 | if(i%4 == 0)
|
---|
1593 | {
|
---|
1594 | if(i != 0)
|
---|
1595 | {
|
---|
1596 | strcat(tmp," ");
|
---|
1597 | }
|
---|
1598 | sprintf_html(str, 7, i);
|
---|
1599 | strcat(tmp,str);
|
---|
1600 | }
|
---|
1601 | if(!(i%4))
|
---|
1602 | strcat(tmp,"H: ");
|
---|
1603 | sprintf(str,"    %08X",(unsigned)buff[i]);
|
---|
1604 | strcat(tmp,str);
|
---|
1605 | last[i%4] = buff[i];
|
---|
1606 | if((i%4 == 3) || (i == (size-1)))
|
---|
1607 | {
|
---|
1608 | strcat(tmp,"<br />");
|
---|
1609 | for(j = 0; j <= (i%4); j++)
|
---|
1610 | {
|
---|
1611 | if(j == 0)
|
---|
1612 | strcat(tmp,"        D: ");
|
---|
1613 | sprintf_html(str, 12, (int)last[j]);
|
---|
1614 | strcat(tmp,str);
|
---|
1615 | }
|
---|
1616 | strcat(tmp,"<br />");
|
---|
1617 | }
|
---|
1618 | strcpy(ptr, tmp);
|
---|
1619 | ptr += (int)strlen(tmp);
|
---|
1620 | }
|
---|
1621 | strcpy(tmp,"<br />");
|
---|
1622 | strcpy(ptr, tmp);
|
---|
1623 | }
|
---|
1624 |
|
---|
1625 | void print_service_short(short *buff, int size)
|
---|
1626 | {
|
---|
1627 | int i,j;
|
---|
1628 | char *ptr, str[80], tmp[256];
|
---|
1629 | short last[8];
|
---|
1630 |
|
---|
1631 | ptr = Service_content_str;
|
---|
1632 | ptr += (int)strlen(Service_content_str);
|
---|
1633 | for( i = 0; i < size; i++)
|
---|
1634 | {
|
---|
1635 | strcpy(tmp,"");
|
---|
1636 | if(i%8 == 0)
|
---|
1637 | {
|
---|
1638 | if(i != 0)
|
---|
1639 | {
|
---|
1640 | strcat(tmp," ");
|
---|
1641 | }
|
---|
1642 | sprintf_html(str, 7, i);
|
---|
1643 | strcat(tmp,str);
|
---|
1644 | }
|
---|
1645 | if(!(i%8))
|
---|
1646 | strcat(tmp,"H: ");
|
---|
1647 | sprintf(str,"  %04X",buff[i]);
|
---|
1648 | strcat(tmp,str);
|
---|
1649 | last[i%8] = buff[i];
|
---|
1650 | if((i%8 == 7) || (i == (size-1)))
|
---|
1651 | {
|
---|
1652 | strcat(tmp,"<br />");
|
---|
1653 | for(j = 0; j <= (i%8); j++)
|
---|
1654 | {
|
---|
1655 | if(j == 0)
|
---|
1656 | strcat(tmp,"        D: ");
|
---|
1657 | sprintf_html(str, 6, last[j]);
|
---|
1658 | strcat(tmp,str);
|
---|
1659 | }
|
---|
1660 | strcat(tmp,"<br />");
|
---|
1661 | }
|
---|
1662 | strcpy(ptr, tmp);
|
---|
1663 | ptr += (int)strlen(tmp);
|
---|
1664 | }
|
---|
1665 | strcpy(tmp,"<br />");
|
---|
1666 | strcpy(ptr, tmp);
|
---|
1667 | }
|
---|
1668 |
|
---|
1669 | void print_service_char(char *buff, int size)
|
---|
1670 | {
|
---|
1671 | int i,j;
|
---|
1672 | char *asc, *ptr, str[80], tmp[256];
|
---|
1673 |
|
---|
1674 | asc = (char *)buff;
|
---|
1675 | ptr = Service_content_str;
|
---|
1676 | ptr += (int)strlen(Service_content_str);
|
---|
1677 | for( i = 0; i < size; i++)
|
---|
1678 | {
|
---|
1679 | strcpy(tmp,"");
|
---|
1680 | if(i%16 == 0)
|
---|
1681 | {
|
---|
1682 | if(i != 0)
|
---|
1683 | {
|
---|
1684 | strcat(tmp," ");
|
---|
1685 | }
|
---|
1686 | sprintf_html(str, 7, i);
|
---|
1687 | strcat(tmp,str);
|
---|
1688 | }
|
---|
1689 | if(!(i%16))
|
---|
1690 | strcat(tmp,"H: ");
|
---|
1691 | sprintf(str,"%02X",buff[i]);
|
---|
1692 | /* strcat(tmp,str);
|
---|
1693 | */
|
---|
1694 | strcat(tmp," ");
|
---|
1695 | strcat(tmp,&str[(int)strlen(str)-2]);
|
---|
1696 | /*
|
---|
1697 | if(i%4 == 3)
|
---|
1698 | strcat(tmp," ");
|
---|
1699 | */
|
---|
1700 | if((i%16 == 15) || (i == (size-1)))
|
---|
1701 | {
|
---|
1702 | if(i%16 != 15)
|
---|
1703 | {
|
---|
1704 | for(j = 1; j < 16 - (i%16); j++)
|
---|
1705 | strcat(tmp,"   ");
|
---|
1706 | }
|
---|
1707 | strcat(tmp,"    '");
|
---|
1708 | for(j = 0; j <= (i%16) ; j++)
|
---|
1709 | {
|
---|
1710 | if(isprint(asc[j]))
|
---|
1711 | {
|
---|
1712 | if(asc[j] == ' ')
|
---|
1713 | sprintf(str," ");
|
---|
1714 | else if(asc[j] == '<')
|
---|
1715 | sprintf(str,"<");
|
---|
1716 | else if(asc[j] == '>')
|
---|
1717 | sprintf(str,">");
|
---|
1718 | else if(asc[j] == '&')
|
---|
1719 | sprintf(str,"&");
|
---|
1720 | else
|
---|
1721 | sprintf(str,"%c",asc[j]);
|
---|
1722 | strcat(tmp,str);
|
---|
1723 | }
|
---|
1724 | else
|
---|
1725 | {
|
---|
1726 | sprintf(str,".");
|
---|
1727 | strcat(tmp,str);
|
---|
1728 | }
|
---|
1729 | }
|
---|
1730 | strcat(tmp,"'<br />");
|
---|
1731 | asc = (char *)&buff[i+1];
|
---|
1732 | }
|
---|
1733 | strcpy(ptr, tmp);
|
---|
1734 | ptr += (int)strlen(tmp);
|
---|
1735 | }
|
---|
1736 | strcpy(tmp,"<br />");
|
---|
1737 | strcpy(ptr, tmp);
|
---|
1738 | }
|
---|
1739 |
|
---|
1740 | void print_service_float(float *buff, int size)
|
---|
1741 | {
|
---|
1742 | int i;
|
---|
1743 | char *ptr, str[80], tmp[256];
|
---|
1744 |
|
---|
1745 | ptr = Service_content_str;
|
---|
1746 | ptr += (int)strlen(Service_content_str);
|
---|
1747 | for( i = 0; i < size; i++)
|
---|
1748 | {
|
---|
1749 | strcpy(tmp,"");
|
---|
1750 | if(i%4 == 0)
|
---|
1751 | {
|
---|
1752 | if(i != 0)
|
---|
1753 | {
|
---|
1754 | strcat(tmp," ");
|
---|
1755 | }
|
---|
1756 | sprintf_html(str, 7, i);
|
---|
1757 | strcat(tmp,str);
|
---|
1758 | }
|
---|
1759 | sprintf(str,"%12.3G",*(buff++));
|
---|
1760 | strcat(tmp,str);
|
---|
1761 | if((i%4 == 3) || (i == size-1))
|
---|
1762 | {
|
---|
1763 | strcat(tmp,"<br />");
|
---|
1764 | }
|
---|
1765 | strcpy(ptr, tmp);
|
---|
1766 | ptr += (int)strlen(tmp);
|
---|
1767 | }
|
---|
1768 | strcpy(tmp,"<br />");
|
---|
1769 | strcpy(ptr, tmp);
|
---|
1770 | ptr += (int)strlen(tmp);
|
---|
1771 | }
|
---|
1772 |
|
---|
1773 | void print_service_double(double *buff, int size)
|
---|
1774 | {
|
---|
1775 | int i;
|
---|
1776 | char *ptr, str[80], tmp[256];
|
---|
1777 |
|
---|
1778 | ptr = Service_content_str;
|
---|
1779 | ptr += (int)strlen(Service_content_str);
|
---|
1780 | for( i = 0; i < size; i++)
|
---|
1781 | {
|
---|
1782 | strcpy(tmp,"");
|
---|
1783 | if(i%4 == 0)
|
---|
1784 | {
|
---|
1785 | if(i != 0)
|
---|
1786 | {
|
---|
1787 | strcat(tmp," ");
|
---|
1788 | }
|
---|
1789 | sprintf_html(str, 7, i);
|
---|
1790 | strcat(tmp,str);
|
---|
1791 | }
|
---|
1792 | sprintf(str,"%12.3G",*(buff++));
|
---|
1793 | strcat(tmp,str);
|
---|
1794 | if((i%4 == 3) || (i == size-1))
|
---|
1795 | {
|
---|
1796 | strcat(tmp,"<br />");
|
---|
1797 | }
|
---|
1798 | strcpy(ptr, tmp);
|
---|
1799 | ptr += (int)strlen(tmp);
|
---|
1800 | }
|
---|
1801 | strcpy(tmp,"<br />");
|
---|
1802 | strcpy(ptr, tmp);
|
---|
1803 | ptr += (int)strlen(tmp);
|
---|
1804 | }
|
---|
1805 |
|
---|
1806 | char *addJSONStart(char *ptr)
|
---|
1807 | {
|
---|
1808 | char *ptro;
|
---|
1809 |
|
---|
1810 | strcat(ptr,"{\n");
|
---|
1811 | ptro = ptr + (int)strlen(ptr);
|
---|
1812 | return ptro;
|
---|
1813 | }
|
---|
1814 |
|
---|
1815 | char *addJSONEnd(char *ptr)
|
---|
1816 | {
|
---|
1817 | char *ptro;
|
---|
1818 |
|
---|
1819 | strcat(ptr,"}\n");
|
---|
1820 | ptro = ptr + (int)strlen(ptr);
|
---|
1821 | return ptro;
|
---|
1822 | }
|
---|
1823 |
|
---|
1824 | char *addJSONNodeStart(char *ptr, char *node)
|
---|
1825 | {
|
---|
1826 | char *ptro;
|
---|
1827 |
|
---|
1828 | sprintf(ptr,"%s: [\n", node);
|
---|
1829 | ptro = ptr + (int)strlen(ptr);
|
---|
1830 | return ptro;
|
---|
1831 | }
|
---|
1832 |
|
---|
1833 | char *addJSONNodeEnd(char *ptr)
|
---|
1834 | {
|
---|
1835 | char *ptro;
|
---|
1836 |
|
---|
1837 | strcat(ptr,"]\n");
|
---|
1838 | ptro = ptr + (int)strlen(ptr);
|
---|
1839 | return ptro;
|
---|
1840 | }
|
---|
1841 |
|
---|
1842 | char *addJSONChildStart(char *ptr, char *child, int sep)
|
---|
1843 | {
|
---|
1844 | char *ptro;
|
---|
1845 |
|
---|
1846 | if(sep)
|
---|
1847 | sprintf(ptr,"{ %s, ", child);
|
---|
1848 | else
|
---|
1849 | sprintf(ptr,"{ %s", child);
|
---|
1850 | ptro = ptr + (int)strlen(ptr);
|
---|
1851 | return ptro;
|
---|
1852 | }
|
---|
1853 |
|
---|
1854 | char *addJSONChildEnd(char *ptr, int sep)
|
---|
1855 | {
|
---|
1856 | char *ptro;
|
---|
1857 |
|
---|
1858 | if(sep)
|
---|
1859 | strcat(ptr," },\n");
|
---|
1860 | else
|
---|
1861 | strcat(ptr," }\n");
|
---|
1862 | ptro = ptr + (int)strlen(ptr);
|
---|
1863 | return ptro;
|
---|
1864 | }
|
---|
1865 |
|
---|
1866 | char *getJSONBuffer(char *node, int browser)
|
---|
1867 | {
|
---|
1868 | BROWSER *browserp;
|
---|
1869 | int prepareJSONTree();
|
---|
1870 |
|
---|
1871 | if(browser)
|
---|
1872 | {
|
---|
1873 | if((browserp = find_browser(browser)))
|
---|
1874 | {
|
---|
1875 | if(browserp->pattern[0] != '\0')
|
---|
1876 | {
|
---|
1877 | prepareJSONTree(node, browserp);
|
---|
1878 | return(browserp->JSONBuffer);
|
---|
1879 | }
|
---|
1880 | browserp->n_services = 0;
|
---|
1881 | browserp->n_servers = 0;
|
---|
1882 | browserp->n_nodes = 0;
|
---|
1883 | }
|
---|
1884 | }
|
---|
1885 | prepareJSONTree(node, 0);
|
---|
1886 | return(JSONBuffer);
|
---|
1887 | }
|
---|
1888 |
|
---|
1889 | char *getJSONSmiBuffer(char *node, int browser)
|
---|
1890 | {
|
---|
1891 | BROWSER *browserp;
|
---|
1892 | int prepareJSONSmiTree();
|
---|
1893 |
|
---|
1894 | if(!(browserp = find_browser(browser)))
|
---|
1895 | {
|
---|
1896 | browserp = create_browser(browser);
|
---|
1897 | browserp->isSMI = 1;
|
---|
1898 | strcpy(browserp->pattern,"SMI/");
|
---|
1899 | }
|
---|
1900 | if(browser)
|
---|
1901 | {
|
---|
1902 | if((browserp = find_browser(browser)))
|
---|
1903 | {
|
---|
1904 | if(browserp->pattern[0] != '\0')
|
---|
1905 | {
|
---|
1906 | prepareJSONSmiTree(node, browserp);
|
---|
1907 | return(browserp->JSONSmiBuffer);
|
---|
1908 | }
|
---|
1909 | // browserp->n_services = 0;
|
---|
1910 | // browserp->n_servers = 0;
|
---|
1911 | // browserp->n_nodes = 0;
|
---|
1912 | }
|
---|
1913 | }
|
---|
1914 | prepareJSONSmiTree(node, 0);
|
---|
1915 | return(JSONSmiBuffer);
|
---|
1916 | }
|
---|
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 |
|
---|
1941 | char *getJSONHeader(int isSMI)
|
---|
1942 | {
|
---|
1943 | int prepareJSONHeader();
|
---|
1944 |
|
---|
1945 | if(isSMI){}
|
---|
1946 | if(JSONHeader[0] == '\0')
|
---|
1947 | prepareJSONHeader();
|
---|
1948 | return(JSONHeader);
|
---|
1949 | }
|
---|
1950 |
|
---|
1951 | int getNodeLabel(char *name, char *label)
|
---|
1952 | {
|
---|
1953 | int i;
|
---|
1954 | extern int web_get_node_name();
|
---|
1955 |
|
---|
1956 | web_get_node_name(name, label);
|
---|
1957 | for(i = 0; i < ((int)strlen(label) + 1); i++)
|
---|
1958 | {
|
---|
1959 | label[i] = (char)tolower((int)label[i]);
|
---|
1960 | if(label[i] == '.')
|
---|
1961 | {
|
---|
1962 | label[i] = '\0';
|
---|
1963 | break;
|
---|
1964 | }
|
---|
1965 | }
|
---|
1966 | return 1;
|
---|
1967 | }
|
---|
1968 |
|
---|
1969 | int prepareJSONTree(char *node, BROWSER *browserp)
|
---|
1970 | {
|
---|
1971 | char *ptr;
|
---|
1972 | NODE *nodep;
|
---|
1973 | SERVER *servp;
|
---|
1974 | char str[256], aux[128];
|
---|
1975 | int selective = 0;
|
---|
1976 | int n_nodes, tot_n_nodes;
|
---|
1977 | int n_servers, tot_n_servers;
|
---|
1978 | int ret, n_found = 0;
|
---|
1979 |
|
---|
1980 | if(browserp)
|
---|
1981 | {
|
---|
1982 | if(browserp->pattern[0] != '\0')
|
---|
1983 | selective = 1;
|
---|
1984 | else
|
---|
1985 | return(0);
|
---|
1986 | }
|
---|
1987 | if(!selective)
|
---|
1988 | {
|
---|
1989 | if(JSONBufferSize == 0)
|
---|
1990 | {
|
---|
1991 | JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1992 | }
|
---|
1993 | else if (JSONBufferSize < N_nodes*128+N_servers*128)
|
---|
1994 | {
|
---|
1995 | free(JSONBuffer);
|
---|
1996 | JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1997 | }
|
---|
1998 | ptr = JSONBuffer;
|
---|
1999 | }
|
---|
2000 | else
|
---|
2001 | {
|
---|
2002 | if(browserp->JSONBufferSize == 0)
|
---|
2003 | {
|
---|
2004 | browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
2005 | }
|
---|
2006 | else if (browserp->JSONBufferSize < N_nodes*128+N_servers*128)
|
---|
2007 | {
|
---|
2008 | free(browserp->JSONBuffer);
|
---|
2009 | browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
2010 | }
|
---|
2011 | ptr = browserp->JSONBuffer;
|
---|
2012 | }
|
---|
2013 | *ptr = '\0';
|
---|
2014 | if(!strcmp(node, "src"))
|
---|
2015 | {
|
---|
2016 | ptr = addJSONStart(ptr);
|
---|
2017 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2018 | sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
|
---|
2019 | ptr = addJSONChildStart(ptr,str,1);
|
---|
2020 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2021 | nodep = Node_head;
|
---|
2022 | tot_n_nodes = 0;
|
---|
2023 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
2024 | {
|
---|
2025 | nodep->match = 1;
|
---|
2026 | if(selective)
|
---|
2027 | {
|
---|
2028 | if(!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers, 0)))
|
---|
2029 | {
|
---|
2030 | nodep->match = 0;
|
---|
2031 | continue;
|
---|
2032 | }
|
---|
2033 | else
|
---|
2034 | {
|
---|
2035 | n_found += ret;
|
---|
2036 | }
|
---|
2037 | }
|
---|
2038 | tot_n_nodes++;
|
---|
2039 | }
|
---|
2040 | n_nodes = 0;
|
---|
2041 | nodep = Node_head;
|
---|
2042 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
2043 | {
|
---|
2044 | if(!nodep->match)
|
---|
2045 | continue;
|
---|
2046 | getNodeLabel(nodep->name, aux);
|
---|
2047 | sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
|
---|
2048 | aux, nodep->name, nodep->name);
|
---|
2049 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2050 | n_nodes++;
|
---|
2051 | if(WebDID_Debug)
|
---|
2052 | printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
|
---|
2053 | if(n_nodes < tot_n_nodes)
|
---|
2054 | ptr = addJSONChildEnd(ptr,1);
|
---|
2055 | else
|
---|
2056 | ptr = addJSONChildEnd(ptr,0);
|
---|
2057 | }
|
---|
2058 | ptr = addJSONNodeEnd(ptr);
|
---|
2059 | ptr = addJSONChildEnd(ptr,0);
|
---|
2060 | ptr = addJSONNodeEnd(ptr);
|
---|
2061 | ptr = addJSONEnd(ptr);
|
---|
2062 | if(selective)
|
---|
2063 | {
|
---|
2064 | browserp->n_services = n_found;
|
---|
2065 | browserp->n_servers = tot_n_servers;
|
---|
2066 | browserp->n_nodes = tot_n_nodes;
|
---|
2067 | }
|
---|
2068 | }
|
---|
2069 | else
|
---|
2070 | {
|
---|
2071 | if((nodep = find_node(node)))
|
---|
2072 | {
|
---|
2073 | ptr = addJSONStart(ptr);
|
---|
2074 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2075 | servp = nodep->server_head;
|
---|
2076 | tot_n_servers = 0;
|
---|
2077 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
2078 | {
|
---|
2079 | servp->match = 1;
|
---|
2080 | if(servp->busy != 1)
|
---|
2081 | {
|
---|
2082 | servp->match = 0;
|
---|
2083 | continue;
|
---|
2084 | }
|
---|
2085 | if(selective)
|
---|
2086 | {
|
---|
2087 | if(!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0, 0)))
|
---|
2088 | {
|
---|
2089 | servp->match = 0;
|
---|
2090 | continue;
|
---|
2091 | }
|
---|
2092 | else
|
---|
2093 | {
|
---|
2094 | n_found += ret;
|
---|
2095 | }
|
---|
2096 | }
|
---|
2097 | tot_n_servers++;
|
---|
2098 | }
|
---|
2099 | n_servers = 0;
|
---|
2100 | servp = nodep->server_head;
|
---|
2101 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
2102 | {
|
---|
2103 | if(!servp->match)
|
---|
2104 | continue;
|
---|
2105 | sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\"",servp->name, servp->server.pid);
|
---|
2106 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2107 | n_servers++;
|
---|
2108 | if(n_servers < tot_n_servers)
|
---|
2109 | ptr = addJSONChildEnd(ptr,1);
|
---|
2110 | else
|
---|
2111 | ptr = addJSONChildEnd(ptr,0);
|
---|
2112 | }
|
---|
2113 | ptr = addJSONNodeEnd(ptr);
|
---|
2114 | ptr = addJSONEnd(ptr);
|
---|
2115 | }
|
---|
2116 | }
|
---|
2117 | /*
|
---|
2118 | if(!selective)
|
---|
2119 | printf(" Nodes&Servers %s\n",JSONBuffer);
|
---|
2120 | else
|
---|
2121 | printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
|
---|
2122 | */
|
---|
2123 | return(1);
|
---|
2124 | }
|
---|
2125 |
|
---|
2126 | int prepareJSONSmiTree(char *node, BROWSER *browserp)
|
---|
2127 | {
|
---|
2128 | char *ptr;
|
---|
2129 | NODE *nodep;
|
---|
2130 | SERVER *servp;
|
---|
2131 | char str[256], aux[128];
|
---|
2132 | int selective = 0;
|
---|
2133 | int n_nodes, tot_n_nodes;
|
---|
2134 | int n_servers, tot_n_servers;
|
---|
2135 | int ret, n_found = 0;
|
---|
2136 | char pattern[256] = {'\0'};
|
---|
2137 | char *sptr;
|
---|
2138 |
|
---|
2139 | if(browserp)
|
---|
2140 | {
|
---|
2141 | if(browserp->pattern[0] != '\0')
|
---|
2142 | {
|
---|
2143 | selective = 1;
|
---|
2144 | strcpy(pattern, browserp->pattern);
|
---|
2145 | }
|
---|
2146 | // else
|
---|
2147 | // return(0);
|
---|
2148 | }
|
---|
2149 | // selective = 1;
|
---|
2150 | // strcpy(pattern,"SMI/*");
|
---|
2151 | if(!selective)
|
---|
2152 | {
|
---|
2153 | if(JSONSmiBufferSize == 0)
|
---|
2154 | {
|
---|
2155 | JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
2156 | }
|
---|
2157 | else if (JSONSmiBufferSize < N_nodes*128+N_servers*128)
|
---|
2158 | {
|
---|
2159 | free(JSONSmiBuffer);
|
---|
2160 | JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
2161 | }
|
---|
2162 | ptr = JSONSmiBuffer;
|
---|
2163 | }
|
---|
2164 | else
|
---|
2165 | {
|
---|
2166 | if(browserp->JSONSmiBufferSize == 0)
|
---|
2167 | {
|
---|
2168 | browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
2169 | }
|
---|
2170 | else if (browserp->JSONSmiBufferSize < N_nodes*128+N_servers*128)
|
---|
2171 | {
|
---|
2172 | free(browserp->JSONSmiBuffer);
|
---|
2173 | browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
2174 | }
|
---|
2175 | ptr = browserp->JSONSmiBuffer;
|
---|
2176 | }
|
---|
2177 | *ptr = '\0';
|
---|
2178 | if(!strcmp(node, "src"))
|
---|
2179 | {
|
---|
2180 | ptr = addJSONStart(ptr);
|
---|
2181 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2182 | sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
|
---|
2183 | ptr = addJSONChildStart(ptr,str,1);
|
---|
2184 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2185 | nodep = Node_head;
|
---|
2186 | tot_n_nodes = 0;
|
---|
2187 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
2188 | {
|
---|
2189 | nodep->match = 1;
|
---|
2190 | if(selective)
|
---|
2191 | {
|
---|
2192 | if(!(ret = find_service_pattern(nodep, 0, pattern, &tot_n_servers, 0)))
|
---|
2193 | {
|
---|
2194 | nodep->match = 0;
|
---|
2195 | continue;
|
---|
2196 | }
|
---|
2197 | else
|
---|
2198 | {
|
---|
2199 | n_found += ret;
|
---|
2200 | }
|
---|
2201 | }
|
---|
2202 | tot_n_nodes++;
|
---|
2203 | }
|
---|
2204 | n_nodes = 0;
|
---|
2205 | nodep = Node_head;
|
---|
2206 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
2207 | {
|
---|
2208 | if(!nodep->match)
|
---|
2209 | continue;
|
---|
2210 | getNodeLabel(nodep->name, aux);
|
---|
2211 | sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
|
---|
2212 | aux, nodep->name, nodep->name);
|
---|
2213 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2214 | n_nodes++;
|
---|
2215 | if(WebDID_Debug)
|
---|
2216 | printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
|
---|
2217 | if(n_nodes < tot_n_nodes)
|
---|
2218 | ptr = addJSONChildEnd(ptr,1);
|
---|
2219 | else
|
---|
2220 | ptr = addJSONChildEnd(ptr,0);
|
---|
2221 | }
|
---|
2222 | ptr = addJSONNodeEnd(ptr);
|
---|
2223 | ptr = addJSONChildEnd(ptr,0);
|
---|
2224 | ptr = addJSONNodeEnd(ptr);
|
---|
2225 | ptr = addJSONEnd(ptr);
|
---|
2226 | if(selective)
|
---|
2227 | {
|
---|
2228 | browserp->n_services = n_found;
|
---|
2229 | browserp->n_servers = tot_n_servers;
|
---|
2230 | browserp->n_nodes = tot_n_nodes;
|
---|
2231 | }
|
---|
2232 | }
|
---|
2233 | else
|
---|
2234 | {
|
---|
2235 | if((nodep = find_node(node)))
|
---|
2236 | {
|
---|
2237 | ptr = addJSONStart(ptr);
|
---|
2238 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2239 | servp = nodep->server_head;
|
---|
2240 | tot_n_servers = 0;
|
---|
2241 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
2242 | {
|
---|
2243 | servp->match = 1;
|
---|
2244 | if(servp->busy != 1)
|
---|
2245 | {
|
---|
2246 | servp->match = 0;
|
---|
2247 | continue;
|
---|
2248 | }
|
---|
2249 | if(selective)
|
---|
2250 | {
|
---|
2251 | if(!(ret = find_service_pattern(nodep, servp, pattern, 0, 0)))
|
---|
2252 | {
|
---|
2253 | servp->match = 0;
|
---|
2254 | continue;
|
---|
2255 | }
|
---|
2256 | else
|
---|
2257 | {
|
---|
2258 | n_found += ret;
|
---|
2259 | }
|
---|
2260 | }
|
---|
2261 | tot_n_servers++;
|
---|
2262 | }
|
---|
2263 | n_servers = 0;
|
---|
2264 | servp = nodep->server_head;
|
---|
2265 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
2266 | {
|
---|
2267 | if(!servp->match)
|
---|
2268 | continue;
|
---|
2269 | strcpy(aux, servp->name);
|
---|
2270 | sptr = strstr(aux,"_SMI");
|
---|
2271 | if(sptr)
|
---|
2272 | *sptr = '\0';
|
---|
2273 | sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\", name: \"%s\"",aux, servp->server.pid, servp->name);
|
---|
2274 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2275 | n_servers++;
|
---|
2276 | if(n_servers < tot_n_servers)
|
---|
2277 | ptr = addJSONChildEnd(ptr,1);
|
---|
2278 | else
|
---|
2279 | ptr = addJSONChildEnd(ptr,0);
|
---|
2280 | }
|
---|
2281 | ptr = addJSONNodeEnd(ptr);
|
---|
2282 | ptr = addJSONEnd(ptr);
|
---|
2283 | }
|
---|
2284 | }
|
---|
2285 | /*
|
---|
2286 | if(!selective)
|
---|
2287 | printf(" Nodes&Servers %s\n",JSONBuffer);
|
---|
2288 | else
|
---|
2289 | printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
|
---|
2290 | */
|
---|
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 | */
|
---|
2456 | return(1);
|
---|
2457 | }
|
---|
2458 |
|
---|
2459 | int prepareJSONHeader()
|
---|
2460 | {
|
---|
2461 | char *ptr;
|
---|
2462 | char str[128];
|
---|
2463 |
|
---|
2464 | ptr = JSONHeader;
|
---|
2465 | *ptr = '\0';
|
---|
2466 | ptr = addJSONStart(ptr);
|
---|
2467 | ptr = addJSONNodeStart(ptr,"items");
|
---|
2468 | sprintf(str,"text: \"%s\"",Title);
|
---|
2469 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2470 | ptr = addJSONChildEnd(ptr,1);
|
---|
2471 | sprintf(str,"text: \"%d Servers Known - %d Services Available\"",N_servers, N_services);
|
---|
2472 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2473 | ptr = addJSONChildEnd(ptr,0);
|
---|
2474 | ptr = addJSONNodeEnd(ptr);
|
---|
2475 | ptr = addJSONEnd(ptr);
|
---|
2476 | if(WebDID_Debug)
|
---|
2477 | printf(" Header %s\n",JSONHeader);
|
---|
2478 | return(1);
|
---|
2479 | }
|
---|
2480 |
|
---|
2481 | char *JSONServices = 0;
|
---|
2482 | int JSONServicesSize = 0;
|
---|
2483 | char *prepareJSONServiceList(SERVER *servp, char *node, int pid, BROWSER *browserp)
|
---|
2484 | {
|
---|
2485 | DNS_SERVICE_INFO *servicep;
|
---|
2486 | char *ptr;
|
---|
2487 | int n_services, i;
|
---|
2488 | char str[256], type_str[256];
|
---|
2489 | int selective = 0;
|
---|
2490 | int n_found = 0, n;
|
---|
2491 |
|
---|
2492 | servicep = servp->service_ptr;
|
---|
2493 | n_services = servp->server.n_services;
|
---|
2494 | if(JSONServicesSize == 0)
|
---|
2495 | {
|
---|
2496 | JSONServicesSize = n_services*256;
|
---|
2497 | JSONServices = malloc((size_t)JSONServicesSize);
|
---|
2498 | }
|
---|
2499 | else if (JSONServicesSize < n_services*256)
|
---|
2500 | {
|
---|
2501 | free(JSONServices);
|
---|
2502 | JSONServicesSize = n_services*256;
|
---|
2503 | JSONServices = malloc((size_t)JSONServicesSize);
|
---|
2504 | }
|
---|
2505 | if(browserp)
|
---|
2506 | {
|
---|
2507 | if(browserp->pattern[0] != '\0')
|
---|
2508 | selective = 1;
|
---|
2509 | }
|
---|
2510 | n_found = n_services;
|
---|
2511 | if(selective)
|
---|
2512 | {
|
---|
2513 | n_found = find_server_service_pattern(servp, browserp->pattern, 0);
|
---|
2514 | }
|
---|
2515 | ptr = JSONServices;
|
---|
2516 | *ptr = '\0';
|
---|
2517 | ptr = addJSONStart(ptr);
|
---|
2518 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2519 | if(selective)
|
---|
2520 | sprintf(str,"text: \"%s (%d/%d services, pid %d)\"",servp->name, n_found, n_services, servp->server.pid);
|
---|
2521 | else
|
---|
2522 | sprintf(str,"text: \"%s (%d services, pid %d)\"",servp->name, n_services, servp->server.pid);
|
---|
2523 | ptr = addJSONChildStart(ptr,str,1);
|
---|
2524 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2525 | servicep = servp->service_ptr;
|
---|
2526 | n = 0;
|
---|
2527 | for(i = 0; i < n_services; i++)
|
---|
2528 | {
|
---|
2529 | /*
|
---|
2530 | printf("Service type = %d\n",servicep->type);
|
---|
2531 | */
|
---|
2532 | if((!selective) || (strstr(servicep->name, browserp->pattern)))
|
---|
2533 | {
|
---|
2534 | if(servicep->type == 1)
|
---|
2535 | {
|
---|
2536 | sprintf(type_str,"%d@%s|%s|CMD", pid, node, servicep->name);
|
---|
2537 | sprintf(str,"text: \"%s\", id: \"%s\", leaf: true, icon: \"leaf_cmd.gif\"",servicep->name, type_str);
|
---|
2538 | }
|
---|
2539 | else
|
---|
2540 | {
|
---|
2541 | sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
|
---|
2542 | sprintf(str,"text: \"%s\", id: \"%s\", leaf: true",servicep->name, type_str);
|
---|
2543 | }
|
---|
2544 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2545 | n++;
|
---|
2546 | if(n < n_found)
|
---|
2547 | ptr = addJSONChildEnd(ptr,1);
|
---|
2548 | else
|
---|
2549 | ptr = addJSONChildEnd(ptr,0);
|
---|
2550 | }
|
---|
2551 | servicep++;
|
---|
2552 | }
|
---|
2553 | ptr = addJSONNodeEnd(ptr);
|
---|
2554 | ptr = addJSONChildEnd(ptr,0);
|
---|
2555 | ptr = addJSONNodeEnd(ptr);
|
---|
2556 | ptr = addJSONEnd(ptr);
|
---|
2557 | return JSONServices;
|
---|
2558 | }
|
---|
2559 |
|
---|
2560 | char *JSONSmiServices = 0;
|
---|
2561 | int JSONSmiServicesSize = 0;
|
---|
2562 |
|
---|
2563 | char *prepareJSONSmiObjectList(SERVER *servp, char *node, int pid, BROWSER *browserp)
|
---|
2564 | {
|
---|
2565 | DNS_SERVICE_INFO *servicep;
|
---|
2566 | char *ptr;
|
---|
2567 | int n_services, i;
|
---|
2568 | char str[512], type_str[512];
|
---|
2569 | int selective = 0;
|
---|
2570 | int n_found = 0, n, mode_index;
|
---|
2571 | char aux[512], *sptr, state[512], *stptr;
|
---|
2572 | OBJSTATE *smidomainp;
|
---|
2573 | int findSmiServices();
|
---|
2574 |
|
---|
2575 | printf("prepareJSONSmiObjectList name %s\n", servp->name);
|
---|
2576 | servicep = servp->service_ptr;
|
---|
2577 | n_services = servp->server.n_services;
|
---|
2578 | if(JSONSmiServicesSize == 0)
|
---|
2579 | {
|
---|
2580 | JSONSmiServicesSize = n_services*512;
|
---|
2581 | JSONSmiServices = malloc((size_t)JSONSmiServicesSize);
|
---|
2582 | }
|
---|
2583 | else if (JSONSmiServicesSize < n_services*512)
|
---|
2584 | {
|
---|
2585 | free(JSONSmiServices);
|
---|
2586 | JSONSmiServicesSize = n_services*512;
|
---|
2587 | JSONSmiServices = malloc((size_t)JSONSmiServicesSize);
|
---|
2588 | }
|
---|
2589 | if(browserp)
|
---|
2590 | {
|
---|
2591 | if(browserp->pattern[0] != '\0')
|
---|
2592 | selective = 1;
|
---|
2593 | }
|
---|
2594 | n_found = n_services;
|
---|
2595 | /*
|
---|
2596 | if(selective)
|
---|
2597 | {
|
---|
2598 | n_found = find_server_service_pattern(servp, browserp->pattern);
|
---|
2599 | }
|
---|
2600 | */
|
---|
2601 |
|
---|
2602 | n_found = findSmiServices(browserp, servp);
|
---|
2603 | smidomainp = browserp->smidomainp;
|
---|
2604 |
|
---|
2605 | printf("prepareJSONSmiObjectList1 name %s\n", servp->name);
|
---|
2606 |
|
---|
2607 |
|
---|
2608 | ptr = JSONSmiServices;
|
---|
2609 | *ptr = '\0';
|
---|
2610 | ptr = addJSONStart(ptr);
|
---|
2611 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2612 | /*
|
---|
2613 | if(selective)
|
---|
2614 | sprintf(str,"name: \"%s (%d/%d services, pid %d)\"",servp->name, n_found, n_services, servp->server.pid);
|
---|
2615 | else
|
---|
2616 | sprintf(str,"name: \"%s (%d services, pid %d)\"",servp->name, n_services, servp->server.pid);
|
---|
2617 | */
|
---|
2618 | sprintf(str,"name: \"%s (%d objects, pid %d)\"",servp->name, n_found, servp->server.pid);
|
---|
2619 | ptr = addJSONChildStart(ptr,str,1);
|
---|
2620 | ptr = addJSONNodeStart(ptr,"children");
|
---|
2621 | servicep = servp->service_ptr;
|
---|
2622 | n = 0;
|
---|
2623 | for(i = 0; i < n_services; i++)
|
---|
2624 | {
|
---|
2625 | /*
|
---|
2626 | printf("Service type = %d\n",servicep->type);
|
---|
2627 | */
|
---|
2628 | printf("prepareJSONSmiObjectList2 obj name %s\n", servicep->name);
|
---|
2629 | if((!selective) || (strstr(servicep->name, browserp->pattern)))
|
---|
2630 | {
|
---|
2631 | /*
|
---|
2632 | if(servicep->type == 1)
|
---|
2633 | {
|
---|
2634 | sprintf(type_str,"%d@%s|%s|CMD", pid, node, servicep->name);
|
---|
2635 | sprintf(str,"name: \"%s\", id: \"%s\", leaf: true, icon: \"leaf_cmd.gif\"",servicep->name, type_str);
|
---|
2636 | }
|
---|
2637 | else
|
---|
2638 | {
|
---|
2639 | sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
|
---|
2640 | sprintf(str,"name: \"%s\", state: \"RUNNING\", id: \"%s\", leaf: true",servicep->name, type_str);
|
---|
2641 | }
|
---|
2642 | */
|
---|
2643 | if(servicep->status == 2)
|
---|
2644 | {
|
---|
2645 | sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
|
---|
2646 | strcpy(aux, servicep->name);
|
---|
2647 | sptr = strchr(aux,'/');
|
---|
2648 | if(sptr)
|
---|
2649 | {
|
---|
2650 | sptr++;
|
---|
2651 | sptr = strchr(sptr,'/');
|
---|
2652 | if(sptr)
|
---|
2653 | sptr++;
|
---|
2654 | }
|
---|
2655 | strcpy(state, smidomainp[i].state);
|
---|
2656 | stptr = strchr(state,'/');
|
---|
2657 | if(stptr)
|
---|
2658 | {
|
---|
2659 | *stptr = '\0';
|
---|
2660 | }
|
---|
2661 | mode_index = smidomainp[i].mode_index;
|
---|
2662 | // sprintf(str,"name: \"%s\", state: \"%s\", id: \"%s\", leaf: true, fname: \"%s\"",sptr, state, type_str, servicep->name);
|
---|
2663 | sprintf(str,"name: \"%s\", state: \"%s\", mode: \"%s\",id: \"%s\", leaf: true, fname: \"%s\"",
|
---|
2664 | sptr, state, smidomainp[mode_index].state, type_str, servicep->name);
|
---|
2665 |
|
---|
2666 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2667 | n++;
|
---|
2668 | if(n < n_found)
|
---|
2669 | ptr = addJSONChildEnd(ptr,1);
|
---|
2670 | else
|
---|
2671 | ptr = addJSONChildEnd(ptr,0);
|
---|
2672 | }
|
---|
2673 | }
|
---|
2674 | servicep++;
|
---|
2675 | }
|
---|
2676 | ptr = addJSONNodeEnd(ptr);
|
---|
2677 | ptr = addJSONChildEnd(ptr,0);
|
---|
2678 | ptr = addJSONNodeEnd(ptr);
|
---|
2679 | ptr = addJSONEnd(ptr);
|
---|
2680 | printf("%s\n",JSONSmiServices);
|
---|
2681 | return JSONSmiServices;
|
---|
2682 | }
|
---|
2683 |
|
---|
2684 | void update_smi_state(OBJSTATE **tag, char *data, int *size)
|
---|
2685 | {
|
---|
2686 | OBJSTATE *servicep;
|
---|
2687 | time_t tsecs;
|
---|
2688 |
|
---|
2689 | if(*size){}
|
---|
2690 | servicep = *tag;
|
---|
2691 |
|
---|
2692 | if(strcmp(servicep->state, data))
|
---|
2693 | {
|
---|
2694 | strcpy(servicep->state, data);
|
---|
2695 | tsecs = time((time_t *)0);
|
---|
2696 | ((BROWSER *)(servicep->browserp))->last_changed = tsecs;
|
---|
2697 | }
|
---|
2698 | //printf("SMI State %s %s %08x\n", servicep->name, servicep->state, (unsigned int)servicep);
|
---|
2699 | }
|
---|
2700 |
|
---|
2701 | int findSmiServices(BROWSER *browserp, SERVER *servp)
|
---|
2702 | {
|
---|
2703 | DNS_SERVICE_INFO *servicep;
|
---|
2704 | int n_services, i, index;
|
---|
2705 | int n_found = 0, sid;
|
---|
2706 | int checkSmiObjName();
|
---|
2707 | int findSmiModeObj();
|
---|
2708 |
|
---|
2709 | n_services = servp->server.n_services;
|
---|
2710 | if(strcmp(browserp->curr_smidomain,servp->name))
|
---|
2711 | {
|
---|
2712 | if(browserp->curr_smidomain[0] != '\0')
|
---|
2713 | {
|
---|
2714 | // unsubscribe; free
|
---|
2715 | for(i = 0; i < browserp->curr_smidomain_size; i++)
|
---|
2716 | {
|
---|
2717 | if(browserp->smidomainp[i].sid)
|
---|
2718 | dic_release_service(browserp->smidomainp[i].sid);
|
---|
2719 | }
|
---|
2720 | free(browserp->smidomainp);
|
---|
2721 | browserp->curr_smidomain[0] = '\0';
|
---|
2722 | browserp->curr_smidomain_size = 0;
|
---|
2723 | }
|
---|
2724 | strcpy(browserp->curr_smidomain, servp->name);
|
---|
2725 | browserp->smidomainp = malloc(n_services * sizeof(OBJSTATE));
|
---|
2726 | browserp->curr_smidomain_size = n_services;
|
---|
2727 | }
|
---|
2728 | else
|
---|
2729 | return browserp->curr_smidomain_nobjs;
|
---|
2730 | servicep = servp->service_ptr;
|
---|
2731 | for(i = 0; i < n_services; i++)
|
---|
2732 | {
|
---|
2733 | browserp->smidomainp[i].sid = 0;
|
---|
2734 | browserp->smidomainp[i].state[0] = '\0';
|
---|
2735 | if(checkSmiObjName(servicep))
|
---|
2736 | {
|
---|
2737 | strcpy(browserp->smidomainp[i].name, servicep->name);
|
---|
2738 | // strcpy(browserp->smidomainp[i].state, "");
|
---|
2739 | browserp->smidomainp[i].browserp = browserp;
|
---|
2740 | //printf("address %s %08x\n",browserp->smidomainp[i].name, (unsigned int)&(browserp->smidomainp[i]));
|
---|
2741 | sid = dic_info_service(servicep->name,MONITORED,0,0,0,update_smi_state, &(browserp->smidomainp[i]),
|
---|
2742 | no_link_str, 5);
|
---|
2743 | browserp->smidomainp[i].sid = sid;
|
---|
2744 | if(servicep->status == 2)
|
---|
2745 | n_found++;
|
---|
2746 | }
|
---|
2747 | servicep++;
|
---|
2748 | }
|
---|
2749 | servicep = servp->service_ptr;
|
---|
2750 | for(i = 0; i < n_services; i++)
|
---|
2751 | {
|
---|
2752 | if(servicep->status == 2)
|
---|
2753 | {
|
---|
2754 | index = findSmiModeObj(servp->service_ptr, n_services, servicep->name);
|
---|
2755 | browserp->smidomainp[i].mode_index = index;
|
---|
2756 | }
|
---|
2757 | servicep++;
|
---|
2758 | }
|
---|
2759 | browserp->curr_smidomain_nobjs = n_found;
|
---|
2760 | return n_found;
|
---|
2761 | }
|
---|
2762 |
|
---|
2763 | int findSmiModeObj(DNS_SERVICE_INFO *serviceptr, int n_services, char *name)
|
---|
2764 | {
|
---|
2765 | int i;
|
---|
2766 | DNS_SERVICE_INFO *servicep;
|
---|
2767 | char mode_name[256], *ptr, *ptr1, *ptr2;
|
---|
2768 |
|
---|
2769 | servicep = serviceptr;
|
---|
2770 | strcpy(mode_name, name);
|
---|
2771 | ptr1 = mode_name;
|
---|
2772 | if((ptr = strstr(mode_name,"::")))
|
---|
2773 | {
|
---|
2774 | *ptr = '\0';
|
---|
2775 | ptr2 = ptr1;
|
---|
2776 | while((ptr1 = strchr(ptr1,'/')))
|
---|
2777 | {
|
---|
2778 | ptr1++;
|
---|
2779 | ptr2 = ptr1;
|
---|
2780 | }
|
---|
2781 | if(strcmp(ptr2, ptr+2))
|
---|
2782 | *ptr = ':';
|
---|
2783 | }
|
---|
2784 | strcat(mode_name,"_FWM");
|
---|
2785 | printf("Find SMI Mode %s %s\n",name, mode_name);
|
---|
2786 | for(i = 0; i < n_services; i++)
|
---|
2787 | {
|
---|
2788 | if(servicep->status == 3)
|
---|
2789 | {
|
---|
2790 | if(!strcmp(servicep->name, mode_name))
|
---|
2791 | {
|
---|
2792 | printf("Find SMI Mode index %s %s %d\n",mode_name, servicep->name, i);
|
---|
2793 | return i;
|
---|
2794 | }
|
---|
2795 | }
|
---|
2796 | servicep++;
|
---|
2797 | }
|
---|
2798 | return 0;
|
---|
2799 | }
|
---|
2800 |
|
---|
2801 | int checkSmiObjName(DNS_SERVICE_INFO *servicep)
|
---|
2802 | {
|
---|
2803 | int ismode = 0, ret = 0;
|
---|
2804 | char *name;
|
---|
2805 | int matchString();
|
---|
2806 |
|
---|
2807 | name = servicep->name;
|
---|
2808 | if(matchString(name,"SMI/*"))
|
---|
2809 | {
|
---|
2810 | ret = 1;
|
---|
2811 | if(matchString(name,"*&ALLOC*"))
|
---|
2812 | ret = 0;
|
---|
2813 | else if(matchString(name,"*/ACTIONS&PARS"))
|
---|
2814 | ret = 0;
|
---|
2815 | else if(matchString(name,"*/BUSY"))
|
---|
2816 | ret = 0;
|
---|
2817 | else if(matchString(name,"*/CMD"))
|
---|
2818 | ret = 0;
|
---|
2819 | else if(matchString(name,"*/OBJECTSET_LIST"))
|
---|
2820 | ret = 0;
|
---|
2821 | else if(matchString(name,"*/OBJECT_LIST"))
|
---|
2822 | ret = 0;
|
---|
2823 | else if(matchString(name,"*/SMI_VERSION_NUMBER"))
|
---|
2824 | ret = 0;
|
---|
2825 | else if(matchString(name,"*/SET/*"))
|
---|
2826 | ret = 0;
|
---|
2827 | // If JCOP framework
|
---|
2828 | else if(matchString(name,"*_FWDM"))
|
---|
2829 | ret = 0;
|
---|
2830 | else if(matchString(name,"*_FWCNM"))
|
---|
2831 | ret = 0;
|
---|
2832 | else if(matchString(name,"*_FWM"))
|
---|
2833 | {
|
---|
2834 | ismode = 1;
|
---|
2835 | if(matchString(name,"*::*"))
|
---|
2836 | ret = 0;
|
---|
2837 | }
|
---|
2838 | }
|
---|
2839 | if(ret)
|
---|
2840 | {
|
---|
2841 | if(ismode)
|
---|
2842 | servicep->status = 3;
|
---|
2843 | else
|
---|
2844 | servicep->status = 2;
|
---|
2845 | }
|
---|
2846 | return ret;
|
---|
2847 | }
|
---|
2848 |
|
---|
2849 | int matchString( char *wzString, char *wzPattern )
|
---|
2850 | {
|
---|
2851 | switch (*wzPattern){
|
---|
2852 | case '\0':
|
---|
2853 | return !*wzString;
|
---|
2854 | case '*':
|
---|
2855 | return matchString(wzString, wzPattern+1) ||
|
---|
2856 | ( *wzString && matchString(wzString+1, wzPattern) );
|
---|
2857 | case '?':
|
---|
2858 | return *wzString &&
|
---|
2859 | matchString(wzString+1, wzPattern+1);
|
---|
2860 | default:
|
---|
2861 | return (*wzPattern == *wzString) &&
|
---|
2862 | matchString(wzString+1, wzPattern+1);
|
---|
2863 | }
|
---|
2864 | }
|
---|
2865 |
|
---|
2866 | int get_type_size(char type)
|
---|
2867 | {
|
---|
2868 | int size;
|
---|
2869 |
|
---|
2870 | switch(type)
|
---|
2871 | {
|
---|
2872 | case 'L':
|
---|
2873 | case 'l':
|
---|
2874 | size = sizeof(long);
|
---|
2875 | break;
|
---|
2876 | case 'I':
|
---|
2877 | case 'i':
|
---|
2878 | size = sizeof(int);
|
---|
2879 | break;
|
---|
2880 | case 'S':
|
---|
2881 | case 's':
|
---|
2882 | size = sizeof(short);
|
---|
2883 | break;
|
---|
2884 | case 'F':
|
---|
2885 | case 'f':
|
---|
2886 | size = sizeof(float);
|
---|
2887 | break;
|
---|
2888 | case 'D':
|
---|
2889 | case 'd':
|
---|
2890 | size = sizeof(double);
|
---|
2891 | break;
|
---|
2892 | case 'C':
|
---|
2893 | case 'c':
|
---|
2894 | default:
|
---|
2895 | size = 1;
|
---|
2896 | }
|
---|
2897 | return(size);
|
---|
2898 | }
|
---|
2899 |
|
---|
2900 | void did_prepare_command(char *str, char *service, char *format)
|
---|
2901 | {
|
---|
2902 | char type;
|
---|
2903 | int num;
|
---|
2904 | int size, full_size = 0;
|
---|
2905 | char *ptr;
|
---|
2906 | static int last_size = 0;
|
---|
2907 | static void *last_buffer = 0;
|
---|
2908 | void *buffer_ptr;
|
---|
2909 | char *str_ptr;
|
---|
2910 | void did_read_string(char, int, void **, char **);
|
---|
2911 |
|
---|
2912 | str_ptr = str;
|
---|
2913 | ptr = format;
|
---|
2914 | while(*ptr)
|
---|
2915 | {
|
---|
2916 | type = *ptr++;
|
---|
2917 | if(*ptr == ':')
|
---|
2918 | {
|
---|
2919 | ptr++;
|
---|
2920 | size = get_type_size(type);
|
---|
2921 | sscanf(ptr, "%d", &num);
|
---|
2922 | full_size += size * num;
|
---|
2923 | if( (ptr = strchr(ptr,';')) )
|
---|
2924 | ptr++;
|
---|
2925 | else
|
---|
2926 | break;
|
---|
2927 | }
|
---|
2928 | }
|
---|
2929 |
|
---|
2930 | full_size += 256;
|
---|
2931 | if(full_size > last_size)
|
---|
2932 | {
|
---|
2933 | if(last_size)
|
---|
2934 | free(last_buffer);
|
---|
2935 | last_buffer = malloc((size_t)full_size);
|
---|
2936 | last_size = full_size;
|
---|
2937 | }
|
---|
2938 | memset(last_buffer, 0, (size_t)last_size);
|
---|
2939 | buffer_ptr = last_buffer;
|
---|
2940 | ptr = format;
|
---|
2941 | while(*ptr)
|
---|
2942 | {
|
---|
2943 | type = *ptr++;
|
---|
2944 | if(*ptr == ':')
|
---|
2945 | {
|
---|
2946 | ptr++;
|
---|
2947 | sscanf(ptr, "%d", &num);
|
---|
2948 | did_read_string(type, num, &buffer_ptr, &str_ptr);
|
---|
2949 | if(!str_ptr)
|
---|
2950 | break;
|
---|
2951 | if( (ptr = strchr(ptr,';')) )
|
---|
2952 | ptr++;
|
---|
2953 | else
|
---|
2954 | break;
|
---|
2955 | }
|
---|
2956 | else
|
---|
2957 | {
|
---|
2958 | did_read_string(type, 0, &buffer_ptr, &str_ptr);
|
---|
2959 | break;
|
---|
2960 | }
|
---|
2961 | }
|
---|
2962 | full_size = (int) ((char *)buffer_ptr - (char *)last_buffer);
|
---|
2963 | dic_cmnd_service(service,last_buffer,full_size);
|
---|
2964 | }
|
---|
2965 |
|
---|
2966 | int read_str_int(char *str)
|
---|
2967 | {
|
---|
2968 | int i;
|
---|
2969 | if((str[0] == '0') && (str[1] == 'x'))
|
---|
2970 | sscanf(str+2,"%x",&i);
|
---|
2971 | else
|
---|
2972 | sscanf(str,"%d",&i);
|
---|
2973 | return(i);
|
---|
2974 | }
|
---|
2975 |
|
---|
2976 | int read_str_char(char *str, char *cc)
|
---|
2977 | {
|
---|
2978 | int num;
|
---|
2979 |
|
---|
2980 | if(str[0] == '\'')
|
---|
2981 | *cc = str[1];
|
---|
2982 | else if(str[0] == '\"')
|
---|
2983 | return(0);
|
---|
2984 | else if((str[0] == '0') && (str[1] == 'x'))
|
---|
2985 | {
|
---|
2986 | sscanf(str+2,"%x",&num);
|
---|
2987 | if(num <= 0xff)
|
---|
2988 | *cc = (char)num;
|
---|
2989 | else
|
---|
2990 | return(-1);
|
---|
2991 | }
|
---|
2992 | else if(isalpha(str[0]))
|
---|
2993 | return(-1);
|
---|
2994 | else
|
---|
2995 | {
|
---|
2996 | sscanf(str,"%d",&num);
|
---|
2997 | if(num <= 0xff)
|
---|
2998 | *cc = (char)num;
|
---|
2999 | else
|
---|
3000 | return(-1);
|
---|
3001 | }
|
---|
3002 | return(1);
|
---|
3003 | }
|
---|
3004 |
|
---|
3005 | void did_read_string(char type, int num, void **buffer_ptr, char **str_ptr)
|
---|
3006 | {
|
---|
3007 | int i, ret = 0;
|
---|
3008 | float ff;
|
---|
3009 | double dd;
|
---|
3010 | void *ptr;
|
---|
3011 | char *strp, *ptr1;
|
---|
3012 | char cc;
|
---|
3013 | short s;
|
---|
3014 |
|
---|
3015 | strp = *str_ptr;
|
---|
3016 | ptr = *buffer_ptr;
|
---|
3017 | if(!num)
|
---|
3018 | num = 1000000;
|
---|
3019 | switch(type)
|
---|
3020 | {
|
---|
3021 | case 'L':
|
---|
3022 | case 'l':
|
---|
3023 | case 'I':
|
---|
3024 | case 'i':
|
---|
3025 | for(i = 0; i<num; i++)
|
---|
3026 | {
|
---|
3027 | *(int *)ptr = read_str_int(strp);
|
---|
3028 | ptr = (int *)ptr +1;
|
---|
3029 | if( (strp = strchr(strp,' ')) )
|
---|
3030 | strp++;
|
---|
3031 | else
|
---|
3032 | break;
|
---|
3033 | }
|
---|
3034 | break;
|
---|
3035 | case 'S':
|
---|
3036 | case 's':
|
---|
3037 | for(i = 0; i<num; i++)
|
---|
3038 | {
|
---|
3039 | s = (short)read_str_int(strp);
|
---|
3040 | *((short *)ptr) = s;
|
---|
3041 | ptr = (short *)ptr +1;
|
---|
3042 | if( (strp = strchr(strp,' ')) )
|
---|
3043 | strp++;
|
---|
3044 | else
|
---|
3045 | break;
|
---|
3046 | }
|
---|
3047 | break;
|
---|
3048 | case 'F':
|
---|
3049 | case 'f':
|
---|
3050 | for(i = 0; i<num; i++)
|
---|
3051 | {
|
---|
3052 | sscanf(strp,"%f",&ff);
|
---|
3053 | *(float *)ptr = ff;
|
---|
3054 | ptr = (float *)ptr +1;
|
---|
3055 | if( (strp = strchr(strp,' ')) )
|
---|
3056 | strp++;
|
---|
3057 | else
|
---|
3058 | break;
|
---|
3059 | }
|
---|
3060 | break;
|
---|
3061 | case 'D':
|
---|
3062 | case 'd':
|
---|
3063 | for(i = 0; i<num; i++)
|
---|
3064 | {
|
---|
3065 | sscanf(strp,"%f",&ff);
|
---|
3066 | dd = (double)ff;
|
---|
3067 | *(double *)ptr = dd;
|
---|
3068 | ptr = (double *)ptr +1;
|
---|
3069 | if( (strp = strchr(strp,' ')) )
|
---|
3070 | strp++;
|
---|
3071 | else
|
---|
3072 | break;
|
---|
3073 | }
|
---|
3074 | break;
|
---|
3075 | case 'C':
|
---|
3076 | case 'c':
|
---|
3077 | default:
|
---|
3078 | for(i = 0; i<num; i++)
|
---|
3079 | {
|
---|
3080 | if((ret = read_str_char(strp, &cc)) <= 0)
|
---|
3081 | break;
|
---|
3082 | *(char *)ptr = cc;
|
---|
3083 | ptr = (char *)ptr +1;
|
---|
3084 | if( (strp = strchr(strp,' ')) )
|
---|
3085 | strp++;
|
---|
3086 | else
|
---|
3087 | break;
|
---|
3088 | }
|
---|
3089 | if(ret <= 0)
|
---|
3090 | {
|
---|
3091 | if(!ret)
|
---|
3092 | {
|
---|
3093 | strp++;
|
---|
3094 | }
|
---|
3095 | num = (int)strlen(strp)+1;
|
---|
3096 | strncpy((char *)ptr,strp,(size_t)num);
|
---|
3097 | if( (ptr1 = (char *)strchr((char *)ptr,'\"')) )
|
---|
3098 | {
|
---|
3099 | num--;
|
---|
3100 | *ptr1 = '\0';
|
---|
3101 | }
|
---|
3102 | ptr = (char *)ptr + num;
|
---|
3103 | if( (strp = strchr(strp,' ')) )
|
---|
3104 | strp++;
|
---|
3105 | else
|
---|
3106 | break;
|
---|
3107 | }
|
---|
3108 | }
|
---|
3109 | *buffer_ptr = ptr;
|
---|
3110 | *str_ptr = strp;
|
---|
3111 | }
|
---|