16 # include <cfortran.h> 25 #include <sys/timeb.h> 160 int size,
int status ) );
215 if((
int)strlen(name) > (
MAX_NAME - 1))
250 return((
unsigned) 0);
254 strcpy(str,
"Service name too long: ");
258 return((
unsigned) 0);
262 strcpy(str,
"Duplicate Service: ");
266 return((
unsigned) 0);
270 if(type != (
char *)0)
272 if ((
int)strlen(type) >= MAX_NAME)
274 strcpy(str,
"Format String Too Long: ");
279 return((
unsigned) 0);
283 strcpy(str,
"Bad Format String: ");
288 return((
unsigned) 0);
290 strcpy(new_serv->
def,type);
295 new_serv->
def[0] =
'\0';
298 new_serv->
address = (
int *)address;
311 new_serv->
dnsp = dnsp;
323 return((
unsigned)service_id);
334 void dis_destroy(
int tid)
336 register SERVICE *servp, *prevp;
342 if(servp->
tid == tid)
384 servp->
tid = taskIdSelf();
405 servp->
tid = taskIdSelf();
428 return((
unsigned) 0);
432 strcpy(str,
"Command name too long: ");
436 return((
unsigned) 0);
441 return((
unsigned) 0);
445 if(type != (
char *)0)
450 return((
unsigned) 0);
452 strcpy(new_serv->
def,type);
457 new_serv->
def[0] =
'\0';
478 new_serv->
dnsp = dnsp;
488 return((
unsigned) service_id);
550 register char code, last_code = 0;
556 if(code != last_code)
559 format_data->
flags = 0;
625 sscanf(def,
"%d",&num);
627 while((*def !=
';') && (*def !=
'\0'))
634 if(code != last_code)
688 do_register_services, dnsp );
698 type = vtohl(packet->
type);
699 exit_code = (type >> 16) & 0xFFFF;
705 "%s: Watchdog Timeout, DNS requests registration",
712 "%s: Some Services already known to DNS",
732 "%s: DNS refuses connection",dnsp->
task_name);
751 "%s: DNS requests Exit",dnsp->
task_name);
759 "%s: DNS requests Exit(%d)",dnsp->
task_name, exit_code);
788 strcpy( serv_regp->
service_name,
"DUMMY_UPDATE_PACKET" );
794 printf(
"Sending UpdatePacket to dns %d as %s@%s, %d services\n",
815 register int n_services, tot_n_services;
818 int hash_index, new_entries;
835 dis_dns_p->
pid = htovl(getpid());
838 dis_dns_p->
format = htovl(MY_FORMAT);
842 printf(
"Registering as %d %s@%s\n",
861 printf(
"Sending NONE to dns %d as %s@%s, %d services\n",
879 if(servp->
dnsp == dnsp)
898 if(servp->
dnsp != dnsp)
904 printf(
"Registering %s\n",
927 printf(
"Sending MAX_SERVICE_UNIT to dns %d as %s@%s, %d services\n",
955 printf(
"Sending to dns %d as %s@%s, %d services\n",
966 tot_n_services += n_services;
980 register int n_services;
999 dis_dns_p->
format = htovl(MY_FORMAT);
1004 serv_regp->
service_id = (int)htovl( (
unsigned)servp->
id | 0x80000000);
1015 printf(
"Sending UNREGISTER to dns %d as %s@%s, %d services\n",
1068 static int done = 0;
1136 task_name_aux[MAX_TASK_NAME-1] =
'\0';
1141 printf(
"Opening Server Connection %s\n",task_name_aux);
1155 sprintf(str0,
"%s/VERSION_NUMBER", task);
1156 sprintf(str1,
"%s/CLIENT_LIST", task);
1157 sprintf(str2,
"%s/SERVICE_LIST", task);
1158 sprintf(str3,
"%s/SET_EXIT_HANDLER", task);
1159 sprintf(str4,
"%s/EXIT", task);
1165 dnsp->dis_client_id = more_ids[1];
1167 dnsp->dis_service_id = more_ids[2];
1171 strcpy( dnsp->task_name, task );
1175 printf(
"start serving %s\n",task);
1210 if(!strcmp(task,
"DIS_DNS"))
1254 register REQUEST *newp, *reqp;
1257 int type, new_client = 0, found = 0;
1275 printf(
"Received Disconnection %d, from %s@%s\n",
1286 printf(
"Received Connection %d, from %s@%s\n",
1297 printf(
"Received Request for %s, from %d %s@%s\n",
1301 dic_packet->
type = vtohl(dic_packet->
type);
1302 type = dic_packet->
type & 0xFFF;
1370 newp->
reqpp = reqpp;
1404 int *pkt_buffer, header_size, aux;
1406 struct timeb timebuf;
1409 struct timezone *tz;
1425 printf(
"Updating %s for %s@%s (req_id = %d)\n",
1435 sprintf(str,
"This is a COMMAND Service");
1465 if( Dis_packet_size )
1484 aux = timebuf.millitm;
1486 Dis_packet->
time_stamp[1] = htovl((
int)timebuf.time);
1489 gettimeofday(&tv, tz);
1490 aux = (int)tv.tv_usec / 1000;
1492 Dis_packet->
time_stamp[1] = htovl((
int)tv.tv_sec);
1501 Dis_packet->
reserved[0] = (int)htovl(0xc0dec0de);
1506 pkt_buffer = ((
DIS_PACKET *)Dis_packet)->buffer;
1509 memcpy(format_data_cp, servp->
format_data,
sizeof(format_data_cp));
1513 Dis_packet->
size = htovl(header_size + size);
1521 printf(
" Server (Explicitly) Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",
1522 servp->
name, conn_id,
1527 printf(
" Server Updating Service %s: Couldn't write to Conn %3d : Client %s@%s\n",
1528 servp->
name, conn_id,
1562 static int packet_size = 0;
1568 if( !packet_size ) {
1572 service_id = (int)((
unsigned)reqp->
service_id | 0x80000000);
1582 printf(
" Server Removing Service: Couldn't write to Conn %3d : Client %s@%s\n",
1595 static int buffer_size = 0;
1599 add_size = size + (size/2);
1602 buffer = (
int *)
malloc((
size_t)add_size);
1603 buffer_size = add_size;
1607 if( add_size > buffer_size )
1610 buffer = (
int *)
malloc((
size_t)add_size);
1611 buffer_size = add_size;
1618 format = vtohl(packet->
format);
1619 memcpy(format_data_cp, servp->
format_data,
sizeof(format_data_cp));
1620 if((format & 0xF) == ((MY_FORMAT) & 0xF))
1622 for(formatp = format_data_cp; formatp->
par_bytes; formatp++)
1625 formatp->
flags |= ((short)format & (
short)0xf0);
1626 formatp->
flags &= (short)0xFFF0;
1631 for(formatp = format_data_cp; formatp->
par_bytes; formatp++)
1634 formatp->
flags |= ((short)format & (
short)0xf0);
1648 int to_delete = 0, more;
1653 reqp = servp->request_head;
1669 reqp = servp->request_head;
1705 if(reqp->
conn_id == *client_ids)
1720 register int found = 0;
1721 int to_delete = 0, more, conn_id;
1734 sprintf(str,
"Update Service - Invalid service id");
1835 reqpp = reqp->
reqpp;
1869 register int found = 0;
1875 sprintf(str,
"Service Has Clients- Invalid service id");
1909 sprintf(str,
"Get Timeout - Invalid service id");
1922 if(reqp->
conn_id == client_id)
1936 sprintf(str,
"Set Quality - Invalid service id");
1961 struct timeb timebuf;
1964 struct timezone *tz;
1970 sprintf(str,
"Set Timestamp - Invalid service id");
1994 gettimeofday(&tv, tz);
2021 sprintf(str,
"Get Timestamp - Invalid service id");
2055 register REQUEST *reqp, *prevp;
2058 static int packet_size = 0;
2064 sprintf(str,
"Send Service - Invalid service id");
2094 memcpy(dis_packet->
buffer, buffer, (
size_t)size);
2101 printf(
" Server Sending Service: Couldn't write to Conn %3d : Client %s@%s\n",conn_id,
2114 register REQUEST *reqp, *auxp;
2128 sprintf(str,
"Remove Service - Invalid service id");
2147 printf(
"Removing service %s, delay_delete = %d\n",
2168 release_request(reqp, reqpp, 1);
2176 dis_hash_service_remove(servp);
2224 register SERVICE *servp, *prevp;
2227 int hash_index, old_index;
2263 if(servp->
dnsp == dnsp)
2269 if(old_index != hash_index)
2276 old_index = hash_index;
2287 if(clip->
dnsp != dnsp)
2297 printf(
"Releasing conn %d, to %s@%s\n",
2313 printf(
"Cleaning dnsp variables\n");
2345 register SERVICE *servp, *prevp;
2415 if(
Dna_conns[i].read_ast == dis_insert_request)
2481 release_request(reqp, reqpp, 0);
2545 static int curr_allocated_size = 0;
2546 static char *service_info_buffer;
2569 if(!curr_allocated_size)
2571 service_info_buffer = (
char *)
malloc((
size_t)max_size);
2572 curr_allocated_size = max_size;
2574 else if (max_size > curr_allocated_size)
2576 free(service_info_buffer);
2577 service_info_buffer = (
char *)
malloc((
size_t)max_size);
2578 curr_allocated_size = max_size;
2580 service_info_buffer[0] =
'\0';
2581 buff_ptr = service_info_buffer;
2588 strcat(buff_ptr, servp->
name);
2589 strcat(buff_ptr,
"\n");
2590 buff_ptr += (int)strlen(buff_ptr);
2606 return(service_info_buffer);
2620 reqpp = clip->requestp_head;
2668 if((
remove) && (
Serving == 0))
2686 static int releasing = 0;
2703 printf(
" Couldn't write to client %s@%s, releasing connection %d\n",
2704 task,
node, conn_id);
2750 memcpy(new_cmnd->
buffer, cmnd_buff, (
size_t)*size);
2757 register int ret_val = -1;
2771 *size = cmndp->
size;
2780 if (*size >= cmndp->
size)
2782 *size = cmndp->
size;
2785 memcpy(buffer, cmndp->
buffer, (
size_t)*size);
2822 struct dsc$descriptor_s *for_str;
2826 strcpy(for_str->dsc$a_pointer, c_str);
2827 for(i = (
int)strlen(c_str); i< for_str->dsc$w_length; i++)
2828 for_str->dsc$a_pointer[i] =
' ';
2836 int i, index, max_size;
2837 static int curr_allocated_size = 0;
2838 static char *dns_info_buffer;
2839 register char *dns_client_info;
2844 if(!curr_allocated_size)
2846 dns_info_buffer =
malloc((
size_t)max_size);
2847 curr_allocated_size = max_size;
2849 dns_client_info = dns_info_buffer;
2850 dns_client_info[0] =
'\0';
2858 if(clip->
dnsp != dnsp)
2860 curr_conns[index++] = clip->
conn_id;
2863 if (max_size > curr_allocated_size)
2865 free(dns_info_buffer);
2866 dns_info_buffer =
malloc((
size_t)max_size);
2867 curr_allocated_size = max_size;
2869 dns_client_info = dns_info_buffer;
2870 dns_client_info[0] =
'\0';
2876 strcat(dns_client_info,
"+");
2881 strcat(dns_client_info,
"-");
2886 for(i=0; i<index;i++)
2889 strcat(dns_client_info,task);
2890 strcat(dns_client_info,
"@");
2891 strcat(dns_client_info,node);
2892 strcat(dns_client_info,
"|");
2895 dns_client_info[(int)strlen(dns_client_info)-1] =
'\0';
2896 *bufp = (
int *)dns_info_buffer;
2897 *size = (int)strlen(dns_info_buffer)+1;
2904 if(strstr(servp->
name,
"/RpcIn"))
2906 strcpy(name,servp->
name);
2907 ptr = (
char *)strstr(name,
"/RpcIn");
2909 strcat(service_info_buffer, name);
2910 strcat(service_info_buffer,
"|");
2913 strcat(service_info_buffer, servp->
def);
2915 strcat(name,
"/RpcOut");
2918 strcat(service_info_buffer,
",");
2921 strcat(service_info_buffer, servp->
def);
2924 strcat(service_info_buffer,
"|RPC");
2925 strcat(service_info_buffer,
"\n");
2927 else if(strstr(servp->
name,
"/RpcOut"))
2941 strcat(service_info_buffer, servp->
name);
2942 strcat(service_info_buffer,
"|");
2945 strcat(service_info_buffer, servp->
def);
2947 strcat(service_info_buffer,
"|");
2950 strcat(service_info_buffer,
"CMD");
2952 strcat(service_info_buffer,
"\n");
2959 int max_size, done = 0;
2960 static int curr_allocated_size = 0;
2961 static char *service_info_buffer;
2968 if(!curr_allocated_size)
2970 service_info_buffer = (
char *)
malloc((
size_t)max_size);
2971 curr_allocated_size = max_size;
2973 else if (max_size > curr_allocated_size)
2975 free(service_info_buffer);
2976 service_info_buffer = (
char *)
malloc((
size_t)max_size);
2977 curr_allocated_size = max_size;
2979 service_info_buffer[0] =
'\0';
2980 buff_ptr = service_info_buffer;
2987 if(servp->
dnsp != dnsp)
2999 buff_ptr += (int)strlen(buff_ptr);
3007 if(servp->
dnsp != dnsp)
3014 strcat(buff_ptr,
"-");
3015 buff_ptr += (int)strlen(buff_ptr);
3017 buff_ptr += (int)strlen(buff_ptr);
3023 strcat(buff_ptr,
"+");
3024 buff_ptr += (int)strlen(buff_ptr);
3028 buff_ptr += (int)strlen(buff_ptr);
3036 *bufp = (
int *)service_info_buffer;
3037 *size = (int)(buff_ptr - service_info_buffer+1);
3054 (
char *)&conn_id, 4)) )
3199 static void error_handler(
int conn_id,
int severity,
int errcode,
char *reason,
int exit)
3201 int exit_tag, exit_code, exit_size;
3221 exit_code = errcode;
3224 exit_size =
sizeof(int);
3231 #define MAX_HASH_ENTRIES 5000 3240 static int done = 0;
3250 Service_hash_table[
i] = 0;
3251 Service_new_entries[
i] = 0;
3263 if(!Service_hash_table[index])
3268 Service_new_entries[index]++;
3277 Service_new_entries[index]--;
3278 if(Service_new_entries[index] < 0)
3279 Service_new_entries[index] = 0;
3287 if(!Service_hash_table[index])
3302 if(!Service_hash_table[index])
3307 (
DLL *) Service_hash_table[index],
3308 name, (
int)strlen(name)+1)) )
3325 index = *curr_index;
3329 prevp = Service_hash_table[index];
3333 prevp = Service_hash_table[index];
3339 if((!new_entries) || (Service_new_entries[index] > 0))
3342 (
DLL *) Service_hash_table[index],
3354 prevp = Service_hash_table[index];
3356 *curr_index = index;
3409 int n_entries, max_entry_index = 0;
3410 int max_entries = 0;
3415 servp = Service_hash_table[
i];
3417 (
DLL *) Service_hash_table[i],
3422 printf(
" Name = %s\n",servp->
name);
3425 printf(
"HASH[%d] - %d entries\n", i, n_entries);
3426 if(n_entries > max_entries)
3428 max_entries = n_entries;
3429 max_entry_index =
i;
3432 printf(
"Maximum : HASH[%d] - %d entries\n", max_entry_index, max_entries);
3445 printf(
"Name = %s\n",servp->
name);
3458 STRING, PVOID, PVOID, INT, PVOID, INT)
3460 STRING, PVOID, PVOID, INT)
DIS_DNS_CONN * Default_DNS
int close_dns(dim_long dnsid, SRC_TYPES src_type)
int do_exit_handler(int conn_id)
#define MAX_REGISTRATION_UNIT
static void error_handler(int conn_id, int severity, int errcode, char *reason, int exit)
int dtq_delete(int queue_id)
static DIS_CMND * Cmnds_head
DllExp DIM_NOSHARE int Curr_N_Conns
SLL * sll_get_head(SLL *head)
int dis_selective_update_service(unsigned service_id, int *client_ids)
int dna_write(int conn_id, void *buffer, int size)
SERVICE * dis_hash_service_get_next(int *curr_index, SERVICE *prevp, int new_entries)
static EXIT_H * Exit_h_head
int dis_hash_service_init()
int dis_start_serving_dns(dim_long dnsid, char *task)
int copy_swap_buffer_in(FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
static int check_exit_handler_item(EXIT_H *exitp, int conn_id)
void service_info(dim_long *tag, int **bufp, int *size, int *first_time)
char service_name[MAX_NAME]
int dis_start_serving(char *task)
int dis_hash_service_registered(int index, SERVICE *servp)
void release_all_requests(int conn_id, CLIENT *clip)
DllExp DIM_NOSHARE NET_CONNECTION * Net_conns
static void(* Client_exit_user_routine)()=0
int send_dns_update_packet(DIS_DNS_CONN *dnsp)
void * id_get_ptr(int id, SRC_TYPES type)
void std_cmnd_handler(dim_long *tag, int *cmnd_buff, int *size)
DIS_DNS_CONN * find_dns_by_conn_id(int conn_id)
void dll_insert_queue(DLL *head, DLL *item)
int execute_service(int req_id)
int dis_set_buffer_size(int size)
struct dis_dns_ent * prev
void do_dis_stop_serving_dns(DIS_DNS_CONN *dnsp)
int rand_tmout(int min, int max)
int dna_close(int conn_id)
int dis_hash_service_insert(SERVICE *servp)
int find_release_request(int conn_id, int service_id)
SERVICE * find_service(char *name)
void dis_send_service(unsigned service_id, int *buffer, int size)
int copy_swap_buffer_out(int format, FORMAT_STR *format_data, void *buff_out, void *buff_in, int size)
int dis_get_client(char *name)
#define DIS_STAMPED_HEADER
#define DIS_DNS_TMOUT_MAX
unsigned dis_add_cmnd(char *name, char *type, void(*user_routine)(), dim_long tag)
char task_name[MAX_TASK_NAME-4]
static int release_conn(int conn_id, int print_flg, int dns_flag)
int dis_hash_service_remove(SERVICE *servp)
CLIENT * find_client(int conn_id)
void add_exit_handler(int *tag, int *bufp, int *size)
static void dis_insert_request(int conn_id, DIC_PACKET *dic_packet, int size, int status)
void register_services(DIS_DNS_CONN *dnsp, int flag, int dns_flag)
void execute_command(SERVICE *servp, DIC_PACKET *packet)
int get_node_addr(char *node_addr)
int updating_service_list
#define DIS_DNS_TMOUT_MIN
CLIENT * check_delay_delete(int conn_id)
void dis_add_error_handler(void(*user_routine)())
char service_name[MAX_NAME]
void dll_remove(DLL *item)
int do_update_service(unsigned service_id, int *client_ids)
void append_service(char *service_info_buffer, SERVICE *servp)
void do_update_service_list(DIS_DNS_CONN *dnsp)
unsigned dis_add_service(char *name, char *type, void *address, int size, void(*user_routine)(), dim_long tag)
char node_name[MAX_NODE_NAME]
static int Service_new_entries[MAX_HASH_ENTRIES]
FORMAT_STR format_data[MAX_NAME/4]
static CLIENT * Client_head
int dis_remove_service(unsigned service_id)
void unregister_service(DIS_DNS_CONN *dnsp, SERVICE *servp)
char * dis_get_client_services(int conn_id)
unsigned dis_add_service_dns(dim_long dnsid, char *name, char *type, void *address, int size, void(*user_routine)(), dim_long tag)
int open_dns(dim_long dnsid, void(*recv_rout)(), void(*error_rout)(), int tmout_min, int tmout_max, SRC_TYPES src_type)
void dtq_start_timer(int time, void(*user_routine)(), dim_long tag)
struct reqp_ent REQUEST_PTR
SLL * sll_remove_head(SLL *head)
static unsigned do_dis_add_cmnd(char *name, char *type, void(*user_routine)(), dim_long tag)
void dis_report_service(char *serv_name)
#define WATCHDOG_TMOUT_MIN
int sll_insert_queue(SLL *head, SLL *item)
_DIM_PROTO(static void dis_insert_request,(int conn_id, DIC_PACKET *dic_packet, int size, int status))
static int Dis_packet_size
SERVICE * dis_hash_service_exists(char *name)
int dtq_rem_entry(int queue_id, TIMR_ENT *entry)
static int Dis_first_time
char service_def[MAX_NAME]
static void rem_exit_handler_item(EXIT_H *exitp)
static SERVICE * Service_hash_table[MAX_HASH_ENTRIES]
static EXIT_H * find_exit_handler_item(int conn_id)
static DIS_DNS_CONN * create_dns(dim_long dnsid)
static unsigned do_dis_add_cmnd_dns(char *name, char *type, void(*user_routine)(), dim_long tag, dim_long dnsid)
void client_info(dim_long *tag, int **bufp, int *size, int *first_time)
static void add_exit_handler_item(int conn_id, int tag)
int dis_get_next_cmnd(dim_long *tag, int *buffer, int *size)
unsigned dis_add_cmnd_dns(dim_long dnsid, char *name, char *type, void(*user_routine)(), dim_long tag)
dim_long dns_get_dnsid(int conn_id, SRC_TYPES src_type)
REQUEST_PTR * requestp_head
int dis_update_service(unsigned service_id)
int dna_get_node_task(int conn_id, char *node, char *task)
DIS_DNS_CONN * dis_find_dns(dim_long dnsid)
void dis_add_exit_handler(void(*user_routine)())
int sll_remove(SLL *head, SLL *item)
static int get_format_data(FORMAT_STR *format_data, char *def)
static int check_service_name(char *name)
#define WATCHDOG_TMOUT_MAX
int dna_write_nowait(int conn_id, void *buffer, int size)
struct serv * service_ptr
void recv_dns_dis_rout(int conn_id, DNS_DIS_PACKET *packet, int size, int status)
static int Version_number
int check_client(REQUEST *reqp, int *client_ids)
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 release_request(REQUEST *reqp, REQUEST_PTR *reqpp, int remove)
int dna_open_server(char *task, void(*read_ast)(), int *protocol, int *port, void(*error_ast)())
int dis_find_client_conns()
static void exit_handler(int *tag, int *bufp, int *size)
static unsigned do_dis_add_service_dns(char *name, char *type, void *address, int size, void(*user_routine)(), dim_long tag, dim_long dnsid)
void id_free(int id, SRC_TYPES type)
TIMR_ENT * dtq_add_entry(int queue_id, int time, void(*user_routine)(), dim_long tag)
void dis_add_client_exit_handler(void(*user_routine)())
DllExp DIM_NOSHARE DNA_CONNECTION * Dna_conns
DLL * dll_get_next(DLL *head, DLL *item)
void dis_print_hash_table()
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
int dis_get_timeout(unsigned service_id, int client_id)
static void(* Exit_user_routine)()=0
int dis_set_timestamp(unsigned serv_id, int secs, int millisecs)
void dis_set_client_exit_handler(int conn_id, int tag)
static void(* Error_user_routine)()=0
SERVICE_REG services[MAX_SERVICE_UNIT]
CLIENT * create_client(int conn_id, SERVICE *servp, int *new_client)
unsigned int dis_client_id
void remove_service(int req_id)
char * dis_get_error_services()
static unsigned do_dis_add_service(char *name, char *type, void *address, int size, void(*user_routine)(), dim_long tag)
void dis_set_quality(unsigned serv_id, int quality)
int get_node_name(char *node_name)
struct dis_dns_ent DIS_DNS_CONN
int dis_get_n_clients(unsigned service_id)
DIS_DNS_PACKET dis_dns_packet
sprintf(name1,"NewService%d", i)
static DIS_DNS_CONN * DNS_head
void dis_stop_serving_dns(dim_long dnsid)
SLL * sll_search(SLL *head, char *data, int size)
static void user_routine(void *tagp, void *bufp, int *size)
DLL * dll_search(DLL *head, char *data, int size)
static DIS_STAMPED_PACKET * Dis_packet
static int Last_n_clients
int dis_get_timestamp(unsigned serv_id, int *secs, int *millisecs)
void do_register_services(DIS_DNS_CONN *dnsp)