FACT++  1.0
int handle_client_request ( int  conn_id,
DIC_DNS_PACKET packet 
)

Definition at line 660 of file dns.c.

References node::conn_id, red_node::conn_id, serv::conn_id, Curr_n_services, Debug, dim_get_keepalive_timeout(), dim_print_date_time(), dll_empty(), dll_get_next(), dll_init(), dll_insert_queue(), dll_remove(), dna_set_test_write(), dna_test_write(), dna_write_nowait(), DNS_accepted_nodes, Dns_conns, DNS_DIC_HEADER, DNS_DIC_PACKET::format, Memory::free(), get_dns_accepted_nodes(), i, Memory::malloc(), MAX_NAME, MY_OS9, Net_conns, node::next, serv::next, DNS_DIC_PACKET::node_addr, DNS_CONNECTION::node_addr, serv::node_head, red_serv::node_head, DNS_CONNECTION::node_head, DNS_DIC_PACKET::node_name, DNS_CONNECTION::node_name, DNS_DIC_PACKET::pid, DNS_CONNECTION::pid, DNS_DIC_PACKET::port, DNS_CONNECTION::port, red_node::prev, DNS_DIC_PACKET::protocol, DNS_CONNECTION::protocol, release_conn(), serv::serv_def, serv::serv_name, serv::server_format, DIC_DNS_PACKET::service, DNS_DIC_PACKET::service_def, service_exists(), node::service_id, red_node::service_id, SERVICE_REG::service_id, DNS_DIC_PACKET::service_id, service_insert(), SERVICE_REG::service_name, service_remove(), node::servp, DNS_DIC_PACKET::size, SRC_DIC, SRC_NONE, DNS_CONNECTION::src_type, serv::state, DNS_DIC_PACKET::task_name, and DNS_CONNECTION::task_name.

Referenced by recv_rout().

