Example #1
0
int MOD_CLS_NAME::preload() {
   AmConfigReader cfg;
   if(cfg.loadPluginConf(MOD_NAME)) {
     INFO("no module configuration for '%s' found, not preloading regular expressions\n",
	  MOD_NAME);
     return 0;
   }

   bool failed = false;
   for (std::map<string,string>::const_iterator it =
	  cfg.begin(); it != cfg.end(); it++) {
     if (add_regex(it->first, it->second)) {
       ERROR("compiling regex '%s' for '%s'\n",
	     it->second.c_str(), it->first.c_str());
       failed = true;
     } else {
       DBG("compiled regex '%s' as '%s'\n", it->second.c_str(), it->first.c_str());
     }
   }

   return failed? -1 : 0;
}
Example #2
0
int CCBLRedis::onLoad() {
  AmConfigReader cfg;

  string redis_server = "127.0.0.1";
  string redis_port = "6379";
  string redis_reconnect_timers = "5,10,20,50,100,500,1000";
  string redis_connections = "10";
  string redis_max_conn_wait = "1000";
  pass_on_bl_unavailable = false;

  full_logging = false;

  if(cfg.loadPluginConf(MOD_NAME)) {
    INFO(MOD_NAME "configuration  file not found, assuming default "
	 "configuration is fine\n");
  } else {
    redis_server = cfg.getParameter("redis_server", redis_server);
    redis_port = cfg.getParameter("redis_port", redis_port);
    redis_reconnect_timers =
      cfg.getParameter("redis_reconnect_timers", redis_reconnect_timers);
    redis_connections = cfg.getParameter("redis_connections", redis_connections);
    redis_max_conn_wait = cfg.getParameter("redis_max_conn_wait", redis_max_conn_wait);
    full_logging = cfg.getParameter("redis_full_logging", "no")=="yes";

    pass_on_bl_unavailable = cfg.getParameter("pass_on_bl_unavailable", "no")=="yes";
  }

  unsigned int i_redis_connections;
  if (str2i(redis_connections, i_redis_connections)) {
    ERROR("could not understand redis_connections=%s\n", redis_connections.c_str());
    return -1;
  }

  unsigned int i_redis_port;
  if (str2i(redis_port, i_redis_port)) {
    ERROR("could not understand redis_port=%s\n", redis_port.c_str());
    return -1;
  }

 unsigned int i_redis_max_conn_wait;
  if (str2i(redis_max_conn_wait, i_redis_max_conn_wait)) {
    ERROR("could not understand redis_max_conn_wait=%s\n", redis_max_conn_wait.c_str());
    return -1;
  }

 std::vector<unsigned int> reconnect_timers;
 std::vector<string> timeouts_v = explode(redis_reconnect_timers, ",");
  for (std::vector<string>::iterator it=
         timeouts_v.begin(); it != timeouts_v.end(); it++) {
    int r;
    if (!str2int(*it, r)) {
      ERROR("REDIS reconnect timeout '%s' not understood\n",
            it->c_str());
      return -1;
    }
    reconnect_timers.push_back(r);
  }

  connection_pool.set_config(redis_server, i_redis_port,
			     reconnect_timers, i_redis_max_conn_wait);
  connection_pool.add_connections(i_redis_connections);
  connection_pool.start();

  DBG("setting max number max_retries to %u (as connections)\n", i_redis_connections);
  max_retries = i_redis_connections;

  return 0;
}