int AnswerMachineFactory::onLoad() { AmConfigReader cfg; if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1, MOD_NAME ".conf"))) return -1; // get application specific global parameters configureModule(cfg); AnnouncePath = cfg.getParameter("announce_path",ANNOUNCE_PATH); DefaultAnnounce = cfg.getParameter("default_announce",DEFAULT_ANNOUNCE); MaxRecordTime = cfg.getParameterInt("max_record_time",DEFAULT_RECORD_TIME); RecFileExt = cfg.getParameter("rec_file_ext",DEFAULT_AUDIO_EXT); if(loadEmailTemplates(cfg.getParameter("email_template_path",DEFAULT_MAIL_TMPL_PATH))){ ERROR("while loading email templates\n"); return -1; } AcceptDelay = DEFAULT_ACCEPT_DELAY; UserTimer = AmPlugIn::instance()->getFactory4Di("user_timer"); if(!UserTimer){ ERROR("could not load user_timer from session_timer plug-in\n"); return -1; } return 0; }
int JsonRPCServerModule::load() { AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) { INFO("no '%s' configuration file present. using default values\n", (AmConfig::ModConfigPath + string(MOD_NAME ".conf")).c_str()); } else { port = cfg.getParameterInt("jsonrpc_port", DEFAULT_JSONRPC_SERVER_PORT); threads = cfg.getParameterInt("server_threads", DEFAULT_JSONRPC_SERVER_THREADS); } DBG("using server port %d\n", port); DBG("using %d server threads\n", threads); DBG("starting server loop thread\n"); server_loop = new JsonRPCServerLoop(); server_loop->start(); return 0; }
int XMLRPC2DI::load() { if (configured) // load only once return 0; configured = true; AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) return -1; ServerRetryAfter = cfg.getParameterInt("server_retry_after", 10); DBG("retrying failed server after %u seconds\n", ServerRetryAfter); string run_server = cfg.getParameter("run_server","yes"); if (run_server != "yes") { DBG("XMLRPC server will not be started.\n"); return 0; } string conf_xmlrpc_port = cfg.getParameter("xmlrpc_port",XMLRPC_PORT); if (conf_xmlrpc_port.empty()) { ERROR("configuration: xmlrpc_port must be defined!\n"); return -1; } if (str2i(conf_xmlrpc_port, XMLRPCPort)) { ERROR("configuration: unable to decode xmlrpc_port value '%s'!\n", conf_xmlrpc_port.c_str()); return -1; } bool export_di = false; string direct_export = cfg.getParameter("direct_export",""); if (direct_export.length()) { DBG("direct_export interfaces: %s\n", direct_export.c_str()); } else { DBG("No direct_export interfaces.\n"); } string export_di_s = cfg.getParameter("export_di","yes"); if (export_di_s == "yes") { export_di = true; } DBG("XMLRPC Server: %snabling builtin method 'di'.\n", export_di?"E":"Not e"); server = new XMLRPC2DIServer(XMLRPCPort, export_di, direct_export); server->start(); return 0; }
int CallTimerFactory::onLoad() { AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) { DBG("using default timer of %d seconds\n", DEFAULT_CALL_TIMER); DefaultCallTimer = DEFAULT_CALL_TIMER; } else { DefaultCallTimer = cfg.getParameterInt("default_call_time", DEFAULT_CALL_TIMER); UseAppParam = (cfg.getParameter("use_app_param") == "yes"); } user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer"); if(!user_timer_fact) { ERROR("could not load user_timer from session_timer plug-in\n"); return -1; } return 0; }
int CallBackFactory::onLoad() { AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME)+ ".conf")) return -1; // get application specific global parameters configureModule(cfg); // get prompts AM_PROMPT_START; AM_PROMPT_ADD(WELCOME_PROMPT, WELCOME_PROMPT ".wav"); AM_PROMPT_END(prompts, cfg, MOD_NAME); string DigitsDir = cfg.getParameter("digits_dir"); if (DigitsDir.length() && DigitsDir[DigitsDir.length()-1]!='/') DigitsDir+='/'; if (!DigitsDir.length()) { ERROR("No digits_dir specified in configuration.\n"); } for (int i=0;i<10;i++) prompts.setPrompt(int2str(i), DigitsDir+int2str(i)+".wav", MOD_NAME); string playout_type = cfg.getParameter("playout_type"); if (playout_type == "simple") { m_PlayoutType = SIMPLE_PLAYOUT; DBG("Using simple (fifo) buffer as playout technique.\n"); } else if (playout_type == "adaptive_jb") { m_PlayoutType = JB_PLAYOUT; DBG("Using adaptive jitter buffer as playout technique.\n"); } else { DBG("Using adaptive playout buffer as playout technique.\n"); } string accept_caller_re_str = cfg.getParameter(ACCEPT_CALLER_RE); if (!accept_caller_re_str.length()) { ERROR("no '" ACCEPT_CALLER_RE "' set.\n"); return -1; } else { if (regcomp(&accept_caller_re, accept_caller_re_str.c_str(), REG_EXTENDED|REG_NOSUB)) { ERROR("unable to compile caller RE '%s'.\n", accept_caller_re_str.c_str()); return -1; } } gw_user = cfg.getParameter("gw_user"); if (!gw_user.length()) { ERROR("need gw_user configured!\n"); return -1; } gw_domain = cfg.getParameter("gw_domain"); if (!gw_domain.length()) { ERROR("need gw_domain configured!\n"); return -1; } auth_user = cfg.getParameter("auth_user"); if (!auth_user.length()) auth_user = gw_user; // default to user auth_pwd = cfg.getParameter("auth_pwd"); if (!auth_pwd.length()) { ERROR("need auth_pwd configured!\n"); return -1; } cb_wait = cfg.getParameterInt("cb_wait", 5); DBG("cb_wait set to %d\n", cb_wait); DBG("starting callback thread. (%ld)\n", (long)this); start(); return 0; }
int WebConferenceFactory::onLoad() { // only execute this once if (configured) return 0; configured = true; AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(APP_NAME)+ ".conf")) return -1; // get application specific global parameters configureModule(cfg); // get prompts AM_PROMPT_START; AM_PROMPT_ADD(FIRST_PARTICIPANT, WEBCONF_ANNOUNCE_PATH "first_paricipant.wav"); AM_PROMPT_ADD(JOIN_SOUND, WEBCONF_ANNOUNCE_PATH "beep.wav"); AM_PROMPT_ADD(DROP_SOUND, WEBCONF_ANNOUNCE_PATH "beep.wav"); AM_PROMPT_ADD(ENTER_PIN, WEBCONF_ANNOUNCE_PATH "enter_pin.wav"); AM_PROMPT_ADD(WRONG_PIN, WEBCONF_ANNOUNCE_PATH "wrong_pin.wav"); AM_PROMPT_ADD(ENTERING_CONFERENCE, WEBCONF_ANNOUNCE_PATH "entering_conference.wav"); AM_PROMPT_END(prompts, cfg, APP_NAME); DigitsDir = cfg.getParameter("digits_dir"); if (DigitsDir.length() && DigitsDir[DigitsDir.length()-1]!='/') DigitsDir+='/'; if (!DigitsDir.length()) { WARN("No digits_dir specified in configuration.\n"); } for (int i=0;i<10;i++) prompts.setPrompt(int2str(i), DigitsDir+int2str(i)+".wav", APP_NAME); string playout_type = cfg.getParameter("playout_type"); if (playout_type == "simple") { m_PlayoutType = SIMPLE_PLAYOUT; DBG("Using simple (fifo) buffer as playout technique.\n"); } else if (playout_type == "adaptive_jb") { m_PlayoutType = JB_PLAYOUT; DBG("Using adaptive jitter buffer as playout technique.\n"); } else { DBG("Using adaptive playout buffer as playout technique.\n"); } string direct_room_re_str = cfg.getParameter("direct_room_re"); if (!direct_room_re_str.length()) { DBG("no direct room access prefixes set.\n"); } else { if (regcomp(&direct_room_re, direct_room_re_str.c_str(), REG_EXTENDED|REG_NOSUB)) { ERROR("unable to compile direct room RE '%s'.\n", direct_room_re_str.c_str()); return -1; } use_direct_room = true; string direct_room_strip_str = cfg.getParameter("direct_room_strip"); if (direct_room_strip_str.length() && str2i(direct_room_strip_str, direct_room_strip)) { ERROR("unable to decipher direct_room_strip amount '%s'\n", direct_room_strip_str.c_str()); return -1; } DBG("Webconference will strip %d leading characters from " "direct room access usernames\n", direct_room_strip); } string feedback_filename = cfg.getParameter("feedback_file"); if (!feedback_filename.empty()) { feedback_file.open(feedback_filename.c_str(), std::ios::out|std::ios::app); if (!feedback_file.good()) { ERROR("opening feedback file '%s'\n", feedback_filename.c_str()); } else { DBG("successfully opened feedback file '%s'\n", feedback_filename.c_str()); } } string stats_dir = cfg.getParameter("stats_dir"); if (stats_dir.empty()) DBG("call statistics will not be persistent across restart.\n"); stats = new WCCCallStats(stats_dir); urlbase = cfg.getParameter("webconference_urlbase"); if (urlbase.empty()) DBG("No urlbase set - SDP will not contain direct access URL.\n"); MasterPassword = cfg.getParameter("master_password"); if (!MasterPassword.empty()) { DBG("Master password set.\n"); } if (cfg.getParameter("participants_expire") == "no") { ParticipantExpiredDelay = -1; } else { // default: 10s ParticipantExpiredDelay = cfg.getParameterInt("participants_expire_delay", 10); } if (cfg.getParameter("rooms_expire") == "no") { RoomExpiredDelay = -1; } else { RoomExpiredDelay = cfg.getParameterInt("rooms_expire_delay", 7200); // default: 2h } // default: every 10 times RoomSweepInterval = cfg.getParameterInt("room_sweep_interval", 10); return 0; }
int StatsUDPServer::init() { string udp_addr; int udp_port = 0; int optval; AmConfigReader cfg; if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1, MOD_NAME ".conf"))) return -1; udp_port = (int)cfg.getParameterInt("monit_udp_port",(unsigned int)-1); if(udp_port == -1){ ERROR("invalid port number in the monit_udp_port parameter\n "); return -1; } if(!udp_port) udp_port = DEFAULT_MONIT_UDP_PORT; DBG("udp_port = %i\n",udp_port); udp_addr = cfg.getParameter("monit_udp_ip",""); sd = socket(PF_INET,SOCK_DGRAM,0); if(sd == -1){ ERROR("could not open socket: %s\n",strerror(errno)); return -1; } /* set sock opts? */ optval=1; if (setsockopt(sd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval, sizeof(optval)) ==-1){ ERROR("ERROR: setsockopt(reuseaddr): %s\n", strerror(errno)); return -1; } /* tos */ optval=IPTOS_LOWDELAY; if (setsockopt(sd, IPPROTO_IP, IP_TOS, (void*)&optval, sizeof(optval)) ==-1){ ERROR("WARNING: setsockopt(tos): %s\n", strerror(errno)); /* continue since this is not critical */ } struct sockaddr_in sa; sa.sin_family = AF_INET; sa.sin_port = htons(udp_port); if(!inet_aton(udp_addr.c_str(),(in_addr*)&sa.sin_addr.s_addr)){ // non valid address ERROR("invalid IP in the monit_udp_ip parameter\n"); return -1; } //bool socket_bound = false; //while(!socket_bound){ if( bind(sd,(sockaddr*)&sa,sizeof(struct sockaddr_in)) == -1 ){ ERROR("could not bind socket at port %i: %s\n",udp_port,strerror(errno)); //udp_port += 1; //sa.sin_port = htons(udp_port); return -1; } else{ DBG("socket bound at port %i\n",udp_port); //socket_bound = true; } //} return 0; }
int AnswerMachineFactory::onLoad() { AmConfigReader cfg; if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1, MOD_NAME ".conf"))) return -1; // get application specific global parameters configureModule(cfg); // smtp_server SmtpServerAddress = cfg.getParameter("smtp_server",SmtpServerAddress); // smtp_port if(cfg.hasParameter("smtp_port")){ if(sscanf(cfg.getParameter("smtp_port").c_str(), "%u",&SmtpServerPort) != 1) { ERROR("invalid smtp_port specified\n"); return -1; } } DBG("SMTP server set to %s:%u\n", SmtpServerAddress.c_str(), SmtpServerPort); #ifdef USE_MYSQL /* Get email templates from MySQL */ string mysql_server, mysql_user, mysql_passwd, mysql_db; mysql_server = cfg.getParameter("mysql_server"); if (mysql_server.empty()) { mysql_server = "localhost"; } mysql_user = cfg.getParameter("mysql_user"); if (mysql_user.empty()) { ERROR("voicemail.conf paramater 'mysql_user' is missing.\n"); return -1; } mysql_passwd = cfg.getParameter("mysql_passwd"); if (mysql_passwd.empty()) { ERROR("voicemail.conf paramater 'mysql_passwd' is missing.\n"); return -1; } mysql_db = cfg.getParameter("mysql_db"); if (mysql_db.empty()) { mysql_db = "sems"; } try { Connection.connect(mysql_db.c_str(), mysql_server.c_str(), mysql_user.c_str(), mysql_passwd.c_str()); if (!Connection) { ERROR("Database connection failed: %s\n", Connection.error()); return -1; } Connection.set_option(mysqlpp::Connection::opt_reconnect, true); } catch (const mysqlpp::Exception& er) { // Catch-all for any MySQL++ exceptions ERROR("MySQL++ error: %s\n", er.what()); return -1; } if(loadEmailTemplatesFromMySQL()){ ERROR("while loading email templates from MySQL\n"); return -1; } #else /* Get email templates from file system */ if(loadEmailTemplates(cfg.getParameter("email_template_path", DEFAULT_MAIL_TMPL_PATH))){ ERROR("while loading email templates\n"); return -1; } AnnouncePath = cfg.getParameter("announce_path"); DefaultAnnounce = cfg.getParameter("default_announce"); #endif MaxRecordTime = cfg.getParameterInt("max_record_time",DEFAULT_RECORD_TIME); RecFileExt = cfg.getParameter("rec_file_ext",DEFAULT_AUDIO_EXT); UserTimer = AmPlugIn::instance()->getFactory4Di("user_timer"); if(!UserTimer){ ERROR("could not load user_timer from session_timer plug-in\n"); return -1; } MessageStorage = NULL; MessageStorage = AmPlugIn::instance()->getFactory4Di("msg_storage"); if(NULL == MessageStorage){ INFO("could not load msg_storage. Voice Box mode will not be available.\n"); } else { if ((msg_storage = MessageStorage->getInstance()) == NULL) { ERROR("getting msg_storage instance\n"); return -1; } } TryPersonalGreeting = cfg.getParameter("try_personal_greeting") == "yes"; DBG("voicemail will %stry to find a personal greeting.\n", TryPersonalGreeting?"":"not "); DBG("Starting SMTP daemon\n"); AmMailDeamon::instance()->start(); string s_save_empty_msg = cfg.getParameter("box_save_empty_msg"); if (!s_save_empty_msg.empty()) { SaveEmptyMsg = !(s_save_empty_msg == "no"); } DBG("Voicebox will%s save empty messages.\n", SaveEmptyMsg?"":" not"); return 0; }
static int readSIPInterface(AmConfigReader& cfg, const string& i_name) { int ret=0; AmConfig::SIP_interface intf; string suffix; if(!i_name.empty()) suffix = "_" + i_name; // listen, sip_ip, sip_port, and media_ip if(cfg.hasParameter("sip_ip" + suffix)) { intf.LocalIP = cfg.getParameter("sip_ip" + suffix); } else { // no sip_ip definition return 0; } if(cfg.hasParameter("sip_port" + suffix)){ string sip_port_str = cfg.getParameter("sip_port" + suffix); if(sscanf(sip_port_str.c_str(),"%u", &(intf.LocalPort)) != 1){ ERROR("sip_port%s: invalid sip port specified (%s)\n", suffix.c_str(), sip_port_str.c_str()); ret = -1; } } // public_ip if(cfg.hasParameter("public_ip" + suffix)){ intf.PublicIP = cfg.getParameter("public_ip" + suffix); } if(cfg.hasParameter("sig_sock_opts" + suffix)){ vector<string> opt_strs = explode(cfg.getParameter("sig_sock_opts" + suffix),","); unsigned int opts = 0; for(vector<string>::iterator it_opt = opt_strs.begin(); it_opt != opt_strs.end(); ++it_opt) { if(*it_opt == "force_via_address") { opts |= trsp_socket::force_via_address; } else if(*it_opt == "no_transport_in_contact") { opts |= trsp_socket::no_transport_in_contact; } else { WARN("unknown signaling socket option '%s' set on interface '%s'\n", it_opt->c_str(),i_name.c_str()); } } intf.SigSockOpts = opts; } intf.tcp_connect_timeout = cfg.getParameterInt("tcp_connect_timeout" + suffix, DEFAULT_TCP_CONNECT_TIMEOUT); intf.tcp_idle_timeout = cfg.getParameterInt("tcp_idle_timeout" + suffix, DEFAULT_TCP_IDLE_TIMEOUT); if(!i_name.empty()) intf.name = i_name; else intf.name = "default"; return AmConfig::insert_SIP_interface(intf); }
int AmConfig::readConfiguration() { DBG("Reading configuration...\n"); AmConfigReader cfg; int ret=0; if(cfg.loadFile(AmConfig::ConfigurationFile.c_str())){ ERROR("while loading main configuration file\n"); return -1; } // take values from global configuration file // they will be overwritten by command line args // log_level if(cfg.hasParameter("loglevel")){ if(!setLogLevel(cfg.getParameter("loglevel"))){ ERROR("invalid log level specified\n"); ret = -1; } } // stderr if(cfg.hasParameter("stderr")){ if(!setLogStderr(cfg.getParameter("stderr"), true)){ ERROR("invalid stderr value specified," " valid are only yes or no\n"); ret = -1; } } #ifndef DISABLE_SYSLOG_LOG if (cfg.hasParameter("syslog_facility")) { set_syslog_facility(cfg.getParameter("syslog_facility").c_str()); } #endif // plugin_config_path if (cfg.hasParameter("plugin_config_path")) { ModConfigPath = cfg.getParameter("plugin_config_path",ModConfigPath); } if(!ModConfigPath.empty() && (ModConfigPath[ModConfigPath.length()-1] != '/')) ModConfigPath += '/'; // Reads IP and port parameters if(readInterfaces(cfg) == -1) ret = -1; // outbound_proxy if (cfg.hasParameter("outbound_proxy")) OutboundProxy = cfg.getParameter("outbound_proxy"); // force_outbound_proxy if(cfg.hasParameter("force_outbound_proxy")) { ForceOutboundProxy = (cfg.getParameter("force_outbound_proxy") == "yes"); } if(cfg.hasParameter("next_hop")) { NextHop = cfg.getParameter("next_hop"); NextHop1stReq = (cfg.getParameter("next_hop_1st_req") == "yes"); } if(cfg.hasParameter("proxy_sticky_auth")) { ProxyStickyAuth = (cfg.getParameter("proxy_sticky_auth") == "yes"); } if(cfg.hasParameter("force_outbound_if")) { ForceOutboundIf = (cfg.getParameter("force_outbound_if") == "yes"); } if(cfg.hasParameter("use_raw_sockets")) { UseRawSockets = (cfg.getParameter("use_raw_sockets") == "yes"); if(UseRawSockets && (raw_sender::init() < 0)) { UseRawSockets = false; } } if(cfg.hasParameter("ignore_notify_lower_cseq")) { IgnoreNotifyLowerCSeq = (cfg.getParameter("ignore_notify_lower_cseq") == "yes"); } if(cfg.hasParameter("force_symmetric_rtp")) { ForceSymmetricRtp = (cfg.getParameter("force_symmetric_rtp") == "yes"); } if(cfg.hasParameter("sip_nat_handling")) { SipNATHandling = (cfg.getParameter("sip_nat_handling") == "yes"); } if(cfg.hasParameter("disable_dns_srv")) { _resolver::disable_srv = (cfg.getParameter("disable_dns_srv") == "yes"); } for (int t = STIMER_A; t < __STIMER_MAX; t++) { string timer_cfg = string("sip_timer_") + timer_name(t); if(cfg.hasParameter(timer_cfg)) { sip_timers[t] = cfg.getParameterInt(timer_cfg, sip_timers[t]); INFO("Set SIP Timer '%s' to %u ms\n", timer_name(t), sip_timers[t]); } } if (cfg.hasParameter("sip_timer_t2")) { sip_timer_t2 = cfg.getParameterInt("sip_timer_t2", DEFAULT_T2_TIMER); INFO("Set SIP Timer T2 to %u ms\n", sip_timer_t2); } // plugin_path if (cfg.hasParameter("plugin_path")) PlugInPath = cfg.getParameter("plugin_path"); // load_plugins if (cfg.hasParameter("load_plugins")) LoadPlugins = cfg.getParameter("load_plugins"); if (cfg.hasParameter("load_plugins_rtld_global")) { vector<string> rtld_global_plugins = explode(cfg.getParameter("load_plugins_rtld_global"), ","); for (vector<string>::iterator it= rtld_global_plugins.begin(); it != rtld_global_plugins.end(); it++) { AmPlugIn::instance()->set_load_rtld_global(*it); } } // exclude_plugins if (cfg.hasParameter("exclude_plugins")) ExcludePlugins = cfg.getParameter("exclude_plugins"); // exclude_plugins if (cfg.hasParameter("exclude_payloads")) ExcludePayloads = cfg.getParameter("exclude_payloads"); // user_agent if (cfg.getParameter("use_default_signature")=="yes") Signature = DEFAULT_SIGNATURE; else Signature = cfg.getParameter("signature"); if (cfg.hasParameter("max_forwards")) { unsigned int mf=0; if(str2i(cfg.getParameter("max_forwards"), mf)) { ERROR("invalid max_forwards specified\n"); } else { MaxForwards = mf; } } if(cfg.hasParameter("log_sessions")) LogSessions = cfg.getParameter("log_sessions")=="yes"; if(cfg.hasParameter("log_events")) LogEvents = cfg.getParameter("log_events")=="yes"; if (cfg.hasParameter("unhandled_reply_loglevel")) { string msglog = cfg.getParameter("unhandled_reply_loglevel"); if (msglog == "no") UnhandledReplyLoglevel = -1; else if (msglog == "error") UnhandledReplyLoglevel = 0; else if (msglog == "warn") UnhandledReplyLoglevel = 1; else if (msglog == "info") UnhandledReplyLoglevel = 2; else if (msglog == "debug") UnhandledReplyLoglevel = 3; else ERROR("Could not interpret unhandled_reply_loglevel \"%s\"\n", msglog.c_str()); } Application = cfg.getParameter("application"); if (Application == "$(ruri.user)") { AppSelect = App_RURIUSER; } else if (Application == "$(ruri.param)") { AppSelect = App_RURIPARAM; } else if (Application == "$(apphdr)") { AppSelect = App_APPHDR; } else if (Application == "$(mapping)") { AppSelect = App_MAPPING; string appcfg_fname = ModConfigPath + "app_mapping.conf"; DBG("Loading application mapping...\n"); if (!read_regex_mapping(appcfg_fname, "=>", "application mapping", AppMapping)) { ERROR("reading application mapping\n"); ret = -1; } } else { AppSelect = App_SPECIFIED; } #ifndef DISABLE_DAEMON_MODE // fork if(cfg.hasParameter("fork")){ if(!setDaemonMode(cfg.getParameter("fork"))){ ERROR("invalid fork value specified," " valid are only yes or no\n"); ret = -1; } } // daemon (alias for fork) if(cfg.hasParameter("daemon")){ if(!setDaemonMode(cfg.getParameter("daemon"))){ ERROR("invalid daemon value specified," " valid are only yes or no\n"); ret = -1; } } if(cfg.hasParameter("daemon_uid")){ DaemonUid = cfg.getParameter("daemon_uid"); } if(cfg.hasParameter("daemon_gid")){ DaemonGid = cfg.getParameter("daemon_gid"); } #endif /* !DISABLE_DAEMON_MODE */ MaxShutdownTime = cfg.getParameterInt("max_shutdown_time", DEFAULT_MAX_SHUTDOWN_TIME); if(cfg.hasParameter("session_processor_threads")){ #ifdef SESSION_THREADPOOL if(!setSessionProcessorThreads(cfg.getParameter("session_processor_threads"))){ ERROR("invalid session_processor_threads value specified\n"); ret = -1; } if (SessionProcessorThreads<1) { ERROR("invalid session_processor_threads value specified." " need at least one thread\n"); ret = -1; } #else WARN("session_processor_threads specified in sems.conf,\n"); WARN("but SEMS is compiled without SESSION_THREADPOOL support.\n"); WARN("set USE_THREADPOOL in Makefile.defs to enable session thread pool.\n"); WARN("SEMS will start now, but every call will have its own thread.\n"); #endif } if(cfg.hasParameter("media_processor_threads")){ if(!setMediaProcessorThreads(cfg.getParameter("media_processor_threads"))){ ERROR("invalid media_processor_threads value specified"); ret = -1; } } if(cfg.hasParameter("rtp_receiver_threads")){ if(!setRTPReceiverThreads(cfg.getParameter("rtp_receiver_threads"))){ ERROR("invalid rtp_receiver_threads value specified"); ret = -1; } } if(cfg.hasParameter("sip_server_threads")){ if(!setSIPServerThreads(cfg.getParameter("sip_server_threads"))){ ERROR("invalid sip_server_threads value specified"); ret = -1; } } // single codec in 200 OK if(cfg.hasParameter("single_codec_in_ok")){ SingleCodecInOK = (cfg.getParameter("single_codec_in_ok") == "yes"); } // single codec in 200 OK if(cfg.hasParameter("ignore_rtpxheaders")){ IgnoreRTPXHdrs = (cfg.getParameter("ignore_rtpxheaders") == "yes"); } // codec_order CodecOrder = explode(cfg.getParameter("codec_order"), ","); // dead_rtp_time if(cfg.hasParameter("dead_rtp_time")){ if(!setDeadRtpTime(cfg.getParameter("dead_rtp_time"))){ ERROR("invalid dead_rtp_time value specified"); ret = -1; } } if(cfg.hasParameter("dtmf_detector")){ if (cfg.getParameter("dtmf_detector") == "spandsp") { #ifndef USE_SPANDSP WARN("spandsp support not compiled in.\n"); #endif DefaultDTMFDetector = Dtmf::SpanDSP; } } #ifdef WITH_ZRTP enable_zrtp = cfg.getParameter("enable_zrtp", "yes") == "yes"; INFO("ZRTP %sabled\n", enable_zrtp ? "en":"dis"); enable_zrtp_debuglog = cfg.getParameter("enable_zrtp_debuglog", "yes") == "yes"; INFO("ZRTP debug log %sabled\n", enable_zrtp_debuglog ? "en":"dis"); #endif if(cfg.hasParameter("session_limit")){ vector<string> limit = explode(cfg.getParameter("session_limit"), ";"); if (limit.size() != 3) { ERROR("invalid session_limit specified.\n"); } else { if (str2i(limit[0], SessionLimit) || str2i(limit[1], SessionLimitErrCode)) { ERROR("invalid session_limit specified.\n"); } SessionLimitErrReason = limit[2]; } } if(cfg.hasParameter("options_session_limit")){ vector<string> limit = explode(cfg.getParameter("options_session_limit"), ";"); if (limit.size() != 3) { ERROR("invalid options_session_limit specified.\n"); } else { if (str2i(limit[0], OptionsSessionLimit) || str2i(limit[1], OptionsSessionLimitErrCode)) { ERROR("invalid options_session_limit specified.\n"); } OptionsSessionLimitErrReason = limit[2]; } } if(cfg.hasParameter("cps_limit")){ unsigned int CPSLimit; vector<string> limit = explode(cfg.getParameter("cps_limit"), ";"); if (limit.size() != 3) { ERROR("invalid cps_limit specified.\n"); } else { if (str2i(limit[0], CPSLimit) || str2i(limit[1], CPSLimitErrCode)) { ERROR("invalid cps_limit specified.\n"); } CPSLimitErrReason = limit[2]; } AmSessionContainer::instance()->setCPSLimit(CPSLimit); } if(cfg.hasParameter("accept_forked_dialogs")) AcceptForkedDialogs = !(cfg.getParameter("accept_forked_dialogs") == "no"); if(cfg.hasParameter("shutdown_mode_reply")){ string c_reply = cfg.getParameter("shutdown_mode_reply"); size_t spos = c_reply.find(" "); if (spos == string::npos || spos == c_reply.length()) { ERROR("invalid shutdown_mode_reply specified, expected \"<code> <reason>\"," "e.g. shutdown_mode_reply=\"503 Not At The Moment, Please\".\n"); ret = -1; } else { if (str2i(c_reply.substr(0, spos), ShutdownModeErrCode)) { ERROR("invalid shutdown_mode_reply specified, expected \"<code> <reason>\"," "e.g. shutdown_mode_reply=\"503 Not At The Moment, Please\".\n"); ret = -1; } ShutdownModeErrReason = c_reply.substr(spos+1); } } OptionsTranscoderOutStatsHdr = cfg.getParameter("options_transcoder_out_stats_hdr"); OptionsTranscoderInStatsHdr = cfg.getParameter("options_transcoder_in_stats_hdr"); TranscoderOutStatsHdr = cfg.getParameter("transcoder_out_stats_hdr"); TranscoderInStatsHdr = cfg.getParameter("transcoder_in_stats_hdr"); if (cfg.hasParameter("100rel")) { string rel100s = cfg.getParameter("100rel"); if (rel100s == "disabled" || rel100s == "off") { rel100 = Am100rel::REL100_DISABLED; } else if (rel100s == "supported") { rel100 = Am100rel::REL100_SUPPORTED; } else if (rel100s == "require") { rel100 = Am100rel::REL100_REQUIRE; } else { ERROR("unknown setting for '100rel' config option: '%s'.\n", rel100s.c_str()); ret = -1; } } if (cfg.hasParameter("resampling_library")) { string resamplings = cfg.getParameter("resampling_library"); if (resamplings == "libsamplerate") { ResamplingImplementationType = AmAudio::LIBSAMPLERATE; } } return ret; }
int AnswerMachineFactory::onLoad() { AmConfigReader cfg; if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1, MOD_NAME ".conf"))) return -1; // get application specific global parameters configureModule(cfg); #ifdef USE_MYSQL /* Get email templates from MySQL */ string mysql_server, mysql_user, mysql_passwd, mysql_db; mysql_server = cfg.getParameter("mysql_server"); if (mysql_server.empty()) { mysql_server = "localhost"; } mysql_user = cfg.getParameter("mysql_user"); if (mysql_user.empty()) { ERROR("voicemail.conf paramater 'mysql_user' is missing.\n"); return -1; } mysql_passwd = cfg.getParameter("mysql_passwd"); if (mysql_passwd.empty()) { ERROR("voicemail.conf paramater 'mysql_passwd' is missing.\n"); return -1; } mysql_db = cfg.getParameter("mysql_db"); if (mysql_db.empty()) { mysql_db = "sems"; } try { Connection.connect(mysql_db.c_str(), mysql_server.c_str(), mysql_user.c_str(), mysql_passwd.c_str()); if (!Connection) { ERROR("Database connection failed: %s\n", Connection.error()); return -1; } Connection.set_option(mysqlpp::Connection::opt_reconnect, true); } catch (const mysqlpp::Exception& er) { // Catch-all for any MySQL++ exceptions ERROR("MySQL++ error: %s\n", er.what()); return -1; } if(loadEmailTemplatesFromMySQL()){ ERROR("while loading email templates from MySQL\n"); return -1; } #else /* Get email templates from file system */ if(loadEmailTemplates(cfg.getParameter("email_template_path",DEFAULT_MAIL_TMPL_PATH))){ ERROR("while loading email templates\n"); return -1; } AnnouncePath = cfg.getParameter("announce_path",ANNOUNCE_PATH); DefaultAnnounce = cfg.getParameter("default_announce",DEFAULT_ANNOUNCE); #endif MaxRecordTime = cfg.getParameterInt("max_record_time",DEFAULT_RECORD_TIME); RecFileExt = cfg.getParameter("rec_file_ext",DEFAULT_AUDIO_EXT); UserTimer = AmPlugIn::instance()->getFactory4Di("user_timer"); if(!UserTimer){ ERROR("could not load user_timer from session_timer plug-in\n"); return -1; } EmailAddress = cfg.getParameter("email_address"); return 0; }
int AmZRTP::init() { zrtp_log_set_log_engine(zrtp_log); AmConfigReader cfg; string cfgname=add2path(AmConfig::ModConfigPath, 1, "zrtp.conf"); if(cfg.loadFile(cfgname)) { ERROR("No %s config file present.\n", cfgname.c_str()); return -1; } cache_path = cfg.getParameter("cache_path"); if (cfg.hasParameter("zid_hex")) { string zid_hex = cfg.getParameter("zid_hex"); if (zid_hex.size() != 2*sizeof(zrtp_instance_zid)) { ERROR("zid_hex config parameter in zrtp.conf must be %lu characters long.\n", sizeof(zrtp_zid_t)*2); return -1; } for (size_t i=0;i<sizeof(zrtp_instance_zid);i++) { unsigned int h; if (reverse_hex2int(zid_hex.substr(i*2, 2), h)) { ERROR("in zid_hex in zrtp.conf: '%s' is no hex number\n", zid_hex.substr(i*2, 2).c_str()); return -1; } zrtp_instance_zid[i]=h % 0xff; } } else if (cfg.hasParameter("zid")) { string zid = cfg.getParameter("zid"); WARN("zid parameter in zrtp.conf is only supported for backwards compatibility. Please use zid_hex\n"); if (zid.length() != sizeof(zrtp_zid_t)) { ERROR("zid config parameter in zrtp.conf must be %lu characters long.\n", sizeof(zrtp_zid_t)); return -1; } for (size_t i=0;i<zid.length();i++) zrtp_instance_zid[i]=zid[i]; } else { // generate one string zid_hex; for (size_t i=0;i<sizeof(zrtp_instance_zid);i++) { zrtp_instance_zid[i]=get_random() % 0xff; zid_hex+=char2hex(zrtp_instance_zid[i], true); } WARN("Generated random ZID. To support key continuity through key cache " "on the peers, add this to zrtp.conf: 'zid_hex=\"%s\"'", zid_hex.c_str()); } DBG("initializing ZRTP library with cache path '%s'.\n", cache_path.c_str()); zrtp_config_defaults(&zrtp_config); strcpy(zrtp_config.client_id, SEMS_CLIENT_ID); memcpy((char*)zrtp_config.zid, (char*)zrtp_instance_zid, sizeof(zrtp_zid_t)); zrtp_config.lic_mode = ZRTP_LICENSE_MODE_UNLIMITED; strncpy(zrtp_config.cache_file_cfg.cache_path, cache_path.c_str(), 256); zrtp_config.cb.misc_cb.on_send_packet = AmZRTP::on_send_packet; zrtp_config.cb.event_cb.on_zrtp_secure = AmZRTP::on_zrtp_secure; zrtp_config.cb.event_cb.on_zrtp_security_event = AmZRTP::on_zrtp_security_event; zrtp_config.cb.event_cb.on_zrtp_protocol_event = AmZRTP::on_zrtp_protocol_event; if ( zrtp_status_ok != zrtp_init(&zrtp_config, &zrtp_global) ) { ERROR("Error during ZRTP initialization\n"); return -1; } size_t rand_bytes = cfg.getParameterInt("random_entropy_bytes", 172); if (rand_bytes) { INFO("adding %zd bytes entropy from /dev/random to ZRTP entropy pool\n", rand_bytes); FILE* fd = fopen("/dev/random", "r"); if (!fd) { ERROR("opening /dev/random for adding entropy to the pool\n"); return -1; } void* p = malloc(rand_bytes); if (p==NULL) return -1; size_t read_bytes = fread(p, 1, rand_bytes, fd); if (read_bytes != rand_bytes) { ERROR("reading %zd bytes from /dev/random\n", rand_bytes); return -1; } zrtp_entropy_add(zrtp_global, (const unsigned char*)p, read_bytes); free(p); } // zrtp_add_entropy(zrtp_global, NULL, 0); // fixme DBG("ZRTP initialized ok.\n"); return 0; }