/* * check that there is basic thingies in configuration */ static int check_config(Cfg *cfg) { CfgGroup *grp; long smsp, wapp; grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) return -1; if (cfg_get_integer(&smsp, grp, octstr_imm("smsbox-port")) == -1) smsp = -1; if (cfg_get_integer(&wapp, grp, octstr_imm("wapbox-port")) == -1) wapp = -1; #ifndef NO_SMS grp = cfg_get_single_group(cfg, octstr_imm("smsbox")); if (smsp != -1 && grp == NULL) { error(0, "No 'smsbox' group in configuration, but smsbox-port set"); return -1; } #endif #ifndef NO_WAP grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (wapp != -1 && grp == NULL) { error(0, "No 'wapbox' group in configuration, but wapbox-port set"); return -1; } #endif return 0; }
int udp_start(Cfg *cfg) { CfgGroup *grp; Octstr *iface; List *ifs; int allow_wtls; if (udp_running) return -1; debug("bb.udp", 0, "starting UDP sender/receiver module"); grp = cfg_get_single_group(cfg, octstr_imm("core")); iface = cfg_get(grp, octstr_imm("wdp-interface-name")); if (iface == NULL) { error(0, "Missing wdp-interface-name variable, cannot start UDP"); return -1; } allow_ip = cfg_get(grp, octstr_imm("udp-allow-ip")); deny_ip = cfg_get(grp, octstr_imm("udp-deny-ip")); /* we'll activate WTLS as soon as we have a 'wtls' config group */ grp = cfg_get_single_group(cfg, octstr_imm("wtls")); allow_wtls = grp != NULL ? 1 : 0; udpc_list = gwlist_create(); /* have a list of running systems */ ifs = octstr_split(iface, octstr_imm(";")); octstr_destroy(iface); while (gwlist_len(ifs) > 0) { iface = gwlist_extract_first(ifs); info(0, "Adding interface %s", octstr_get_cstr(iface)); add_service(9200, octstr_get_cstr(iface)); /* wsp */ add_service(9201, octstr_get_cstr(iface)); /* wsp/wtp */ #ifdef HAVE_WTLS_OPENSSL if (allow_wtls) { add_service(9202, octstr_get_cstr(iface)); /* wsp/wtls */ add_service(9203, octstr_get_cstr(iface)); /* wsp/wtp/wtls */ } #else if (allow_wtls) error(0, "These is a 'wtls' group in configuration, but no WTLS support compiled in!"); #endif /* add_service(9204, octstr_get_cstr(interface_name)); * vcard */ /* add_service(9205, octstr_get_cstr(interface_name)); * vcal */ /* add_service(9206, octstr_get_cstr(interface_name)); * vcard/wtls */ /* add_service(9207, octstr_get_cstr(interface_name)); * vcal/wtls */ octstr_destroy(iface); } gwlist_destroy(ifs, NULL); gwlist_add_producer(incoming_wdp); udp_running = 1; return 0; }
void cfg_dump(Cfg *cfg) { CfgGroup *grp; List *list; List *names; Octstr *name; debug("gwlib.cfg", 0, "Dumping Cfg %p", (void *) cfg); debug("gwlib.cfg", 0, " filename = <%s>", octstr_get_cstr(cfg->filename)); names = dict_keys(cfg->single_groups); while ((name = gwlist_extract_first(names)) != NULL) { grp = cfg_get_single_group(cfg, name); if (grp != NULL) grp_dump(grp); octstr_destroy(name); } gwlist_destroy(names, NULL); names = dict_keys(cfg->multi_groups); while ((name = gwlist_extract_first(names)) != NULL) { list = cfg_get_multi_group(cfg, name); while ((grp = gwlist_extract_first(list)) != NULL) grp_dump(grp); gwlist_destroy(list, NULL); octstr_destroy(name); } gwlist_destroy(names, NULL); debug("gwlib.cfg", 0, "Dump ends."); }
void sqlbox_configure_mysql(Cfg* cfg) { CfgGroup *grp; Octstr *sql; if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: MySQL: group 'sqlbox' is not specified!"); sqlbox_logtable = cfg_get(grp, octstr_imm("sql-log-table")); if (sqlbox_logtable == NULL) { panic(0, "No 'sql-log-table' not configured."); } sqlbox_insert_table = cfg_get(grp, octstr_imm("sql-insert-table")); if (sqlbox_insert_table == NULL) { panic(0, "No 'sql-insert-table' not configured."); } /* create send_sms && sent_sms tables if they do not exist */ sql = octstr_format(SQLBOX_MYSQL_CREATE_LOG_TABLE, sqlbox_logtable); sql_update(sql); octstr_destroy(sql); sql = octstr_format(SQLBOX_MYSQL_CREATE_INSERT_TABLE, sqlbox_insert_table); sql_update(sql); octstr_destroy(sql); /* end table creation */ }
/* * Initialize dlr_waiting_list and return out storage handles. */ struct dlr_storage *dlr_init_spool(Cfg *cfg) { CfgGroup *grp; if (!(grp = cfg_get_single_group(cfg, octstr_imm("core")))) panic(0, "DLR: spool: group 'core' is not specified!"); if (!(spool_dir = cfg_get(grp, octstr_imm("dlr-spool")))) panic(0, "DLR: spool: directive 'dlr-spool' is not specified!"); #ifdef HAVE_LIBSSL OpenSSL_add_all_digests(); #endif counter = counter_create(); /* we need to traverse the DLR spool to determine how * many entries we have. */ #ifdef VERIFIED for_each_file(spool_dir, 1, verified_file); #else for_each_file(spool_dir, 1, non_verified_file); #endif return &handles; }
int httpadmin_start(Cfg *cfg) { CfgGroup *grp; int ssl = 0; #ifdef HAVE_LIBSSL Octstr *ssl_server_cert_file; Octstr *ssl_server_key_file; #endif /* HAVE_LIBSSL */ if (httpadmin_running) return -1; grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&ha_port, grp, octstr_imm("admin-port")) == -1) panic(0, "Missing admin-port variable, cannot start HTTP admin"); ha_interface = cfg_get(grp, octstr_imm("admin-interface")); ha_password = cfg_get(grp, octstr_imm("admin-password")); if (ha_password == NULL) panic(0, "You MUST set HTTP admin-password"); ha_status_pw = cfg_get(grp, octstr_imm("status-password")); ha_allow_ip = cfg_get(grp, octstr_imm("admin-allow-ip")); ha_deny_ip = cfg_get(grp, octstr_imm("admin-deny-ip")); #ifdef HAVE_LIBSSL cfg_get_bool(&ssl, grp, octstr_imm("admin-port-ssl")); /* * check if SSL is desired for HTTP servers and then * load SSL client and SSL server public certificates * and private keys */ ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file")); ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file")); if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) { /* we are fine here, the following call is now in conn_config_ssl(), * so there is no reason to do this twice. use_global_server_certkey_file(ssl_server_cert_file, ssl_server_key_file); */ } else if (ssl) { panic(0, "You MUST specify cert and key files within core group for SSL-enabled HTTP servers!"); } octstr_destroy(ssl_server_cert_file); octstr_destroy(ssl_server_key_file); #endif /* HAVE_LIBSSL */ http_open_port_if(ha_port, ssl, ha_interface); if (gwthread_create(httpadmin_run, NULL) == -1) panic(0, "Failed to start a new thread for HTTP admin"); httpadmin_running = 1; return 0; }
static void init_smpp_server_box(Cfg *cfg) { CfgGroup *cfg_group; Octstr *log_file; long log_level; log_file = NULL; log_level = 0; debug("httpClient", 0, "********** HTTP Client Box Configuration Initialization **********"); /* initialize low level PDUs */ if (smpp_pdu_init(cfg) == -1) panic(0, "Connot start with PDU init failed."); /* * first we take the port number in bearerbox and other values from the * httpClient group in configuration file */ cfg_group = cfg_get_single_group(cfg, octstr_imm("httpClient")); if (cfg_group == NULL) panic(0, "No 'httpClient' group in configuration"); httpBoxId = cfg_get(cfg_group, octstr_imm("httpClient-id")); /* setup logfile stuff */ log_file = cfg_get(cfg_group, octstr_imm("log-file")); cfg_get_integer(&log_level, cfg_group, octstr_imm("log-level")); if (log_file != NULL) { info(0, "Starting to log to file %s level %ld", octstr_get_cstr(log_file), log_level); log_open(octstr_get_cstr(log_file), log_level, GW_NON_EXCL); } if (cfg_get_integer(&timeOut, cfg_group, octstr_imm("time-out")) == -1) timeOut = TIMEOUT_SECONDS; integratorId = cfg_get(cfg_group, octstr_imm("integrator-id")); integratorQueueId = cfg_get(cfg_group, octstr_imm("integrator-queue-id")); debug("httpClient", 0, "==========Configuration Parameters============"); debug("httpClient", 0, "===> httpClient-id: %s ", octstr_get_cstr(httpBoxId)); debug("httpClient", 0, "===> integrator-id: %s ", octstr_get_cstr(integratorId)); debug("httpClient", 0, "===> integrator-queue-id: %s ", octstr_get_cstr(integratorQueueId)); debug("httpClient", 0, "===> log-file: %s ", octstr_get_cstr(log_file)); debug("httpClient", 0, "===> log-level: %ld", log_level); debug("httpClient", 0, "===> timeout: %ld ", timeOut); debug("httpClient", 0, "=============================================="); octstr_destroy(log_file); gw_smpp_enter(cfg); httpbox_status = SMPP_RUNNING; debug("httpClient", 0, "http_status: %d ", httpbox_status); debug("httpClient", 0, "********** HTTP Client Box Configuration End **********"); }
/* * Initialize specifically dlr storage. If defined storage is unknown * then panic. */ void dlr_init(Cfg* cfg) { CfgGroup *grp; Octstr *dlr_type; /* check which DLR storage type we are using */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if(grp == NULL) panic(0, "DLR: can't find group core"); dlr_type = cfg_get(grp, octstr_imm("dlr-storage")); /* * assume we are using internal memory in case no directive * has been specified, warn the user anyway */ if (dlr_type == NULL) { dlr_type = octstr_imm("internal"); warning(0, "DLR: using default 'internal' for storage type."); } /* call the sub-init routine */ if (octstr_compare(dlr_type, octstr_imm("mysql")) == 0) { handles = dlr_init_mysql(cfg); } else if (octstr_compare(dlr_type, octstr_imm("sdb")) == 0) { handles = dlr_init_sdb(cfg); } else if (octstr_compare(dlr_type, octstr_imm("oracle")) == 0) { handles = dlr_init_oracle(cfg); } else if (octstr_compare(dlr_type, octstr_imm("internal")) == 0) { handles = dlr_init_mem(cfg); } else if (octstr_compare(dlr_type, octstr_imm("pgsql")) == 0) { handles = dlr_init_pgsql(cfg); } else if (octstr_compare(dlr_type, octstr_imm("mssql")) == 0) { handles = dlr_init_mssql(cfg); } /* * add aditional types here */ if (handles == NULL) { panic(0, "DLR: storage type '%s' is not supported!", octstr_get_cstr(dlr_type)); } /* check needed function pointers */ if (handles->dlr_add == NULL || handles->dlr_get == NULL || handles->dlr_remove == NULL) panic(0, "DLR: storage type '%s' don't implement needed functions", octstr_get_cstr(dlr_type)); /* get info from storage */ info(0, "DLR using storage type: %s", handles->type); /* cleanup */ octstr_destroy(dlr_type); }
int smsbox_start(Cfg *cfg) { CfgGroup *grp; if (smsbox_running) return -1; debug("bb", 0, "starting smsbox connection module"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&smsbox_port, grp, octstr_imm("smsbox-port")) == -1) { error(0, "Missing smsbox-port variable, cannot start smsboxes"); return -1; } #ifdef HAVE_LIBSSL cfg_get_bool(&smsbox_port_ssl, grp, octstr_imm("smsbox-port-ssl")); #endif /* HAVE_LIBSSL */ if (smsbox_port_ssl) debug("bb", 0, "smsbox connection module is SSL-enabled"); if (cfg_get_integer(&smsbox_max_pending, grp, octstr_imm("smsbox-max-pending")) == -1) { smsbox_max_pending = SMSBOX_MAX_PENDING; info(0, "BOXC: 'smsbox-max-pending' not set, using default (%ld).", smsbox_max_pending); } smsbox_list = gwlist_create(); /* have a list of connections */ smsbox_list_rwlock = gw_rwlock_create(); if (!boxid) boxid = counter_create(); /* the smsbox routing specific inits */ smsbox_by_id = dict_create(10, NULL); /* and a hash directory of identified */ smsbox_by_smsc = dict_create(30, (void(*)(void *)) octstr_destroy); smsbox_by_receiver = dict_create(50, (void(*)(void *)) octstr_destroy); smsbox_by_smsc_receiver = dict_create(50, (void(*)(void *)) octstr_destroy); /* load the defined smsbox routing rules */ init_smsbox_routes(cfg); gwlist_add_producer(outgoing_sms); gwlist_add_producer(smsbox_list); smsbox_running = 1; if ((sms_dequeue_thread = gwthread_create(sms_to_smsboxes, NULL)) == -1) panic(0, "Failed to start a new thread for smsbox routing"); if (gwthread_create(smsboxc_run, &smsbox_port) == -1) panic(0, "Failed to start a new thread for smsbox connections"); return 0; }
static void read_test_ppg_config(Octstr *name) { Cfg *cfg; CfgGroup *grp; cfg = cfg_create(name); if (cfg_read(cfg) == -1) panic(0, "Cannot read a configuration file %s, exiting", octstr_get_cstr(name)); cfg_dump(cfg); grp = cfg_get_single_group(cfg, octstr_imm("test-ppg")); cfg_get_integer(&retries, grp, octstr_imm("retries")); cfg_get_bool(&pi_ssl, grp, octstr_imm("pi-ssl")); #ifdef HAVE_LIBSSL if (pi_ssl) { ssl_client_certkey_file = cfg_get(grp, octstr_imm("ssl-client-certkey-file")); if (ssl_client_certkey_file != NULL) { use_global_client_certkey_file(ssl_client_certkey_file); } else { error(0, "cannot set up SSL without client certkey file"); exit(1); } } #endif grp = cfg_get_single_group(cfg, octstr_imm("configuration")); push_url = cfg_get(grp, octstr_imm("push-url")); pap_file = cfg_get(grp, octstr_imm("pap-file")); content_file = cfg_get(grp, octstr_imm("content-file")); if (!use_hardcoded) { username = cfg_get(grp, octstr_imm("username")); password = cfg_get(grp, octstr_imm("password")); } cfg_destroy(cfg); }
void sqlbox_configure_mssql(Cfg* cfg) { DBPoolConn *pc; CfgGroup *grp; Octstr *sql; if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: MSSql: group 'sqlbox' is not specified!"); sqlbox_logtable = cfg_get(grp, octstr_imm("sql-log-table")); if (sqlbox_logtable == NULL) { panic(0, "Parameter 'sql-log-table' not configured."); } sqlbox_insert_table = cfg_get(grp, octstr_imm("sql-insert-table")); if (sqlbox_insert_table == NULL) { panic(0, "Parameter 'sql-insert-table' not configured."); } pc = dbpool_conn_consume(pool); if (pc == NULL) { error(0, "MSSql: DBPool Error!"); return; } /* create send_sms && sent_sms tables if they do not exist */ sql = octstr_format(SQLBOX_MSSQL_CREATE_LOG_TABLE, sqlbox_logtable, sqlbox_logtable); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); sql = octstr_format(SQLBOX_MSSQL_CREATE_INSERT_TABLE, sqlbox_insert_table, sqlbox_insert_table); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); dbpool_conn_produce(pc); }
int wapbox_start(Cfg *cfg) { CfgGroup *grp; if (wapbox_running) return -1; debug("bb", 0, "starting wapbox connection module"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (cfg_get_integer(&wapbox_port, grp, octstr_imm("wapbox-port")) == -1) { error(0, "Missing wapbox-port variable, cannot start WAP"); return -1; } #ifdef HAVE_LIBSSL cfg_get_bool(&wapbox_port_ssl, grp, octstr_imm("wapbox-port-ssl")); #endif /* HAVE_LIBSSL */ box_allow_ip = cfg_get(grp, octstr_imm("box-allow-ip")); if (box_allow_ip == NULL) box_allow_ip = octstr_create(""); box_deny_ip = cfg_get(grp, octstr_imm("box-deny-ip")); if (box_deny_ip == NULL) box_deny_ip = octstr_create(""); if (box_allow_ip != NULL && box_deny_ip == NULL) info(0, "Box connection allowed IPs defined without any denied..."); wapbox_list = gwlist_create(); /* have a list of connections */ gwlist_add_producer(outgoing_wdp); if (!boxid) boxid = counter_create(); if (gwthread_create(wdp_to_wapboxes, NULL) == -1) panic(0, "Failed to start a new thread for wapbox routing"); if (gwthread_create(wapboxc_run, &wapbox_port) == -1) panic(0, "Failed to start a new thread for wapbox connections"); wapbox_running = 1; return 0; }
void smpp_route_init(SMPPServer *smpp_server) { SMPPRouting *smpp_routing = gw_malloc(sizeof(SMPPRouting)); smpp_server->routing = smpp_routing; smpp_routing->lock = gw_rwlock_create(); smpp_routing->inbound_routes = NULL; smpp_routing->outbound_routes = NULL; smpp_routing->reload = NULL; smpp_routing->route_message = NULL; smpp_routing->outbound_lock = gw_rwlock_create(); smpp_routing->initialized = 0; CfgGroup *grp = cfg_get_single_group(smpp_server->running_configuration, octstr_imm("smpp-routing")); long tmp; if(!grp) { warning(0, "No 'smpp-routing' group specified, using defaults (database)"); tmp = SMPP_ROUTING_DEFAULT_METHOD; } else { if(cfg_get_integer(&tmp, grp, octstr_imm("routing-method")) == -1) { tmp = SMPP_ROUTING_DEFAULT_METHOD; } } if(tmp == SMPP_ROUTING_METHOD_DATABASE) { info(0, "Initializing database based routing"); smpp_routing->reload = smpp_route_rebuild_database; smpp_routing->route_message = smpp_route_message_database; smpp_routing->shutdown = smpp_route_shutdown_database; } else if(tmp == SMPP_ROUTING_METHOD_HTTP) { smpp_routing->init = smpp_http_client_route_init; } smpp_route_init_method(smpp_server); smpp_route_rebuild(smpp_server); smpp_http_server_add_command(smpp_server, octstr_imm("rebuild-routes"), smpp_route_rebuild_command); }
void sqlbox_configure_redis(Cfg* cfg) { CfgGroup *grp; Octstr *sql; if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: Redis: group 'sqlbox' is not specified!"); sqlbox_logtable = cfg_get(grp, octstr_imm("sql-log-table")); if (sqlbox_logtable == NULL) { panic(0, "'sql-log-table' is not configured in the group 'sqlbox'."); } sqlbox_insert_table = cfg_get(grp, octstr_imm("sql-insert-table")); if (sqlbox_insert_table == NULL) { panic(0, "'sql-insert-table' is not configured in the group 'sqlbox'."); } sqlbox_inflight_table = cfg_get(grp, octstr_imm("sql-inflight-table")); json_set_alloc_funcs(gw_malloc_json, gw_free_json); /* no need to create tables on redis */ }
struct server_type *sqlbox_init_redis(Cfg* cfg) { CfgGroup *grp; List *grplist; Octstr *redis_host, *redis_password, *redis_id; Octstr *p = NULL; long pool_size, redis_port = 0, redis_database = -1, redis_idle_timeout_secs = -1; DBConf *db_conf = NULL; struct server_type *res = NULL; /* * check for all mandatory directives that specify the key names * for the redis storage */ if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: Redis: group 'sqlbox' is not specified!"); if (!(redis_id = cfg_get(grp, octstr_imm("id")))) panic(0, "SQLBOX: Redis: directive 'id' is not specified in the 'sqlbox' group!"); /* * now grap the required information from the 'redis-connection' group * with the redis-id we just obtained * * we have to loop through all available Redis connection definitions * and search for the one we are looking for */ grplist = cfg_get_multi_group(cfg, octstr_imm("redis-connection")); while (grplist && (grp = (CfgGroup *)gwlist_extract_first(grplist)) != NULL) { p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, redis_id) == 0) { goto found; } if (p != NULL) octstr_destroy(p); } panic(0, "SQLBOX: Redis: connection settings for id '%s' are not specified!", octstr_get_cstr(redis_id)); found: octstr_destroy(p); gwlist_destroy(grplist, NULL); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1 || pool_size == 0) pool_size = 1; if (!(redis_host = cfg_get(grp, octstr_imm("host")))) panic(0, "SQLBOX: Redis: directive 'host' is not specified!"); if (cfg_get_integer(&redis_port, grp, octstr_imm("port")) == -1) panic(0, "SQLBOX: Redis: directive 'port' is not specified!"); redis_password = cfg_get(grp, octstr_imm("password")); cfg_get_integer(&redis_database, grp, octstr_imm("database")); cfg_get_integer(&redis_idle_timeout_secs, grp, octstr_imm("idle-timeout-secs")); /* * ok, ready to connect to Redis */ db_conf = gw_malloc(sizeof(DBConf)); gw_assert(db_conf != NULL); db_conf->redis = gw_malloc(sizeof(RedisConf)); gw_assert(db_conf->redis != NULL); db_conf->redis->host = redis_host; db_conf->redis->port = redis_port; db_conf->redis->password = redis_password; db_conf->redis->database = redis_database; db_conf->redis->idle_timeout_secs = redis_idle_timeout_secs; pool = dbpool_create(DBPOOL_REDIS, db_conf, pool_size); gw_assert(pool != NULL); /* * XXX should a failing connect throw panic?! */ if (dbpool_conn_count(pool) == 0) panic(0,"SQLBOX: Redis: database pool has no connections!"); octstr_destroy(redis_id); res = gw_malloc(sizeof(struct server_type)); gw_assert(res != NULL); res->type = octstr_create("Redis"); res->sql_enter = sqlbox_configure_redis; res->sql_leave = redis_leave; res->sql_fetch_msg = redis_fetch_msg; res->sql_save_msg = redis_save_msg; return res; }
struct server_type *sqlbox_init_oracle(Cfg* cfg) { CfgGroup *grp; List *grplist; Octstr *oracle_user, *oracle_pass, *oracle_tnsname, *oracle_id; Octstr *p = NULL; long pool_size; DBConf *db_conf = NULL; struct server_type *res = NULL; /* * check for all mandatory directives that specify the field names * of the used Oracle table */ if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: Oracle: group 'sqlbox' is not specified!"); if (!(oracle_id = cfg_get(grp, octstr_imm("id")))) panic(0, "SQLBOX: Oracle: directive 'id' is not specified!"); /* * now grap the required information from the 'oracle-connection' group * with the oracle-id we just obtained * * we have to loop through all available Oracle connection definitions * and search for the one we are looking for */ grplist = cfg_get_multi_group(cfg, octstr_imm("oracle-connection")); while (grplist && (grp = (CfgGroup *)gwlist_extract_first(grplist)) != NULL) { p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, oracle_id) == 0) { goto found; } if (p != NULL) octstr_destroy(p); } panic(0, "SQLBOX: Oracle: connection settings for id '%s' are not specified!", octstr_get_cstr(oracle_id)); found: octstr_destroy(p); gwlist_destroy(grplist, NULL); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1 || pool_size == 0) pool_size = 1; if (!(oracle_user = cfg_get(grp, octstr_imm("username")))) panic(0, "SQLBOX: Oracle: directive 'username' is not specified!"); if (!(oracle_pass = cfg_get(grp, octstr_imm("password")))) panic(0, "SQLBOX: Oracle: directive 'password' is not specified!"); if (!(oracle_tnsname = cfg_get(grp, octstr_imm("tnsname")))) panic(0, "SQLBOX: Oracle: directive 'tnsname' is not specified!"); /* * ok, ready to connect to Oracle */ db_conf = gw_malloc(sizeof(DBConf)); gw_assert(db_conf != NULL); db_conf->oracle = gw_malloc(sizeof(OracleConf)); gw_assert(db_conf->oracle != NULL); db_conf->oracle->username = oracle_user; db_conf->oracle->password = oracle_pass; db_conf->oracle->tnsname = oracle_tnsname; pool = dbpool_create(DBPOOL_ORACLE, db_conf, pool_size); gw_assert(pool != NULL); /* * XXX should a failing connect throw panic?! */ if (dbpool_conn_count(pool) == 0) panic(0,"SQLBOX: Oracle: database pool has no connections!"); octstr_destroy(oracle_id); res = gw_malloc(sizeof(struct server_type)); gw_assert(res != NULL); res->type = octstr_create("Oracle"); res->sql_enter = sqlbox_configure_oracle; res->sql_leave = oracle_leave; res->sql_fetch_msg = oracle_fetch_msg; res->sql_save_msg = oracle_save_msg; return res; }
struct dlr_storage *dlr_init_redis(Cfg *cfg) { CfgGroup *grp; List *grplist; Octstr *redis_host, *redis_pass, *redis_id; long redis_port = 0, redis_database = -1, redis_idle_timeout = -1; Octstr *p = NULL; long pool_size; DBConf *db_conf = NULL; /* * Check for all mandatory directives that specify the field names * of the used Redis key */ if (!(grp = cfg_get_single_group(cfg, octstr_imm("dlr-db")))) panic(0, "DLR: Redis: group 'dlr-db' is not specified!"); if (!(redis_id = cfg_get(grp, octstr_imm("id")))) panic(0, "DLR: Redis: directive 'id' is not specified!"); fields = dlr_db_fields_create(grp); gw_assert(fields != NULL); /* * Escaping special quotes for field/table names */ octstr_replace(fields->table, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_smsc, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_ts, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_src, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_dst, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_serv, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_url, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_mask, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_status, octstr_imm("`"), octstr_imm("``")); octstr_replace(fields->field_boxc, octstr_imm("`"), octstr_imm("``")); /* * Now grab the required information from the 'redis-connection' group * with the redis-id we just obtained. * * We have to loop through all available Redis connection definitions * and search for the one we are looking for. */ grplist = cfg_get_multi_group(cfg, octstr_imm("redis-connection")); while (grplist && (grp = gwlist_extract_first(grplist)) != NULL) { p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, redis_id) == 0) { goto found; } if (p != NULL) octstr_destroy(p); } panic(0, "DLR: Redis: connection settings for id '%s' are not specified!", octstr_get_cstr(redis_id)); found: octstr_destroy(p); gwlist_destroy(grplist, NULL); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1 || pool_size == 0) pool_size = 1; if (!(redis_host = cfg_get(grp, octstr_imm("host")))) panic(0, "DLR: Redis: directive 'host' is not specified!"); if (cfg_get_integer(&redis_port, grp, octstr_imm("port")) == -1) panic(0, "DLR: Redis: directive 'port' is not specified!"); redis_pass = cfg_get(grp, octstr_imm("password")); cfg_get_integer(&redis_database, grp, octstr_imm("database")); cfg_get_integer(&redis_idle_timeout, grp, octstr_imm("idle-timeout")); /* * Ok, ready to connect to Redis */ db_conf = gw_malloc(sizeof(DBConf)); gw_assert(db_conf != NULL); db_conf->redis = gw_malloc(sizeof(RedisConf)); gw_assert(db_conf->redis != NULL); db_conf->redis->host = redis_host; db_conf->redis->port = redis_port; db_conf->redis->password = redis_pass; db_conf->redis->database = redis_database; db_conf->redis->idle_timeout = redis_idle_timeout; pool = dbpool_create(DBPOOL_REDIS, db_conf, pool_size); gw_assert(pool != NULL); /* * Panic on failure to connect. Should we just try to reconnect? */ if (dbpool_conn_count(pool) == 0) panic(0,"DLR: Redis: database pool has no connections!"); octstr_destroy(redis_id); return &handles; }
static void init_sqlbox(Cfg *cfg) { CfgGroup *grp; Octstr *logfile; long lvl; /* some default values */ sqlbox_port_ssl = 0; bearerbox_port = BB_DEFAULT_SMSBOX_PORT; bearerbox_port_ssl = 0; logfile = NULL; lvl = 0; /* * first we take the port number in bearerbox and other values from the * core group in configuration file */ grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")); if (cfg_get_integer(&bearerbox_port, grp, octstr_imm("bearerbox-port")) == -1) panic(0, "Missing or bad 'bearerbox-port' in sqlbox group"); #ifdef HAVE_LIBSSL cfg_get_bool(&bearerbox_port_ssl, grp, octstr_imm("smsbox-port-ssl")); conn_config_ssl(grp); #endif grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")); if (grp == NULL) panic(0, "No 'sqlbox' group in configuration"); bearerbox_host = cfg_get( grp, octstr_imm("bearerbox-host")); if (bearerbox_host == NULL) bearerbox_host = octstr_create(BB_DEFAULT_HOST); sqlbox_id = cfg_get(grp, octstr_imm("smsbox-id")); global_sender = cfg_get(grp, octstr_imm("global-sender")); if (cfg_get_integer(&sqlbox_port, grp, octstr_imm("smsbox-port")) == -1) sqlbox_port = 13005; /* setup limit per cycle */ if (cfg_get_integer(&limit_per_cycle, grp, octstr_imm("limit-per-cycle")) == -1) limit_per_cycle = DEFAULT_LIMIT_PER_CYCLE; /* set up save parameters */ if (cfg_get_bool(&save_mo, grp, octstr_imm("save-mo")) == -1) save_mo = 1; if (cfg_get_bool(&save_mt, grp, octstr_imm("save-mt")) == -1) save_mt = 1; if (cfg_get_bool(&save_dlr, grp, octstr_imm("save-dlr")) == -1) save_dlr = 1; /* setup logfile stuff */ logfile = cfg_get(grp, octstr_imm("log-file")); cfg_get_integer(&lvl, grp, octstr_imm("log-level")); if (logfile != NULL) { info(0, "Starting to log to file %s level %ld", octstr_get_cstr(logfile), lvl); log_open(octstr_get_cstr(logfile), lvl, GW_NON_EXCL); octstr_destroy(logfile); } sql_type = sqlbox_init_sql(cfg); if (sql_type == NULL) { panic(0, "No proper SQL server defined."); } gw_sql_enter(cfg); sqlbox_status = SQL_RUNNING; }
void sqlbox_configure_oracle(Cfg* cfg) { DBPoolConn *pc; CfgGroup *grp; Octstr *sql; if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: Oracle: group 'sqlbox' is not specified!"); sqlbox_logtable = cfg_get(grp, octstr_imm("sql-log-table")); if (sqlbox_logtable == NULL) { panic(0, "Parameter 'sql-log-table' not configured."); } sqlbox_insert_table = cfg_get(grp, octstr_imm("sql-insert-table")); if (sqlbox_insert_table == NULL) { panic(0, "Parameter 'sql-insert-table' not configured."); } pc = dbpool_conn_consume(pool); if (pc == NULL) { error(0, "Oracle: DBPool Error!"); return; } /* create send_sms && sent_sms tables if they do not exist */ sql = octstr_format(SQLBOX_ORACLE_CREATE_LOG_TABLE, sqlbox_logtable, sqlbox_logtable); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); sql = octstr_format(SQLBOX_ORACLE_CREATE_INSERT_TABLE, sqlbox_insert_table, sqlbox_insert_table); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); /* * Oracle implementation using a sequence and a trigger for auto_increment fields. */ sql = octstr_format(SQLBOX_ORACLE_CREATE_LOG_SEQUENCE, sqlbox_logtable); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); sql = octstr_format(SQLBOX_ORACLE_CREATE_INSERT_SEQUENCE, sqlbox_insert_table); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); sql = octstr_format(SQLBOX_ORACLE_CREATE_LOG_TRIGGER, sqlbox_logtable, sqlbox_logtable, sqlbox_logtable); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); sql = octstr_format(SQLBOX_ORACLE_CREATE_INSERT_TRIGGER, sqlbox_insert_table, sqlbox_insert_table, sqlbox_insert_table); #if defined(SQLBOX_TRACE) debug("SQLBOX", 0, "sql: %s", octstr_get_cstr(sql)); #endif sql_update(pc, sql, NULL); octstr_destroy(sql); /* end table creation */ dbpool_conn_produce(pc); }
struct server_type *sqlbox_init_mysql(Cfg* cfg) { CfgGroup *grp; List *grplist; Octstr *mysql_host, *mysql_user, *mysql_pass, *mysql_db, *mysql_id; Octstr *p = NULL; long pool_size, mysql_port; int have_port; DBConf *db_conf = NULL; struct server_type *res = NULL; /* * check for all mandatory directives that specify the field names * of the used MySQL table */ if (!(grp = cfg_get_single_group(cfg, octstr_imm("sqlbox")))) panic(0, "SQLBOX: MySQL: group 'sqlbox' is not specified!"); if (!(mysql_id = cfg_get(grp, octstr_imm("id")))) panic(0, "SQLBOX: MySQL: directive 'id' is not specified!"); /* * now grap the required information from the 'mysql-connection' group * with the mysql-id we just obtained * * we have to loop through all available MySQL connection definitions * and search for the one we are looking for */ grplist = cfg_get_multi_group(cfg, octstr_imm("mysql-connection")); while (grplist && (grp = (CfgGroup *)gwlist_extract_first(grplist)) != NULL) { p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, mysql_id) == 0) { goto found; } if (p != NULL) octstr_destroy(p); } panic(0, "SQLBOX: MySQL: connection settings for id '%s' are not specified!", octstr_get_cstr(mysql_id)); found: octstr_destroy(p); gwlist_destroy(grplist, NULL); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1 || pool_size == 0) pool_size = 1; if (!(mysql_host = cfg_get(grp, octstr_imm("host")))) panic(0, "SQLBOX: MySQL: directive 'host' is not specified!"); if (!(mysql_user = cfg_get(grp, octstr_imm("username")))) panic(0, "SQLBOX: MySQL: directive 'username' is not specified!"); if (!(mysql_pass = cfg_get(grp, octstr_imm("password")))) panic(0, "SQLBOX: MySQL: directive 'password' is not specified!"); if (!(mysql_db = cfg_get(grp, octstr_imm("database")))) panic(0, "SQLBOX: MySQL: directive 'database' is not specified!"); have_port = (cfg_get_integer(&mysql_port, grp, octstr_imm("port")) != -1); /* * ok, ready to connect to MySQL */ db_conf = gw_malloc(sizeof(DBConf)); gw_assert(db_conf != NULL); db_conf->mysql = gw_malloc(sizeof(MySQLConf)); gw_assert(db_conf->mysql != NULL); db_conf->mysql->host = mysql_host; db_conf->mysql->username = mysql_user; db_conf->mysql->password = mysql_pass; db_conf->mysql->database = mysql_db; if (have_port) { db_conf->mysql->port = mysql_port; } pool = dbpool_create(DBPOOL_MYSQL, db_conf, pool_size); gw_assert(pool != NULL); /* * XXX should a failing connect throw panic?! */ if (dbpool_conn_count(pool) == 0) panic(0,"SQLBOX: MySQL: database pool has no connections!"); octstr_destroy(mysql_id); res = gw_malloc(sizeof(struct server_type)); gw_assert(res != NULL); res->type = octstr_create("MySQL"); res->sql_enter = sqlbox_configure_mysql; res->sql_leave = mysql_leave; res->sql_fetch_msg = mysql_fetch_msg; res->sql_save_msg = mysql_save_msg; return res; }
struct dlr_storage *dlr_init_mongodb(Cfg *cfg) { CfgGroup *grp; List *grplist; Octstr *mongodb_host, *mongodb_user, *mongodb_pass, *mongodb_db, *mongodb_id; long pool_size; long mongodb_port = 27017; DBConf *db_conf = NULL; int found; if ((grp = cfg_get_single_group(cfg, octstr_imm("dlr-db"))) == NULL) { panic(0, "DLR: MongoDB: group 'dlr-db' is not specified!"); } if (!(mongodb_id = cfg_get(grp, octstr_imm("id")))) { panic(0, "DLR: MongoDB: directive 'id' is not specified!"); } /* initialize database fields */ fields = dlr_db_fields_create(grp); gw_assert(fields != NULL); grplist = cfg_get_multi_group(cfg, octstr_imm("mongodb-connection")); found = 0; while (grplist && (grp = gwlist_extract_first(grplist)) != NULL) { Octstr *p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, mongodb_id) == 0) { found = 1; } if (p != NULL) { octstr_destroy(p); } if (found == 1) { break; } } gwlist_destroy(grplist, NULL); if (found == 0) { panic(0, "DLR: MongoDB: connection settings for id '%s' are not specified!", octstr_get_cstr(mongodb_id)); } if (!(mongodb_host = cfg_get(grp, octstr_imm("host")))) { panic(0, "DLR: MongoDB: directive 'host' is not specified!"); } if (!(mongodb_db = cfg_get(grp, octstr_imm("database")))) { panic(0, "DLR: MongoDB: directive 'database' is not specified!"); } /* Keep a global reference to the database and table */ mongodb_database = octstr_get_cstr(mongodb_db); mongodb_table = octstr_get_cstr(fields->table); mongodb_namespace = (char *)gw_malloc(strlen(mongodb_database) + strlen(mongodb_table) + 2); /* . and \0 */ sprintf(mongodb_namespace, "%s.%s", mongodb_database, mongodb_table); mongodb_user = cfg_get(grp, octstr_imm("username")); mongodb_pass = cfg_get(grp, octstr_imm("password")); cfg_get_integer(&mongodb_port, grp, octstr_imm("port")); /* optional */ if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1) { pool_size = 1; } /* ok we are ready to create dbpool */ db_conf = gw_malloc(sizeof(*db_conf)); gw_assert(db_conf != NULL); db_conf->mongodb = gw_malloc(sizeof(MongoDBConf)); gw_assert(db_conf->mongodb != NULL); db_conf->mongodb->host = mongodb_host; db_conf->mongodb->port = mongodb_port; db_conf->mongodb->username = mongodb_user; db_conf->mongodb->password = mongodb_pass; db_conf->mongodb->database = mongodb_db; pool = dbpool_create(DBPOOL_MONGODB, db_conf, pool_size); gw_assert(pool != NULL); if (dbpool_conn_count(pool) == 0) { panic(0, "DLR: MongoDB: Could not establish connection(s)."); } octstr_destroy(mongodb_id); return &handles; }
static Cfg *init_bearerbox(Cfg *cfg) { CfgGroup *grp; Octstr *log, *val; long loglevel; int lf, m; #ifdef HAVE_LIBSSL Octstr *ssl_server_cert_file; Octstr *ssl_server_key_file; int ssl_enabled = 0; #endif /* HAVE_LIBSSL */ /* defaults: use localtime and markers for access-log */ lf = m = 1; grp = cfg_get_single_group(cfg, octstr_imm("core")); log = cfg_get(grp, octstr_imm("log-file")); if (log != NULL) { if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1) loglevel = 0; log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL); octstr_destroy(log); } if (check_config(cfg) == -1) panic(0, "Cannot start with corrupted configuration"); /* determine which timezone we use for access logging */ if ((log = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(log, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(log); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* custom access-log format */ if ((log = cfg_get(grp, octstr_imm("access-log-format"))) != NULL) { bb_alog_init(log); octstr_destroy(log); } /* open access-log file */ if ((log = cfg_get(grp, octstr_imm("access-log"))) != NULL) { alog_open(octstr_get_cstr(log), lf, m ? 0 : 1); octstr_destroy(log); } log = cfg_get(grp, octstr_imm("store-file")); /* initialize the store file */ if (log != NULL) { store_init(log); octstr_destroy(log); } conn_config_ssl (grp); /* * Make sure we have "ssl-server-cert-file" and "ssl-server-key-file" specified * in the core group since we need it to run SSL-enabled internal box * connections configured via "smsbox-port-ssl = yes" and "wapbox-port-ssl = yes". * Check only these, because for "admin-port-ssl" and "sendsms-port-ssl" for the * SSL-enabled HTTP servers are probed within gw/bb_http.c:httpadmin_start() */ #ifdef HAVE_LIBSSL ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file")); ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file")); if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) { /* we are fine, at least files are specified in the configuration */ } else { cfg_get_bool(&ssl_enabled, grp, octstr_imm("smsbox-port-ssl")); cfg_get_bool(&ssl_enabled, grp, octstr_imm("wapbox-port-ssl")); if (ssl_enabled) { panic(0, "You MUST specify cert and key files within core group for SSL-enabled inter-box connections!"); } } octstr_destroy(ssl_server_cert_file); octstr_destroy(ssl_server_key_file); #endif /* HAVE_LIBSSL */ /* if all seems to be OK by the first glimpse, real start-up */ outgoing_sms = list_create(); incoming_sms = list_create(); outgoing_wdp = list_create(); incoming_wdp = list_create(); outgoing_sms_counter = counter_create(); incoming_sms_counter = counter_create(); outgoing_wdp_counter = counter_create(); incoming_wdp_counter = counter_create(); status_mutex = mutex_create(); setup_signal_handlers(); /* http-admin is REQUIRED */ httpadmin_start(cfg); if (cfg_get_integer(&max_incoming_sms_qlength, grp, octstr_imm("maximum-queue-length")) == -1) max_incoming_sms_qlength = -1; else { warning(0, "Option 'maximum-queue-length' is deprecated! Please use" " 'sms-incoming-queue-limit' instead!"); } if (max_incoming_sms_qlength == -1 && cfg_get_integer(&max_incoming_sms_qlength, grp, octstr_imm("sms-incoming-queue-limit")) == -1) max_incoming_sms_qlength = -1; #ifndef NO_SMS { List *list; list = cfg_get_multi_group(cfg, octstr_imm("smsc")); if (list != NULL) { start_smsc(cfg); list_destroy(list, NULL); } } #endif #ifndef NO_WAP grp = cfg_get_single_group(cfg, octstr_imm("core")); val = cfg_get(grp, octstr_imm("wdp-interface-name")); if (val != NULL && octstr_len(val) > 0) start_udp(cfg); octstr_destroy(val); if (cfg_get_single_group(cfg, octstr_imm("wapbox")) != NULL) start_wap(cfg); #endif return cfg; }
int main(int argc, char **argv) { char id[UUID_STR_LEN + 1]; int cf_index, ret, type; Octstr *os, *store_type, *store_location, *status; Msg *msg; CfgGroup *grp; conf_file = NULL; gwlib_init(); //This can be overwritten with the -v flag at runtime log_set_output_level(DEFAULT_LOG_LEVEL); cf_index = get_and_set_debugs(argc, argv, check_args); if (argv[cf_index] == NULL) { print_usage(argv[0]); goto error; } if (conf_file == NULL) conf_file = octstr_create("kannel.conf"); cfg = cfg_create(conf_file); if (cfg_read(cfg) == -1) panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(conf_file)); info(0, "1"); grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) { printf("FATAL: Could not load Kannel's core group. Exiting.\n"); return 2; } store_location = cfg_get(grp, octstr_imm("store-location")); store_type = cfg_get(grp, octstr_imm("store-type")); store_init(store_type, store_location, -1, msg_pack, msg_unpack_wrapper); switch (command) { case COMMAND_LIST: printf("Listing records %d -> %d\n", list_from+1, list_limit); print_header(); store_load(print_msg); if (counter == 0) { printf("|%60s%14s%60s|\n", "", "Store is Empty", ""); } print_sep(); break; case COMMAND_DELETE: store_load(msg_count); msg = msg_create(ack); msg->ack.nack = ack_failed; msg->ack.time = time(NULL); uuid_parse(octstr_get_cstr(param_1), msg->ack.id); ret = store_save(msg); if (ret == 0) { printf("Deleted message %s\n", octstr_get_cstr(param_1)); counter--; } else { printf("Could not delete message %s\n", octstr_get_cstr(param_1)); } msg_destroy(msg); break; case COMMAND_EXPORT: counter = 0; type = 0; list = gwlist_create(); store_load(msg_push); printf("Exporting %ld messages...\n", gwlist_len(list)); if ((octstr_compare(param_1, octstr_imm("file")) == 0) || (octstr_compare(param_1, octstr_imm("spool")) == 0)) { store_shutdown(); store_init(param_1, param_2, -1, msg_pack, msg_unpack_wrapper); store_load(msg_count); while ((os = gwlist_extract_first(list)) != NULL) { msg = msg_unpack_wrapper(os); if (msg != NULL) { ret = store_save(msg); if (ret == 0) { counter++; } else { printf("Error saving message\n"); } } else { printf("Error extracting message\n"); } msg_destroy(msg); } status = NULL; } else if (octstr_compare(param_1, octstr_imm("text")) == 0) { status = store_status(BBSTATUS_TEXT); } else if (octstr_compare(param_1, octstr_imm("html")) == 0) { status = store_status(BBSTATUS_HTML); } else if (octstr_compare(param_1, octstr_imm("xml")) == 0) { status = store_status(BBSTATUS_XML); } else { status = NULL; } if (status != NULL) { file = fopen(octstr_get_cstr(param_2), "w"); if (file == NULL) { error(errno, "Failed to open '%s' for writing, cannot create output file", octstr_get_cstr(param_2)); return -1; } octstr_print(file, status); fflush(file); if (file != NULL) fclose(file); //printf("%s", octstr_get_cstr(status)); } gwlist_destroy(list, octstr_destroy_item); break; default: break; } octstr_destroy(store_type); octstr_destroy(store_location); cfg_destroy(cfg); store_shutdown(); error: gwlib_shutdown(); return 1; }
struct dlr_storage *dlr_init_oracle(Cfg *cfg) { CfgGroup *grp; List *grplist; long pool_size; DBConf *db_conf = NULL; Octstr *id, *username, *password, *tnsname; int found; if ((grp = cfg_get_single_group(cfg, octstr_imm("dlr-db"))) == NULL) panic(0, "DLR: ORACLE: group 'dlr-db' is not specified!"); if (!(id = cfg_get(grp, octstr_imm("id")))) panic(0, "DLR: ORACLE: directive 'id' is not specified!"); /* initialize database fields */ fields = dlr_db_fields_create(grp); gw_assert(fields != NULL); grplist = cfg_get_multi_group(cfg, octstr_imm("oracle-connection")); found = 0; while (grplist && (grp = gwlist_extract_first(grplist)) != NULL) { Octstr *p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, id) == 0) { found = 1; } if (p != NULL) octstr_destroy(p); if (found == 1) break; } gwlist_destroy(grplist, NULL); if (found == 0) panic(0, "DLR: ORACLE: connection settings for id '%s' are not specified!", octstr_get_cstr(id)); username = cfg_get(grp, octstr_imm("username")); password = cfg_get(grp, octstr_imm("password")); tnsname = cfg_get(grp, octstr_imm("tnsname")); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1) pool_size = 1; if (username == NULL || password == NULL || tnsname == NULL) panic(0, "DLR: ORACLE: connection settings missing for id '%s', please" " check you configuration.",octstr_get_cstr(id)); /* ok we are ready to create dbpool */ db_conf = gw_malloc(sizeof(*db_conf)); db_conf->oracle = gw_malloc(sizeof(OracleConf)); db_conf->oracle->username = username; db_conf->oracle->password = password; db_conf->oracle->tnsname = tnsname; pool = dbpool_create(DBPOOL_ORACLE, db_conf, pool_size); gw_assert(pool != NULL); if (dbpool_conn_count(pool) == 0) panic(0, "DLR: ORACLE: Couldnot establish oracle connection(s)."); octstr_destroy(id); return &handles; }
static Cfg *init_bearerbox(Cfg *cfg) { CfgGroup *grp; Octstr *log, *val; long loglevel, store_dump_freq, value; int lf, m; #ifdef HAVE_LIBSSL Octstr *ssl_server_cert_file; Octstr *ssl_server_key_file; int ssl_enabled = 0; #endif /* HAVE_LIBSSL */ Octstr *http_proxy_host = NULL; long http_proxy_port = -1; int http_proxy_ssl = 0; List *http_proxy_exceptions = NULL; Octstr *http_proxy_username = NULL; Octstr *http_proxy_password = NULL; Octstr *http_proxy_exceptions_regex = NULL; /* defaults: use localtime and markers for access-log */ lf = m = 1; grp = cfg_get_single_group(cfg, octstr_imm("core")); log = cfg_get(grp, octstr_imm("log-file")); if (log != NULL) { if (cfg_get_integer(&loglevel, grp, octstr_imm("log-level")) == -1) loglevel = 0; log_open(octstr_get_cstr(log), loglevel, GW_NON_EXCL); octstr_destroy(log); } if ((val = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) { long level; Octstr *facility; if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) { log_set_syslog_facility(octstr_get_cstr(facility)); octstr_destroy(facility); } if (octstr_compare(val, octstr_imm("none")) == 0) { log_set_syslog(NULL, 0); } else if (octstr_parse_long(&level, val, 0, 10) > 0) { log_set_syslog("bearerbox", level); } octstr_destroy(val); } else { log_set_syslog(NULL, 0); } if (check_config(cfg) == -1) panic(0, "Cannot start with corrupted configuration"); /* determine which timezone we use for access logging */ if ((log = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(log, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(log); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* custom access-log format */ if ((log = cfg_get(grp, octstr_imm("access-log-format"))) != NULL) { bb_alog_init(log); octstr_destroy(log); } /* open access-log file */ if ((log = cfg_get(grp, octstr_imm("access-log"))) != NULL) { alog_open(octstr_get_cstr(log), lf, m ? 0 : 1); octstr_destroy(log); } if (cfg_get_integer(&store_dump_freq, grp, octstr_imm("store-dump-freq")) == -1) store_dump_freq = -1; log = cfg_get(grp, octstr_imm("store-file")); /* initialize the store file */ if (log != NULL) { warning(0, "'store-file' option deprecated, please use 'store-location' and 'store-type' instead."); val = octstr_create("file"); } else { log = cfg_get(grp, octstr_imm("store-location")); val = cfg_get(grp, octstr_imm("store-type")); } if (store_init(val, log, store_dump_freq, msg_pack, msg_unpack_wrapper) == -1) panic(0, "Could not start with store init failed."); octstr_destroy(val); octstr_destroy(log); cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port")); #ifdef HAVE_LIBSSL cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl")); #endif /* HAVE_LIBSSL */ http_proxy_host = cfg_get(grp, octstr_imm("http-proxy-host")); http_proxy_username = cfg_get(grp, octstr_imm("http-proxy-username")); http_proxy_password = cfg_get(grp, octstr_imm("http-proxy-password")); http_proxy_exceptions = cfg_get_list(grp, octstr_imm("http-proxy-exceptions")); http_proxy_exceptions_regex = cfg_get(grp, octstr_imm("http-proxy-exceptions-regex")); conn_config_ssl (grp); /* * Make sure we have "ssl-server-cert-file" and "ssl-server-key-file" specified * in the core group since we need it to run SSL-enabled internal box * connections configured via "smsbox-port-ssl = yes" and "wapbox-port-ssl = yes". * Check only these, because for "admin-port-ssl" and "sendsms-port-ssl" for the * SSL-enabled HTTP servers are probed within gw/bb_http.c:httpadmin_start() */ #ifdef HAVE_LIBSSL ssl_server_cert_file = cfg_get(grp, octstr_imm("ssl-server-cert-file")); ssl_server_key_file = cfg_get(grp, octstr_imm("ssl-server-key-file")); if (ssl_server_cert_file != NULL && ssl_server_key_file != NULL) { /* we are fine, at least files are specified in the configuration */ } else { cfg_get_bool(&ssl_enabled, grp, octstr_imm("smsbox-port-ssl")); cfg_get_bool(&ssl_enabled, grp, octstr_imm("wapbox-port-ssl")); if (ssl_enabled) { panic(0, "You MUST specify cert and key files within core group for SSL-enabled inter-box connections!"); } } octstr_destroy(ssl_server_cert_file); octstr_destroy(ssl_server_key_file); #endif /* HAVE_LIBSSL */ /* if all seems to be OK by the first glimpse, real start-up */ outgoing_sms = gwlist_create(); incoming_sms = gwlist_create(); outgoing_wdp = gwlist_create(); incoming_wdp = gwlist_create(); outgoing_sms_counter = counter_create(); incoming_sms_counter = counter_create(); incoming_dlr_counter = counter_create(); outgoing_dlr_counter = counter_create(); outgoing_wdp_counter = counter_create(); incoming_wdp_counter = counter_create(); status_mutex = mutex_create(); outgoing_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(outgoing_sms_load, 60); load_add_interval(outgoing_sms_load, 300); load_add_interval(outgoing_sms_load, -1); incoming_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(incoming_sms_load, 60); load_add_interval(incoming_sms_load, 300); load_add_interval(incoming_sms_load, -1); incoming_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(incoming_dlr_load, 60); load_add_interval(incoming_dlr_load, 300); load_add_interval(incoming_dlr_load, -1); outgoing_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(outgoing_dlr_load, 60); load_add_interval(outgoing_dlr_load, 300); load_add_interval(outgoing_dlr_load, -1); setup_signal_handlers(); /* http-admin is REQUIRED */ httpadmin_start(cfg); if (cfg_get_integer(&max_incoming_sms_qlength, grp, octstr_imm("maximum-queue-length")) == -1) max_incoming_sms_qlength = -1; else { warning(0, "Option 'maximum-queue-length' is deprecated! Please use" " 'sms-incoming-queue-limit' instead!"); } if (max_incoming_sms_qlength == -1 && cfg_get_integer(&max_incoming_sms_qlength, grp, octstr_imm("sms-incoming-queue-limit")) == -1) max_incoming_sms_qlength = -1; if (cfg_get_integer(&max_outgoing_sms_qlength, grp, octstr_imm("sms-outgoing-queue-limit")) == -1) max_outgoing_sms_qlength = -1; if (max_outgoing_sms_qlength < 0) max_outgoing_sms_qlength = DEFAULT_OUTGOING_SMS_QLENGTH; if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0) http_set_client_timeout(value); #ifndef NO_SMS { List *list; list = cfg_get_multi_group(cfg, octstr_imm("smsc")); if (list != NULL) { gwlist_destroy(list, NULL); if (start_smsc(cfg) == -1) { panic(0, "Unable to start SMSCs."); return NULL; } } } #endif #ifndef NO_WAP grp = cfg_get_single_group(cfg, octstr_imm("core")); val = cfg_get(grp, octstr_imm("wdp-interface-name")); if (val != NULL && octstr_len(val) > 0) start_udp(cfg); octstr_destroy(val); if (cfg_get_single_group(cfg, octstr_imm("wapbox")) != NULL) start_wap(cfg); #endif if (http_proxy_host != NULL && http_proxy_port > 0) { http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl, http_proxy_exceptions, http_proxy_username, http_proxy_password, http_proxy_exceptions_regex); } octstr_destroy(http_proxy_host); octstr_destroy(http_proxy_username); octstr_destroy(http_proxy_password); octstr_destroy(http_proxy_exceptions_regex); gwlist_destroy(http_proxy_exceptions, octstr_destroy_item); return cfg; }
static Cfg *init_wapbox(Cfg *cfg) { CfgGroup *grp; Octstr *s; Octstr *logfile; int lf, m; long value; lf = m = 1; cfg_dump(cfg); /* * Extract info from the core group. */ grp = cfg_get_single_group(cfg, octstr_imm("core")); if (grp == NULL) panic(0, "No 'core' group in configuration."); if (cfg_get_integer(&bearerbox_port,grp,octstr_imm("wapbox-port")) == -1) panic(0, "No 'wapbox-port' in core group"); #ifdef HAVE_LIBSSL cfg_get_bool(&bearerbox_ssl, grp, octstr_imm("wapbox-port-ssl")); #endif /* HAVE_LIBSSL */ /* load parameters that could be later reloaded */ config_reload(0); conn_config_ssl(grp); /* * And the rest of the pull info comes from the wapbox group. */ grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) panic(0, "No 'wapbox' group in configuration."); bearerbox_host = cfg_get(grp, octstr_imm("bearerbox-host")); if (cfg_get_integer(&timer_freq, grp, octstr_imm("timer-freq")) == -1) timer_freq = DEFAULT_TIMER_FREQ; logfile = cfg_get(grp, octstr_imm("log-file")); if (logfile != NULL) { log_open(octstr_get_cstr(logfile), logfilelevel, GW_NON_EXCL); info(0, "Starting to log to file %s level %ld", octstr_get_cstr(logfile), logfilelevel); } octstr_destroy(logfile); if ((s = cfg_get(grp, octstr_imm("syslog-level"))) != NULL) { long level; Octstr *facility; if ((facility = cfg_get(grp, octstr_imm("syslog-facility"))) != NULL) { log_set_syslog_facility(octstr_get_cstr(facility)); octstr_destroy(facility); } if (octstr_compare(s, octstr_imm("none")) == 0) { log_set_syslog(NULL, 0); debug("wap", 0, "syslog parameter is none"); } else if (octstr_parse_long(&level, s, 0, 10) > 0) { log_set_syslog("wapbox", level); debug("wap", 0, "syslog parameter is %ld", level); } octstr_destroy(s); } else { log_set_syslog(NULL, 0); debug("wap", 0, "no syslog parameter"); } /* determine which timezone we use for access logging */ if ((s = cfg_get(grp, octstr_imm("access-log-time"))) != NULL) { lf = (octstr_case_compare(s, octstr_imm("gmt")) == 0) ? 0 : 1; octstr_destroy(s); } /* should predefined markers be used, ie. prefixing timestamp */ cfg_get_bool(&m, grp, octstr_imm("access-log-clean")); /* open access-log file */ if ((s = cfg_get(grp, octstr_imm("access-log"))) != NULL) { info(0, "Logging accesses to '%s'.", octstr_get_cstr(s)); alog_open(octstr_get_cstr(s), lf, m ? 0 : 1); octstr_destroy(s); } if (cfg_get_integer(&value, grp, octstr_imm("http-timeout")) == 0) http_set_client_timeout(value); /* configure the 'wtls' group */ #if (HAVE_WTLS_OPENSSL) /* Load up the necessary keys */ grp = cfg_get_single_group(cfg, octstr_imm("wtls")); if (grp != NULL) { if ((s = cfg_get(grp, octstr_imm("certificate-file"))) != NULL) { if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "certificate file not set"); } else { /* Load the certificate into the necessary parameter */ get_cert_from_file(s, &x509_cert); gw_assert(x509_cert != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } octstr_destroy(s); } else panic(0, "No 'certificate-file' in wtls group"); if ((s = cfg_get(grp, octstr_imm("privatekey-file"))) != NULL) { Octstr *password; password = cfg_get(grp, octstr_imm("privatekey-password")); if (octstr_compare(s, octstr_imm("none")) == 0) { debug("bbox", 0, "privatekey-file not set"); } else { /* Load the private key into the necessary parameter */ get_privkey_from_file(s, &private_key, password); gw_assert(private_key != NULL); debug("bbox", 0, "certificate parameter is %s", octstr_get_cstr(s)); } if (password != NULL) octstr_destroy(password); octstr_destroy(s); } else panic(0, "No 'privatekey-file' in wtls group"); } #endif /* * Check if we have a 'radius-acct' proxy group and start the * corresponding thread for the proxy. */ grp = cfg_get_single_group(cfg, octstr_imm("radius-acct")); if (grp) { radius_acct_init(grp); } /* * We pass ppg configuration groups to the ppg module. */ grp = cfg_get_single_group(cfg, octstr_imm("ppg")); if (grp == NULL) { cfg_destroy(cfg); return NULL; } return cfg; }
struct dlr_storage *dlr_init_pgsql(Cfg *cfg) { CfgGroup *grp; List *grplist; Octstr *pgsql_host, *pgsql_user, *pgsql_pass, *pgsql_db, *pgsql_id; long pgsql_port = 0; Octstr *p = NULL; long pool_size; DBConf *db_conf = NULL; /* * check for all mandatory directives that specify the field names * of the table used */ if (!(grp = cfg_get_single_group(cfg, octstr_imm("dlr-db")))) panic(0, "DLR: PgSQL: group 'dlr-db' is not specified!"); if (!(pgsql_id = cfg_get(grp, octstr_imm("id")))) panic(0, "DLR: PgSQL: directive 'id' is not specified!"); fields = dlr_db_fields_create(grp); gw_assert(fields != NULL); /* * now grap the required information from the 'pgsql-connection' group * with the pgsql-id we just obtained * * we have to loop through all available PostgreSQL connection definitions * and search for the one we are looking for */ grplist = cfg_get_multi_group(cfg, octstr_imm("pgsql-connection")); while (grplist && (grp = gwlist_extract_first(grplist)) != NULL) { p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, pgsql_id) == 0) { goto found; } if (p != NULL) octstr_destroy(p); } panic(0, "DLR: PgSQL: connection settings for id '%s' are not specified!", octstr_get_cstr(pgsql_id)); found: octstr_destroy(p); gwlist_destroy(grplist, NULL); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1 || pool_size == 0) pool_size = 1; if (!(pgsql_host = cfg_get(grp, octstr_imm("host")))) panic(0, "DLR: PgSQL: directive 'host' is not specified!"); if (!(pgsql_user = cfg_get(grp, octstr_imm("username")))) panic(0, "DLR: PgSQL: directive 'username' is not specified!"); if (!(pgsql_pass = cfg_get(grp, octstr_imm("password")))) panic(0, "DLR: PgSQL: directive 'password' is not specified!"); if (!(pgsql_db = cfg_get(grp, octstr_imm("database")))) panic(0, "DLR: PgSQL: directive 'database' is not specified!"); cfg_get_integer(&pgsql_port, grp, octstr_imm("port")); /* optional */ /* * ok, ready to connect to the database */ db_conf = gw_malloc(sizeof(DBConf)); gw_assert(db_conf != NULL); db_conf->pgsql = gw_malloc(sizeof(PgSQLConf)); gw_assert(db_conf->pgsql != NULL); db_conf->pgsql->host = pgsql_host; db_conf->pgsql->port = pgsql_port; db_conf->pgsql->username = pgsql_user; db_conf->pgsql->password = pgsql_pass; db_conf->pgsql->database = pgsql_db; pool = dbpool_create(DBPOOL_PGSQL, db_conf, pool_size); gw_assert(pool != NULL); /* * XXX should a failing connect throw panic?! */ if (dbpool_conn_count(pool) == 0) panic(0,"DLR: PgSQL: database pool has no connections!"); octstr_destroy(pgsql_id); return &handles; }
/* * Read all reloadable configuration directives */ static void config_reload(int reload) { Cfg *cfg; CfgGroup *grp; List *groups; long map_url_max; Octstr *s; long i; long new_value; int new_bool; Octstr *http_proxy_host; Octstr *http_interface_name; long http_proxy_port; int http_proxy_ssl = 0; List *http_proxy_exceptions; Octstr *http_proxy_username; Octstr *http_proxy_password; Octstr *http_proxy_exceptions_regex; int warn_map_url = 0; /* XXX TO-DO: if(reload) implement wapbox.suspend/mutex.lock */ if (reload) debug("config_reload", 0, "Reloading configuration"); /* * NOTE: we could lstat config file and only reload if it was modified, * but as we have a include directive, we don't know every file's * timestamp at this point */ cfg = cfg_create(config_filename); if (cfg_read(cfg) == -1) { warning(0, "Couldn't %sload configuration from `%s'.", (reload ? "re" : ""), octstr_get_cstr(config_filename)); return; } grp = cfg_get_single_group(cfg, octstr_imm("core")); http_proxy_host = cfg_get(grp, octstr_imm("http-proxy-host")); http_proxy_port = -1; cfg_get_integer(&http_proxy_port, grp, octstr_imm("http-proxy-port")); #ifdef HAVE_LIBSSL cfg_get_bool(&http_proxy_ssl, grp, octstr_imm("http-proxy-ssl")); #endif /* HAVE_LIBSSL */ http_proxy_username = cfg_get(grp, octstr_imm("http-proxy-username")); http_proxy_password = cfg_get(grp, octstr_imm("http-proxy-password")); http_proxy_exceptions = cfg_get_list(grp, octstr_imm("http-proxy-exceptions")); http_proxy_exceptions_regex = cfg_get(grp, octstr_imm("http-proxy-exceptions-regex")); if (http_proxy_host != NULL && http_proxy_port > 0) { http_use_proxy(http_proxy_host, http_proxy_port, http_proxy_ssl, http_proxy_exceptions, http_proxy_username, http_proxy_password, http_proxy_exceptions_regex); } octstr_destroy(http_proxy_host); octstr_destroy(http_proxy_username); octstr_destroy(http_proxy_password); octstr_destroy(http_proxy_exceptions_regex); gwlist_destroy(http_proxy_exceptions, octstr_destroy_item); grp = cfg_get_single_group(cfg, octstr_imm("wapbox")); if (grp == NULL) { warning(0, "No 'wapbox' group in configuration."); return; } if (cfg_get_integer(&new_value, grp, octstr_imm("log-level")) != -1) { reload_int(reload, octstr_imm("log level"), &logfilelevel, &new_value); logfilelevel = new_value; log_set_log_level(new_value); } /* Configure interface name for http requests */ http_interface_name = cfg_get(grp, octstr_imm("http-interface-name")); if (http_interface_name != NULL) { http_set_interface(http_interface_name); octstr_destroy(http_interface_name); } /* * users may define 'smart-errors' to have WML decks returned with * error information instead of signaling using the HTTP reply codes */ cfg_get_bool(&new_bool, grp, octstr_imm("smart-errors")); reload_bool(reload, octstr_imm("smart error messaging"), &wsp_smart_errors, &new_bool); /* decide if our XML parser within WML compiler is strict or relaxed */ cfg_get_bool(&new_bool, grp, octstr_imm("wml-strict")); reload_bool(reload, octstr_imm("XML within WML has to be strict"), &wml_xml_strict, &new_bool); if (!wml_xml_strict) warning(0, "'wml-strict' config directive has been set to no, " "this may make you vulnerable against XML bogus input."); if (cfg_get_bool(&new_bool, grp, octstr_imm("concatenation")) == 1) reload_bool(reload, octstr_imm("concatenation"), &concatenation, &new_bool); else concatenation = 1; if (cfg_get_integer(&new_value, grp, octstr_imm("max-messages")) != -1) { max_messages = new_value; reload_int(reload, octstr_imm("max messages"), &max_messages, &new_value); } /* configure URL mappings */ map_url_max = -1; cfg_get_integer(&map_url_max, grp, octstr_imm("map-url-max")); if (map_url_max > 0) warn_map_url = 1; if (reload) { /* clear old map */ wap_map_destroy(); wap_map_user_destroy(); } if ((device_home = cfg_get(grp, octstr_imm("device-home"))) != NULL) { wap_map_url_config_device_home(octstr_get_cstr(device_home)); } if ((s = cfg_get(grp, octstr_imm("map-url"))) != NULL) { warn_map_url = 1; wap_map_url_config(octstr_get_cstr(s)); octstr_destroy(s); } debug("wap", 0, "map_url_max = %ld", map_url_max); for (i = 0; i <= map_url_max; i++) { Octstr *name; name = octstr_format("map-url-%d", i); if ((s = cfg_get(grp, name)) != NULL) wap_map_url_config(octstr_get_cstr(s)); octstr_destroy(name); } /* warn the user that he/she should use the new wap-url-map groups */ if (warn_map_url) warning(0, "'map-url' config directive and related are deprecated, " "please use wap-url-map group"); /* configure wap-url-map */ groups = cfg_get_multi_group(cfg, octstr_imm("wap-url-map")); while (groups && (grp = gwlist_extract_first(groups)) != NULL) { Octstr *name, *url, *map_url, *send_msisdn_query; Octstr *send_msisdn_header, *send_msisdn_format; int accept_cookies; name = cfg_get(grp, octstr_imm("name")); url = cfg_get(grp, octstr_imm("url")); map_url = cfg_get(grp, octstr_imm("map-url")); send_msisdn_query = cfg_get(grp, octstr_imm("send-msisdn-query")); send_msisdn_header = cfg_get(grp, octstr_imm("send-msisdn-header")); send_msisdn_format = cfg_get(grp, octstr_imm("send-msisdn-format")); accept_cookies = -1; cfg_get_bool(&accept_cookies, grp, octstr_imm("accept-cookies")); wap_map_add_url(name, url, map_url, send_msisdn_query, send_msisdn_header, send_msisdn_format, accept_cookies); info(0, "Added wap-url-map <%s> with url <%s>, map-url <%s>, " "send-msisdn-query <%s>, send-msisdn-header <%s>, " "send-msisdn-format <%s>, accept-cookies <%s>", octstr_get_cstr(name), octstr_get_cstr(url), octstr_get_cstr(map_url), octstr_get_cstr(send_msisdn_query), octstr_get_cstr(send_msisdn_header), octstr_get_cstr(send_msisdn_format), (accept_cookies ? "yes" : "no")); } gwlist_destroy(groups, NULL); /* configure wap-user-map */ groups = cfg_get_multi_group(cfg, octstr_imm("wap-user-map")); while (groups && (grp = gwlist_extract_first(groups)) != NULL) { Octstr *name, *user, *pass, *msisdn; name = cfg_get(grp, octstr_imm("name")); user = cfg_get(grp, octstr_imm("user")); pass = cfg_get(grp, octstr_imm("pass")); msisdn = cfg_get(grp, octstr_imm("msisdn")); wap_map_add_user(name, user, pass, msisdn); info(0,"Added wap-user-map <%s> with credentials <%s:%s> " "and MSISDN <%s>", octstr_get_cstr(name), octstr_get_cstr(user), octstr_get_cstr(pass), octstr_get_cstr(msisdn)); } gwlist_destroy(groups, NULL); cfg_destroy(cfg); /* XXX TO-DO: if(reload) implement wapbox.resume/mutex.unlock */ }
struct dlr_storage *dlr_init_sdb(Cfg* cfg) { CfgGroup *grp; List *grplist; Octstr *sdb_url, *sdb_id; Octstr *p = NULL; long pool_size; DBConf *db_conf = NULL; /* * check for all mandatory directives that specify the field names * of the used table */ if (!(grp = cfg_get_single_group(cfg, octstr_imm("dlr-db")))) panic(0, "DLR: SDB: group 'dlr-db' is not specified!"); if (!(sdb_id = cfg_get(grp, octstr_imm("id")))) panic(0, "DLR: SDB: directive 'id' is not specified!"); fields = dlr_db_fields_create(grp); gw_assert(fields != NULL); /* * now grap the required information from the 'mysql-connection' group * with the sdb-id we just obtained * * we have to loop through all available SDB connection definitions * and search for the one we are looking for */ grplist = cfg_get_multi_group(cfg, octstr_imm("sdb-connection")); while (grplist && (grp = gwlist_extract_first(grplist)) != NULL) { p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, sdb_id) == 0) { goto found; } if (p != NULL) octstr_destroy(p); } panic(0, "DLR: SDB: connection settings for id '%s' are not specified!", octstr_get_cstr(sdb_id)); found: octstr_destroy(p); gwlist_destroy(grplist, NULL); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1 || pool_size == 0) pool_size = 1; if (!(sdb_url = cfg_get(grp, octstr_imm("url")))) panic(0, "DLR: SDB: directive 'url' is not specified!"); if (octstr_search(sdb_url, octstr_imm("oracle:"), 0) == 0) sdb_conn_type = SDB_ORACLE; else if (octstr_search(sdb_url, octstr_imm("mysql:"), 0) == 0) { warning(0, "DLR[sdb]: Please use native MySQL support, instead of libsdb."); sdb_conn_type = SDB_MYSQL; } else if (octstr_search(sdb_url, octstr_imm("postgres:"), 0) == 0) { sdb_conn_type = SDB_POSTGRES; } else sdb_conn_type = SDB_OTHER; /* * ok, ready to connect */ info(0,"Connecting to sdb resource <%s>.", octstr_get_cstr(sdb_url)); db_conf = gw_malloc(sizeof(DBConf)); gw_assert(db_conf != NULL); db_conf->sdb = gw_malloc(sizeof(SDBConf)); gw_assert(db_conf->sdb != NULL); db_conf->sdb->url = sdb_url; pool = dbpool_create(DBPOOL_SDB, db_conf, pool_size); gw_assert(pool != NULL); /* * XXX should a failing connect throw panic?! */ if (dbpool_conn_count(pool) == 0) panic(0,"DLR: SDB: database pool has no connections!"); return &handles; }
struct dlr_storage *dlr_init_sqlite3(Cfg *cfg) { CfgGroup *grp; List *grplist; long pool_size; DBConf *db_conf = NULL; Octstr *id, *file; int found; if ((grp = cfg_get_single_group(cfg, octstr_imm("dlr-db"))) == NULL) panic(0, "DLR: SQLite3: group 'dlr-db' is not specified!"); if (!(id = cfg_get(grp, octstr_imm("id")))) panic(0, "DLR: SQLite3: directive 'id' is not specified!"); /* initialize database fields */ fields = dlr_db_fields_create(grp); gw_assert(fields != NULL); grplist = cfg_get_multi_group(cfg, octstr_imm("sqlite3-connection")); found = 0; while (grplist && (grp = gwlist_extract_first(grplist)) != NULL) { Octstr *p = cfg_get(grp, octstr_imm("id")); if (p != NULL && octstr_compare(p, id) == 0) { found = 1; } if (p != NULL) octstr_destroy(p); if (found == 1) break; } gwlist_destroy(grplist, NULL); if (found == 0) panic(0, "DLR: SQLite3: connection settings for id '%s' are not specified!", octstr_get_cstr(id)); file = cfg_get(grp, octstr_imm("database")); if (cfg_get_integer(&pool_size, grp, octstr_imm("max-connections")) == -1) pool_size = 1; if (file == NULL) panic(0, "DLR: SQLite3: connection settings missing for id '%s', please" " check you configuration.",octstr_get_cstr(id)); /* ok we are ready to create dbpool */ db_conf = gw_malloc(sizeof(*db_conf)); db_conf->sqlite3 = gw_malloc(sizeof(SQLite3Conf)); db_conf->sqlite3->file = file; pool = dbpool_create(DBPOOL_SQLITE3, db_conf, pool_size); gw_assert(pool != NULL); if (dbpool_conn_count(pool) == 0) panic(0, "DLR: SQLite3: Could not establish sqlite3 connection(s)."); octstr_destroy(id); return &handles; }