当前位置: 首页>>代码示例>>C++>>正文


C++ AmConfigReader::hasParameter方法代码示例

本文整理汇总了C++中AmConfigReader::hasParameter方法的典型用法代码示例。如果您正苦于以下问题:C++ AmConfigReader::hasParameter方法的具体用法?C++ AmConfigReader::hasParameter怎么用?C++ AmConfigReader::hasParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AmConfigReader的用法示例。


在下文中一共展示了AmConfigReader::hasParameter方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: readFromConfig

int AmSessionTimerConfig::readFromConfig(AmConfigReader& cfg)
{
  // enable_session_timer
  if(cfg.hasParameter("enable_session_timer")){
    if(!setEnableSessionTimer(cfg.getParameter("enable_session_timer"))){
      ERROR("invalid enable_session_timer specified\n");
      return -1;
    }
  }

  // session_expires
  if(cfg.hasParameter("session_expires")){
    if(!setSessionExpires(cfg.getParameter("session_expires"))){
      ERROR("invalid session_expires specified\n");
      return -1;
    }
  }

  // minimum_timer
  if(cfg.hasParameter("minimum_timer")){
    if(!setMinimumTimer(cfg.getParameter("minimum_timer"))){
      ERROR("invalid minimum_timer specified\n");
      return -1;
    }
  }
  return 0;
}
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:27,代码来源:AmConfig.cpp

示例2: onLoad

int SipCtrlInterfaceFactory::onLoad()
{
    
    bind_addr = AmConfig::LocalSIPIP;
    bind_port = AmConfig::LocalSIPPort;
  
    INFO("SIP bind_addr: `%s'.\n", bind_addr.c_str());
    INFO("SIP bind_port: `%i'.\n", bind_port);

    if (!AmConfig::OutboundProxy.empty()) {
	sip_uri parsed_uri;
	if (parse_uri(&parsed_uri, (char *)AmConfig::OutboundProxy.c_str(),
		      AmConfig::OutboundProxy.length()) < 0) {
	    ERROR("invalid outbound_proxy specified\n");
	    return -1;
	}
	SipCtrlInterfaceFactory::outbound_host = c2stlstr(parsed_uri.host);
	if (parsed_uri.port) {
	    SipCtrlInterfaceFactory::outbound_port = parsed_uri.port;
	}
    }

    AmConfigReader cfg;
    string cfgfile = AmConfig::ModConfigPath + string(MOD_NAME ".conf");
    if (file_exists(cfgfile) && !cfg.loadFile(cfgfile)) {
	if (cfg.hasParameter("accept_fr_without_totag")) {
	    accept_fr_without_totag = 
		cfg.getParameter("accept_fr_without_totag") == "yes";
	}
	DBG("sipctrl: accept_fr_without_totag = %s\n", 
	    accept_fr_without_totag?"yes":"no");

	if (cfg.hasParameter("log_raw_messages")) {
	    string msglog = cfg.getParameter("log_raw_messages");
	    if (msglog == "no") log_raw_messages = -1;
	    else if (msglog == "error") log_raw_messages = 0;
	    else if (msglog == "warn")  log_raw_messages = 1;
	    else if (msglog == "info")  log_raw_messages = 2;
	    else if (msglog == "debug") log_raw_messages = 3;
	}
	DBG("sipctrl: log_raw_messages level = %d\n", 
	    log_raw_messages);

	if (cfg.hasParameter("log_parsed_messages")) {
	    log_parsed_messages = cfg.getParameter("log_parsed_messages")=="yes";
	}
	DBG("sipctrl: log_parsed_messages = %s\n", 
	    log_parsed_messages?"yes":"no");

    } else {
	DBG("assuming SIP default settings.\n");
    }

    return 0;
    
}
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:56,代码来源:SipCtrlInterface.cpp

示例3: readRTPInterface

