source: trunk/FACT++/dim/src/dic.c@ 19861

Last change on this file since 19861 was 18920, checked in by tbretz, 7 years ago
Updated to v20r20 - This also includes some minor fixes, I requested.
File size: 52.8 KB
Line 
1
2/*
3 * DIC (Delphi Information Client) Package implements a library of
4 * routines to be used by clients.
5 *
6 * Started on : 10-11-91
7 * Last modification : 10-08-94
8 * Written by : C. Gaspar
9 * Adjusted by : G.C. Ballintijn
10 *
11 */
12
13#ifdef VMS
14# include <cfortran.h>
15# include <assert.h>
16#endif
17
18#define DIMLIB
19#include <dim.h>
20#include <dic.h>
21
22/*
23#define DEBUG
24*/
25
26#ifdef VMS
27#define TMP_ENABLE_AST long int ast_enable = sys$setast(1);
28#define TMP_DISABLE_AST if (ast_enable != SS$_WASSET) sys$setast(0);
29#endif
30
31#define BAD_CONN_TIMEOUT 2
32
33typedef struct bad_conn {
34 struct bad_conn *next;
35 struct bad_conn *prev;
36 DIC_CONNECTION conn;
37 int n_retries;
38 int retrying;
39} DIC_BAD_CONNECTION;
40
41static DIC_SERVICE *Service_pend_head = 0;
42static DIC_SERVICE *Cmnd_head = 0;
43static DIC_SERVICE *Current_server = 0;
44static DIC_BAD_CONNECTION *Bad_connection_head = 0;
45static int Dic_timer_q = 0;
46static int Dns_dic_conn_id = 0;
47static TIMR_ENT *Dns_dic_timr = NULL;
48static int Tmout_max = 0;
49static int Tmout_min = 0;
50static int Threads_off = 0;
51
52static void (*Error_user_routine)() = 0;
53static int Error_conn_id = 0;
54static int Curr_conn_id = 0;
55
56#ifdef DEBUG
57static int Debug_on = 1;
58#else
59static int Debug_on = 0;
60#endif
61
62_DIM_PROTO( unsigned request_service, (char *service_name, int req_type,
63 int req_timeout, void *service_address,
64 int service_size, void (*usr_routine)(void*,void*,int*),
65 dim_long tag, void *fill_addr, int fill_size, int stamped) );
66_DIM_PROTO( int request_command, (char *service_name, void *service_address,
67 int service_size, void (*usr_routine)(void*,int*),
68 dim_long tag, int stamped) );
69_DIM_PROTO( DIC_SERVICE *insert_service, (int type, int timeout, char *name,
70 int *address, int size, void (*routine)(),
71 dim_long tag, int *fill_addr, int fill_size,
72 int pending, int stamped ) );
73_DIM_PROTO( void modify_service, (DIC_SERVICE *servp, int timeout,
74 int *address, int size, void (*routine)(),
75 dim_long tag, int *fill_addr, int fill_size, int stamped) );
76_DIM_PROTO( DIC_SERVICE *locate_command, (char *serv_name) );
77_DIM_PROTO( DIC_SERVICE *locate_pending, (char *serv_name) );
78_DIM_PROTO( DIC_BAD_CONNECTION *locate_bad, (char *node, char *task, int port) );
79_DIM_PROTO( void service_tmout, (int serv_id) );
80_DIM_PROTO( static void request_dns_info, (int retry) );
81_DIM_PROTO( static int handle_dns_info, (DNS_DIC_PACKET *) );
82_DIM_PROTO( void close_dns_conn, (void) );
83_DIM_PROTO( static void release_conn, (int conn_id) );
84_DIM_PROTO( static void get_format_data, (int format, FORMAT_STR *format_data,
85 char *def) );
86_DIM_PROTO( static void execute_service, (DIS_PACKET *packet,
87 DIC_SERVICE *servp, int size) );
88
89void print_packet(DIS_PACKET *packet)
90{
91 dim_print_date_time();
92 printf("Bad ID received from server -> Packet received:\n");
93 printf("\tpacket->size = %d\n",vtohl(packet->size));
94 printf("\tpacket->service_id = %d\n",vtohl(packet->service_id));
95}
96
97void dic_set_debug_on()
98{
99 Debug_on = 1;
100}
101
102void dic_set_debug_off()
103{
104 Debug_on = 0;
105}
106
107void dic_no_threads()
108{
109 Threads_off = 1;
110}
111
112void dic_add_error_handler( void (*user_routine)())
113{
114
115 DISABLE_AST
116 Error_user_routine = user_routine;
117 ENABLE_AST
118}
119
120static void error_handler(int conn_id, int severity, int errcode, char *reason)
121{
122 int last_conn_id;
123
124 if(Error_user_routine)
125 {
126 Error_conn_id = conn_id;
127 last_conn_id = Curr_conn_id;
128 (Error_user_routine)(severity, errcode, reason);
129 Error_conn_id = 0;
130 Curr_conn_id = last_conn_id;
131 }
132 else
133 {
134 dim_print_msg(reason, severity);
135 if(severity == 3)
136 {
137 printf("Exiting!\n");
138 exit(2);
139 }
140 }
141}
142
143static void recv_rout( int conn_id, DIS_PACKET *packet, int size, int status )
144{
145 register DIC_SERVICE *servp, *auxp;
146 register DIC_CONNECTION *dic_connp;
147 int service_id, once_only, found = 0;
148 char node[MAX_NODE_NAME], task[MAX_TASK_NAME];
149 void move_to_notok_service();
150 void do_cmnd_callback();
151 void dim_panic(char *);
152
153 dic_connp = &Dic_conns[conn_id] ;
154 switch( status )
155 {
156 case STA_DISC:
157 if(Debug_on)
158 {
159 dna_get_node_task(conn_id, node, task);
160 dim_print_date_time();
161 printf("Conn %d: Server %s on node %s Disconnected\n",
162 conn_id, task, node);
163 fflush(stdout);
164 }
165 if( !(servp = (DIC_SERVICE *) dic_connp->service_head) )
166 {
167 release_conn( conn_id );
168 break;
169 }
170 while( (servp = (DIC_SERVICE *) dll_get_next(
171 (DLL *) dic_connp->service_head,
172 (DLL *) servp)) )
173 {
174#ifdef DEBUG
175 printf("\t %s was in the service list\n",servp->serv_name);
176 fflush(stdout);
177#endif
178/*
179 Will be done later by the DNS answer
180 service_tmout( servp->serv_id );
181*/
182 if(!strcmp(dic_connp->task_name,"DIS_DNS"))
183 {
184 service_tmout( servp->serv_id );
185 }
186 else if(Dns_dic_conn_id <= 0)
187 {
188 service_tmout( servp->serv_id );
189 }
190/*
191 servp->pending = WAITING_DNS_UP;
192 servp->conn_id = 0;
193*/
194 auxp = servp->prev;
195 move_to_notok_service( servp );
196 servp = auxp;
197 }
198 if( (servp = (DIC_SERVICE *) Cmnd_head) )
199 {
200 while( (servp = (DIC_SERVICE *) dll_get_next(
201 (DLL *) Cmnd_head,
202 (DLL *) servp)) )
203 {
204 if( servp->conn_id == conn_id )
205 {
206#ifdef DEBUG
207 printf("\t%s was in the Command list\n", servp->serv_name);
208 printf("servp = %x, type = %d, pending = %d\n",servp, servp->type, servp->pending);
209 fflush(stdout);
210#endif
211 auxp = servp->prev;
212 if( (servp->type == ONCE_ONLY ) &&
213 (servp->pending == WAITING_SERVER_UP))
214 {
215 service_tmout( servp->serv_id );
216 }
217 else if( (servp->type == COMMAND ) &&
218 (servp->pending == WAITING_CMND_ANSWER))
219 {
220 service_tmout( servp->serv_id );
221 }
222 else
223 {
224 servp->pending = WAITING_DNS_UP;
225 dic_release_service( (unsigned)servp->serv_id );
226 }
227 servp = auxp;
228 }
229 }
230 }
231 release_conn( conn_id );
232 request_dns_info(0);
233 break;
234 case STA_DATA:
235 if( !(DIC_SERVICE *) dic_connp->service_head )
236 break;
237 service_id = vtohl(packet->service_id);
238 if((unsigned)service_id & 0x80000000) /* Service removed by server */
239 {
240 service_id &= 0x7fffffff;
241 if( (servp = (DIC_SERVICE *) id_get_ptr(service_id, SRC_DIC)))
242 {
243 if( servp->type != COMMAND )
244 {
245 service_tmout( servp->serv_id );
246/*
247 servp->pending = WAITING_DNS_UP;
248 servp->conn_id = 0;
249*/
250 move_to_notok_service( servp );
251 }
252 else
253 {
254 service_tmout( servp->serv_id );
255 break;
256 }
257 }
258 else
259 {
260/*
261 print_packet(packet);
262*/
263 if( (servp = (DIC_SERVICE *) Cmnd_head) )
264 {
265 while( (servp = (DIC_SERVICE *) dll_get_next(
266 (DLL *) Cmnd_head,
267 (DLL *) servp)) )
268 {
269 if( servp->conn_id == conn_id )
270 {
271#ifdef DEBUG
272 printf("\t%s was in the Command list\n", servp->serv_name);
273 fflush(stdout);
274#endif
275 auxp = servp->prev;
276 if( (servp->type == ONCE_ONLY ) &&
277 (servp->pending == WAITING_SERVER_UP))
278 {
279 service_tmout( servp->serv_id );
280 }
281 else if( (servp->type == COMMAND ) &&
282 (servp->pending == WAITING_CMND_ANSWER))
283 {
284 service_tmout( servp->serv_id );
285 }
286 else
287 {
288 servp->pending = WAITING_DNS_UP;
289 dic_release_service( (unsigned)servp->serv_id );
290 }
291 servp = auxp;
292 }
293 }
294 }
295 }
296 if( dll_empty((DLL *)dic_connp->service_head) ) {
297 if( (servp = (DIC_SERVICE *) Cmnd_head) ) {
298 while( (servp = (DIC_SERVICE *) dll_get_next(
299 (DLL *) Cmnd_head,
300 (DLL *) servp)) )
301 {
302 if( servp->conn_id == conn_id)
303 found = 1;
304 }
305 }
306 if( !found)
307 {
308 release_conn( conn_id );
309 }
310 }
311 request_dns_info(0);
312 break;
313 }
314 if( (servp = (DIC_SERVICE *) id_get_ptr(service_id, SRC_DIC)))
315 {
316 if(servp->serv_id == service_id)
317 {
318 once_only = 0;
319 if(servp->type == ONCE_ONLY)
320 once_only = 1;
321 else
322 {
323 if( servp->timeout > 0 )
324 {
325 if(servp->timer_ent)
326 dtq_clear_entry( servp->timer_ent );
327 }
328 }
329 Curr_conn_id = conn_id;
330 execute_service(packet, servp, size);
331 Curr_conn_id = 0;
332 if( once_only )
333 {
334 auxp = locate_command(servp->serv_name);
335 if((auxp) && (auxp != servp))
336 {
337 servp->pending = WAITING_DNS_UP;
338 dic_release_service( (unsigned)servp->serv_id );
339 }
340 else
341 {
342 servp->pending = NOT_PENDING;
343 servp->tmout_done = 0;
344 if( servp->timer_ent )
345 {
346 dtq_rem_entry( Dic_timer_q, servp->timer_ent );
347 servp->timer_ent = 0;
348 }
349 }
350 }
351 }
352 }
353/*
354 else
355 {
356 print_packet(packet);
357 if(Error_user_routine)
358 (Error_user_routine)( packet->buffer );
359 }
360*/
361 break;
362 case STA_CONN:
363 if(Debug_on)
364 {
365 dna_get_node_task(conn_id, node, task);
366 dim_print_date_time();
367 printf("Conn %d: Server %s on node %s Connected\n",
368 conn_id, task, node);
369 fflush(stdout);
370 }
371 break;
372 default: dim_panic( "recv_rout(): Bad switch" );
373 }
374}
375
376static void execute_service(DIS_PACKET *packet, DIC_SERVICE *servp, int size)
377{
378 int format;
379 FORMAT_STR format_data_cp[MAX_NAME/4], *formatp;
380 static int *buffer;
381 static int buffer_size = 0;
382 int add_size;
383 int *pkt_buffer, header_size;
384
385 Current_server = servp;
386 format = servp->format;
387 memcpy(format_data_cp, servp->format_data, sizeof(format_data_cp));
388 if((format & 0xF) == ((MY_FORMAT) & 0xF))
389 {
390 for(formatp = format_data_cp; formatp->par_bytes; formatp++)
391 formatp->flags &= (short)0xFFF0; /* NOSWAP */
392 }
393 if( servp->stamped)
394 {
395 pkt_buffer = ((DIS_STAMPED_PACKET *)packet)->buffer;
396 header_size = DIS_STAMPED_HEADER;
397 servp->time_stamp[0] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[0]);
398 if(((unsigned)servp->time_stamp[0] & 0xFFFF0000) == 0xc0de0000)
399 {
400/*
401 servp->time_stamp[0] &= 0x0000FFFF;
402*/
403 servp->time_stamp[1] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[1]);
404 servp->quality = vtohl(((DIS_STAMPED_PACKET *)packet)->quality);
405 }
406 else if((vtohl(((DIS_STAMPED_PACKET *)packet)->reserved[0])) == (int)0xc0dec0de)
407 {
408/*
409 servp->time_stamp[0] &= 0x0000FFFF;
410*/
411 servp->time_stamp[1] = vtohl(((DIS_STAMPED_PACKET *)packet)->time_stamp[1]);
412 servp->quality = vtohl(((DIS_STAMPED_PACKET *)packet)->quality);
413 }
414 else
415 {
416 pkt_buffer = ((DIS_PACKET *)packet)->buffer;
417 header_size = DIS_HEADER;
418 }
419 }
420 else
421 {
422 pkt_buffer = ((DIS_PACKET *)packet)->buffer;
423 header_size = DIS_HEADER;
424 }
425 size -= header_size;
426 if( servp->serv_address )
427 {
428 if( size > servp->serv_size )
429 size = servp->serv_size;
430 add_size = copy_swap_buffer_in(format_data_cp,
431 servp->serv_address,
432 pkt_buffer, size);
433 if( servp->user_routine )
434 (servp->user_routine)(&servp->tag, servp->serv_address, &add_size );
435 }
436 else
437 {
438 if( servp->user_routine )
439 {
440 add_size = size + (size/2);
441 if(!buffer_size)
442 {
443 buffer = (int *)malloc((size_t)add_size);
444 buffer_size = add_size;
445 }
446 else
447 {
448 if( add_size > buffer_size )
449 {
450 free(buffer);
451 buffer = (int *)malloc((size_t)add_size);
452 buffer_size = add_size;
453 }
454 }
455 add_size = copy_swap_buffer_in(format_data_cp,
456 buffer,
457 pkt_buffer, size);
458 (servp->user_routine)( &servp->tag, buffer, &add_size );
459 }
460 }
461 Current_server = 0;
462}
463
464static void recv_dns_dic_rout( int conn_id, DNS_DIC_PACKET *packet, int size, int status )
465{
466 register DIC_SERVICE *servp, *auxp;
467 void dim_panic(char *);
468
469 if(size){}
470 switch( status )
471 {
472 case STA_DISC: /* connection broken */
473 servp = Service_pend_head;
474 while( (servp = (DIC_SERVICE *) dll_get_next(
475 (DLL *) Service_pend_head,
476 (DLL *) servp)) )
477 {
478 if( (servp->pending == WAITING_DNS_ANSWER) ||
479 (servp->pending == WAITING_SERVER_UP))
480 {
481 if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
482 {
483 auxp = servp->prev;
484 servp->pending = WAITING_DNS_UP;
485 service_tmout( servp->serv_id );
486 servp = auxp;
487 }
488 else
489 {
490 servp->pending = WAITING_DNS_UP;
491 }
492 }
493 }
494 dna_close( Dns_dic_conn_id );
495 Dns_dic_conn_id = 0;
496 request_dns_info(0);
497 break;
498 case STA_CONN: /* connection received */
499 dna_set_test_write(conn_id, 2*(dim_get_keepalive_timeout()));
500 if(Dns_dic_conn_id < 0)
501 {
502 Dns_dic_conn_id = conn_id;
503 request_dns_info(0);
504
505 }
506 break;
507 case STA_DATA: /* normal packet */
508 if( vtohl(packet->size) == DNS_DIC_HEADER )
509 {
510 handle_dns_info( packet );
511 }
512 break;
513 default: dim_panic( "recv_dns_dic_rout(): Bad switch" );
514 }
515}
516
517
518void service_tmout( int serv_id )
519{
520 int once_only, size = 0;
521 register DIC_SERVICE *servp;
522 char str[512];
523
524/*
525dim_print_date_time();
526printf("In service tmout\n");
527*/
528 servp=(DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
529 if(!servp)
530 return;
531 if(servp->tmout_done)
532 return;
533/*
534dim_print_date_time();
535printf("In service tmout %s\n", servp->serv_name);
536*/
537 servp->tmout_done = 1;
538 Curr_conn_id = servp->conn_id;
539/*
540 if( servp->type == UPDATE )
541 return;
542*/
543 if( servp->type == COMMAND )
544 {
545 if( servp->user_routine )
546 {
547 if(servp->pending == WAITING_CMND_ANSWER)
548 size = 1;
549 else
550 size = 0;
551 (servp->user_routine)( &servp->tag, &size );
552 }
553 else
554 {
555 if((servp->pending == WAITING_DNS_UP) || (servp->pending == WAITING_DNS_ANSWER))
556 {
557 sprintf(str, "Client Sending Command: Command %s discarded, no DNS answer\n", servp->serv_name);
558 error_handler(0, DIM_ERROR, DIMDNSCNERR, str);
559/*
560 dim_print_date_time();
561 printf("Client Sending Command: Command %s discarded, no DNS answer\n", servp->serv_name);
562 fflush(stdout);
563*/
564 }
565/*
566 else if(servp->pending == WAITING_SERVER_UP)
567 {
568 }
569*/
570 }
571 dic_release_service( (unsigned)servp->serv_id );
572 Curr_conn_id = 0;
573 return;
574 }
575 once_only = 0;
576 if(servp->type == ONCE_ONLY)
577 once_only = 1;
578/*
579 if( servp->fill_address )
580*/
581 if( servp->fill_size >= 0 )
582 {
583 size = servp->fill_size;
584 if( servp->serv_address )
585 {
586 if( size > servp->serv_size )
587 size = servp->serv_size;
588 memcpy(servp->serv_address, servp->fill_address, (size_t)size);
589 if( servp->user_routine )
590 (servp->user_routine)( &servp->tag, servp->serv_address, &size);
591 }
592 else
593 {
594 if( servp->user_routine )
595 (servp->user_routine)( &servp->tag, servp->fill_address, &size);
596 }
597 }
598 if( once_only )
599 {
600 dic_release_service( (unsigned)servp->serv_id );
601 }
602 Curr_conn_id = 0;
603}
604
605
606unsigned dic_info_service( char *serv_name, int req_type, int req_timeout, void *serv_address,
607 int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size )
608{
609 unsigned ret;
610
611 ret = request_service( serv_name, req_type, req_timeout,
612 serv_address, serv_size, usr_routine, tag,
613 fill_addr, fill_size, 0 );
614
615 return(ret);
616}
617
618unsigned dic_info_service_stamped( char *serv_name, int req_type, int req_timeout, void *serv_address,
619 int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size )
620{
621 unsigned ret;
622
623 ret = request_service( serv_name, req_type, req_timeout,
624 serv_address, serv_size, usr_routine, tag,
625 fill_addr, fill_size, 1 );
626
627 return(ret);
628}
629
630unsigned request_service( char *serv_name, int req_type, int req_timeout, void *serv_address,
631 int serv_size, void (*usr_routine)(), dim_long tag, void *fill_addr, int fill_size, int stamped )
632{
633 register DIC_SERVICE *servp;
634 int conn_id;
635 int send_service();
636 int locate_service();
637 void dim_init_threads(void);
638
639 if(!Threads_off)
640 {
641 dim_init_threads();
642 }
643 {
644 DISABLE_AST
645 /* create a timer queue for timeouts if not yet done */
646 if( !Dic_timer_q ) {
647 conn_arr_create( SRC_DIC );
648 Dic_timer_q = dtq_create();
649 }
650
651 /* store_service */
652 if(req_timeout < 0)
653 req_timeout = 0;
654 if(req_type == ONCE_ONLY)
655 {
656 if( !Cmnd_head ) {
657 Cmnd_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE) );
658 dll_init( (DLL *) Cmnd_head );
659 Cmnd_head->serv_id = 0;
660 }
661 if( (servp = locate_command(serv_name)) )
662 {
663 if( (conn_id = servp->conn_id) )
664 {
665 if(servp->pending == NOT_PENDING)
666 {
667 modify_service( servp, req_timeout,
668 (int *)serv_address, serv_size, usr_routine, tag,
669 (int *)fill_addr, fill_size, stamped);
670 servp->pending = WAITING_SERVER_UP;
671 if(send_service(conn_id, servp))
672 {
673 ENABLE_AST
674 return(1);
675 }
676 }
677 }
678 }
679 }
680 servp = insert_service( req_type, req_timeout,
681 serv_name, (int *)serv_address, serv_size, usr_routine, tag,
682 (int *)fill_addr, fill_size, WAITING_DNS_UP, stamped );
683
684 /* get_address of server from name_server */
685
686 if( locate_service(servp) <= 0)
687 {
688/*
689 service_tmout( servp->serv_id );
690*/
691 dtq_start_timer( 0, service_tmout, servp->serv_id);
692 }
693 ENABLE_AST
694 }
695 return((unsigned) servp->serv_id);
696}
697
698
699int dic_cmnd_service( char *serv_name, void *serv_address, int serv_size )
700{
701 int ret;
702
703 ret = request_command( serv_name, serv_address, serv_size,
704 0, 0, 0 );
705
706 return(ret ? 1 : 0);
707
708}
709
710int dic_cmnd_service_stamped( char *serv_name, void *serv_address, int serv_size )
711{
712 int ret;
713
714 ret = request_command( serv_name, serv_address, serv_size,
715 0, 0, 1 );
716
717 return(ret ? 1 : 0);
718
719}
720
721int dic_cmnd_callback( char *serv_name, void *serv_address, int serv_size,
722 void (*usr_routine)(), dim_long tag )
723{
724 int ret;
725
726 ret = request_command( serv_name, serv_address, serv_size,
727 usr_routine, tag, 0 );
728 return(ret ? 1 : 0);
729}
730
731int dic_cmnd_callback_stamped( char *serv_name, void *serv_address, int serv_size,
732 void (*usr_routine)(), dim_long tag )
733{
734 int ret;
735
736 ret = request_command( serv_name, serv_address, serv_size,
737 usr_routine, tag, 1 );
738 return(ret ? 1 : 0);
739}
740
741int request_command(char *serv_name, void *serv_address, int serv_size,
742 void (*usr_routine)(), dim_long tag, int stamped)
743{
744 int conn_id, ret;
745 register DIC_SERVICE *servp, *testp;
746 int *fillp;
747 int send_command();
748 int end_command();
749 void dim_init_threads(void);
750 int locate_service();
751
752 if(!Threads_off)
753 {
754 dim_init_threads();
755 }
756 {
757 DISABLE_AST
758 /* create a timer queue for timeouts if not yet done */
759 if( !Dic_timer_q ) {
760 conn_arr_create( SRC_DIC );
761 Dic_timer_q = dtq_create();
762 }
763
764 /* store_service */
765 if( !Cmnd_head ) {
766 Cmnd_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE) );
767 dll_init( (DLL *) Cmnd_head );
768 Cmnd_head->serv_id = 0;
769 }
770 if( (servp = locate_command(serv_name)) )
771 {
772 if(!(testp = locate_pending(serv_name)))
773 {
774 if( (conn_id = servp->conn_id) )
775 {
776 if(servp->fill_size > 0)
777 free( servp->fill_address );
778 fillp = serv_address;
779 if(serv_size > 0)
780 {
781 fillp = (int *)malloc((size_t)serv_size);
782 memcpy( (char *)fillp, (char *)serv_address, (size_t)serv_size );
783 }
784 servp->fill_address = fillp;
785 servp->fill_size = serv_size;
786/*
787 servp->fill_address = (int *)serv_address;
788 servp->fill_size = serv_size;
789*/
790 servp->user_routine = usr_routine;
791 servp->tag = tag;
792 ret = send_command(conn_id, servp);
793 end_command(servp, ret);
794 ENABLE_AST
795 return(1);
796 }
797 }
798 }
799 servp = insert_service( COMMAND, 0,
800 serv_name, 0, 0, usr_routine, tag,
801 (int *)serv_address, serv_size,
802 WAITING_DNS_UP, stamped );
803 if( locate_service(servp) <= 0)
804 {
805/*
806 service_tmout( servp->serv_id );
807*/
808 dtq_start_timer( 0, service_tmout, servp->serv_id);
809 }
810 ENABLE_AST
811 }
812 return(-1);
813}
814
815DIC_SERVICE *insert_service( int type, int timeout, char *name, int *address, int size,
816 void (*routine)(), dim_long tag, int *fill_addr, int fill_size,
817 int pending, int stamped)
818{
819 register DIC_SERVICE *newp;
820 int *fillp;
821 int service_id;
822 int tout;
823 float ftout;
824
825 DISABLE_AST
826 newp = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE));
827 newp->pending = 0;
828 strncpy( newp->serv_name, name, (size_t)MAX_NAME );
829 newp->type = type;
830 newp->timeout = timeout;
831 newp->serv_address = address;
832 newp->serv_size = size;
833 newp->user_routine = routine;
834 newp->tag = tag;
835 fillp = fill_addr;
836 if(fill_size > 0)
837 {
838 fillp = (int *)malloc((size_t)fill_size);
839 memcpy( (char *) fillp, (char *) fill_addr, (size_t)fill_size );
840 }
841 newp->fill_address = fillp;
842 newp->fill_size = fill_size;
843 newp->conn_id = 0;
844 newp->format_data[0].par_bytes = 0;
845 newp->next = (DIC_SERVICE *)0;
846 service_id = id_get((void *)newp, SRC_DIC);
847 newp->serv_id = service_id;
848 if( !Service_pend_head )
849 {
850 Service_pend_head = (DIC_SERVICE *) malloc(sizeof(DIC_SERVICE));
851 dll_init( (DLL *) Service_pend_head );
852 Service_pend_head->serv_id = 0;
853 }
854 dll_insert_queue( (DLL *) Service_pend_head, (DLL *)newp );
855 newp->timer_ent = NULL;
856 if(type != MONIT_FIRST)
857 {
858 if( timeout )
859 {
860 tout = timeout;
861 if(type != ONCE_ONLY)
862 {
863 if(tout < 10)
864 tout = 10;
865 ftout = (float)tout * (float)1.5;
866 tout = (int)ftout;
867 }
868 newp->curr_timeout = tout;
869 newp->timer_ent = dtq_add_entry( Dic_timer_q,
870 newp->curr_timeout,
871 service_tmout, newp->serv_id );
872 }
873 }
874 newp->pending = pending;
875 newp->tmout_done = 0;
876 newp->stamped = stamped;
877 newp->time_stamp[0] = 0;
878 newp->time_stamp[1] = 0;
879 newp->quality = 0;
880 newp->def[0] = '\0';
881#ifdef VxWorks
882 newp->tid = taskIdSelf();
883#endif
884 ENABLE_AST
885 return(newp);
886}
887
888
889void modify_service( DIC_SERVICE *servp, int timeout, int *address, int size, void (*routine)(),
890 dim_long tag, int *fill_addr, int fill_size, int stamped)
891{
892 int *fillp;
893
894 if( servp->timer_ent )
895 {
896 dtq_rem_entry( Dic_timer_q, servp->timer_ent );
897 servp->timer_ent = 0;
898 }
899 servp->timeout = timeout;
900 servp->serv_address = address;
901 servp->serv_size = size;
902 servp->user_routine = routine;
903 servp->tag = tag;
904 if(servp->fill_size > 0)
905 free( servp->fill_address );
906 fillp = fill_addr;
907 if(fill_size > 0)
908 {
909 fillp = (int *)malloc((size_t)fill_size);
910 memcpy( (char *) fillp, (char *) fill_addr, (size_t)fill_size );
911 }
912 servp->fill_address = fillp;
913 servp->fill_size = fill_size;
914 servp->stamped = stamped;
915 if(timeout)
916 {
917 servp->curr_timeout = timeout;
918 servp->timer_ent = dtq_add_entry( Dic_timer_q,
919 servp->curr_timeout,
920 service_tmout, servp->serv_id );
921 }
922 else
923 servp->timer_ent = NULL;
924}
925
926void dic_change_address( unsigned serv_id, void *serv_address, int serv_size)
927{
928 register DIC_SERVICE *servp;
929
930 DISABLE_AST
931 if( serv_id == 0 )
932 {
933 ENABLE_AST
934 return;
935 }
936 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
937 servp->serv_address = (int *)serv_address;
938 servp->serv_size = serv_size;
939 ENABLE_AST
940}
941
942int dic_get_quality( unsigned serv_id )
943{
944 register DIC_SERVICE *servp;
945
946 DISABLE_AST
947 if( serv_id == 0 )
948 {
949 if(Current_server)
950 servp = Current_server;
951 else
952 {
953
954 ENABLE_AST
955 return(-1);
956 }
957 }
958 else
959 {
960 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
961 }
962 ENABLE_AST
963 return(servp->quality);
964}
965
966char *dic_get_format( unsigned serv_id )
967{
968 register DIC_SERVICE *servp;
969
970 DISABLE_AST
971 if( serv_id == 0 )
972 {
973 if(Current_server)
974 servp = Current_server;
975 else
976 {
977 ENABLE_AST
978 return((char *) 0);
979 }
980 }
981 else
982 {
983 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
984 }
985 ENABLE_AST
986 return(servp->def);
987}
988
989int dic_get_timestamp( unsigned serv_id, int *secs, int *milisecs )
990{
991 register DIC_SERVICE *servp;
992
993 DISABLE_AST
994 *secs = 0;
995 *milisecs = 0;
996 if( serv_id == 0 )
997 {
998 if(Current_server)
999 servp = Current_server;
1000 else
1001 {
1002 ENABLE_AST
1003 return(-1);
1004 }
1005 }
1006 else
1007 {
1008 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
1009 }
1010 ENABLE_AST
1011 if(servp->time_stamp[1])
1012 {
1013 *secs = servp->time_stamp[1];
1014 if(((unsigned)servp->time_stamp[0] & 0xFFFF0000) == 0xc0de0000)
1015 *milisecs = servp->time_stamp[0] & 0x0000FFFF;
1016 else
1017 *milisecs = servp->time_stamp[0];
1018 return(1);
1019 }
1020 else
1021 {
1022/*
1023 *secs = 0;
1024 *milisecs = 0;
1025*/
1026 return(0);
1027 }
1028}
1029
1030void dic_release_service( unsigned service_id )
1031{
1032 register DIC_SERVICE *servp;
1033 register int conn_id, pending;
1034 static DIC_PACKET *dic_packet;
1035 static int packet_size = 0;
1036 DIC_DNS_PACKET dic_dns_packet;
1037 register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
1038 SERVICE_REQ *serv_reqp;
1039 int release_service();
1040
1041 DISABLE_AST
1042 if( !packet_size ) {
1043 dic_packet = (DIC_PACKET *)malloc((size_t)DIC_HEADER);
1044 packet_size = DIC_HEADER;
1045 }
1046 if( service_id == 0 )
1047 {
1048 ENABLE_AST
1049 return;
1050 }
1051 servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
1052 if( servp == 0 )
1053 {
1054 ENABLE_AST
1055 return;
1056 }
1057 if(servp->serv_id != (int)service_id)
1058 {
1059 ENABLE_AST
1060 return;
1061 }
1062 pending = servp->pending;
1063 switch( pending )
1064 {
1065 case NOT_PENDING :
1066 conn_id = servp->conn_id;
1067 strncpy(dic_packet->service_name, servp->serv_name, (size_t)MAX_NAME);
1068 dic_packet->type = htovl(DIM_DELETE);
1069 dic_packet->service_id = (int)htovl(service_id);
1070 dic_packet->size = htovl(DIC_HEADER);
1071 dna_write_nowait( conn_id, dic_packet, DIC_HEADER );
1072 release_service( servp );
1073 break;
1074 case WAITING_SERVER_UP :
1075 if( ( servp->type == COMMAND )||( servp->type == ONCE_ONLY ) )
1076 {
1077 servp->pending = DELETED;
1078 break;
1079 }
1080 if( Dns_dic_conn_id > 0) {
1081 dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1082 dic_dns_p->src_type = htovl(SRC_DIC);
1083 serv_reqp = &dic_dns_p->service;
1084 strcpy( serv_reqp->service_name, servp->serv_name );
1085 serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1086 dna_write( Dns_dic_conn_id, dic_dns_p,
1087 sizeof(DIC_DNS_PACKET) );
1088 }
1089 release_service( servp );
1090 break;
1091 case WAITING_CMND_ANSWER :
1092 case WAITING_DNS_UP :
1093 release_service( servp );
1094 break;
1095 case WAITING_DNS_ANSWER :
1096 servp->pending = DELETED;
1097 break;
1098 }
1099 ENABLE_AST
1100}
1101
1102
1103int release_service( DIC_SERVICE *servicep )
1104{
1105 register DIC_SERVICE *servp;
1106 register int conn_id = 0;
1107 register int found = 0;
1108 register DIC_CONNECTION *dic_connp;
1109 char name[MAX_NAME], *ptr;
1110 int id;
1111
1112 id = servicep->serv_id;
1113 servicep->serv_id = 0;
1114 conn_id = servicep->conn_id;
1115 dic_connp = &Dic_conns[conn_id] ;
1116 dll_remove( (DLL *) servicep );
1117 if( servicep->timer_ent )
1118 {
1119 dtq_rem_entry( Dic_timer_q, servicep->timer_ent );
1120 }
1121/*
1122 if(servicep->type != COMMAND)
1123*/
1124 if(servicep->fill_size > 0)
1125 free( servicep->fill_address );
1126 if(strstr(servicep->serv_name,"/RpcOut"))
1127 {
1128 strcpy(name, servicep->serv_name);
1129 }
1130 else
1131 name[0] = '\0';
1132 free( servicep );
1133 if( conn_id && dic_connp->service_head )
1134 {
1135 if( dll_empty((DLL *)dic_connp->service_head) )
1136 {
1137 if( (servp = (DIC_SERVICE *) Cmnd_head) )
1138 {
1139 while( (servp = (DIC_SERVICE *) dll_get_next(
1140 (DLL *) Cmnd_head,
1141 (DLL *) servp)) )
1142 {
1143 if( servp->conn_id == conn_id)
1144 found = 1;
1145 }
1146 }
1147 if( !found)
1148 {
1149 if(Debug_on)
1150 {
1151 dim_print_date_time();
1152 printf("Conn %d, Server %s on node %s released\n",
1153 conn_id, dic_connp->task_name, dic_connp->node_name);
1154 fflush(stdout);
1155 }
1156 release_conn( conn_id );
1157 }
1158 }
1159 }
1160 if(name[0])
1161 {
1162 ptr = strstr(name,"/RpcOut");
1163 strcpy(ptr + 4, "In");
1164 if( (servp = locate_command(name)) )
1165 release_service(servp);
1166 }
1167 id_free(id, SRC_DIC);
1168 return(1);
1169}
1170
1171
1172int locate_service( DIC_SERVICE *servp )
1173{
1174 extern int open_dns(dim_long, void (*)(), void (*)(), int, int, int);
1175
1176 if(!strcmp(servp->serv_name,"DIS_DNS/SERVER_INFO"))
1177 {
1178 Tmout_min = DID_DNS_TMOUT_MIN;
1179 Tmout_max = DID_DNS_TMOUT_MAX;
1180 }
1181 if(Tmout_min == 0)
1182 {
1183 Tmout_min = DIC_DNS_TMOUT_MIN;
1184 Tmout_max = DIC_DNS_TMOUT_MAX;
1185 }
1186 if( !Dns_dic_conn_id )
1187 {
1188 DISABLE_AST;
1189 Dns_dic_conn_id = open_dns( 0, recv_dns_dic_rout, error_handler,
1190 Tmout_min,
1191 Tmout_max,
1192 SRC_DIC);
1193 if(Dns_dic_conn_id == -2)
1194 error_handler(0, DIM_FATAL, DIMDNSUNDEF, "DIM_DNS_NODE undefined");
1195 ENABLE_AST;
1196 }
1197 if( Dns_dic_conn_id > 0)
1198 {
1199 DISABLE_AST;
1200 request_dns_info(servp->prev->serv_id);
1201 ENABLE_AST;
1202 }
1203
1204 return(Dns_dic_conn_id);
1205}
1206
1207DIC_SERVICE *locate_command( char *serv_name )
1208{
1209 register DIC_SERVICE *servp;
1210
1211 if(!Cmnd_head)
1212 return((DIC_SERVICE *)0);
1213 if( (servp = (DIC_SERVICE *) dll_search( (DLL *) Cmnd_head, serv_name,
1214 (int)strlen(serv_name)+1)) )
1215 return(servp);
1216 return((DIC_SERVICE *)0);
1217}
1218
1219DIC_SERVICE *locate_pending( char *serv_name )
1220{
1221 register DIC_SERVICE *servp;
1222
1223 if(!Service_pend_head)
1224 return((DIC_SERVICE *)0);
1225 if( (servp = (DIC_SERVICE *) dll_search( (DLL *) Service_pend_head, serv_name,
1226 (int)strlen(serv_name)+1)) )
1227 return(servp);
1228 return((DIC_SERVICE *)0);
1229}
1230
1231DIC_BAD_CONNECTION *locate_bad(char *node, char *task, int port)
1232{
1233 DIC_BAD_CONNECTION *bad_connp;
1234
1235 if(!Bad_connection_head)
1236 return((DIC_BAD_CONNECTION *)0);
1237 bad_connp = Bad_connection_head;
1238 while( (bad_connp = (DIC_BAD_CONNECTION *) dll_get_next(
1239 (DLL *) Bad_connection_head,
1240 (DLL *) bad_connp)) )
1241 {
1242 if((!strcmp(bad_connp->conn.node_name, node)) &&
1243 (!strcmp(bad_connp->conn.task_name, task)) &&
1244 (bad_connp->conn.port == port) )
1245 return(bad_connp);
1246 }
1247 return((DIC_BAD_CONNECTION *)0);
1248}
1249
1250static void request_dns_info(int id)
1251{
1252 DIC_SERVICE *servp, *ptr;
1253 int n_pend = 0;
1254 int request_dns_single_info();
1255 extern int open_dns();
1256
1257 DISABLE_AST
1258 if( Dns_dic_conn_id <= 0)
1259 {
1260 Dns_dic_conn_id = open_dns( 0, recv_dns_dic_rout, error_handler,
1261 Tmout_min,
1262 Tmout_max,
1263 SRC_DIC);
1264 if(Dns_dic_conn_id == -2)
1265 error_handler(0, DIM_FATAL, DIMDNSUNDEF, "DIM_DNS_NODE undefined");
1266 }
1267 if( Dns_dic_conn_id > 0)
1268 {
1269 servp = Service_pend_head;
1270 if(id > 0)
1271 {
1272 ptr = (DIC_SERVICE *)id_get_ptr(id, SRC_DIC);
1273 if(ptr)
1274 {
1275 if((ptr->serv_id == id) && (ptr->pending != NOT_PENDING))
1276 servp = ptr;
1277 }
1278 }
1279
1280 while( (servp = (DIC_SERVICE *) dll_get_next(
1281 (DLL *) Service_pend_head,
1282 (DLL *) servp)) )
1283 {
1284 if( servp->pending == WAITING_DNS_UP)
1285 {
1286 if(!request_dns_single_info( servp ))
1287 {
1288 ENABLE_AST
1289 return;
1290 }
1291 n_pend++;
1292 }
1293 if(n_pend == 1000)
1294 {
1295 dtq_start_timer( 0, request_dns_info, servp->serv_id);
1296 ENABLE_AST
1297 return;
1298 }
1299 }
1300 }
1301 else
1302 {
1303 servp = Service_pend_head;
1304 while( (servp = (DIC_SERVICE *) dll_get_next(
1305 (DLL *) Service_pend_head,
1306 (DLL *) servp)) )
1307 {
1308 if( servp->pending == WAITING_DNS_UP)
1309 {
1310 if(( servp->type != COMMAND )&&( servp->type != ONCE_ONLY ))
1311 service_tmout( servp->serv_id );
1312 }
1313 }
1314 }
1315 ENABLE_AST
1316}
1317
1318
1319int request_dns_single_info( DIC_SERVICE *servp )
1320{
1321 static DIC_DNS_PACKET Dic_dns_packet;
1322 static SERVICE_REQ *serv_reqp;
1323 int ret = 1;
1324
1325 if( Dns_dic_conn_id > 0)
1326 {
1327 if(Debug_on)
1328 {
1329 dim_print_date_time();
1330 printf("Requesting DNS Info for %s, id %d\n",
1331 servp->serv_name, servp->serv_id);
1332 }
1333
1334 Dic_dns_packet.src_type = htovl(SRC_DIC);
1335 serv_reqp = &Dic_dns_packet.service;
1336 strcpy( serv_reqp->service_name, servp->serv_name );
1337 serv_reqp->service_id = htovl(servp->serv_id);
1338 servp->pending = WAITING_DNS_ANSWER;
1339 Dic_dns_packet.size = htovl(sizeof(DIC_DNS_PACKET));
1340 if(!dna_write( Dns_dic_conn_id, &Dic_dns_packet,
1341 sizeof(DIC_DNS_PACKET) ) )
1342 {
1343 ret = 0;
1344 }
1345
1346 }
1347 return ret;
1348}
1349
1350
1351static int handle_dns_info( DNS_DIC_PACKET *packet )
1352{
1353 int conn_id, service_id;
1354 DIC_SERVICE *servp;
1355 char *node_name, *task_name;
1356 char node_info[MAX_NODE_NAME+4];
1357 int i, port, protocol, format, pid;
1358 register DIC_CONNECTION *dic_connp ;
1359 DIC_DNS_PACKET dic_dns_packet;
1360 register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
1361 SERVICE_REQ *serv_reqp;
1362 DIC_BAD_CONNECTION *bad_connp;
1363 int retrying = 0;
1364 int tmout;
1365 int send_service_command();
1366 int find_connection();
1367 void move_to_bad_service();
1368 void retry_bad_connection();
1369
1370 service_id = vtohl(packet->service_id);
1371
1372 servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
1373 if(!servp)
1374 return(0);
1375 if(servp->serv_id != service_id)
1376 return(0);
1377 if(Debug_on)
1378 {
1379 dim_print_date_time();
1380 printf("Receiving DNS Info for service %s, id %d\n",servp->serv_name,
1381 vtohl(packet->service_id));
1382 }
1383 node_name = packet->node_name;
1384 if(node_name[0] == (char)0xFF)
1385 {
1386 error_handler(0, DIM_FATAL, DIMDNSREFUS, "DIM_DNS refuses connection");
1387 return(0);
1388 }
1389
1390 task_name = packet->task_name;
1391 strcpy(node_info,node_name);
1392 for(i = 0; i < 4; i ++)
1393 node_info[(int)strlen(node_name)+i+1] = packet->node_addr[i];
1394 port = vtohl(packet->port);
1395 pid = vtohl(packet->pid);
1396 protocol = vtohl(packet->protocol);
1397 format = vtohl(packet->format);
1398
1399 if( Dns_dic_timr )
1400 dtq_clear_entry( Dns_dic_timr );
1401 if( servp->pending == DELETED ) {
1402 if( Dns_dic_conn_id > 0) {
1403 dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1404 dic_dns_p->src_type = htovl(SRC_DIC);
1405 serv_reqp = &dic_dns_p->service;
1406 strcpy( serv_reqp->service_name, servp->serv_name );
1407 serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1408 dna_write( Dns_dic_conn_id, dic_dns_p,
1409 sizeof(DIC_DNS_PACKET) );
1410 }
1411 release_service( servp );
1412 return(0);
1413 }
1414 if( !node_name[0] )
1415 {
1416 servp->pending = WAITING_SERVER_UP;
1417 service_tmout( servp->serv_id );
1418 if( servp->pending == DELETED )
1419 {
1420 if( Dns_dic_conn_id > 0)
1421 {
1422 dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1423 dic_dns_p->src_type = htovl(SRC_DIC);
1424 serv_reqp = &dic_dns_p->service;
1425 strcpy( serv_reqp->service_name, servp->serv_name );
1426 serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1427 dna_write( Dns_dic_conn_id, dic_dns_p,
1428 sizeof(DIC_DNS_PACKET) );
1429 }
1430 release_service( servp );
1431 }
1432 return(0);
1433 }
1434#ifdef OSK
1435 {
1436 register char *ptr;
1437
1438 if(strncmp(node_name,"fidel",5))
1439 {
1440 for(ptr = node_name; *ptr; ptr++)
1441 {
1442 if(*ptr == '.')
1443 {
1444 *ptr = '\0';
1445 break;
1446 }
1447 }
1448 }
1449 }
1450#endif
1451 if( !(conn_id = find_connection(node_name, task_name, port)) )
1452 {
1453 bad_connp = locate_bad(node_name, task_name, port);
1454 if(bad_connp)
1455 retrying = bad_connp->retrying;
1456 if((!bad_connp) || (retrying))
1457 {
1458 if( (conn_id = dna_open_client(node_info, task_name, port,
1459 protocol, recv_rout, error_handler, SRC_DIC)) )
1460 {
1461/*
1462#ifndef VxWorks
1463 if(format & MY_OS9)
1464 {
1465 dna_set_test_write(conn_id, TEST_TIME_OSK);
1466 format &= 0xfffff7ff;
1467 }
1468 else
1469 {
1470 dna_set_test_write(conn_id, TEST_TIME_VMS);
1471 }
1472#endif
1473*/
1474 dna_set_test_write(conn_id, dim_get_keepalive_timeout());
1475 dic_connp = &Dic_conns[conn_id];
1476 strncpy( dic_connp->node_name, node_name,
1477 (size_t)MAX_NODE_NAME);
1478 strncpy( dic_connp->task_name, task_name,
1479 (size_t)MAX_TASK_NAME);
1480 dic_connp->port = port;
1481 dic_connp->pid = pid;
1482 if(Debug_on)
1483 {
1484 dim_print_date_time();
1485 printf("Conn %d, Server %s on node %s Connecting\n",
1486 conn_id, dic_connp->task_name, dic_connp->node_name);
1487 fflush(stdout);
1488 }
1489
1490 dic_connp->service_head =
1491 malloc(sizeof(DIC_SERVICE));
1492 dll_init( (DLL *) dic_connp->service_head);
1493 ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
1494 if(retrying)
1495 {
1496 dll_remove((DLL *)bad_connp->conn.service_head);
1497 free(bad_connp->conn.service_head);
1498 dll_remove((DLL *)bad_connp);
1499 free(bad_connp);
1500 }
1501 }
1502 else
1503 {
1504 if(!retrying)
1505 {
1506 if( !Bad_connection_head )
1507 {
1508 Bad_connection_head = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
1509 dll_init( (DLL *) Bad_connection_head );
1510 Bad_connection_head->conn.service_head = 0;
1511 }
1512 bad_connp = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
1513 bad_connp->n_retries = 0;
1514 bad_connp->conn.service_head = malloc(sizeof(DIC_SERVICE));
1515 dll_init( (DLL *) bad_connp->conn.service_head);
1516
1517 dll_insert_queue( (DLL *) Bad_connection_head, (DLL *) bad_connp );
1518 if(Debug_on)
1519 {
1520 dim_print_date_time();
1521 printf("Failed connecting to Server %s on node %s port %d\n",
1522 task_name, node_name, port);
1523 fflush(stdout);
1524 }
1525 service_tmout( servp->serv_id );
1526 }
1527 bad_connp->n_retries++;
1528 bad_connp->retrying = 0;
1529 strncpy( bad_connp->conn.node_name, node_name, (size_t)MAX_NODE_NAME);
1530 strncpy( bad_connp->conn.task_name, task_name, (size_t)MAX_TASK_NAME);
1531 bad_connp->conn.port = port;
1532 tmout = BAD_CONN_TIMEOUT * (bad_connp->n_retries - 1);
1533 if(tmout > 120)
1534 tmout = 120;
1535/* Can not be 0, the callback of dtq_start_timer(0) is not protected */
1536 if(tmout == 0)
1537 tmout = 1;
1538 dtq_start_timer(tmout, retry_bad_connection, (dim_long)bad_connp);
1539 if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
1540 return(0);
1541 move_to_bad_service(servp, bad_connp);
1542/*
1543 ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
1544
1545 servp = Service_pend_head;
1546 while( (servp = (DIC_SERVICE *) dll_get_next(
1547 (DLL *) Service_pend_head,
1548 (DLL *) servp)) )
1549 {
1550 if( (servp->pending == WAITING_DNS_ANSWER) ||
1551 (servp->pending == WAITING_SERVER_UP))
1552 servp->pending = WAITING_DNS_UP;
1553 }
1554 dna_close( Dns_dic_conn_id );
1555 Dns_dic_conn_id = 0;
1556 request_dns_info(0);
1557*/
1558 return(0);
1559 }
1560 }
1561 else
1562 {
1563 if(!retrying)
1564 service_tmout( servp->serv_id );
1565 if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
1566 return(0);
1567 move_to_bad_service(servp, bad_connp);
1568 return(0);
1569 }
1570 }
1571 strcpy(servp->def, packet->service_def);
1572 get_format_data(format, servp->format_data, servp->def);
1573 servp->format = format;
1574 servp->conn_id = conn_id;
1575
1576 send_service_command( servp );
1577/*
1578 if( ret == 1)
1579 {
1580 if(servp->pending != WAITING_CMND_ANSWER)
1581 servp->pending = NOT_PENDING;
1582 servp->tmout_done = 0;
1583 }
1584*/
1585 return(1);
1586}
1587
1588void retry_bad_connection(DIC_BAD_CONNECTION *bad_connp)
1589{
1590DIC_SERVICE *servp, *auxp;
1591int found = 0;
1592void move_to_notok_service();
1593
1594 if(!bad_connp)
1595 return;
1596 servp = (DIC_SERVICE *)bad_connp->conn.service_head;
1597 while( (servp = (DIC_SERVICE *) dll_get_next(
1598 (DLL *) bad_connp->conn.service_head,
1599 (DLL *) servp)) )
1600 {
1601/*
1602 servp->pending = WAITING_DNS_UP;
1603 servp->conn_id = 0;
1604*/
1605 auxp = servp->prev;
1606 move_to_notok_service( servp );
1607 servp = auxp;
1608 found = 1;
1609 }
1610 bad_connp->retrying = 1;
1611 if(found)
1612 request_dns_info(0);
1613}
1614
1615void move_to_ok_service( DIC_SERVICE *servp, int conn_id )
1616{
1617 if(Dic_conns[conn_id].service_head)
1618 {
1619 DISABLE_AST
1620/*
1621printf("move_to_ok %s\n",servp->serv_name);
1622*/
1623 servp->pending = NOT_PENDING;
1624 servp->tmout_done = 0;
1625 dll_remove( (DLL *) servp );
1626 dll_insert_queue( (DLL *) Dic_conns[conn_id].service_head,
1627 (DLL *) servp );
1628 ENABLE_AST
1629 }
1630}
1631
1632void move_to_bad_service( DIC_SERVICE *servp, DIC_BAD_CONNECTION *bad_connp)
1633{
1634 DISABLE_AST
1635/*
1636printf("move_to_bad %s\n",servp->serv_name);
1637*/
1638 servp->pending = WAITING_DNS_UP;
1639 dll_remove( (DLL *) servp );
1640 dll_insert_queue( (DLL *) bad_connp->conn.service_head, (DLL *) servp );
1641 ENABLE_AST
1642}
1643
1644void move_to_cmnd_service( DIC_SERVICE *servp )
1645{
1646/*
1647 if(servp->pending != WAITING_CMND_ANSWER)
1648*/
1649 DISABLE_AST
1650/*
1651printf("move_to_cmnd %s\n",servp->serv_name);
1652*/
1653 servp->pending = NOT_PENDING;
1654 servp->tmout_done = 0;
1655 dll_remove( (DLL *) servp );
1656 dll_insert_queue( (DLL *) Cmnd_head, (DLL *) servp );
1657 ENABLE_AST
1658}
1659
1660void move_to_notok_service(DIC_SERVICE *servp )
1661{
1662 DISABLE_AST
1663/*
1664printf("move_to_notok %s\n",servp->serv_name);
1665*/
1666 servp->pending = WAITING_DNS_UP;
1667 servp->conn_id = 0;
1668 dll_remove( (DLL *) servp );
1669 dll_insert_queue( (DLL *) Service_pend_head, (DLL *) servp );
1670 ENABLE_AST
1671}
1672
1673static void get_format_data(int format, FORMAT_STR *format_data, char *def)
1674{
1675 register FORMAT_STR *formatp = format_data;
1676 register char code, last_code = 0;
1677 int num;
1678 char *ptr = def;
1679
1680 if(format){}
1681 while(*ptr)
1682 {
1683 switch(*ptr)
1684 {
1685 case 'i':
1686 case 'I':
1687 case 'l':
1688 case 'L':
1689 *ptr = 'I';
1690 break;
1691 case 'x':
1692 case 'X':
1693 *ptr = 'X';
1694 break;
1695 case 's':
1696 case 'S':
1697 *ptr = 'S';
1698 break;
1699 case 'f':
1700 case 'F':
1701 *ptr = 'F';
1702 break;
1703 case 'd':
1704 case 'D':
1705 *ptr = 'D';
1706 break;
1707 case 'c':
1708 case 'C':
1709 *ptr = 'C';
1710 break;
1711 }
1712 ptr++;
1713 }
1714 code = *def;
1715 while(*def)
1716 {
1717 if(code != last_code)
1718 {
1719 formatp->par_num = 0;
1720 formatp->flags = 0;
1721 switch(code)
1722 {
1723 case 'i':
1724 case 'I':
1725 case 'l':
1726 case 'L':
1727 formatp->par_bytes = SIZEOF_LONG;
1728 formatp->flags |= SWAPL;
1729 break;
1730 case 'x':
1731 case 'X':
1732 formatp->par_bytes = SIZEOF_DOUBLE;
1733 formatp->flags |= SWAPD;
1734 break;
1735 case 's':
1736 case 'S':
1737 formatp->par_bytes = SIZEOF_SHORT;
1738 formatp->flags |= SWAPS;
1739 break;
1740 case 'f':
1741 case 'F':
1742 formatp->par_bytes = SIZEOF_LONG;
1743 formatp->flags |= SWAPL;
1744#ifdef vms
1745/*
1746 if((format & 0xF0) != (MY_FORMAT & 0xF0))
1747*/
1748 formatp->flags |= (format & 0xF0);
1749 formatp->flags |= IT_IS_FLOAT;
1750#endif
1751 break;
1752 case 'd':
1753 case 'D':
1754 formatp->par_bytes = SIZEOF_DOUBLE;
1755 formatp->flags |= SWAPD;
1756#ifdef vms
1757/*
1758 if((format & 0xF0) != (MY_FORMAT & 0xF0))
1759*/
1760 formatp->flags |= (format & 0xF0);
1761 formatp->flags |= IT_IS_FLOAT;
1762#endif
1763 break;
1764 case 'c':
1765 case 'C':
1766 case 'b':
1767 case 'B':
1768 case 'v':
1769 case 'V':
1770 formatp->par_bytes = SIZEOF_CHAR;
1771 formatp->flags |= NOSWAP;
1772 break;
1773 }
1774 }
1775 def++;
1776 if(*def != ':')
1777 {
1778/* tested by the server
1779 if(*def)
1780 {
1781 printf("Bad service definition parsing\n");
1782 fflush(stdout);
1783 }
1784 else
1785*/
1786 formatp->par_num = 0;
1787 }
1788 else
1789 {
1790 def++;
1791 sscanf(def,"%d",&num);
1792 formatp->par_num += num;
1793 while((*def != ';') && (*def != '\0'))
1794 def++;
1795 if(*def)
1796 def++;
1797 }
1798 last_code = code;
1799 code = *def;
1800 if(code != last_code)
1801 formatp++;
1802 }
1803 formatp->par_bytes = 0;
1804/*
1805 if((format & 0xF) == (MY_FORMAT & 0xF))
1806 {
1807 for(i = 0, formatp = format_data; i<index;i++, formatp++)
1808 formatp->flags &= 0xF0;
1809 }
1810*/
1811}
1812
1813int end_command(DIC_SERVICE *servp, int ret)
1814{
1815 DIC_SERVICE *aux_servp;
1816 DIC_CONNECTION *dic_connp;
1817
1818 DISABLE_AST
1819 dic_connp = &Dic_conns[servp->conn_id];
1820 if(servp->pending != WAITING_CMND_ANSWER)
1821 {
1822 if((!ret) || (!dic_connp->service_head))
1823 {
1824 servp->pending = WAITING_DNS_UP;
1825 dic_release_service( (unsigned)servp->serv_id );
1826 }
1827 else
1828 {
1829 aux_servp = locate_command(servp->serv_name);
1830 if( !aux_servp )
1831 {
1832 move_to_cmnd_service( servp );
1833 }
1834 else
1835 {
1836 if(aux_servp != servp)
1837 {
1838 servp->pending = WAITING_DNS_UP;
1839 dic_release_service( (unsigned)servp->serv_id );
1840 }
1841 }
1842 }
1843 }
1844 ENABLE_AST
1845 return(ret);
1846}
1847
1848int send_service_command(DIC_SERVICE *servp)
1849{
1850 int ret = 1;
1851 int conn_id;
1852 int send_command();
1853 int send_service();
1854
1855 conn_id = servp->conn_id;
1856 if( servp->type == COMMAND )
1857 {
1858 ret = send_command(conn_id, servp);
1859 end_command(servp, ret);
1860 }
1861 else
1862 {
1863 if( send_service(conn_id, servp))
1864 {
1865 if( servp->type == ONCE_ONLY )
1866 {
1867 if( !locate_command(servp->serv_name) )
1868 {
1869 move_to_cmnd_service( servp );
1870 }
1871 }
1872 else
1873 move_to_ok_service( servp, conn_id );
1874 }
1875 else
1876 {
1877 if( servp->type == ONCE_ONLY )
1878 {
1879 servp->pending = WAITING_DNS_UP;
1880 dic_release_service( (unsigned)servp->serv_id );
1881 }
1882 else
1883 {
1884 servp->pending = WAITING_DNS_UP;
1885 servp->conn_id = 0;
1886/*
1887 release_conn(conn_id);
1888*/
1889 request_dns_info(0);
1890 }
1891 }
1892 }
1893 return(ret);
1894}
1895
1896int send_service(int conn_id, DIC_SERVICE *servp)
1897{
1898 static DIC_PACKET *dic_packet;
1899 static int serv_packet_size = 0;
1900 int type, ret;
1901 char str[256];
1902
1903 if( !serv_packet_size ) {
1904 dic_packet = (DIC_PACKET *)malloc((size_t)DIC_HEADER);
1905 serv_packet_size = DIC_HEADER;
1906 }
1907
1908 strncpy( dic_packet->service_name, servp->serv_name, (size_t)MAX_NAME );
1909 type = servp->type;
1910 if(servp->stamped)
1911 type |= STAMPED;
1912 dic_packet->type = htovl(type);
1913 dic_packet->timeout = htovl(servp->timeout);
1914 dic_packet->service_id = htovl(servp->serv_id);
1915 dic_packet->format = htovl(MY_FORMAT);
1916 dic_packet->size = htovl(DIC_HEADER);
1917 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER);
1918 if(!ret)
1919 {
1920 sprintf(str, "Client Sending Service Request: Couldn't write to Conn %3d : Server %s@%s service %s\n",
1921 conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node, servp->serv_name);
1922 error_handler(0, DIM_ERROR, DIMTCPWRTMO, str);
1923 }
1924 return(ret);
1925}
1926
1927typedef struct
1928{
1929 int ret_code;
1930 int serv_id;
1931} CMNDCB_ITEM;
1932
1933void do_cmnd_callback(CMNDCB_ITEM *itemp)
1934{
1935
1936 DIC_SERVICE *servp;
1937 int ret, serv_id;
1938/*
1939 itemp = (CMNDCB_ITEM *)id_get_ptr(id, SRC_DIC);
1940*/
1941 serv_id = itemp->serv_id;
1942 ret = itemp->ret_code;
1943 servp = (DIC_SERVICE *)id_get_ptr(serv_id, SRC_DIC);
1944 if(servp)
1945 {
1946 if(servp->serv_id == serv_id)
1947 {
1948 Curr_conn_id = servp->conn_id;
1949 (servp->user_routine)( &servp->tag, &ret );
1950 servp->pending = NOT_PENDING;
1951 end_command(servp, ret);
1952 Curr_conn_id = 0;
1953 }
1954 }
1955/*
1956 id_free(id, SRC_DIC);
1957*/
1958 free(itemp);
1959}
1960
1961int send_command(int conn_id, DIC_SERVICE *servp)
1962{
1963 static DIC_PACKET *dic_packet;
1964 static int cmnd_packet_size = 0;
1965 register int size;
1966 int ret;
1967 CMNDCB_ITEM *itemp;
1968 char str[256];
1969
1970 size = servp->fill_size;
1971
1972 if(size < 0)
1973 return(1);
1974
1975 if( !cmnd_packet_size ) {
1976 dic_packet = (DIC_PACKET *)malloc((size_t)(DIC_HEADER + size));
1977 cmnd_packet_size = DIC_HEADER + size;
1978 }
1979 else
1980 {
1981 if( DIC_HEADER + size > cmnd_packet_size ) {
1982 free( dic_packet );
1983 dic_packet = (DIC_PACKET *)malloc((size_t)(DIC_HEADER + size));
1984 cmnd_packet_size = DIC_HEADER + size;
1985 }
1986 }
1987
1988 strncpy(dic_packet->service_name, servp->serv_name, (size_t)MAX_NAME);
1989 dic_packet->type = htovl(COMMAND);
1990 dic_packet->timeout = htovl(0);
1991 dic_packet->format = htovl(MY_FORMAT);
1992
1993 dic_packet->service_id = /*id_get((void *)servp)*/servp->serv_id;
1994
1995 size = copy_swap_buffer_out(servp->format, servp->format_data,
1996 dic_packet->buffer, servp->fill_address,
1997 size);
1998 dic_packet->size = htovl( size + DIC_HEADER);
1999 if( servp->user_routine )
2000 {
2001 servp->pending = WAITING_CMND_ANSWER;
2002 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
2003 itemp = (CMNDCB_ITEM *)malloc(sizeof(CMNDCB_ITEM));
2004 itemp->serv_id = servp->serv_id;
2005 itemp->ret_code = ret;
2006/*
2007 id = id_get((void *)itemp, SRC_DIC);
2008*/
2009 dtq_start_timer(0, do_cmnd_callback, (dim_long)itemp);
2010/*
2011 (servp->user_routine)( &servp->tag, &ret );
2012*/
2013 }
2014 else
2015 {
2016 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
2017 }
2018/*
2019 if(!ret)
2020 {
2021 servp->pending = WAITING_DNS_UP;
2022 dic_release_service( (unsigned)servp->serv_id );
2023 }
2024*/
2025 /*
2026 ret = dna_write_nowait(conn_id, dic_packet, DIC_HEADER + size);
2027 if(!ret)
2028 {
2029 servp->pending = WAITING_DNS_UP;
2030 dic_release_service( (unsigned)servp->serv_id );
2031 }
2032 else
2033 {
2034 dim_usleep(5000);
2035 if( servp->user_routine )
2036 (servp->user_routine)( &servp->tag, &ret );
2037 }
2038*/
2039 if(!ret)
2040 {
2041 sprintf(str, "Client Sending Command: Couldn't write to Conn %3d : Server %s@%s\n", conn_id,
2042 Net_conns[conn_id].task, Net_conns[conn_id].node);
2043 error_handler(0, DIM_ERROR, DIMTCPWRTMO, str);
2044 }
2045 return(ret);
2046}
2047
2048int find_connection(char *node, char *task, int port)
2049{
2050 register int i;
2051 register DIC_CONNECTION *dic_connp;
2052
2053 if(task){}
2054 for( i=0, dic_connp = Dic_conns; i<Curr_N_Conns; i++, dic_connp++ )
2055 {
2056/*
2057 if((!strcmp(dic_connp->task_name, task))
2058 &&(!strcmp(dic_connp->node_name, node)))
2059*/
2060 if((!strcmp(dic_connp->node_name, node))
2061 && (dic_connp->port == port))
2062 return(i);
2063 }
2064 return(0);
2065}
2066
2067int dic_get_id(char *name)
2068{
2069 extern int get_proc_name(char *name);
2070
2071 get_proc_name(name);
2072 strcat(name,"@");
2073 get_node_name(&name[(int)strlen(name)]);
2074 return(1);
2075}
2076
2077#ifdef VxWorks
2078void dic_destroy(int tid)
2079{
2080 register int i;
2081 register DIC_CONNECTION *dic_connp;
2082 register DIC_SERVICE *servp, *auxp;
2083 int found = 0;
2084
2085 if(!Dic_conns)
2086 return;
2087 for( i=0, dic_connp = Dic_conns; i<Curr_N_Conns; i++, dic_connp++ )
2088 {
2089 if(servp = (DIC_SERVICE *) dic_connp->service_head)
2090 {
2091 while( servp = (DIC_SERVICE *) dll_get_next(
2092 (DLL *) dic_connp->service_head,
2093 (DLL *) servp) )
2094 {
2095 if( servp->tid == tid )
2096 {
2097 auxp = servp->prev;
2098 dic_release_service( (unsigned)servp->serv_id );
2099 servp = auxp;
2100 if(!dic_connp->service_head)
2101 break;
2102 }
2103 else
2104 found = 1;
2105 }
2106 }
2107 }
2108 if(!found)
2109 {
2110 if(Dns_dic_conn_id > 0)
2111 {
2112 dna_close( Dns_dic_conn_id );
2113 Dns_dic_conn_id = 0;
2114 }
2115 }
2116}
2117
2118void DIMDestroy(int tid)
2119{
2120 dis_destroy(tid);
2121 dic_destroy(tid);
2122}
2123
2124#endif
2125
2126static void release_conn(int conn_id)
2127{
2128 register DIC_CONNECTION *dic_connp = &Dic_conns[conn_id];
2129
2130 if(Debug_on)
2131 {
2132 dim_print_date_time();
2133 printf("Conn %d, Server %s on node %s completely released\n",
2134 conn_id, dic_connp->task_name, dic_connp->node_name);
2135 fflush(stdout);
2136 }
2137 dic_connp->task_name[0] = '\0';
2138 dic_connp->port = 0;
2139 if(dic_connp->service_head)
2140 {
2141 free((DIC_SERVICE *)dic_connp->service_head);
2142 dic_connp->service_head = (char *)0;
2143 }
2144 dna_close(conn_id);
2145}
2146
2147void dic_close_dns()
2148{
2149 register DIC_SERVICE *servp, *auxp;
2150
2151 if(Dns_dic_conn_id > 0)
2152 {
2153 if( (servp = (DIC_SERVICE *) Cmnd_head) )
2154 {
2155 while( (servp = (DIC_SERVICE *) dll_get_next(
2156 (DLL *) Cmnd_head,
2157 (DLL *) servp)) )
2158 {
2159#ifdef DEBUG
2160 printf("\t%s was in the Command list\n", servp->serv_name);
2161 printf("type = %d, pending = %d\n",servp->type, servp->pending);
2162 fflush(stdout);
2163#endif
2164 auxp = servp->prev;
2165 if( (servp->type == ONCE_ONLY ) &&
2166 (servp->pending == WAITING_SERVER_UP))
2167 {
2168 service_tmout( servp->serv_id );
2169 }
2170 else if( (servp->type == COMMAND ) &&
2171 (servp->pending == WAITING_CMND_ANSWER))
2172 {
2173 service_tmout( servp->serv_id );
2174 }
2175 else
2176 {
2177 servp->pending = WAITING_DNS_UP;
2178 dic_release_service( (unsigned)servp->serv_id );
2179 }
2180 servp = auxp;
2181 }
2182 }
2183 dna_close( Dns_dic_conn_id );
2184 Dns_dic_conn_id = 0;
2185 }
2186}
2187/*
2188append_service(service_info_buffer, servp)
2189char *service_info_buffer;
2190SERVICE *servp;
2191{
2192 char name[MAX_NAME], *ptr;
2193
2194 if(strstr(servp->name,"/RpcIn"))
2195 {
2196 strcpy(name,servp->name);
2197 ptr = (char *)strstr(name,"/RpcIn");
2198 *ptr = 0;
2199 strcat(service_info_buffer, name);
2200 strcat(service_info_buffer, "|");
2201 if(servp->def[0])
2202 {
2203 strcat(service_info_buffer, servp->def);
2204 }
2205 strcat(name,"/RpcOut");
2206 if(servp = find_service(name))
2207 {
2208 strcat(service_info_buffer, ",");
2209 if(servp->def[0])
2210 {
2211 strcat(service_info_buffer, servp->def);
2212 }
2213 }
2214 strcat(service_info_buffer, "|RPC");
2215 strcat(service_info_buffer, "\n");
2216 }
2217 else if(strstr(servp->name,"/RpcOut"))
2218 {
2219 }
2220 else
2221 {
2222 strcat(service_info_buffer, servp->name);
2223 strcat(service_info_buffer, "|");
2224 if(servp->def[0])
2225 {
2226 strcat(service_info_buffer, servp->def);
2227 }
2228 strcat(service_info_buffer, "|");
2229 if(servp->type == COMMAND)
2230 {
2231 strcat(service_info_buffer, "CMD");
2232 }
2233 strcat(service_info_buffer, "\n");
2234 }
2235}
2236*/
2237
2238char *dic_get_error_services()
2239{
2240 return(dic_get_server_services(Error_conn_id));
2241}
2242
2243char *dic_get_server_services(int conn_id)
2244{
2245 DIC_SERVICE *servp;
2246 DIC_CONNECTION *dic_connp;
2247 int n_services = 0;
2248 int max_size;
2249 static int curr_allocated_size = 0;
2250 static char *service_info_buffer;
2251 char *buff_ptr;
2252
2253
2254 if(!conn_id)
2255 return((char *)0);
2256 dic_connp = &Dic_conns[conn_id];
2257 if( (servp = (DIC_SERVICE *) dic_connp->service_head) )
2258 {
2259 while( (servp = (DIC_SERVICE *) dll_get_next(
2260 (DLL *) dic_connp->service_head,
2261 (DLL *) servp)) )
2262 {
2263 n_services++;
2264 }
2265 if(!n_services)
2266 return((char *)0);
2267 max_size = n_services * MAX_NAME;
2268 if(!curr_allocated_size)
2269 {
2270 service_info_buffer = (char *)malloc((size_t)max_size);
2271 curr_allocated_size = max_size;
2272 }
2273 else if (max_size > curr_allocated_size)
2274 {
2275 free(service_info_buffer);
2276 service_info_buffer = (char *)malloc((size_t)max_size);
2277 curr_allocated_size = max_size;
2278 }
2279 service_info_buffer[0] = '\0';
2280 buff_ptr = service_info_buffer;
2281
2282 servp = (DIC_SERVICE *) dic_connp->service_head;
2283 while( (servp = (DIC_SERVICE *) dll_get_next(
2284 (DLL *) dic_connp->service_head,
2285 (DLL *) servp)) )
2286 {
2287 strcat(buff_ptr, servp->serv_name);
2288 strcat(buff_ptr, "\n");
2289 buff_ptr += (int)strlen(buff_ptr);
2290 }
2291 }
2292 else
2293 {
2294 return((char *)0);
2295 }
2296/*
2297 dim_print_date_time();
2298 printf("Server %s@%s provides services:\n",
2299 dic_connp->task_name, dic_connp->node_name);
2300 printf("%s\n",service_info_buffer);
2301*/
2302 return(service_info_buffer);
2303}
2304
2305int dic_get_conn_id()
2306{
2307 return(Curr_conn_id);
2308}
2309
2310int dic_get_server(char *name)
2311{
2312 int ret = 0;
2313 char node[MAX_NODE_NAME], task[MAX_TASK_NAME];
2314
2315 DISABLE_AST
2316
2317 if(Curr_conn_id)
2318 {
2319 dna_get_node_task(Curr_conn_id, node, task);
2320 strcpy(name,task);
2321 strcat(name,"@");
2322 strcat(name,node);
2323 ret = Curr_conn_id;
2324 }
2325 ENABLE_AST
2326 return(ret);
2327}
2328
2329int dic_get_server_pid(int *pid)
2330{
2331 int ret = 0;
2332
2333 DISABLE_AST
2334
2335 *pid = 0;
2336 if(Curr_conn_id)
2337 {
2338 *pid = Dic_conns[Curr_conn_id].pid;
2339 ret = Curr_conn_id;
2340 }
2341 ENABLE_AST
2342 return(ret);
2343}
2344
2345void dic_stop()
2346{
2347 int dic_find_server_conns();
2348
2349 dtq_delete(Dic_timer_q);
2350 dic_close_dns();
2351 if(!dic_find_server_conns())
2352 dim_stop();
2353}
2354
2355int dic_find_server_conns()
2356{
2357 int i;
2358 int n = 0;
2359
2360 for( i = 0; i< Curr_N_Conns; i++ )
2361 {
2362 if(Net_conns[i].channel != 0)
2363 {
2364 if(Dna_conns[i].read_ast == recv_rout)
2365 {
2366 dna_close(i);
2367 }
2368 else
2369 {
2370 n++;
2371 }
2372 }
2373 }
2374 return(n);
2375}
2376
2377#ifdef VMS
2378/* CFORTRAN WRAPPERS */
2379FCALLSCFUN9(INT, dic_info_service, DIC_INFO_SERVICE, dic_info_service,
2380 STRING, INT, INT, PVOID, INT, PVOID, INT, PVOID, INT)
2381FCALLSCFUN9(INT, dic_info_service_stamped, DIC_INFO_SERVICE_STAMPED,
2382 dic_info_service_stamped,
2383 STRING, INT, INT, PVOID, INT, PVOID, INT, PVOID, INT)
2384FCALLSCFUN3(INT, dic_cmnd_service, DIC_CMND_SERVICE, dic_cmnd_service,
2385 STRING, PVOID, INT)
2386FCALLSCFUN5(INT, dic_cmnd_callback, DIC_CMND_CALLBACK, dic_cmnd_callback,
2387 STRING, PVOID, INT, PVOID, INT)
2388FCALLSCFUN3(INT, dic_cmnd_service_stamped, DIC_CMND_SERVICE_STAMPED,
2389 dic_cmnd_service_stamped,
2390 STRING, PVOID, INT)
2391FCALLSCFUN5(INT, dic_cmnd_callback_stamped, DIC_CMND_CALLBACK_STAMPED,
2392 dic_cmnd_callback_stamped,
2393 STRING, PVOID, INT, PVOID, INT)
2394FCALLSCSUB3( dic_change_address, DIC_CHANGE_ADDRESS, dic_change_address,
2395 INT, PVOID, INT)
2396FCALLSCSUB1( dic_release_service, DIC_RELEASE_SERVICE, dic_release_service,
2397 INT)
2398FCALLSCFUN1(INT, dic_get_quality, DIC_GET_QUALITY, dic_get_quality,
2399 INT)
2400FCALLSCFUN3(INT, dic_get_timestamp, DIC_GET_TIMESTAMP, dic_get_timestamp,
2401 INT,PINT,PINT)
2402FCALLSCFUN1(INT, dic_get_id, DIC_GET_ID, dic_get_id,
2403 PSTRING)
2404FCALLSCFUN1(STRING, dic_get_format, DIC_GET_FORMAT, dic_get_format,
2405 INT)
2406#endif
Note: See TracBrowser for help on using the repository browser.