FACT++  1.0
int handle_registration ( int  conn_id,
DIS_DNS_PACKET packet,
int  tmout_flag 
)

Definition at line 176 of file dns.c.

References DNS_CONNECTION::already, check_validity(), node::conn_id, serv::conn_id, Curr_n_servers, Curr_n_services, Debug, dim_get_keepalive_timeout(), dim_print_date_time(), dll_empty(), dll_init(), dll_insert_queue(), dll_remove(), dna_set_test_write(), dna_write(), dna_write_nowait(), DNS_accepted_domains, Dns_conns, DNS_DIS_HEADER, DNS_DIS_KILL, DNS_DIS_STOP, do_inform_clients(), do_update_did(), dtq_add_entry(), DIS_DNS_PACKET::format, Memory::free(), get_dns_accepted_domains(), i, inform_clients(), Memory::malloc(), MAX_NAME, MAX_NODE_NAME, MAX_REGISTRATION_UNIT, MAX_TASK_NAME, MY_OS9, DIS_DNS_PACKET::n_services, DNS_CONNECTION::n_services, serv::next, DIS_DNS_PACKET::node_addr, serv::node_head, DIS_DNS_PACKET::node_name, DNS_CONNECTION::node_name, DNS_CONNECTION::old_n_services, DIS_DNS_PACKET::pid, DNS_CONNECTION::pid, DIS_DNS_PACKET::port, DNS_CONNECTION::port, DIS_DNS_PACKET::protocol, DNS_CONNECTION::protocol, release_conn(), serv::serv_def, serv::serv_id, serv::serv_name, serv::server_format, SERVICE_REG::service_def, service_exists(), DNS_CONNECTION::service_head, node::service_id, SERVICE_REG::service_id, service_init(), service_insert(), SERVICE_REG::service_name, service_remove(), DIS_DNS_PACKET::services, node::servp, DNS_DIS_PACKET::size, SRC_DIS, DNS_CONNECTION::src_type, serv::state, DIS_DNS_PACKET::task_name, DNS_CONNECTION::task_name, time, Timer_q, DNS_CONNECTION::timr_ent, DNS_DIS_PACKET::type, update_did(), DNS_CONNECTION::validity, and WATCHDOG_TMOUT_MAX.

Referenced by main(), and recv_rout().

