/* * Initialize UAC */ int uac_init(void) { str src[3]; struct socket_info *si; if (RAND_MAX < TM_TABLE_ENTRIES) { LM_WARN("uac does not spread across the whole hash table\n"); } /* on tcp/tls bind_address is 0 so try to get the first address we listen * on no matter the protocol */ si=bind_address?bind_address:get_first_socket(); if (si==0){ LM_CRIT("null socket list\n"); return -1; } /* calculate the initial From tag */ src[0].s = "Long live SER server"; src[0].len = strlen(src[0].s); src[1].s = si->address_str.s; src[1].len = strlen(src[1].s); src[2].s = si->port_no_str.s; src[2].len = strlen(src[2].s); MD5StringArray(from_tag, src, 3); from_tag[MD5_LEN] = '-'; return 1; }
/** * \brief Child initialization, generates suffix * \param rank not used * \return 0 on success, -1 on error */ int child_init_callid(int rank) { struct socket_info *si; /* on tcp/tls bind_address is 0 so try to get the first address we listen * on no matter the protocol */ si=bind_address?bind_address:get_first_socket(); if (si==0){ LOG(L_CRIT, "BUG: child_init_callid: null socket list\n"); return -1; } callid_suffix.s = callid_buf + callid_prefix.len; callid_suffix.len = snprintf(callid_suffix.s, CALLID_SUFFIX_LEN, "%c%d@%.*s", '-', my_pid(), si->address_str.len, si->address_str.s); if ((callid_suffix.len == -1) || (callid_suffix.len > CALLID_SUFFIX_LEN)) { LOG(L_ERR, "ERROR: child_init_callid: buffer too small\n"); return -1; } DBG("DEBUG: callid: '%.*s'\n", callid_prefix.len + callid_suffix.len, callid_prefix.s); return 0; }
/* this should close the sockets open to any of the application servers, and * send them an EOF event or something that signals that SER is beeing shutdown, * so they could do their cleanup, etc. */ static int seas_exit(void) { if( seas_listen_ip!=NULL && seas_listen_ip!=&(get_first_socket()->address)) pkg_free(seas_listen_ip); return 0; }
/** Initializes seas module. It first parses the listen_sockets parameter * which has the form "ip_address[:port]", creates the pipe to * communicate with the dispatcher. */ static int seas_init(void) { char *p,*port; struct hostent *he; struct socket_info *si; int c_pipe[2],mierr,i; /** Populate seas_functions*/ if (load_tm_api(&seas_f.tmb)!=0) { LM_ERR( "can't load TM API\n"); return -1; } if(!(seas_f.t_check_orig_trans = find_export("t_check_trans", 0, 0))){ LM_ERR( "Seas requires transaction module (t_check_trans not found)\n"); return -1; } /** Populate seas_functions*/ c_pipe[0]=c_pipe[1]=-1; p=seas_listen_socket; port=(char *)0; seas_listen_port=5080; /*if the seas_listen_socket configuration string is empty, use default values*/ if(p==NULL || *p==0){ si=get_first_socket(); seas_listen_ip=&si->address; } else {/*if config string is not empty, then try to find host first, and maybe port..*/ while(*p){ if(*p == ':'){ *p=0; port=p+1; break; } p++; } if(!(he=resolvehost(seas_listen_socket,0))) goto error; if(!(seas_listen_ip=pkg_malloc(sizeof(struct ip_addr)))) goto error; hostent2ip_addr(seas_listen_ip, he, 0); if(port!=(char *)0 && (seas_listen_port=str2s(port,strlen(port),&mierr))==0){ LM_ERR("invalid port %s \n",port); goto error; } } memset(unc_as_t,0,2*MAX_UNC_AS_NR*sizeof(struct unc_as));//useless because unc_as_t is in bss? if (pipe(c_pipe)==-1) { LM_ERR("cannot create pipe!\n"); goto error; } read_pipe=c_pipe[0]; write_pipe=c_pipe[1]; seas_init_tags(); if(0>start_stats_server(seas_stats_socket)) goto error; if(0>prepare_ha()) goto error; if(0>parse_cluster_cfg()) goto error; return 0; error: for(i=0;i<2;i++) if(c_pipe[i]!=-1) close(c_pipe[i]); if(seas_listen_ip!=0) pkg_free(seas_listen_ip); if(use_stats) stop_stats_server(); return -1; }
int global_init(void) { load_tm_f load_tm; int i, net_pipe[2], foo; char *p; struct socket_info* si; /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LM_ERR("cannot import load_tm\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) goto error; /*fix domain*/ if (!domain.s){ si=get_first_socket(); if (si==0){ LM_CRIT("null listen socket list\n"); goto error; } /*do I have to add port?*/ i = (si->port_no_str.len && si->port_no!=5060); domain.len = si->name.len + i*(si->port_no_str.len+1); domain.s = (char*)pkg_malloc(domain.len); if (!domain.s) { LM_ERR("no free pkg memory!\n"); goto error; } p = domain.s; memcpy(p,si->name.s,si->name.len); p += si->name.len; if (i) { *p=':'; p++; memcpy(p,si->port_no_str.s, si->port_no_str.len); p += si->port_no_str.len; } } /* creates pipes for networks */ for(i=0;i<nr_of_networks;i++) { /* create the pipe*/ if (pipe(net_pipe)==-1) { LM_ERR("failed to create pipe!\n"); goto error; } networks[i].pipe_out = net_pipe[0]; net_pipes_in[i] = net_pipe[1]; /* sets reading from pipe to non blocking */ if ((foo=fcntl(net_pipe[0],F_GETFL,0))<0) { LM_ERR("failed to get flag for pipe - fcntl\n"); goto error; } foo |= O_NONBLOCK; if (fcntl(net_pipe[0],F_SETFL,foo)<0) { LM_ERR("failed to set flag for pipe - fcntl\n"); goto error; } } /* if report will be used, init the report queue */ if (sms_report_type!=NO_REPORT && !init_report_queue()) { LM_ERR("cannot get shm memory!\n"); goto error; } /* alloc in shm for queued_msgs */ queued_msgs = (int*)shm_malloc(sizeof(int)); if (!queued_msgs) { LM_ERR("cannot get shm memory!\n"); goto error; } *queued_msgs = 0; /* register nr_of_modems number of child processes that will * update their local configuration */ cfg_register_child(nr_of_modems); return 1; error: return -1; }
int global_init(void) { int i, net_pipe[2], foo; char *p; struct socket_info* si; /* load the TM API */ if (load_tm_api(&tmb)!=0) { LM_ERR("failed to load TM API\n"); goto error; } /*fix domain length*/ if (domain_str) { domain.s = domain_str; domain.len = strlen(domain_str); } else { si=get_first_socket(); if (si==0){ LM_CRIT("null listen socket list\n"); goto error; } /*do I have to add port?*/ i = (si->port_no_str.len && si->port_no!=5060); domain.len = si->name.len + i*(si->port_no_str.len+1); domain.s = (char*)pkg_malloc(domain.len); if (!domain.s) { LM_ERR("no more pkg memory!\n"); goto error; } p = domain.s; memcpy(p,si->name.s,si->name.len); p += si->name.len; if (i) { *p=':'; p++; memcpy(p,si->port_no_str.s, si->port_no_str.len); p += si->port_no_str.len; } } /* creates pipes for networks */ for(i=0;i<nr_of_networks;i++) { /* create the pipe*/ if (pipe(net_pipe)==-1) { LM_ERR("failed create pipe!\n"); goto error; } networks[i].pipe_out = net_pipe[0]; net_pipes_in[i] = net_pipe[1]; /* sets reading from pipe to non blocking */ if ((foo=fcntl(net_pipe[0],F_GETFL,0))<0) { LM_ERR("failed to get flag for pipe - fcntl\n"); goto error; } foo |= O_NONBLOCK; if (fcntl(net_pipe[0],F_SETFL,foo)<0) { LM_ERR("failed to set flag for pipe" " - fcntl\n"); goto error; } } /* if report will be used, init the report queue */ if (sms_report_type!=NO_REPORT && !init_report_queue()) { LM_ERR("no more share memory!\n"); goto error; } /* alloc in shm for queued_msgs */ queued_msgs = (int*)shm_malloc(sizeof(int)); if (!queued_msgs) { LM_ERR("no more share memory!\n"); goto error; } *queued_msgs = 0; return 1; error: return -1; }