static int readRTPInterface(AmConfigReader& cfg, const string& i_name)
{
  int ret=0;
  AmConfig::RTP_interface intf;

  string suffix;
  if(!i_name.empty())
    suffix = "_" + i_name;

  // media_ip
  if(cfg.hasParameter("media_ip" + suffix)) {
    intf.LocalIP = cfg.getParameter("media_ip" + suffix);
  }
  else {
    // no media definition for this interface name
    return 0;
  }

  // public_ip
  if(cfg.hasParameter("public_ip" + suffix)){
    intf.PublicIP = cfg.getParameter("public_ip" + suffix);
  }

  // rtp_low_port
  if(cfg.hasParameter("rtp_low_port" + suffix)){
    string rtp_low_port_str = cfg.getParameter("rtp_low_port" + suffix);
    if(sscanf(rtp_low_port_str.c_str(),"%u",
	      &(intf.RtpLowPort)) != 1){
      ERROR("rtp_low_port%s: invalid port number (%s)\n",
	    suffix.c_str(),rtp_low_port_str.c_str());
      ret = -1;
    }
  }

  // rtp_high_port
  if(cfg.hasParameter("rtp_high_port" + suffix)){
    string rtp_high_port_str = cfg.getParameter("rtp_high_port" + suffix);
    if(sscanf(rtp_high_port_str.c_str(),"%u",
	      &(intf.RtpHighPort)) != 1){
      ERROR("rtp_high_port%s: invalid port number (%s)\n",
	    suffix.c_str(),rtp_high_port_str.c_str());
      ret = -1;
    }
  }

  if(!i_name.empty())
    intf.name = i_name;
  else
    intf.name = "default";

  return AmConfig::insert_RTP_interface(intf);
}
开发者ID:shenya,项目名称:sems,代码行数:52,代码来源:AmConfig.cpp

示例4: readInterfaces

static int readInterfaces(AmConfigReader& cfg)
{
  if(!cfg.hasParameter("interfaces")) {
    // no interface list defined:
    // read default params
    readSIPInterface(cfg,"");
    readRTPInterface(cfg,"");
    return 0;
  }

  vector<string> if_names;
  string ifs_str = cfg.getParameter("interfaces");
  if(ifs_str.empty()) {
    ERROR("empty interface list.\n");
    return -1;
  }

  if_names = explode(ifs_str,",");
  if(!if_names.size()) {
    ERROR("could not parse interface list.\n");
    return -1;
  }

  for(vector<string>::iterator it = if_names.begin();
      it != if_names.end(); it++) {

    readSIPInterface(cfg,*it);
    readRTPInterface(cfg,*it);

    if((AmConfig::SIP_If_names.find(*it) == AmConfig::SIP_If_names.end()) &&
       (AmConfig::RTP_If_names.find(*it) == AmConfig::RTP_If_names.end())) {
      ERROR("missing interface definition for '%s'\n",it->c_str());
      return -1;
    }
  }

  //TODO: check interfaces
  return 0;
}
开发者ID:shenya,项目名称:sems,代码行数:39,代码来源:AmConfig.cpp

示例5: onLoad

