示例#1
0
static void read_config(void) {
	char *filename = NULL;
	FILE *file = open_config_file(&filename);

	if (config_read(config, file) != CONFIG_TRUE)
		die("%s:%d %s", filename, config_error_line(config), config_error_text(config));

	if (fclose(file) == EOF) perror_die("fclose");
}
示例#2
0
文件: sh_init.c 项目: loopfz/SHaft
void		init_shell(char **initial_env) {
  memset(&sh, 0, sizeof(sh));
  sh.environment = duplicate_env(initial_env);
  sh.args = make_sh_args_tab();
  init_pwd();

  open_config_file();
  init_prompt();
  init_signals(1);
}
示例#3
0
void
write_nh_config(void)
{
    FILE *fp;
    fnchar filename[BUFSZ];

    if (get_config_name(filename, FALSE) &&
        (fp = open_config_file(filename))) {
        write_config_options(fp, nh_options);
        fclose(fp);
    }
}
示例#4
0
void
write_ui_config(void)
{
    FILE *fp;
    fnchar filename[BUFSZ];

    if (get_config_name(filename, TRUE) &&
        (fp = open_config_file(filename))) {
        write_config_options(fp, curses_options);
        fclose(fp);
    }
}
示例#5
0
void write_config(void)
{
    FILE *fp;
    fnchar filename[BUFSZ];
    fnchar uiconfname[BUFSZ];
    
    get_config_name(filename, FALSE);
    get_config_name(uiconfname, TRUE);
    
    fp = open_config_file(filename);
    if (fp && should_write_config()) {
	write_config_options(fp, nh_get_options(GAME_OPTIONS));
	write_config_options(fp, nh_get_options(CURRENT_BIRTH_OPTIONS));
	fclose(fp);
    }
    
    fp = open_config_file(uiconfname);
    if (fp) {
	write_config_options(fp, curses_options);
	fclose(fp);
    }
}
示例#6
0
void pi_parse_config_file(void) {
    int i = 0;

    open_config_file();

    config_options.display_smooth_stretch = get_integer_conf("Graphics", "DisplaySmoothStretch", 1);
    config_options.option_display_border = get_integer_conf("Graphics", "DisplayBorder", 0);
    config_options.display_effect = get_integer_conf("Graphics", "DisplayEffect", 0);
    config_options.maintain_aspect_ratio = get_integer_conf("Graphics", "MaintainAspectRatio", 1);
    config_options.rotate = get_integer_conf("Graphics", "RotateScreen", 1);

    close_config_file();

}
示例#7
0
文件: main.c 项目: intgr/bluez
static int proximity_init(void)
{
	if (!main_opts.gatt_enabled) {
		DBG("GATT is disabled");
		return -ENOTSUP;
	}

	config = open_config_file(CONFIGDIR "/proximity.conf");

	if (proximity_manager_init(config) < 0)
		return -EIO;

	return 0;
}
示例#8
0
static void fe_S9xInitInputDevices ()
{
  memset(joy_buttons, 0, 32);
  memset(joy_axes, 0, 8*2);
  memset(sfc_key, 0, NUMKEYS*2);
  memset(sfc_joy, 0, NUMKEYS*2);

  //Open config file to read joystick values below
  open_config_file();

  //Configure keys from config file or defaults
  sfc_key[A_1] = get_keyjoy_conf("Keyboard", "A_1", RPI_KEY_A);
  sfc_key[B_1] = get_keyjoy_conf("Keyboard", "B_1", RPI_KEY_B);
  sfc_key[X_1] = get_keyjoy_conf("Keyboard", "X_1", RPI_KEY_X);
  sfc_key[Y_1] = get_keyjoy_conf("Keyboard", "Y_1", RPI_KEY_Y);
  sfc_key[L_1] = get_keyjoy_conf("Keyboard", "L_1", RPI_KEY_L);
  sfc_key[R_1] = get_keyjoy_conf("Keyboard", "R_1", RPI_KEY_R);
  sfc_key[START_1] = get_keyjoy_conf("Keyboard", "START_1", RPI_KEY_START);
  sfc_key[SELECT_1] = get_keyjoy_conf("Keyboard", "SELECT_1", RPI_KEY_SELECT);
  sfc_key[LEFT_1] = get_keyjoy_conf("Keyboard", "LEFT_1", RPI_KEY_LEFT);
  sfc_key[RIGHT_1] = get_keyjoy_conf("Keyboard", "RIGHT_1", RPI_KEY_RIGHT);
  sfc_key[UP_1] = get_keyjoy_conf("Keyboard", "UP_1", RPI_KEY_UP);
  sfc_key[DOWN_1] = get_keyjoy_conf("Keyboard", "DOWN_1", RPI_KEY_DOWN);

  sfc_key[QUIT] = get_keyjoy_conf("Keyboard", "QUIT", RPI_KEY_QUIT);
  sfc_key[ACCEL] = get_keyjoy_conf("Keyboard", "ACCEL", RPI_KEY_ACCEL);

  //Configure joysticks from config file or defaults
  sfc_joy[A_1] = get_keyjoy_conf("Joystick", "A_1", RPI_JOY_A);
  sfc_joy[B_1] = get_keyjoy_conf("Joystick", "B_1", RPI_JOY_B);
  sfc_joy[X_1] = get_keyjoy_conf("Joystick", "X_1", RPI_JOY_X);
  sfc_joy[Y_1] = get_keyjoy_conf("Joystick", "Y_1", RPI_JOY_Y);
  sfc_joy[L_1] = get_keyjoy_conf("Joystick", "L_1", RPI_JOY_L);
  sfc_joy[R_1] = get_keyjoy_conf("Joystick", "R_1", RPI_JOY_R);
  sfc_joy[START_1] = get_keyjoy_conf("Joystick", "START_1", RPI_JOY_START);
  sfc_joy[SELECT_1] = get_keyjoy_conf("Joystick", "SELECT_1", RPI_JOY_SELECT);

  sfc_joy[QUIT] = get_keyjoy_conf("Joystick", "QUIT", RPI_JOY_QUIT);
  sfc_joy[ACCEL] = get_keyjoy_conf("Joystick", "ACCEL", RPI_JOY_ACCEL);

  sfc_joy[QLOAD] = get_keyjoy_conf("Joystick", "QLOAD", RPI_JOY_QLOAD);
  sfc_joy[QSAVE] = get_keyjoy_conf("Joystick", "QSAVE", RPI_JOY_QSAVE);

  //Read joystick axis to use, default to 0 & 1
  joyaxis_LR = get_keyjoy_conf("Joystick", "JA_LR", 0);
  joyaxis_UD = get_keyjoy_conf("Joystick", "JA_UD", 1);

  close_config_file();
}
示例#9
0
文件: core.c 项目: LoongWin/libvmi
status_t read_config_file_entry(vmi_instance_t vmi) {
    status_t ret = VMI_FAILURE;
    FILE* config_file = NULL;

    config_file = open_config_file();
    if (NULL == config_file) {
        fprintf(stderr, "ERROR: config file not found.\n");
        ret = VMI_FAILURE;
        return ret;
    }

    ret = read_config_file(vmi, config_file);

    return ret;
}
示例#10
0
/*
 * read_config_file
 *
 * This method opens up the file specified by 'filename' and searches
 * through the file for 'keyword'. If 'keyword' is found any string
 * following it is stored in 'value'.
 *
 * args: filename (IN) - config filename
 *       keyword (IN) - word to search for in config file
 *       value (OUT) - value of keyword
 *
 * retn: -1 on error, 0 if keyword not found, 1 on value success
 */
int read_config_file(char *filename, char *keyword, char *value)
{
	FILE *in;
	int len;
	char buffer[MAX_CONFIG_STRING_SIZE], w[MAX_CONFIG_STRING_SIZE],
		v[MAX_CONFIG_STRING_SIZE];

	in = open_config_file(filename);
	if (in == NULL) {
		/* Couldn't find config file, or permission denied */
		return -1;
	}
	while ((fgets(buffer, MAX_CONFIG_STRING_SIZE - 1, in)) != NULL) {
		/* ignore long lines */
		if (buffer[(len = strlen(buffer)) - 1] != '\n') {
			syslog(LOG_ERR, "Long config file line ignored.");
			do
				fgets(buffer, MAX_CONFIG_STRING_SIZE - 1, in);
			while (buffer[strlen(buffer) - 1] != '\n');
			continue;
		}
		buffer[len - 1] = '\0';

		/* short-circuit comments */
		if (buffer[0] == '#')
			continue;

		/* check if it's what we want */
		if (sscanf(buffer, "%s %s", w, v) > 0 && !strcmp(w, keyword)) {
			/* found it :-) */
			strcpy(value, v);
			close_config_file(in);
			/* tell them we got it */
			return 1;
		}
	}
	close_config_file(in);
	/* didn't find it - better luck next time */
	return 0;
}
示例#11
0
void load_config()
{
    FILE * file;

    yaml_parser_t parser;
    yaml_document_t document;

    yaml_node_t * root;

    yaml_node_t * map;
    yaml_node_pair_t * pair;

    yaml_node_t * key, * value;

    char name[256];

    /* Look for velox.yaml in the config directories */
    file = open_config_file("velox.yaml");

    /* Nothing to do if there is no configuration file */
    if (file == NULL) return;

    yaml_parser_initialize(&parser);
    yaml_parser_set_input_file(&parser, file);

    if (!yaml_parser_load(&parser, &document))
    {
        fprintf(stderr, "Error parsing config file\n");
        goto cleanup;
    }

    /* The root node should be a mapping */
    map = yaml_document_get_root_node(&document);
    assert(map->type == YAML_MAPPING_NODE);

    /* For each key/value pair in the root mapping */
    for (pair = map->data.mapping.pairs.start; pair < map->data.mapping.pairs.top; ++pair)
    {
        key = yaml_document_get_node(&document, pair->key);
        value = yaml_document_get_node(&document, pair->value);

        assert(key->type == YAML_SCALAR_NODE);

        /* The module section */
        if (strcmp((const char *) key->data.scalar.value, "modules") == 0)
        {
            yaml_node_item_t * module_item;
            yaml_node_t * node;

            assert(value->type == YAML_SEQUENCE_NODE);

            printf("\n** Loading Modules **\n");

            /* For each module */
            for (module_item = value->data.sequence.items.start;
                module_item < value->data.sequence.items.top;
                ++module_item)
            {
                node = yaml_document_get_node(&document, *module_item);

                load_module((const char *) node->data.scalar.value);
            }
        }
        /* The border_width property */
        else if (strcmp((const char *) key->data.scalar.value, "border_width") == 0)
        {
            assert(value->type == YAML_SCALAR_NODE);

            border_width = strtoul((const char *) value->data.scalar.value, NULL, 10);
        }
    }

    yaml_document_delete(&document);

    printf("\n** Configuring Modules **\n");

    /* While we still have documents to parse */
    while (yaml_parser_load(&parser, &document))
    {
        /* If the document contains no root node, we are at the end */
        if (yaml_document_get_root_node(&document) == NULL)
        {
            yaml_document_delete(&document);
            break;
        }

        sscanf((const char *) yaml_document_get_root_node(&document)->tag, "!velox:%s", name);

        /* Configure the specified module with this YAML document */
        configure_module(name, &document);

        yaml_document_delete(&document);
    }

    cleanup:
        yaml_parser_delete(&parser);
        fclose(file);
}
示例#12
0
//Format:
//caid:prov:srvid:pid:chid:ecmlen=caid:prov:srvid:pid:chid:ecmlen[,validfrom,validto]
//validfrom: default=-2000
//validto: default=4000
//valid time if found in cache
static struct s_cacheex_matcher *cacheex_matcher_read_int(void)
{
    FILE *fp = open_config_file(cs_cacheex_matcher);
    if(!fp)
    {
        return NULL;
    }

    char token[1024];
    unsigned char type;
    int32_t i, ret, count = 0;
    struct s_cacheex_matcher *new_cacheex_matcher = NULL, *entry, *last = NULL;
    uint32_t line = 0;

    while(fgets(token, sizeof(token), fp))
    {
        line++;
        if(strlen(token) <= 1) {
            continue;
        }
        if(token[0] == '#' || token[0] == '/') {
            continue;
        }
        if(strlen(token) > 100) {
            continue;
        }

        for(i = 0; i < (int)strlen(token); i++)
        {
            if((token[i] == ':' || token[i] == ' ') && token[i + 1] == ':')
            {
                memmove(token + i + 2, token + i + 1, strlen(token) - i + 1);
                token[i + 1] = '0';
            }
            if(token[i] == '#' || token[i] == '/')
            {
                token[i] = '\0';
                break;
            }
        }

        type = 'm';
        uint32_t caid = 0, provid = 0, srvid = 0, pid = 0, chid = 0, ecmlen = 0;
        uint32_t to_caid = 0, to_provid = 0, to_srvid = 0, to_pid = 0, to_chid = 0, to_ecmlen = 0;
        int32_t valid_from = -2000, valid_to = 4000;

        ret = sscanf(token, "%c:%4x:%6x:%4x:%4x:%4x:%4X=%4x:%6x:%4x:%4x:%4x:%4X,%4d,%4d",
                     &type,
                     &caid, &provid, &srvid, &pid, &chid, &ecmlen,
                     &to_caid, &to_provid, &to_srvid, &to_pid, &to_chid, &to_ecmlen,
                     &valid_from, &valid_to);

        type = tolower(type);

        if(ret < 7 || type != 'm')
        {
            continue;
        }

        if(!cs_malloc(&entry, sizeof(struct s_cacheex_matcher)))
        {
            fclose(fp);
            return new_cacheex_matcher;
        }
        count++;
        entry->line = line;
        entry->type = type;
        entry->caid = caid;
        entry->provid = provid;
        entry->srvid = srvid;
        entry->pid = pid;
        entry->chid = chid;
        entry->ecmlen = ecmlen;
        entry->to_caid = to_caid;
        entry->to_provid = to_provid;
        entry->to_srvid = to_srvid;
        entry->to_pid = to_pid;
        entry->to_chid = to_chid;
        entry->to_ecmlen = to_ecmlen;
        entry->valid_from = valid_from;
        entry->valid_to = valid_to;

        cs_debug_mask(D_TRACE, "cacheex-matcher: %c: %04X:%06X:%04X:%04X:%04X:%02X = %04X:%06X:%04X:%04X:%04X:%02X valid %d/%d",
                      entry->type, entry->caid, entry->provid, entry->srvid, entry->pid, entry->chid, entry->ecmlen,
                      entry->to_caid, entry->to_provid, entry->to_srvid, entry->to_pid, entry->to_chid, entry->to_ecmlen,
                      entry->valid_from, entry->valid_to);

        if(!new_cacheex_matcher)
        {
            new_cacheex_matcher = entry;
            last = new_cacheex_matcher;
        }
        else
        {
            last->next = entry;
            last = entry;
        }
    }

    if(count)
    {
        cs_log("%d entries read from %s", count, cs_cacheex_matcher);
    }

    fclose(fp);

    return new_cacheex_matcher;
}
示例#13
0
int
config_ini_init(config_ini_state_t *state, const char *filepath)
{
	config_ini_section_t *section = NULL;
	state->sections = NULL;

	FILE *f = open_config_file(filepath);
	if (f == NULL) {
		/* Only a serious error if a file was explicitly requested. */
		if (filepath != NULL) return -1;
		return 0;
	}

	char line[MAX_LINE_LENGTH];
	char *s;

	while (1) {
		/* Handle the file input linewise. */
		char *r = fgets(line, sizeof(line), f);
		if (r == NULL) break;

		/* Strip leading blanks and trailing newline. */
		s = line + strspn(line, " \t");
		s[strcspn(s, "\r\n")] = '\0';

		/* Skip comments and empty lines. */
		if (s[0] == ';' || s[0] == '\0') continue;

		if (s[0] == '[') {
			/* Read name of section. */
			const char *name = s+1;
			char *end = strchr(s, ']');
			if (end == NULL || end[1] != '\0' || end == name) {
				fputs(_("Malformed section header in config"
					" file.\n"), stderr);
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			*end = '\0';

			/* Create section. */
			section = malloc(sizeof(config_ini_section_t));
			if (section == NULL) {
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			/* Insert into section list. */
			section->name = NULL;
			section->settings = NULL;
			section->next = state->sections;
			state->sections = section;

			/* Copy section name. */
			section->name = malloc(end - name + 1);
			if (section->name == NULL) {
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			memcpy(section->name, name, end - name + 1);
		} else {
			/* Split assignment at equals character. */
			char *end = strchr(s, '=');
			if (end == NULL || end == s) {
				fputs(_("Malformed assignment in config"
					" file.\n"), stderr);
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			*end = '\0';
			char *value = end + 1;

			if (section == NULL) {
				fputs(_("Assignment outside section in config"
					" file.\n"), stderr);
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			/* Create section. */
			config_ini_setting_t *setting =
				malloc(sizeof(config_ini_setting_t));
			if (setting == NULL) {
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			/* Insert into section list. */
			setting->name = NULL;
			setting->value = NULL;
			setting->next = section->settings;
			section->settings = setting;

			/* Copy name of setting. */
			setting->name = malloc(end - s + 1);
			if (setting->name == NULL) {
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			memcpy(setting->name, s, end - s + 1);

			/* Copy setting value. */
			size_t value_len = strlen(value) + 1;
			setting->value = malloc(value_len);
			if (setting->value == NULL) {
				fclose(f);
				config_ini_free(state);
				return -1;
			}

			memcpy(setting->value, value, value_len);
		}
	}

	fclose(f);

	return 0;
}
示例#14
0
static void ac_load_config(void)
{
	FILE *fp = open_config_file(cs_ac);
	if(!fp)
		{ return; }

	int32_t nr;
	char *saveptr1 = NULL, *token;
	if(!cs_malloc(&token, MAXLINESIZE))
		{ return; }
	struct s_cpmap *cur_cpmap, *first_cpmap = NULL, *last_cpmap = NULL;

	for(nr = 0; fgets(token, MAXLINESIZE, fp);)
	{
		int32_t i, skip;
		uint16_t caid, sid, chid, dwtime;
		uint32_t  provid;
		char *ptr, *ptr1;

		if(strlen(token) < 4) { continue; }

		caid = sid = chid = dwtime = 0;
		provid = 0;
		skip = 0;
		ptr1 = 0;
		for(i = 0, ptr = strtok_r(token, "=", &saveptr1); (i < 2) && (ptr); ptr = strtok_r(NULL, "=", &saveptr1), i++)
		{
			trim(ptr);
			if(*ptr == ';' || *ptr == '#' || *ptr == '-')
			{
				skip = 1;
				break;
			}
			switch(i)
			{
			case 0:
				ptr1 = ptr;
				break;
			case 1:
				dwtime = atoi(ptr);
				break;
			}
		}

		if(!skip)
		{
			for(i = 0, ptr = strtok_r(ptr1, ":", &saveptr1); (i < 4) && (ptr); ptr = strtok_r(NULL, ":", &saveptr1), i++)
			{
				trim(ptr);
				switch(i)
				{
				case 0:
					if(*ptr == '*') { caid = 0; }
					else { caid = a2i(ptr, 4); }
					break;
				case 1:
					if(*ptr == '*') { provid = 0; }
					else { provid = a2i(ptr, 6); }
					break;
				case 2:
					if(*ptr == '*') { sid = 0; }
					else { sid = a2i(ptr, 4); }
					break;
				case 3:
					if(*ptr == '*') { chid = 0; }
					else { chid = a2i(ptr, 4); }
					break;
				}
			}
			if(!cs_malloc(&cur_cpmap, sizeof(struct s_cpmap)))
			{
				for(cur_cpmap = first_cpmap; cur_cpmap;)
				{
					last_cpmap = cur_cpmap;
					cur_cpmap = cur_cpmap->next;
					NULLFREE(last_cpmap);
				}
				NULLFREE(token);
				return;
			}
			if(last_cpmap)
				{ last_cpmap->next = cur_cpmap; }
			else
				{ first_cpmap = cur_cpmap; }
			last_cpmap = cur_cpmap;

			cur_cpmap->caid   = caid;
			cur_cpmap->provid = provid;
			cur_cpmap->sid    = sid;
			cur_cpmap->chid   = chid;
			cur_cpmap->dwtime = dwtime;
			cur_cpmap->next   = 0;

			cs_log_dbg(D_CLIENT, "nr=%d, caid=%04X, provid=%06X, sid=%04X, chid=%04X, dwtime=%d",
						  nr, caid, provid, sid, chid, dwtime);
			nr++;
		}
	}
	NULLFREE(token);
	fclose(fp);

	last_cpmap = cfg.cpmap;
	cfg.cpmap = first_cpmap;
	for(cur_cpmap = last_cpmap; cur_cpmap; cur_cpmap = cur_cpmap->next)
		{ add_garbage(cur_cpmap); }
	//cs_log("%d lengths for caid guessing loaded", nr);
	return;
}
示例#15
0
int32_t init_config(void)
{
	FILE *fp;

	if(config_enabled(WEBIF))
	{
		fp = open_config_file(cs_conf);
	}
	else
	{
		fp = open_config_file_or_die(cs_conf);
	}

	const struct config_sections *cur_section = oscam_conf; // Global
	char *token;

	config_sections_set_defaults(oscam_conf, &cfg);

	if(!fp)
	{
		// no oscam.conf but webif is included in build, set it up for lan access and tweak defaults
#ifdef WEBIF
		cfg.http_port = DEFAULT_HTTP_PORT;
		chk_iprange(cs_strdup(DEFAULT_HTTP_ALLOW), &cfg.http_allowed);
#endif
		NULLFREE(cfg.logfile);
		cfg.logtostdout = 1;
#ifdef HAVE_DVBAPI
		cfg.dvbapi_enabled = 1;
#endif
		return 0;
	}

	if(!cs_malloc(&token, MAXLINESIZE))
		{ return 1; }

	int line = 0;
	int valid_section = 1;
	while(fgets(token, MAXLINESIZE, fp))
	{
		++line;
		int len = strlen(trim(token));
		if(len < 3)  // a=b or [a] are at least 3 chars
			{ continue; }
		if(token[0] == '#')  // Skip comments
			{ continue; }
		if(token[0] == '[' && token[len - 1] == ']')
		{
			token[len - 1] = '\0';
			valid_section = 0;
			const struct config_sections *newconf = config_find_section(oscam_conf, token + 1);
			if(config_section_is_active(newconf) && cur_section)
			{
				config_list_apply_fixups(cur_section->config, &cfg);
				cur_section = newconf;
				valid_section = 1;
			}
			if(!newconf)
			{
				fprintf(stderr, "WARNING: %s line %d unknown section [%s].\n",
						cs_conf, line, token + 1);
				continue;
			}
			if(!config_section_is_active(newconf))
			{
				fprintf(stderr, "WARNING: %s line %d section [%s] is ignored (support not compiled in).\n",
						cs_conf, line, newconf->section);
			}
			continue;
		}
		if(!valid_section)
			{ continue; }
		char *value = strchr(token, '=');
		if(!value)  // No = found, well go on
			{ continue; }
		*value++ = '\0';
		char *tvalue = trim(value);
		char *ttoken = trim(strtolower(token));
		if(cur_section && !config_list_parse(cur_section->config, ttoken, tvalue, &cfg))
		{
			fprintf(stderr, "WARNING: %s line %d section [%s] contains unknown setting '%s=%s'\n",
					cs_conf, line, cur_section->section, ttoken, tvalue);
		}
	}
	free(token);
	fclose(fp);
	if(cur_section) { config_list_apply_fixups(cur_section->config, &cfg); }
	return 0;
}
示例#16
0
int32_t init_srvid(void)
{
	int8_t new_syntax = 1;
	FILE *fp = open_config_file("oscam.srvid2");
	if(!fp)
	{ 
		fp = open_config_file(cs_srid);
		if(fp)
		{
			new_syntax = 0;
		}
	}

	if(!fp)
	{ 
		fp = create_config_file("oscam.srvid2");
		if(fp)
		{
			flush_config_file(fp, "oscam.srvid2");
		}
		
		return 0;
	}

	int32_t nr = 0, i, j;
	char *payload, *saveptr1 = NULL, *saveptr2 = NULL, *token;
	const char *tmp;
	if(!cs_malloc(&token, MAXLINESIZE))
		{ return 0; }
	struct s_srvid *srvid = NULL, *new_cfg_srvid[16], *last_srvid[16];
	// A cache for strings within srvids. A checksum is calculated which is the start point in the array (some kind of primitive hash algo).
	// From this point, a sequential search is done. This greatly reduces the amount of string comparisons.
	const char **stringcache[1024];
	int32_t allocated[1024] = { 0 };
	int32_t used[1024] = { 0 };
	struct timeb ts, te;
	cs_ftime(&ts);

	memset(last_srvid, 0, sizeof(last_srvid));
	memset(new_cfg_srvid, 0, sizeof(new_cfg_srvid));

	while(fgets(token, MAXLINESIZE, fp))
	{
		int32_t l, len = 0, len2, srvidtmp;
		uint32_t k;
		uint32_t pos;
		char *srvidasc, *prov;
		tmp = trim(token);

		if(tmp[0] == '#') { continue; }
		if((l = strlen(tmp)) < 6) { continue; }
		if(!(srvidasc = strchr(token, ':'))) { continue; }
		if(!(payload = strchr(token, '|'))) { continue; }
		*payload++ = '\0';
		
		if(!cs_malloc(&srvid, sizeof(struct s_srvid)))
		{
			NULLFREE(token);
			fclose(fp);
			return (1);
		}

		char tmptxt[128];

		int32_t offset[4] = { -1, -1, -1, -1 };
		char *ptr1 = NULL, *ptr2 = NULL;
		const char *searchptr[4] = { NULL, NULL, NULL, NULL };
		const char **ptrs[4] = { &srvid->prov, &srvid->name, &srvid->type, &srvid->desc };
		uint32_t max_payload_length = MAXLINESIZE - (payload - token);
		
		if(new_syntax)
		{
			ptrs[0] = &srvid->name;
			ptrs[1] = &srvid->type;
			ptrs[2] = &srvid->desc;
			ptrs[3] = &srvid->prov;
		}
		
		// allow empty strings as "||"
		if(payload[0] == '|' && (strlen(payload)+2 < max_payload_length))
		{
			memmove(payload+1, payload, strlen(payload)+1);
			payload[0] = ' ';
		}
		
		for(k=1; ((k < max_payload_length) && (payload[k] != '\0')); k++)
		{
			if(payload[k-1] == '|' && payload[k] == '|')
			{
				if(strlen(payload+k)+2 < max_payload_length-k)
				{
					memmove(payload+k+1, payload+k, strlen(payload+k)+1);
					payload[k] = ' ';
				}
				else
				{
					break;
				}	
			}
		}
	
		for(i = 0, ptr1 = strtok_r(payload, "|", &saveptr1); ptr1 && (i < 4) ; ptr1 = strtok_r(NULL, "|", &saveptr1), ++i)
		{
			// check if string is in cache
			len2 = strlen(ptr1);
			pos = 0;
			for(j = 0; j < len2; ++j) { pos += (uint8_t)ptr1[j]; }
			pos = pos % 1024;
			for(j = 0; j < used[pos]; ++j)
			{
				if(!strcmp(stringcache[pos][j], ptr1))
				{
					searchptr[i] = stringcache[pos][j];
					break;
				}
			}
			if(searchptr[i]) { continue; }

			offset[i] = len;
			cs_strncpy(tmptxt + len, trim(ptr1), sizeof(tmptxt) - len);
			len += strlen(ptr1) + 1;
		}

		char *tmpptr = NULL;
		if(len > 0 && !cs_malloc(&tmpptr, len))
			{ continue; }

		srvid->data = tmpptr;
		if(len > 0) { memcpy(tmpptr, tmptxt, len); }

		for(i = 0; i < 4; i++)
		{
			if(searchptr[i])
			{
				*ptrs[i] = searchptr[i];
				continue;
			}
			if(offset[i] > -1)
			{
				*ptrs[i] = tmpptr + offset[i];
				// store string in stringcache
				tmp = *ptrs[i];
				len2 = strlen(tmp);
				pos = 0;
				for(j = 0; j < len2; ++j) { pos += (uint8_t)tmp[j]; }
				pos = pos % 1024;
				if(used[pos] >= allocated[pos])
				{
					if(allocated[pos] == 0)
					{
						if(!cs_malloc(&stringcache[pos], 16 * sizeof(char *)))
							{ break; }
					}
					else
					{
						if(!cs_realloc(&stringcache[pos], (allocated[pos] + 16) * sizeof(char *)))
							{ break; }
					}
					allocated[pos] += 16;
				}
				stringcache[pos][used[pos]] = tmp;
				used[pos] += 1;
			}
		}

		*srvidasc++ = '\0';
		if(new_syntax)
			{ srvidtmp = dyn_word_atob(token) & 0xFFFF; }
		else
			{ srvidtmp = dyn_word_atob(srvidasc) & 0xFFFF; }
			
		if(srvidtmp < 0)
		{
			NULLFREE(tmpptr);
			NULLFREE(srvid);
			continue;
		}
		else
		{
			srvid->srvid = srvidtmp;
		}		
		
		srvid->ncaid = 0;
		for(i = 0, ptr1 = strtok_r(new_syntax ? srvidasc : token, ",", &saveptr1); (ptr1); ptr1 = strtok_r(NULL, ",", &saveptr1), i++)
		{
			srvid->ncaid++;
		}
		
		if(!cs_malloc(&srvid->caid, sizeof(struct s_srvid_caid) * srvid->ncaid))
		{
			NULLFREE(tmpptr);
			NULLFREE(srvid);
			return 0;
		}
		
		ptr1 = new_syntax ? srvidasc : token;
		for(i = 0; i < srvid->ncaid; i++)
		{
			prov = strchr(ptr1,'@');
						
			srvid->caid[i].nprovid = 0;
			
			if(prov)
			{
				if(prov[1] != '\0')
				{
					for(j = 0, ptr2 = strtok_r(prov+1, "@", &saveptr2); (ptr2); ptr2 = strtok_r(NULL, "@", &saveptr2), j++)
					{
						srvid->caid[i].nprovid++;
					}
		    		
					if(!cs_malloc(&srvid->caid[i].provid, sizeof(uint32_t) * srvid->caid[i].nprovid))
					{
						for(j = 0; j < i; j++)
							{ NULLFREE(srvid->caid[j].provid); } 
						NULLFREE(srvid->caid);
						NULLFREE(tmpptr);
						NULLFREE(srvid);
						return 0;
					}
					
					ptr2 = prov+1;
					for(j = 0;  j < srvid->caid[i].nprovid; j++)
					{
						srvid->caid[i].provid[j] = dyn_word_atob(ptr2) & 0xFFFFFF;
						ptr2 = ptr2 + strlen(ptr2) + 1;
					}
				}
				else
				{
					ptr2 = prov+2;
				}
				
				prov[0] = '\0';
			}

			srvid->caid[i].caid = dyn_word_atob(ptr1) & 0xFFFF;
			if(prov)
				{ ptr1 = ptr2; }
			else 
				{ ptr1 = ptr1 + strlen(ptr1) + 1; }
		}
			
		nr++;

		if(new_cfg_srvid[srvid->srvid >> 12])
			{ last_srvid[srvid->srvid >> 12]->next = srvid; }
		else
			{ new_cfg_srvid[srvid->srvid >> 12] = srvid; }

		last_srvid[srvid->srvid >> 12] = srvid;
	}
struct s_auth *init_userdb(void)
{
	FILE *fp = open_config_file(cs_user);
	if (!fp)
		return NULL;

	struct s_auth *authptr = NULL;
	int32_t tag = 0, nr = 0, expired = 0, disabled = 0;
	char *token;
	struct s_auth *account = NULL;
	struct s_auth *probe = NULL;
	if (!cs_malloc(&token, MAXLINESIZE))
		return NULL;

	while (fgets(token, MAXLINESIZE, fp)) {
		int32_t l;
		void *ptr;

		if ((l=strlen(trim(token))) < 3)
			continue;
		if (token[0] == '[' && token[l-1] == ']') {
			token[l - 1] = 0;
			tag = streq("account", strtolower(token + 1));
			if (!cs_malloc(&ptr, sizeof(struct s_auth)))
				break;
			if (account)
				account->next = ptr;
			else
				authptr = ptr;

			account = ptr;
			account_set_defaults(account);
			nr++;

			continue;
		}

		if (!tag)
			continue;
		char *value = strchr(token, '=');
		if (!value)
			continue;

		*value++ = '\0';

		// check for duplicate useraccounts and make the name unique
		if (streq(trim(strtolower(token)), "user")) {
			for(probe = authptr; probe; probe = probe->next){
				if (!strcmp(probe->usr, trim(value))){
					fprintf(stderr, "Warning: duplicate account '%s'\n", value);
					strncat(value, "_x", sizeof(probe->usr) - strlen(value) - 1);
				}
			}
		}
		chk_account(trim(strtolower(token)), trim(value), account);
	}
	free(token);
	fclose(fp);

	for(account = authptr; account; account = account->next){
		if(account->expirationdate && account->expirationdate < time(NULL))
			++expired;
		if(account->disabled)
			++disabled;
	}
	cs_log("userdb reloaded: %d accounts loaded, %d expired, %d disabled", nr, expired, disabled);
	return authptr;
}
示例#18
0
文件: configfile.c 项目: OPSF/uClinux
/*
 * read_config_file
 *
 * This method opens up the file specified by 'filename' and searches
 * through the file for 'keyword'. If 'keyword' is found any string
 * following it is stored in 'value'.
 *
 * args: filename (IN) - config filename
 *       keyword (IN) - word to search for in config file
 *       value (OUT) - value of keyword
 *
 * retn: -1 on error, 0 if keyword not found, 1 on value success
 */
int read_config_file(char *filename, char *keyword, char *value)
{
	FILE *in;
	int len = 0, keyword_len = 0;
	int foundit = 0;

	char *buff_ptr;
	char buffer[MAX_CONFIG_STRING_SIZE];

	*value = '\0';
	buff_ptr = buffer;
	keyword_len = strlen(keyword);

	in = open_config_file(filename);
	if (in == NULL) {
		/* Couldn't find config file, or permission denied */
		return -1;
	}
	while ((fgets(buffer, MAX_CONFIG_STRING_SIZE - 1, in)) != NULL) {
		/* ignore long lines */
		if (buffer[(len = strlen(buffer)) - 1] != '\n') {
			syslog(LOG_ERR, "Long config file line ignored.");
			do
				fgets(buffer, MAX_CONFIG_STRING_SIZE - 1, in);
			while (buffer[strlen(buffer) - 1] != '\n');
			continue;
		}

		len--;			/* For the NL at the end */
		while (--len >= 0)
			if (buffer[len] != ' ' && buffer[len] != '\t')
				break;

		len++;
		buffer[len] = '\0';

		buff_ptr = buffer;

		/* Short-circuit blank lines and comments */
		if (!len || *buff_ptr == '#')
			continue;

		/* Non-blank lines starting with a space are an error */

		if (*buff_ptr == ' ' || *buff_ptr == '\t') {
			syslog(LOG_ERR, "Config file line starts with a space: %s", buff_ptr);
			continue;
		}

		/* At this point we have a line trimmed for trailing spaces. */
		/* Now we need to check if the keyword matches, and if so */
		/* then get the value (if any). */

		/* Check if it's the right keyword */

		do {
			if (*buff_ptr == ' ' || *buff_ptr == '\t')
				break;
		} while (*++buff_ptr);

		len = buff_ptr - buffer;
		if (len == keyword_len && !strncmp(buffer, keyword, len)) {
			foundit++;
			break;
		}
	}

	close_config_file(in);

	if (foundit) {
		/* Right keyword, now get the value (if any) */

		do {
			if (*buff_ptr != ' ' && *buff_ptr != '\t')
				break;
			
		} while (*++buff_ptr);

		strcpy(value, buff_ptr);
		return 1;
	} else {
		/* didn't find it - better luck next time */
		return 0;
	}
}
示例#19
0
void test()
{
    bool result;
    const uint8_t* filename = (const uint8_t*)"/home/user/test.conf";
    uint8_t buffer[64];
    config_parser_t cfg;

    for(;;)
    {
        toggle_led(LED2);

        log_info(&log, "remove file %s", filename);

        // delete the file
        unlink((const char*)filename);

        // check the file is not present
        if(open_config_file(&cfg, buffer, sizeof(buffer), filename))
        {
            while(get_next_config(&cfg))
            	log_info(&log, "read %s=%s", get_config_key(&cfg), get_config_value(&cfg));
            close_config_file(&cfg);
        }
        else
            log_info(&log, "file %s removed successfully", filename);

        // add to a new file
        result = add_config_entry(buffer, sizeof(buffer),
        							filename,
									(const uint8_t*)"testkey",
									(const uint8_t*)"testvalue");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey", "testvalue", filename, result);

        result = add_config_entry(buffer, sizeof(buffer),
        							filename,
									(const uint8_t*)"testkey1",
									(const uint8_t*)"testvalue1");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey1", "testvalue1", filename, result);

        // check the file is now present with
        if(open_config_file(&cfg, buffer, sizeof(buffer), filename))
        {
            while(get_next_config(&cfg))
            	log_info(&log, "read %s=%s", get_config_key(&cfg), get_config_value(&cfg));
            close_config_file(&cfg);
        }

        // edit within file
        result = edit_config_entry(buffer, sizeof(buffer),
                                    filename,
                                    (const uint8_t*)"testkey",
                                    (const uint8_t*)"newtestvalue");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey", "testvalue", filename, result);

        result = edit_config_entry(buffer, sizeof(buffer),
                                    filename,
                                    (const uint8_t*)"testkey1",
                                    (const uint8_t*)"newtestvalue1");
        log_info(&log, "wrote %s=%s to %s, result=%d", "testkey1", "testvalue1", filename, result);

        // check the file is now present with new values
        if(open_config_file(&cfg, buffer, sizeof(buffer), filename))
        {
            while(get_next_config(&cfg))
                log_info(&log, "read %s=%s", get_config_key(&cfg), get_config_value(&cfg));
            close_config_file(&cfg);
        }

        sleep(10);
    }

	pthread_exit(0);
}
示例#20
0
void pi_initialize_input() {
    memset(joy_buttons, 0, 32 * 4);
    memset(joy_axes, 0, 8 * 4 * sizeof(int));
    memset(joy_hats, 0, 4 * sizeof(int));
    memset(pi_key, 0, NUMKEYS * 2);
    memset(pi_joy, 0, NUMKEYS * 2 * 4);

    //Open config file for reading below
    open_config_file();

    //Configure keys from config file or defaults
    pi_key[A_1] = get_integer_conf("Keyboard", "A_1", RPI_KEY_A);
    pi_key[B_1] = get_integer_conf("Keyboard", "B_1", RPI_KEY_B);
    pi_key[X_1] = get_integer_conf("Keyboard", "X_1", RPI_KEY_X);
    pi_key[Y_1] = get_integer_conf("Keyboard", "Y_1", RPI_KEY_Y);
    pi_key[L_1] = get_integer_conf("Keyboard", "L_1", RPI_KEY_L);
    pi_key[R_1] = get_integer_conf("Keyboard", "R_1", RPI_KEY_R);
    pi_key[START_1] = get_integer_conf("Keyboard", "START_1", RPI_KEY_START);
    pi_key[SELECT_1] = get_integer_conf("Keyboard", "SELECT_1", RPI_KEY_SELECT);
    pi_key[LEFT_1] = get_integer_conf("Keyboard", "LEFT_1", RPI_KEY_LEFT);
    pi_key[RIGHT_1] = get_integer_conf("Keyboard", "RIGHT_1", RPI_KEY_RIGHT);
    pi_key[UP_1] = get_integer_conf("Keyboard", "UP_1", RPI_KEY_UP);
    pi_key[DOWN_1] = get_integer_conf("Keyboard", "DOWN_1", RPI_KEY_DOWN);

    pi_key[A_2] = get_integer_conf("Keyboard", "A_2", RPI_KEY_A_2);
    pi_key[B_2] = get_integer_conf("Keyboard", "B_2", RPI_KEY_B_2);
    pi_key[X_2] = get_integer_conf("Keyboard", "X_2", RPI_KEY_X_2);
    pi_key[Y_2] = get_integer_conf("Keyboard", "Y_2", RPI_KEY_Y_2);
    pi_key[L_2] = get_integer_conf("Keyboard", "L_2", RPI_KEY_L_2);
    pi_key[R_2] = get_integer_conf("Keyboard", "R_2", RPI_KEY_R_2);
    pi_key[START_2] = get_integer_conf("Keyboard", "START_2", RPI_KEY_START_2);
    pi_key[SELECT_2] = get_integer_conf("Keyboard", "SELECT_2", RPI_KEY_SELECT_2);
    pi_key[LEFT_2] = get_integer_conf("Keyboard", "LEFT_2", RPI_KEY_LEFT_2);
    pi_key[RIGHT_2] = get_integer_conf("Keyboard", "RIGHT_2", RPI_KEY_RIGHT_2);
    pi_key[UP_2] = get_integer_conf("Keyboard", "UP_2", RPI_KEY_UP_2);
    pi_key[DOWN_2] = get_integer_conf("Keyboard", "DOWN_2", RPI_KEY_DOWN_2);


    pi_key[A_2] = get_integer_conf("Keyboard", "A_2", RPI_KEY_A_2);
    pi_key[B_2] = get_integer_conf("Keyboard", "B_2", RPI_KEY_B_2);
    pi_key[X_2] = get_integer_conf("Keyboard", "X_2", RPI_KEY_X_2);
    pi_key[Y_2] = get_integer_conf("Keyboard", "Y_2", RPI_KEY_Y_2);
    pi_key[L_2] = get_integer_conf("Keyboard", "L_2", RPI_KEY_L_2);
    pi_key[R_2] = get_integer_conf("Keyboard", "R_2", RPI_KEY_R_2);
    pi_key[START_2] = get_integer_conf("Keyboard", "START_2", RPI_KEY_START_2);
    pi_key[SELECT_2] = get_integer_conf("Keyboard", "SELECT_2", RPI_KEY_SELECT_2);
    pi_key[LEFT_2] = get_integer_conf("Keyboard", "LEFT_2", RPI_KEY_LEFT_2);
    pi_key[RIGHT_2] = get_integer_conf("Keyboard", "RIGHT_2", RPI_KEY_RIGHT_2);
    pi_key[UP_2] = get_integer_conf("Keyboard", "UP_2", RPI_KEY_UP_2);
    pi_key[DOWN_2] = get_integer_conf("Keyboard", "DOWN_2", RPI_KEY_DOWN_2);
    pi_key[QUIT] = get_integer_conf("Keyboard", "QUIT", RPI_KEY_QUIT);


    //Configure joysticks from config file or defaults
    joy_indexes[0] = get_integer_conf("Joystick", "SDLID_1", -1);
    joy_indexes[1] = get_integer_conf("Joystick", "SDLID_2", -1);
    joy_indexes[2] = get_integer_conf("Joystick", "SDLID_3", -1);
    joy_indexes[3] = get_integer_conf("Joystick", "SDLID_4", -1);

    char configName[10];
    for (int player = 0; player < 4; player++) {
        logoutput("Setting player %d input\n", player + 1);

        sprintf(configName, "A_%d", player + 1);
        pi_joy[player][J_A] = get_integer_conf("Joystick", configName, 200);
        logoutput("Setted J_A : %d\n", pi_joy[player][J_A]);

        sprintf(configName, "B_%d", player + 1);
        pi_joy[player][J_B] = get_integer_conf("Joystick", configName, RPI_JOY_B);
        sprintf(configName, "X_%d", player + 1);
        pi_joy[player][J_X] = get_integer_conf("Joystick", configName, RPI_JOY_X);
        sprintf(configName, "Y_%d", player + 1);
        pi_joy[player][J_Y] = get_integer_conf("Joystick", configName, RPI_JOY_Y);
        sprintf(configName, "L_%d", player + 1);
        pi_joy[player][J_L] = get_integer_conf("Joystick", configName, RPI_JOY_L);
        sprintf(configName, "R_%d", player + 1);
        pi_joy[player][J_R] = get_integer_conf("Joystick", configName, RPI_JOY_R);


        sprintf(configName, "UP_%d", player + 1);
        pi_joy[player][J_UP] = get_integer_conf("Joystick", configName, RPI_JOY_UP);

        sprintf(configName, "DOWN_%d", player + 1);
        pi_joy[player][J_DOWN] = get_integer_conf("Joystick", configName, RPI_JOY_DOWN);

        sprintf(configName, "LEFT_%d", player + 1);
        pi_joy[player][J_LEFT] = get_integer_conf("Joystick", configName, RPI_JOY_LEFT);

        sprintf(configName, "RIGHT_%d", player + 1);
        pi_joy[player][J_RIGHT] = get_integer_conf("Joystick", configName, RPI_JOY_RIGHT);


        sprintf(configName, "START_%d", player + 1);
        pi_joy[player][J_START] = get_integer_conf("Joystick", configName, RPI_JOY_START);

        sprintf(configName, "SELECT_%d", player + 1);
        pi_joy[player][J_SELECT] = get_integer_conf("Joystick", configName, RPI_JOY_SELECT);

        sprintf(configName, "JA_LR_%d", player + 1);
        pi_joy[player][J_AXIS_LR] = get_integer_conf("Joystick", configName, RPI_JOY_AXIS_LR);
        sprintf(configName, "JA_UD_%d", player + 1);
        pi_joy[player][J_AXIS_UD] = get_integer_conf("Joystick", configName, RPI_JOY_AXIS_UD);

    }

    pi_specials[HOTKEY] = get_integer_conf("Joystick", "HOTKEY", RPI_JOY_HOTKEY);

    pi_specials[QUIT] = get_integer_conf("Joystick", "QUIT", RPI_JOY_QUIT);
    pi_specials[ACCEL] = get_integer_conf("Joystick", "ACCEL", RPI_JOY_ACCEL);

    pi_specials[QLOAD] = get_integer_conf("Joystick", "QLOAD", RPI_JOY_QLOAD);
    pi_specials[QSAVE] = get_integer_conf("Joystick", "QSAVE", RPI_JOY_QSAVE);

//	Read joystick axis to use, default to 0 & 1 (keep it for hats...)
//	joyaxis_LR_1 = get_integer_conf("Joystick", "JA_LR_1", 0);
//	joyaxis_UD_1 = get_integer_conf("Joystick", "JA_UD_1", 1);
//
//	joyaxis_LR_2 = get_integer_conf("Joystick", "JA_LR_2", 0);
//	joyaxis_UD_2 = get_integer_conf("Joystick", "JA_UD_2", 1);
//        
//	joyaxis_LR_3 = get_integer_conf("Joystick", "JA_LR_3", 0);
//	joyaxis_UD_3 = get_integer_conf("Joystick", "JA_UD_3", 1);
//        
//	joyaxis_LR_4 = get_integer_conf("Joystick", "JA_LR_4", 0);
//	joyaxis_UD_4 = get_integer_conf("Joystick", "JA_UD_4", 1);

    close_config_file();

}
示例#21
0
int
main (int argc, char **argv)
{
    int     option_index = 0;
    int     c = 0;
    int     verbosity = 0;
    int     ch = 0;
    int     d_ch = 0;
    int     perm_ch = 0;
    int     l_ch = 0;

    ArguxPlugin *plugin;
    ArguxPluginDB *db_plugin;
    char *plugin_path = malloc (200);
    ArguxError *error = NULL;

    while (1)
    {
        c = getopt_long (argc, argv, "vVh",
                long_options, &option_index);
        if (c == -1)
            break;

        switch (c)
        {
        case 0:
            switch (option_index)
            {
            case OPTION_VERSION:
                show_version ();
                exit (0);
                break;
            case OPTION_VERBOSE:
                verbosity = verbosity + 1;
                break;
            case OPTION_HELP:
                show_usage ();
                exit (0);
                break;
            case OPTION_API_CHECK:
                ch = 1;
                break;
            case OPTION_DB_CONNECT:
                d_ch = 1;
                break;
            case OPTION_DB_LISTPROP:
                l_ch = 1;
                break;
            case OPTION_DB_PERM:
                perm_ch = 1;
                break;
            case OPTION_DB_HOST:
                d_ch = 1;
                break;
            case OPTION_DB_NS:
                d_ch = 1;
                break;
            case OPTION_CONFIG:
                config_file = optarg;
                break;
            }
            break;
        case 'V':
            show_version ();
            exit (0);
            break;
        case 'h':
            show_usage ();
            exit (0);
            break;
        case 'v':
            verbosity = verbosity + 1;
            break;
        default:
            fprintf (stderr,"Try '%s --help' for more information\n", PACKAGE_NAME);
            exit (1);
            break;
        }
    }

    if (argc-optind > 1)
    {
        fprintf (stderr, "No plugin-name provided\n");
        return 1;
    }

    sprintf (
            plugin_path,
            "%s/%s/%s/%s.so",
            PLUGINDIR,
            argv[optind],
            PLUGINSUBDIR,
            argv[optind]);

    fprintf(stderr, "Loading plugin: %s\n", plugin_path);

    int fd = open(plugin_path, O_RDONLY);
    if (fd == -1) {
        fprintf(stderr, "Open Failed");
        exit(1);
    }

    plugin = argux_plugin_load ( plugin_path, &error );
    if (plugin == NULL)
    {
        fprintf(stderr, "%s\n", argux_error_get_msg (error));
        exit(1);
    }

    if (plugin->type != ARGUX_PLUGIN_DB)
    {
        fprintf(stderr, "Plugin '%s' is not a DB Plugin\n", argv[optind]);
        exit(1);
    }

    db_plugin = (ArguxPluginDB *)plugin;

    fprintf(stderr, "[ OK ] Plugin %s Loaded\n", argv[optind]);

    if (ch == 1) {

        API_CHECK(db_plugin->db.setprop);
        API_CHECK(db_plugin->db.getprop);
        API_CHECK(db_plugin->db.listprop);
        API_CHECK(db_plugin->db.connect);
        API_CHECK(db_plugin->db.disconnect);
        API_CHECK(db_plugin->db.init);

        API_CHECK(db_plugin->host.add);
        API_CHECK(db_plugin->host.get);

        API_CHECK(db_plugin->ns.add);
        API_CHECK(db_plugin->ns.get);

        API_CHECK(db_plugin->metric.add);
        API_CHECK(db_plugin->metric.get);
        API_CHECK(db_plugin->metric.copy);
        API_CHECK(db_plugin->metric.free);

        API_CHECK(db_plugin->perm.host.set);
        API_CHECK(db_plugin->perm.host.get);
        API_CHECK(db_plugin->perm.host.check);

        exit(0);
    }

    if (d_ch == 1) {
        if (config_file == NULL) {
            fprintf(stderr, "--db-connect requires --config\n");
            exit(1);
        }

        FILE *f_config = open_config_file (config_file);
        if (f_config == NULL) {
            exit(1);
        }

        char line[128];

        while( fgets (line, sizeof(line), f_config) != NULL)
        {
            char *key = strtok(line,"=");
            char *value = strtok(NULL,"=");

            if (value[strlen(value)-1] == '\n')
            {
                value[strlen(value)-1] = '\0';
            }

            db_plugin->db.setprop(key, value);
        }

        if (db_plugin->db.connect(NULL))
        {
            exit(1);
        }

        if (db_plugin->db.disconnect(NULL))
        {
            exit(1);
        }

        exit(0);
    }

    /**
     * properties are listed, should be compared to a file.
     */
    if (l_ch) {
        char **keys;
        int i = db_plugin->db.listprop (&keys);
        int a;

        for (a = 0; a < i; ++a) {
            printf("%s\n", keys[a]);
        }

        exit(0);
    }

    if (perm_ch) {
        if (config_file == NULL) {
            fprintf(stderr, "--db-perm requires --config\n");
            exit(1);
        }

        FILE *f_config = open_config_file (config_file);
        if (f_config == NULL) {
            exit(1);
        }

        char line[128];

        while( fgets (line, sizeof(line), f_config) != NULL)
        {
            char *key = strtok(line,"=");
            char *value = strtok(NULL,"=");

            if (value[strlen(value)-1] == '\n')
            {
                value[strlen(value)-1] = '\0';
            }

            db_plugin->db.setprop(key, value);
        }

        if (db_plugin->db.connect(NULL))
        {
            exit(1);
        }

        db_plugin->perm.host.set (
                    "sys",
                    "host1.example.com",
                    1,
                    NULL);
        if (db_plugin->db.disconnect(NULL))
        {
            exit(1);
        }

        exit(0);

    }

    exit(1);
}
示例#22
0
int32_t init_srvid(void)
{
	FILE *fp = open_config_file(cs_srid);
	if (!fp)
		return 0;

	int32_t nr = 0, i;
	char *payload, *tmp, *saveptr1 = NULL, *token;
	if (!cs_malloc(&token, MAXLINESIZE))
		return 0;
	struct s_srvid *srvid=NULL, *new_cfg_srvid[16], *last_srvid[16];
	// A cache for strings within srvids. A checksum is calculated which is the start point in the array (some kind of primitive hash algo).
	// From this point, a sequential search is done. This greatly reduces the amount of string comparisons.
	char **stringcache[1024];
	int32_t allocated[1024] = { 0 };
	int32_t used[1024] = { 0 };
	struct timeb ts, te;
  cs_ftime(&ts);

	memset(last_srvid, 0, sizeof(last_srvid));
	memset(new_cfg_srvid, 0, sizeof(new_cfg_srvid));

	while (fgets(token, MAXLINESIZE, fp)) {
		int32_t l, j, len=0, len2, srvidtmp;
		uint32_t pos;
		char *srvidasc;
		tmp = trim(token);

		if (tmp[0] == '#') continue;
		if ((l=strlen(tmp)) < 6) continue;
		if (!(srvidasc = strchr(token, ':'))) continue;
		if (!(payload=strchr(token, '|'))) continue;
		*payload++ = '\0';

		if (!cs_malloc(&srvid, sizeof(struct s_srvid))) {
			free(token);
			fclose(fp);
			return(1);
		}

		char tmptxt[128];

		int32_t offset[4] = { -1, -1, -1, -1 };
		char *ptr1, *searchptr[4] = { NULL, NULL, NULL, NULL };
		char **ptrs[4] = { &srvid->prov, &srvid->name, &srvid->type, &srvid->desc };

		for (i = 0, ptr1 = strtok_r(payload, "|", &saveptr1); ptr1 && (i < 4) ; ptr1 = strtok_r(NULL, "|", &saveptr1), ++i){
			// check if string is in cache
			len2 = strlen(ptr1);
			pos = 0;
			for(j = 0; j < len2; ++j) pos += (uint8_t)ptr1[j];
			pos = pos%1024;
			for(j = 0; j < used[pos]; ++j){
				if (!strcmp(stringcache[pos][j], ptr1)){
					searchptr[i]=stringcache[pos][j];
					break;
				}
			}
			if (searchptr[i]) continue;

			offset[i]=len;
			cs_strncpy(tmptxt+len, trim(ptr1), sizeof(tmptxt)-len);
			len+=strlen(ptr1)+1;
		}

		char *tmpptr = NULL;
		if (len > 0 && !cs_malloc(&tmpptr, len))
			continue;

		srvid->data=tmpptr;
		if(len > 0) memcpy(tmpptr, tmptxt, len);

		for (i=0;i<4;i++) {
			if (searchptr[i]) {
				*ptrs[i] = searchptr[i];
				continue;
			}
			if (offset[i]>-1){
				*ptrs[i] = tmpptr + offset[i];
				// store string in stringcache
				tmp = *ptrs[i];
				len2 = strlen(tmp);
				pos = 0;
				for(j = 0; j < len2; ++j) pos += (uint8_t)tmp[j];
				pos = pos%1024;
				if(used[pos] >= allocated[pos]){
					if (allocated[pos] == 0) {
						if (!cs_malloc(&stringcache[pos], 16 * sizeof(char *)))
							break;
					} else {
						if (!cs_realloc(&stringcache[pos], (allocated[pos] + 16) * sizeof(char *)))
							break;
					}
					allocated[pos] += 16;
				}
				stringcache[pos][used[pos]] = tmp;
				used[pos] += 1;
			}
		}

		*srvidasc++ = '\0';
		srvidtmp = dyn_word_atob(srvidasc) & 0xFFFF;
		//printf("srvid %s - %d\n",srvidasc,srvid->srvid );

		if (srvidtmp<0) {
			free(tmpptr);
			free(srvid);
			continue;
		} else srvid->srvid = srvidtmp;

		srvid->ncaid = 0;
		for (i = 0, ptr1 = strtok_r(token, ",", &saveptr1); (ptr1) && (i < 10) ; ptr1 = strtok_r(NULL, ",", &saveptr1), i++){
			srvid->caid[i] = dyn_word_atob(ptr1);
			srvid->ncaid = i+1;
			//cs_debug_mask(D_CLIENT, "ld caid: %04X srvid: %04X Prov: %s Chan: %s",srvid->caid[i],srvid->srvid,srvid->prov,srvid->name);
		}
		nr++;

		if (new_cfg_srvid[srvid->srvid>>12])
			last_srvid[srvid->srvid>>12]->next = srvid;
		else
			new_cfg_srvid[srvid->srvid>>12] = srvid;

		last_srvid[srvid->srvid>>12] = srvid;
	}
示例#23
0
//Todo #ifdef CCCAM
int32_t init_provid(void) {
	FILE *fp = open_config_file(cs_provid);
	if (!fp)
		return 0;

	int32_t nr;
	char *payload, *saveptr1 = NULL, *token;
	if (!cs_malloc(&token, MAXLINESIZE))
		return 0;
	static struct s_provid *provid=(struct s_provid *)0;

	nr=0;
	while (fgets(token, MAXLINESIZE, fp)) {

		int32_t l;
		void *ptr;
		char *tmp, *providasc;
		tmp = trim(token);

		if (tmp[0] == '#') continue;
		if ((l = strlen(tmp)) < 11) continue;
		if (!(payload = strchr(token, '|'))) continue;
		if (!(providasc = strchr(token, ':'))) continue;

		*payload++ = '\0';

		if (!cs_malloc(&ptr, sizeof(struct s_provid))) {
			free(token);
			fclose(fp);
			return(1);
		}
		if (provid)
			provid->next = ptr;
		else
			cfg.provid = ptr;

		provid = ptr;

		int32_t i;
		char *ptr1;
		for (i = 0, ptr1 = strtok_r(payload, "|", &saveptr1); ptr1; ptr1 = strtok_r(NULL, "|", &saveptr1), i++){
			switch(i){
			case 0:
				cs_strncpy(provid->prov, trim(ptr1), sizeof(provid->prov));
				break;
			case 1:
				cs_strncpy(provid->sat, trim(ptr1), sizeof(provid->sat));
				break;
			case 2:
				cs_strncpy(provid->lang, trim(ptr1), sizeof(provid->lang));
				break;
			}
		}

		*providasc++ = '\0';
		provid->provid = a2i(providasc, 3);
		provid->caid = a2i(token, 3);
		nr++;
	}
	free(token);
	fclose(fp);
	if (nr>0)
		cs_log("%d provid's loaded", nr);
	return(0);
}
示例#24
0
void frontend_gui (char *gamename, int first_run)
{
	FILE *f;

	/* GP2X Initialization */
	gp2x_frontend_init();

	gp2xmenu_bmp = (unsigned short*)calloc(1, 1000000);
	gp2xsplash_bmp = (unsigned short*)calloc(1, 1000000);

	/* Show load bitmaps and show intro screen */
    gp2x_intro_screen(first_run);

	/* Initialize list of available games */
	game_list_init(1);
	if (game_num_avail==0)
	{
		/* Draw background image */
    	load_bmp_16bpp(gp2x_screen15,gp2xmenu_bmp);
		gp2x_gamelist_text_out(35, 110, "ERROR: NO AVAILABLE GAMES FOUND",gp2x_color15(255,255,255));
		FE_DisplayScreen();
		sleep(5);
		gp2x_exit();
	}

	/* Read default configuration */
	f=fopen("frontend/mame.cfg","r");
	if (f) {
		fscanf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&gp2x_freq,&gp2x_video_depth,&gp2x_video_aspect,&gp2x_video_sync,
		&gp2x_frameskip,&gp2x_sound,&gp2x_clock_cpu,&gp2x_clock_sound,&gp2x_cpu_cores,&gp2x_ramtweaks,&last_game_selected,&gp2x_cheat,&gp2x_volume);
		fclose(f);
	}

	//Read joystick configuration
	memset(pi_key, 0, NUMKEYS*2);
	memset(pi_joy, 0, NUMKEYS*2);
	open_config_file();	

	pi_key[START_1] = get_int("frontend", "K_START",    NULL, KEY_ENTER);
	pi_key[SELECT_1] = get_int("frontend", "K_SELECT",    NULL, KEY_5);
	pi_key[LEFT_1] = get_int("frontend", "K_LEFT",    NULL, KEY_LEFT);
	pi_key[RIGHT_1] = get_int("frontend", "K_RIGHT",    NULL, KEY_RIGHT);
	pi_key[UP_1] = get_int("frontend", "K_UP",    NULL, KEY_UP);
	pi_key[DOWN_1] = get_int("frontend", "K_DOWN",    NULL, KEY_DOWN);
	pi_key[A_1] = get_int("frontend", "K_A",    NULL, KEY_LCONTROL);
	pi_key[QUIT] = get_int("frontend", "K_QUIT",    NULL, KEY_ESC);

	pi_joy[START_1] = get_int("frontend", "J_START",    NULL, 9);
	pi_joy[SELECT_1] = get_int("frontend", "J_SELECT",    NULL, 8);
	pi_joy[A_1] = get_int("frontend", "J_A",    NULL, 3);

    //Read joystick axis to use, default to 0 & 1
    joyaxis_LR = get_int("frontend", "AXIS_LR", NULL, 0);
    joyaxis_UD = get_int("frontend", "AXIS_UD", NULL, 1);

	close_config_file();

	
	/* Select Game */
	select_game(playemu,playgame); 

	/* Write default configuration */
	f=fopen("frontend/mame.cfg","w");
	if (f) {
		fprintf(f,"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",gp2x_freq,gp2x_video_depth,gp2x_video_aspect,gp2x_video_sync,
		gp2x_frameskip,gp2x_sound,gp2x_clock_cpu,gp2x_clock_sound,gp2x_cpu_cores,gp2x_ramtweaks,last_game_selected,gp2x_cheat,gp2x_volume);
		fclose(f);
		sync();
	}
	
    strcpy(gamename, playgame);
    
    gp2x_frontend_deinit();

	free(gp2xmenu_bmp);
	free(gp2xsplash_bmp);
	
}
示例#25
0
int32_t init_sidtab(void)
{
	FILE *fp = open_config_file(cs_sidt);
	if(!fp)
		{ return 1; }

	int32_t nr, nro, nrr;
	char *value, *token;
	if(!cs_malloc(&token, MAXLINESIZE))
		{ return 1; }
	struct s_sidtab *ptr;
	struct s_sidtab *sidtab = (struct s_sidtab *)0;

	for(nro = 0, ptr = cfg.sidtab; ptr; nro++)
	{
		struct s_sidtab *ptr_next;
		ptr_next = ptr->next;
		free_sidtab(ptr);
		ptr = ptr_next;
	}
	nr = 0;
	nrr = 0;
	while(fgets(token, MAXLINESIZE, fp))
	{
		int32_t l;
		if((l = strlen(trim(token))) < 3) { continue; }
		if((token[0] == '[') && (token[l - 1] == ']'))
		{
			token[l - 1] = 0;
			if(nr > MAX_SIDBITS)
			{
				fprintf(stderr, "Warning: Service No.%d - '%s' ignored. Max allowed Services %d\n", nr, strtolower(token + 1), MAX_SIDBITS);
				nr++;
				nrr++;
			}
			else
			{
				if(!cs_malloc(&ptr, sizeof(struct s_sidtab)))
				{
					NULLFREE(token);
					return (1);
				}
				if(sidtab)
					{ sidtab->next = ptr; }
				else
					{ cfg.sidtab = ptr; }
				sidtab = ptr;
				nr++;
				cs_strncpy(sidtab->label, strtolower(token + 1), sizeof(sidtab->label));
				continue;
			}
		}
		if(!sidtab) { continue; }
		if(!(value = strchr(token, '='))) { continue; }
		*value++ = '\0';
		chk_sidtab(trim(strtolower(token)), trim(strtolower(value)), sidtab);
	}
	NULLFREE(token);
	fclose(fp);

	show_sidtab(cfg.sidtab);
	++cfg_sidtab_generation;
	cs_log("services reloaded: %d services freed, %d services loaded, rejected %d", nro, nr, nrr);
	return (0);
}
示例#26
0
文件: config.c 项目: snsl/pvfs2-osd
int get_config(PORANGEFS_OPTIONS options,
               char *error_msg,
               unsigned int error_msg_len)
{
    FILE *config_file;
    char line[256], copy[256], *token, *p, *endptr;
    int ret = 0, debug_file_flag = FALSE;
    long mask;

    config_file = open_config_file(error_msg, error_msg_len);
    if (config_file == NULL)
        /* config file is required */
        return -1;

    set_defaults(options);

    /* parse options from the file */
    while (!feof(config_file))
    {
        line[0] = '\0';
        fgets(line, 256, config_file);

        /* remove \n */        
        if (strlen(line) > 0 && line[strlen(line)-1] == '\n')
            line[strlen(line)-1] = '\0';
        
        /* check line -- # used for comments */
        if (strlen(line) > 0 && line[0] != '#')
        {
            /* make a copy */
            strncpy(copy, line, 256);
            /* parse line */
            token = strtok(copy, " \t");
            if (token == NULL)
                continue;

            if (!stricmp(token, "mount"))
            {
                /* copy the remaining portion of the line 
                   as the mount point */
                token = strtok(NULL, " \t");
                strncpy(options->mount_point, token, MAX_PATH);
            }
            else if (!stricmp(token, "threads"))
            {
                token = strtok(NULL, " \t");
                options->threads = atoi(token);
            }
            else if (!stricmp(token, "user-mode"))
            {
                token = strtok(NULL, " \t");
                if (token == NULL)
                {
                    _snprintf(error_msg, error_msg_len, 
                        "Configuration file (fatal): "
                        "user-mode option must be list, certificate, "
                        "or ldap");
                    ret = -1;
                    goto get_config_exit;
                }
                if (!stricmp(token, "list"))
                {
                    options->user_mode = USER_MODE_LIST;
                }
                else if (!stricmp(token, "certificate"))
                {
                    options->user_mode = USER_MODE_CERT;
                }
                else if (!stricmp(token, "ldap"))
                {
                    options->user_mode = USER_MODE_LDAP;
                }
                else
                {
                    _snprintf(error_msg, error_msg_len,
                        "Configuration file (fatal): "
                        "user-mode option must be list, certificate, "
                        "or ldap");
                    ret = -1;
                    goto get_config_exit;
                }
            }
            else if (!stricmp(token, "user")) 
            {
                if (options->user_mode == USER_MODE_NONE)
                {
                    _snprintf(error_msg, error_msg_len, 
                        "Configuration file (fatal): "
                        "user option: specify 'user-mode list' above user "
                        "option");
                    ret = -1;
                    goto get_config_exit;
                }
                else if (options->user_mode != USER_MODE_LIST)
                {
                    _snprintf(error_msg, error_msg_len, 
                        "Configuration file (fatal): "
                        "user option: not legal with current user mode");
                    ret = -1;
                    goto get_config_exit;
                }

                if (parse_user() != 0)
                {
                    _snprintf(error_msg, error_msg_len, 
                        "Configuration file (fatal): "
                        "user option: parse error");
                    ret = -1;
                    goto get_config_exit;
                }
            }            
            else if (!stricmp(token, "cert-dir-prefix"))
            {
                p = line + strlen(token);
                EAT_WS(p);
                if (strlen(p) > 0)
                {
                    strncpy(options->cert_dir_prefix, p, MAX_PATH-2);
                    options->cert_dir_prefix[MAX_PATH-2] = '\0';
                    if (options->cert_dir_prefix[strlen(options->cert_dir_prefix)-1] != '\\')
                        strcat(options->cert_dir_prefix, "\\");
                }
                else
                {
                    _snprintf(error_msg, error_msg_len, 
                        "Configuration file (fatal): "
                        "cert-dir-prefix option: parse error");
                    ret = -1;
                    goto get_config_exit;
                }
            }
            else if (!stricmp(token, "ca-path"))
            {
                p = line + strlen(token);
                EAT_WS(p);
                if (strlen(p) > 0)
                {
                    strncpy(options->ca_path, p, MAX_PATH-2);
                    options->ca_path[MAX_PATH-2] = '\0';
                }
                else
                {
                    _snprintf(error_msg, error_msg_len, 
                        "Configuration file (fatal): "
                        "ca-path option: parse error\n");
                    ret = -1;
                    goto get_config_exit;
                }
            }
            else if (!stricmp(token, "new-file-perms") ||
                     !stricmp(token, "new-dir-perms"))
            {
                p = line + strlen(token);
                EAT_WS(p);
                /* get mask in octal format */
                mask = strtol(p, &endptr, 8);
                if (!mask || *endptr != '\0')
                {
                    _snprintf(error_msg, error_msg_len,
                        "Configuration file (fatal): "
                        "%s option: parse error - value must be "
                        "nonzero octal integer\n", token);
                    ret = -1;
                    goto get_config_exit;
                }
                if (!stricmp(token, "new-file-perms"))
                {
                    options->new_file_perms = (unsigned int) mask;
                }
                else
                {
                    options->new_dir_perms = (unsigned int) mask;
                }
            }
            else if (!stricmp(token, "debug"))
            {
                options->debug = TRUE;
                /* rest of line gives optional debug mask */
                p = line + strlen(token);
                EAT_WS(p);
                if (strlen(p) > 0)
                {
                    strncpy(options->debug_mask, p, 256);
                    options->debug_mask[255] = '\0';
                }
                else
                {
                    /* just debug Windows client */
                    strcpy(options->debug_mask, "win_client");
                }
            }
            else if (!stricmp(token, "debug-stderr"))
            {
                options->debug_stderr = options->debug = TRUE;
            }
            else if (!stricmp(token, "debug-file"))
            {
                debug_file_flag = TRUE;
                /* path to debug file */
                p = line + strlen(token);
                EAT_WS(p);
                if (strlen(p) > 0)
                {
                    strncpy(options->debug_file, p, MAX_PATH-2);
                    options->debug_file[MAX_PATH-2] = '\0';
                }
            }
            else if (!strnicmp(token, "ldap", 4))
            {
                ret = parse_ldap_option(options, line, token, error_msg, 
                    error_msg_len);
                if (ret != 0)
                    goto get_config_exit;
            }
            else
            {
                _snprintf(error_msg, error_msg_len, 
                    "Configuration file (fatal): "
                    "Unknown option %s", token);
                ret = -1;
                goto get_config_exit;
            }
        }
    }

    if (options->user_mode == USER_MODE_NONE)
    {
        _snprintf(error_msg, error_msg_len, 
            "Configuration file (fatal): "
            "Must specify user-mode (list, certificate or ldap)");
        ret = -1;
        goto get_config_exit;
    }

    if (options->user_mode == USER_MODE_LDAP &&
        (strlen(options->ldap.host) == 0 ||
         strlen(options->ldap.search_root) == 0))
    {        
        _snprintf(error_msg, error_msg_len, 
            "Configuration file (fatal): "
            "Missing ldap option: ldap-host, or ldap-search-root");
        ret = -1;
    }

    /* gossip can only print to either a file or stderr */
    if (options->debug_stderr && debug_file_flag)
    {
        _snprintf(error_msg, error_msg_len, 
            "Configuration file (fatal): "
            "Cannot specify both debug-stderr and debug-file");
        ret = -1;
    }

    if (options->user_mode == USER_MODE_LDAP &&
        options->ldap.port == 0)
        options->ldap.port = options->ldap.secure ? 636 : 389;

get_config_exit:

    close_config_file(config_file);

    return ret;
}
示例#27
0
int32_t init_provid(void)
{
	FILE *fp = open_config_file(cs_provid);
	if(!fp)
		{ return 0; }

	int32_t nr;
	char *payload, *saveptr1 = NULL, *token;
	if(!cs_malloc(&token, MAXLINESIZE))
		{ return 0; }
	struct s_provid *provid_ptr = NULL;
	struct s_provid *new_cfg_provid = NULL, *last_provid;

	nr = 0;
	while(fgets(token, MAXLINESIZE, fp))
	{
		int32_t i, l;
		struct s_provid *new_provid = NULL;
		char *tmp, *ptr1;
		
		tmp = trim(token);

		if(tmp[0] == '#') { continue; }
		if((l = strlen(tmp)) < 11) { continue; }
		if(!(payload = strchr(token, '|'))) { continue; }

		*payload++ = '\0';
		
		if(!cs_malloc(&new_provid, sizeof(struct s_provid)))
		{
			NULLFREE(token);
			fclose(fp);
			return (1);
		}
				
		new_provid->nprovid = 0;
		for(i = 0, ptr1 = strtok_r(token, ":@", &saveptr1); ptr1; ptr1 = strtok_r(NULL, ":@", &saveptr1), i++)
		{
			if(i==0)
			{
				new_provid->caid = a2i(ptr1, 3);
				continue;	
			}
			
			new_provid->nprovid++;
		}

		if(!cs_malloc(&new_provid->provid, sizeof(uint32_t) * new_provid->nprovid))
		{
			NULLFREE(new_provid);
			NULLFREE(token);
			fclose(fp);
			return (1);
		}

		ptr1 = token + strlen(token) + 1;
		for(i = 0; i < new_provid->nprovid ; i++)
		{
			new_provid->provid[i] = a2i(ptr1, 3);
			
			ptr1 = ptr1 + strlen(ptr1) + 1;
		}
		
		for(i = 0, ptr1 = strtok_r(payload, "|", &saveptr1); ptr1; ptr1 = strtok_r(NULL, "|", &saveptr1), i++)
		{
			switch(i)
			{
			case 0:
				cs_strncpy(new_provid->prov, trim(ptr1), sizeof(new_provid->prov));
				break;
			case 1:
				cs_strncpy(new_provid->sat, trim(ptr1), sizeof(new_provid->sat));
				break;
			case 2:
				cs_strncpy(new_provid->lang, trim(ptr1), sizeof(new_provid->lang));
				break;
			}
		}
		
		if(strlen(new_provid->prov) == 0)
		{
			NULLFREE(new_provid->provid);
			NULLFREE(new_provid);
			continue;
		}
		
		nr++;
				
		if(provid_ptr)
		{
			provid_ptr->next = new_provid;
		}
		else
		{ 
			new_cfg_provid = new_provid;
		}	
		provid_ptr = new_provid;
	}
	
	NULLFREE(token);
	fclose(fp);
	
	if(nr > 0)
		{ cs_log("%d provid's loaded", nr); }
	
	if(new_cfg_provid == NULL)
	{
		if(!cs_malloc(&new_cfg_provid, sizeof(struct s_provid)))
		{
			return (1);
		}		
	}
	
	cs_writelock(__func__, &config_lock);
	
	//this allows reloading of provids, so cleanup of old data is needed:
	last_provid = cfg.provid; //old data
	cfg.provid = new_cfg_provid; //assign after loading, so everything is in memory

	cs_writeunlock(__func__, &config_lock);

	struct s_client *cl;
	for(cl = first_client->next; cl ; cl = cl->next)
		{ cl->last_providptr = NULL; }

	struct s_provid *ptr, *nptr;
	
	if(last_provid)
	{
		ptr = last_provid;
		while(ptr)    //cleanup old data:
		{
			add_garbage(ptr->provid);
			nptr = ptr->next;
			add_garbage(ptr);
			ptr = nptr;
		}
	}
			
	return (0);
}
示例#28
0
void pi_initialize_input()
{
    memset(joy_buttons, 0, 32*2);
    memset(joy_axes, 0, 4*2);
    memset(pi_key, 0, NUMKEYS*2);
    memset(pi_joy, 0, NUMKEYS*2);

    //Open config file for reading below
    open_config_file();

    //Configure keys from config file or defaults
    pi_key[A_1] = get_integer_conf("Keyboard", "A_1", RPI_KEY_A);
    pi_key[B_1] = get_integer_conf("Keyboard", "B_1", RPI_KEY_B);
    pi_key[X_1] = get_integer_conf("Keyboard", "X_1", RPI_KEY_X);
    pi_key[Y_1] = get_integer_conf("Keyboard", "Y_1", RPI_KEY_Y);
    pi_key[L_1] = get_integer_conf("Keyboard", "L_1", RPI_KEY_L);
    pi_key[R_1] = get_integer_conf("Keyboard", "R_1", RPI_KEY_R);
    pi_key[START_1] = get_integer_conf("Keyboard", "START_1", RPI_KEY_START);
    pi_key[SELECT_1] = get_integer_conf("Keyboard", "SELECT_1", RPI_KEY_SELECT);
    pi_key[LEFT_1] = get_integer_conf("Keyboard", "LEFT_1", RPI_KEY_LEFT);
    pi_key[RIGHT_1] = get_integer_conf("Keyboard", "RIGHT_1", RPI_KEY_RIGHT);
    pi_key[UP_1] = get_integer_conf("Keyboard", "UP_1", RPI_KEY_UP);
    pi_key[DOWN_1] = get_integer_conf("Keyboard", "DOWN_1", RPI_KEY_DOWN);

    pi_key[A_2] = get_integer_conf("Keyboard", "A_2", RPI_KEY_A_2);
    pi_key[B_2] = get_integer_conf("Keyboard", "B_2", RPI_KEY_B_2);
    pi_key[X_2] = get_integer_conf("Keyboard", "X_2", RPI_KEY_X_2);
    pi_key[Y_2] = get_integer_conf("Keyboard", "Y_2", RPI_KEY_Y_2);
    pi_key[L_2] = get_integer_conf("Keyboard", "L_2", RPI_KEY_L_2);
    pi_key[R_2] = get_integer_conf("Keyboard", "R_2", RPI_KEY_R_2);
    pi_key[START_2] = get_integer_conf("Keyboard", "START_2", RPI_KEY_START_2);
    pi_key[SELECT_2] = get_integer_conf("Keyboard", "SELECT_2", RPI_KEY_SELECT_2);
    pi_key[LEFT_2] = get_integer_conf("Keyboard", "LEFT_2", RPI_KEY_LEFT_2);
    pi_key[RIGHT_2] = get_integer_conf("Keyboard", "RIGHT_2", RPI_KEY_RIGHT_2);
    pi_key[UP_2] = get_integer_conf("Keyboard", "UP_2", RPI_KEY_UP_2);
    pi_key[DOWN_2] = get_integer_conf("Keyboard", "DOWN_2", RPI_KEY_DOWN_2);

    pi_key[QUIT] = get_integer_conf("Keyboard", "QUIT", RPI_KEY_QUIT);

    //Configure joysticks from config file or defaults
    pi_joy[A_1] = get_integer_conf("Joystick", "A_1", RPI_JOY_A);
    pi_joy[B_1] = get_integer_conf("Joystick", "B_1", RPI_JOY_B);
    pi_joy[X_1] = get_integer_conf("Joystick", "X_1", RPI_JOY_X);
    pi_joy[Y_1] = get_integer_conf("Joystick", "Y_1", RPI_JOY_Y);
    pi_joy[L_1] = get_integer_conf("Joystick", "L_1", RPI_JOY_L);
    pi_joy[R_1] = get_integer_conf("Joystick", "R_1", RPI_JOY_R);

    pi_joy[UP_1] = get_integer_conf("Joystick", "UP_1", RPI_JOY_UP);
    pi_joy[DOWN_1] = get_integer_conf("Joystick", "DOWN_1", RPI_JOY_DOWN);
    pi_joy[LEFT_1] = get_integer_conf("Joystick", "LEFT_1", RPI_JOY_LEFT);
    pi_joy[RIGHT_1] = get_integer_conf("Joystick", "RIGHT_1", RPI_JOY_RIGHT);

    pi_joy[START_1] = get_integer_conf("Joystick", "START_1", RPI_JOY_START);
    pi_joy[SELECT_1] = get_integer_conf("Joystick", "SELECT_1", RPI_JOY_SELECT);

    pi_joy[A_2] = get_integer_conf("Joystick", "A_2", RPI_JOY_A);
    pi_joy[B_2] = get_integer_conf("Joystick", "B_2", RPI_JOY_B);
    pi_joy[X_2] = get_integer_conf("Joystick", "X_2", RPI_JOY_X);
    pi_joy[Y_2] = get_integer_conf("Joystick", "Y_2", RPI_JOY_Y);
    pi_joy[L_2] = get_integer_conf("Joystick", "L_2", RPI_JOY_L);
    pi_joy[R_2] = get_integer_conf("Joystick", "R_2", RPI_JOY_R);

    pi_joy[UP_2] = get_integer_conf("Joystick", "UP_2", RPI_JOY_UP);
    pi_joy[DOWN_2] = get_integer_conf("Joystick", "DOWN_2", RPI_JOY_DOWN);
    pi_joy[LEFT_2] = get_integer_conf("Joystick", "LEFT_2", RPI_JOY_LEFT);
    pi_joy[RIGHT_2] = get_integer_conf("Joystick", "RIGHT_2", RPI_JOY_RIGHT);

    pi_joy[START_2] = get_integer_conf("Joystick", "START_2", RPI_JOY_START);
    pi_joy[SELECT_2] = get_integer_conf("Joystick", "SELECT_2", RPI_JOY_SELECT);

    pi_joy[A_3] = get_integer_conf("Joystick", "A_3", RPI_JOY_A);
    pi_joy[B_3] = get_integer_conf("Joystick", "B_3", RPI_JOY_B);
    pi_joy[X_3] = get_integer_conf("Joystick", "X_3", RPI_JOY_X);
    pi_joy[Y_3] = get_integer_conf("Joystick", "Y_3", RPI_JOY_Y);
    pi_joy[L_3] = get_integer_conf("Joystick", "L_3", RPI_JOY_L);
    pi_joy[R_3] = get_integer_conf("Joystick", "R_3", RPI_JOY_R);

    pi_joy[UP_3] = get_integer_conf("Joystick", "UP_3", RPI_JOY_UP);
    pi_joy[DOWN_3] = get_integer_conf("Joystick", "DOWN_3", RPI_JOY_DOWN);
    pi_joy[LEFT_3] = get_integer_conf("Joystick", "LEFT_3", RPI_JOY_LEFT);
    pi_joy[RIGHT_3] = get_integer_conf("Joystick", "RIGHT_3", RPI_JOY_RIGHT);

    pi_joy[START_3] = get_integer_conf("Joystick", "START_3", RPI_JOY_START);
    pi_joy[SELECT_3] = get_integer_conf("Joystick", "SELECT_3", RPI_JOY_SELECT);

    pi_joy[A_4] = get_integer_conf("Joystick", "A_4", RPI_JOY_A);
    pi_joy[B_4] = get_integer_conf("Joystick", "B_4", RPI_JOY_B);
    pi_joy[X_4] = get_integer_conf("Joystick", "X_4", RPI_JOY_X);
    pi_joy[Y_4] = get_integer_conf("Joystick", "Y_4", RPI_JOY_Y);
    pi_joy[L_4] = get_integer_conf("Joystick", "L_4", RPI_JOY_L);
    pi_joy[R_4] = get_integer_conf("Joystick", "R_4", RPI_JOY_R);

    pi_joy[UP_4] = get_integer_conf("Joystick", "UP_4", RPI_JOY_UP);
    pi_joy[DOWN_4] = get_integer_conf("Joystick", "DOWN_4", RPI_JOY_DOWN);
    pi_joy[LEFT_4] = get_integer_conf("Joystick", "LEFT_4", RPI_JOY_LEFT);
    pi_joy[RIGHT_4] = get_integer_conf("Joystick", "RIGHT_4", RPI_JOY_RIGHT);

    pi_joy[START_4] = get_integer_conf("Joystick", "START_4", RPI_JOY_START);
    pi_joy[SELECT_4] = get_integer_conf("Joystick", "SELECT_4", RPI_JOY_SELECT);

    pi_joy[QUIT] = get_integer_conf("Joystick", "QUIT", RPI_JOY_QUIT);
    pi_joy[ACCEL] = get_integer_conf("Joystick", "ACCEL", RPI_JOY_ACCEL);

    pi_joy[QLOAD] = get_integer_conf("Joystick", "QLOAD", RPI_JOY_QLOAD);
    pi_joy[QSAVE] = get_integer_conf("Joystick", "QSAVE", RPI_JOY_QSAVE);

    //Read joystick axis to use, default to 0 & 1
    joyaxis_LR[0] = get_integer_conf("Joystick", "JA_LR_1", 0);
    joyaxis_UD[0] = get_integer_conf("Joystick", "JA_UD_1", 1);
    joyaxis_LR[1] = get_integer_conf("Joystick", "JA_LR_2", 0);
    joyaxis_UD[1] = get_integer_conf("Joystick", "JA_UD_2", 1);
    joyaxis_LR[2] = get_integer_conf("Joystick", "JA_LR_3", 0);
    joyaxis_UD[2] = get_integer_conf("Joystick", "JA_UD_3", 1);
    joyaxis_LR[3] = get_integer_conf("Joystick", "JA_LR_4", 0);
    joyaxis_UD[3] = get_integer_conf("Joystick", "JA_UD_4", 1);

    close_config_file();

}
示例#29
0
文件: core.c 项目: adrianlshaw/libvmi
status_t
read_config_file(
    vmi_instance_t vmi)
{
    status_t ret = VMI_SUCCESS;
    vmi_config_entry_t *entry;
    char *configstr = (char *)vmi->config;
    char *tmp = NULL;

    yyin = NULL;

    if (configstr) {
        yyin = fmemopen(configstr, strlen(configstr), "r");
    }

    if (NULL == yyin) {
        yyin = open_config_file();
        if (NULL == yyin) {
            fprintf(stderr, "ERROR: config file not found.\n");
            ret = VMI_FAILURE;
            goto error_exit;
        }
    }

    if (vmi_parse_config(vmi->image_type) != 0) {
        errprint("Failed to read config file.\n");
        ret = VMI_FAILURE;
        goto error_exit;
    }
    entry = vmi_get_config();

    /* copy the values from entry into instance struct */
    vmi->sysmap = strdup(entry->sysmap);
    dbprint("--got sysmap from config (%s).\n", vmi->sysmap);

    if (strncmp(entry->ostype, "Linux", CONFIG_STR_LENGTH) == 0) {
        vmi->os_type = VMI_OS_LINUX;
    }
    else if (strncmp(entry->ostype, "Windows", CONFIG_STR_LENGTH) == 0) {
        vmi->os_type = VMI_OS_WINDOWS;
    }
    else {
        errprint("Unknown or undefined OS type.\n");
        ret = VMI_FAILURE;
        goto error_exit;
    }

    /* Copy config info based on OS type */
    if (VMI_OS_LINUX == vmi->os_type) {
        dbprint("--reading in linux offsets from config file.\n");
        if (entry->offsets.linux_offsets.tasks) {
            vmi->os.linux_instance.tasks_offset =
                entry->offsets.linux_offsets.tasks;
        }

        if (entry->offsets.linux_offsets.mm) {
            vmi->os.linux_instance.mm_offset =
                entry->offsets.linux_offsets.mm;
        }

        if (entry->offsets.linux_offsets.pid) {
            vmi->os.linux_instance.pid_offset =
                entry->offsets.linux_offsets.pid;
        }

        if (entry->offsets.linux_offsets.name) {
            vmi->os.linux_instance.name_offset =
                entry->offsets.linux_offsets.name;
        }

        if (entry->offsets.linux_offsets.pgd) {
            vmi->os.linux_instance.pgd_offset =
                entry->offsets.linux_offsets.pgd;
        }
    }
    else if (VMI_OS_WINDOWS == vmi->os_type) {
        dbprint("--reading in windows offsets from config file.\n");
        if (entry->offsets.windows_offsets.ntoskrnl) {
            vmi->os.windows_instance.ntoskrnl =
                entry->offsets.windows_offsets.ntoskrnl;
        }

        if (entry->offsets.windows_offsets.tasks) {
            vmi->os.windows_instance.tasks_offset =
                entry->offsets.windows_offsets.tasks;
        }

        if (entry->offsets.windows_offsets.pdbase) {
            vmi->os.windows_instance.pdbase_offset =
                entry->offsets.windows_offsets.pdbase;
        }

        if (entry->offsets.windows_offsets.pid) {
            vmi->os.windows_instance.pid_offset =
                entry->offsets.windows_offsets.pid;
        }

        if (entry->offsets.windows_offsets.pname) {
            vmi->os.windows_instance.pname_offset =
                entry->offsets.windows_offsets.pname;
        }

        if (entry->offsets.windows_offsets.kdvb) {
            vmi->os.windows_instance.kdversion_block =
                entry->offsets.windows_offsets.kdvb;
        }

        if (entry->offsets.windows_offsets.sysproc) {
            vmi->os.windows_instance.sysproc =
                entry->offsets.windows_offsets.sysproc;
        }
    }

#ifdef VMI_DEBUG
    dbprint("--got ostype from config (%s).\n", entry->ostype);
    if (vmi->os_type == VMI_OS_LINUX) {
        dbprint("**set os_type to Linux.\n");
    }
    else if (vmi->os_type == VMI_OS_WINDOWS) {
        dbprint("**set os_type to Windows.\n");
    }
    else {
        dbprint("**set os_type to unknown.\n");
    }
#endif

error_exit:
    if (tmp)
        free(tmp);
    if (yyin)
        fclose(yyin);
    return ret;
}