/* * 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; }
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 **********"); }
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; }
void radius_acct_init(CfgGroup *grp) { long nas_ports = 0; /* get configured parameters */ if ((our_host = cfg_get(grp, octstr_imm("our-host"))) == NULL) { our_host = octstr_create("0.0.0.0"); } if ((remote_host = cfg_get(grp, octstr_imm("remote-host"))) != NULL) { cfg_get_integer(&remote_port, grp, octstr_imm("remote-port")); if ((secret_radius = cfg_get(grp, octstr_imm("secret-radius"))) == NULL) { panic(0, "RADIUS: No shared secret `secret-radius' for remote RADIUS in `radius-acct' provided."); } } cfg_get_integer(&our_port, grp, octstr_imm("our-port")); cfg_get_integer(&remote_timeout, grp, octstr_imm("remote-timeout")); if ((cfg_get_integer(&nas_ports, grp, octstr_imm("nas-ports"))) == -1) { nas_ports = RADIUS_NAS_PORTS; } if ((secret_nas = cfg_get(grp, octstr_imm("secret-nas"))) == NULL) { panic(0, "RADIUS: No shared secret `secret-nas' for NAS in `radius-acct' provided."); } unified_prefix = cfg_get(grp, octstr_imm("unified-prefix")); info(0, "RADIUS: local RADIUS accounting proxy at <%s:%ld>", octstr_get_cstr(our_host), our_port); if (remote_host == NULL) { info(0, "RADIUS: remote RADIUS accounting server is absent"); } else { info(0, "RADIUS: remote RADIUS accounting server at <%s:%ld>", octstr_get_cstr(remote_host), remote_port); } info(0, "RADIUS: initializing internal hash tables with %ld buckets.", nas_ports); radius_mutex = mutex_create(); /* init hash tables */ radius_table = dict_create(nas_ports, (void (*)(void *))octstr_destroy); session_table = dict_create(nas_ports, (void (*)(void *))octstr_destroy); client_table = dict_create(nas_ports, (void (*)(void *))octstr_destroy); gwthread_create(proxy_thread, NULL); }
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; }
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); }
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; }
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); }
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; }
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; }
int init (int argc, char *argv[]) { char *p; int rc = 0, oldmode; url_t u; int x0=-1, y0=-1, r=-1, c=-1; struct hostent *remote; char buffer[MAX_PATH]; if (action == ACTION_TESTONLY) exit (0); if (action == ACTION_BADAGS) { usage (); exit (1); } if (options.keep_winsize) { r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows"); c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols"); if (r == 0 && c == 0) r = -1, c = -1; } if (options.keep_winpos) { x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0"); y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0"); if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1; } p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font"); if (p[0] == '\0') p = NULL; fly_init (x0, y0, r, c, p); if (options.show_hw_cursor) video_cursor_state (1); fly_mouse (options.mouse); wintitle = get_window_name (); if (fl_opt.platform == PLATFORM_OS2_VIO) { strcpy (buffer, paths.system_libpath); str_cats (buffer, "nftp.ico"); if (access (buffer, R_OK) == 0) set_icon (buffer); } if (main_menu != NULL) { menu_activate (main_menu); adjust_menu_status (); } display.dir_mode = options.defaultdirmode; display.view_mode = VIEW_CONTROL; display.rshift = 0; display.lshift = 0; display.tabsize = 8; if (options.slowlink) set_view_mode (VIEW_REMOTE); else set_view_mode (VIEW_CONTROL); site.maxndir = 1024; site.dir = malloc (sizeof(directory)*site.maxndir); // ignore "broken PIPE" signals signal (SIGPIPE, SIG_IGN); set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION); local.dir.files = NULL; local.sortmode = abs (options.default_localsort); if (options.default_localsort >= 0) local.sortdirection = 1; else local.sortdirection = -1; build_local_filelist (NULL); site.batch_mode = FALSE; site.chunks = NULL; PutLineIntoResp2 ("NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name); PutLineIntoResp1 ("Copyright (C) 1994-2003 Sergey Ayukov <*****@*****.**>"); PutLineIntoResp1 ("Portions Copyright (C) Eric Young <*****@*****.**>"); //PutLineIntoResp1 ("Portions Copyright (C) Martin Nicolay <*****@*****.**>"); status.usage_interval = 0; if (!fl_opt.has_osmenu) PutLineIntoResp1 (M("Press F9 or Ctrl-F for menu")); update (1); if (options.firewall_type != 0) { if (options.fire_server[0] == '\0') { fly_ask_ok (ASK_WARN, M("Firewall proxy host isn't specified in NFTP.INI")); options.firewall_type = 0; } else { if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server)) { firewall.fwip = inet_addr (options.fire_server); } else { PutLineIntoResp2 (M("Looking up '%s'"), options.fire_server); remote = gethostbyname (options.fire_server); if (remote == NULL) { PutLineIntoResp2 (M("Cannot find '%s'"), options.fire_server); options.firewall_type = 0; } else { firewall.fwip = *((unsigned long *)(remote->h_addr)); PutLineIntoResp2 (M("Found '%s'"), remote->h_name); } } } } // read password cache psw_read (); // analyze arguments switch (action) { case 0: if (options.download_path != NULL) { set_local_path (options.download_path); } else { p = cfg_get_string (CONFIG_NFTP, "", "local-directory"); if (p[0] != '\0') set_local_path (p); } build_local_filelist (NULL); switch (options.start_prompt) { case 1: return FMSG_BASE_MENU + KEY_GEN_LOGIN; case 2: return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS; case 3: return FMSG_BASE_MENU + KEY_GEN_HISTORY; case 5: return FMSG_BASE_MENU + KEY_MENU; } return 0; case ACTION_DOWNLOAD: case ACTION_UPLOAD: oldmode = site.batch_mode; site.batch_mode = TRUE; if (action == ACTION_DOWNLOAD) rc = do_get (optarg1); if (action == ACTION_UPLOAD) rc = do_put (optarg1); //set_view_mode (VIEW_CONTROL); //update (1); if (rc && !cmdline.batchmode) fly_ask_ok (0, M("Transfer of '%s' has failed"), optarg1); if ((disc_after && rc == 0) || cmdline.batchmode) { Logoff (); terminate (); exit (0); } site.batch_mode = oldmode; return 0; case ACTION_CMDLIST: rc = runscript (optarg1); return 0; case ACTION_NICK_BOOK: case ACTION_NICK_HIST: if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0; if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0; rc = Login (&u); if (rc) return 0; if (options.login_bell) Bell (3); return 0; case ACTION_OPEN_BOOKMARKS: return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS; case ACTION_OPEN_HISTORY: return FMSG_BASE_MENU + KEY_GEN_HISTORY; case ACTION_LOGIN: // if download_path was specified in nftp.ini, set it now if (options.download_path != NULL) set_local_path (options.download_path); build_local_filelist (NULL); parse_url (optarg1, &u); rc = Login (&u); // attempt to download file if chdir failed /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0) { rc = do_get (optarg1); } if (rc) return 0; */ if (options.login_bell) Bell (3); return 0; case ACTION_TESTONLY: terminate (); exit (0); } fly_error ("internal error in init()"); return 0; }
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; }
SMSCConn *smscconn_create(CfgGroup *grp, int start_as_stopped) { SMSCConn *conn; Octstr *smsc_type; int ret; Octstr *allowed_smsc_id_regex; Octstr *denied_smsc_id_regex; Octstr *allowed_prefix_regex; Octstr *denied_prefix_regex; Octstr *preferred_prefix_regex; Octstr *tmp; if (grp == NULL) return NULL; conn = gw_malloc(sizeof(*conn)); memset(conn, 0, sizeof(*conn)); conn->why_killed = SMSCCONN_ALIVE; conn->status = SMSCCONN_CONNECTING; conn->connect_time = -1; conn->is_stopped = start_as_stopped; conn->received = counter_create(); conn->received_dlr = counter_create(); conn->sent = counter_create(); conn->sent_dlr = counter_create(); conn->failed = counter_create(); conn->flow_mutex = mutex_create(); conn->outgoing_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(conn->outgoing_sms_load, 60); load_add_interval(conn->outgoing_sms_load, 300); load_add_interval(conn->outgoing_sms_load, -1); conn->incoming_sms_load = load_create(); /* add 60,300,-1 entries */ load_add_interval(conn->incoming_sms_load, 60); load_add_interval(conn->incoming_sms_load, 300); load_add_interval(conn->incoming_sms_load, -1); conn->incoming_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(conn->incoming_dlr_load, 60); load_add_interval(conn->incoming_dlr_load, 300); load_add_interval(conn->incoming_dlr_load, -1); conn->outgoing_dlr_load = load_create(); /* add 60,300,-1 entries to dlr */ load_add_interval(conn->outgoing_dlr_load, 60); load_add_interval(conn->outgoing_dlr_load, 300); load_add_interval(conn->outgoing_dlr_load, -1); #define GET_OPTIONAL_VAL(x, n) x = cfg_get(grp, octstr_imm(n)) #define SPLIT_OPTIONAL_VAL(x, n) \ do { \ Octstr *tmp = cfg_get(grp, octstr_imm(n)); \ if (tmp) x = octstr_split(tmp, octstr_imm(";")); \ else x = NULL; \ octstr_destroy(tmp); \ }while(0) GET_OPTIONAL_VAL(conn->id, "smsc-id"); SPLIT_OPTIONAL_VAL(conn->allowed_smsc_id, "allowed-smsc-id"); SPLIT_OPTIONAL_VAL(conn->denied_smsc_id, "denied-smsc-id"); SPLIT_OPTIONAL_VAL(conn->preferred_smsc_id, "preferred-smsc-id"); GET_OPTIONAL_VAL(conn->allowed_prefix, "allowed-prefix"); GET_OPTIONAL_VAL(conn->denied_prefix, "denied-prefix"); GET_OPTIONAL_VAL(conn->preferred_prefix, "preferred-prefix"); GET_OPTIONAL_VAL(conn->unified_prefix, "unified-prefix"); GET_OPTIONAL_VAL(conn->our_host, "our-host"); GET_OPTIONAL_VAL(conn->log_file, "log-file"); cfg_get_bool(&conn->alt_dcs, grp, octstr_imm("alt-dcs")); GET_OPTIONAL_VAL(allowed_smsc_id_regex, "allowed-smsc-id-regex"); if (allowed_smsc_id_regex != NULL) if ((conn->allowed_smsc_id_regex = gw_regex_comp(allowed_smsc_id_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_smsc_id_regex)); GET_OPTIONAL_VAL(denied_smsc_id_regex, "denied-smsc-id-regex"); if (denied_smsc_id_regex != NULL) if ((conn->denied_smsc_id_regex = gw_regex_comp(denied_smsc_id_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_smsc_id_regex)); GET_OPTIONAL_VAL(allowed_prefix_regex, "allowed-prefix-regex"); if (allowed_prefix_regex != NULL) if ((conn->allowed_prefix_regex = gw_regex_comp(allowed_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_prefix_regex)); GET_OPTIONAL_VAL(denied_prefix_regex, "denied-prefix-regex"); if (denied_prefix_regex != NULL) if ((conn->denied_prefix_regex = gw_regex_comp(denied_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_prefix_regex)); GET_OPTIONAL_VAL(preferred_prefix_regex, "preferred-prefix-regex"); if (preferred_prefix_regex != NULL) if ((conn->preferred_prefix_regex = gw_regex_comp(preferred_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(preferred_prefix_regex)); if ((tmp = cfg_get(grp, octstr_imm("throughput"))) != NULL) { if (octstr_parse_double(&conn->throughput, tmp, 0) == -1) conn->throughput = 0; octstr_destroy(tmp); info(0, "Set throughput to %.3f for smsc id <%s>", conn->throughput, octstr_get_cstr(conn->id)); } /* Sets the admin_id. Equals to connection id if empty */ GET_OPTIONAL_VAL(conn->admin_id, "smsc-admin-id"); if (conn->admin_id == NULL) conn->admin_id = octstr_duplicate(conn->id); /* configure the internal rerouting rules for this smsc id */ init_reroute(conn, grp); if (cfg_get_integer(&conn->log_level, grp, octstr_imm("log-level")) == -1) conn->log_level = 0; if (cfg_get_integer(&conn->max_sms_octets, grp, octstr_imm("max-sms-octets")) == -1) conn->max_sms_octets = MAX_SMS_OCTETS; if (cfg_get_bool(&conn->dead_start, grp, octstr_imm("dead-start")) == -1) conn->dead_start = 0; /* default to connect at start-up time */ /* open a smsc-id specific log-file in exlusive mode */ if (conn->log_file) conn->log_idx = log_open(octstr_get_cstr(conn->log_file), conn->log_level, GW_EXCL); #undef GET_OPTIONAL_VAL #undef SPLIT_OPTIONAL_VAL if (conn->allowed_smsc_id && conn->denied_smsc_id) warning(0, "Both 'allowed-smsc-id' and 'denied-smsc-id' set, deny-list " "automatically ignored"); if (conn->allowed_smsc_id_regex && conn->denied_smsc_id_regex) warning(0, "Both 'allowed-smsc-id_regex' and 'denied-smsc-id_regex' set, deny-regex " "automatically ignored"); if (cfg_get_integer(&conn->reconnect_delay, grp, octstr_imm("reconnect-delay")) == -1) conn->reconnect_delay = SMSCCONN_RECONNECT_DELAY; smsc_type = cfg_get(grp, octstr_imm("smsc")); if (smsc_type == NULL) { error(0, "Required field 'smsc' missing for smsc group."); smscconn_destroy(conn); octstr_destroy(smsc_type); return NULL; } if (octstr_compare(smsc_type, octstr_imm("fake")) == 0) ret = smsc_fake_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("cimd2")) == 0) ret = smsc_cimd2_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("emi")) == 0) ret = smsc_emi2_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("http")) == 0) ret = smsc_http_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("smpp")) == 0) ret = smsc_smpp_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("at")) == 0) ret = smsc_at2_create(conn,grp); else if (octstr_compare(smsc_type, octstr_imm("cgw")) == 0) ret = smsc_cgw_create(conn,grp); else if (octstr_compare(smsc_type, octstr_imm("smasi")) == 0) ret = smsc_smasi_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("oisd")) == 0) ret = smsc_oisd_create(conn, grp); else if (octstr_compare(smsc_type, octstr_imm("loopback")) == 0) ret = smsc_loopback_create(conn, grp); #ifdef HAVE_GSOAP else if (octstr_compare(smsc_type, octstr_imm("parlayx")) == 0) ret = smsc_soap_parlayx_create(conn, grp); #endif else ret = smsc_wrapper_create(conn, grp); octstr_destroy(smsc_type); if (ret == -1) { smscconn_destroy(conn); return NULL; } gw_assert(conn->send_msg != NULL); bb_smscconn_ready(conn); return conn; }
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 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; }
/* * Create one URLTranslation. Return NULL for failure, pointer to it for OK. */ static URLTranslation *create_onetrans(CfgGroup *grp) { URLTranslation *ot; Octstr *url, *post_url, *post_xml, *text, *file, *exec; Octstr *accepted_smsc, *accepted_account, *forced_smsc, *default_smsc; Octstr *grpname; int is_sms_service, regex_flag = REG_EXTENDED; Octstr *accepted_smsc_regex; Octstr *accepted_account_regex; Octstr *allowed_prefix_regex; Octstr *denied_prefix_regex; Octstr *allowed_receiver_prefix_regex; Octstr *denied_receiver_prefix_regex; Octstr *white_list_regex; Octstr *black_list_regex; Octstr *keyword_regex; Octstr *os, *tmp; grpname = cfg_get_group_name(grp); if (grpname == NULL) return NULL; if (octstr_str_compare(grpname, "sms-service") == 0) is_sms_service = 1; else if (octstr_str_compare(grpname, "sendsms-user") == 0) is_sms_service = 0; else { octstr_destroy(grpname); return NULL; } octstr_destroy(grpname); ot = gw_malloc(sizeof(URLTranslation)); memset(ot, 0, sizeof(*ot)); if (is_sms_service) { cfg_get_bool(&ot->catch_all, grp, octstr_imm("catch-all")); ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url")); if (cfg_get_integer(&ot->dlr_mask, grp, octstr_imm("dlr-mask")) == -1) ot->dlr_mask = DLR_UNDEFINED; ot->alt_charset = cfg_get(grp, octstr_imm("alt-charset")); url = cfg_get(grp, octstr_imm("get-url")); if (url == NULL) url = cfg_get(grp, octstr_imm("url")); post_url = cfg_get(grp, octstr_imm("post-url")); post_xml = cfg_get(grp, octstr_imm("post-xml")); file = cfg_get(grp, octstr_imm("file")); text = cfg_get(grp, octstr_imm("text")); exec = cfg_get(grp, octstr_imm("exec")); if (url != NULL) { ot->type = TRANSTYPE_GET_URL; ot->pattern = octstr_duplicate(url); } else if (post_url != NULL) { ot->type = TRANSTYPE_POST_URL; ot->pattern = octstr_duplicate(post_url); ot->catch_all = 1; } else if (post_xml != NULL) { ot->type = TRANSTYPE_POST_XML; ot->pattern = octstr_duplicate(post_xml); ot->catch_all = 1; } else if (file != NULL) { ot->type = TRANSTYPE_FILE; ot->pattern = octstr_duplicate(file); } else if (text != NULL) { ot->type = TRANSTYPE_TEXT; ot->pattern = octstr_duplicate(text); } else if (exec != NULL) { ot->type = TRANSTYPE_EXECUTE; ot->pattern = octstr_duplicate(exec); } else { octstr_destroy(url); octstr_destroy(post_url); octstr_destroy(post_xml); octstr_destroy(file); octstr_destroy(text); octstr_destroy(exec); error(0, "Configuration group `sms-service' " "did not specify get-url, post-url, post-xml, file or text."); goto error; } octstr_destroy(url); octstr_destroy(post_url); octstr_destroy(post_xml); octstr_destroy(file); octstr_destroy(text); octstr_destroy(exec); tmp = cfg_get(grp, octstr_imm("keyword")); keyword_regex = cfg_get(grp, octstr_imm("keyword-regex")); if (tmp == NULL && keyword_regex == NULL) { error(0, "Group 'sms-service' must include either 'keyword' or 'keyword-regex'."); goto error; } if (tmp != NULL && keyword_regex != NULL) { error(0, "Group 'sms-service' may inlcude either 'keyword' or 'keyword-regex'."); octstr_destroy(tmp); octstr_destroy(keyword_regex); goto error; } if (tmp != NULL && octstr_str_compare(tmp, "default") == 0) { /* default sms-service */ ot->keyword_regex = NULL; octstr_destroy(tmp); } else if (tmp != NULL) { Octstr *aliases; /* convert to regex */ regex_flag |= REG_ICASE; keyword_regex = octstr_format("^[ ]*(%S", tmp); octstr_destroy(tmp); aliases = cfg_get(grp, octstr_imm("aliases")); if (aliases != NULL) { long i; List *l; l = octstr_split(aliases, octstr_imm(";")); octstr_destroy(aliases); for (i = 0; i < gwlist_len(l); ++i) { os = gwlist_get(l, i); octstr_format_append(keyword_regex, "|%S", os); } gwlist_destroy(l, octstr_destroy_item); } octstr_append_cstr(keyword_regex, ")[ ]*"); } if (keyword_regex != NULL && (ot->keyword_regex = gw_regex_comp(keyword_regex, regex_flag)) == NULL) { error(0, "Could not compile pattern '%s'", octstr_get_cstr(keyword_regex)); octstr_destroy(keyword_regex); goto error; } ot->name = cfg_get(grp, octstr_imm("name")); if (ot->name == NULL) ot->name = keyword_regex ? octstr_duplicate(keyword_regex) : octstr_create("default"); octstr_destroy(keyword_regex); accepted_smsc = cfg_get(grp, octstr_imm("accepted-smsc")); if (accepted_smsc != NULL) { ot->accepted_smsc = octstr_split(accepted_smsc, octstr_imm(";")); octstr_destroy(accepted_smsc); } accepted_account = cfg_get(grp, octstr_imm("accepted-account")); if (accepted_account != NULL) { ot->accepted_account = octstr_split(accepted_account, octstr_imm(";")); octstr_destroy(accepted_account); } accepted_smsc_regex = cfg_get(grp, octstr_imm("accepted-smsc-regex")); if (accepted_smsc_regex != NULL) { if ( (ot->accepted_smsc_regex = gw_regex_comp(accepted_smsc_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(accepted_smsc_regex)); octstr_destroy(accepted_smsc_regex); } accepted_account_regex = cfg_get(grp, octstr_imm("accepted-account-regex")); if (accepted_account_regex != NULL) { if ( (ot->accepted_account_regex = gw_regex_comp(accepted_account_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(accepted_account_regex)); octstr_destroy(accepted_account_regex); } cfg_get_bool(&ot->assume_plain_text, grp, octstr_imm("assume-plain-text")); cfg_get_bool(&ot->accept_x_kannel_headers, grp, octstr_imm("accept-x-kannel-headers")); cfg_get_bool(&ot->strip_keyword, grp, octstr_imm("strip-keyword")); cfg_get_bool(&ot->send_sender, grp, octstr_imm("send-sender")); ot->prefix = cfg_get(grp, octstr_imm("prefix")); ot->suffix = cfg_get(grp, octstr_imm("suffix")); ot->allowed_recv_prefix = cfg_get(grp, octstr_imm("allowed-receiver-prefix")); allowed_receiver_prefix_regex = cfg_get(grp, octstr_imm("allowed-receiver-prefix-regex")); if (allowed_receiver_prefix_regex != NULL) { if ((ot->allowed_receiver_prefix_regex = gw_regex_comp(allowed_receiver_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_receiver_prefix_regex)); octstr_destroy(allowed_receiver_prefix_regex); } ot->allowed_recv_prefix = cfg_get(grp, octstr_imm("allowed-receiver-prefix")); ot->denied_recv_prefix = cfg_get(grp, octstr_imm("denied-receiver-prefix")); denied_receiver_prefix_regex = cfg_get(grp, octstr_imm("denied-receiver-prefix-regex")); if (denied_receiver_prefix_regex != NULL) { if ((ot->denied_receiver_prefix_regex = gw_regex_comp(denied_receiver_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'",octstr_get_cstr(denied_receiver_prefix_regex)); octstr_destroy(denied_receiver_prefix_regex); } ot->args = count_occurences(ot->pattern, octstr_imm("%s")); ot->args += count_occurences(ot->pattern, octstr_imm("%S")); ot->has_catchall_arg = (count_occurences(ot->pattern, octstr_imm("%r")) > 0) || (count_occurences(ot->pattern, octstr_imm("%a")) > 0); } else { ot->type = TRANSTYPE_SENDSMS; ot->pattern = octstr_create(""); ot->args = 0; ot->has_catchall_arg = 0; ot->catch_all = 1; ot->username = cfg_get(grp, octstr_imm("username")); ot->password = cfg_get(grp, octstr_imm("password")); ot->dlr_url = cfg_get(grp, octstr_imm("dlr-url")); grp_dump(grp); if (ot->password == NULL) { error(0, "Password required for send-sms user"); goto error; } ot->name = cfg_get(grp, octstr_imm("name")); if (ot->name == NULL) ot->name = octstr_duplicate(ot->username); forced_smsc = cfg_get(grp, octstr_imm("forced-smsc")); default_smsc = cfg_get(grp, octstr_imm("default-smsc")); if (forced_smsc != NULL) { if (default_smsc != NULL) { info(0, "Redundant default-smsc for send-sms user %s", octstr_get_cstr(ot->username)); } ot->forced_smsc = forced_smsc; octstr_destroy(default_smsc); } else if (default_smsc != NULL) ot->default_smsc = default_smsc; ot->deny_ip = cfg_get(grp, octstr_imm("user-deny-ip")); ot->allow_ip = cfg_get(grp, octstr_imm("user-allow-ip")); ot->default_sender = cfg_get(grp, octstr_imm("default-sender")); } ot->allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix")); allowed_prefix_regex = cfg_get(grp, octstr_imm("allowed-prefix-regex")); if (allowed_prefix_regex != NULL) { if ((ot->allowed_prefix_regex = gw_regex_comp(allowed_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(allowed_prefix_regex)); octstr_destroy(allowed_prefix_regex); } ot->denied_prefix = cfg_get(grp, octstr_imm("denied-prefix")); denied_prefix_regex = cfg_get(grp, octstr_imm("denied-prefix-regex")); if (denied_prefix_regex != NULL) { if ((ot->denied_prefix_regex = gw_regex_comp(denied_prefix_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(denied_prefix_regex)); octstr_destroy(denied_prefix_regex); } os = cfg_get(grp, octstr_imm("white-list")); if (os != NULL) { ot->white_list = numhash_create(octstr_get_cstr(os)); octstr_destroy(os); } white_list_regex = cfg_get(grp, octstr_imm("white-list-regex")); if (white_list_regex != NULL) { if ((ot->white_list_regex = gw_regex_comp(white_list_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(white_list_regex)); octstr_destroy(white_list_regex); } os = cfg_get(grp, octstr_imm("black-list")); if (os != NULL) { ot->black_list = numhash_create(octstr_get_cstr(os)); octstr_destroy(os); } black_list_regex = cfg_get(grp, octstr_imm("black-list-regex")); if (black_list_regex != NULL) { if ((ot->black_list_regex = gw_regex_comp(black_list_regex, REG_EXTENDED)) == NULL) panic(0, "Could not compile pattern '%s'", octstr_get_cstr(black_list_regex)); octstr_destroy(black_list_regex); } if (cfg_get_integer(&ot->max_messages, grp, octstr_imm("max-messages")) == -1) ot->max_messages = 1; cfg_get_bool(&ot->concatenation, grp, octstr_imm("concatenation")); cfg_get_bool(&ot->omit_empty, grp, octstr_imm("omit-empty")); ot->header = cfg_get(grp, octstr_imm("header")); ot->footer = cfg_get(grp, octstr_imm("footer")); ot->faked_sender = cfg_get(grp, octstr_imm("faked-sender")); ot->split_chars = cfg_get(grp, octstr_imm("split-chars")); ot->split_suffix = cfg_get(grp, octstr_imm("split-suffix")); if ( (ot->prefix == NULL && ot->suffix != NULL) || (ot->prefix != NULL && ot->suffix == NULL) ) { warning(0, "Service : suffix and prefix are only used" " if both are set."); } if ((ot->prefix != NULL || ot->suffix != NULL) && ot->type != TRANSTYPE_GET_URL) { warning(0, "Service : suffix and prefix are only used" " if type is 'get-url'."); } return ot; error: error(0, "Couldn't create a URLTranslation."); destroy_onetrans(ot); return NULL; }
/* * 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; }
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; }
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; }
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; }
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; }
int init (int argc, char *argv[]) { char *p; int rc = 0, oldmode, i; url_t u; int x0=-1, y0=-1, r=-1, c=-1; struct hostent *remote; char buffer[MAX_PATH]; if (action == ACTION_TESTONLY) exit (0); if (action == ACTION_BADARGS) { usage (); exit (1); } if (options.keep_winsize) { r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows"); c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols"); if (r == 0 && c == 0) r = -1, c = -1; } if (options.keep_winpos) { x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0"); y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0"); if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1; } p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font"); if (p[0] == '\0') p = NULL; fly_init (x0, y0, r, c, p); fly_mouse (options.mouse); wintitle = get_window_name (); if (fl_opt.platform == PLATFORM_OS2_VIO) { strcpy (buffer, paths.system_libpath); str_cats (buffer, "nftp.ico"); if (access (buffer, R_OK) == 0) set_icon (buffer); } if (main_menu != NULL) { menu_activate (main_menu); } display.rshift = 0; display.lshift = 0; display.tabsize = 8; display.view[V_LEFT] = -1; display.view[V_RIGHT] = -1; display.cursor = V_LEFT; display.parsed = TRUE; for (i=0; i<MAX_SITE; i++) { site[i].set_up = FALSE; site[i].CC.na = 0; site[i].CC.n = 0; } // ignore "broken PIPE" signals signal (SIGPIPE, SIG_IGN); set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION); lcache.lda = 0; lcache.ld = 0; lcache.L = NULL; local[V_LEFT].dir.name = NULL; local[V_LEFT].dir.files = NULL; local[V_LEFT].dir.nfiles = 0; local[V_LEFT].sortmode = abs (options.default_localsort); if (options.default_localsort >= 0) local[V_LEFT].sortdirection = 1; else local[V_LEFT].sortdirection = -1; l_chdir (V_LEFT, NULL); local[V_RIGHT].dir.name = NULL; local[V_RIGHT].dir.files = NULL; local[V_RIGHT].dir.nfiles = 0; local[V_RIGHT].sortmode = abs (options.default_localsort); if (options.default_localsort >= 0) local[V_RIGHT].sortdirection = 1; else local[V_RIGHT].sortdirection = -1; l_chdir (V_RIGHT, NULL); PutLineIntoResp (RT_COMM, 0, "NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name); PutLineIntoResp (RT_RESP, 0, "Copyright (C) 1994--2000 Sergey Ayukov <*****@*****.**>"); PutLineIntoResp (RT_RESP, 0, "Portions Copyright (C) Eric Young <*****@*****.**>"); status.usage_interval = 0; if (!fl_opt.has_osmenu) PutLineIntoResp (RT_RESP, 0, MSG(M_RESP_F9_FOR_MENU)); update (1); if (options.firewall_type != 0) { if (options.fire_server[0] == '\0') { fly_ask_ok (ASK_WARN, MSG(M_PROXY_ISNT_SPECIFIED)); options.firewall_type = 0; } else { if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server)) { firewall.fwip = inet_addr (options.fire_server); } else { PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_LOOKING_UP), options.fire_server); remote = gethostbyname (options.fire_server); if (remote == NULL) { PutLineIntoResp (RT_COMM, 0, MSG(M_RESP_CANNOT_RESOLVE), options.fire_server); options.firewall_type = 0; } else { firewall.fwip = *((unsigned long *)(remote->h_addr)); PutLineIntoResp (RT_COMM,0, MSG(M_RESP_FOUND), remote->h_name); } } } } // read password cache psw_read (); // analyze arguments switch (action) { case ACTION_NONE: if (options.download_path != NULL) { l_chdir (V_RIGHT, options.download_path); } else { p = cfg_get_string (CONFIG_NFTP, "", "local-directory-left"); if (p[0] != '\0') { l_chdir (V_LEFT, p); } p = cfg_get_string (CONFIG_NFTP, "", "local-directory-right"); if (p[0] != '\0') { l_chdir (V_RIGHT, p); } } switch (options.start_prompt) { case 1: return FMSG_BASE_MENU + KEY_GEN_LOGIN; case 2: return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS; case 3: return FMSG_BASE_MENU + KEY_GEN_HISTORY; case 5: return FMSG_BASE_MENU + KEY_MENU; } return 0; case ACTION_DOWNLOAD: case ACTION_UPLOAD: oldmode = status.batch_mode; status.batch_mode = TRUE; if (action == ACTION_DOWNLOAD) rc = do_get (optarg1); if (action == ACTION_UPLOAD) rc = do_put (optarg1); //set_view_mode (VIEW_CONTROL); //update (1); if (rc && !cmdline.batchmode) fly_ask_ok (0, MSG(M_TRANSFER_FAILED), optarg1); if ((disc_after && rc == 0) || cmdline.batchmode) { Logoff (0); terminate (); exit (0); } status.batch_mode = oldmode; return 0; //case ACTION_CMDLIST: // rc = runscript (optarg1); // return 0; case ACTION_NICK_BOOK: case ACTION_NICK_HIST: if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0; if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0; rc = Login (-1, &u, V_LEFT); if (rc) return 0; if ((action == ACTION_NICK_BOOK && MAX_SITE > 1 && optarg2 != NULL && bookmark_nickname (optarg2, &u) == 1) || (action == ACTION_NICK_HIST && MAX_SITE > 1 && optarg2 != NULL && history_nickname (optarg2, &u) == 1)) { rc = Login (-1, &u, V_RIGHT); } if (options.login_bell) Bell (3); return 0; case ACTION_OPEN_BOOKMARKS: return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS; case ACTION_OPEN_HISTORY: return FMSG_BASE_MENU + KEY_GEN_HISTORY; case ACTION_LOGIN: // if download_path was specified in nftp.ini, set it now if (options.download_path != NULL) { l_chdir (V_LEFT, options.download_path); l_chdir (V_RIGHT, options.download_path); } dmsg ("optarg1 is [%s]\n", optarg1); parse_url (optarg1, &u); rc = Login (-1, &u, V_LEFT); if (MAX_SITE > 1 && optarg2 != NULL) { parse_url (optarg2, &u); rc = Login (-1, &u, V_RIGHT); } // attempt to download file if chdir failed /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0) { rc = do_get (optarg1); } if (rc) return 0; */ if (options.login_bell) Bell (3); return 0; case ACTION_TESTONLY: terminate (); exit (0); } fly_error ("internal error in init()"); return 0; }
int smsc_http_create(SMSCConn *conn, CfgGroup *cfg) { ConnData *conndata = NULL; Octstr *type; int ssl = 0; /* indicate if SSL-enabled server should be used */ long max_ps; if ((type = cfg_get(cfg, octstr_imm("system-type"))) == NULL) { error(0, "HTTP[%s]: 'system-type' missing in smsc 'http' record.", octstr_get_cstr(conn->id)); octstr_destroy(type); return -1; } conndata = gw_malloc(sizeof(ConnData)); /* reset conndata */ memset(conndata, 0, sizeof(ConnData)); conn->data = conndata; conndata->http_ref = NULL; conndata->data = NULL; if (cfg_get_integer(&conndata->port, cfg, octstr_imm("port")) == -1) { warning(0, "HTTP[%s]: 'port' not set in smsc 'http' group.", octstr_get_cstr(conn->id)); conndata->port = -1; } conndata->allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip")); conndata->send_url = cfg_get(cfg, octstr_imm("send-url")); conndata->username = cfg_get(cfg, octstr_imm("smsc-username")); conndata->password = cfg_get(cfg, octstr_imm("smsc-password")); conndata->system_id = cfg_get(cfg, octstr_imm("system-id")); cfg_get_bool(&conndata->no_sender, cfg, octstr_imm("no-sender")); cfg_get_bool(&conndata->no_coding, cfg, octstr_imm("no-coding")); cfg_get_bool(&conndata->no_sep, cfg, octstr_imm("no-sep")); conndata->proxy = cfg_get(cfg, octstr_imm("system-id")); cfg_get_bool(&ssl, cfg, octstr_imm("use-ssl")); conndata->dlr_url = cfg_get(cfg, octstr_imm("dlr-url")); conndata->alt_charset = cfg_get(cfg, octstr_imm("alt-charset")); if (cfg_get_integer(&max_ps, cfg, octstr_imm("max-pending-submits")) == -1 || max_ps < 1) max_ps = 10; conndata->max_pending_sends = semaphore_create(max_ps); if (conndata->port <= 0 && conndata->send_url == NULL) { error(0, "Sender and receiver disabled. Dummy SMSC not allowed."); goto error; } if (conndata->send_url == NULL) panic(0, "HTTP[%s]: Sending not allowed. No 'send-url' specified.", octstr_get_cstr(conn->id)); if (octstr_case_compare(type, octstr_imm("kannel")) == 0) { if (conndata->username == NULL || conndata->password == NULL) { error(0, "HTTP[%s]: 'username' and 'password' required for Kannel http smsc", octstr_get_cstr(conn->id)); goto error; } conndata->callbacks = &smsc_http_kannel_callback; } else if (octstr_case_compare(type, octstr_imm("brunet")) == 0) { conndata->callbacks = &smsc_http_brunet_callback; } else if (octstr_case_compare(type, octstr_imm("xidris")) == 0) { conndata->callbacks = &smsc_http_xidris_callback; } else if (octstr_case_compare(type, octstr_imm("generic")) == 0) { conndata->callbacks = &smsc_http_generic_callback; } else if (octstr_case_compare(type, octstr_imm("clickatell")) == 0) { conndata->callbacks = &smsc_http_clickatell_callback; } else if (octstr_case_compare(type, octstr_imm("wapme")) == 0) { conndata->callbacks = &smsc_http_wapme_callback; } /* * ADD NEW HTTP SMSC TYPES HERE */ else { error(0, "HTTP[%s]: system-type '%s' unknown smsc 'http' record.", octstr_get_cstr(conn->id), octstr_get_cstr(type)); goto error; } if (conndata->callbacks != NULL && conndata->callbacks->init != NULL && conndata->callbacks->init(conn, cfg)) { error(0, "HTTP[%s]: submodule '%s' init failed.", octstr_get_cstr(conn->id), octstr_get_cstr(type)); goto error; } conndata->open_sends = counter_create(); conndata->msg_to_send = gwlist_create(); gwlist_add_producer(conndata->msg_to_send); conndata->http_ref = http_caller_create(); conn->name = octstr_format("HTTP%s:%S:%d", (ssl?"S":""), type, conndata->port); if (conndata->send_url != NULL) { conn->status = SMSCCONN_ACTIVE; } else { conn->status = SMSCCONN_ACTIVE_RECV; } conn->connect_time = time(NULL); conn->shutdown = httpsmsc_shutdown; conn->queued = httpsmsc_queued; conn->send_msg = httpsmsc_send; conndata->shutdown = 0; /* start receiver thread */ if (conndata->port > 0) { if (http_open_port(conndata->port, ssl) == -1) goto error; if ((conndata->receive_thread = gwthread_create(httpsmsc_receiver, conn)) == -1) goto error; } else conndata->receive_thread = -1; /* start sender threads */ if (conndata->send_url) { if ((conndata->send_cb_thread = gwthread_create(httpsmsc_send_cb, conn)) == -1) goto error; if ((conndata->sender_thread = gwthread_create(httpsmsc_sender, conn)) == -1) goto error; } else { conndata->send_cb_thread = conndata->sender_thread = -1; } info(0, "HTTP[%s]: Initiated and ready", octstr_get_cstr(conn->id)); octstr_destroy(type); return 0; error: error(0, "HTTP[%s]: Failed to create HTTP SMSC connection", octstr_get_cstr(conn->id)); if (conndata->callbacks != NULL && conndata->callbacks->destroy != NULL) conndata->callbacks->destroy(conn); conn->data = NULL; conndata_destroy(conndata); conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT; conn->status = SMSCCONN_DEAD; octstr_destroy(type); return -1; }
int smpp_pdu_init(Cfg *cfg) { CfgGroup *grp; List *l; if (initialized) return 0; l = cfg_get_multi_group(cfg, octstr_imm("smpp-tlv")); tlvs = gwlist_create(); tlvs_by_tag = dict_create(1024, (void(*)(void*))dict_destroy); tlvs_by_name = dict_create(1024, (void(*)(void*))dict_destroy); while (l != NULL && (grp = gwlist_extract_first(l)) != NULL) { struct smpp_tlv *tlv; Octstr *tmp, *smsc_id; List *l2; tlv = gw_malloc(sizeof(*tlv)); if ((tlv->name = cfg_get(grp, octstr_imm("name"))) == NULL) { error(0, "SMPP: Unable to get name for smpp-tlv."); smpp_tlv_destroy(tlv); goto failed; } if (cfg_get_integer(&tlv->tag, grp, octstr_imm("tag")) == -1) { error(0, "SMPP: Unable to get tag for smpp-tlv."); smpp_tlv_destroy(tlv); goto failed; } if (cfg_get_integer(&tlv->length, grp, octstr_imm("length")) == -1) { error(0, "SMPP: Unable to get length for smpp-tlv."); smpp_tlv_destroy(tlv); goto failed; } if ((tmp = cfg_get(grp, octstr_imm("type"))) == NULL) { error(0, "SMPP: Unable to get type for smpp-tlv."); smpp_tlv_destroy(tlv); goto failed; } if (octstr_str_case_compare(tmp, "octetstring") == 0) tlv->type = SMPP_TLV_OCTETS; else if (octstr_str_case_compare(tmp, "nulterminated") == 0) tlv->type = SMPP_TLV_NULTERMINATED; else if (octstr_str_case_compare(tmp, "integer") == 0) tlv->type = SMPP_TLV_INTEGER; else { error(0, "SMPP: Unknown type for smpp-tlv: `%s'", octstr_get_cstr(tmp)); octstr_destroy(tmp); smpp_tlv_destroy(tlv); goto failed; } octstr_destroy(tmp); /* put to all TLVs */ gwlist_produce(tlvs, tlv); smsc_id = cfg_get(grp, octstr_imm("smsc-id")); if (smsc_id != NULL) { l2 = octstr_split(smsc_id, octstr_imm(";")); octstr_destroy(smsc_id); } else { l2 = gwlist_create(); gwlist_produce(l2, octstr_create(DEFAULT_SMSC_ID)); } while(l2 != NULL && (smsc_id = gwlist_extract_first(l2)) != NULL) { Dict *tmp_dict; debug("sms.smpp", 0, "adding smpp-tlv for smsc-id=%s", octstr_get_cstr(smsc_id)); tmp_dict = dict_get(tlvs_by_name, smsc_id); if (tmp_dict == NULL) { tmp_dict = dict_create(1024, NULL); dict_put(tlvs_by_name, smsc_id, tmp_dict); } /* put into dict */ if (!dict_put_once(tmp_dict, tlv->name, tlv)) { error(0, "SMPP: Double TLV name %s found.", octstr_get_cstr(tlv->name)); octstr_destroy(smsc_id); goto failed; } tmp_dict = dict_get(tlvs_by_tag, smsc_id); if (tmp_dict == NULL) { tmp_dict = dict_create(1024, NULL); dict_put(tlvs_by_tag, smsc_id, tmp_dict); } tmp = octstr_format("%ld", tlv->tag); if (!dict_put_once(tmp_dict, tmp, tlv)) { error(0, "SMPP: Double TLV tag %s found.", octstr_get_cstr(tmp)); gwlist_destroy(l2, octstr_destroy_item); octstr_destroy(tmp); octstr_destroy(smsc_id); goto failed; } octstr_destroy(tmp); octstr_destroy(smsc_id); } gwlist_destroy(l2, octstr_destroy_item); } gwlist_destroy(l, NULL); initialized = 1; return 0; failed: gwlist_destroy(tlvs, (void(*)(void*))smpp_tlv_destroy); dict_destroy(tlvs_by_tag); dict_destroy(tlvs_by_name); return -1; }
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; }
int smsc_cgw_create(SMSCConn *conn, CfgGroup *cfg) { PrivData *privdata; Octstr *allow_ip, *deny_ip, *host, *appname; long portno, our_port, waitack; int i; privdata = gw_malloc(sizeof(PrivData)); privdata->outgoing_queue = gwlist_create(); privdata->listening_socket = -1; if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) portno = 0; privdata->port = portno; if (cfg_get_integer(&portno, cfg, octstr_imm("receive-port")) < 0) portno = 0; privdata->rport = portno; host = cfg_get(cfg, octstr_imm("host")); appname = cfg_get(cfg, octstr_imm("appname")); if (cfg_get_integer(&our_port, cfg, octstr_imm("our-port")) == -1) privdata->our_port = 0; /* 0 means use any port */ else privdata->our_port = our_port; allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip")); if (allow_ip) deny_ip = octstr_create("*.*.*.*"); else deny_ip = NULL; if (cfg_get_integer(&waitack, cfg, octstr_imm("wait-ack")) < 0) privdata->waitack = 60; else privdata->waitack = waitack; if (privdata->port <= 0 || privdata->port > 65535) { info(1, "No port defined for cgw -> using default (%d)", CGW_DEFPORT); privdata->port = CGW_DEFPORT; } if (host == NULL) { error(0, "'host' missing in cgw configuration."); goto error; } if (appname == NULL) appname = octstr_create("send"); privdata->allow_ip = allow_ip; privdata->deny_ip = deny_ip; privdata->host = host; privdata->appname = appname; privdata->nexttrn = 0; privdata->check_time = 0; for (i = 0; i < CGW_TRN_MAX; i++) { privdata->sendtime[i] = 0; privdata->dlr[i] = 0; } if (privdata->rport > 0 && cgw_open_listening_socket(conn,privdata) < 0) { gw_free(privdata); privdata = NULL; goto error; } conn->data = privdata; conn->name = octstr_format("CGW:%d", privdata->port); privdata->shutdown = 0; conn->status = SMSCCONN_CONNECTING; conn->connect_time = time(NULL); if (privdata->rport > 0 && (privdata->receiver_thread = gwthread_create(cgw_listener, conn)) == -1) goto error; if ((privdata->sender_thread = gwthread_create(cgw_sender, conn)) == -1) { privdata->shutdown = 1; goto error; } conn->shutdown = cgw_shutdown_cb; conn->queued = cgw_queued_cb; conn->start_conn = cgw_start_cb; conn->send_msg = cgw_add_msg_cb; return 0; error: error(0, "Failed to create CGW smsc connection"); if (privdata != NULL) gwlist_destroy(privdata->outgoing_queue, NULL); gw_free(privdata); octstr_destroy(host); octstr_destroy(allow_ip); octstr_destroy(deny_ip); octstr_destroy(appname); conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT; conn->status = SMSCCONN_DEAD; info(0, "exiting"); return -1; }
SMSCenter *smsc_open(CfgGroup *grp) { SMSCenter *smsc; Octstr *type, *host, *username, *password, *phone, *device; Octstr *preferred_prefix, *allowed_prefix, *denied_prefix; Octstr *alt_chars, *allow_ip; Octstr *sema_smscnua, *sema_homenua, *sema_report; Octstr *sender_prefix; long iwaitreport; long port, receive_port, our_port; long keepalive; long ois_debug; long alt_dcs; int typeno; type = cfg_get(grp, octstr_imm("smsc")); if (type == NULL) { error(0, "Required field 'smsc' missing for smsc group."); return NULL; } if (octstr_compare(type, octstr_imm("cimd")) == 0) typeno = SMSC_TYPE_CIMD; else if (octstr_compare(type, octstr_imm("emi_x25")) == 0) typeno = SMSC_TYPE_EMI_X25; else if (octstr_compare(type, octstr_imm("sema")) == 0) typeno = SMSC_TYPE_SEMA_X28; else if (octstr_compare(type, octstr_imm("ois")) == 0) typeno = SMSC_TYPE_OIS; else { error(0, "Unknown SMSC type '%s'", octstr_get_cstr(type)); octstr_destroy(type); return NULL; } host = cfg_get(grp, octstr_imm("host")); if (cfg_get_integer(&port, grp, octstr_imm("port")) == -1) port = 0; if (cfg_get_integer(&receive_port, grp, octstr_imm("receive-port")) == -1) receive_port = 0; if (cfg_get_integer(&our_port, grp, octstr_imm("our-port")) == -1) our_port = 0; username = cfg_get(grp, octstr_imm("smsc-username")); password = cfg_get(grp, octstr_imm("smsc-password")); phone = cfg_get(grp, octstr_imm("phone")); device = cfg_get(grp, octstr_imm("device")); preferred_prefix = cfg_get(grp, octstr_imm("preferred-prefix")); allowed_prefix = cfg_get(grp, octstr_imm("allowed-prefix")); denied_prefix = cfg_get(grp, octstr_imm("denied-prefix")); alt_chars = cfg_get(grp, octstr_imm("alt-charset")); allow_ip = cfg_get(grp, octstr_imm("connect-allow-ip")); sema_smscnua = cfg_get(grp, octstr_imm("smsc_nua")); sema_homenua = cfg_get(grp, octstr_imm("home_nua")); sema_report = cfg_get(grp, octstr_imm("wait_report")); if (sema_report == NULL) iwaitreport = 1; else octstr_parse_long(&iwaitreport, sema_report, 0, 0); if (cfg_get_integer(&keepalive, grp, octstr_imm("keepalive")) == -1) keepalive = 0; if (cfg_get_integer(&alt_dcs, grp, octstr_imm("alt-dcs")) == -1) alt_dcs = 0; if (alt_dcs > 1) alt_dcs = 1; if (cfg_get_integer(&ois_debug, grp, octstr_imm("ois-debug-level")) == -1) ois_debug = 0; sender_prefix = cfg_get(grp, octstr_imm("sender-prefix")); if (sender_prefix == NULL) sender_prefix = octstr_create("never"); smsc = NULL; switch (typeno) { case SMSC_TYPE_CIMD: if (host == NULL || port == 0 || username == NULL || password == NULL) error(0, "Required field missing for CIMD center."); else smsc = cimd_open(octstr_get_cstr(host), port, octstr_get_cstr(username), octstr_get_cstr(password)); break; case SMSC_TYPE_EMI_X25: if (phone == NULL || device == NULL || username == NULL || password == NULL) error(0, "Required field missing for EMI_X25 center."); else smsc = emi_open(octstr_get_cstr(phone), octstr_get_cstr(device), octstr_get_cstr(username), octstr_get_cstr(password)); break; case SMSC_TYPE_SEMA_X28: if (device == NULL || sema_smscnua == NULL || sema_homenua == NULL) error(0, "Required field missing for SEMA center."); else smsc = sema_open(octstr_get_cstr(sema_smscnua), octstr_get_cstr(sema_homenua), octstr_get_cstr(device), iwaitreport); break; case SMSC_TYPE_OIS: if (host == NULL || port == 0 || receive_port == 0) error(0, "Required field missing for OIS center."); else smsc = ois_open(receive_port, octstr_get_cstr(host), port, ois_debug); break; /* add new SMSCes here */ default: /* Unknown SMSC type */ break; } if (smsc != NULL) { if (cfg_get_integer(&smsc->alt_charset, grp, octstr_imm("alt-charset")) == -1) smsc->alt_charset = 0; if (preferred_prefix == NULL) smsc->preferred_prefix = NULL; else smsc->preferred_prefix = gw_strdup(octstr_get_cstr(preferred_prefix)); if (allowed_prefix == NULL) smsc->allowed_prefix = NULL; else smsc->allowed_prefix = gw_strdup(octstr_get_cstr(allowed_prefix)); if (denied_prefix == NULL) smsc->denied_prefix = NULL; else smsc->denied_prefix = gw_strdup(octstr_get_cstr(denied_prefix)); } octstr_destroy(type); octstr_destroy(host); octstr_destroy(username); octstr_destroy(password); octstr_destroy(phone); octstr_destroy(device); octstr_destroy(preferred_prefix); octstr_destroy(denied_prefix); octstr_destroy(allowed_prefix); octstr_destroy(alt_chars); octstr_destroy(allow_ip); octstr_destroy(sema_smscnua); octstr_destroy(sema_homenua); octstr_destroy(sema_report); octstr_destroy(sender_prefix); return smsc; }
int smsc_fake_create(SMSCConn *conn, CfgGroup *cfg) { PrivData *privdata = NULL; Octstr *allow_ip, *deny_ip; long portno; /* has to be long because of cfg_get_integer */ if (cfg_get_integer(&portno, cfg, octstr_imm("port")) == -1) portno = 0; allow_ip = cfg_get(cfg, octstr_imm("connect-allow-ip")); if (allow_ip) deny_ip = octstr_create("*.*.*.*"); else deny_ip = NULL; if (portno == 0) { error(0, "'port' invalid in 'fake' record."); goto error; } privdata = gw_malloc(sizeof(PrivData)); privdata->listening_socket = -1; privdata->port = portno; privdata->allow_ip = allow_ip; privdata->deny_ip = deny_ip; if (fake_open_connection(conn, privdata) < 0) { gw_free(privdata); privdata = NULL; goto error; } conn->data = privdata; conn->name = octstr_format("FAKE:%d", privdata->port); privdata->outgoing_queue = gwlist_create(); privdata->shutdown = 0; conn->status = SMSCCONN_CONNECTING; conn->connect_time = time(NULL); if ((privdata->connection_thread = gwthread_create(fake_listener, conn)) == -1) goto error; conn->shutdown = shutdown_cb; conn->queued = queued_cb; conn->start_conn = start_cb; conn->send_msg = add_msg_cb; return 0; error: error(0, "Failed to create fake smsc connection"); if (privdata != NULL) { gwlist_destroy(privdata->outgoing_queue, NULL); if (close(privdata->listening_socket == -1)) { error(errno, "smsc_fake: closing listening socket port %d failed", privdata->listening_socket); } } gw_free(privdata); octstr_destroy(allow_ip); octstr_destroy(deny_ip); conn->why_killed = SMSCCONN_KILLED_CANNOT_CONNECT; conn->status = SMSCCONN_DEAD; return -1; }