661 {
662  DNS_SERVICE *servp;
663  NODE *nodep;
664  RED_NODE *red_nodep;
665  int i, service_id;
666  DNS_DIC_PACKET dic_packet;
667  SERVICE_REG *serv_regp;
668  void service_insert();
669  void service_remove();
670  void tcpip_get_addresses();
671  char *ptr, *ptr1;
672  int found;
673 
674  serv_regp = (SERVICE_REG *)(&(packet->service));
675  if(Debug)
676  {
678  printf(" Conn %3d : Client %s@%s requested %s\n",
679  conn_id, Net_conns[conn_id].task, Net_conns[conn_id].node,
680  serv_regp->service_name);
681  fflush(stdout);
682  }
683 
684  if(DNS_accepted_nodes[0] == 0)
685  {
687  DNS_accepted_nodes[0] = (char)0xFF;
688  }
689  if(DNS_accepted_nodes[0] != (char)0xFF)
690  {
691  ptr = DNS_accepted_nodes;
692  found = 0;
693  while(*ptr)
694  {
695  ptr1 = strchr(ptr,',');
696  if(ptr1)
697  {
698  *ptr1 = '\0';
699  ptr1++;
700  }
701  else
702  {
703  ptr1 = ptr;
704  ptr1 += (int)strlen(ptr);
705  }
706  if(strstr(Net_conns[conn_id].node,ptr))
707  {
708  found = 1;
709  break;
710  }
711  ptr = ptr1;
712  }
713  if(!found)
714  {
715  dic_packet.service_id = serv_regp->service_id;
716  dic_packet.node_name[0] = (char)0xFF;
717  dic_packet.task_name[0] = 0;
718  dic_packet.node_addr[0] = 0;
719  dic_packet.pid = 0;
720  dic_packet.size = htovl(DNS_DIC_HEADER);
722  printf(" Connection from %s refused, stopping client pid=%s\n",
723  Net_conns[conn_id].node,
724  Net_conns[conn_id].task);
725  fflush(stdout);
726  if( !dna_write_nowait(conn_id, &dic_packet, DNS_DIC_HEADER) )
727  {
729  printf(" Stop Client: Couldn't write, releasing Conn %3d : Client %s@%s\n",conn_id,
730  Net_conns[conn_id].task,
731  Net_conns[conn_id].node);
732  fflush(stdout);
733  }
734  release_conn(conn_id);
735 
736  return 0;
737  }
738  }
739 
740  service_id = vtohl(serv_regp->service_id);
741  if( service_id == -1 ) /* remove service */
742  {
743  if(Debug)
744  {
745  printf("\tRemoving Request\n");
746  fflush(stdout);
747  }
748  if( (servp = service_exists(serv_regp->service_name)) )
749  {
750  red_nodep = servp->node_head;
751  while( (red_nodep =
753  (DLL *) servp->node_head,
754  (DLL *) red_nodep)) )
755  {
756  if( red_nodep->conn_id == conn_id )
757  {
758  dll_remove((DLL *) red_nodep);
759  ptr = (char *)red_nodep - (2 * sizeof(void *));
760  nodep = (NODE *)ptr;
761  dll_remove((DLL *) nodep);
762  red_nodep = red_nodep->prev;
763  free(nodep);
764  break;
765  }
766  }
767  if(( dll_empty((DLL *) servp->node_head) ) && (servp->state == 0))
768  {
769  if(Debug)
770  {
771  printf("\tand Removing Service\n");
772  fflush(stdout);
773  }
774  service_remove(&(servp->next));
775  Curr_n_services--;
776  free(servp);
777  }
778  }
779  return(0);
780  }
781  if( (unsigned)service_id & 0x80000000 ) /* remove service */
782  {
783  service_id &= 0x7fffffff;
784  if(Debug)
785  {
786  printf("\tRemoving Request\n");
787  fflush(stdout);
788  }
789  if( (servp = service_exists(serv_regp->service_name)) )
790  {
791  red_nodep = servp->node_head;
792  while( (red_nodep =
794  (DLL *) servp->node_head,
795  (DLL *) red_nodep)) )
796  {
797  if(( red_nodep->conn_id == conn_id ) &&
798  ( red_nodep->service_id == service_id ) )
799  {
800  dll_remove((DLL *) red_nodep);
801  ptr = (char *)red_nodep - (2 * sizeof(void *));
802  nodep = (NODE *)ptr;
803  dll_remove((DLL *) nodep);
804  red_nodep = red_nodep->prev;
805  free(nodep);
806  break;
807  }
808  }
809  if(( dll_empty((DLL *) servp->node_head) ) && (servp->state == 0))
810  {
811  if(Debug)
812  {
813  printf("\tand Removing Service\n");
814  fflush(stdout);
815  }
816  service_remove(&(servp->next));
817  Curr_n_services--;
818  free(servp);
819  }
820  }
821  return(0);
822  }
823  /* Is already in v.format */
824  dic_packet.service_id = serv_regp->service_id;
825  dic_packet.node_name[0] = 0;
826  dic_packet.task_name[0] = 0;
827  dic_packet.node_addr[0] = 0;
828  dic_packet.pid = 0;
829  dic_packet.size = htovl(DNS_DIC_HEADER);
830  if( Dns_conns[conn_id].src_type == SRC_NONE )
832  if( !(servp = service_exists(serv_regp->service_name)) )
833  {
834  if(Debug)
835  {
836  printf("\tService does not exist, queueing request\n");
837  fflush(stdout);
838  }
839  if( !Dns_conns[conn_id].node_head )
840  {
841  Dns_conns[conn_id].src_type = SRC_DIC;
842  Dns_conns[conn_id].node_head =
843  malloc(sizeof(NODE));
844  dll_init( (DLL *) Dns_conns[conn_id].node_head );
845  }
846  servp = (DNS_SERVICE *) malloc(sizeof(DNS_SERVICE));
847  strncpy( servp->serv_name, serv_regp->service_name, (size_t)MAX_NAME );
848  servp->serv_def[0] = '\0';
849  servp->state = 0;
850  servp->conn_id = 0;
851  service_insert(&(servp->next));
852  Curr_n_services++;
853  servp->node_head = (RED_NODE *)malloc(sizeof(NODE));
854  dll_init( (DLL *) servp->node_head );
855  nodep = (NODE *)malloc(sizeof(NODE));
856  nodep->conn_id = conn_id;
857  nodep->service_id = service_id;
858  nodep->servp = servp;
859  dll_insert_queue((DLL *) Dns_conns[conn_id].node_head,
860  (DLL *) nodep);
861  dll_insert_queue((DLL *) servp->node_head,
862  (DLL *) &(nodep->next));
863  }
864  else
865  {
866  if( servp->state == 1 )
867  {
868 #ifdef VMS
869  if(servp->server_format & MY_OS9)
870  {
871  dna_test_write(servp->conn_id);
872  }
873 #endif
874  Dns_conns[conn_id].src_type = SRC_DIC;
875  strcpy( dic_packet.node_name,
876  Dns_conns[servp->conn_id].node_name );
877  strcpy( dic_packet.task_name,
878  Dns_conns[servp->conn_id].task_name );
879  for(i = 0; i < 4; i++)
880  dic_packet.node_addr[i] =
881  Dns_conns[servp->conn_id].node_addr[i];
882  dic_packet.port = htovl(Dns_conns[servp->conn_id].port);
883  dic_packet.pid = htovl(Dns_conns[servp->conn_id].pid);
884  dic_packet.protocol = htovl(Dns_conns[servp->conn_id].protocol);
885  dic_packet.format = htovl(servp->server_format);
886  strcpy( dic_packet.service_def, servp->serv_def );
887  if(Debug)
888  {
889  printf("\tService exists in %s@%s, port = %d\n",
890  dic_packet.task_name, dic_packet.node_name,
891  dic_packet.port);
892  fflush(stdout);
893  }
894  }
895  else
896  {
897  if(Debug)
898  {
899  if(servp->state == -1)
900  {
901  printf("\tService exists in BAD state, queueing request\n");
902  fflush(stdout);
903  }
904  else
905  {
906  printf("\tService does not exist (other client(s) waiting), queueing request\n");
907  fflush(stdout);
908  }
909  }
910  if(!(NODE *)Dns_conns[conn_id].node_head )
911  {
912  Dns_conns[conn_id].src_type = SRC_DIC;
913  Dns_conns[conn_id].node_head =
914  (char *) malloc(sizeof(NODE));
915  dll_init((DLL *)Dns_conns[conn_id].node_head);
916  }
917  nodep = (NODE *)malloc(sizeof(NODE));
918  nodep->conn_id = conn_id;
919  nodep->service_id = service_id;
920  nodep->servp = servp;
921  dll_insert_queue((DLL *) Dns_conns[conn_id].node_head,
922  (DLL *) nodep);
923  dll_insert_queue((DLL *) servp->node_head,
924  (DLL *) &(nodep->next));
925  }
926  }
927 /* Should it be dna_write_nowait? 16/9/2008 */
928 /* moved from dna_write to dna_write_nowait in 14/10/2008 */
929  if( !dna_write_nowait(conn_id, &dic_packet, DNS_DIC_HEADER) )
930  {
932  printf(" Client Request: Couldn't write, releasing Conn %3d : Client %s@%s\n",conn_id,
933  Net_conns[conn_id].task,
934  Net_conns[conn_id].node);
935  fflush(stdout);
936  release_conn(conn_id);
937  }
938 
939  return(1);
940 }
char node_name[MAX_NODE_NAME]
Definition: dim.h:431
#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 dna_test_write(int conn_id)
Definition: dna.c:335
char node_addr[4]
Definition: dim.h:433
unsigned service_id
Definition: db_dim_client.c:22
struct red_node * prev
Definition: dns.c:38
SERVICE_REQ service
Definition: dim.h:302
DllExp DIM_NOSHARE DNS_CONNECTION * Dns_conns
Definition: conn_handler.c:29
int i
Definition: db_dim_client.c:21
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
Definition: conn_handler.c:32
void dll_insert_queue(DLL *head, DLL *item)
Definition: dll.c:23
char serv_name[MAX_NAME]
Definition: dns.c:49
struct serv * servp
Definition: dns.c:33
static char DNS_accepted_nodes[1024]
Definition: dns.c:89
void * malloc()
Definition: EventBuilder.cc:99
char node_addr[4]
Definition: dim.h:312
char service_def[MAX_NAME]
Definition: dim.h:309
void dna_set_test_write(int conn_id, int time)
Definition: dna.c:606
void dll_init(DLL *head)
Definition: dll.c:14
int service_id
Definition: dim.h:265
int service_id
Definition: dns.c:32
char node_name[MAX_NODE_NAME]
Definition: dim.h:310
int conn_id
Definition: dns.c:31
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 protocol
Definition: dim.h:315
void service_remove(RED_DNS_SERVICE *servp)
Definition: dns.c:1641
#define DNS_DIC_HEADER
Definition: dim.h:319
int format
Definition: dim.h:316
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 get_dns_accepted_nodes(char *nodes)
Definition: utilities.c:275
int state
Definition: dns.c:51
void service_insert(RED_DNS_SERVICE *servp)
Definition: dns.c:1631
struct serv * next
Definition: dis.c:70
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 dll_empty(DLL *head)
Definition: dll.c:88
int port
Definition: dim.h:435
void free(void *mem)
struct node * next
Definition: dns.c:29
DLL * dll_get_next(DLL *head, DLL *item)
Definition: dll.c:66
void dim_print_date_time()
Definition: utilities.c:134
static int Debug
Definition: dns.c:78
int service_id
Definition: dns.c:40
SRC_TYPES src_type
Definition: dim.h:430
char * node_head
Definition: dim.h:437
int service_id
Definition: dim.h:308
char task_name[MAX_TASK_NAME-4]
Definition: dim.h:311
static int Curr_n_services
Definition: dns.c:72
#define MY_OS9
Definition: dim.h:26
int pid
Definition: dim.h:313
int conn_id
Definition: dns.c:39
int port
Definition: dim.h:314
int size
Definition: dim.h:307
Definition: dns.c:36

+ Here is the call graph for this function:

+ Here is the caller graph for this function: