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 | extern int WebDID_Debug;
|
---|
9 |
|
---|
10 | typedef struct item{
|
---|
11 | struct item *next;
|
---|
12 | DNS_SERVER_INFO server;
|
---|
13 | DNS_SERVICE_INFO *service_ptr;
|
---|
14 | char name[MAX_NAME];
|
---|
15 | int match;
|
---|
16 | int busy;
|
---|
17 | int isSMI;
|
---|
18 | }SERVER;
|
---|
19 |
|
---|
20 | typedef struct nitem{
|
---|
21 | struct nitem *next;
|
---|
22 | SERVER *server_head;
|
---|
23 | char name[MAX_NAME];
|
---|
24 | int match;
|
---|
25 | int busy;
|
---|
26 | int hasSMI;
|
---|
27 | }NODE;
|
---|
28 | NODE *Node_head = (NODE *)0;
|
---|
29 |
|
---|
30 | typedef struct sitem{
|
---|
31 | struct sitem *next;
|
---|
32 | char name[MAX_NAME];
|
---|
33 | int sid;
|
---|
34 | void *buffer;
|
---|
35 | int buffer_size;
|
---|
36 | int size;
|
---|
37 | time_t timestamp;
|
---|
38 | void *buffer_str;
|
---|
39 | int buffer_str_size;
|
---|
40 | int str_size;
|
---|
41 | int conn_id;
|
---|
42 | time_t last_subscribed;
|
---|
43 | time_t last_updated;
|
---|
44 | int n_browsers;
|
---|
45 | }CURR_SERVICE;
|
---|
46 | CURR_SERVICE *Curr_service_head = (CURR_SERVICE *)0;
|
---|
47 |
|
---|
48 | typedef struct objstate{
|
---|
49 | char name[MAX_NAME];
|
---|
50 | char state[512];
|
---|
51 | int sid;
|
---|
52 | int mode_index;
|
---|
53 | void *browserp;
|
---|
54 | }OBJSTATE;
|
---|
55 | /*
|
---|
56 | typedef struct domainitem{
|
---|
57 | char name[MAX_NAME];
|
---|
58 | OBJSTATE objs[1];
|
---|
59 | }CURR_SMIDOMAIN;
|
---|
60 | */
|
---|
61 | typedef struct bitem{
|
---|
62 | struct bitem *next;
|
---|
63 | int id;
|
---|
64 | int subscribe;
|
---|
65 | time_t last_subscribed;
|
---|
66 | time_t last_updated;
|
---|
67 | time_t last_polled;
|
---|
68 | time_t last_changed;
|
---|
69 | int conn_id;
|
---|
70 | int n_services;
|
---|
71 | int n_servers;
|
---|
72 | int n_nodes;
|
---|
73 | CURR_SERVICE *servicep;
|
---|
74 | char *JSONBuffer;
|
---|
75 | int JSONBufferSize;
|
---|
76 | char *JSONSmiBuffer;
|
---|
77 | int JSONSmiBufferSize;
|
---|
78 | char pattern[256];
|
---|
79 | char curr_command[MAX_NAME];
|
---|
80 | char *service_format_ptr;
|
---|
81 | int isSMI;
|
---|
82 | int n_domains;
|
---|
83 | char curr_smidomain[MAX_NAME];
|
---|
84 | int curr_smidomain_size;
|
---|
85 | int curr_smidomain_nobjs;
|
---|
86 | OBJSTATE *smidomainp;
|
---|
87 | }BROWSER;
|
---|
88 | BROWSER *Browser_head = (BROWSER *)0;
|
---|
89 |
|
---|
90 | char *JSONBuffer = 0;
|
---|
91 | int JSONBufferSize = 0;
|
---|
92 | char JSONHeader[256] = {'\0'};
|
---|
93 | char JSONSmiHeader[256] = {'\0'};
|
---|
94 |
|
---|
95 | char *JSONSmiBuffer = 0;
|
---|
96 | int JSONSmiBufferSize = 0;
|
---|
97 |
|
---|
98 | int First_time = 1;
|
---|
99 | int Curr_view_opt = -1;
|
---|
100 | char Curr_view_opt_par[80];
|
---|
101 | char Curr_service_name[132];
|
---|
102 | char Curr_service_format[256];
|
---|
103 | int Curr_service_print_type = 0;
|
---|
104 | int N_nodes = 0;
|
---|
105 | int N_servers = 0;
|
---|
106 | int N_services = 0;
|
---|
107 | static char no_link = -1;
|
---|
108 | static char no_link_str[5] = "DEAD";
|
---|
109 | int no_link_int = -1;
|
---|
110 | FILE *fptr;
|
---|
111 |
|
---|
112 | char *Service_content_str;
|
---|
113 | char *Curr_service_list = 0;
|
---|
114 | char *Curr_client_list = 0;
|
---|
115 | int Curr_service_id = 0;
|
---|
116 | SERVER *Got_Service_List = 0;
|
---|
117 | SERVER *Got_Client_List = 0;
|
---|
118 |
|
---|
119 | int Timer_q;
|
---|
120 | char Title[128];
|
---|
121 |
|
---|
122 | int did_init(char *local_node, int dns_port)
|
---|
123 | {
|
---|
124 | void update_servers();
|
---|
125 | char icon_title[128];
|
---|
126 | char dns_node[128];
|
---|
127 | int ret;
|
---|
128 |
|
---|
129 | dim_init();
|
---|
130 | dic_disable_padding();
|
---|
131 | dis_disable_padding();
|
---|
132 |
|
---|
133 | ret = dim_get_dns_node(dns_node);
|
---|
134 | if(!ret)
|
---|
135 | {
|
---|
136 | strcpy(dns_node, local_node);
|
---|
137 | dim_set_dns_node(dns_node);
|
---|
138 | }
|
---|
139 | dns_port = dic_get_dns_port();
|
---|
140 | if(dns_port != DNS_PORT)
|
---|
141 | {
|
---|
142 | sprintf(Title,"DIM DNS: %s:%d",dns_node,dns_port);
|
---|
143 | }
|
---|
144 | else
|
---|
145 | {
|
---|
146 | sprintf(Title,"DIM DNS: %s",dns_node);
|
---|
147 | }
|
---|
148 | sprintf(icon_title,"DID %s",dns_node);
|
---|
149 | dim_print_date_time();
|
---|
150 | printf("webDid Starting up on %s\n\t serving %s\n", local_node, Title);
|
---|
151 | Timer_q = dtq_create();
|
---|
152 | dic_info_service("DIS_DNS/SERVER_INFO",MONITORED,0,0,0,update_servers,0,
|
---|
153 | &no_link,1);
|
---|
154 | return 1;
|
---|
155 | }
|
---|
156 |
|
---|
157 | SERVER *find_server(NODE *nodep, int pid)
|
---|
158 | {
|
---|
159 | SERVER *servp;
|
---|
160 | DNS_SERVER_INFO *ptr;
|
---|
161 |
|
---|
162 | servp = nodep->server_head;
|
---|
163 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
164 | {
|
---|
165 | ptr = &servp->server;
|
---|
166 | if(ptr->pid == pid)
|
---|
167 | {
|
---|
168 | return(servp);
|
---|
169 | }
|
---|
170 | }
|
---|
171 | return ((SERVER *)0);
|
---|
172 | }
|
---|
173 |
|
---|
174 | NODE *find_node(char *node)
|
---|
175 | {
|
---|
176 | NODE *nodep;
|
---|
177 |
|
---|
178 | nodep = Node_head;
|
---|
179 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
180 | {
|
---|
181 | if(!strcmp(nodep->name,node))
|
---|
182 | {
|
---|
183 | return(nodep);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | return ((NODE *)0);
|
---|
187 | }
|
---|
188 |
|
---|
189 | int find_server_service_pattern(SERVER *servp, char *pattern)
|
---|
190 | {
|
---|
191 | DNS_SERVICE_INFO *servicep;
|
---|
192 | int n_services, i;
|
---|
193 | int n_found = 0;
|
---|
194 |
|
---|
195 | servicep = servp->service_ptr;
|
---|
196 | n_services = servp->server.n_services;
|
---|
197 | for(i = 0; i < n_services; i++)
|
---|
198 | {
|
---|
199 | if(strstr(servicep->name, pattern))
|
---|
200 | {
|
---|
201 | n_found++;
|
---|
202 | }
|
---|
203 | servicep++;
|
---|
204 | }
|
---|
205 | return(n_found);
|
---|
206 | }
|
---|
207 |
|
---|
208 | int find_service_pattern(NODE *nodep, SERVER *servpp, char *pattern, int *n_servers)
|
---|
209 | {
|
---|
210 | SERVER *servp;
|
---|
211 | int ret, n_found = 0;
|
---|
212 | int n_servers_found = 0;
|
---|
213 |
|
---|
214 | if(!servpp)
|
---|
215 | {
|
---|
216 | servp = nodep->server_head;
|
---|
217 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
218 | {
|
---|
219 | if((ret = find_server_service_pattern(servp, pattern)))
|
---|
220 | {
|
---|
221 | n_found += ret;
|
---|
222 | n_servers_found++;
|
---|
223 | }
|
---|
224 | }
|
---|
225 | }
|
---|
226 | else
|
---|
227 | {
|
---|
228 | if((ret = find_server_service_pattern(servpp, pattern)))
|
---|
229 | {
|
---|
230 | n_found += ret;
|
---|
231 | }
|
---|
232 | }
|
---|
233 | if(n_servers != 0)
|
---|
234 | *n_servers = n_servers_found;
|
---|
235 | return(n_found);
|
---|
236 | }
|
---|
237 |
|
---|
238 | CURR_SERVICE *find_curr_service(char *service)
|
---|
239 | {
|
---|
240 | CURR_SERVICE *servicep;
|
---|
241 |
|
---|
242 | servicep = Curr_service_head ;
|
---|
243 | while( (servicep = (CURR_SERVICE *)sll_get_next((SLL *)servicep)) )
|
---|
244 | {
|
---|
245 | if(!strcmp(servicep->name,service))
|
---|
246 | {
|
---|
247 | return(servicep);
|
---|
248 | }
|
---|
249 | }
|
---|
250 | return ((CURR_SERVICE *)0);
|
---|
251 | }
|
---|
252 |
|
---|
253 | BROWSER *find_browser(int id)
|
---|
254 | {
|
---|
255 | BROWSER *browserp;
|
---|
256 |
|
---|
257 | browserp = Browser_head;
|
---|
258 | while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
|
---|
259 | {
|
---|
260 | if(browserp->id == id)
|
---|
261 | {
|
---|
262 | return(browserp);
|
---|
263 | }
|
---|
264 | }
|
---|
265 | return ((BROWSER *)0);
|
---|
266 | }
|
---|
267 | /*
|
---|
268 | void set_browser_changes(int n_services, int n_servers, int n_nodes)
|
---|
269 | {
|
---|
270 | BROWSER *browserp;
|
---|
271 |
|
---|
272 | browserp = Browser_head;
|
---|
273 | while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
|
---|
274 | {
|
---|
275 | if(browserp->n_services != n_services)
|
---|
276 | browserp->n_services_changed = 1;
|
---|
277 | if(browserp->n_servers != n_servers)
|
---|
278 | browserp->n_servers_changed = 1;
|
---|
279 | if(browserp->n_nodes != n_nodes)
|
---|
280 | browserp->n_nodes_changed = 1;
|
---|
281 | }
|
---|
282 | }
|
---|
283 | */
|
---|
284 | void prepare_browser_tree()
|
---|
285 | {
|
---|
286 | BROWSER *browserp;
|
---|
287 | int prepareJSONTree();
|
---|
288 |
|
---|
289 | browserp = Browser_head;
|
---|
290 | while( (browserp = (BROWSER *)sll_get_next((SLL *)browserp)) )
|
---|
291 | {
|
---|
292 | if(browserp->pattern[0] != '\0')
|
---|
293 | prepareJSONTree(browserp);
|
---|
294 | }
|
---|
295 | }
|
---|
296 | /*
|
---|
297 | void clear_browser_changes(BROWSER *browserp)
|
---|
298 | {
|
---|
299 | browserp->n_services_changed = 0;
|
---|
300 | browserp->n_servers_changed = 0;
|
---|
301 | browserp->n_nodes_changed = 0;
|
---|
302 | }
|
---|
303 | */
|
---|
304 | void update_servers(int *tag, DNS_DID *buffer, int *size)
|
---|
305 | {
|
---|
306 | int n_services, service_size;
|
---|
307 | SERVER *servp;
|
---|
308 | NODE *nodep;
|
---|
309 | int j;
|
---|
310 | char str[MAX_NAME], sname[MAX_NAME], *ptr;
|
---|
311 | int prepareJSONTree();
|
---|
312 | int prepareJSONHeader();
|
---|
313 |
|
---|
314 | if(tag){}
|
---|
315 | if(!Node_head)
|
---|
316 | {
|
---|
317 | Node_head = (NODE *)malloc(sizeof(NODE));
|
---|
318 | sll_init((SLL *)Node_head);
|
---|
319 | }
|
---|
320 | if(First_time)
|
---|
321 | {
|
---|
322 | First_time = 0;
|
---|
323 | }
|
---|
324 |
|
---|
325 | if(!*size)
|
---|
326 | return;
|
---|
327 | if(*(char *)buffer == -1)
|
---|
328 | {
|
---|
329 | N_servers = 0;
|
---|
330 | N_services = 0;
|
---|
331 | return;
|
---|
332 | }
|
---|
333 | buffer->server.n_services = vtohl(buffer->server.n_services);
|
---|
334 | buffer->server.pid = vtohl(buffer->server.pid);
|
---|
335 | n_services = buffer->server.n_services;
|
---|
336 |
|
---|
337 | if(n_services == 1)
|
---|
338 | return;
|
---|
339 | strcpy(sname, buffer->server.task);
|
---|
340 | if(n_services > 1)
|
---|
341 | {
|
---|
342 | for(j = 0; j < n_services; j++)
|
---|
343 | {
|
---|
344 | buffer->services[j].type = vtohl(
|
---|
345 | buffer->services[j].type);
|
---|
346 | buffer->services[j].status = vtohl(
|
---|
347 | buffer->services[j].status);
|
---|
348 | buffer->services[j].n_clients = vtohl(
|
---|
349 | buffer->services[j].n_clients);
|
---|
350 | if((int)strlen(sname) == MAX_TASK_NAME-4-1)
|
---|
351 | {
|
---|
352 | strcpy(str,buffer->services[j].name);
|
---|
353 | if( (ptr = strstr(str,"/CLIENT_LIST")) )
|
---|
354 | {
|
---|
355 | *ptr = '\0';
|
---|
356 | strcpy(sname,str);
|
---|
357 | }
|
---|
358 | }
|
---|
359 | }
|
---|
360 | }
|
---|
361 | if (!(nodep = find_node(buffer->server.node)))
|
---|
362 | {
|
---|
363 | if(n_services)
|
---|
364 | {
|
---|
365 | N_nodes++;
|
---|
366 | nodep = (NODE *)malloc(sizeof(NODE));
|
---|
367 | strcpy(nodep->name,buffer->server.node);
|
---|
368 | nodep->hasSMI = 0;
|
---|
369 | nodep->server_head = (SERVER *)malloc(sizeof(SERVER));
|
---|
370 | sll_init((SLL *)nodep->server_head);
|
---|
371 | sll_insert_queue((SLL *)Node_head,(SLL *)nodep);
|
---|
372 | }
|
---|
373 | }
|
---|
374 | if (!(servp = find_server(nodep,buffer->server.pid)))
|
---|
375 | {
|
---|
376 | if(n_services)
|
---|
377 | {
|
---|
378 | servp = (SERVER *)malloc(sizeof(SERVER));
|
---|
379 | strcpy(servp->name,sname);
|
---|
380 | servp->next = 0;
|
---|
381 | servp->busy = 0;
|
---|
382 | servp->server.n_services = 0;
|
---|
383 | servp->service_ptr = 0;
|
---|
384 | servp->isSMI = 0;
|
---|
385 | if(strstr(sname,"_SMI"))
|
---|
386 | {
|
---|
387 | servp->isSMI = 1;
|
---|
388 | nodep->hasSMI = 1;
|
---|
389 | }
|
---|
390 | sll_insert_queue((SLL *)nodep->server_head,(SLL *)servp);
|
---|
391 | }
|
---|
392 | }
|
---|
393 | if(n_services != 0)
|
---|
394 | {
|
---|
395 | if(n_services == servp->server.n_services)
|
---|
396 | {
|
---|
397 | return;
|
---|
398 | }
|
---|
399 | if(servp->server.n_services == 0)
|
---|
400 | N_servers++;
|
---|
401 | if(servp->server.n_services != -1)
|
---|
402 | N_services -= servp->server.n_services;
|
---|
403 | memcpy(&servp->server,&buffer->server,sizeof(DNS_SERVER_INFO));
|
---|
404 | if(servp->service_ptr)
|
---|
405 | {
|
---|
406 | free(servp->service_ptr);
|
---|
407 | servp->service_ptr = 0;
|
---|
408 | }
|
---|
409 | if(n_services != -1)
|
---|
410 | {
|
---|
411 | service_size = n_services*(int)sizeof(DNS_SERVICE_INFO);
|
---|
412 | servp->service_ptr = (DNS_SERVICE_INFO *)malloc((size_t)service_size);
|
---|
413 | memcpy(servp->service_ptr, buffer->services, (size_t)service_size);
|
---|
414 | N_services += n_services;
|
---|
415 | }
|
---|
416 | servp->busy = 1;
|
---|
417 | }
|
---|
418 | else
|
---|
419 | {
|
---|
420 | if(servp)
|
---|
421 | {
|
---|
422 | N_servers--;
|
---|
423 | if(servp->server.n_services != -1)
|
---|
424 | {
|
---|
425 | N_services -= servp->server.n_services;
|
---|
426 | }
|
---|
427 | servp->server.n_services = 0;
|
---|
428 | servp->busy = -1;
|
---|
429 | servp->isSMI = 0;
|
---|
430 | }
|
---|
431 | }
|
---|
432 | if(JSONHeader[0])
|
---|
433 | prepareJSONHeader();
|
---|
434 | }
|
---|
435 |
|
---|
436 | void got_update_services(BROWSER **tag, char *buffer, int *size)
|
---|
437 | {
|
---|
438 | BROWSER *browserp;
|
---|
439 |
|
---|
440 | if(size){}
|
---|
441 | browserp = (BROWSER *)*tag;
|
---|
442 | if(browserp->service_format_ptr)
|
---|
443 | free(browserp->service_format_ptr);
|
---|
444 | browserp->service_format_ptr = (char *)malloc(strlen(buffer)+1);
|
---|
445 | strcpy(browserp->service_format_ptr, buffer);
|
---|
446 | }
|
---|
447 |
|
---|
448 | char *update_services(char *node, char *server, int pid, int browser)
|
---|
449 | {
|
---|
450 | char str[MAX_NAME];
|
---|
451 | NODE *nodep;
|
---|
452 | SERVER *servp;
|
---|
453 | char *ptr = 0;
|
---|
454 | BROWSER *browserp;
|
---|
455 | char *prepareJSONServiceList();
|
---|
456 | BROWSER *create_browser();
|
---|
457 |
|
---|
458 | if(!(browserp = find_browser(browser)))
|
---|
459 | browserp = create_browser(browser);
|
---|
460 |
|
---|
461 | if(server){}
|
---|
462 | sprintf(str,"%s/SERVICE_LIST",server);
|
---|
463 | dic_info_service(str,ONCE_ONLY,20,0,0,
|
---|
464 | got_update_services,(dim_long)browserp,"None",5);
|
---|
465 | if((nodep = find_node(node)))
|
---|
466 | {
|
---|
467 | if((servp = find_server(nodep, pid)))
|
---|
468 | {
|
---|
469 | ptr = prepareJSONServiceList(servp, node, pid, browserp);
|
---|
470 | }
|
---|
471 | }
|
---|
472 | return ptr;
|
---|
473 | }
|
---|
474 |
|
---|
475 | void got_update_smi_objects(BROWSER **tag, char *buffer, int *size)
|
---|
476 | {
|
---|
477 | BROWSER *browserp;
|
---|
478 |
|
---|
479 | if(size){}
|
---|
480 | browserp = (BROWSER *)*tag;
|
---|
481 | if(browserp->service_format_ptr)
|
---|
482 | free(browserp->service_format_ptr);
|
---|
483 | browserp->service_format_ptr = (char *)malloc(strlen(buffer)+1);
|
---|
484 | strcpy(browserp->service_format_ptr, buffer);
|
---|
485 | }
|
---|
486 |
|
---|
487 | char *update_smi_objects(char *node, char *server, int pid, int browser)
|
---|
488 | {
|
---|
489 | char str[MAX_NAME];
|
---|
490 | NODE *nodep;
|
---|
491 | SERVER *servp;
|
---|
492 | char *ptr = 0;
|
---|
493 | BROWSER *browserp;
|
---|
494 | char *prepareJSONSmiObjectList();
|
---|
495 | BROWSER *create_browser();
|
---|
496 |
|
---|
497 | if(!(browserp = find_browser(browser)))
|
---|
498 | {
|
---|
499 | browserp = create_browser(browser);
|
---|
500 | browserp->isSMI = 1;
|
---|
501 | }
|
---|
502 | if(server){}
|
---|
503 | sprintf(str,"%s/SERVICE_LIST",server);
|
---|
504 | dic_info_service(str,ONCE_ONLY,20,0,0,
|
---|
505 | got_update_smi_objects,(dim_long)browserp,"None",5);
|
---|
506 | if((nodep = find_node(node)))
|
---|
507 | {
|
---|
508 | if((servp = find_server(nodep, pid)))
|
---|
509 | {
|
---|
510 | ptr = prepareJSONSmiObjectList(servp, node, pid, browserp);
|
---|
511 | }
|
---|
512 | }
|
---|
513 | return ptr;
|
---|
514 | }
|
---|
515 |
|
---|
516 | void get_curr_service_format()
|
---|
517 | {
|
---|
518 | char *format;
|
---|
519 | char *dic_get_format();
|
---|
520 | /*
|
---|
521 | char str[256], *ptr, *ptr1;
|
---|
522 | int rpc_flag;
|
---|
523 |
|
---|
524 | strcpy(str,Curr_service_name);
|
---|
525 | rpc_flag = 0;
|
---|
526 | if( (ptr = strstr(str,"/RpcIn")) )
|
---|
527 | {
|
---|
528 | *ptr = '\0';
|
---|
529 | rpc_flag = 1;
|
---|
530 | }
|
---|
531 | if( (ptr = strstr(str,"/RpcOut")) )
|
---|
532 | {
|
---|
533 | *ptr = '\0';
|
---|
534 | rpc_flag = 2;
|
---|
535 | }
|
---|
536 | strcat(str,"|");
|
---|
537 | */
|
---|
538 | format = dic_get_format(0);
|
---|
539 | /*
|
---|
540 | if( (ptr = strstr(Curr_service_list,str)) )
|
---|
541 | {
|
---|
542 | if(!rpc_flag)
|
---|
543 | {
|
---|
544 | ptr += (int)strlen(str);
|
---|
545 | ptr1 = strchr(ptr,'|');
|
---|
546 | }
|
---|
547 | else if(rpc_flag == 1)
|
---|
548 | {
|
---|
549 | ptr += (int)strlen(str);
|
---|
550 | ptr1 = strchr(ptr,',');
|
---|
551 | }
|
---|
552 | else
|
---|
553 | {
|
---|
554 | ptr += (int)strlen(str);
|
---|
555 | ptr = strchr(ptr,',');
|
---|
556 | ptr++;
|
---|
557 | ptr1 = strchr(ptr,'|');
|
---|
558 | }
|
---|
559 | strncpy(Curr_service_format,ptr,(int)(ptr1 - ptr));
|
---|
560 | Curr_service_format[(int)(ptr1-ptr)] = '\0';
|
---|
561 | }
|
---|
562 | */
|
---|
563 | if(format)
|
---|
564 | strcpy(Curr_service_format,format);
|
---|
565 | else
|
---|
566 | Curr_service_format[0] = '\0';
|
---|
567 | }
|
---|
568 |
|
---|
569 | void get_service_format(char *buffer, char *service, char *format)
|
---|
570 | {
|
---|
571 | char str[256], *ptr, *ptr1;
|
---|
572 | int rpc_flag;
|
---|
573 |
|
---|
574 | strcpy(str, service);
|
---|
575 | rpc_flag = 0;
|
---|
576 | *format = '\0';
|
---|
577 | if( (ptr = strstr(str,"/RpcIn")) )
|
---|
578 | {
|
---|
579 | *ptr = '\0';
|
---|
580 | rpc_flag = 1;
|
---|
581 | }
|
---|
582 | if( (ptr = strstr(str,"/RpcOut")) )
|
---|
583 | {
|
---|
584 | *ptr = '\0';
|
---|
585 | rpc_flag = 2;
|
---|
586 | }
|
---|
587 | strcat(str,"|");
|
---|
588 | if( (ptr = strstr(buffer, str)) )
|
---|
589 | {
|
---|
590 | if(!rpc_flag)
|
---|
591 | {
|
---|
592 | ptr += (int)strlen(str);
|
---|
593 | ptr1 = strchr(ptr,'|');
|
---|
594 | }
|
---|
595 | else if(rpc_flag == 1)
|
---|
596 | {
|
---|
597 | ptr += (int)strlen(str);
|
---|
598 | ptr1 = strchr(ptr,',');
|
---|
599 | }
|
---|
600 | else
|
---|
601 | {
|
---|
602 | ptr += (int)strlen(str);
|
---|
603 | ptr = strchr(ptr,',');
|
---|
604 | ptr++;
|
---|
605 | ptr1 = strchr(ptr,'|');
|
---|
606 | }
|
---|
607 | strncpy(format,ptr,(size_t)(ptr1 - ptr));
|
---|
608 | format[(int)(ptr1-ptr)] = '\0';
|
---|
609 | }
|
---|
610 | }
|
---|
611 |
|
---|
612 | int delete_curr_service(CURR_SERVICE *servicep)
|
---|
613 | {
|
---|
614 |
|
---|
615 | if(WebDID_Debug)
|
---|
616 | printf("\nUnsubscribing %s\n\n",servicep->name);
|
---|
617 | dic_release_service(servicep->sid);
|
---|
618 | if(servicep->buffer_size)
|
---|
619 | free(servicep->buffer);
|
---|
620 | if(servicep->buffer_str_size)
|
---|
621 | free(servicep->buffer_str);
|
---|
622 | sll_remove((SLL *)Curr_service_head, (SLL *)servicep);
|
---|
623 | free(servicep);
|
---|
624 | return(1);
|
---|
625 | }
|
---|
626 |
|
---|
627 | int delete_browser(BROWSER *browserp)
|
---|
628 | {
|
---|
629 | CURR_SERVICE *servicep;
|
---|
630 |
|
---|
631 | if((servicep = browserp->servicep))
|
---|
632 | {
|
---|
633 | servicep->n_browsers--;
|
---|
634 | if(!servicep->n_browsers)
|
---|
635 | delete_curr_service(servicep);
|
---|
636 | }
|
---|
637 | if(browserp->service_format_ptr)
|
---|
638 | free(browserp->service_format_ptr);
|
---|
639 | sll_remove((SLL *)Browser_head, (SLL *)browserp);
|
---|
640 | free(browserp);
|
---|
641 | return(1);
|
---|
642 | }
|
---|
643 |
|
---|
644 | void check_browser( BROWSER *tag)
|
---|
645 | {
|
---|
646 | BROWSER *browserp;
|
---|
647 | time_t tsecs;
|
---|
648 |
|
---|
649 | browserp = (BROWSER *)tag;
|
---|
650 | if(WebDID_Debug)
|
---|
651 | printf("\nCheck_browser %d\n",browserp->id);
|
---|
652 | tsecs = time((time_t *)0);
|
---|
653 | if((tsecs - browserp->last_polled) > 20)
|
---|
654 | {
|
---|
655 | if(WebDID_Debug)
|
---|
656 | printf("\nDeleting browser %d\n\n",browserp->id);
|
---|
657 | delete_browser(browserp);
|
---|
658 | }
|
---|
659 | else
|
---|
660 | dtq_start_timer(10, check_browser, browserp);
|
---|
661 | }
|
---|
662 |
|
---|
663 | BROWSER *create_browser(int id)
|
---|
664 | {
|
---|
665 | BROWSER *browserp;
|
---|
666 |
|
---|
667 | if(!Browser_head)
|
---|
668 | {
|
---|
669 | Browser_head = (BROWSER *)malloc(sizeof(BROWSER));
|
---|
670 | sll_init((SLL *)Browser_head);
|
---|
671 | }
|
---|
672 | browserp = (BROWSER *)malloc(sizeof(BROWSER));
|
---|
673 | browserp->id = id;
|
---|
674 | browserp->last_subscribed = 0;
|
---|
675 | browserp->last_updated = 0;
|
---|
676 | browserp->last_polled = 0;
|
---|
677 | browserp->last_changed = 0;
|
---|
678 | browserp->n_nodes = 0;
|
---|
679 | browserp->n_servers = 0;
|
---|
680 | browserp->n_services = 0;
|
---|
681 | browserp->servicep = 0;
|
---|
682 | browserp->JSONBuffer = 0;
|
---|
683 | browserp->JSONBufferSize = 0;
|
---|
684 | browserp->JSONSmiBuffer = 0;
|
---|
685 | browserp->JSONSmiBufferSize = 0;
|
---|
686 | browserp->pattern[0] = '\0';
|
---|
687 | browserp->service_format_ptr = 0;
|
---|
688 | browserp->curr_command[0] = '\0';
|
---|
689 | browserp->curr_smidomain[0] = '\0';
|
---|
690 | browserp->smidomainp = 0;
|
---|
691 | sll_insert_queue((SLL *)Browser_head,(SLL *)browserp);
|
---|
692 | dtq_start_timer(10, check_browser, browserp);
|
---|
693 | return browserp;
|
---|
694 | }
|
---|
695 |
|
---|
696 | int update_command_data(char *service, int conn_id, BROWSER *browserp)
|
---|
697 | {
|
---|
698 | char format[MAX_NAME];
|
---|
699 | char answer[MAX_NAME*3];
|
---|
700 | extern void sendData();
|
---|
701 |
|
---|
702 | if(browserp->service_format_ptr)
|
---|
703 | {
|
---|
704 | get_service_format(browserp->service_format_ptr, service, format);
|
---|
705 | if(WebDID_Debug)
|
---|
706 | printf("CMD data %s %s\n",service,format);
|
---|
707 | }
|
---|
708 | else
|
---|
709 | {
|
---|
710 | strcpy(format,"?");
|
---|
711 | }
|
---|
712 | strcpy(browserp->curr_command, service);
|
---|
713 | sprintf(answer,"To %s (%s)",service, format);
|
---|
714 | sendData(conn_id, answer, 4);
|
---|
715 | return 1;
|
---|
716 | }
|
---|
717 |
|
---|
718 | int update_service_data(char *service, int conn_id, int subscribe, int req, int browser, int force)
|
---|
719 | {
|
---|
720 | CURR_SERVICE *servicep;
|
---|
721 | time_t tsecs;
|
---|
722 | void recv_service_info();
|
---|
723 | extern void sendData();
|
---|
724 | BROWSER *browserp;
|
---|
725 |
|
---|
726 | if(req){}
|
---|
727 | if(!Curr_service_head)
|
---|
728 | {
|
---|
729 | Curr_service_head = (CURR_SERVICE *)malloc(sizeof(CURR_SERVICE));
|
---|
730 | sll_init((SLL *)Curr_service_head);
|
---|
731 | }
|
---|
732 | if(!(browserp = find_browser(browser)))
|
---|
733 | browserp = create_browser(browser);
|
---|
734 | if(force == -1)
|
---|
735 | {
|
---|
736 | update_command_data(service, conn_id, browserp);
|
---|
737 | return 1;
|
---|
738 | }
|
---|
739 | if((servicep = browserp->servicep))
|
---|
740 | {
|
---|
741 | servicep->n_browsers--;
|
---|
742 | if(!servicep->n_browsers)
|
---|
743 | delete_curr_service(servicep);
|
---|
744 | }
|
---|
745 | if(!(servicep = find_curr_service(service)))
|
---|
746 | {
|
---|
747 | servicep = (CURR_SERVICE *)malloc(sizeof(CURR_SERVICE));
|
---|
748 | strcpy(servicep->name,service);
|
---|
749 | servicep->conn_id = conn_id;
|
---|
750 | servicep->buffer = 0;
|
---|
751 | servicep->buffer_size = 0;
|
---|
752 | servicep->size = 0;
|
---|
753 | servicep->buffer_str = 0;
|
---|
754 | servicep->buffer_str_size = 0;
|
---|
755 | servicep->str_size = 0;
|
---|
756 | servicep->last_updated = 0;
|
---|
757 | tsecs = time((time_t *)0);
|
---|
758 | browserp->last_subscribed = tsecs;
|
---|
759 | browserp->last_updated = tsecs;
|
---|
760 | servicep->last_subscribed = tsecs;
|
---|
761 | servicep->n_browsers = 0;
|
---|
762 | sll_insert_queue((SLL *)Curr_service_head,(SLL *)servicep);
|
---|
763 | servicep->sid = (int)dic_info_service_stamped( service, MONITORED, subscribe, 0, 0,
|
---|
764 | recv_service_info, servicep, &no_link_int, 4);
|
---|
765 | }
|
---|
766 | else
|
---|
767 | {
|
---|
768 | if(servicep->size)
|
---|
769 | {
|
---|
770 | if((servicep->timestamp > browserp->last_updated) || (force))
|
---|
771 | {
|
---|
772 | sendData(conn_id, servicep->buffer_str, 4);
|
---|
773 | }
|
---|
774 | else
|
---|
775 | {
|
---|
776 | sendData(conn_id, "", 4);
|
---|
777 | }
|
---|
778 | browserp->last_updated = servicep->timestamp;
|
---|
779 | }
|
---|
780 | }
|
---|
781 | if(force)
|
---|
782 | {
|
---|
783 | browserp->servicep = servicep;
|
---|
784 | servicep->n_browsers++;
|
---|
785 | }
|
---|
786 | return 1;
|
---|
787 | }
|
---|
788 |
|
---|
789 | int check_browser_changes(char *service, int conn_id, int subscribe, int req, int browser, int force)
|
---|
790 | {
|
---|
791 | CURR_SERVICE *servicep;
|
---|
792 | time_t tsecs;
|
---|
793 | void recv_service_info();
|
---|
794 | extern void sendData();
|
---|
795 | BROWSER *browserp;
|
---|
796 | char answer[256];
|
---|
797 | int service_changed = 0;
|
---|
798 |
|
---|
799 | if(req){}
|
---|
800 | if(subscribe){}
|
---|
801 | if(!(browserp = find_browser(browser)))
|
---|
802 | browserp = create_browser(browser);
|
---|
803 | if(!Curr_service_head)
|
---|
804 | {
|
---|
805 | Curr_service_head = (CURR_SERVICE *)malloc(sizeof(CURR_SERVICE));
|
---|
806 | sll_init((SLL *)Curr_service_head);
|
---|
807 | }
|
---|
808 | if(service[0] != '\0')
|
---|
809 | {
|
---|
810 | if((servicep = find_curr_service(service)))
|
---|
811 | {
|
---|
812 | if(servicep->size)
|
---|
813 | {
|
---|
814 | if((servicep->timestamp > browserp->last_updated) || (force))
|
---|
815 | {
|
---|
816 | service_changed = 1;
|
---|
817 | }
|
---|
818 | }
|
---|
819 | }
|
---|
820 | }
|
---|
821 | if(browserp->isSMI)
|
---|
822 | {
|
---|
823 | if((browserp->last_changed >= browserp->last_polled) || (force))
|
---|
824 | {
|
---|
825 | service_changed = 1;
|
---|
826 | }
|
---|
827 | }
|
---|
828 | /*
|
---|
829 | sprintf(answer,"%d %d %d %d\n",
|
---|
830 | browserp->n_services_changed, browserp->n_servers_changed,
|
---|
831 | browserp->n_nodes_changed, service_changed);
|
---|
832 | */
|
---|
833 | sprintf(answer,"%d %d %d %d %d %d %d\n",
|
---|
834 | N_services, N_servers, N_nodes, service_changed,
|
---|
835 | browserp->n_services, browserp->n_servers, browserp->n_nodes);
|
---|
836 | sendData(conn_id, answer, 4);
|
---|
837 | tsecs = time((time_t *)0);
|
---|
838 | browserp->last_polled = tsecs;
|
---|
839 | return 1;
|
---|
840 | }
|
---|
841 |
|
---|
842 | int find_services(char *pattern, int conn_id, int browser, int force)
|
---|
843 | {
|
---|
844 | void recv_service_info();
|
---|
845 | extern void sendData();
|
---|
846 | BROWSER *browserp;
|
---|
847 | char format[MAX_NAME];
|
---|
848 | int prepareJSONTree();
|
---|
849 | void did_prepare_command();
|
---|
850 |
|
---|
851 | if(conn_id){}
|
---|
852 | if(!(browserp = find_browser(browser)))
|
---|
853 | browserp = create_browser(browser);
|
---|
854 | if(force == -1)
|
---|
855 | {
|
---|
856 | if(browserp->service_format_ptr)
|
---|
857 | {
|
---|
858 | get_service_format(browserp->service_format_ptr, browserp->curr_command, format);
|
---|
859 | did_prepare_command(pattern, browserp->curr_command, format);
|
---|
860 | }
|
---|
861 | return 1;
|
---|
862 | }
|
---|
863 | if(conn_id){}
|
---|
864 | if(!(browserp = find_browser(browser)))
|
---|
865 | browserp = create_browser(browser);
|
---|
866 | strcpy(browserp->pattern, pattern);
|
---|
867 | return 1;
|
---|
868 | }
|
---|
869 |
|
---|
870 | void recv_service_info(void **tag, int *buffer, int *size)
|
---|
871 | {
|
---|
872 | int conn_id;
|
---|
873 | void print_service_formatted();
|
---|
874 | extern void sendData();
|
---|
875 | CURR_SERVICE *servicep;
|
---|
876 | time_t tsecs;
|
---|
877 |
|
---|
878 | servicep = *tag;
|
---|
879 | conn_id = servicep->conn_id;
|
---|
880 | if (servicep->buffer_size < *size)
|
---|
881 | {
|
---|
882 | if(servicep->buffer_size)
|
---|
883 | free(servicep->buffer);
|
---|
884 | servicep->buffer = malloc((size_t)*size);
|
---|
885 | servicep->buffer_size = *size;
|
---|
886 | }
|
---|
887 | memcpy(servicep->buffer, (char *)buffer, (size_t)*size);
|
---|
888 | servicep->size = *size;
|
---|
889 | if (servicep->buffer_str_size < (1024 + (*size)*16))
|
---|
890 | {
|
---|
891 | if(servicep->buffer_str_size)
|
---|
892 | free(servicep->buffer_str);
|
---|
893 | servicep->buffer_str = malloc((size_t)(1024 + (*size)*16));
|
---|
894 | servicep->buffer_str_size = 1024 + (*size)*16;
|
---|
895 | }
|
---|
896 | Service_content_str = servicep->buffer_str;
|
---|
897 | strcpy(Curr_service_name, servicep->name);
|
---|
898 | get_curr_service_format();
|
---|
899 | if((*size == 4 ) && (*buffer == -1))
|
---|
900 | {
|
---|
901 | sprintf(Service_content_str,
|
---|
902 | "Service %s Not Available", Curr_service_name);
|
---|
903 | }
|
---|
904 | else
|
---|
905 | {
|
---|
906 | print_service_formatted(servicep, buffer, *size);
|
---|
907 | }
|
---|
908 | if(servicep->last_updated == 0)
|
---|
909 | {
|
---|
910 | sendData(conn_id, Service_content_str, 4);
|
---|
911 | tsecs = time((time_t *)0);
|
---|
912 | servicep->last_updated = tsecs;
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | void print_service_formatted(CURR_SERVICE *servicep, void *buff, int size)
|
---|
917 | {
|
---|
918 | char type;
|
---|
919 | int num, ret;
|
---|
920 | char str[256];
|
---|
921 | char *ptr;
|
---|
922 | void *buffer_ptr;
|
---|
923 | char timestr[256], aux[64], sizestr[64];
|
---|
924 | int quality = 0, secs = 0, mili = 0;
|
---|
925 | int did_write_string(char, int, void **, int);
|
---|
926 | time_t tsecs;
|
---|
927 |
|
---|
928 | if(size < 1024)
|
---|
929 | sprintf(sizestr,"%d bytes",size);
|
---|
930 | else if (size < 1024*1024)
|
---|
931 | sprintf(sizestr,"%2.2f Kb",(float)size/1024);
|
---|
932 | else
|
---|
933 | sprintf(sizestr,"%2.2f Mb",(float)size/(1024*1024));
|
---|
934 |
|
---|
935 | sprintf(Service_content_str,
|
---|
936 | "<FONT FACE=\"consolas\">Service %s (%s) Contents :<br /> <br />", Curr_service_name,
|
---|
937 | Curr_service_format);
|
---|
938 | dic_get_timestamp(0, &secs, &mili);
|
---|
939 | quality = dic_get_quality(0);
|
---|
940 | tsecs = secs;
|
---|
941 | servicep->timestamp = tsecs;
|
---|
942 | my_ctime(&tsecs, timestr, 128);
|
---|
943 | ptr = strrchr(timestr,' ');
|
---|
944 | strcpy(aux, ptr);
|
---|
945 | sprintf(ptr,".%03d",mili);
|
---|
946 | strcat(timestr, aux);
|
---|
947 | timestr[(int)strlen(timestr)-1] = '\0';
|
---|
948 |
|
---|
949 | sprintf(str," Timestamp: %s         Quality: %d    Size: %s<br /><br />",
|
---|
950 | timestr, quality, sizestr);
|
---|
951 |
|
---|
952 | strcat(Service_content_str,str);
|
---|
953 | ptr = Curr_service_format;
|
---|
954 | buffer_ptr = buff;
|
---|
955 | while(*ptr)
|
---|
956 | {
|
---|
957 | type = *ptr++;
|
---|
958 | if(*ptr == ':')
|
---|
959 | {
|
---|
960 | ptr++;
|
---|
961 | sscanf(ptr, "%d", &num);
|
---|
962 | ret = did_write_string(type, num, &buffer_ptr, size);
|
---|
963 | size -= ret;
|
---|
964 | if( (ptr = strchr(ptr,';')) )
|
---|
965 | ptr++;
|
---|
966 | else
|
---|
967 | break;
|
---|
968 | }
|
---|
969 | else
|
---|
970 | {
|
---|
971 | ret = did_write_string(type, 0, &buffer_ptr, size);
|
---|
972 | size -= ret;
|
---|
973 | break;
|
---|
974 | }
|
---|
975 | }
|
---|
976 | strcat(Service_content_str,"</FONT>");
|
---|
977 | }
|
---|
978 |
|
---|
979 |
|
---|
980 | int did_write_string(char type, int num, void **buffer_ptr, int ssize)
|
---|
981 | {
|
---|
982 | void *ptr;
|
---|
983 | int size, psize;
|
---|
984 |
|
---|
985 | void print_service_standard();
|
---|
986 | void print_service_char();
|
---|
987 | void print_service_short();
|
---|
988 | void print_service_float();
|
---|
989 | void print_service_double();
|
---|
990 |
|
---|
991 | ptr = *buffer_ptr;
|
---|
992 | switch(type)
|
---|
993 | {
|
---|
994 | case 'L':
|
---|
995 | case 'l':
|
---|
996 | strcat(Service_content_str," L");
|
---|
997 | if(!num)
|
---|
998 | size = ssize/(int)sizeof(int);
|
---|
999 | else
|
---|
1000 | size = num;
|
---|
1001 | psize = size * (int)sizeof(int);
|
---|
1002 | print_service_standard(ptr, size);
|
---|
1003 | break;
|
---|
1004 | case 'I':
|
---|
1005 | case 'i':
|
---|
1006 | strcat(Service_content_str," I");
|
---|
1007 | if(!num)
|
---|
1008 | size = ssize/(int)sizeof(int);
|
---|
1009 | else
|
---|
1010 | size = num;
|
---|
1011 | psize = size * (int)sizeof(int);
|
---|
1012 | print_service_standard(ptr, size);
|
---|
1013 | break;
|
---|
1014 | case 'S':
|
---|
1015 | case 's':
|
---|
1016 | strcat(Service_content_str," S");
|
---|
1017 | if(!num)
|
---|
1018 | size = ssize/(int)sizeof(short);
|
---|
1019 | else
|
---|
1020 | size = num;
|
---|
1021 | psize = size * (int)sizeof(short);
|
---|
1022 | print_service_short(ptr, size);
|
---|
1023 | break;
|
---|
1024 | case 'F':
|
---|
1025 | case 'f':
|
---|
1026 | strcat(Service_content_str," F");
|
---|
1027 | if(!num)
|
---|
1028 | size = ssize/(int)sizeof(float);
|
---|
1029 | else
|
---|
1030 | size = num;
|
---|
1031 | psize = size * (int)sizeof(float);
|
---|
1032 | print_service_float(ptr, size);
|
---|
1033 | break;
|
---|
1034 | case 'D':
|
---|
1035 | case 'd':
|
---|
1036 | strcat(Service_content_str," D");
|
---|
1037 | if(!num)
|
---|
1038 | size = ssize/(int)sizeof(double);
|
---|
1039 | else
|
---|
1040 | size = num;
|
---|
1041 | psize = size * (int)sizeof(double);
|
---|
1042 | print_service_double(ptr, size);
|
---|
1043 | break;
|
---|
1044 | case 'X':
|
---|
1045 | case 'x':
|
---|
1046 | strcat(Service_content_str," X");
|
---|
1047 | if(!num)
|
---|
1048 | size = ssize/(int)sizeof(longlong);
|
---|
1049 | else
|
---|
1050 | size = num;
|
---|
1051 | psize = size * (int)sizeof(longlong);
|
---|
1052 | print_service_standard(ptr, size*2);
|
---|
1053 | break;
|
---|
1054 | case 'C':
|
---|
1055 | case 'c':
|
---|
1056 | default:
|
---|
1057 | strcat(Service_content_str," C");
|
---|
1058 | if(!num)
|
---|
1059 | size = ssize;
|
---|
1060 | else
|
---|
1061 | size = num;
|
---|
1062 | psize = size;
|
---|
1063 | print_service_char(ptr, size);
|
---|
1064 | }
|
---|
1065 | ptr = (char *)ptr + psize;
|
---|
1066 | *buffer_ptr = ptr;
|
---|
1067 | return psize;
|
---|
1068 | }
|
---|
1069 |
|
---|
1070 | void sprintf_html(char *str, int n, int value)
|
---|
1071 | {
|
---|
1072 | char tmp[80];
|
---|
1073 | int min, i;
|
---|
1074 |
|
---|
1075 | str[0] = '\0';
|
---|
1076 | min = sprintf(tmp,"%d",value);
|
---|
1077 | for(i = 0; i < (n-min); i++)
|
---|
1078 | {
|
---|
1079 | strcat(str," ");
|
---|
1080 | }
|
---|
1081 | strcat(str, tmp);
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | void print_service_standard(int *buff, int size)
|
---|
1085 | {
|
---|
1086 | int i,j;
|
---|
1087 | char *ptr, str[80], tmp[256];
|
---|
1088 | int last[4];
|
---|
1089 |
|
---|
1090 | ptr = Service_content_str;
|
---|
1091 | ptr += (int)strlen(Service_content_str);
|
---|
1092 | for( i = 0; i < size; i++)
|
---|
1093 | {
|
---|
1094 | strcpy(tmp,"");
|
---|
1095 | if(i%4 == 0)
|
---|
1096 | {
|
---|
1097 | if(i != 0)
|
---|
1098 | {
|
---|
1099 | strcat(tmp," ");
|
---|
1100 | }
|
---|
1101 | sprintf_html(str, 7, i);
|
---|
1102 | strcat(tmp,str);
|
---|
1103 | }
|
---|
1104 | if(!(i%4))
|
---|
1105 | strcat(tmp,"H: ");
|
---|
1106 | sprintf(str,"    %08X",buff[i]);
|
---|
1107 | strcat(tmp,str);
|
---|
1108 | last[i%4] = buff[i];
|
---|
1109 | if((i%4 == 3) || (i == (size-1)))
|
---|
1110 | {
|
---|
1111 | strcat(tmp,"<br />");
|
---|
1112 | for(j = 0; j <= (i%4); j++)
|
---|
1113 | {
|
---|
1114 | if(j == 0)
|
---|
1115 | strcat(tmp,"        D: ");
|
---|
1116 | sprintf_html(str, 12, last[j]);
|
---|
1117 | strcat(tmp,str);
|
---|
1118 | }
|
---|
1119 | strcat(tmp,"<br />");
|
---|
1120 | }
|
---|
1121 | strcpy(ptr, tmp);
|
---|
1122 | ptr += (int)strlen(tmp);
|
---|
1123 | }
|
---|
1124 | strcpy(tmp,"<br />");
|
---|
1125 | strcpy(ptr, tmp);
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | void print_service_longlong(longlong *buff, int size)
|
---|
1129 | {
|
---|
1130 | int i,j;
|
---|
1131 | char *ptr, str[80], tmp[256];
|
---|
1132 | longlong last[4];
|
---|
1133 |
|
---|
1134 | ptr = Service_content_str;
|
---|
1135 | ptr += (int)strlen(Service_content_str);
|
---|
1136 | for( i = 0; i < size; i++)
|
---|
1137 | {
|
---|
1138 | strcpy(tmp,"");
|
---|
1139 | if(i%4 == 0)
|
---|
1140 | {
|
---|
1141 | if(i != 0)
|
---|
1142 | {
|
---|
1143 | strcat(tmp," ");
|
---|
1144 | }
|
---|
1145 | sprintf_html(str, 7, i);
|
---|
1146 | strcat(tmp,str);
|
---|
1147 | }
|
---|
1148 | if(!(i%4))
|
---|
1149 | strcat(tmp,"H: ");
|
---|
1150 | sprintf(str,"    %08X",(unsigned)buff[i]);
|
---|
1151 | strcat(tmp,str);
|
---|
1152 | last[i%4] = buff[i];
|
---|
1153 | if((i%4 == 3) || (i == (size-1)))
|
---|
1154 | {
|
---|
1155 | strcat(tmp,"<br />");
|
---|
1156 | for(j = 0; j <= (i%4); j++)
|
---|
1157 | {
|
---|
1158 | if(j == 0)
|
---|
1159 | strcat(tmp,"        D: ");
|
---|
1160 | sprintf_html(str, 12, (int)last[j]);
|
---|
1161 | strcat(tmp,str);
|
---|
1162 | }
|
---|
1163 | strcat(tmp,"<br />");
|
---|
1164 | }
|
---|
1165 | strcpy(ptr, tmp);
|
---|
1166 | ptr += (int)strlen(tmp);
|
---|
1167 | }
|
---|
1168 | strcpy(tmp,"<br />");
|
---|
1169 | strcpy(ptr, tmp);
|
---|
1170 | }
|
---|
1171 |
|
---|
1172 | void print_service_short(short *buff, int size)
|
---|
1173 | {
|
---|
1174 | int i,j;
|
---|
1175 | char *ptr, str[80], tmp[256];
|
---|
1176 | short last[8];
|
---|
1177 |
|
---|
1178 | ptr = Service_content_str;
|
---|
1179 | ptr += (int)strlen(Service_content_str);
|
---|
1180 | for( i = 0; i < size; i++)
|
---|
1181 | {
|
---|
1182 | strcpy(tmp,"");
|
---|
1183 | if(i%8 == 0)
|
---|
1184 | {
|
---|
1185 | if(i != 0)
|
---|
1186 | {
|
---|
1187 | strcat(tmp," ");
|
---|
1188 | }
|
---|
1189 | sprintf_html(str, 7, i);
|
---|
1190 | strcat(tmp,str);
|
---|
1191 | }
|
---|
1192 | if(!(i%8))
|
---|
1193 | strcat(tmp,"H: ");
|
---|
1194 | sprintf(str,"  %04X",buff[i]);
|
---|
1195 | strcat(tmp,str);
|
---|
1196 | last[i%8] = buff[i];
|
---|
1197 | if((i%8 == 7) || (i == (size-1)))
|
---|
1198 | {
|
---|
1199 | strcat(tmp,"<br />");
|
---|
1200 | for(j = 0; j <= (i%8); j++)
|
---|
1201 | {
|
---|
1202 | if(j == 0)
|
---|
1203 | strcat(tmp,"        D: ");
|
---|
1204 | sprintf_html(str, 6, last[j]);
|
---|
1205 | strcat(tmp,str);
|
---|
1206 | }
|
---|
1207 | strcat(tmp,"<br />");
|
---|
1208 | }
|
---|
1209 | strcpy(ptr, tmp);
|
---|
1210 | ptr += (int)strlen(tmp);
|
---|
1211 | }
|
---|
1212 | strcpy(tmp,"<br />");
|
---|
1213 | strcpy(ptr, tmp);
|
---|
1214 | }
|
---|
1215 |
|
---|
1216 | void print_service_char(char *buff, int size)
|
---|
1217 | {
|
---|
1218 | int i,j;
|
---|
1219 | char *asc, *ptr, str[80], tmp[256];
|
---|
1220 |
|
---|
1221 | asc = (char *)buff;
|
---|
1222 | ptr = Service_content_str;
|
---|
1223 | ptr += (int)strlen(Service_content_str);
|
---|
1224 | for( i = 0; i < size; i++)
|
---|
1225 | {
|
---|
1226 | strcpy(tmp,"");
|
---|
1227 | if(i%16 == 0)
|
---|
1228 | {
|
---|
1229 | if(i != 0)
|
---|
1230 | {
|
---|
1231 | strcat(tmp," ");
|
---|
1232 | }
|
---|
1233 | sprintf_html(str, 7, i);
|
---|
1234 | strcat(tmp,str);
|
---|
1235 | }
|
---|
1236 | if(!(i%16))
|
---|
1237 | strcat(tmp,"H: ");
|
---|
1238 | sprintf(str,"%02X",buff[i]);
|
---|
1239 | /* strcat(tmp,str);
|
---|
1240 | */
|
---|
1241 | strcat(tmp," ");
|
---|
1242 | strcat(tmp,&str[(int)strlen(str)-2]);
|
---|
1243 | /*
|
---|
1244 | if(i%4 == 3)
|
---|
1245 | strcat(tmp," ");
|
---|
1246 | */
|
---|
1247 | if((i%16 == 15) || (i == (size-1)))
|
---|
1248 | {
|
---|
1249 | if(i%16 != 15)
|
---|
1250 | {
|
---|
1251 | for(j = 1; j < 16 - (i%16); j++)
|
---|
1252 | strcat(tmp,"   ");
|
---|
1253 | }
|
---|
1254 | strcat(tmp,"    '");
|
---|
1255 | for(j = 0; j <= (i%16) ; j++)
|
---|
1256 | {
|
---|
1257 | if(isprint(asc[j]))
|
---|
1258 | {
|
---|
1259 | if(asc[j] == ' ')
|
---|
1260 | sprintf(str," ");
|
---|
1261 | else if(asc[j] == '<')
|
---|
1262 | sprintf(str,"<");
|
---|
1263 | else if(asc[j] == '>')
|
---|
1264 | sprintf(str,">");
|
---|
1265 | else if(asc[j] == '&')
|
---|
1266 | sprintf(str,"&");
|
---|
1267 | else
|
---|
1268 | sprintf(str,"%c",asc[j]);
|
---|
1269 | strcat(tmp,str);
|
---|
1270 | }
|
---|
1271 | else
|
---|
1272 | {
|
---|
1273 | sprintf(str,".");
|
---|
1274 | strcat(tmp,str);
|
---|
1275 | }
|
---|
1276 | }
|
---|
1277 | strcat(tmp,"'<br />");
|
---|
1278 | asc = (char *)&buff[i+1];
|
---|
1279 | }
|
---|
1280 | strcpy(ptr, tmp);
|
---|
1281 | ptr += (int)strlen(tmp);
|
---|
1282 | }
|
---|
1283 | strcpy(tmp,"<br />");
|
---|
1284 | strcpy(ptr, tmp);
|
---|
1285 | }
|
---|
1286 |
|
---|
1287 | void print_service_float(float *buff, int size)
|
---|
1288 | {
|
---|
1289 | int i;
|
---|
1290 | char *ptr, str[80], tmp[256];
|
---|
1291 |
|
---|
1292 | ptr = Service_content_str;
|
---|
1293 | ptr += (int)strlen(Service_content_str);
|
---|
1294 | for( i = 0; i < size; i++)
|
---|
1295 | {
|
---|
1296 | strcpy(tmp,"");
|
---|
1297 | if(i%4 == 0)
|
---|
1298 | {
|
---|
1299 | if(i != 0)
|
---|
1300 | {
|
---|
1301 | strcat(tmp," ");
|
---|
1302 | }
|
---|
1303 | sprintf_html(str, 7, i);
|
---|
1304 | strcat(tmp,str);
|
---|
1305 | }
|
---|
1306 | sprintf(str,"%12.3G",*(buff++));
|
---|
1307 | strcat(tmp,str);
|
---|
1308 | if((i%4 == 3) || (i == size-1))
|
---|
1309 | {
|
---|
1310 | strcat(tmp,"<br />");
|
---|
1311 | }
|
---|
1312 | strcpy(ptr, tmp);
|
---|
1313 | ptr += (int)strlen(tmp);
|
---|
1314 | }
|
---|
1315 | strcpy(tmp,"<br />");
|
---|
1316 | strcpy(ptr, tmp);
|
---|
1317 | ptr += (int)strlen(tmp);
|
---|
1318 | }
|
---|
1319 |
|
---|
1320 | void print_service_double(double *buff, int size)
|
---|
1321 | {
|
---|
1322 | int i;
|
---|
1323 | char *ptr, str[80], tmp[256];
|
---|
1324 |
|
---|
1325 | ptr = Service_content_str;
|
---|
1326 | ptr += (int)strlen(Service_content_str);
|
---|
1327 | for( i = 0; i < size; i++)
|
---|
1328 | {
|
---|
1329 | strcpy(tmp,"");
|
---|
1330 | if(i%4 == 0)
|
---|
1331 | {
|
---|
1332 | if(i != 0)
|
---|
1333 | {
|
---|
1334 | strcat(tmp," ");
|
---|
1335 | }
|
---|
1336 | sprintf_html(str, 7, i);
|
---|
1337 | strcat(tmp,str);
|
---|
1338 | }
|
---|
1339 | sprintf(str,"%12.3G",*(buff++));
|
---|
1340 | strcat(tmp,str);
|
---|
1341 | if((i%4 == 3) || (i == size-1))
|
---|
1342 | {
|
---|
1343 | strcat(tmp,"<br />");
|
---|
1344 | }
|
---|
1345 | strcpy(ptr, tmp);
|
---|
1346 | ptr += (int)strlen(tmp);
|
---|
1347 | }
|
---|
1348 | strcpy(tmp,"<br />");
|
---|
1349 | strcpy(ptr, tmp);
|
---|
1350 | ptr += (int)strlen(tmp);
|
---|
1351 | }
|
---|
1352 |
|
---|
1353 | char *addJSONStart(char *ptr)
|
---|
1354 | {
|
---|
1355 | char *ptro;
|
---|
1356 |
|
---|
1357 | strcat(ptr,"{\n");
|
---|
1358 | ptro = ptr + (int)strlen(ptr);
|
---|
1359 | return ptro;
|
---|
1360 | }
|
---|
1361 |
|
---|
1362 | char *addJSONEnd(char *ptr)
|
---|
1363 | {
|
---|
1364 | char *ptro;
|
---|
1365 |
|
---|
1366 | strcat(ptr,"}\n");
|
---|
1367 | ptro = ptr + (int)strlen(ptr);
|
---|
1368 | return ptro;
|
---|
1369 | }
|
---|
1370 |
|
---|
1371 | char *addJSONNodeStart(char *ptr, char *node)
|
---|
1372 | {
|
---|
1373 | char *ptro;
|
---|
1374 |
|
---|
1375 | sprintf(ptr,"%s: [\n", node);
|
---|
1376 | ptro = ptr + (int)strlen(ptr);
|
---|
1377 | return ptro;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | char *addJSONNodeEnd(char *ptr)
|
---|
1381 | {
|
---|
1382 | char *ptro;
|
---|
1383 |
|
---|
1384 | strcat(ptr,"]\n");
|
---|
1385 | ptro = ptr + (int)strlen(ptr);
|
---|
1386 | return ptro;
|
---|
1387 | }
|
---|
1388 |
|
---|
1389 | char *addJSONChildStart(char *ptr, char *child, int sep)
|
---|
1390 | {
|
---|
1391 | char *ptro;
|
---|
1392 |
|
---|
1393 | if(sep)
|
---|
1394 | sprintf(ptr,"{ %s, ", child);
|
---|
1395 | else
|
---|
1396 | sprintf(ptr,"{ %s", child);
|
---|
1397 | ptro = ptr + (int)strlen(ptr);
|
---|
1398 | return ptro;
|
---|
1399 | }
|
---|
1400 |
|
---|
1401 | char *addJSONChildEnd(char *ptr, int sep)
|
---|
1402 | {
|
---|
1403 | char *ptro;
|
---|
1404 |
|
---|
1405 | if(sep)
|
---|
1406 | strcat(ptr," },\n");
|
---|
1407 | else
|
---|
1408 | strcat(ptr," }\n");
|
---|
1409 | ptro = ptr + (int)strlen(ptr);
|
---|
1410 | return ptro;
|
---|
1411 | }
|
---|
1412 |
|
---|
1413 | char *getJSONBuffer(char *node, int browser)
|
---|
1414 | {
|
---|
1415 | BROWSER *browserp;
|
---|
1416 | int prepareJSONTree();
|
---|
1417 |
|
---|
1418 | if(browser)
|
---|
1419 | {
|
---|
1420 | if((browserp = find_browser(browser)))
|
---|
1421 | {
|
---|
1422 | if(browserp->pattern[0] != '\0')
|
---|
1423 | {
|
---|
1424 | prepareJSONTree(node, browserp);
|
---|
1425 | return(browserp->JSONBuffer);
|
---|
1426 | }
|
---|
1427 | browserp->n_services = 0;
|
---|
1428 | browserp->n_servers = 0;
|
---|
1429 | browserp->n_nodes = 0;
|
---|
1430 | }
|
---|
1431 | }
|
---|
1432 | prepareJSONTree(node, 0);
|
---|
1433 | return(JSONBuffer);
|
---|
1434 | }
|
---|
1435 |
|
---|
1436 | char *getJSONSmiBuffer(char *node, int browser)
|
---|
1437 | {
|
---|
1438 | BROWSER *browserp;
|
---|
1439 | int prepareJSONSmiTree();
|
---|
1440 |
|
---|
1441 | if(!(browserp = find_browser(browser)))
|
---|
1442 | {
|
---|
1443 | browserp = create_browser(browser);
|
---|
1444 | browserp->isSMI = 1;
|
---|
1445 | strcpy(browserp->pattern,"SMI/");
|
---|
1446 | }
|
---|
1447 | if(browser)
|
---|
1448 | {
|
---|
1449 | if((browserp = find_browser(browser)))
|
---|
1450 | {
|
---|
1451 | if(browserp->pattern[0] != '\0')
|
---|
1452 | {
|
---|
1453 | prepareJSONSmiTree(node, browserp);
|
---|
1454 | return(browserp->JSONSmiBuffer);
|
---|
1455 | }
|
---|
1456 | // browserp->n_services = 0;
|
---|
1457 | // browserp->n_servers = 0;
|
---|
1458 | // browserp->n_nodes = 0;
|
---|
1459 | }
|
---|
1460 | }
|
---|
1461 | prepareJSONSmiTree(node, 0);
|
---|
1462 | return(JSONSmiBuffer);
|
---|
1463 | }
|
---|
1464 |
|
---|
1465 | char *getJSONHeader(int isSMI)
|
---|
1466 | {
|
---|
1467 | int prepareJSONHeader();
|
---|
1468 |
|
---|
1469 | if(isSMI){}
|
---|
1470 | if(JSONHeader[0] == '\0')
|
---|
1471 | prepareJSONHeader();
|
---|
1472 | return(JSONHeader);
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | int getNodeLabel(char *name, char *label)
|
---|
1476 | {
|
---|
1477 | int i;
|
---|
1478 | extern int web_get_node_name();
|
---|
1479 |
|
---|
1480 | web_get_node_name(name, label);
|
---|
1481 | for(i = 0; i < ((int)strlen(label) + 1); i++)
|
---|
1482 | {
|
---|
1483 | label[i] = (char)tolower((int)label[i]);
|
---|
1484 | if(label[i] == '.')
|
---|
1485 | {
|
---|
1486 | label[i] = '\0';
|
---|
1487 | break;
|
---|
1488 | }
|
---|
1489 | }
|
---|
1490 | return 1;
|
---|
1491 | }
|
---|
1492 |
|
---|
1493 | int prepareJSONTree(char *node, BROWSER *browserp)
|
---|
1494 | {
|
---|
1495 | char *ptr;
|
---|
1496 | NODE *nodep;
|
---|
1497 | SERVER *servp;
|
---|
1498 | char str[256], aux[128];
|
---|
1499 | int selective = 0;
|
---|
1500 | int n_nodes, tot_n_nodes;
|
---|
1501 | int n_servers, tot_n_servers;
|
---|
1502 | int ret, n_found = 0;
|
---|
1503 |
|
---|
1504 | if(browserp)
|
---|
1505 | {
|
---|
1506 | if(browserp->pattern[0] != '\0')
|
---|
1507 | selective = 1;
|
---|
1508 | else
|
---|
1509 | return(0);
|
---|
1510 | }
|
---|
1511 | if(!selective)
|
---|
1512 | {
|
---|
1513 | if(JSONBufferSize == 0)
|
---|
1514 | {
|
---|
1515 | JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1516 | }
|
---|
1517 | else if (JSONBufferSize < N_nodes*128+N_servers*128)
|
---|
1518 | {
|
---|
1519 | free(JSONBuffer);
|
---|
1520 | JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1521 | }
|
---|
1522 | ptr = JSONBuffer;
|
---|
1523 | }
|
---|
1524 | else
|
---|
1525 | {
|
---|
1526 | if(browserp->JSONBufferSize == 0)
|
---|
1527 | {
|
---|
1528 | browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1529 | }
|
---|
1530 | else if (browserp->JSONBufferSize < N_nodes*128+N_servers*128)
|
---|
1531 | {
|
---|
1532 | free(browserp->JSONBuffer);
|
---|
1533 | browserp->JSONBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1534 | }
|
---|
1535 | ptr = browserp->JSONBuffer;
|
---|
1536 | }
|
---|
1537 | *ptr = '\0';
|
---|
1538 | if(!strcmp(node, "src"))
|
---|
1539 | {
|
---|
1540 | ptr = addJSONStart(ptr);
|
---|
1541 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1542 | sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
|
---|
1543 | ptr = addJSONChildStart(ptr,str,1);
|
---|
1544 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1545 | nodep = Node_head;
|
---|
1546 | tot_n_nodes = 0;
|
---|
1547 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
1548 | {
|
---|
1549 | nodep->match = 1;
|
---|
1550 | if(selective)
|
---|
1551 | {
|
---|
1552 | if(!(ret = find_service_pattern(nodep, 0, browserp->pattern, &tot_n_servers)))
|
---|
1553 | {
|
---|
1554 | nodep->match = 0;
|
---|
1555 | continue;
|
---|
1556 | }
|
---|
1557 | else
|
---|
1558 | {
|
---|
1559 | n_found += ret;
|
---|
1560 | }
|
---|
1561 | }
|
---|
1562 | tot_n_nodes++;
|
---|
1563 | }
|
---|
1564 | n_nodes = 0;
|
---|
1565 | nodep = Node_head;
|
---|
1566 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
1567 | {
|
---|
1568 | if(!nodep->match)
|
---|
1569 | continue;
|
---|
1570 | getNodeLabel(nodep->name, aux);
|
---|
1571 | sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
|
---|
1572 | aux, nodep->name, nodep->name);
|
---|
1573 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1574 | n_nodes++;
|
---|
1575 | if(WebDID_Debug)
|
---|
1576 | printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
|
---|
1577 | if(n_nodes < tot_n_nodes)
|
---|
1578 | ptr = addJSONChildEnd(ptr,1);
|
---|
1579 | else
|
---|
1580 | ptr = addJSONChildEnd(ptr,0);
|
---|
1581 | }
|
---|
1582 | ptr = addJSONNodeEnd(ptr);
|
---|
1583 | ptr = addJSONChildEnd(ptr,0);
|
---|
1584 | ptr = addJSONNodeEnd(ptr);
|
---|
1585 | ptr = addJSONEnd(ptr);
|
---|
1586 | if(selective)
|
---|
1587 | {
|
---|
1588 | browserp->n_services = n_found;
|
---|
1589 | browserp->n_servers = tot_n_servers;
|
---|
1590 | browserp->n_nodes = tot_n_nodes;
|
---|
1591 | }
|
---|
1592 | }
|
---|
1593 | else
|
---|
1594 | {
|
---|
1595 | if((nodep = find_node(node)))
|
---|
1596 | {
|
---|
1597 | ptr = addJSONStart(ptr);
|
---|
1598 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1599 | servp = nodep->server_head;
|
---|
1600 | tot_n_servers = 0;
|
---|
1601 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
1602 | {
|
---|
1603 | servp->match = 1;
|
---|
1604 | if(servp->busy != 1)
|
---|
1605 | {
|
---|
1606 | servp->match = 0;
|
---|
1607 | continue;
|
---|
1608 | }
|
---|
1609 | if(selective)
|
---|
1610 | {
|
---|
1611 | if(!(ret = find_service_pattern(nodep, servp, browserp->pattern, 0)))
|
---|
1612 | {
|
---|
1613 | servp->match = 0;
|
---|
1614 | continue;
|
---|
1615 | }
|
---|
1616 | else
|
---|
1617 | {
|
---|
1618 | n_found += ret;
|
---|
1619 | }
|
---|
1620 | }
|
---|
1621 | tot_n_servers++;
|
---|
1622 | }
|
---|
1623 | n_servers = 0;
|
---|
1624 | servp = nodep->server_head;
|
---|
1625 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
1626 | {
|
---|
1627 | if(!servp->match)
|
---|
1628 | continue;
|
---|
1629 | sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\"",servp->name, servp->server.pid);
|
---|
1630 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1631 | n_servers++;
|
---|
1632 | if(n_servers < tot_n_servers)
|
---|
1633 | ptr = addJSONChildEnd(ptr,1);
|
---|
1634 | else
|
---|
1635 | ptr = addJSONChildEnd(ptr,0);
|
---|
1636 | }
|
---|
1637 | ptr = addJSONNodeEnd(ptr);
|
---|
1638 | ptr = addJSONEnd(ptr);
|
---|
1639 | }
|
---|
1640 | }
|
---|
1641 | /*
|
---|
1642 | if(!selective)
|
---|
1643 | printf(" Nodes&Servers %s\n",JSONBuffer);
|
---|
1644 | else
|
---|
1645 | printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
|
---|
1646 | */
|
---|
1647 | return(1);
|
---|
1648 | }
|
---|
1649 |
|
---|
1650 | int prepareJSONSmiTree(char *node, BROWSER *browserp)
|
---|
1651 | {
|
---|
1652 | char *ptr;
|
---|
1653 | NODE *nodep;
|
---|
1654 | SERVER *servp;
|
---|
1655 | char str[256], aux[128];
|
---|
1656 | int selective = 0;
|
---|
1657 | int n_nodes, tot_n_nodes;
|
---|
1658 | int n_servers, tot_n_servers;
|
---|
1659 | int ret, n_found = 0;
|
---|
1660 | char pattern[256] = {'\0'};
|
---|
1661 | char *sptr;
|
---|
1662 |
|
---|
1663 | if(browserp)
|
---|
1664 | {
|
---|
1665 | if(browserp->pattern[0] != '\0')
|
---|
1666 | {
|
---|
1667 | selective = 1;
|
---|
1668 | strcpy(pattern, browserp->pattern);
|
---|
1669 | }
|
---|
1670 | // else
|
---|
1671 | // return(0);
|
---|
1672 | }
|
---|
1673 | // selective = 1;
|
---|
1674 | // strcpy(pattern,"SMI/*");
|
---|
1675 | if(!selective)
|
---|
1676 | {
|
---|
1677 | if(JSONSmiBufferSize == 0)
|
---|
1678 | {
|
---|
1679 | JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1680 | }
|
---|
1681 | else if (JSONSmiBufferSize < N_nodes*128+N_servers*128)
|
---|
1682 | {
|
---|
1683 | free(JSONSmiBuffer);
|
---|
1684 | JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1685 | }
|
---|
1686 | ptr = JSONSmiBuffer;
|
---|
1687 | }
|
---|
1688 | else
|
---|
1689 | {
|
---|
1690 | if(browserp->JSONSmiBufferSize == 0)
|
---|
1691 | {
|
---|
1692 | browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1693 | }
|
---|
1694 | else if (browserp->JSONSmiBufferSize < N_nodes*128+N_servers*128)
|
---|
1695 | {
|
---|
1696 | free(browserp->JSONSmiBuffer);
|
---|
1697 | browserp->JSONSmiBuffer = malloc((size_t)(N_nodes*128+N_servers*128));
|
---|
1698 | }
|
---|
1699 | ptr = browserp->JSONSmiBuffer;
|
---|
1700 | }
|
---|
1701 | *ptr = '\0';
|
---|
1702 | if(!strcmp(node, "src"))
|
---|
1703 | {
|
---|
1704 | ptr = addJSONStart(ptr);
|
---|
1705 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1706 | sprintf(str,"text: \"%s\", id: \"Nodes\", expanded: false", Title);
|
---|
1707 | ptr = addJSONChildStart(ptr,str,1);
|
---|
1708 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1709 | nodep = Node_head;
|
---|
1710 | tot_n_nodes = 0;
|
---|
1711 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
1712 | {
|
---|
1713 | nodep->match = 1;
|
---|
1714 | if(selective)
|
---|
1715 | {
|
---|
1716 | if(!(ret = find_service_pattern(nodep, 0, pattern, &tot_n_servers)))
|
---|
1717 | {
|
---|
1718 | nodep->match = 0;
|
---|
1719 | continue;
|
---|
1720 | }
|
---|
1721 | else
|
---|
1722 | {
|
---|
1723 | n_found += ret;
|
---|
1724 | }
|
---|
1725 | }
|
---|
1726 | tot_n_nodes++;
|
---|
1727 | }
|
---|
1728 | n_nodes = 0;
|
---|
1729 | nodep = Node_head;
|
---|
1730 | while( (nodep = (NODE *)sll_get_next((SLL *)nodep)) )
|
---|
1731 | {
|
---|
1732 | if(!nodep->match)
|
---|
1733 | continue;
|
---|
1734 | getNodeLabel(nodep->name, aux);
|
---|
1735 | sprintf(str,"text: \"%s\", id: \"%s\", qtip: \"%s\"",
|
---|
1736 | aux, nodep->name, nodep->name);
|
---|
1737 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1738 | n_nodes++;
|
---|
1739 | if(WebDID_Debug)
|
---|
1740 | printf("adding %s %d %d\n",nodep->name, n_nodes, tot_n_nodes);
|
---|
1741 | if(n_nodes < tot_n_nodes)
|
---|
1742 | ptr = addJSONChildEnd(ptr,1);
|
---|
1743 | else
|
---|
1744 | ptr = addJSONChildEnd(ptr,0);
|
---|
1745 | }
|
---|
1746 | ptr = addJSONNodeEnd(ptr);
|
---|
1747 | ptr = addJSONChildEnd(ptr,0);
|
---|
1748 | ptr = addJSONNodeEnd(ptr);
|
---|
1749 | ptr = addJSONEnd(ptr);
|
---|
1750 | if(selective)
|
---|
1751 | {
|
---|
1752 | browserp->n_services = n_found;
|
---|
1753 | browserp->n_servers = tot_n_servers;
|
---|
1754 | browserp->n_nodes = tot_n_nodes;
|
---|
1755 | }
|
---|
1756 | }
|
---|
1757 | else
|
---|
1758 | {
|
---|
1759 | if((nodep = find_node(node)))
|
---|
1760 | {
|
---|
1761 | ptr = addJSONStart(ptr);
|
---|
1762 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1763 | servp = nodep->server_head;
|
---|
1764 | tot_n_servers = 0;
|
---|
1765 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
1766 | {
|
---|
1767 | servp->match = 1;
|
---|
1768 | if(servp->busy != 1)
|
---|
1769 | {
|
---|
1770 | servp->match = 0;
|
---|
1771 | continue;
|
---|
1772 | }
|
---|
1773 | if(selective)
|
---|
1774 | {
|
---|
1775 | if(!(ret = find_service_pattern(nodep, servp, pattern, 0)))
|
---|
1776 | {
|
---|
1777 | servp->match = 0;
|
---|
1778 | continue;
|
---|
1779 | }
|
---|
1780 | else
|
---|
1781 | {
|
---|
1782 | n_found += ret;
|
---|
1783 | }
|
---|
1784 | }
|
---|
1785 | tot_n_servers++;
|
---|
1786 | }
|
---|
1787 | n_servers = 0;
|
---|
1788 | servp = nodep->server_head;
|
---|
1789 | while( (servp = (SERVER *)sll_get_next((SLL *)servp)) )
|
---|
1790 | {
|
---|
1791 | if(!servp->match)
|
---|
1792 | continue;
|
---|
1793 | strcpy(aux, servp->name);
|
---|
1794 | sptr = strstr(aux,"_SMI");
|
---|
1795 | if(sptr)
|
---|
1796 | *sptr = '\0';
|
---|
1797 | sprintf(str,"text: \"%s\", id: \"%d\", leaf: true, icon: \"server.png\", name: \"%s\"",aux, servp->server.pid, servp->name);
|
---|
1798 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1799 | n_servers++;
|
---|
1800 | if(n_servers < tot_n_servers)
|
---|
1801 | ptr = addJSONChildEnd(ptr,1);
|
---|
1802 | else
|
---|
1803 | ptr = addJSONChildEnd(ptr,0);
|
---|
1804 | }
|
---|
1805 | ptr = addJSONNodeEnd(ptr);
|
---|
1806 | ptr = addJSONEnd(ptr);
|
---|
1807 | }
|
---|
1808 | }
|
---|
1809 | /*
|
---|
1810 | if(!selective)
|
---|
1811 | printf(" Nodes&Servers %s\n",JSONBuffer);
|
---|
1812 | else
|
---|
1813 | printf(" Nodes&Servers %s\n",browserp->JSONBuffer);
|
---|
1814 | */
|
---|
1815 | printf("%s\n",browserp->JSONSmiBuffer);
|
---|
1816 | return(1);
|
---|
1817 | }
|
---|
1818 |
|
---|
1819 | int prepareJSONHeader()
|
---|
1820 | {
|
---|
1821 | char *ptr;
|
---|
1822 | char str[128];
|
---|
1823 |
|
---|
1824 | ptr = JSONHeader;
|
---|
1825 | *ptr = '\0';
|
---|
1826 | ptr = addJSONStart(ptr);
|
---|
1827 | ptr = addJSONNodeStart(ptr,"items");
|
---|
1828 | sprintf(str,"text: \"%s\"",Title);
|
---|
1829 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1830 | ptr = addJSONChildEnd(ptr,1);
|
---|
1831 | sprintf(str,"text: \"%d Servers Known - %d Services Available\"",N_servers, N_services);
|
---|
1832 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1833 | ptr = addJSONChildEnd(ptr,0);
|
---|
1834 | ptr = addJSONNodeEnd(ptr);
|
---|
1835 | ptr = addJSONEnd(ptr);
|
---|
1836 | if(WebDID_Debug)
|
---|
1837 | printf(" Header %s\n",JSONHeader);
|
---|
1838 | return(1);
|
---|
1839 | }
|
---|
1840 |
|
---|
1841 | char *JSONServices = 0;
|
---|
1842 | int JSONServicesSize = 0;
|
---|
1843 | char *prepareJSONServiceList(SERVER *servp, char *node, int pid, BROWSER *browserp)
|
---|
1844 | {
|
---|
1845 | DNS_SERVICE_INFO *servicep;
|
---|
1846 | char *ptr;
|
---|
1847 | int n_services, i;
|
---|
1848 | char str[256], type_str[256];
|
---|
1849 | int selective = 0;
|
---|
1850 | int n_found = 0, n;
|
---|
1851 |
|
---|
1852 | servicep = servp->service_ptr;
|
---|
1853 | n_services = servp->server.n_services;
|
---|
1854 | if(JSONServicesSize == 0)
|
---|
1855 | {
|
---|
1856 | JSONServicesSize = n_services*256;
|
---|
1857 | JSONServices = malloc((size_t)JSONServicesSize);
|
---|
1858 | }
|
---|
1859 | else if (JSONServicesSize < n_services*256)
|
---|
1860 | {
|
---|
1861 | free(JSONServices);
|
---|
1862 | JSONServicesSize = n_services*256;
|
---|
1863 | JSONServices = malloc((size_t)JSONServicesSize);
|
---|
1864 | }
|
---|
1865 | if(browserp)
|
---|
1866 | {
|
---|
1867 | if(browserp->pattern[0] != '\0')
|
---|
1868 | selective = 1;
|
---|
1869 | }
|
---|
1870 | n_found = n_services;
|
---|
1871 | if(selective)
|
---|
1872 | {
|
---|
1873 | n_found = find_server_service_pattern(servp, browserp->pattern);
|
---|
1874 | }
|
---|
1875 | ptr = JSONServices;
|
---|
1876 | *ptr = '\0';
|
---|
1877 | ptr = addJSONStart(ptr);
|
---|
1878 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1879 | if(selective)
|
---|
1880 | sprintf(str,"text: \"%s (%d/%d services, pid %d)\"",servp->name, n_found, n_services, servp->server.pid);
|
---|
1881 | else
|
---|
1882 | sprintf(str,"text: \"%s (%d services, pid %d)\"",servp->name, n_services, servp->server.pid);
|
---|
1883 | ptr = addJSONChildStart(ptr,str,1);
|
---|
1884 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1885 | servicep = servp->service_ptr;
|
---|
1886 | n = 0;
|
---|
1887 | for(i = 0; i < n_services; i++)
|
---|
1888 | {
|
---|
1889 | /*
|
---|
1890 | printf("Service type = %d\n",servicep->type);
|
---|
1891 | */
|
---|
1892 | if((!selective) || (strstr(servicep->name, browserp->pattern)))
|
---|
1893 | {
|
---|
1894 | if(servicep->type == 1)
|
---|
1895 | {
|
---|
1896 | sprintf(type_str,"%d@%s|%s|CMD", pid, node, servicep->name);
|
---|
1897 | sprintf(str,"text: \"%s\", id: \"%s\", leaf: true, icon: \"leaf_cmd.gif\"",servicep->name, type_str);
|
---|
1898 | }
|
---|
1899 | else
|
---|
1900 | {
|
---|
1901 | sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
|
---|
1902 | sprintf(str,"text: \"%s\", id: \"%s\", leaf: true",servicep->name, type_str);
|
---|
1903 | }
|
---|
1904 | ptr = addJSONChildStart(ptr,str,0);
|
---|
1905 | n++;
|
---|
1906 | if(n < n_found)
|
---|
1907 | ptr = addJSONChildEnd(ptr,1);
|
---|
1908 | else
|
---|
1909 | ptr = addJSONChildEnd(ptr,0);
|
---|
1910 | }
|
---|
1911 | servicep++;
|
---|
1912 | }
|
---|
1913 | ptr = addJSONNodeEnd(ptr);
|
---|
1914 | ptr = addJSONChildEnd(ptr,0);
|
---|
1915 | ptr = addJSONNodeEnd(ptr);
|
---|
1916 | ptr = addJSONEnd(ptr);
|
---|
1917 | return JSONServices;
|
---|
1918 | }
|
---|
1919 |
|
---|
1920 | char *JSONSmiServices = 0;
|
---|
1921 | int JSONSmiServicesSize = 0;
|
---|
1922 |
|
---|
1923 | char *prepareJSONSmiObjectList(SERVER *servp, char *node, int pid, BROWSER *browserp)
|
---|
1924 | {
|
---|
1925 | DNS_SERVICE_INFO *servicep;
|
---|
1926 | char *ptr;
|
---|
1927 | int n_services, i;
|
---|
1928 | char str[512], type_str[512];
|
---|
1929 | int selective = 0;
|
---|
1930 | int n_found = 0, n, mode_index;
|
---|
1931 | char aux[512], *sptr, state[512], *stptr;
|
---|
1932 | OBJSTATE *smidomainp;
|
---|
1933 | int findSmiServices();
|
---|
1934 |
|
---|
1935 | printf("prepareJSONSmiObjectList name %s\n", servp->name);
|
---|
1936 | servicep = servp->service_ptr;
|
---|
1937 | n_services = servp->server.n_services;
|
---|
1938 | if(JSONSmiServicesSize == 0)
|
---|
1939 | {
|
---|
1940 | JSONSmiServicesSize = n_services*512;
|
---|
1941 | JSONSmiServices = malloc((size_t)JSONSmiServicesSize);
|
---|
1942 | }
|
---|
1943 | else if (JSONSmiServicesSize < n_services*512)
|
---|
1944 | {
|
---|
1945 | free(JSONSmiServices);
|
---|
1946 | JSONSmiServicesSize = n_services*512;
|
---|
1947 | JSONSmiServices = malloc((size_t)JSONSmiServicesSize);
|
---|
1948 | }
|
---|
1949 | if(browserp)
|
---|
1950 | {
|
---|
1951 | if(browserp->pattern[0] != '\0')
|
---|
1952 | selective = 1;
|
---|
1953 | }
|
---|
1954 | n_found = n_services;
|
---|
1955 | /*
|
---|
1956 | if(selective)
|
---|
1957 | {
|
---|
1958 | n_found = find_server_service_pattern(servp, browserp->pattern);
|
---|
1959 | }
|
---|
1960 | */
|
---|
1961 |
|
---|
1962 | n_found = findSmiServices(browserp, servp);
|
---|
1963 | smidomainp = browserp->smidomainp;
|
---|
1964 |
|
---|
1965 | printf("prepareJSONSmiObjectList1 name %s\n", servp->name);
|
---|
1966 |
|
---|
1967 |
|
---|
1968 | ptr = JSONSmiServices;
|
---|
1969 | *ptr = '\0';
|
---|
1970 | ptr = addJSONStart(ptr);
|
---|
1971 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1972 | /*
|
---|
1973 | if(selective)
|
---|
1974 | sprintf(str,"name: \"%s (%d/%d services, pid %d)\"",servp->name, n_found, n_services, servp->server.pid);
|
---|
1975 | else
|
---|
1976 | sprintf(str,"name: \"%s (%d services, pid %d)\"",servp->name, n_services, servp->server.pid);
|
---|
1977 | */
|
---|
1978 | sprintf(str,"name: \"%s (%d objects, pid %d)\"",servp->name, n_found, servp->server.pid);
|
---|
1979 | ptr = addJSONChildStart(ptr,str,1);
|
---|
1980 | ptr = addJSONNodeStart(ptr,"children");
|
---|
1981 | servicep = servp->service_ptr;
|
---|
1982 | n = 0;
|
---|
1983 | for(i = 0; i < n_services; i++)
|
---|
1984 | {
|
---|
1985 | /*
|
---|
1986 | printf("Service type = %d\n",servicep->type);
|
---|
1987 | */
|
---|
1988 | printf("prepareJSONSmiObjectList2 obj name %s\n", servicep->name);
|
---|
1989 | if((!selective) || (strstr(servicep->name, browserp->pattern)))
|
---|
1990 | {
|
---|
1991 | /*
|
---|
1992 | if(servicep->type == 1)
|
---|
1993 | {
|
---|
1994 | sprintf(type_str,"%d@%s|%s|CMD", pid, node, servicep->name);
|
---|
1995 | sprintf(str,"name: \"%s\", id: \"%s\", leaf: true, icon: \"leaf_cmd.gif\"",servicep->name, type_str);
|
---|
1996 | }
|
---|
1997 | else
|
---|
1998 | {
|
---|
1999 | sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
|
---|
2000 | sprintf(str,"name: \"%s\", state: \"RUNNING\", id: \"%s\", leaf: true",servicep->name, type_str);
|
---|
2001 | }
|
---|
2002 | */
|
---|
2003 | if(servicep->status == 2)
|
---|
2004 | {
|
---|
2005 | sprintf(type_str,"%d@%s|%s", pid, node, servicep->name);
|
---|
2006 | strcpy(aux, servicep->name);
|
---|
2007 | sptr = strchr(aux,'/');
|
---|
2008 | if(sptr)
|
---|
2009 | {
|
---|
2010 | sptr++;
|
---|
2011 | sptr = strchr(sptr,'/');
|
---|
2012 | if(sptr)
|
---|
2013 | sptr++;
|
---|
2014 | }
|
---|
2015 | strcpy(state, smidomainp[i].state);
|
---|
2016 | stptr = strchr(state,'/');
|
---|
2017 | if(stptr)
|
---|
2018 | {
|
---|
2019 | *stptr = '\0';
|
---|
2020 | }
|
---|
2021 | mode_index = smidomainp[i].mode_index;
|
---|
2022 | // sprintf(str,"name: \"%s\", state: \"%s\", id: \"%s\", leaf: true, fname: \"%s\"",sptr, state, type_str, servicep->name);
|
---|
2023 | sprintf(str,"name: \"%s\", state: \"%s\", mode: \"%s\",id: \"%s\", leaf: true, fname: \"%s\"",
|
---|
2024 | sptr, state, smidomainp[mode_index].state, type_str, servicep->name);
|
---|
2025 |
|
---|
2026 | ptr = addJSONChildStart(ptr,str,0);
|
---|
2027 | n++;
|
---|
2028 | if(n < n_found)
|
---|
2029 | ptr = addJSONChildEnd(ptr,1);
|
---|
2030 | else
|
---|
2031 | ptr = addJSONChildEnd(ptr,0);
|
---|
2032 | }
|
---|
2033 | }
|
---|
2034 | servicep++;
|
---|
2035 | }
|
---|
2036 | ptr = addJSONNodeEnd(ptr);
|
---|
2037 | ptr = addJSONChildEnd(ptr,0);
|
---|
2038 | ptr = addJSONNodeEnd(ptr);
|
---|
2039 | ptr = addJSONEnd(ptr);
|
---|
2040 | printf("%s\n",JSONSmiServices);
|
---|
2041 | return JSONSmiServices;
|
---|
2042 | }
|
---|
2043 |
|
---|
2044 | void update_smi_state(OBJSTATE **tag, char *data, int *size)
|
---|
2045 | {
|
---|
2046 | OBJSTATE *servicep;
|
---|
2047 | time_t tsecs;
|
---|
2048 |
|
---|
2049 | if(*size){}
|
---|
2050 | servicep = *tag;
|
---|
2051 |
|
---|
2052 | if(strcmp(servicep->state, data))
|
---|
2053 | {
|
---|
2054 | strcpy(servicep->state, data);
|
---|
2055 | tsecs = time((time_t *)0);
|
---|
2056 | ((BROWSER *)(servicep->browserp))->last_changed = tsecs;
|
---|
2057 | }
|
---|
2058 | //printf("SMI State %s %s %08x\n", servicep->name, servicep->state, (unsigned int)servicep);
|
---|
2059 | }
|
---|
2060 |
|
---|
2061 | int findSmiServices(BROWSER *browserp, SERVER *servp)
|
---|
2062 | {
|
---|
2063 | DNS_SERVICE_INFO *servicep;
|
---|
2064 | int n_services, i, index;
|
---|
2065 | int n_found = 0, sid;
|
---|
2066 | int checkSmiObjName();
|
---|
2067 | int findSmiModeObj();
|
---|
2068 |
|
---|
2069 | n_services = servp->server.n_services;
|
---|
2070 | if(strcmp(browserp->curr_smidomain,servp->name))
|
---|
2071 | {
|
---|
2072 | if(browserp->curr_smidomain[0] != '\0')
|
---|
2073 | {
|
---|
2074 | // unsubscribe; free
|
---|
2075 | for(i = 0; i < browserp->curr_smidomain_size; i++)
|
---|
2076 | {
|
---|
2077 | if(browserp->smidomainp[i].sid)
|
---|
2078 | dic_release_service(browserp->smidomainp[i].sid);
|
---|
2079 | }
|
---|
2080 | free(browserp->smidomainp);
|
---|
2081 | browserp->curr_smidomain[0] = '\0';
|
---|
2082 | browserp->curr_smidomain_size = 0;
|
---|
2083 | }
|
---|
2084 | strcpy(browserp->curr_smidomain, servp->name);
|
---|
2085 | browserp->smidomainp = malloc(n_services * sizeof(OBJSTATE));
|
---|
2086 | browserp->curr_smidomain_size = n_services;
|
---|
2087 | }
|
---|
2088 | else
|
---|
2089 | return browserp->curr_smidomain_nobjs;
|
---|
2090 | servicep = servp->service_ptr;
|
---|
2091 | for(i = 0; i < n_services; i++)
|
---|
2092 | {
|
---|
2093 | browserp->smidomainp[i].sid = 0;
|
---|
2094 | browserp->smidomainp[i].state[0] = '\0';
|
---|
2095 | if(checkSmiObjName(servicep))
|
---|
2096 | {
|
---|
2097 | strcpy(browserp->smidomainp[i].name, servicep->name);
|
---|
2098 | // strcpy(browserp->smidomainp[i].state, "");
|
---|
2099 | browserp->smidomainp[i].browserp = browserp;
|
---|
2100 | //printf("address %s %08x\n",browserp->smidomainp[i].name, (unsigned int)&(browserp->smidomainp[i]));
|
---|
2101 | sid = dic_info_service(servicep->name,MONITORED,0,0,0,update_smi_state, &(browserp->smidomainp[i]),
|
---|
2102 | no_link_str, 5);
|
---|
2103 | browserp->smidomainp[i].sid = sid;
|
---|
2104 | if(servicep->status == 2)
|
---|
2105 | n_found++;
|
---|
2106 | }
|
---|
2107 | servicep++;
|
---|
2108 | }
|
---|
2109 | servicep = servp->service_ptr;
|
---|
2110 | for(i = 0; i < n_services; i++)
|
---|
2111 | {
|
---|
2112 | if(servicep->status == 2)
|
---|
2113 | {
|
---|
2114 | index = findSmiModeObj(servp->service_ptr, n_services, servicep->name);
|
---|
2115 | browserp->smidomainp[i].mode_index = index;
|
---|
2116 | }
|
---|
2117 | servicep++;
|
---|
2118 | }
|
---|
2119 | browserp->curr_smidomain_nobjs = n_found;
|
---|
2120 | return n_found;
|
---|
2121 | }
|
---|
2122 |
|
---|
2123 | int findSmiModeObj(DNS_SERVICE_INFO *serviceptr, int n_services, char *name)
|
---|
2124 | {
|
---|
2125 | int i;
|
---|
2126 | DNS_SERVICE_INFO *servicep;
|
---|
2127 | char mode_name[256], *ptr, *ptr1, *ptr2;
|
---|
2128 |
|
---|
2129 | servicep = serviceptr;
|
---|
2130 | strcpy(mode_name, name);
|
---|
2131 | ptr1 = mode_name;
|
---|
2132 | if((ptr = strstr(mode_name,"::")))
|
---|
2133 | {
|
---|
2134 | *ptr = '\0';
|
---|
2135 | ptr2 = ptr1;
|
---|
2136 | while((ptr1 = strchr(ptr1,'/')))
|
---|
2137 | {
|
---|
2138 | ptr1++;
|
---|
2139 | ptr2 = ptr1;
|
---|
2140 | }
|
---|
2141 | if(strcmp(ptr2, ptr+2))
|
---|
2142 | *ptr = ':';
|
---|
2143 | }
|
---|
2144 | strcat(mode_name,"_FWM");
|
---|
2145 | printf("Find SMI Mode %s %s\n",name, mode_name);
|
---|
2146 | for(i = 0; i < n_services; i++)
|
---|
2147 | {
|
---|
2148 | if(servicep->status == 3)
|
---|
2149 | {
|
---|
2150 | if(!strcmp(servicep->name, mode_name))
|
---|
2151 | {
|
---|
2152 | printf("Find SMI Mode index %s %s %d\n",mode_name, servicep->name, i);
|
---|
2153 | return i;
|
---|
2154 | }
|
---|
2155 | }
|
---|
2156 | servicep++;
|
---|
2157 | }
|
---|
2158 | return 0;
|
---|
2159 | }
|
---|
2160 |
|
---|
2161 | int checkSmiObjName(DNS_SERVICE_INFO *servicep)
|
---|
2162 | {
|
---|
2163 | int ismode = 0, ret = 0;
|
---|
2164 | char *name;
|
---|
2165 | int matchString();
|
---|
2166 |
|
---|
2167 | name = servicep->name;
|
---|
2168 | if(matchString(name,"SMI/*"))
|
---|
2169 | {
|
---|
2170 | ret = 1;
|
---|
2171 | if(matchString(name,"*&ALLOC*"))
|
---|
2172 | ret = 0;
|
---|
2173 | else if(matchString(name,"*/ACTIONS&PARS"))
|
---|
2174 | ret = 0;
|
---|
2175 | else if(matchString(name,"*/BUSY"))
|
---|
2176 | ret = 0;
|
---|
2177 | else if(matchString(name,"*/CMD"))
|
---|
2178 | ret = 0;
|
---|
2179 | else if(matchString(name,"*/OBJECTSET_LIST"))
|
---|
2180 | ret = 0;
|
---|
2181 | else if(matchString(name,"*/OBJECT_LIST"))
|
---|
2182 | ret = 0;
|
---|
2183 | else if(matchString(name,"*/SMI_VERSION_NUMBER"))
|
---|
2184 | ret = 0;
|
---|
2185 | else if(matchString(name,"*/SET/*"))
|
---|
2186 | ret = 0;
|
---|
2187 | // If JCOP framework
|
---|
2188 | else if(matchString(name,"*_FWDM"))
|
---|
2189 | ret = 0;
|
---|
2190 | else if(matchString(name,"*_FWCNM"))
|
---|
2191 | ret = 0;
|
---|
2192 | else if(matchString(name,"*_FWM"))
|
---|
2193 | {
|
---|
2194 | ismode = 1;
|
---|
2195 | if(matchString(name,"*::*"))
|
---|
2196 | ret = 0;
|
---|
2197 | }
|
---|
2198 | }
|
---|
2199 | if(ret)
|
---|
2200 | {
|
---|
2201 | if(ismode)
|
---|
2202 | servicep->status = 3;
|
---|
2203 | else
|
---|
2204 | servicep->status = 2;
|
---|
2205 | }
|
---|
2206 | return ret;
|
---|
2207 | }
|
---|
2208 |
|
---|
2209 | int matchString( char *wzString, char *wzPattern )
|
---|
2210 | {
|
---|
2211 | switch (*wzPattern){
|
---|
2212 | case '\0':
|
---|
2213 | return !*wzString;
|
---|
2214 | case '*':
|
---|
2215 | return matchString(wzString, wzPattern+1) ||
|
---|
2216 | ( *wzString && matchString(wzString+1, wzPattern) );
|
---|
2217 | case '?':
|
---|
2218 | return *wzString &&
|
---|
2219 | matchString(wzString+1, wzPattern+1);
|
---|
2220 | default:
|
---|
2221 | return (*wzPattern == *wzString) &&
|
---|
2222 | matchString(wzString+1, wzPattern+1);
|
---|
2223 | }
|
---|
2224 | }
|
---|
2225 |
|
---|
2226 | int get_type_size(char type)
|
---|
2227 | {
|
---|
2228 | int size;
|
---|
2229 |
|
---|
2230 | switch(type)
|
---|
2231 | {
|
---|
2232 | case 'L':
|
---|
2233 | case 'l':
|
---|
2234 | size = sizeof(long);
|
---|
2235 | break;
|
---|
2236 | case 'I':
|
---|
2237 | case 'i':
|
---|
2238 | size = sizeof(int);
|
---|
2239 | break;
|
---|
2240 | case 'S':
|
---|
2241 | case 's':
|
---|
2242 | size = sizeof(short);
|
---|
2243 | break;
|
---|
2244 | case 'F':
|
---|
2245 | case 'f':
|
---|
2246 | size = sizeof(float);
|
---|
2247 | break;
|
---|
2248 | case 'D':
|
---|
2249 | case 'd':
|
---|
2250 | size = sizeof(double);
|
---|
2251 | break;
|
---|
2252 | case 'C':
|
---|
2253 | case 'c':
|
---|
2254 | default:
|
---|
2255 | size = 1;
|
---|
2256 | }
|
---|
2257 | return(size);
|
---|
2258 | }
|
---|
2259 |
|
---|
2260 | void did_prepare_command(char *str, char *service, char *format)
|
---|
2261 | {
|
---|
2262 | char type;
|
---|
2263 | int num;
|
---|
2264 | int size, full_size = 0;
|
---|
2265 | char *ptr;
|
---|
2266 | static int last_size = 0;
|
---|
2267 | static void *last_buffer = 0;
|
---|
2268 | void *buffer_ptr;
|
---|
2269 | char *str_ptr;
|
---|
2270 | void did_read_string(char, int, void **, char **);
|
---|
2271 |
|
---|
2272 | str_ptr = str;
|
---|
2273 | ptr = format;
|
---|
2274 | while(*ptr)
|
---|
2275 | {
|
---|
2276 | type = *ptr++;
|
---|
2277 | if(*ptr == ':')
|
---|
2278 | {
|
---|
2279 | ptr++;
|
---|
2280 | size = get_type_size(type);
|
---|
2281 | sscanf(ptr, "%d", &num);
|
---|
2282 | full_size += size * num;
|
---|
2283 | if( (ptr = strchr(ptr,';')) )
|
---|
2284 | ptr++;
|
---|
2285 | else
|
---|
2286 | break;
|
---|
2287 | }
|
---|
2288 | }
|
---|
2289 |
|
---|
2290 | full_size += 256;
|
---|
2291 | if(full_size > last_size)
|
---|
2292 | {
|
---|
2293 | if(last_size)
|
---|
2294 | free(last_buffer);
|
---|
2295 | last_buffer = malloc((size_t)full_size);
|
---|
2296 | last_size = full_size;
|
---|
2297 | }
|
---|
2298 | memset(last_buffer, 0, (size_t)last_size);
|
---|
2299 | buffer_ptr = last_buffer;
|
---|
2300 | ptr = format;
|
---|
2301 | while(*ptr)
|
---|
2302 | {
|
---|
2303 | type = *ptr++;
|
---|
2304 | if(*ptr == ':')
|
---|
2305 | {
|
---|
2306 | ptr++;
|
---|
2307 | sscanf(ptr, "%d", &num);
|
---|
2308 | did_read_string(type, num, &buffer_ptr, &str_ptr);
|
---|
2309 | if(!str_ptr)
|
---|
2310 | break;
|
---|
2311 | if( (ptr = strchr(ptr,';')) )
|
---|
2312 | ptr++;
|
---|
2313 | else
|
---|
2314 | break;
|
---|
2315 | }
|
---|
2316 | else
|
---|
2317 | {
|
---|
2318 | did_read_string(type, 0, &buffer_ptr, &str_ptr);
|
---|
2319 | break;
|
---|
2320 | }
|
---|
2321 | }
|
---|
2322 | full_size = (int) ((char *)buffer_ptr - (char *)last_buffer);
|
---|
2323 | dic_cmnd_service(service,last_buffer,full_size);
|
---|
2324 | }
|
---|
2325 |
|
---|
2326 | int read_str_int(char *str)
|
---|
2327 | {
|
---|
2328 | int i;
|
---|
2329 | if((str[0] == '0') && (str[1] == 'x'))
|
---|
2330 | sscanf(str+2,"%x",&i);
|
---|
2331 | else
|
---|
2332 | sscanf(str,"%d",&i);
|
---|
2333 | return(i);
|
---|
2334 | }
|
---|
2335 |
|
---|
2336 | int read_str_char(char *str, char *cc)
|
---|
2337 | {
|
---|
2338 | int num;
|
---|
2339 |
|
---|
2340 | if(str[0] == '\'')
|
---|
2341 | *cc = str[1];
|
---|
2342 | else if(str[0] == '\"')
|
---|
2343 | return(0);
|
---|
2344 | else if((str[0] == '0') && (str[1] == 'x'))
|
---|
2345 | {
|
---|
2346 | sscanf(str+2,"%x",&num);
|
---|
2347 | if(num <= 0xff)
|
---|
2348 | *cc = (char)num;
|
---|
2349 | else
|
---|
2350 | return(-1);
|
---|
2351 | }
|
---|
2352 | else if(isalpha(str[0]))
|
---|
2353 | return(-1);
|
---|
2354 | else
|
---|
2355 | {
|
---|
2356 | sscanf(str,"%d",&num);
|
---|
2357 | if(num <= 0xff)
|
---|
2358 | *cc = (char)num;
|
---|
2359 | else
|
---|
2360 | return(-1);
|
---|
2361 | }
|
---|
2362 | return(1);
|
---|
2363 | }
|
---|
2364 |
|
---|
2365 | void did_read_string(char type, int num, void **buffer_ptr, char **str_ptr)
|
---|
2366 | {
|
---|
2367 | int i, ret = 0;
|
---|
2368 | float ff;
|
---|
2369 | double dd;
|
---|
2370 | void *ptr;
|
---|
2371 | char *strp, *ptr1;
|
---|
2372 | char cc;
|
---|
2373 | short s;
|
---|
2374 |
|
---|
2375 | strp = *str_ptr;
|
---|
2376 | ptr = *buffer_ptr;
|
---|
2377 | if(!num)
|
---|
2378 | num = 1000000;
|
---|
2379 | switch(type)
|
---|
2380 | {
|
---|
2381 | case 'L':
|
---|
2382 | case 'l':
|
---|
2383 | case 'I':
|
---|
2384 | case 'i':
|
---|
2385 | for(i = 0; i<num; i++)
|
---|
2386 | {
|
---|
2387 | *(int *)ptr = read_str_int(strp);
|
---|
2388 | ptr = (int *)ptr +1;
|
---|
2389 | if( (strp = strchr(strp,' ')) )
|
---|
2390 | strp++;
|
---|
2391 | else
|
---|
2392 | break;
|
---|
2393 | }
|
---|
2394 | break;
|
---|
2395 | case 'S':
|
---|
2396 | case 's':
|
---|
2397 | for(i = 0; i<num; i++)
|
---|
2398 | {
|
---|
2399 | s = (short)read_str_int(strp);
|
---|
2400 | *((short *)ptr) = s;
|
---|
2401 | ptr = (short *)ptr +1;
|
---|
2402 | if( (strp = strchr(strp,' ')) )
|
---|
2403 | strp++;
|
---|
2404 | else
|
---|
2405 | break;
|
---|
2406 | }
|
---|
2407 | break;
|
---|
2408 | case 'F':
|
---|
2409 | case 'f':
|
---|
2410 | for(i = 0; i<num; i++)
|
---|
2411 | {
|
---|
2412 | sscanf(strp,"%f",&ff);
|
---|
2413 | *(float *)ptr = ff;
|
---|
2414 | ptr = (float *)ptr +1;
|
---|
2415 | if( (strp = strchr(strp,' ')) )
|
---|
2416 | strp++;
|
---|
2417 | else
|
---|
2418 | break;
|
---|
2419 | }
|
---|
2420 | break;
|
---|
2421 | case 'D':
|
---|
2422 | case 'd':
|
---|
2423 | for(i = 0; i<num; i++)
|
---|
2424 | {
|
---|
2425 | sscanf(strp,"%f",&ff);
|
---|
2426 | dd = (double)ff;
|
---|
2427 | *(double *)ptr = dd;
|
---|
2428 | ptr = (double *)ptr +1;
|
---|
2429 | if( (strp = strchr(strp,' ')) )
|
---|
2430 | strp++;
|
---|
2431 | else
|
---|
2432 | break;
|
---|
2433 | }
|
---|
2434 | break;
|
---|
2435 | case 'C':
|
---|
2436 | case 'c':
|
---|
2437 | default:
|
---|
2438 | for(i = 0; i<num; i++)
|
---|
2439 | {
|
---|
2440 | if((ret = read_str_char(strp, &cc)) <= 0)
|
---|
2441 | break;
|
---|
2442 | *(char *)ptr = cc;
|
---|
2443 | ptr = (char *)ptr +1;
|
---|
2444 | if( (strp = strchr(strp,' ')) )
|
---|
2445 | strp++;
|
---|
2446 | else
|
---|
2447 | break;
|
---|
2448 | }
|
---|
2449 | if(ret <= 0)
|
---|
2450 | {
|
---|
2451 | if(!ret)
|
---|
2452 | {
|
---|
2453 | strp++;
|
---|
2454 | }
|
---|
2455 | num = (int)strlen(strp)+1;
|
---|
2456 | strncpy((char *)ptr,strp,(size_t)num);
|
---|
2457 | if( (ptr1 = (char *)strchr((char *)ptr,'\"')) )
|
---|
2458 | {
|
---|
2459 | num--;
|
---|
2460 | *ptr1 = '\0';
|
---|
2461 | }
|
---|
2462 | ptr = (char *)ptr + num;
|
---|
2463 | if( (strp = strchr(strp,' ')) )
|
---|
2464 | strp++;
|
---|
2465 | else
|
---|
2466 | break;
|
---|
2467 | }
|
---|
2468 | }
|
---|
2469 | *buffer_ptr = ptr;
|
---|
2470 | *str_ptr = strp;
|
---|
2471 | }
|
---|