int EarlyAnnounceFactory::onLoad()
{
  AmConfigReader cfg;
  if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf")))
    return -1;

  // get application specific global parameters
  configureModule(cfg);

  if (cfg.hasParameter("continue_b2b")) { 
    if (cfg.getParameter("continue_b2b") == "yes") {
      ContinueB2B = Always;
      DBG("early_announce in b2bua mode.\n");
    }
    else if (cfg.getParameter("continue_b2b") == "app-param") {
      ContinueB2B = AppParam;
      DBG("early_announce in b2bua/final reply mode "
	  "(depends on app-param).\n");
    } else {
      DBG("early_announce sends final reply.\n");
    }
  }

#ifdef USE_MYSQL

  /* Get default audio 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("conference.conf paramater 'mysql_user' is missing.\n");
    return -1;
  }

  mysql_passwd = cfg.getParameter("mysql_passwd");
  if (mysql_passwd.empty()) {
    ERROR("conference.conf paramater 'mysql_passwd' is missing.\n");
    return -1;
  }

  mysql_db = cfg.getParameter("mysql_db");
  if (mysql_db.empty()) {
    mysql_db = "sems";
  }

  AnnounceApplication = cfg.getParameter("application");
  if (AnnounceApplication.empty()) {
    AnnounceApplication = MOD_NAME;
  }

  AnnounceMessage = cfg.getParameter("message");
  if (AnnounceMessage.empty()) {
    AnnounceMessage = "greeting_msg";
  }

  DefaultLanguage = cfg.getParameter("default_language");
  if (DefaultLanguage.empty()) {
    DefaultLanguage = "en";
  }

  try {

#ifdef VERSION2
    Connection.set_option(Connection.opt_reconnect, true);
#else
    Connection.set_option(new mysqlpp::ReconnectOption(true));
#endif
    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;
    }
  }

  catch (const mysqlpp::BadOption& er) {
    ERROR("MySQL++ set_option error: %s\n", er.what());
    return -1;
  }
 	
  catch (const mysqlpp::Exception& er) {
    // Catch-all for any MySQL++ exceptions
    ERROR("MySQL++ error: %s\n", er.what());
    return -1;
  }

  string announce_file;
  if (!get_announce_msg(AnnounceApplication, AnnounceMessage, "", "",
			DefaultLanguage, &announce_file)) {
    return -1;
  }
  if (announce_file.empty()) {
    ERROR("default announce for " MOD_NAME " module does not exist.\n");
    return -1;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:101,代码来源:EarlyAnnounce.cpp

示例6: readConfiguration

int AmConfig::readConfiguration()
{
  DBG("Reading configuration...");
  
  AmConfigReader cfg;

  if(cfg.loadFile(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


  if (cfg.hasParameter("syslog_facility")) {
    set_log_facility(cfg.getParameter("syslog_facility").c_str());
  }

  // plugin_config_path
  ModConfigPath = cfg.getParameter("plugin_config_path",ModConfigPath);

  if(!ModConfigPath.empty() && (ModConfigPath[ModConfigPath.length()-1] != '/'))
    ModConfigPath += '/';

  // listen, sip_ip, sip_port, and media_ip
  if(cfg.hasParameter("sip_ip")) {
    LocalSIPIP = cfg.getParameter("sip_ip");
  }
  if(cfg.hasParameter("sip_port")){
    if(!setSIPPort(cfg.getParameter("sip_port").c_str())){
      ERROR("invalid sip port specified\n");
      return -1;
    }		
  }
  if(cfg.hasParameter("media_ip")) {
    LocalIP = cfg.getParameter("media_ip");
  }

  // public_ip
  if(cfg.hasParameter("public_ip")){
    string p_ip = cfg.getParameter("public_ip");
    DBG("Setting public_ip parameter to %s.\n", p_ip.c_str());
    PublicIP = p_ip;
  }
  else {
    DBG("Config file has no public_ip parameter.");
  }
  
  // outbound_proxy
  OutboundProxy = cfg.getParameter("outbound_proxy");
  
  // plugin_path
  PlugInPath = cfg.getParameter("plugin_path");

  // load_plugins
  LoadPlugins = cfg.getParameter("load_plugins");

  // exclude_plugins
  ExcludePlugins = cfg.getParameter("exclude_plugins");

  // exclude_plugins
  ExcludePayloads = cfg.getParameter("exclude_payloads");

  // user_agent
  if (cfg.getParameter("use_default_signature")=="yes")
    Signature = DEFAULT_SIGNATURE;
  else 
    Signature = cfg.getParameter("signature");

  // log_level
  if(cfg.hasParameter("loglevel")){
    if(!setLoglevel(cfg.getParameter("loglevel"))){
      ERROR("invalid log level specified\n");
      return -1;
    }
  }

  LogSessions = cfg.getParameter("log_sessions")=="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)") {
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:101,代码来源:AmConfig.cpp

示例7: 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;
//.........这里部分代码省略.........
开发者ID:BackupTheBerlios,项目名称:sems-svn,代码行数:101,代码来源:AnswerMachine.cpp

示例8: 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);
}
开发者ID:shenya,项目名称:sems,代码行数:65,代码来源:AmConfig.cpp

示例9: readConfiguration

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)) {
//.........这里部分代码省略.........
开发者ID:shenya,项目名称:sems,代码行数:101,代码来源:AmConfig.cpp

示例10: 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;
}
开发者ID:Chocolatbuddha,项目名称:sems,代码行数:99,代码来源:AmZRTP.cpp


注:本文中的AmConfigReader::hasParameter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。