177 {
178  DNS_SERVICE *servp;
179  DNS_DIS_PACKET dis_packet;
180  int i, service_id;
181  int n_services;
182  char *ptr, *ptr1, *ptrt;
183  int found;
184  void do_update_did();
185  void do_inform_clients();
186  void inform_clients();
187  void service_init();
188  void service_insert();
189  void service_remove();
190 #ifdef WIN32
191  extern int time();
192 #endif
193 #ifdef VMS
194  int format;
195 #endif
196  int update_did = 0;
197  int name_too_long = 0;
198  int rem_only = 0;
199 
200  Dns_conns[conn_id].validity = (int)time(NULL);
201  if( !Dns_conns[conn_id].service_head )
202  {
203 
204  if(vtohl(packet->n_services) > 0)
205  {
206  service_id = vtohl(packet->services[0].service_id);
207  if((unsigned)service_id & 0x80000000)
208  rem_only = 1;
209  }
210 /*
211  if( Debug )
212  {
213  dim_print_date_time();
214  printf( " !!!! New Conn %3d : Server %s@%s (PID %d) registering %d services, to delete %d\n",
215  conn_id, packet->task_name,
216  packet->node_name,
217  vtohl(packet->pid),
218  vtohl(packet->n_services), rem_only );
219  fflush(stdout);
220  }
221 */
222  if(rem_only)
223  return 0;
224 
225  Dns_conns[conn_id].already = 0;
226  Dns_conns[conn_id].service_head =
227  (char *) malloc(sizeof(DNS_SERVICE));
228  dll_init( (DLL *) Dns_conns[conn_id].service_head );
229  Dns_conns[conn_id].n_services = 0;
230  Dns_conns[conn_id].timr_ent = NULL;
231  Curr_n_servers++;
232  Dns_conns[conn_id].src_type = SRC_DIS;
233  Dns_conns[conn_id].protocol = vtohl(packet->protocol);
234  strncpy( Dns_conns[conn_id].node_name, packet->node_name,
235  (size_t)MAX_NODE_NAME );
236  strncpy( Dns_conns[conn_id].task_name, packet->task_name,
237  (size_t)(MAX_TASK_NAME-4) );
238  strcpy(Dns_conns[conn_id].long_task_name, packet->task_name);
239  Dns_conns[conn_id].task_name[MAX_TASK_NAME-4-1] = '\0';
240  for(i = 0; i < 4; i++)
241  Dns_conns[conn_id].node_addr[i] = packet->node_addr[i];
242  Dns_conns[conn_id].pid = vtohl(packet->pid);
243  Dns_conns[conn_id].port = vtohl(packet->port);
244 /*
245  if( Debug )
246  {
247  dim_print_date_time();
248  printf( " !!!! New Conn %3d : Server %s@%s (PID %d) registered %d services\n",
249  conn_id, Dns_conns[conn_id].task_name,
250  Dns_conns[conn_id].node_name,
251  Dns_conns[conn_id].pid,
252  vtohl(packet->n_services) );
253  fflush(stdout);
254  }
255 */
256 
257 
258  if(strcmp(Dns_conns[conn_id].task_name,"DIS_DNS"))
259  if(DNS_accepted_domains[0] == 0)
260  {
262  DNS_accepted_domains[0] = (char)0xFF;
263  }
264  if((DNS_accepted_domains[0] != (char)0xFF) && (strcmp(Dns_conns[conn_id].task_name,"DIS_DNS")))
265  {
266  ptr = DNS_accepted_domains;
267  found = 0;
268  while(*ptr)
269  {
270  ptr1 = strchr(ptr,',');
271  if(ptr1)
272  {
273  *ptr1 = '\0';
274  ptr1++;
275  }
276  else
277  {
278  ptr1 = ptr;
279  ptr1 += (int)strlen(ptr);
280  }
281  if(strstr(Dns_conns[conn_id].node_name,ptr))
282  {
283  found = 1;
284  break;
285  }
286  ptr = ptr1;
287  }
288  if(!found)
289  {
290  dis_packet.type = htovl(DNS_DIS_STOP);
291  dis_packet.size = htovl(DNS_DIS_HEADER);
292  if( !dna_write_nowait(conn_id, &dis_packet, DNS_DIS_HEADER) )
293  {
295  printf(" Stop Server: Couldn't write, releasing %d\n",conn_id);
296  fflush(stdout);
297  }
299  printf(" Connection from %s refused, stopping server %s\n",
300  Dns_conns[conn_id].node_name,
301  Dns_conns[conn_id].task_name);
302  fflush(stdout);
303  release_conn(conn_id);
304 
305  return 0;
306  }
307  }
308  if(tmout_flag)
310  (int)(WATCHDOG_TMOUT_MAX * 1.3), check_validity, conn_id);
311  if(strcmp(Dns_conns[conn_id].task_name,"DIS_DNS"))
312  {
314  }
315  Dns_conns[conn_id].old_n_services = 0;
316 /*
317  Dns_conns[conn_id].n_services = 1;
318  do_update_did(conn_id);
319 */
320  update_did = 1;
321 /*
322  Dns_conns[conn_id].old_n_services = 0;
323 */
324  Dns_conns[conn_id].n_services = 0;
325  }
326  else
327  {
328  if( (Dns_conns[conn_id].n_services == -1) &&
329  vtohl(packet->n_services) )
330  {
331  if(strcmp(Dns_conns[conn_id].task_name,"DIS_DNS"))
334  printf( " Server %s out of error\n",
335  Dns_conns[conn_id].task_name );
336  fflush(stdout);
337  Dns_conns[conn_id].n_services = 0;
338  }
339  }
340  n_services = vtohl(packet->n_services);
341  if((int)strlen(Dns_conns[conn_id].task_name) == MAX_TASK_NAME-4-1)
342  name_too_long = 1;
343  for( i = 0; i < n_services; i++ )
344  {
345 /*
346  if( Debug )
347  {
348  dim_print_date_time();
349  printf( " Conn %3d : Server %s@%s (PID %d) registered %s\n",
350  conn_id, Dns_conns[conn_id].task_name,
351  Dns_conns[conn_id].node_name,
352  Dns_conns[conn_id].pid,
353  packet->services[i].service_name );
354  fflush(stdout);
355  }
356 */
357  if(n_services == 1)
358  {
359  if(!strcmp(packet->services[i].service_name, "DUMMY_UPDATE_PACKET"))
360  {
361  do_inform_clients(conn_id);
362  break;
363  }
364  }
365  if( (servp = service_exists(packet->services[i].service_name)) )
366  {
367  /* if service available on another server send kill signal */
368  if((servp->conn_id) && (servp->conn_id != conn_id))
369  {
370  dis_packet.type = htovl(DNS_DIS_KILL);
371  dis_packet.size = htovl(DNS_DIS_HEADER);
372 #ifdef VMS
373  format = vtohl(packet->format);
374  if((format & MY_OS9) || (servp->state == -1))
375  {
376  Dns_conns[servp->conn_id].already = 1;
377  if( !dna_write(servp->conn_id, &dis_packet, DNS_DIS_HEADER) )
378  {
380  printf(" Couldn't write, releasing %d\n",servp->conn_id);
381  fflush(stdout);
382  }
384  printf(" Service %s already declared, killing server %s\n",
385  servp->serv_name, Dns_conns[servp->conn_id].task_name);
386  fflush(stdout);
387  release_client(servp->conn_id);
388  release_conn(servp->conn_id);
389  }
390  else
391  {
392 #endif
393  if((Dns_conns[servp->conn_id].port == Dns_conns[conn_id].port) &&
394  (!strcmp(Dns_conns[servp->conn_id].node_name, Dns_conns[conn_id].node_name)))
395  {
397 printf(" Service %s already declared by conn %d - %s@%s:%d (PID %d), Redeclared by conn %d - %s@%s:%d (PID %d)(same server) - Closing both conns %d %d\n",
398  servp->serv_name, servp->conn_id,
399  Dns_conns[servp->conn_id].task_name,
400  Dns_conns[servp->conn_id].node_name,
401  Dns_conns[servp->conn_id].port,
402  Dns_conns[servp->conn_id].pid,
403  conn_id,
404  Dns_conns[conn_id].task_name,
405  Dns_conns[conn_id].node_name,
406  Dns_conns[conn_id].port,
407  Dns_conns[conn_id].pid,
408  servp->conn_id, conn_id);
409  fflush(stdout);
410  release_conn(servp->conn_id);
411  release_conn(conn_id);
412 /*
413  update_did = 0;
414 */
415  return(0);
416 
417  }
418  else
419  {
420  Dns_conns[conn_id].already = 1;
421 
422  if( !dna_write_nowait(conn_id, &dis_packet, DNS_DIS_HEADER) )
423  {
425  printf(" Kill Server: Couldn't write, releasing %d\n",conn_id);
426  fflush(stdout);
427  }
429 printf(" Service %s already declared by conn %d - %s@%s:%d (PID %d), killing server conn %d - %s@%s:%d (PID %d) \n",
430  servp->serv_name, servp->conn_id,
431  Dns_conns[servp->conn_id].task_name,
432  Dns_conns[servp->conn_id].node_name,
433  Dns_conns[servp->conn_id].port,
434  Dns_conns[servp->conn_id].pid,
435  conn_id,
436  Dns_conns[conn_id].task_name,
437  Dns_conns[conn_id].node_name,
438  Dns_conns[conn_id].port,
439  Dns_conns[conn_id].pid);
440  fflush(stdout);
441 
442  release_conn(conn_id);
443 
444  return(0);
445  }
446 #ifdef VMS
447  }
448 #endif
449  }
450  else if( servp->state != -1 )
451  {
452  if( !dll_empty((DLL *) servp->node_head))
453  {
454  /*there are interested clients waiting*/
455  strncpy( servp->serv_def,
456  packet->services[i].service_def,(size_t)MAX_NAME );
457  servp->conn_id = conn_id;
458  servp->state = 1;
459  servp->server_format = vtohl(packet->format);
460  servp->serv_id = vtohl(packet->services[i].service_id);
462  Dns_conns[conn_id].service_head,
463  (DLL *) servp);
464  Dns_conns[conn_id].n_services++;
465 
466 /*
467  if(n_services == 1)
468 */
469  if(n_services < MAX_REGISTRATION_UNIT)
470  {
471  inform_clients(servp);
472  }
473  continue;
474  }
475  else
476  {
477  /* test if Service is to be removed */
478  service_id = vtohl(packet->services[i].service_id);
479  if((unsigned)service_id & 0x80000000)
480  {
481  dll_remove((DLL *) servp);
482  service_remove(&(servp->next));
483  Curr_n_services--;
484  free(servp);
485  Dns_conns[conn_id].n_services--;
486  if( dll_empty((DLL *) Dns_conns[conn_id].service_head))
487  {
488  if( Debug )
489  {
491  printf( " Conn %3d : Server %s@%s unregistered All services, releasing it.\n",
492  conn_id, Dns_conns[conn_id].task_name,
493  Dns_conns[conn_id].node_name );
494  fflush(stdout);
495  }
496  release_conn(conn_id);
497  return(0);
498  }
499  continue;
500  }
501  }
502  }
503  else
504  {
505  servp->state = 1;
506  Dns_conns[conn_id].n_services++;
507 /*
508  if(n_services == 1)
509 */
510  if(n_services < MAX_REGISTRATION_UNIT)
511  {
512  if( !dll_empty((DLL *) servp->node_head) )
513  {
514  inform_clients( servp );
515  }
516  }
517  continue;
518  }
519 
520  }
521  if(!(servp = service_exists(packet->services[i].service_name)))
522  {
523  servp = (DNS_SERVICE *)malloc(sizeof(DNS_SERVICE));
524  if(name_too_long)
525  {
526  if(strstr(packet->services[i].service_name,"/CLIENT_LIST"))
527  {
528  strncpy(Dns_conns[conn_id].long_task_name, packet->services[i].service_name,
529  (size_t)MAX_NAME);
530  ptrt = strstr(Dns_conns[conn_id].long_task_name,"/CLIENT_LIST");
531  *ptrt = '\0';
532  }
533  }
534  strncpy( servp->serv_name,
535  packet->services[i].service_name,
536  (size_t)MAX_NAME );
537  strncpy( servp->serv_def,
538  packet->services[i].service_def,
539  (size_t)MAX_NAME );
540  servp->state = 1;
541  servp->conn_id = conn_id;
542  servp->server_format = vtohl(packet->format);
543  servp->serv_id = vtohl(packet->services[i].service_id);
544  dll_insert_queue( (DLL *)
545  Dns_conns[conn_id].service_head,
546  (DLL *) servp );
547  Dns_conns[conn_id].n_services++;
548  service_insert( &(servp->next) );
549  servp->node_head = (RED_NODE *) malloc(sizeof(NODE));
550  dll_init( (DLL *) servp->node_head );
551  Curr_n_services++;
552  }
553  }
554  if(update_did)
555  do_update_did(conn_id);
556  if( Debug )
557  {
558  if(vtohl(packet->n_services) != 0)
559  {
561  printf( " Conn %3d : Server %s@%s (PID %d) registered %d services\n",
562  conn_id, Dns_conns[conn_id].task_name,
563  Dns_conns[conn_id].node_name,
564  Dns_conns[conn_id].pid,
565  vtohl(packet->n_services) );
566  fflush(stdout);
567  }
568  }
569 
570  return(1);
571 }
char node_name[MAX_NODE_NAME]
Definition: dim.h:431
void update_did()
Definition: dns.c:573
#define MAX_REGISTRATION_UNIT
Definition: dim.h:161
#define MAX_NAME
Definition: dim.h:182
Definition: dns.c:26
static void release_conn(int conn_id)
Definition: dns.c:1077
int protocol
Definition: dim.h:438
int dim_get_keepalive_timeout()
Definition: tcpip.c:128
void do_inform_clients(int conn_id)
Definition: dns.c:942
void inform_clients(DNS_SERVICE *servp)
Definition: dns.c:984
int dna_write(int conn_id, void *buffer, int size)
Definition: dna.c:455
unsigned service_id
Definition: db_dim_client.c:22
TIMR_ENT * timr_ent
Definition: dim.h:442
DllExp DIM_NOSHARE DNS_CONNECTION * Dns_conns
Definition: conn_handler.c:29
static char DNS_accepted_domains[1024]
Definition: dns.c:88
int i
Definition: db_dim_client.c:21
void dll_insert_queue(DLL *head, DLL *item)
Definition: dll.c:23
char serv_name[MAX_NAME]
Definition: dns.c:49
char * service_head
Definition: dim.h:436
int type
Definition: dim.h:288
char node_addr[4]
Definition: dim.h:274
void * malloc()
Definition: EventBuilder.cc:99
#define DNS_DIS_HEADER
Definition: dim.h:291
void do_update_did(int conn_id)
Definition: dns.c:587
char task_name[MAX_TASK_NAME-4]
Definition: dim.h:273
void dna_set_test_write(int conn_id, int time)
Definition: dna.c:606
void dll_init(DLL *head)
Definition: dll.c:14
int protocol
Definition: dim.h:277
int service_id
Definition: dim.h:265
char service_name[MAX_NAME]
Definition: dim.h:264
void dll_remove(DLL *item)
Definition: dll.c:100
int conn_id
Definition: dns.c:52
int n_services
Definition: dim.h:279
static int Curr_n_servers
Definition: dns.c:73
void service_remove(RED_DNS_SERVICE *servp)
Definition: dns.c:1641
int format
Definition: dim.h:278
char node_name[MAX_NODE_NAME]
Definition: dim.h:272
void check_validity(int conn_id)
Definition: dns.c:610
char task_name[MAX_TASK_NAME-4]
Definition: dim.h:432
int pid
Definition: dim.h:434
RED_NODE * node_head
Definition: dns.c:55
Definition: dim.h:530
Definition: dis.c:69
int server_format
Definition: dns.c:53
int size
Definition: dim.h:287
char service_def[MAX_NAME]
Definition: dim.h:266
#define MAX_TASK_NAME
Definition: dim.h:181
void service_init()
Definition: dns.c:1620
int validity
Definition: dim.h:439
int state
Definition: dns.c:51
void service_insert(RED_DNS_SERVICE *servp)
Definition: dns.c:1631
Warning because the service this data corrsponds to might have been last updated longer ago than Local time
Definition: smartfact.txt:92
struct serv * next
Definition: dis.c:70
#define WATCHDOG_TMOUT_MAX
Definition: dim.h:175
char serv_def[MAX_NAME]
Definition: dns.c:50
DNS_SERVICE * service_exists(char *name)
Definition: dns.c:1649
int dna_write_nowait(int conn_id, void *buffer, int size)
Definition: dna.c:412
int n_services
Definition: dim.h:440
int dll_empty(DLL *head)
Definition: dll.c:88
int port
Definition: dim.h:435
int port
Definition: dim.h:276
static int Timer_q
Definition: dns.c:80
void free(void *mem)
TIMR_ENT * dtq_add_entry(int queue_id, int time, void(*user_routine)(), dim_long tag)
Definition: dtq.c:399
#define MAX_NODE_NAME
Definition: dim.h:180
void dim_print_date_time()
Definition: utilities.c:134
static int Debug
Definition: dns.c:78
SRC_TYPES src_type
Definition: dim.h:430
int pid
Definition: dim.h:275
int already
Definition: dim.h:443
SERVICE_REG services[MAX_SERVICE_UNIT]
Definition: dim.h:280
static int Curr_n_services
Definition: dns.c:72
#define MY_OS9
Definition: dim.h:26
int old_n_services
Definition: dim.h:441
int serv_id
Definition: dns.c:54
int get_dns_accepted_domains(char *domains)
Definition: utilities.c:249
Definition: dns.c:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function: