Example #1
0
bool parse_ue_sim_param(config_setting_t *ue_setting, int user_id, usim_data_conf_t *u) {
	int rc = true;
	config_setting_t *ue_param_setting = NULL;
	ue_param_setting = config_setting_get_member(ue_setting, SIM);
	if (ue_param_setting == NULL) {
		printf("Check SIM section for UE%d. EXITING...\n", user_id);
		return false;
	}
	rc = config_setting_lookup_string(ue_param_setting, MSIN, &u->msin);
	if (rc != 1 || strlen(u->msin) > 10 || strlen(u->msin) < 9) {
		printf("Check SIM MSIN section for UE%d. Exiting\n", user_id);
		return false;
	}
	rc = config_setting_lookup_string(ue_param_setting, USIM_API_K,
			&u->usim_api_k);
	if (rc != 1) {
		printf("Check SIM USIM_API_K  section for UE%d. Exiting\n", user_id);
		return false;
	}
	rc = config_setting_lookup_string(ue_param_setting, OPC, &u->opc);
	if (rc != 1) {
		printf("Check SIM OPC section for UE%d. Exiting\n", user_id);
		return false;
	}
	rc = config_setting_lookup_string(ue_param_setting, MSISDN, &u->msisdn);
	if (rc != 1) {
		printf("Check SIM MSISDN section for UE%d. Exiting\n", user_id);
		return false;
	}
	return true;
}
Example #2
0
void configure_cgi_handlers(spade_server* server, config_t* configuration) {
    config_setting_t* handler_settings = config_lookup(configuration,
            "cgi.handlers");
    int cgi_handler_count = config_setting_length(handler_settings);

    for (int n = 0; n < cgi_handler_count; n++) {
        config_setting_t* handler_setting = config_setting_get_elem(
                handler_settings, n);
        const char* handler = NULL;
        config_setting_lookup_string(handler_setting, "handler", &handler);

        const char* url = NULL;
        config_setting_lookup_string(handler_setting, "url", &url);

        if(!register_cgi_handler(server, url, handler)) {
            log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                    "Registered CGI handler '%s' for URL prefix '%s'",
                    handler, url);
        }
    }
    if (server->cgi_handler_count == 0) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No CGI handlers registered");
    } else {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "Registered a total of %d CGI handlers",
                server->cgi_handler_count);
    }
}
Example #3
0
/*! \brief read pair setting */
static int read_pairs_setting(config_setting_t * setting, add_pair_mapping add, void * data)
{
	int i;
	config_setting_t * pair;
	for (i = 0; (pair = config_setting_get_elem(setting, i)) != NULL; ++i)
	{
		int rv;
		const char * local;
		const char * remote;

		rv = config_setting_lookup_string(pair, "local", &local);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Failed to read local key from pairs in shared config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_string(pair, "remote", &remote);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Failed to read remote key from pairs in shared config.\n");
			return CONFIG_FALSE;
		}

		add(data, local, remote);
	}

	return CONFIG_TRUE;
}
Example #4
0
void configure_clay_handlers(spade_server* server, config_t* configuration) {
    config_setting_t* handler_settings = config_lookup(configuration,
            "clay.handlers");
    if (!handler_settings) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No Clay handlers registered");
        return;
    }
    int clay_handler_count = config_setting_length(handler_settings);

    for (int n = 0; n < clay_handler_count; n++) {
        config_setting_t* handler_setting = config_setting_get_elem(
                handler_settings, n);
        const char* endpoint = NULL;
        config_setting_lookup_string(handler_setting, "endpoint", &endpoint);

        const char* url = NULL;
        config_setting_lookup_string(handler_setting, "url", &url);

        if(!register_clay_handler(server, url, endpoint)) {
            log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                    "Registered Clay handler for URL prefix '%s' at endpoint %s",
                    url, endpoint);
        }
    }
    if (server->clay_handler_count == 0) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No Clay handlers registered");
    } else {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "Registered a total of %d Clay handlers",
                server->clay_handler_count);
    }
}
Example #5
0
/*! \brief read dokan config from local config */
static int read_dokan_config(config_t * config)
{
	config_setting_t * dokan_setting = config_lookup(config, "dokan");
	if (dokan_setting == NULL)
	{
		message(LOG_INFO, FACILITY_CONFIG, "No dokan section was found in local config.\n");
		return CONFIG_TRUE;
	}

	int rv;
	const char * volume_name;
	/* dokan::volume_name */
	rv = config_setting_lookup_string(dokan_setting, "volume_name", &volume_name);
	if (rv == CONFIG_TRUE)
	{
		xmkstring(&(zfs_config.dokan.volume_name), volume_name);
	}

	const char * file_system_name;
	/* dokan::filesystem_name */
	rv = config_setting_lookup_string(dokan_setting, "file_system_name", &file_system_name);
	if (rv == CONFIG_TRUE)
	{
		xmkstring(&(zfs_config.dokan.file_system_name), file_system_name);
	}

	return CONFIG_TRUE;
}
static int
load_mods(config_t *config, config_setting_t *setting)
{
    int err;
    unsigned int mod_count;
    int i;
    const char* mod_name;
    const char* mod_so;
    const char* mod_ident;
    config_setting_t *mod_setting;
    err = 0;

    fprintf(stderr, "load mods from config\n");
    setting = config_lookup(config, "mods");
    if (setting != NULL) {
        mod_count = config_setting_length(setting);
        for (i = 0; i < mod_count; ++i) {
            mod_setting = config_setting_get_elem(setting, i);
            if (mod_setting) {
                if (!config_setting_lookup_string(mod_setting,
                                                  "name",
                                                  &mod_name) ||
                        !config_setting_lookup_string(mod_setting,
                                                      "so",
                                                      &mod_so)) {
                    continue;
                }
                if (!config_setting_lookup_string(mod_setting,
                                                  "ident",
                                                  &mod_ident)) {
                    mod_ident = NULL;
                }
                fprintf(stderr, "load module %s - %s - [%s]\n",
                        mod_name, mod_so, mod_ident);
                module_t *mod = module_open(mod_name,
                                            mod_ident,
                                            mod_so,
                                            RTLD_NOW);
                if (!mod) {
                    err = 1;
                    break;
                }
                if (module_map_insert(&g_config.module_root, mod) == NULL) {
                    err = 1;
                    module_close(mod);
                    break;
                }
                if (module_call_init_func(mod, &g_config)) {
                    fprintf(stderr, "ERROR %s returned not 0\n", mod->name);
                    err = 1;
                    module_close(mod);
                    break;
                }
            }
        }
    }

    return err;
}
Example #7
0
static GtkWidget *
thermal_constructor(LXPanel *panel, config_setting_t *settings)
{
    thermal *th;
    GtkWidget *p;
    const char *tmp;

    ENTER;
    th = g_new0(thermal, 1);
    th->panel = panel;
    th->settings = settings;

    p = gtk_event_box_new();
    lxpanel_plugin_set_data(p, th, thermal_destructor);
    gtk_widget_set_has_window(p, FALSE);
    gtk_container_set_border_width( GTK_CONTAINER(p), 2 );

    th->namew = gtk_label_new("ww");
    gtk_container_add(GTK_CONTAINER(p), th->namew);

    th->tip = g_string_new(NULL);

    /* By default, use automatic, that is, "not custom" temperature levels. If
     * we were using custom levels, they would be 0°C at startup, so we would
     * display in warning colors by default. */
    th->not_custom_levels = TRUE;

    if (config_setting_lookup_string(settings, "NormalColor", &tmp))
        th->str_cl_normal = g_strdup(tmp);
    if (config_setting_lookup_string(settings, "Warning1Color", &tmp))
        th->str_cl_warning1 = g_strdup(tmp);
    if (config_setting_lookup_string(settings, "Warning2Color", &tmp))
        th->str_cl_warning2 = g_strdup(tmp);
    config_setting_lookup_int(settings, "AutomaticSensor", &th->auto_sensor);
    /* backward compatibility for wrong variable */
    config_setting_lookup_int(settings, "CustomLevels", &th->not_custom_levels);
    config_setting_lookup_int(settings, "AutomaticLevels", &th->not_custom_levels);
    if (config_setting_lookup_string(settings, "Sensor", &tmp))
        th->sensor = g_strdup(tmp);
    config_setting_lookup_int(settings, "Warning1Temp", &th->warning1);
    config_setting_lookup_int(settings, "Warning2Temp", &th->warning2);

    if(!th->str_cl_normal)
        th->str_cl_normal = g_strdup("#00ff00");
    if(!th->str_cl_warning1)
        th->str_cl_warning1 = g_strdup("#fff000");
    if(!th->str_cl_warning2)
        th->str_cl_warning2 = g_strdup("#ff0000");

    applyConfig(p);

    gtk_widget_show(th->namew);

    update_display(th);
    th->timer = g_timeout_add_seconds(3, (GSourceFunc) update_display_timeout, (gpointer)th);

    RET(p);
}
Example #8
0
/**
 * Attempt to create a global channel from the channel config
 * @param chan: Channel list
 * @param tmp_chan: Temporary channel data
 * @param i: Index
 * @return True on success or false on failure
 */
bool channel_read_sub(config_setting_t *chan, struct Channel *tmp_chan, uint8 i) {
	config_setting_t  *group_list = NULL;
	int delay = 1000, autojoin = 0, leave = 1, chat = 1, color_override = 0,
		self_notif = 1, join_notif = 0, leave_notif = 0;
	int type = CHAN_TYPE_PUBLIC, group_count = 0;
	const char *name = NULL, *password = NULL, *alias = NULL, *color_str = "Default", *type_str = NULL;

	if (tmp_chan == NULL)
		return false;

	if (!config_setting_lookup_string(chan, "name", &name)) {
		ShowError("Please input channel 'name' at '%s' line '%d'! Skipping...\n", chan->file, chan->line);
		return false;
	}
	if (config_setting_lookup_string(chan, "type", &type_str) && !script_get_constant(type_str, &type)) {
		ShowError("Invalid channel type %s at '%s' line '%d'! Skipping...\n", type_str, chan->file, chan->line);
		return false;
	}
	config_setting_lookup_string(chan, "password", &password);
	config_setting_lookup_string(chan, "alias", &alias);
	config_setting_lookup_string(chan, "color", &color_str);
	config_setting_lookup_int(chan, "delay", &delay);
	config_setting_lookup_bool(chan, "autojoin", &autojoin);
	config_setting_lookup_bool(chan, "leave", &leave);
	config_setting_lookup_bool(chan, "chat", &chat);
	config_setting_lookup_bool(chan, "color_override", &color_override);
	config_setting_lookup_bool(chan, "self_notif", &self_notif);
	config_setting_lookup_bool(chan, "join_notif", &join_notif);
	config_setting_lookup_bool(chan, "leave_notif", &leave_notif);

	safestrncpy(tmp_chan->name,name+1,sizeof(tmp_chan->name));
	if (password)
		safestrncpy(tmp_chan->pass,password,sizeof(tmp_chan->pass));
	else
		tmp_chan->pass[0] = '\0';
	safestrncpy(tmp_chan->alias,alias?alias:name,sizeof(tmp_chan->alias));
	tmp_chan->msg_delay = delay;
	tmp_chan->type = (enum Channel_Type)type;
	tmp_chan->color = channel_getColor(color_str);

	tmp_chan->opt = (autojoin ? CHAN_OPT_AUTOJOIN : 0) |
		(leave ? CHAN_OPT_CAN_LEAVE : 0) |
		(chat ? CHAN_OPT_CAN_CHAT : 0) |
		(color_override ? CHAN_OPT_COLOR_OVERRIDE : 0) |
		(self_notif ? CHAN_OPT_ANNOUNCE_SELF : 0) |
		(join_notif ? CHAN_OPT_ANNOUNCE_JOIN : 0) |
		(leave_notif ? CHAN_OPT_ANNOUNCE_LEAVE : 0);

	if ((group_list = config_setting_get_member(chan, "groupid")) && (group_count = config_setting_length(group_list)) > 0) {
		int j;
		CREATE(tmp_chan->groups, unsigned short, group_count);
		tmp_chan->group_count = group_count;
		for (j = 0; j < group_count; j++) {
			int groupid = config_setting_get_int_elem(group_list, j);
			tmp_chan->groups[j] = groupid;
		}
	}
Example #9
0
int read_node_list_shared_config(config_t * config)
{
	config_setting_t * node_list = config_lookup(config, "node:list");
	if (node_list == NULL)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "No node list section in shared config was found.\n");
		return CONFIG_FALSE;
	}

	config_setting_t * node_entry;
	int i;

	for (i = 0; (node_entry = config_setting_get_elem(node_list, i)) != NULL; ++i)
	{
		
		uint64_t id;
		const char * name;
		const char * address;
		int rv;

		rv = config_setting_lookup_uint64_t(node_entry, "id", &id);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Id config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_string(node_entry, "name", &name);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Name config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_string(node_entry, "address", &address);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Addres config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		string str_name;
		string str_address;

		xmkstring(&str_name, name);
		xmkstring(&str_address, address);

		node nod = try_create_node(id, &str_name, &str_name, read_tcp_port_setting(node_entry));
		if (nod)
			zfsd_mutex_unlock(&nod->mutex);
	}

	return CONFIG_TRUE;
}
Example #10
0
/*! \brief reads volume entry from shared config */
static int volume_entry_read(config_setting_t * volume_setting, volume_entry * ve)
{
	int rv;

	uint64_t id;
	rv = config_setting_lookup_uint64_t(volume_setting, "id", &id);
	if (rv != CONFIG_TRUE)
	{
		message (LOG_ERROR, FACILITY_CONFIG, "Id confg key is missing or is wrong type in volume list.\n");
		return CONFIG_FALSE;
	}

	const char * volume_name;
	rv = config_setting_lookup_string(volume_setting, "name", &volume_name);
	if (rv != CONFIG_TRUE)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Name config key is missing or is wrong type in volume list.\n");
		return CONFIG_FALSE;
	}

	const char * volume_mountpoint;
	rv = config_setting_lookup_string(volume_setting, "mountpoint", &volume_mountpoint);
	if (rv != CONFIG_TRUE)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Mountpoint config key is missing or is wrong type in volume list.\n");
		return CONFIG_FALSE;
	}
	
	if (is_valid_volume_id(id) == false)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Volume id is invalid.\n");
		return CONFIG_FALSE;
	}

	if (is_valid_volume_name(volume_name) == false)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Volume name is invalid.\n");
		return CONFIG_FALSE;
	}

	if (is_valid_local_path(volume_mountpoint) == false)
	{
		message(LOG_ERROR, FACILITY_CONFIG, "Volume mountpoint is invalid.\n");
		return CONFIG_FALSE;
	}

	//id, name mountpoint
	ve->id = id;
	xmkstring(&ve->name, volume_name);
	xmkstring(&ve->mountpoint, volume_mountpoint);

	return CONFIG_TRUE;
}
Example #11
0
static GtkWidget *
monitors_constructor(LXPanel *panel, config_setting_t *settings)
{
    ENTER;
    int i;
    MonitorsPlugin *mp;
    GtkWidget *p;
    const char *tmp;

    mp = g_new0(MonitorsPlugin, 1);
    mp->panel = panel;
    mp->settings = settings;

    p = gtk_hbox_new(TRUE, 2);
    lxpanel_plugin_set_data(p, mp, monitors_destructor);

    /* First time we use this plugin : only display CPU usage */
    mp->displayed_monitors[CPU_POSITION] = 1;

    /* Apply options */
    config_setting_lookup_int(settings, "DisplayCPU",
                              &mp->displayed_monitors[CPU_POSITION]);
    config_setting_lookup_int(settings, "DisplayRAM",
                              &mp->displayed_monitors[MEM_POSITION]);
    if (config_setting_lookup_string(settings, "Action", &tmp))
        mp->action = g_strdup(tmp);
    if (config_setting_lookup_string(settings, "CPUColor", &tmp))
        colors[CPU_POSITION] = g_strndup(tmp, COLOR_SIZE-1);
    if (config_setting_lookup_string(settings, "RAMColor", &tmp))
        colors[MEM_POSITION] = g_strndup(tmp, COLOR_SIZE-1);

    /* Initializing monitors */
    for (i = 0; i < N_MONITORS; i++)
    {
        if (!colors[i])
            colors[i] = g_strndup(default_colors[i], COLOR_SIZE-1);

        if (mp->displayed_monitors[i])
        {
            mp->monitors[i] = monitors_add_monitor(p, mp,
                                                   update_functions[i],
                                                   tooltip_update[i],
                                                   colors[i]);
        }
    }

    /* Adding a timer : monitors will be updated every UPDATE_PERIOD
     * seconds */
    mp->timer = g_timeout_add_seconds(UPDATE_PERIOD, (GSourceFunc) monitors_update,
                              (gpointer) mp);
    RET(p);
}
Example #12
0
/**
 * Load interfaces section.
 * @param[in] option Option name.
 * @param[in,out] array Resulting array.
 * @return <0 - error. 0 - success. >0 - not found.
 */
int zcfg_load_interfaces(const config_setting_t *option, UT_array *array)
{
    utarray_init(array, &ut_zif_pair_icd);

    if (!option) {
        return 1;
    }

    if (CONFIG_TYPE_LIST != option->type) {
        return -1;
    }

    u_int count = (u_int) config_setting_length(option);

    for (u_int i = 0; i < count; i++) {
        zifpair_t if_pair;
        const char *str;
        config_setting_t *entry = config_setting_get_elem(option, i);

        if (!config_setting_lookup_string(entry, ZCFG_LAN, &str)) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid or missing 'lan' property", option->parent->name, option->name);
            goto fail;
        }
        strncpy(if_pair.lan, str, sizeof(if_pair.lan));

        if (!config_setting_lookup_string(entry, ZCFG_WAN, &str)) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid or missing 'wan' property", option->parent->name, option->name);
            goto fail;
        }
        strncpy(if_pair.wan, str, sizeof(if_pair.wan));

        int affinity = 0;
        if (!config_setting_lookup_int(entry, ZCFG_AFFINITY, &affinity)) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid or missing 'affinity' property", option->parent->name, option->name);
            goto fail;
        }
        if ((affinity < 0) || affinity >= UINT16_MAX) {
            ZLOG(LOG_ERR, "config:%s:%s: invalid 'affinity' value", option->parent->name, option->name);
            goto fail;
        }
        if_pair.affinity = (uint16_t) affinity;

        utarray_push_back(array, &if_pair);
    }

    return 0;

    fail:
    utarray_done(array);
    return -1;
}
static void setup(config_setting_t *settings)
{
    if (settings != NULL) {
        config_setting_lookup_string(settings, "apikey", &apikey);
        config_setting_lookup_string(settings, "email", &email);

        unsigned char *md5bytes = MD5((unsigned char *)email, strlen(email), NULL);

        int i;
        for (i = 0; i < MD5_DIGEST_LENGTH; i++) {
            sprintf(&md5email[i*2], "%02x", md5bytes[i]);
        }
    }
}
Example #14
0
/* Plugin constructor. */
static GtkWidget *wincmd_constructor(LXPanel *panel, config_setting_t *settings)
{
    /* Allocate plugin context and set into Plugin private data pointer. */
    WinCmdPlugin * wc = g_new0(WinCmdPlugin, 1);
    GtkWidget * p;
    const char *str;
    int tmp_int;

    /* Initialize to defaults. */
    wc->button_1_command = WC_ICONIFY;
    wc->button_2_command = WC_SHADE;

    /* Load parameters from the configuration file. */
    if (config_setting_lookup_string(settings, "Button1", &str))
    {
        if (g_ascii_strcasecmp(str, "shade") == 0)
            wc->button_1_command = WC_SHADE;
        else if (g_ascii_strcasecmp(str, "none") == 0)
            wc->button_1_command = WC_NONE;
        /* default is WC_ICONIFY */
    }
    if (config_setting_lookup_string(settings, "Button2", &str))
    {
        if (g_ascii_strcasecmp(str, "iconify") == 0)
            wc->button_2_command = WC_ICONIFY;
        else if (g_ascii_strcasecmp(str, "none") == 0)
            wc->button_2_command = WC_NONE;
    }
    if (config_setting_lookup_string(settings, "image", &str))
        wc->image = expand_tilda(str);
    if (config_setting_lookup_int(settings, "Toggle", &tmp_int))
        wc->toggle_preference = tmp_int != 0;

    /* Default the image if unspecified. */
    if (wc->image == NULL)
        wc->image = g_strdup("window-manager");

    /* Save construction pointers */
    wc->settings = settings;

    /* Allocate top level widget and set into Plugin widget pointer. */
    p = lxpanel_button_new_for_icon(panel, wc->image, NULL, NULL);
    lxpanel_plugin_set_data(p, wc, wincmd_destructor);
    gtk_container_set_border_width(GTK_CONTAINER(p), 0);
    gtk_widget_set_tooltip_text(p, _("Left click to iconify all windows.  Middle click to shade them."));

    /* Show the widget and return. */
    return p;
}
Example #15
0
void print_layouts(int num_frame)
{
	
	config_setting_t *category_list, *category, *layout_list, *layout;
	config_t layout_config;
	int layout_length, i;
	const char* ascii_image;

	config_init(&layout_config);
	config_read_file(&layout_config, "./layout.cfg");
	
	category_list = config_lookup(&layout_config, "application.layout_group");
	category = config_setting_get_elem(category_list, num_frame - MIN_NUM_FRAME);
	
	layout_list = config_setting_get_member(category, "layout");
	layout_length = config_setting_length(layout_list);
	for(i = 0; i < layout_length; i++)
	{
		layout = config_setting_get_elem(layout_list, i);
		config_setting_lookup_string(layout, "image", &ascii_image);
		printf(" %c)\n", 'a' + i);
		printf("%s\n", ascii_image);
	}
	
	config_destroy(&layout_config);
}
Example #16
0
static void configure(config_setting_t *setting_recording, int gfx_event_id)
{
	const char *output_file;

	if (config_setting_lookup_string(setting_recording, CFG_OUTPUT_FILE, &output_file) != CONFIG_TRUE)
	{
		LOG_ERROR("Recording not started: no output file specified");
	}

	SF_INFO sndinfo;

	sndinfo.samplerate = 44100;
	sndinfo.channels = 2;
	sndinfo.format = SF_FORMAT_WAV|SF_FORMAT_PCM_16;
	sndfile = sf_open(output_file, SFM_WRITE, &sndinfo);

	if (sndfile != NULL)
	{
		gfx_object.id = gfx_event_id;
		gfx_register_event_receiver_handler(GFX_EVENT_WAVE, wave_event_handler, &gfx_object);
		gfx_register_event_receiver_handler(GFX_EVENT_SILENCE, silence_event_handler, &gfx_object);
	}
	else
	{
		LOG_ERROR("Recording not started: %s", sf_strerror(sndfile));
	}
}
Example #17
0
int read_mapping_setting(config_setting_t * setting, add_mapping add, void * data)
{
	int i;
	config_setting_t * pair;
	for (i = 0; (pair = config_setting_get_elem(setting, i)) != NULL; ++i)
	{
		int rv;
		uint64_t id;

		rv = config_setting_lookup_uint64_t(pair, "id", &id);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Id config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		const char * name;
		rv = config_setting_lookup_string(pair, "name", &name);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_ERROR, FACILITY_CONFIG, "Name config key is wrong type or is missing in shared config.\n");
			return CONFIG_FALSE;
		}

		string str_name;
		xmkstring(&str_name, name);
		add(data, id, &str_name);	
	}

	return CONFIG_TRUE;
}
Example #18
0
/*! \brief read volume tree node settings */
static int read_volume_tree_node_setting(config_setting_t * node_setting)
{
	int rv;
	const char * node_key;

	rv = config_setting_lookup_string(node_setting, "node", &node_key);
	if (rv != CONFIG_TRUE)
	{
		message(LOG_INFO, FACILITY_CONFIG, "No node key in hierarchy tree in shared config found.\n");
		return rv;
	}

	config_setting_t * children = config_setting_get_member(node_setting, "children");
	if (children == NULL)
		return CONFIG_TRUE;

	int i;
	config_setting_t * child;
	
	for (i = 0; (child = config_setting_get_elem(children, i)) != NULL; ++i)
	{
		rv = read_volume_tree_node_setting(child);
		if (rv != CONFIG_TRUE)
		{
			message(LOG_INFO, FACILITY_CONFIG, "Failed to read hierarchy tree from shared config.\n"); 
			return rv;
		}
	}

	return CONFIG_TRUE;
}
Example #19
0
/**
 * Checks if the configuration is valid. The function checks if all 
 * required parameters are set and adds default values if necessary.
 * @param cfg configuration
 */
void config_check(config_t *cfg)
{
    int i, j;
    const char *s;
    double f;
    config_setting_t *cs, *vs;

    for (i = 0; defaults[i].name; i++) {
        /* Lookup setting group */
        cs = config_lookup(cfg, defaults[i].group);
        if (!cs)
            cs = config_setting_add(config_root_setting(cfg),
                                    defaults[i].group, CONFIG_TYPE_GROUP);

        /* (1) Check for string */
        if (defaults[i].type == CONFIG_TYPE_STRING) {
            if (config_setting_lookup_string(cs, defaults[i].name, &s))
                continue;

            /* Add default value */
            vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_STRING);
            config_setting_set_string(vs, defaults[i].val.sval);
        /* (2) Check for float */            
        } else if (defaults[i].type == CONFIG_TYPE_FLOAT) {
            if (config_setting_lookup_float(cs, defaults[i].name, &f))
                continue;

            /* Check for mis-interpreted integer */
            if (config_setting_lookup_int(cs, defaults[i].name, &j)) {
                config_setting_remove(cs, defaults[i].name);
                vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_FLOAT);
                config_setting_set_float(vs, (double) j);
                continue;
            }

            /* Add default value */
            vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_FLOAT);
            config_setting_set_float(vs, defaults[i].val.fval);
        /* (3) Check for integer */            
        } else if (defaults[i].type == CONFIG_TYPE_INT) {
            if (config_setting_lookup_int(cs, defaults[i].name, &j))
                continue;

            /* Check for mis-interpreted float */
            if (config_setting_lookup_float(cs, defaults[i].name, &f)) {
                config_setting_remove(cs, defaults[i].name);
                vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_INT);
                config_setting_set_int(vs, (long) round(f));
                continue;
            }

            /* Add default value */
            vs = config_setting_add(cs, defaults[i].name, CONFIG_TYPE_INT);
            config_setting_set_int(vs, defaults[i].val.ival);
        } else {
            error("Unknown configuration type");
        }
    }
}
Example #20
0
int initialize_rig()
{
  RIG *my_rig;            /* handle to rig (nstance) */
  int retcode;

  config_setting_t *rig_control_settings;
  rig_control_settings = config_lookup(&cfg, "repeater.rig_control");

  int rig_id, baud_rate, data_bits, stop_bits, enabled;
  const char *serial_port, *frequency;
  
  config_setting_lookup_int(rig_control_settings, "rig_id", &rig_id);
  config_setting_lookup_int(rig_control_settings, "baud_rate", &baud_rate);
  config_setting_lookup_int(rig_control_settings, "data_bits", &data_bits);
  config_setting_lookup_int(rig_control_settings, "stop_bits", &stop_bits);
  config_setting_lookup_bool(rig_control_settings, "enabled", &enabled);
  config_setting_lookup_string(rig_control_settings, "frequency", &frequency);
  config_setting_lookup_string(rig_control_settings, "serial_port", &serial_port);

  if (!enabled)
    return -1;
  
  printf("frequency: %s\n", frequency);

  rig_set_debug(RIG_DEBUG_WARN);
  my_rig = rig_init(rig_id);

  if (!my_rig) {
    fprintf(stderr,"Unknown rig num: %d\n", rig_id);
    fprintf(stderr,"Please check riglist.h\n");
    exit(1); /* whoops! something went wrong (mem alloc?) */
  }

  strncpy(my_rig->state.rigport.pathname, "/dev/ttyS0", FILPATHLEN - 1);
  my_rig->state.rigport.parm.serial.rate = baud_rate;
  my_rig->state.rigport.parm.serial.data_bits = data_bits;
  my_rig->state.rigport.parm.serial.stop_bits = stop_bits;

  retcode = rig_open(my_rig);
  if (retcode != RIG_OK) {
    printf("rig_open: error = %s\n", rigerror(retcode));
    exit(2);
  }

  return rig_set_freq(my_rig, RIG_VFO_CURR, atoi(frequency));
}
Example #21
0
void upd8_source_parse(upd8_source_t *source, config_setting_t *setting) {
  if (source == NULL) {
    fprintf(stderr, "source passed to source_parse was null");
    return;
  }
  source->name = NULL;
  source->update_cmd = NULL;
  source->frequency_update_hours = 0;
  // TODO: check return values:
  config_setting_lookup_string(setting, name_subpath,
                               (const char **)&(source->name));
  config_setting_lookup_string(setting, update_cmd_subpath,
                               (const char **)&(source->update_cmd));
  config_setting_lookup_int(setting, frequency_update_hours_subpath,
                            &(source->frequency_update_hours));
  // TODO: implement
}
Example #22
0
void init(config_setting_t *setting)
{
	const char *str;
	config_setting_lookup_string(setting, "filename", &str);
	char file[256];
	sprintf(file, "pcapfile:%s",str);
	output = trace_create_output(file);
	trace_start_output(output);
}
Example #23
0
/**
 * Load required string value from config.
 * @param[in] cfg Config section.
 * @param[in] opt Option name.
 * @param[out] val Value pointer.
 * @return Zero on success.
 */
