本文整理汇总了C++中AmConfigReader::getParameterInt方法的典型用法代码示例。如果您正苦于以下问题:C++ AmConfigReader::getParameterInt方法的具体用法?C++ AmConfigReader::getParameterInt怎么用?C++ AmConfigReader::getParameterInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AmConfigReader
的用法示例。
在下文中一共展示了AmConfigReader::getParameterInt方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onLoad
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;
}
示例2: load
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;
}
示例3: DBG
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;
}
示例4: onLoad
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;
}
示例5: onLoad
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;
}
示例6: onLoad
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);
}
//.........这里部分代码省略.........
示例7: init
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;
}
示例8: onLoad
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;
//.........这里部分代码省略.........
示例9: readSIPInterface
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);
}
示例10: readConfiguration
//.........这里部分代码省略.........
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
示例11: onLoad
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;
}
示例12: init
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;
}