static int mod_init(void) { struct id_list* l; if (listen_lst==0) { add_binrpc_socket(PARAM_STRING, DEFAULT_CTL_SOCKET); } DBG("listening on:\n"); for (l=listen_lst; l; l=l->next){ fd_no++; switch(l->proto){ case UNIXD_SOCK: DBG(" [%s:unix dgram] %s\n", payload_proto_name(l->data_proto), l->name); break; case UNIXS_SOCK: DBG(" [%s:unix stream] %s\n", payload_proto_name(l->data_proto), l->name); break; case UDP_SOCK: DBG(" [%s:udp] %s:%d\n", payload_proto_name(l->data_proto), l->name, l->port?l->port:DEFAULT_CTL_PORT); break; case TCP_SOCK: DBG(" [%s:tcp] %s:%d\n", payload_proto_name(l->data_proto), l->name, l->port?l->port:DEFAULT_CTL_PORT); break; case FIFO_SOCK: DBG(" [%s:fifo] %s\n", payload_proto_name(l->data_proto), l->name); fd_no++; /* fifos use 2 fds */ break; default: LOG(L_CRIT, "BUG: ctrl: listen protocol %d not supported\n", l->proto); goto error; } } /* open socket now, before suid */ if (init_ctrl_sockets(&ctrl_sock_lst, listen_lst, DEFAULT_CTL_PORT, usock_mode, usock_uid, usock_gid)<0){ LOG(L_ERR, "ERROR: ctl: mod_init: init ctrl. sockets failed\n"); goto error; } if (ctrl_sock_lst){ /* we will fork */ register_procs(1); /* we will be creating an extra process */ register_fds(fd_no); /* The child process will keep updating its local configuration */ cfg_register_child(1); } #ifdef USE_FIFO fifo_rpc_init(); #endif return 0; error: return -1; }
/** * \brief update internal counters for running new basic sec. timers * @param timers number of basic timer processes * @return 0 on success; -1 on error */ int register_basic_timers(int timers) { if(register_procs(timers)<0) return -1; cfg_register_child(timers); return 0; }
int async_task_init(void) { LM_DBG("start initializing asynk task framework\n"); if(_async_task_workers<=0) return 0; /* advertise new processes to core */ register_procs(_async_task_workers); /* advertise new processes to cfg framework */ cfg_register_child(_async_task_workers); return 0; }
/*! This is the first function to be called by Kamailio, to initialize the module. * This call must always return a value as soon as possible. If it were not to * return, then Kamailio would not be able to initialize any of the other * modules. */ static int mod_init(void) { if (register_message_code_statistics() < 0) { return -1; } /* Initialize shared memory used to buffer communication between the * usrloc module and the snmpstats module. */ initInterprocessBuffers(); /* We need to register for callbacks with usrloc module, for whenever a * contact is added or removed from the system. We need to do it now * before Kamailio's functions get a chance to load up old user data from * the database. That load will happen if a lookup() function is come * across in kamailio.cfg. */ if (snmp_export_registrar!=0) { if(!registerForUSRLOCCallbacks()) { /* Originally there were descriptive error messages here to help * the operator debug problems. Turns out this may instead * alarm them about problems they don't need to worry about. So * the messages are commented out for now */ /* LM_ERR("snmpstats module was unable to register callbacks" " with the usrloc module\n"); LM_ERR("Are you sure that the usrloc module was loaded" " before the snmpstats module in "); LM_ERR("kamailio.cfg? kamailioSIPRegUserTable will not be " "updated."); */ } } /* Register the alarm checking function to run periodically */ register_timer(run_alarm_check, 0, ALARM_AGENT_FREQUENCY_IN_SECONDS); /* add space for one extra process */ register_procs(1); /* add child to update local config framework structures */ cfg_register_child(1); /* Initialize config framework in utilities.c */ config_context_init(); return 0; }
/* * initialize module */ static int mod_init(void) { if (load_tm_api(&tmb)) { LM_ERR("failed to load tm API\n"); return -1; } if (strcmp(backend, "component") && strcmp(backend, "server")) { LM_ERR("invalid backend '%s'\n", backend); return -1; } if (!xmpp_port) { if (!strcmp(backend, "component")) xmpp_port = DEFAULT_COMPONENT_PORT; else if (!strcmp(backend, "server")) xmpp_port = DEFAULT_SERVER_PORT; } /* fix up the domain separator -- we only need 1 char */ if (domain_sep_str && *domain_sep_str) domain_separator = *domain_sep_str; if(outbound_proxy.s) outbound_proxy.len= strlen(outbound_proxy.s); if(init_xmpp_cb_list()<0){ LM_ERR("failed to init callback list\n"); return -1; } if (pipe(pipe_fds) < 0) { LM_ERR("pipe() failed\n"); return -1; } /* add space for one extra process */ register_procs(1); /* add child to update local config framework structures */ cfg_register_child(1); return 0; }
/** * init module function */ static int mod_init(void) { char *p; /* init faked sip msg */ if(faked_msg_init()<0) { LM_ERR("failed to init faked sip message\n"); return -1; } if(load_tm_api( &tmb ) < 0) { LM_INFO("cannot load the TM module functions - async relay disabled\n"); memset(&tmb, 0, sizeof(tm_api_t)); } if(_evapi_bind_param!=NULL) { p = strchr(_evapi_bind_param, ':'); if(p!=NULL) { *p++ = '\0'; _evapi_bind_port = (short)atoi(p); if (_evapi_bind_port <= 0) { LM_ERR("invalid port: %d\n", _evapi_bind_port); return -1; } } _evapi_bind_addr = _evapi_bind_param; } /* add space for one extra process */ register_procs(1 + _evapi_workers); /* add child to update local config framework structures */ cfg_register_child(1 + _evapi_workers); evapi_init_environment(_evapi_netstring_format_param); return 0; }
static int mod_init(void) { pv_spec_t avp_spec; str s; bind_usrloc_t bind_usrloc; qvalue_t dq; callback_singleton = shm_malloc(sizeof (int)); *callback_singleton = 0; /*build the required strings */ scscf_serviceroute_uri_str.s = (char*) pkg_malloc(orig_prefix.len + scscf_name_str.len); if (!scscf_serviceroute_uri_str.s) { LM_ERR("Unable to allocate memory for service route uri\n"); return -1; } if (contact_expires_buffer_percentage < 0 || contact_expires_buffer_percentage > 90) { LM_ERR("contact expires percentage not valid, must be >0 and <=90"); return -1; } memcpy(scscf_serviceroute_uri_str.s, orig_prefix.s, orig_prefix.len); scscf_serviceroute_uri_str.len = orig_prefix.len; if (scscf_name_str.len > 4 && strncasecmp(scscf_name_str.s, "sip:", 4) == 0) { memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len, scscf_name_str.s + 4, scscf_name_str.len - 4); scscf_serviceroute_uri_str.len += scscf_name_str.len - 4; } else { memcpy(scscf_serviceroute_uri_str.s + scscf_serviceroute_uri_str.len, scscf_name_str.s, scscf_name_str.len); scscf_serviceroute_uri_str.len += scscf_name_str.len; } pv_tmx_data_init(); /* </build required strings> */ #ifdef STATISTICS /* register statistics */ if (register_module_stats(exports.name, mod_stats) != 0) { LM_ERR("failed to register core statistics\n"); return -1; } if (!register_stats()) { LM_ERR("Unable to register statistics\n"); return -1; } #endif /*register space for notification processors*/ register_procs(notification_processes); cfg_register_child(notification_processes); /* bind the SL API */ if (sl_load_api(&slb) != 0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* load the TM API */ if (load_tm_api(&tmb) != 0) { LM_ERR("can't load TM API\n"); return -1; } /* load the CDP API */ if (load_cdp_api(&cdpb) != 0) { LM_ERR("can't load CDP API\n"); return -1; } cdp_avp = load_cdp_avp(); if (!cdp_avp) { LM_ERR("can't load CDP_AVP API\n"); return -1; } if (cfg_declare("registrar", registrar_cfg_def, &default_registrar_cfg, cfg_sizeof(registrar), ®istrar_cfg)) { LM_ERR("Fail to declare the configuration\n"); return -1; } if (rcv_avp_param && *rcv_avp_param) { s.s = rcv_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", rcv_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, &rcv_avp_name, &rcv_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", rcv_avp_param); return -1; } } else { rcv_avp_name.n = 0; rcv_avp_type = 0; } if (aor_avp_param && *aor_avp_param) { s.s = aor_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", aor_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, &aor_avp_name, &aor_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", aor_avp_param); return -1; } } else { aor_avp_name.n = 0; aor_avp_type = 0; } if (reg_callid_avp_param && *reg_callid_avp_param) { s.s = reg_callid_avp_param; s.len = strlen(s.s); if (pv_parse_spec(&s, &avp_spec) == 0 || avp_spec.type != PVT_AVP) { LM_ERR("malformed or non AVP %s AVP definition\n", reg_callid_avp_param); return -1; } if (pv_get_avp_name(0, &avp_spec.pvp, ®_callid_avp_name, ®_callid_avp_type) != 0) { LM_ERR("[%s]- invalid AVP definition\n", reg_callid_avp_param); return -1; } } else { reg_callid_avp_name.n = 0; reg_callid_avp_type = 0; } bind_usrloc = (bind_usrloc_t) find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LM_ERR("can't bind usrloc\n"); return -1; } /* Normalize default_q parameter */ dq = cfg_get(registrar, registrar_cfg, default_q); if (dq != Q_UNSPECIFIED) { if (dq > MAX_Q) { LM_DBG("default_q = %d, lowering to MAX_Q: %d\n", dq, MAX_Q); dq = MAX_Q; } else if (dq < MIN_Q) { LM_DBG("default_q = %d, raising to MIN_Q: %d\n", dq, MIN_Q); dq = MIN_Q; } } cfg_get(registrar, registrar_cfg, default_q) = dq; if (bind_usrloc(&ul) < 0) { return -1; } /*Register for callback of URECORD being deleted - so we can send a SAR*/ if (ul.register_ulcb == NULL) { LM_ERR("Could not import ul_register_ulcb\n"); return -1; } if (ul.register_ulcb(0, 0, UL_IMPU_INSERT, ul_impu_inserted, 0) < 0) { LM_ERR("can not register callback for insert\n"); return -1; } if (sock_hdr_name.s) { if (sock_hdr_name.len == 0 || sock_flag == -1) { LM_WARN("empty sock_hdr_name or sock_flag no set -> reseting\n"); sock_hdr_name.len = 0; sock_flag = -1; } } else if (sock_flag != -1) { LM_WARN("sock_flag defined but no sock_hdr_name -> reseting flag\n"); sock_flag = -1; } /* fix the flags */ sock_flag = (sock_flag != -1) ? (1 << sock_flag) : 0; tcp_persistent_flag = (tcp_persistent_flag != -1) ? (1 << tcp_persistent_flag) : 0; /* init the registrar notifications */ if (!notify_init()) return -1; /* register the registrar notifications timer */ //Currently we do not use this - we send notifies immediately //if (register_timer(notification_timer, notification_list, 5) < 0) return -1; return 0; }
/*! \brief Initialize fifo transport */ int jsonrpc_init_fifo_file(void) { int n; struct stat filestat; /* checking the jsonrpc_fifo module param */ if (jsonrpc_fifo==NULL || *jsonrpc_fifo == 0) { jsonrpc_fifo=NULL; LM_DBG("No fifo configured\n"); return 0; } LM_DBG("testing if fifo file exists ...\n"); n=stat(jsonrpc_fifo, &filestat); if (n==0) { /* FIFO exist, delete it (safer) if no config check */ if(config_check==0) { if (unlink(jsonrpc_fifo)<0){ LM_ERR("Cannot delete old fifo (%s): %s\n", jsonrpc_fifo, strerror(errno)); return -1; } } } else if (n<0 && errno!=ENOENT){ LM_ERR("MI FIFO stat failed: %s\n", strerror(errno)); return -1; } /* checking the fifo_reply_dir param */ if(!jsonrpc_fifo_reply_dir || *jsonrpc_fifo_reply_dir == 0) { LM_ERR("fifo_reply_dir parameter is empty\n"); return -1; } /* Check if the directory for the reply fifo exists */ n = stat(jsonrpc_fifo_reply_dir, &filestat); if(n < 0){ LM_ERR("Directory stat for MI Fifo reply failed: %s\n", strerror(errno)); return -1; } if(S_ISDIR(filestat.st_mode) == 0){ LM_ERR("fifo_reply_dir parameter is not a directory\n"); return -1; } /* check fifo_mode */ if(!jsonrpc_fifo_mode){ LM_WARN("cannot specify fifo_mode = 0, forcing it to rw-------\n"); jsonrpc_fifo_mode = S_IRUSR | S_IWUSR; } if (jsonrpc_fifo_uid_s){ if (user2uid(&jsonrpc_fifo_uid, &jsonrpc_fifo_gid, jsonrpc_fifo_uid_s)<0){ LM_ERR("Bad user name %s\n", jsonrpc_fifo_uid_s); return -1; } } if (jsonrpc_fifo_gid_s){ if (group2gid(&jsonrpc_fifo_gid, jsonrpc_fifo_gid_s)<0){ LM_ERR("Bad group name %s\n", jsonrpc_fifo_gid_s); return -1; } } /* add space for one extra process */ register_procs(1); /* add child to update local config framework structures */ cfg_register_child(1); 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))) 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; register_procs(1); /* add child to update local config framework structures */ cfg_register_child(1); 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; }
/** * init module function */ static int mod_init(void) { unsigned int n; LM_INFO("Initializing Http Async module\n"); #ifdef STATISTICS /* register statistics */ if (register_module_stats( exports.name, mod_stats)!=0 ) { LM_ERR("failed to register core statistics\n"); return -1; } #endif /* sanitize hash_size */ if (hash_size < 1){ LM_WARN("hash_size is smaller " "than 1 -> rounding from %d to 1\n", hash_size); hash_size = 1; } /* check that the hash table size is a power of 2 */ for( n=0 ; n<(8*sizeof(n)) ; n++) { if (hash_size==(1<<n)) break; if (n && hash_size<(1<<n)) { LM_WARN("hash_size is not a power " "of 2 as it should be -> rounding from %d to %d (n=%d)\n", hash_size, 1<<(n-1), n); hash_size = 1<<(n-1); break; } } /* check 'workers' param */ if (num_workers < 1) { LM_ERR("the 'workers' parameter must be >= 1\n"); return -1; } tls_verify_host = tls_verify_host?1:0; tls_verify_peer = tls_verify_peer?1:0; /* init http parameters list */ init_query_params(&ah_params); if (strncmp("shm", memory_manager, 3) == 0) { curl_memory_manager = 0; } else if (strncmp("sys", memory_manager, 3) == 0) { curl_memory_manager = 1; } else { LM_ERR("invalid memory_manager parameter: '%s'\n", memory_manager); return -1; } if (strncmp("shm", memory_manager, 3) == 0) { curl_memory_manager = 0; } else if (strncmp("sys", memory_manager, 3) == 0) { curl_memory_manager = 1; } else { LM_ERR("invalid memory_manager parameter: '%s'\n", memory_manager); return -1; } /* init faked sip msg */ if(faked_msg_init()<0) { LM_ERR("failed to init faked sip msg\n"); return -1; } if(load_tm_api( &tmb ) < 0) { LM_INFO("cannot load the TM-functions - async relay disabled\n"); memset(&tmb, 0, sizeof(tm_api_t)); } /* allocate workers array */ workers = shm_malloc(num_workers * sizeof(*workers)); if(workers == NULL) { LM_ERR("error in shm_malloc\n"); return -1; } memset(workers, 0, num_workers * sizeof(*workers)); register_procs(num_workers); /* add child to update local config framework structures */ cfg_register_child(num_workers); return 0; }
/** * init module function */ static int mod_init(void) { load_tm_f load_tm; #ifdef HAVE_IHTTP load_ih_f load_ih; #endif int i; DBG("XJAB:mod_init: initializing ...\n"); if(!jdomain) { LOG(L_ERR, "XJAB:mod_init: ERROR jdomain is NULL\n"); return -1; } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR: xjab:mod_init: can't import load_tm\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_tm( &tmb )==-1) return -1; #ifdef HAVE_IHTTP /* import the iHTTP auto-loading function */ if ( !(load_ih=(load_ih_f)find_export("load_ih", IH_NO_SCRIPT_F, 0))) { LOG(L_ERR, "ERROR:xjab:mod_init: can't import load_ih\n"); return -1; } /* let the auto-loading function load all TM stuff */ if (load_ih( &ihb )==-1) return -1; #endif pipes = (int**)pkg_malloc(nrw*sizeof(int*)); if (pipes == NULL) { LOG(L_ERR, "XJAB:mod_init:Error while allocating pipes\n"); return -1; } for(i=0; i<nrw; i++) { pipes[i] = (int*)pkg_malloc(2*sizeof(int)); if (!pipes[i]) { LOG(L_ERR, "XJAB:mod_init: Error while allocating pipes\n"); return -1; } } /** creating the pipes */ for(i=0;i<nrw;i++) { /* create the pipe*/ if (pipe(pipes[i])==-1) { LOG(L_ERR, "XJAB:mod_init: error - cannot create pipe!\n"); return -1; } DBG("XJAB:mod_init: pipe[%d] = <%d>-<%d>\n", i, pipes[i][0], pipes[i][1]); } if((jwl = xj_wlist_init(pipes,nrw,max_jobs,cache_time,sleep_time, delay_time)) == NULL) { LOG(L_ERR, "XJAB:mod_init: error initializing workers list\n"); return -1; } if(xj_wlist_set_aliases(jwl, jaliases, jdomain, proxy) < 0) { LOG(L_ERR, "XJAB:mod_init: error setting aliases and outbound proxy\n"); return -1; } /* register nrw + 1 number of children that will keep * updating their local configuration */ cfg_register_child(nrw + 1); DBG("XJAB:mod_init: initialized ...\n"); return 0; }
int jsonrpc_dgram_mod_init(void) { unsigned int port_no; int n; struct stat filestat; struct hostent *host; char *p, *host_s; str port_str; int len; int sep; /* checking the mi_socket module param */ LM_DBG("testing socket existance...\n"); if( jsonrpc_dgram_socket==NULL || *jsonrpc_dgram_socket == 0) { LM_ERR("no DATAGRAM_ socket configured\n"); return -1; } LM_DBG("the socket's name/address is %s\n", jsonrpc_dgram_socket); memset( &jsonrpc_dgram_addr, 0, sizeof(jsonrpc_dgram_sockaddr_t) ); if(strlen(jsonrpc_dgram_socket)<6) { LM_ERR("lenght of socket address is too short: %s\n", jsonrpc_dgram_socket); return -1; } if(strncmp(jsonrpc_dgram_socket, "udp:", 4) == 0) { /*for an UDP socket*/ LM_DBG("udp socket provided\n"); /*separate proto and host */ p = jsonrpc_dgram_socket+4; if( (*(p)) == '\0') { LM_ERR("malformed ip address\n"); return -1; } host_s=p; LM_DBG("remaining address after separating the protocol is %s\n", p); if( (p = strrchr(p+1, ':')) == 0 ) { LM_ERR("no port specified\n"); return -1; } /*the address contains a port number*/ *p = '\0'; p++; port_str.s = p; port_str.len = strlen(p); LM_DBG("the port string is %s\n", p); if(str2int(&port_str, &port_no) != 0 ) { LM_ERR("there is not a valid number port\n"); return -1; } *p = '\0'; if (port_no<1024 || port_no>65535) { LM_ERR("invalid port number; must be in [1024,65535]\n"); return -1; } if(! (host = resolvehost(host_s)) ) { LM_ERR("failed to resolve %s\n", host_s); return -1; } LM_DBG("the ip is %s\n",host_s); if(hostent2su( &(jsonrpc_dgram_addr.udp_addr), host, 0, port_no ) !=0) { LM_ERR("failed to resolve %s\n", jsonrpc_dgram_socket); return -1; } jsonrpc_dgram_socket_domain = host->h_addrtype; goto done; } /* in case of a Unix socket*/ LM_DBG("UNIX socket provided\n"); if(*jsonrpc_dgram_socket != '/') { if(runtime_dir!=NULL && *runtime_dir!=0) { len = strlen(runtime_dir); sep = 0; if(runtime_dir[len-1]!='/') { sep = 1; } len += sep + strlen(jsonrpc_dgram_socket); p = pkg_malloc(len + 1); if(p==NULL) { LM_ERR("no more pkg\n"); return -1; } strcpy(p, runtime_dir); if(sep) strcat(p, "/"); strcat(p, jsonrpc_dgram_socket); jsonrpc_dgram_socket = p; LM_DBG("unix socket path is [%s]\n", jsonrpc_dgram_socket); } } n=stat(jsonrpc_dgram_socket, &filestat); if( n==0) { LM_INFO("the socket %s already exists, trying to delete it...\n", jsonrpc_dgram_socket); if(config_check==0) { if (unlink(jsonrpc_dgram_socket)<0) { LM_ERR("cannot delete old socket: %s\n", strerror(errno)); return -1; } } } else if (n<0 && errno!=ENOENT) { LM_ERR("socket stat failed:%s\n", strerror(errno)); return -1; } /* check mi_unix_socket_mode */ if(!jsonrpc_dgram_unix_socket_mode) { LM_WARN("cannot specify jsonrpc_dgram_unix_socket_mode = 0," " forcing it to rw-------\n"); jsonrpc_dgram_unix_socket_mode = S_IRUSR| S_IWUSR; } if (jsonrpc_dgram_unix_socket_uid_s) { if (user2uid(&jsonrpc_dgram_unix_socket_uid, &jsonrpc_dgram_unix_socket_gid, jsonrpc_dgram_unix_socket_uid_s)<0) { LM_ERR("bad user name %s\n", jsonrpc_dgram_unix_socket_uid_s); return -1; } } if (jsonrpc_dgram_unix_socket_gid_s) { if (group2gid(&jsonrpc_dgram_unix_socket_gid, jsonrpc_dgram_unix_socket_gid_s)<0) { LM_ERR("bad group name %s\n", jsonrpc_dgram_unix_socket_gid_s); return -1; } } /*create the unix socket address*/ jsonrpc_dgram_addr.unix_addr.sun_family = AF_LOCAL; if(strlen(jsonrpc_dgram_socket) >= sizeof(jsonrpc_dgram_addr.unix_addr.sun_path)-1) { LM_ERR("socket path is too long\n"); return -1; } memcpy(jsonrpc_dgram_addr.unix_addr.sun_path, jsonrpc_dgram_socket, strlen(jsonrpc_dgram_socket)); done: /* add space for extra processes */ register_procs(jsonrpc_dgram_workers); /* add child to update local config framework structures */ cfg_register_child(jsonrpc_dgram_workers); return 0; }
static int mod_init(void) { struct id_list* l; char ctl_socket_path[CTL_SOCKET_PATH_SIZE]; binrpc_callbacks_init(); if(binrpc_max_body_size<=0) binrpc_max_body_size = 4; if(binrpc_struct_max_body_size<=0) binrpc_struct_max_body_size = 1; binrpc_max_body_size *= 1024; binrpc_struct_max_body_size *= 1024; if (listen_lst==0) { if(strcmp(runtime_dir, RUN_DIR)==0) { add_binrpc_socket(PARAM_STRING, DEFAULT_CTL_SOCKET); } else { if(sizeof(DEFAULT_CTL_SOCKET_PROTO) + sizeof(DEFAULT_CTL_SOCKET_NAME) + strlen(runtime_dir) + 4 > CTL_SOCKET_PATH_SIZE) { LM_ERR("ctl socket path is too big\n"); return -1; } strcpy(ctl_socket_path, DEFAULT_CTL_SOCKET_PROTO); strcat(ctl_socket_path, runtime_dir); strcat(ctl_socket_path, "/"); strcat(ctl_socket_path, DEFAULT_CTL_SOCKET_NAME); add_binrpc_socket(PARAM_STRING, ctl_socket_path); } } DBG("listening on:\n"); for (l=listen_lst; l; l=l->next){ fd_no++; switch(l->proto){ case UNIXD_SOCK: DBG(" [%s:unix dgram] %s\n", payload_proto_name(l->data_proto), l->name); break; case UNIXS_SOCK: DBG(" [%s:unix stream] %s\n", payload_proto_name(l->data_proto), l->name); break; case UDP_SOCK: DBG(" [%s:udp] %s:%d\n", payload_proto_name(l->data_proto), l->name, l->port?l->port:DEFAULT_CTL_PORT); break; case TCP_SOCK: DBG(" [%s:tcp] %s:%d\n", payload_proto_name(l->data_proto), l->name, l->port?l->port:DEFAULT_CTL_PORT); break; #ifdef USE_FIFO case FIFO_SOCK: DBG(" [%s:fifo] %s\n", payload_proto_name(l->data_proto), l->name); fd_no++; /* fifos use 2 fds */ break; #endif default: LOG(L_CRIT, "BUG: ctrl: listen protocol %d not supported\n", l->proto); goto error; } } /* get the uid/gid from core if not set for the module */ if(usock_uid==-1 && sock_uid!=-1) usock_uid = sock_uid; if(usock_gid==-1 && sock_gid!=-1) usock_gid = sock_gid; /* open socket now, before suid */ if (init_ctrl_sockets(&ctrl_sock_lst, listen_lst, DEFAULT_CTL_PORT, usock_mode, usock_uid, usock_gid)<0){ LOG(L_ERR, "ERROR: ctl: mod_init: init ctrl. sockets failed\n"); goto error; } if (ctrl_sock_lst){ /* we will fork */ register_procs(1); /* we will be creating an extra process */ register_fds(fd_no); /* The child process will keep updating its local configuration */ cfg_register_child(1); } #ifdef USE_FIFO fifo_rpc_init(); #endif return 0; error: return -1; }
static int mi_mod_init(void) { unsigned int port_no; int n; struct stat filestat; struct hostent * host; char *p, *host_s; str port_str; /* checking the mi_socket module param */ LM_DBG("testing socket existance...\n"); if( mi_socket==NULL || *mi_socket == 0) { LM_ERR("no DATAGRAM_ socket configured\n"); return -1; } LM_DBG("the socket's name/address is %s\n", mi_socket); memset( &mi_dtgram_addr, 0, sizeof(mi_dtgram_addr) ); if(strncmp(mi_socket, "udp:",4) == 0) { /*for an UDP socket*/ LM_DBG("we have an udp socket\n"); /*separate proto and host */ p = mi_socket+4; if( (*(p)) == '\0') { LM_ERR("malformed ip address\n"); return -1; } host_s=p; LM_DBG("the remaining address after separating the protocol is %s\n",p); if( (p = strrchr(p+1, ':')) == 0 ) { LM_ERR("no port specified\n"); return -1; } /*the address contains a port number*/ *p = '\0'; p++; port_str.s = p; port_str.len = strlen(p); LM_DBG("the port string is %s\n", p); if(str2int(&port_str, &port_no) != 0 ) { LM_ERR("there is not a valid number port\n"); return -1; } *p = '\0'; if (port_no<1024 || port_no>MAX_NB_PORT) { LM_ERR("invalid port number; must be in [1024,%d]\n",MAX_NB_PORT); return -1; } if(! (host = resolvehost(host_s)) ) { LM_ERR("failed to resolve %s\n", host_s); return -1; } LM_DBG("the ip is %s\n",host_s); if(hostent2su( &(mi_dtgram_addr.udp_addr), host, 0, port_no ) !=0){ LM_ERR("failed to resolve %s\n", mi_socket); return -1; } mi_socket_domain = host->h_addrtype; goto done; } /* in case of a Unix socket*/ LM_DBG("we have an UNIX socket\n"); n=stat(mi_socket, &filestat); if( n==0) { LM_INFO("the socket %s already exists, trying to delete it...\n", mi_socket); if(config_check==0) { if (unlink(mi_socket)<0) { LM_ERR("cannot delete old socket: %s\n", strerror(errno)); return -1; } } } else if (n<0 && errno!=ENOENT) { LM_ERR("socket stat failed:%s\n", strerror(errno)); return -1; } /* check mi_unix_socket_mode */ if(!mi_unix_socket_mode) { LM_WARN("cannot specify mi_unix_socket_mode = 0, forcing it to rw-------\n"); mi_unix_socket_mode = S_IRUSR| S_IWUSR; } if (mi_unix_socket_uid_s) { if (user2uid(&mi_unix_socket_uid, &mi_unix_socket_gid, mi_unix_socket_uid_s)<0) { LM_ERR("bad user name %s\n", mi_unix_socket_uid_s); return -1; } } if (mi_unix_socket_gid_s) { if (group2gid(&mi_unix_socket_gid, mi_unix_socket_gid_s)<0) { LM_ERR("bad group name %s\n", mi_unix_socket_gid_s); return -1; } } /*create the unix socket address*/ mi_dtgram_addr.unix_addr.sun_family = AF_LOCAL; memcpy( mi_dtgram_addr.unix_addr.sun_path, mi_socket, strlen(mi_socket)); done: /* add space for extra processes */ register_procs(mi_procs[0].no); /* add child to update local config framework structures */ cfg_register_child(mi_procs[0].no); return 0; }
static int mod_init(void) { pv_spec_t avp_spec; if (restore_mode_str && *restore_mode_str) { if (strcasecmp(restore_mode_str,"none")==0) { restore_mode = UAC_NO_RESTORE; } else if (strcasecmp(restore_mode_str,"manual")==0) { restore_mode = UAC_MANUAL_RESTORE; } else if (strcasecmp(restore_mode_str,"auto")==0) { restore_mode = UAC_AUTO_RESTORE; } else { LM_ERR("unsupported value '%s' for restore_mode\n", restore_mode_str); goto error; } } if ( (rr_from_param.len==0 || rr_to_param.len==0) && restore_mode!=UAC_NO_RESTORE) { LM_ERR("rr_store_param cannot be empty if FROM is restoreable\n"); goto error; } /* parse the auth AVP spesc, if any */ if ( auth_username_avp || auth_password_avp || auth_realm_avp) { if (!auth_username_avp || !auth_password_avp || !auth_realm_avp) { LM_ERR("partial definition of auth AVP!"); goto error; } if ( parse_auth_avp(auth_realm_avp, &auth_realm_spec, "realm")<0 || parse_auth_avp(auth_username_avp, &auth_username_spec, "username")<0 || parse_auth_avp(auth_password_avp, &auth_password_spec, "password")<0 ) { goto error; } } else { memset( &auth_realm_spec, 0, sizeof(pv_spec_t)); memset( &auth_password_spec, 0, sizeof(pv_spec_t)); memset( &auth_username_spec, 0, sizeof(pv_spec_t)); } /* load the TM API - FIXME it should be loaded only * if NO_RESTORE and AUTH */ if (load_tm_api(&uac_tmb)!=0) { LM_ERR("can't load TM API\n"); goto error; } if (restore_mode!=UAC_NO_RESTORE) { /* load the RR API */ if (load_rr_api(&uac_rrb)!=0) { LM_ERR("can't load RR API\n"); goto error; } if(restore_from_avp.s) { if (pv_parse_spec(&restore_from_avp, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", restore_from_avp.len, restore_from_avp.s); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &restore_from_avp_name, &restore_from_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", restore_from_avp.len, restore_from_avp.s); return -1; } restore_from_avp_type |= AVP_VAL_STR; } if(restore_to_avp.s) { if (pv_parse_spec(&restore_to_avp, &avp_spec)==0 || avp_spec.type!=PVT_AVP) { LM_ERR("malformed or non AVP %.*s AVP definition\n", restore_to_avp.len, restore_to_avp.s); return -1; } if(pv_get_avp_name(0, &avp_spec.pvp, &restore_to_avp_name, &restore_to_avp_type)!=0) { LM_ERR("[%.*s]- invalid AVP definition\n", restore_to_avp.len, restore_to_avp.s); return -1; } restore_to_avp_type |= AVP_VAL_STR; } if (restore_mode==UAC_AUTO_RESTORE) { /* we need the append_fromtag on in RR */ memset(&dlg_api, 0, sizeof(struct dlg_binds)); if (uac_restore_dlg==0 || load_dlg_api(&dlg_api)!=0) { if (!uac_rrb.append_fromtag) { LM_ERR("'append_fromtag' RR param is not enabled!" " - required by AUTO restore mode\n"); goto error; } if (uac_restore_dlg!=0) LM_DBG("failed to find dialog API - is dialog module loaded?\n"); } /* get all requests doing loose route */ if (uac_rrb.register_rrcb( rr_checker, 0)!=0) { LM_ERR("failed to install RR callback\n"); goto error; } } } if(reg_db_url.s && reg_db_url.len>=0) { if(!reg_contact_addr.s || reg_contact_addr.len<=0) { LM_ERR("contact address parameter not set\n"); goto error; } if(reg_htable_size>14) reg_htable_size = 14; if(reg_htable_size<2) reg_htable_size = 2; reg_htable_size = 1<<reg_htable_size; if(uac_reg_init_rpc()!=0) { LM_ERR("failed to register RPC commands\n"); goto error; } if(uac_reg_init_ht(reg_htable_size)<0) { LM_ERR("failed to init reg htable\n"); goto error; } register_procs(1); /* add child to update local config framework structures */ cfg_register_child(1); } init_from_replacer(); uac_req_init(); return 0; error: return -1; }
static int mod_init(void) { int i; startup_time = (int) time(NULL); kz_json_escape_char = kz_json_escape_str.s[0]; if (dbk_node_hostname.s == NULL) { LM_ERR("You must set the node_hostname parameter\n"); return -1; } dbk_node_hostname.len = strlen(dbk_node_hostname.s); dbk_consumer_event_key.len = strlen(dbk_consumer_event_key.s); dbk_consumer_event_subkey.len = strlen(dbk_consumer_event_subkey.s); if(kz_init_avp()) { LM_ERR("Error in avp params\n"); return -1; } if(!kz_amqp_init()) { return -1; } if(kz_timer_ms > 0) { kz_timer_tv.tv_usec = (kz_timer_ms % 1000) * 1000; kz_timer_tv.tv_sec = kz_timer_ms / 1000; } if(dbk_pua_mode == 1) { kz_db_url.len = kz_db_url.s ? strlen(kz_db_url.s) : 0; LM_DBG("db_url=%s/%d/%p\n", ZSW(kz_db_url.s), kz_db_url.len,kz_db_url.s); kz_presentity_table.len = strlen(kz_presentity_table.s); if(kz_db_url.len > 0) { /* binding to database module */ if (db_bind_mod(&kz_db_url, &kz_pa_dbf)) { LM_ERR("Database module not found\n"); return -1; } if (!DB_CAPABILITY(kz_pa_dbf, DB_CAP_ALL)) { LM_ERR("Database module does not implement all functions" " needed by kazoo module\n"); return -1; } kz_pa_db = kz_pa_dbf.init(&kz_db_url); if (!kz_pa_db) { LM_ERR("Connection to database failed\n"); return -1; } kz_pa_dbf.close(kz_pa_db); kz_pa_db = NULL; } } int total_workers = dbk_consumer_workers + (dbk_consumer_processes * kz_server_counter) + 2; register_procs(total_workers); cfg_register_child(total_workers); if (pipe(kz_cmd_pipe_fds) < 0) { LM_ERR("cmd pipe() failed\n"); return -1; } kz_worker_pipes_fds = (int*) shm_malloc(sizeof(int) * (dbk_consumer_workers) * 2 ); kz_worker_pipes = (int*) shm_malloc(sizeof(int) * dbk_consumer_workers); for(i=0; i < dbk_consumer_workers; i++) { kz_worker_pipes_fds[i*2] = kz_worker_pipes_fds[i*2+1] = -1; if (pipe(&kz_worker_pipes_fds[i*2]) < 0) { LM_ERR("worker pipe(%d) failed\n", i); return -1; } } kz_cmd_pipe = kz_cmd_pipe_fds[1]; for(i=0; i < dbk_consumer_workers; i++) { kz_worker_pipes[i] = kz_worker_pipes_fds[i*2+1]; } return 0; }
static int cpl_init(void) { bind_usrloc_t bind_usrloc; load_tm_f load_tm; struct stat stat_t; char *ptr; int val; str foo; LOG(L_INFO,"CPL - initializing\n"); /* check the module params */ if (DB_URL==0) { LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_db\" " "found empty\n"); goto error; } if (DB_TABLE==0) { LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_table\" " "found empty\n"); goto error; } if (cpl_env.proxy_recurse>MAX_PROXY_RECURSE) { LOG(L_CRIT,"ERROR:cpl_init: value of proxy_recurse param (%d) exceeds " "the maximum safety value (%d)\n", cpl_env.proxy_recurse,MAX_PROXY_RECURSE); goto error; } /* fix the timer_avp name */ if (timer_avp) { foo.s = timer_avp; foo.len = strlen(foo.s); if (parse_avp_spec(&foo,&cpl_env.timer_avp_type,&cpl_env.timer_avp,0)<0){ LOG(L_CRIT,"ERROR:cpl_init: invalid timer AVP specs \"%s\"\n", timer_avp); goto error; } if (cpl_env.timer_avp_type&AVP_NAME_STR && cpl_env.timer_avp.s.s==foo.s) { cpl_env.timer_avp.s = foo; } } if (dtd_file==0) { LOG(L_CRIT,"ERROR:cpl_init: mandatory parameter \"cpl_dtd_file\" " "found empty\n"); goto error; } else { /* check if the dtd file exists */ if (stat( dtd_file, &stat_t)==-1) { LOG(L_ERR,"ERROR:cpl_init: checking file \"%s\" status failed;" " stat returned %s\n",dtd_file,strerror(errno)); goto error; } if ( !S_ISREG( stat_t.st_mode ) ) { LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" is not a regular file!\n", dtd_file); goto error; } if (access( dtd_file, R_OK )==-1) { LOG(L_ERR,"ERROR:cpl_init: checking file \"%s\" for permissions " "failed; access returned %s\n",dtd_file,strerror(errno)); goto error; } } if (cpl_env.log_dir==0) { LOG(L_INFO,"INFO:cpl_init: log_dir param found void -> logging " " disabled!\n"); } else { if ( strlen(cpl_env.log_dir)>MAX_LOG_DIR_SIZE ) { LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" has a too long name :-(!\n", cpl_env.log_dir); goto error; } /* check if the dir exists */ if (stat( cpl_env.log_dir, &stat_t)==-1) { LOG(L_ERR,"ERROR:cpl_init: checking dir \"%s\" status failed;" " stat returned %s\n",cpl_env.log_dir,strerror(errno)); goto error; } if ( !S_ISDIR( stat_t.st_mode ) ) { LOG(L_ERR,"ERROR:cpl_init: dir \"%s\" is not a directory!\n", cpl_env.log_dir); goto error; } if (access( cpl_env.log_dir, R_OK|W_OK )==-1) { LOG(L_ERR,"ERROR:cpl_init: checking dir \"%s\" for permissions " "failed; access returned %s\n", cpl_env.log_dir, strerror(errno)); goto error; } } /* import the TM auto-loading function */ if ( !(load_tm=(load_tm_f)find_export("load_tm", NO_SCRIPT, 0))) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: cannot import load_tm\n"); goto error; } /* let the auto-loading function load all TM stuff */ if (load_tm( &(cpl_fct.tmb) )==-1) goto error; /* bind the SL API */ if (sl_load_api(&cpl_fct.slb)!=0) { LM_ERR("cannot bind to SL API\n"); return -1; } /* bind to usrloc module if requested */ if (lookup_domain) { /* import all usrloc functions */ bind_usrloc = (bind_usrloc_t)find_export("ul_bind_usrloc", 1, 0); if (!bind_usrloc) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: Can't bind usrloc\n"); goto error; } if (bind_usrloc( &(cpl_fct.ulb) ) < 0) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: importing usrloc failed\n"); goto error; } /* convert lookup_domain from char* to udomain_t* pointer */ if (cpl_fct.ulb.register_udomain( lookup_domain, &cpl_env.lu_domain) < 0) { LOG(L_ERR, "ERROR:cpl_c:cpl_init: Error while registering domain " "<%s>\n",lookup_domain); goto error; } } else { LOG(L_NOTICE,"NOTICE:cpl_init: no lookup_domain given -> disable " " lookup node\n"); } /* build a pipe for sending commands to aux process */ if ( pipe( cpl_env.cmd_pipe )==-1 ) { LOG(L_CRIT,"ERROR:cpl_init: cannot create command pipe: %s!\n", strerror(errno) ); goto error; } /* set the writing non blocking */ if ( (val=fcntl(cpl_env.cmd_pipe[1], F_GETFL, 0))<0 ) { LOG(L_ERR,"ERROR:cpl_init: getting flags from pipe[1] failed: fcntl " "said %s!\n",strerror(errno)); goto error; } if ( fcntl(cpl_env.cmd_pipe[1], F_SETFL, val|O_NONBLOCK) ) { LOG(L_ERR,"ERROR:cpl_init: setting flags to pipe[1] failed: fcntl " "said %s!\n",strerror(errno)); goto error; } /* init the CPL parser */ if (init_CPL_parser( dtd_file )!=1 ) { LOG(L_ERR,"ERROR:cpl_init: init_CPL_parser failed!\n"); goto error; } /* make a copy of the original TZ env. variable */ ptr = getenv("TZ"); cpl_env.orig_tz.len = 3/*"TZ="*/ + (ptr?(strlen(ptr)+1):0); if ( (cpl_env.orig_tz.s=shm_malloc( cpl_env.orig_tz.len ))==0 ) { LOG(L_ERR,"ERROR:cpl_init: no more shm mem. for saving TZ!\n"); goto error; } memcpy(cpl_env.orig_tz.s,"TZ=",3); if (ptr) strcpy(cpl_env.orig_tz.s+3,ptr); /* convert realm_prefix from string null terminated to str */ if (cpl_env.realm_prefix.s) { /* convert the realm_prefix to lower cases */ strlower( &cpl_env.realm_prefix ); } /* Register a child process that will keep updating * its local configuration */ cfg_register_child(1); return 0; error: return -1; }