static int load_string_req(const config_setting_t *cfg, const char *opt, char **val)
{
    const char *str_val;
    if (config_setting_lookup_string(cfg, opt, &str_val)) {
        *val = strdup(str_val);
        return 0;
    } else {
        ZERO_LOG(LOG_ERR, "config: '%s' missing", opt);
        return -1;
    }
}
Example #24
0
int exist_field_string(parsertype p, void *e, const char *path)
{
	const char *str;
	switch (p) {
	case LIBCFG_PARSER:
		return config_setting_lookup_string((const config_setting_t *)e,
							path, &str);
	case JSON_PARSER:
		return json_object_object_get_ex((json_object *)e,  path, NULL);
	}

	return 0;
}
Example #25
0
int main()
{
    config_t cfg;               /*Returns all parameters in this structure */
    config_setting_t *setting;
    const char *str1, *str2;
    int tmp;
 
    char *config_file_name = "config.ini";
 
    /*Initialization */
    config_init(&cfg);
 
    /* Read the file. If there is an error, report it and exit. */
    if (!config_read_file(&cfg, config_file_name))
    {
        printf("\n%s:%d - %s", config_error_file(&cfg), config_error_line(&cfg), config_error_text(&cfg));
        config_destroy(&cfg);
        return -1;
    }
 
    /* Get the configuration file name. */
    if (config_lookup_string(&cfg, "filename", &str1))
        printf("\nFile Type: %s", str1);
    else
        printf("\nNo 'filename' setting in configuration file.");
 
    /*Read the parameter group*/
    setting = config_lookup(&cfg, "params");
    if (setting != NULL)
    {
        /*Read the string*/
        if (config_setting_lookup_string(setting, "param1", &str2))
        {
            printf("\nParam1: %s", str2);
        }
        else
            printf("\nNo 'param1' setting in configuration file.");
 
        /*Read the integer*/
        if (config_setting_lookup_int(setting, "param2", &tmp))
        {
            printf("\nParam2: %d", tmp);
        }
        else
            printf("\nNo 'param2' setting in configuration file.");
 
        printf("\n");
    }
 
    config_destroy(&cfg);
}
Example #26
0
/* Plugin constructor. */
static GtkWidget *dirmenu_constructor(LXPanel *panel, config_setting_t *settings)
{
    /* Allocate and initialize plugin context and set into Plugin private data pointer. */
    DirMenuPlugin * dm = g_new0(DirMenuPlugin, 1);
    GtkWidget * p;
    const char *str;

    /* Load parameters from the configuration file. */
    if (config_setting_lookup_string(settings, "image", &str))
        dm->image = g_strdup(str);
    if (config_setting_lookup_string(settings, "path", &str))
        dm->path = expand_tilda(str);
    else
        dm->path = g_strdup(fm_get_home_dir());
    if (config_setting_lookup_string(settings, "name", &str))
        dm->name = g_strdup(str);

    /* Save construction pointers */
    dm->panel = panel;
    dm->settings = settings;

    /* Allocate top level widget and set into Plugin widget pointer.
     * It is not known why, but the button text will not draw if it is edited from empty to non-empty
     * unless this strategy of initializing it with a non-empty value first is followed. */
    p = lxpanel_button_new_for_icon(panel,
                            ((dm->image != NULL) ? dm->image : "file-manager"),
                            NULL, "Temp");
    lxpanel_plugin_set_data(p, dm, dirmenu_destructor);

    /* Initialize the widget. */
    dirmenu_apply_configuration(p);

    g_signal_connect(G_OBJECT(p), "button-release-event",
                     G_CALLBACK(dirmenu_button_release_event), dm);

    /* Show the widget and return. */
    return p;
}
Example #27
0
inline static void ya_check_blk_internal(ya_block_t *blk, config_setting_t *set, const char *strexec) {
	const char *retstr;
	for (int i=0; i < YA_INTERNAL_LEN; i++) {
		if(strcmp(strexec, ya_reserved_blks[i].name)==0) {
			blk->internal = calloc(1, sizeof(blk_intern_t));
			blk->attr |= BLKA_INTERNAL;
			blk->internal->index = i;
			if(config_setting_lookup_string(set, "internal-prefix", &retstr) == CONFIG_TRUE)
				blk->internal->prefix = strdup(retstr);
			if(config_setting_lookup_string(set, "internal-suffix", &retstr) == CONFIG_TRUE)
				blk->internal->suffix = strdup(retstr);
			if(config_setting_lookup_string(set, "internal-option1", &retstr) == CONFIG_TRUE)
				blk->internal->option[0] = strdup(retstr);
			if(config_setting_lookup_string(set, "internal-option2", &retstr) == CONFIG_TRUE)
				blk->internal->option[1] = strdup(retstr);
			if(config_setting_lookup_string(set, "internal-option3", &retstr) == CONFIG_TRUE)
				blk->internal->option[2] = strdup(retstr);
		}
	}
	//check if the for-loop never found a matching internal block
	if ((blk->attr & BLKA_INTERNAL)==0)
		blk->attr |= BLKA_EXTERNAL;
}
Example #28
0
int load_config(CustomData *d) 
{
   config_t cfg, *cf;
//   CustomData *d=*data;
    const config_setting_t *logos,*logo;
    int count, n;
    cf = &cfg;
    config_init(cf);
    if (!config_read_file(cf, "kiosk.ini")) {
       fprintf(stderr, "%s:%d - %s\n",
       config_error_file(cf),
       config_error_line(cf),
       config_error_text(cf));
       config_destroy(cf);
       return -1;
    }
   logos = config_lookup(cf, "logos");
   d->logo_count = config_setting_length(logos);
   g_print("%d logos configured.\n", d->logo_count);
//   d->config= malloc(sizeof(ConfigItem[10]));
   ConfigItem *ci;
   char *b,*i,*p;
   for (n = 0; n < d->logo_count; n++) {
      logo=config_setting_get_elem(logos, n);
      ci=&d->config[n];
      config_setting_lookup_string(logo,"background",
                            &b);
      config_setting_lookup_string(logo,"intro",&i);
      config_setting_lookup_string(logo,"prompter",&p);
      config_setting_lookup_int(logo,"duration",&d->config[n].duration);
      strcpy(d->config[n].background,b);
      strcpy(d->config[n].intro,i);
      strcpy(d->config[n].prompter,p);
  }
   config_destroy(cf);
   return 0;
} 
Example #29
0
void configure_dirt_handlers(spade_server* server, config_t* configuration) {
    config_setting_t* handler_settings = config_lookup(configuration,
            "dirt.handlers");
    if (!handler_settings) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No Dirt handlers registered");
        return;
    }
    int dirt_handler_count = config_setting_length(handler_settings);

    for (int n = 0; n < dirt_handler_count; n++) {
        config_setting_t* handler_setting = config_setting_get_elem(
                handler_settings, n);
        const char* library = NULL;
        config_setting_lookup_string(handler_setting, "library", &library);

        const char* handler = NULL;
        config_setting_lookup_string(handler_setting, "handler", &handler);

        const char* url = NULL;
        config_setting_lookup_string(handler_setting, "url", &url);

        if(!register_dirt_handler(server, url, handler, library)) {
            log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                    "Registered Dirt handler '%s' for URL prefix '%s'",
                    handler, url);
        }
    }
    if (server->dirt_handler_count == 0) {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "No Dirt handlers registered");
    } else {
        log4c_category_log(log4c_category_get("spade"), LOG4C_PRIORITY_INFO,
                "Registered a total of %d Dirt handlers",
                server->dirt_handler_count);
    }
}
Example #30
0
int read_volumes_local_config(config_t * config, bool reread)
{
	config_setting_t * settings = config_lookup(config, "volumes");
	if ((settings == NULL) && (config_setting_is_array(settings) != CONFIG_TRUE))
	{
		// failed to locate volumes configuration section
		message(LOG_ERROR, FACILITY_CONFIG, "Volumes local config section is missing, please add it to local config.\n");
		return CONFIG_FALSE;
	}

	config_setting_t * volume_setting;
	int i;
	// for each volume element
	for (i = 0; (volume_setting = config_setting_get_elem(settings, i)) != NULL; ++i)
	{
		uint64_t id = 0;
		uint64_t cache_size;
		const char * local_path;
		int rv;

		rv = config_setting_lookup_uint64_t(volume_setting, "id", &id);
		if (rv != CONFIG_TRUE || !is_valid_volume_id(id))
		{
			// failed to read volume_setting id from zfsd.config
			message(LOG_ERROR, FACILITY_CONFIG, "Volume id config key is wrong type or is missing in local config.\n");
			return CONFIG_FALSE;
		}

		rv = config_setting_lookup_uint64_t(volume_setting, "cache_size", &cache_size);
		if (rv != CONFIG_TRUE)
		{
			// failed to read volume_setting cache limit, assume 0 will be fine
			message(LOG_WARNING, FACILITY_CONFIG, "Volume cache_size key is wrong type or is missing in local config, assuming cache_size = 0.\n");
			cache_size = 0;
		}

		rv = config_setting_lookup_string(volume_setting, "local_path", &local_path);
		if (rv != CONFIG_TRUE)
		{
			// failed to get local path
			message(LOG_ERROR, FACILITY_CONFIG, "Volume local_path config keyi is wrong type or is missing in local config.\n");
			return CONFIG_FALSE;
		}

		create_volume_from_local_config(id, cache_size, local_path, reread);
	}

	return CONFIG_TRUE;
}