16 # include <cfortran.h> 25 #include <sys/timeb.h> 59 struct serv *service_ptr;
156 int size,
int status ) );
244 strcpy(str,
"Service name too long: ");
248 return((
unsigned) 0);
252 strcpy(str,
"Duplicate Service: ");
256 return((
unsigned) 0);
260 if(type != (
char *)0)
264 strcpy(str,
"Format String Too Long: ");
269 return((
unsigned) 0);
273 strcpy(str,
"Bad Format String: ");
278 return((
unsigned) 0);
280 strcpy(new_serv->
def,type);
285 new_serv->
def[0] =
'\0';
288 new_serv->
address = (
int *)address;
301 new_serv->
dnsp = dnsp;
313 return((
unsigned)service_id);
324 void dis_destroy(
int tid)
326 register SERVICE *servp, *prevp;
332 if(servp->
tid == tid)
374 servp->
tid = taskIdSelf();
395 servp->
tid = taskIdSelf();
417 strcpy(str,
"Command name too long: ");
421 return((
unsigned) 0);
426 return((
unsigned) 0);
430 if(type != (
char *)0)
435 return((
unsigned) 0);
437 strcpy(new_serv->
def,type);
442 new_serv->
def[0] =
'\0';
463 new_serv->
dnsp = dnsp;
473 return((
unsigned) service_id);
535 register char code, last_code = 0;
541 if(code != last_code)
544 format_data->
flags = 0;
606 sscanf(def,
"%d",&num);
608 while((*def !=
';') && (*def !=
'\0'))
615 if(code != last_code)
627 extern int open_dns(
long,
void (*)(),
void (*)(),
int,
int,
int);
666 do_register_services, dnsp );
676 switch( vtohl(packet->
type) )
680 "%s: Watchdog Timeout, DNS requests registration",
687 "%s: Some Services already known to DNS",
704 "%s: DNS refuses connection",dnsp->
task_name);
720 "%s: DNS requests Exit",dnsp->
task_name);
746 strcpy( serv_regp->
service_name,
"DUMMY_UPDATE_PACKET" );
766 register int n_services, tot_n_services;
769 int hash_index, new_entries;
786 dis_dns_p->
pid = htovl(getpid());
789 dis_dns_p->
format = htovl(MY_FORMAT);
817 if(servp->
dnsp == dnsp)
836 if(servp->
dnsp != dnsp)
884 tot_n_services += n_services;
898 register int n_services;
917 dis_dns_p->
format = htovl(MY_FORMAT);
1055 sprintf(str0,
"%s/VERSION_NUMBER", task);
1056 sprintf(str1,
"%s/CLIENT_LIST", task);
1057 sprintf(str2,
"%s/SERVICE_LIST", task);
1058 sprintf(str3,
"%s/SET_EXIT_HANDLER", task);
1059 sprintf(str4,
"%s/EXIT", task);
1065 dnsp->dis_client_id = more_ids[1];
1067 dnsp->dis_service_id = more_ids[2];
1071 strcpy( dnsp->task_name, task );
1105 if(!strcmp(task,
"DIS_DNS"))
1149 register REQUEST *newp, *reqp;
1152 int type, new_client = 0, found = 0;
1177 dic_packet->
type = vtohl(dic_packet->
type);
1178 type = dic_packet->
type & 0xFFF;
1248 newp->
reqpp = reqpp;
1283 int *pkt_buffer, header_size, aux;
1285 struct timeb timebuf;
1288 struct timezone *tz;
1304 sprintf(str,
"This is a COMMAND Service");
1331 if( Dis_packet_size )
1350 aux = timebuf.millitm;
1352 Dis_packet->
time_stamp[1] = htovl((
int)timebuf.time);
1355 gettimeofday(&tv, tz);
1356 aux = tv.tv_usec / 1000;
1358 Dis_packet->
time_stamp[1] = htovl(tv.tv_sec);
1367 Dis_packet->
reserved[0] = htovl(0xc0dec0de);
1372 pkt_buffer = ((
DIS_PACKET *)Dis_packet)->buffer;
1375 memcpy(format_data_cp, servp->
format_data,
sizeof(format_data_cp));
1379 Dis_packet->
size = htovl(header_size + size);
1403 static int packet_size = 0;
1408 if( !packet_size ) {
1412 service_id = (reqp->
service_id | 0x80000000);
1427 static int buffer_size = 0;
1431 add_size = size + (size/2);
1434 buffer = (
int *)
malloc(add_size);
1435 buffer_size = add_size;
1439 if( add_size > buffer_size )
1442 buffer = (
int *)
malloc(add_size);
1443 buffer_size = add_size;
1450 format = vtohl(packet->
format);
1451 memcpy(format_data_cp, servp->
format_data,
sizeof(format_data_cp));
1452 if((format & 0xF) == ((MY_FORMAT) & 0xF))
1454 for(formatp = format_data_cp; formatp->
par_bytes; formatp++)
1457 formatp->
flags |= (format & 0xf0);
1458 formatp->
flags &= 0xFFF0;
1463 for(formatp = format_data_cp; formatp->
par_bytes; formatp++)
1466 formatp->
flags |= (format & 0xf0);
1480 int to_delete = 0, more;
1485 reqp = servp->request_head;
1501 reqp = servp->request_head;
1537 if(reqp->
conn_id == *client_ids)
1552 register int found = 0;
1553 int to_delete = 0, more, conn_id;
1560 sprintf(str,
"Update Service - Invalid service id");
1584 printf(
"Updating %s (id = %d, ptr = %08lX) for %s@%s (req_id = %d, req_ptr = %08lX)\n",
1585 servp->
name, (
int)service_id, (
unsigned long)servp,
1598 if(reqp->delay_delete && ((reqp->type & 0xFFF) !=
COMMAND))
1655 reqpp = reqp->
reqpp;
1689 register int found = 0;
1695 sprintf(str,
"Service Has Clients- Invalid service id");
1729 sprintf(str,
"Get Timeout - Invalid service id");
1742 if(reqp->
conn_id == client_id)
1756 sprintf(str,
"Set Quality - Invalid service id");
1781 struct timeb timebuf;
1784 struct timezone *tz;
1790 sprintf(str,
"Set Timestamp - Invalid service id");
1814 gettimeofday(&tv, tz);
1839 sprintf(str,
"Get Timestamp - Invalid service id");
1871 register REQUEST *reqp, *prevp;
1874 static int packet_size = 0;
1880 sprintf(str,
"Send Service - Invalid service id");
1905 memcpy(dis_packet->
buffer, buffer, size);
1921 register REQUEST *reqp, *auxp;
1935 sprintf(str,
"Remove Service - Invalid service id");
1969 release_request(reqp, reqpp, 1);
1977 dis_hash_service_remove(servp);
2012 register SERVICE *servp, *prevp;
2015 int hash_index, old_index;
2050 if(servp->
dnsp == dnsp)
2053 if(old_index != hash_index)
2059 old_index = hash_index;
2093 register SERVICE *servp, *prevp;
2174 release_request(reqp, reqpp, 0);
2238 static int curr_allocated_size = 0;
2239 static char *service_info_buffer;
2262 if(!curr_allocated_size)
2264 service_info_buffer = (
char *)
malloc(max_size);
2265 curr_allocated_size = max_size;
2267 else if (max_size > curr_allocated_size)
2269 free(service_info_buffer);
2270 service_info_buffer = (
char *)
malloc(max_size);
2271 curr_allocated_size = max_size;
2273 service_info_buffer[0] =
'\0';
2274 buff_ptr = service_info_buffer;
2281 strcat(buff_ptr, servp->
name);
2282 strcat(buff_ptr,
"\n");
2283 buff_ptr += strlen(buff_ptr);
2299 return(service_info_buffer);
2313 reqpp = clip->requestp_head;
2376 static int releasing = 0;
2393 printf(
" Couldn't write to client %s@%s, releasing connection %d\n",
2394 task,
node, conn_id);
2417 typedef struct cmnds{
2440 memcpy(new_cmnd->
buffer, cmnd_buff, *size);
2447 register int ret_val = -1;
2461 *size = cmndp->
size;
2470 if (*size >= cmndp->
size)
2472 *size = cmndp->
size;
2475 memcpy(buffer, cmndp->
buffer, *size);
2512 struct dsc$descriptor_s *for_str;
2516 strcpy(for_str->dsc$a_pointer, c_str);
2517 for(i = strlen(c_str); i< for_str->dsc$w_length; i++)
2518 for_str->dsc$a_pointer[i] =
' ';
2526 int i, index, max_size;
2527 static int curr_allocated_size = 0;
2528 static char *dns_info_buffer;
2529 register char *dns_client_info;
2534 if(!curr_allocated_size)
2536 dns_info_buffer =
malloc(max_size);
2537 curr_allocated_size = max_size;
2539 dns_client_info = dns_info_buffer;
2540 dns_client_info[0] =
'\0';
2548 if(clip->
dnsp != dnsp)
2550 curr_conns[index++] = clip->
conn_id;
2553 if (max_size > curr_allocated_size)
2555 free(dns_info_buffer);
2556 dns_info_buffer =
malloc(max_size);
2557 curr_allocated_size = max_size;
2559 dns_client_info = dns_info_buffer;
2560 dns_client_info[0] =
'\0';
2566 strcat(dns_client_info,
"+");
2571 strcat(dns_client_info,
"-");
2576 for(i=0; i<index;i++)
2579 strcat(dns_client_info,task);
2580 strcat(dns_client_info,
"@");
2581 strcat(dns_client_info,node);
2582 strcat(dns_client_info,
"|");
2585 dns_client_info[strlen(dns_client_info)-1] =
'\0';
2586 *bufp = (
int *)dns_info_buffer;
2587 *size = strlen(dns_info_buffer)+1;
2594 if(strstr(servp->
name,
"/RpcIn"))
2596 strcpy(name,servp->
name);
2597 ptr = (
char *)strstr(name,
"/RpcIn");
2599 strcat(service_info_buffer, name);
2600 strcat(service_info_buffer,
"|");
2603 strcat(service_info_buffer, servp->
def);
2605 strcat(name,
"/RpcOut");
2608 strcat(service_info_buffer,
",");
2611 strcat(service_info_buffer, servp->
def);
2614 strcat(service_info_buffer,
"|RPC");
2615 strcat(service_info_buffer,
"\n");
2617 else if(strstr(servp->
name,
"/RpcOut"))
2631 strcat(service_info_buffer, servp->
name);
2632 strcat(service_info_buffer,
"|");
2635 strcat(service_info_buffer, servp->
def);
2637 strcat(service_info_buffer,
"|");
2640 strcat(service_info_buffer,
"CMD");
2642 strcat(service_info_buffer,
"\n");
2649 int max_size, done = 0;
2650 static int curr_allocated_size = 0;
2651 static char *service_info_buffer;
2658 if(!curr_allocated_size)
2660 service_info_buffer = (
char *)
malloc(max_size);
2661 curr_allocated_size = max_size;
2663 else if (max_size > curr_allocated_size)
2665 free(service_info_buffer);
2666 service_info_buffer = (
char *)
malloc(max_size);
2667 curr_allocated_size = max_size;
2669 service_info_buffer[0] =
'\0';
2670 buff_ptr = service_info_buffer;
2677 if(servp->
dnsp != dnsp)
2683 buff_ptr += strlen(buff_ptr);
2691 if(servp->
dnsp != dnsp)
2697 strcat(buff_ptr,
"+");
2698 buff_ptr += strlen(buff_ptr);
2702 buff_ptr += strlen(buff_ptr);
2707 strcat(buff_ptr,
"-");
2708 buff_ptr += strlen(buff_ptr);
2710 buff_ptr += strlen(buff_ptr);
2714 *bufp = (
int *)service_info_buffer;
2715 *size = buff_ptr - service_info_buffer+1;
2762 (
char *)&conn_id, 4)) )
2783 (
char *)&conn_id, 4)) )
2802 0, (
char *) &conn_id, 4)) )
2829 int exit_tag, exit_code, exit_size;
2848 exit_code = errcode;
2849 exit_size =
sizeof(int);
2856 #define MAX_HASH_ENTRIES 5000 2864 static int done = 0;
2872 Service_new_entries[
i] = 0;
2883 Service_new_entries[index]++;
2892 Service_new_entries[index]--;
2893 if(Service_new_entries[index] < 0)
2894 Service_new_entries[index] = 0;
2912 (
DLL *) Service_hash_table[index],
2913 name, strlen(name)+1)) )
2930 index = *curr_index;
2934 prevp = Service_hash_table[index];
2938 prevp = Service_hash_table[index];
2942 if((!new_entries) || (Service_new_entries[index] > 0))
2945 (
DLL *) Service_hash_table[index],
2956 prevp = Service_hash_table[index];
2958 *curr_index = index;
3011 int n_entries, max_entry_index = 0;
3012 int max_entries = 0;
3017 servp = Service_hash_table[
i];
3019 (
DLL *) Service_hash_table[i],
3024 printf(
" Name = %s\n",servp->
name);
3027 printf(
"HASH[%d] - %d entries\n", i, n_entries);
3028 if(n_entries > max_entries)
3030 max_entries = n_entries;
3031 max_entry_index =
i;
3034 printf(
"Maximum : HASH[%d] - %d entries\n", max_entry_index, max_entries);
3047 printf(
"Name = %s\n",servp->
name);
3060 STRING, PVOID, PVOID, INT, PVOID, INT)
3062 STRING, PVOID, PVOID, INT)
int close_dns(dim_long dnsid, SRC_TYPES src_type)
int execute_service(int req_id)
static int Dis_packet_size
#define MAX_REGISTRATION_UNIT
struct reqp_ent REQUEST_PTR
int dtq_delete(int queue_id)
SLL * sll_get_head(SLL *head)
static DIS_STAMPED_PACKET * Dis_packet
int dna_write(int conn_id, void *buffer, int size)
static unsigned do_dis_add_service(char *name, char *type, void *address, int size, void(*user_routine)(), long tag)
int dis_get_client(char *name)
void add_exit_handler(int *tag, int *bufp, int *size)
void register_services(DIS_DNS_CONN *dnsp, int flag, int dns_flag)
void dis_add_error_handler(void(*user_routine)())
int copy_swap_buffer_in(FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
void dis_set_quality(unsigned serv_id, int quality)
static int get_format_data(FORMAT_STR *format_data, char *def)
int dis_set_buffer_size(int size)
SERVICE * dis_hash_service_exists(char *name)
char service_name[MAX_NAME]
void dis_print_hash_table()
SERVICE * dis_hash_service_get_next(int *curr_index, SERVICE *prevp, int new_entries)
int send_dns_update_packet(DIS_DNS_CONN *dnsp)
int dis_hash_service_insert(SERVICE *servp)
unsigned dis_add_service_dns(long dnsid, char *name, char *type, void *address, int size, void(*user_routine)(), long tag)
static void exit_handler(int *tag, int *bufp, int *size)
void release_all_requests(int conn_id, CLIENT *clip)
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
static int Service_new_entries[MAX_HASH_ENTRIES]
void dis_send_service(unsigned service_id, int *buffer, int size)
void recv_dns_dis_rout(int conn_id, DNS_DIS_PACKET *packet, int size, int status)
void * id_get_ptr(int id, SRC_TYPES type)
void dll_insert_queue(DLL *head, DLL *item)
DIS_DNS_CONN * dis_find_dns(long dnsid)
int find_release_request(int conn_id, int service_id)
void client_info(long *tag, int **bufp, int *size, int *first_time)
struct dis_dns_ent * prev
unsigned dis_add_cmnd_dns(long dnsid, char *name, char *type, void(*user_routine)(), long tag)
int dis_set_timestamp(unsigned serv_id, int secs, int millisecs)
int rand_tmout(int min, int max)
int dna_close(int conn_id)
static CLIENT * Client_head
unsigned dis_add_service(char *name, char *type, void *address, int size, void(*user_routine)(), long tag)
int release_request(REQUEST *reqp, REQUEST_PTR *reqpp, int remove)
static void dis_insert_request(int conn_id, DIC_PACKET *dic_packet, int size, int status)
int do_exit_handler(int conn_id)
int copy_swap_buffer_out(int format, FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
int dis_start_serving(char *task)
#define DIS_STAMPED_HEADER
void dis_set_client_exit_handler(int conn_id, int tag)
#define DIS_DNS_TMOUT_MAX
char task_name[MAX_TASK_NAME-4]
int dis_hash_service_init()
DIS_DNS_CONN * Default_DNS
static unsigned do_dis_add_cmnd(char *name, char *type, void(*user_routine)(), long tag)
int dis_selective_update_service(unsigned service_id, int *client_ids)
int dis_hash_service_registered(int index, SERVICE *servp)
void do_update_service_list(DIS_DNS_CONN *dnsp)
int dis_get_timestamp(unsigned serv_id, int *secs, int *millisecs)
int get_node_addr(char *node_addr)
int updating_service_list
#define DIS_DNS_TMOUT_MIN
void dis_report_service(char *serv_name)
char service_name[MAX_NAME]
void dll_remove(DLL *item)
static void(* Error_user_routine)()=0
void std_cmnd_handler(long *tag, int *cmnd_buff, int *size)
static int Dis_first_time
static SERVICE * Service_hash_table[MAX_HASH_ENTRIES]
void dis_add_client_exit_handler(void(*user_routine)())
char node_name[MAX_NODE_NAME]
static int Version_number
FORMAT_STR format_data[MAX_NAME/4]
void append_service(char *service_info_buffer, SERVICE *servp)
unsigned dis_add_cmnd(char *name, char *type, void(*user_routine)(), long tag)
int open_dns(dim_long dnsid, void(*recv_rout)(), void(*error_rout)(), int tmout_min, int tmout_max, SRC_TYPES src_type)
char * dis_get_error_services()
void dis_add_exit_handler(void(*user_routine)())
static unsigned do_dis_add_cmnd_dns(char *name, char *type, void(*user_routine)(), long tag, long dnsid)
static DIS_CMND * Cmnds_head
void dtq_start_timer(int time, void(*user_routine)(), dim_long tag)
SLL * sll_remove_head(SLL *head)
_DIM_PROTO(static void dis_insert_request,(int conn_id, DIC_PACKET *dic_packet, int size, int status))
int dis_start_serving_dns(long dnsid, char *task)
#define WATCHDOG_TMOUT_MIN
int sll_insert_queue(SLL *head, SLL *item)
void service_info(long *tag, int **bufp, int *size, int *first_time)
int dtq_rem_entry(int queue_id, TIMR_ENT *entry)
char service_def[MAX_NAME]
int dis_get_next_cmnd(long *tag, int *buffer, int *size)
void do_dis_stop_serving_dns(DIS_DNS_CONN *dnsp)
int dis_update_service(unsigned service_id)
int dis_get_timeout(unsigned service_id, int client_id)
void do_register_services(DIS_DNS_CONN *dnsp)
SLL * sll_search_next_remove(SLL *item, int offset, char *data, int size)
void unregister_service(DIS_DNS_CONN *dnsp, SERVICE *servp)
dim_long dns_get_dnsid(int conn_id, SRC_TYPES src_type)
REQUEST_PTR * requestp_head
int dna_get_node_task(int conn_id, char *node, char *task)
struct dis_dns_ent DIS_DNS_CONN
int sll_remove(SLL *head, SLL *item)
#define WATCHDOG_TMOUT_MAX
int dis_remove_service(unsigned service_id)
int dna_write_nowait(int conn_id, void *buffer, int size)
CLIENT * find_client(int conn_id)
int dis_hash_service_remove(SERVICE *servp)
struct serv * service_ptr
void execute_command(SERVICE *servp, DIC_PACKET *packet)
SERVICE * find_service(char *name)
Removed all warnings from DIM sources so that it can be compiled with Wall Wextra on Linux Changed the makefiles so that the default on Linux is now bits The flag
int dna_open_server(char *task, void(*read_ast)(), int *protocol, int *port, void(*error_ast)())
void id_free(int id, SRC_TYPES type)
static void error_handler(int conn_id, int severity, int errcode, char *reason)
TIMR_ENT * dtq_add_entry(int queue_id, int time, void(*user_routine)(), dim_long tag)
static int check_service_name(char *name)
DLL * dll_get_next(DLL *head, DLL *item)
int dis_get_n_clients(unsigned service_id)
int id_get(void *ptr, SRC_TYPES type)
void dim_print_date_time()
struct dis_dns_ent * next
void dim_print_msg(char *msg, int severity)
unsigned int dis_service_id
int HashFunction(char *name, int max)
#define DIM_VERSION_NUMBER
static void(* Exit_user_routine)()=0
static int release_conn(int conn_id, int print_flg, int dns_flag)
static void(* Client_exit_user_routine)()=0
int do_update_service(unsigned service_id, int *client_ids)
SERVICE_REG services[MAX_SERVICE_UNIT]
void remove_service(int req_id)
unsigned int dis_client_id
static unsigned do_dis_add_service_dns(char *name, char *type, void *address, int size, void(*user_routine)(), long tag, long dnsid)
int get_node_name(char *node_name)
int check_client(REQUEST *reqp, int *client_ids)
DIS_DNS_PACKET dis_dns_packet
sprintf(name1,"NewService%d", i)
static DIS_DNS_CONN * create_dns(long dnsid)
SLL * sll_search(SLL *head, char *data, int size)
char * dis_get_client_services(int conn_id)
static void user_routine(void *tagp, void *bufp, int *size)
DLL * dll_search(DLL *head, char *data, int size)
static EXIT_H * Exit_h_head
static DIS_DNS_CONN * DNS_head
DIS_DNS_CONN * find_dns_by_conn_id(int conn_id)
void dis_stop_serving_dns(long dnsid)
CLIENT * check_delay_delete(int conn_id)
void dim_print_date_time_millis()