FACT++  1.0
static int handle_dns_info ( DNS_DIC_PACKET packet)
static

Definition at line 1346 of file dic.c.

References BAD_CONN_TIMEOUT, COMMAND, bad_conn::conn, dic_serv::conn_id, Debug_on, dic_serv::def, DELETED, Dic_conns, DIM_FATAL, dim_get_keepalive_timeout(), dim_print_date_time(), DIMDNSREFUS, dll_init(), dll_insert_queue(), dll_remove(), dna_open_client(), dna_set_test_write(), dna_write(), Dns_dic_conn_id, dtq_clear_entry(), dtq_start_timer(), error_handler(), find_connection(), DNS_DIC_PACKET::format, dic_serv::format, dic_serv::format_data, Memory::free(), get_format_data(), i, id_get_ptr(), locate_bad(), Memory::malloc(), MAX_NODE_NAME, MAX_TASK_NAME, move_to_bad_service(), bad_conn::n_retries, DNS_DIC_PACKET::node_addr, DNS_DIC_PACKET::node_name, DIC_CONNECTION::node_name, ONCE_ONLY, dic_serv::pending, DNS_DIC_PACKET::pid, DIC_CONNECTION::pid, DNS_DIC_PACKET::port, DIC_CONNECTION::port, DNS_DIC_PACKET::protocol, recv_rout(), release_service(), retry_bad_connection(), bad_conn::retrying, send_service_command(), serv_id, dic_serv::serv_id, dic_serv::serv_name, DIC_DNS_PACKET::service, DNS_DIC_PACKET::service_def, DIC_CONNECTION::service_head, service_id, SERVICE_REQ::service_id, DNS_DIC_PACKET::service_id, SERVICE_REQ::service_name, service_tmout(), DIC_DNS_PACKET::size, SRC_DIC, DIC_DNS_PACKET::src_type, DNS_DIC_PACKET::task_name, DIC_CONNECTION::task_name, dic_serv::type, and WAITING_SERVER_UP.

Referenced by recv_dns_dic_rout().

1347 {
1348  int conn_id, service_id;
1349  DIC_SERVICE *servp;
1350  char *node_name, *task_name;
1351  char node_info[MAX_NODE_NAME+4];
1352  int i, port, protocol, format, pid;
1353  register DIC_CONNECTION *dic_connp ;
1354  DIC_DNS_PACKET dic_dns_packet;
1355  register DIC_DNS_PACKET *dic_dns_p = &dic_dns_packet;
1356  SERVICE_REQ *serv_reqp;
1357  DIC_BAD_CONNECTION *bad_connp;
1358  int retrying = 0;
1359  int tmout;
1360  int send_service_command();
1361  int find_connection();
1362  void move_to_bad_service();
1363  void retry_bad_connection();
1364 
1365  service_id = vtohl(packet->service_id);
1366 
1367  servp = (DIC_SERVICE *)id_get_ptr(service_id, SRC_DIC);
1368  if(!servp)
1369  return(0);
1370  if(servp->serv_id != service_id)
1371  return(0);
1372  if(Debug_on)
1373  {
1375  printf("Receiving DNS Info for service %s, id %d\n",servp->serv_name,
1376  vtohl(packet->service_id));
1377  }
1378  node_name = packet->node_name;
1379  if(node_name[0] == (char)0xFF)
1380  {
1381  error_handler(0, DIM_FATAL, DIMDNSREFUS, "DIM_DNS refuses connection");
1382  return(0);
1383  }
1384 
1385  task_name = packet->task_name;
1386  strcpy(node_info,node_name);
1387  for(i = 0; i < 4; i ++)
1388  node_info[(int)strlen(node_name)+i+1] = packet->node_addr[i];
1389  port = vtohl(packet->port);
1390  pid = vtohl(packet->pid);
1391  protocol = vtohl(packet->protocol);
1392  format = vtohl(packet->format);
1393 
1394  if( Dns_dic_timr )
1396  if( servp->pending == DELETED ) {
1397  if( Dns_dic_conn_id > 0) {
1398  dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1399  dic_dns_p->src_type = htovl(SRC_DIC);
1400  serv_reqp = &dic_dns_p->service;
1401  strcpy( serv_reqp->service_name, servp->serv_name );
1402  serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1403  dna_write( Dns_dic_conn_id, dic_dns_p,
1404  sizeof(DIC_DNS_PACKET) );
1405  }
1406  release_service( servp );
1407  return(0);
1408  }
1409  if( !node_name[0] )
1410  {
1411  servp->pending = WAITING_SERVER_UP;
1412  service_tmout( servp->serv_id );
1413  if( servp->pending == DELETED )
1414  {
1415  if( Dns_dic_conn_id > 0)
1416  {
1417  dic_dns_p->size = htovl(sizeof(DIC_DNS_PACKET));
1418  dic_dns_p->src_type = htovl(SRC_DIC);
1419  serv_reqp = &dic_dns_p->service;
1420  strcpy( serv_reqp->service_name, servp->serv_name );
1421  serv_reqp->service_id = (int)htovl((unsigned)servp->serv_id | 0x80000000);
1422  dna_write( Dns_dic_conn_id, dic_dns_p,
1423  sizeof(DIC_DNS_PACKET) );
1424  }
1425  release_service( servp );
1426  }
1427  return(0);
1428  }
1429 #ifdef OSK
1430  {
1431  register char *ptr;
1432 
1433  if(strncmp(node_name,"fidel",5))
1434  {
1435  for(ptr = node_name; *ptr; ptr++)
1436  {
1437  if(*ptr == '.')
1438  {
1439  *ptr = '\0';
1440  break;
1441  }
1442  }
1443  }
1444  }
1445 #endif
1446  if( !(conn_id = find_connection(node_name, task_name, port)) )
1447  {
1448  bad_connp = locate_bad(node_name, task_name, port);
1449  if(bad_connp)
1450  retrying = bad_connp->retrying;
1451  if((!bad_connp) || (retrying))
1452  {
1453  if( (conn_id = dna_open_client(node_info, task_name, port,
1454  protocol, recv_rout, error_handler, SRC_DIC)) )
1455  {
1456 /*
1457 #ifndef VxWorks
1458  if(format & MY_OS9)
1459  {
1460  dna_set_test_write(conn_id, TEST_TIME_OSK);
1461  format &= 0xfffff7ff;
1462  }
1463  else
1464  {
1465  dna_set_test_write(conn_id, TEST_TIME_VMS);
1466  }
1467 #endif
1468 */
1470  dic_connp = &Dic_conns[conn_id];
1471  strncpy( dic_connp->node_name, node_name,
1472  (size_t)MAX_NODE_NAME);
1473  strncpy( dic_connp->task_name, task_name,
1474  (size_t)MAX_TASK_NAME);
1475  dic_connp->port = port;
1476  dic_connp->pid = pid;
1477  if(Debug_on)
1478  {
1480  printf("Conn %d, Server %s on node %s Connecting\n",
1481  conn_id, dic_connp->task_name, dic_connp->node_name);
1482  fflush(stdout);
1483  }
1484 
1485  dic_connp->service_head =
1486  malloc(sizeof(DIC_SERVICE));
1487  dll_init( (DLL *) dic_connp->service_head);
1488  ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
1489  if(retrying)
1490  {
1491  dll_remove((DLL *)bad_connp->conn.service_head);
1492  free(bad_connp->conn.service_head);
1493  dll_remove((DLL *)bad_connp);
1494  free(bad_connp);
1495  }
1496  }
1497  else
1498  {
1499  if(!retrying)
1500  {
1501  if( !Bad_connection_head )
1502  {
1506  }
1507  bad_connp = (DIC_BAD_CONNECTION *) malloc(sizeof(DIC_BAD_CONNECTION));
1508  bad_connp->n_retries = 0;
1509  bad_connp->conn.service_head = malloc(sizeof(DIC_SERVICE));
1510  dll_init( (DLL *) bad_connp->conn.service_head);
1511 
1512  dll_insert_queue( (DLL *) Bad_connection_head, (DLL *) bad_connp );
1513  if(Debug_on)
1514  {
1516  printf("Failed connecting to Server %s on node %s port %d\n",
1517  task_name, node_name, port);
1518  fflush(stdout);
1519  }
1520  service_tmout( servp->serv_id );
1521  }
1522  bad_connp->n_retries++;
1523  bad_connp->retrying = 0;
1524  strncpy( bad_connp->conn.node_name, node_name, (size_t)MAX_NODE_NAME);
1525  strncpy( bad_connp->conn.task_name, task_name, (size_t)MAX_TASK_NAME);
1526  bad_connp->conn.port = port;
1527  tmout = BAD_CONN_TIMEOUT * (bad_connp->n_retries - 1);
1528  if(tmout > 120)
1529  tmout = 120;
1530 /* Can not be 0, the callback of dtq_start_timer(0) is not protected */
1531  if(tmout == 0)
1532  tmout = 1;
1533  dtq_start_timer(tmout, retry_bad_connection, (dim_long)bad_connp);
1534  if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
1535  return(0);
1536  move_to_bad_service(servp, bad_connp);
1537 /*
1538  ((DIC_SERVICE *)(dic_connp->service_head))->serv_id = 0;
1539 
1540  servp = Service_pend_head;
1541  while( (servp = (DIC_SERVICE *) dll_get_next(
1542  (DLL *) Service_pend_head,
1543  (DLL *) servp)) )
1544  {
1545  if( (servp->pending == WAITING_DNS_ANSWER) ||
1546  (servp->pending == WAITING_SERVER_UP))
1547  servp->pending = WAITING_DNS_UP;
1548  }
1549  dna_close( Dns_dic_conn_id );
1550  Dns_dic_conn_id = 0;
1551  request_dns_info(0);
1552 */
1553  return(0);
1554  }
1555  }
1556  else
1557  {
1558  if(!retrying)
1559  service_tmout( servp->serv_id );
1560  if(( servp->type == COMMAND )||( servp->type == ONCE_ONLY ))
1561  return(0);
1562  move_to_bad_service(servp, bad_connp);
1563  return(0);
1564  }
1565  }
1566  strcpy(servp->def, packet->service_def);
1567  get_format_data(format, servp->format_data, servp->def);
1568  servp->format = format;
1569  servp->conn_id = conn_id;
1570 
1571  send_service_command( servp );
1572 /*
1573  if( ret == 1)
1574  {
1575  if(servp->pending != WAITING_CMND_ANSWER)
1576  servp->pending = NOT_PENDING;
1577  servp->tmout_done = 0;
1578  }
1579 */
1580  return(1);
1581 }
int find_connection(char *node, char *task, int port)
Definition: dic.c:2043
static void error_handler(int conn_id, int severity, int errcode, char *reason)
Definition: dic.c:120
int dim_get_keepalive_timeout()
Definition: tcpip.c:128
DIM_NOSHARE DIC_CONNECTION * Dic_conns
Definition: conn_handler.c:30
Definition: dim.h:454
static int Dns_dic_conn_id
Definition: dic.c:46
int dna_write(int conn_id, void *buffer, int size)
Definition: dna.c:455
unsigned service_id
Definition: db_dim_client.c:22
static TIMR_ENT * Dns_dic_timr
Definition: dic.c:47
int release_service(DIC_SERVICE *servicep)
Definition: dic.c:1098
SERVICE_REQ service
Definition: dim.h:302
int dna_open_client(char *server_node, char *server_task, int port, int server_protocol, void(*read_ast)(), void(*error_ast)(), SRC_TYPES src_type)
Definition: dna.c:733
int i
Definition: db_dim_client.c:21
static DIC_BAD_CONNECTION * Bad_connection_head
Definition: dic.c:44
#define COMMAND
Definition: dim_common.h:10
char * service_head
Definition: dim.h:424
void * id_get_ptr(int id, SRC_TYPES type)
Definition: conn_handler.c:184
void dll_insert_queue(DLL *head, DLL *item)
Definition: dll.c:23
int service_id
Definition: dim.h:296
void * malloc()
Definition: EventBuilder.cc:99
char node_addr[4]
Definition: dim.h:312
#define BAD_CONN_TIMEOUT
Definition: dic.c:31
char service_def[MAX_NAME]
Definition: dim.h:309
void dna_set_test_write(int conn_id, int time)
Definition: dna.c:606
char def[MAX_NAME]
Definition: dim.h:463
void dll_init(DLL *head)
Definition: dll.c:14
static void recv_rout(int conn_id, DIS_PACKET *packet, int size, int status)
Definition: dic.c:143
char node_name[MAX_NODE_NAME]
Definition: dim.h:310
void dll_remove(DLL *item)
Definition: dll.c:100
void retry_bad_connection(DIC_BAD_CONNECTION *bad_connp)
Definition: dic.c:1583
int protocol
Definition: dim.h:315
PENDING_STATES pending
Definition: dim.h:476
SRC_TYPES src_type
Definition: dim.h:301
int format
Definition: dim.h:316
int type
Definition: dim.h:465
Definition: dim.h:530
void dtq_start_timer(int time, void(*user_routine)(), dim_long tag)
Definition: dtq.c:790
int n_retries
Definition: dic.c:37
int send_service_command(DIC_SERVICE *servp)
Definition: dic.c:1843
int dtq_clear_entry(TIMR_ENT *entry)
Definition: dtq.c:490
int conn_id
Definition: dim.h:475
Definition: dim.h:457
#define MAX_TASK_NAME
Definition: dim.h:181
long dim_long
Definition: dim_common.h:57
int size
Definition: dim.h:300
void move_to_bad_service(DIC_SERVICE *servp, DIC_BAD_CONNECTION *bad_connp)
Definition: dic.c:1627
static void get_format_data(int format, FORMAT_STR *format_data, char *def)
Definition: dic.c:1668
int port
Definition: dim.h:422
int pid
Definition: dim.h:423
char node_name[MAX_NODE_NAME]
Definition: dim.h:420
int serv_id
Definition: demo_server.c:5
FORMAT_STR format_data[MAX_NAME/4]
Definition: dim.h:462
int serv_id
Definition: dim.h:461
int retrying
Definition: dic.c:38
Definition: dic.c:33
char service_name[MAX_NAME]
Definition: dim.h:295
DIC_CONNECTION conn
Definition: dic.c:36
void free(void *mem)
#define MAX_NODE_NAME
Definition: dim.h:180
char serv_name[MAX_NAME]
Definition: dim.h:460
void service_tmout(int serv_id)
Definition: dic.c:518
void dim_print_date_time()
Definition: utilities.c:134
char task_name[MAX_TASK_NAME]
Definition: dim.h:421
int format
Definition: dim.h:464
int service_id
Definition: dim.h:308
#define ONCE_ONLY
Definition: dim_common.h:7
DIC_BAD_CONNECTION * locate_bad(char *node, char *task, int port)
Definition: dic.c:1226
char task_name[MAX_TASK_NAME-4]
Definition: dim.h:311
int pid
Definition: dim.h:313
#define DIMDNSREFUS
Definition: dim_common.h:283
int port
Definition: dim.h:314
static int Debug_on
Definition: dic.c:59

+ Here is the call graph for this function:

+ Here is the caller graph for this function: