예제 #1
0
int main(int argc, char **argv)
{
    Cfg *cfg;
    int ret = 1;
    Octstr *name;
    int i;
    
    gwlib_init();

    for (i = 1; i < argc; ++i) {
        name = octstr_create(argv[i]);
        cfg = cfg_create(name);
        octstr_destroy(name);
        ret = cfg_read(cfg);
        info(0, "cfg_read returned %d", ret);
        if (ret == 0)
            cfg_dump(cfg);
        cfg_destroy(cfg);
    }
    
    info(0, "Shutting down.");
    gwlib_shutdown();

    return ret;
}
예제 #2
0
파일: cfg.c 프로젝트: jwgcarlson/OPSEC
Config cfg_new_from_stream(FILE* f) {
    Config cfg = cfg_new();
    if(cfg_read(cfg, f) != CFG_OKAY) {
        cfg_destroy(cfg);
        cfg = NULL;
    }
    return cfg;
}
예제 #3
0
파일: cfg.c 프로젝트: jwgcarlson/OPSEC
Config cfg_new_from_file(const char* filename) {
    Config cfg = cfg_new();
    if(cfg_read_file(cfg, filename) != CFG_OKAY) {
        cfg_destroy(cfg);
        cfg = NULL;
    }
    return cfg;
}
예제 #4
0
int main(int argc, char **argv) {
	int cf_index;
	Octstr *filename, *version;

	gwlib_init();
	list_dict = dict_create(32, msg_list_destroy_item);

	cf_index = get_and_set_debugs(argc, argv, check_args);
	setup_signal_handlers();

	if (argv[cf_index] == NULL)
		filename = octstr_create("httpClient.conf");
	else
		filename = octstr_create(argv[cf_index]);

	cfg = cfg_create(filename);

	/* Adding cfg-checks to core */
	cfg_add_hooks(smppbox_is_allowed_in_group, smppbox_is_single_group);

	if (cfg_read(cfg) == -1)
		panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename));

	octstr_destroy(filename);

	version = octstr_format("httpClient version %s gwlib", GW_VERSION);
	report_versions(octstr_get_cstr(version));
	octstr_destroy(version);

	struct server_type *res = NULL;
	res = sqlbox_init_mysql(cfg);
	sqlbox_configure_mysql(cfg);

	init_smpp_server_box(cfg);
	http_client_box_run();

	//gwthread_join_every(sql_to_smpp);
	//gwthread_join_every(smpp_to_sql);
	smpp_server_box_shutdown();

	dict_destroy(list_dict);
	list_dict = NULL;

	cfg_destroy(cfg);

	if (restart_httpbox) {
		gwthread_sleep(1.0);
	}

	gw_smpp_leave();
	gwlib_shutdown();

	if (restart_httpbox)
		execvp(argv[0], argv);
	return 0;
}
예제 #5
0
int main(int argc, char **argv)
{
    int cf_index;
    Octstr *filename;

    gwlib_init();

    cf_index = get_and_set_debugs(argc, argv, check_args);
    setup_signal_handlers();

    if (argv[cf_index] == NULL) {
        filename = octstr_create("sqlbox.conf");
    } else {
        filename = octstr_create(argv[cf_index]);
    }

    cfg = cfg_create(filename);

    /* Adding cfg-checks to core */

    cfg_add_hooks(sqlbox_is_allowed_in_group, sqlbox_is_single_group);

    if (cfg_read(cfg) == -1)
        panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(filename));

    octstr_destroy(filename);

    report_versions("sqlbox");

    init_sqlbox(cfg);

    sqlboxc_run((void *)sqlbox_port);

    cfg_destroy(cfg);
    if (restart_sqlbox) {
        gwthread_sleep(1.0);
    }

    gw_sql_leave();
    gwlib_shutdown();

    if (restart_sqlbox)
        execvp(argv[0], argv);
    return 0;
}
예제 #6
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);
}
예제 #7
0
파일: testio.cpp 프로젝트: jwgcarlson/OPSEC
double* ReadSpectrum(const char* specfile, int* n_, int* nev_) {
    int n, nev;
    double* modes = NULL;
    Config opts = cfg_new();

    FILE* fspec = fopen(specfile, "r");
    if(fspec == NULL) {
        fprintf(stderr, "ReadSpectrum: could not open file '%s'\n", specfile);
        return NULL;
    }

    int err = abn_read(fspec, (void**) &modes, NULL, NULL, NULL, NULL, opts);
    fclose(fspec);

    if(!err && !cfg_has_keys(opts, "n,nev", ",")) {
        fprintf(stderr, "ReadSpectrum: missing options\n");
        err = 1;
    }
    else {
        n = cfg_get_int(opts, "n");
        nev = cfg_get_int(opts, "nev");
    }
    cfg_destroy(opts);

    if(err) {
        fprintf(stderr, "ReadSpectrum: error reading from '%s'\n", specfile);
        perror("system error");
        free(modes);
        return NULL;
    }
    else {
        if(n_) *n_ = n;
        if(nev_) *nev_ = nev;
        return modes;
    }
}
예제 #8
0
int main(int argc, char **argv)
{
    struct sigaction act;
    int port;
    int opt;
    double run_time;
    char *log_file;
    char *config_file;

    gwlib_init();

    act.sa_handler = handler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = 0;
    sigaction(SIGTERM, &act, NULL);
    sigaction(SIGINT, &act, NULL);

    port = 2345;
    smsc_system_id = octstr_create("kannel_smpp");
    smsc_source_addr = octstr_create("123456");
    message_id_counter = counter_create();
    bearerbox_host = octstr_create("127.0.0.1");
    port_for_smsbox = 13001;
    max_to_esme = 1;
    num_to_esme = counter_create();
    num_from_esme = counter_create();
    num_to_bearerbox = counter_create();
    num_from_bearerbox = counter_create();
    log_file = config_file = NULL;

    while ((opt = getopt(argc, argv, "hv:p:m:l:c:")) != EOF) {
	switch (opt) {
	case 'v':
	    log_set_output_level(atoi(optarg));
	    break;

	case 'h':
	    help();
	    exit(0);

	case 'm':
	    max_to_esme = atoi(optarg);
	    break;

	case 'p':
	    port = atoi(optarg);
	    break;

	case 'l':
        log_file = optarg;
        break;
    
    case 'c':
        config_file = optarg;
        break;

	case '?':
	default:
	    error(0, "Invalid option %c", opt);
	    help();
	    panic(0, "Stopping.");
	}
    }

    if (log_file != NULL)
    	log_open(log_file, GW_DEBUG, GW_NON_EXCL);

    if (config_file != NULL) {
        Cfg *cfg;
        Octstr *tmp = octstr_create(config_file);
        
        cfg = cfg_create(tmp);
        octstr_destroy(tmp);
        if (cfg_read(cfg) == -1)
            panic(0, "Errors in config file.");
        smpp_pdu_init(cfg);
        cfg_destroy(cfg);
    }
            
    info(0, "Starting drive_smpp test.");
    gwthread_create(accept_thread, &port);
    gwthread_join_all();
    debug("test.smpp", 0, "Program exiting normally.");

    run_time = difftime(last_from_esme, first_to_esme);

    info(0, "Number of messages sent to ESME: %ld",
    	 counter_value(num_to_esme));
    info(0, "Number of messages sent to smsbox: %ld",
    	 counter_value(num_from_bearerbox));
    info(0, "Number of messages sent to bearerbox: %ld",
    	 counter_value(num_to_bearerbox));
    info(0, "Number of messages sent to SMSC: %ld",
    	 counter_value(num_from_esme));
    info(0, "Time: %.0f secs", run_time);
    info(0, "Time until all sent to ESME: %.0f secs", 
    	 difftime(last_to_esme, start_time));
    info(0, "Time from first from bb to last to bb: %.0f secs", 
    	 difftime(last_to_bb, first_from_bb));
    info(0, "Time until all sent to SMSC: %.0f secs", 
    	 difftime(last_from_esme, start_time));
    info(0, "SMPP messages SMSC to ESME: %.1f msgs/sec",
    	 counter_value(num_to_esme) / run_time);
    info(0, "SMPP messages ESME to SMSC: %.1f msgs/sec",
    	 counter_value(num_from_esme) / run_time);

    octstr_destroy(smsc_system_id);
    octstr_destroy(smsc_source_addr);
    octstr_destroy(bearerbox_host);
    counter_destroy(num_to_esme);
    counter_destroy(num_from_esme);
    counter_destroy(num_to_bearerbox);
    counter_destroy(num_from_bearerbox);
    counter_destroy(message_id_counter);

    gwlib_shutdown();
    return 0;
}
예제 #9
0
파일: bearerbox.c 프로젝트: sivirk/kannel
int main(int argc, char **argv)
{
    int cf_index;
    Cfg *cfg;

    bb_status = BB_RUNNING;
    
    gwlib_init();
    start_time = time(NULL);

    suspended = gwlist_create();
    isolated = gwlist_create();
    gwlist_add_producer(suspended);
    gwlist_add_producer(isolated);

    cf_index = get_and_set_debugs(argc, argv, check_args);

    if (argv[cf_index] == NULL)
        cfg_filename = octstr_create("kannel.conf");
    else
        cfg_filename = octstr_create(argv[cf_index]);
    cfg = cfg_create(cfg_filename);
    
    if (cfg_read(cfg) == -1)
        panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(cfg_filename));

    dlr_init(cfg);
    
    report_versions("bearerbox");

    flow_threads = gwlist_create();
    
    if (init_bearerbox(cfg) == NULL)
        panic(0, "Initialization failed.");

    info(0, "----------------------------------------");
    info(0, GW_NAME " bearerbox II version %s starting", GW_VERSION);

    gwthread_sleep(5.0); /* give time to threads to register themselves */

    if (store_load(dispatch_into_queue) == -1)
        panic(0, "Cannot start with store-file failing");
    
    info(0, "MAIN: Start-up done, entering mainloop");
    if (bb_status == BB_SUSPENDED) {
        info(0, "Gateway is now SUSPENDED by startup arguments");
    } else if (bb_status == BB_ISOLATED) {
        info(0, "Gateway is now ISOLATED by startup arguments");
        gwlist_remove_producer(suspended);
    } else {
        smsc2_resume(1);
        gwlist_remove_producer(suspended);	
        gwlist_remove_producer(isolated);
    }

    while (bb_status != BB_SHUTDOWN && bb_status != BB_DEAD && 
           gwlist_producer_count(flow_threads) > 0) {
        /* debug("bb", 0, "Main Thread: going to sleep."); */
        /*
         * Not infinite sleep here, because we should notice
         * when all "flow threads" are dead and shutting bearerbox
         * down.
         * XXX if all "flow threads" call gwthread_wakeup(MAIN_THREAD_ID),
         * we can enter infinite sleep then.
         */
        gwthread_sleep(10.0);
        /* debug("bb", 0, "Main Thread: woken up."); */

        if (bb_todo == 0) {
            continue;
        }

        if (bb_todo & BB_LOGREOPEN) {
            warning(0, "SIGHUP received, catching and re-opening logs");
            log_reopen();
            alog_reopen();
            bb_todo = bb_todo & ~BB_LOGREOPEN;
        }

        if (bb_todo & BB_CHECKLEAKS) {
            warning(0, "SIGQUIT received, reporting memory usage.");
            gw_check_leaks();
            bb_todo = bb_todo & ~BB_CHECKLEAKS;
        }
    }

    if (bb_status == BB_SHUTDOWN || bb_status == BB_DEAD)
        warning(0, "Killing signal or HTTP admin command received, shutting down...");

    /* call shutdown */
    bb_shutdown();

    /* wait until flow threads exit */
    while (gwlist_consume(flow_threads) != NULL)
        ;

    info(0, "All flow threads have died, killing core");
    bb_status = BB_DEAD;
    httpadmin_stop();

    boxc_cleanup();
    smsc2_cleanup();
    store_shutdown();
    empty_msg_lists();
    gwlist_destroy(flow_threads, NULL);
    gwlist_destroy(suspended, NULL);
    gwlist_destroy(isolated, NULL);
    mutex_destroy(status_mutex);

    alog_close();		/* if we have any */
    bb_alog_shutdown();
    cfg_destroy(cfg);
    octstr_destroy(cfg_filename);
    dlr_shutdown();

    /* now really restart */
    if (restart)
        restart_box(argv);

    gwlib_shutdown();

    return 0;
}
예제 #10
0
int main(int argc, char **argv) {
	int i, opt;
	long repeats;
	URLTranslationList *list;
	URLTranslation *t;
	Cfg *cfg;
	Octstr *name;
	
	gwlib_init();

	repeats = 1;

	while ((opt = getopt(argc, argv, "hr:")) != EOF) {
		switch (opt) {
		case 'r':
			repeats = atoi(optarg);
			break;

		case 'h':
			help();
			exit(0);
		
		case '?':
		default:
			error(0, "Invalid option %c", opt);
			help();
			panic(0, "Stopping.");
		}
	}

	if (optind + 1 >= argc) {
		error(0, "Missing arguments.");
		help();
		panic(0, "Stopping.");
	}
	name = octstr_create(argv[optind]);
	cfg = cfg_create(name);
	octstr_destroy(name);
	if (cfg_read(cfg) == -1)
		panic(0, "Couldn't read configuration file.");
	
	list = urltrans_create();
	if (urltrans_add_cfg(list, cfg) == -1)
		panic(0, "Error parsing configuration.");

	while (repeats-- > 0) {
		for (i = optind + 1; i < argc; ++i) {
		        Msg *msg = msg_create(sms);
		        msg->sms.msgdata = octstr_create(argv[i]);
			t = urltrans_find(list, msg);
			info(0, "type = %d", urltrans_type(t));
			msg_destroy(msg);
		}
	}
	urltrans_destroy(list);
	cfg_destroy(cfg);
	
	gwlib_shutdown();
	
	return 0;
}
예제 #11
0
/* initiate the cfg framework */
int sr_cfg_init(void)
{
	cfg_global_lock = lock_alloc();
	if (!cfg_global_lock) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
		goto error;
	}
	if (lock_init(cfg_global_lock) == 0) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): failed to init lock\n");
		lock_dealloc(cfg_global_lock);
		cfg_global_lock = 0;
		goto error;
	}

	cfg_writer_lock = lock_alloc();
	if (!cfg_writer_lock) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
		goto error;
	}
	if (lock_init(cfg_writer_lock) == 0) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): failed to init lock\n");
		lock_dealloc(cfg_writer_lock);
		cfg_writer_lock = 0;
		goto error;
	}

	cfg_global = (cfg_block_t **)shm_malloc(sizeof(cfg_block_t *));
	if (!cfg_global) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
		goto error;
	}
	*cfg_global = NULL;

	cfg_child_cb_first = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
	if (!cfg_child_cb_first) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
		goto error;
	}
	*cfg_child_cb_first = NULL;

	cfg_child_cb_last = (cfg_child_cb_t **)shm_malloc(sizeof(cfg_child_cb_t *));
	if (!cfg_child_cb_last) {
		LOG(L_ERR, "ERROR: sr_cfg_init(): not enough shm memory\n");
		goto error;
	}
	*cfg_child_cb_last = NULL;

	/* A new cfg_child_cb struct must be created with a NULL callback function.
	This stucture will be the entry point for the child processes, and
	will be freed later, when none of the processes refers to it */
	*cfg_child_cb_first = *cfg_child_cb_last =
		cfg_child_cb_new(NULL, NULL, NULL, 0);

	if (!*cfg_child_cb_first) goto error;

	return 0;

error:
	cfg_destroy();

	return -1;
}
예제 #12
0
파일: wapbox.c 프로젝트: tphipps/kannel
/*
 * 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 */
}
예제 #13
0
파일: wapbox.c 프로젝트: tphipps/kannel
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;
}
예제 #14
0
int main(int argc, char **argv)
{
	char id[UUID_STR_LEN + 1];
    int cf_index, ret, type;
    Octstr *os, *store_type, *store_location, *status;
	Msg *msg;
	CfgGroup *grp;

	conf_file = NULL;

    gwlib_init();

    //This can be overwritten with the -v flag at runtime
    log_set_output_level(DEFAULT_LOG_LEVEL);

    cf_index = get_and_set_debugs(argc, argv, check_args);

    if (argv[cf_index] == NULL) {
        print_usage(argv[0]);
        goto error;
    }

    if (conf_file == NULL)
    	conf_file = octstr_create("kannel.conf");

    cfg = cfg_create(conf_file);

    if (cfg_read(cfg) == -1)
    	panic(0, "Couldn't read configuration from `%s'.", octstr_get_cstr(conf_file));
	info(0, "1");
    grp = cfg_get_single_group(cfg, octstr_imm("core"));
    if (grp == NULL) {
    	printf("FATAL: Could not load Kannel's core group. Exiting.\n");
    	return 2;
    }

    store_location = cfg_get(grp, octstr_imm("store-location"));
    store_type = cfg_get(grp, octstr_imm("store-type"));

    store_init(store_type, store_location, -1, msg_pack, msg_unpack_wrapper);

    switch (command) {
    case COMMAND_LIST:
    	printf("Listing records %d -> %d\n", list_from+1, list_limit);
    	print_header();
		store_load(print_msg);
		if (counter == 0) {
			printf("|%60s%14s%60s|\n", "", "Store is Empty", "");
		}
		print_sep();
		break;
    case COMMAND_DELETE:
    	store_load(msg_count);
    	msg = msg_create(ack);
    	msg->ack.nack = ack_failed;
    	msg->ack.time = time(NULL);
    	uuid_parse(octstr_get_cstr(param_1), msg->ack.id);
    	ret = store_save(msg);
        if (ret == 0) {
        	printf("Deleted message %s\n", octstr_get_cstr(param_1));
        	counter--;
        } else {
        	printf("Could not delete message %s\n", octstr_get_cstr(param_1));
        }
        msg_destroy(msg);
		break;
    case COMMAND_EXPORT:
    	counter = 0;
    	type = 0;
    	list = gwlist_create();
    	store_load(msg_push);
    	printf("Exporting %ld messages...\n", gwlist_len(list));
    	if ((octstr_compare(param_1, octstr_imm("file")) == 0) ||
    		(octstr_compare(param_1, octstr_imm("spool")) == 0)) {
        	store_shutdown();
        	store_init(param_1, param_2, -1, msg_pack, msg_unpack_wrapper);
        	store_load(msg_count);
        	while ((os = gwlist_extract_first(list)) != NULL) {
        		msg = msg_unpack_wrapper(os);
        		if (msg != NULL) {
    				ret = store_save(msg);
    				if (ret == 0) {
    					counter++;
    				} else {
    					printf("Error saving message\n");
    				}
        		} else {
        			printf("Error extracting message\n");
        		}
        		msg_destroy(msg);
        	}
        	status = NULL;
    	} else if (octstr_compare(param_1, octstr_imm("text")) == 0) {
    		status = store_status(BBSTATUS_TEXT);
    	} else if (octstr_compare(param_1, octstr_imm("html")) == 0) {
    		status = store_status(BBSTATUS_HTML);
    	} else if (octstr_compare(param_1, octstr_imm("xml")) == 0) {
    		status = store_status(BBSTATUS_XML);
		} else {
			status = NULL;
		}
    	if (status != NULL) {
    	    file = fopen(octstr_get_cstr(param_2), "w");
    	    if (file == NULL) {
    	        error(errno, "Failed to open '%s' for writing, cannot create output file",
    		      octstr_get_cstr(param_2));
    	        return -1;
    	    }
    	    octstr_print(file, status);
    	    fflush(file);
    	    if (file != NULL)
    	    	fclose(file);
    		//printf("%s", octstr_get_cstr(status));
    	}
    	gwlist_destroy(list, octstr_destroy_item);

		break;
    default:
    	break;
    }

    octstr_destroy(store_type);
    octstr_destroy(store_location);
    cfg_destroy(cfg);
    store_shutdown();
error:
    gwlib_shutdown();

    return 1;
}