Beispiel #1
0
/**
 * Set the filters used by the service
 *
 * @param service	The service itself
 * @param filters	ASCII string of filters to use
 */
void
serviceSetFilters(SERVICE *service, char *filters)
{
FILTER_DEF	**flist;
char		*ptr, *brkt;
int		n = 0;

	if ((flist = (FILTER_DEF **)malloc(sizeof(FILTER_DEF *))) == NULL)
	{
		LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
			"Error : Out of memory adding filters to service.\n")));
		return;
	}
	ptr = strtok_r(filters, "|", &brkt);
	while (ptr)
	{
		n++;
		if ((flist = (FILTER_DEF **)realloc(flist,
				(n + 1) * sizeof(FILTER_DEF *))) == NULL)
		{
			LOGIF(LE, (skygw_log_write_flush(LOGFILE_ERROR,
				"Error : Out of memory adding filters to service.\n")));
			return;
		}
		if ((flist[n-1] = filter_find(trim(ptr))) == NULL)
		{
			LOGIF(LE, (skygw_log_write_flush(
                                LOGFILE_ERROR,
				"Warning : Unable to find filter '%s' for service '%s'\n",
					trim(ptr), service->name
					)));
			n--;
		}
		flist[n] = NULL;
		ptr = strtok_r(NULL, "|", &brkt);
	}

	service->filters = flist;
	service->n_filters = n;
}
Beispiel #2
0
int config_parse_args(config_t *cfg, int argc, char *argv[])
{
    int i;
    int saw_dump_file = 0;

    if (argc < 2) {
        debug_printf(CONFIG, WARNING,
                "Processors tend to be unhappy with nothing on their bus.\n"
                "(Run \"%s --help\" for more info.)\n", argv[0]);
    }

    for (i = 1; i < argc; ) {
        if (!strcmp(argv[i], "--region") || !strcmp(argv[i], "-r")) {
            uint32_t base, size;
            char *end;

            if (argc - i < 4) {
                debug_print(CONFIG, FATAL,
                        "--region: expected <base> <size> <readmemh-file>\n");
                return 1;
            }
            base = strtoul(argv[i + 1], &end, 16);
            if (*end != '\0') {
                debug_printf(CONFIG, FATAL,
                        "--region: invalid base \"%s\"\n", argv[i + 1]);
                return 1;
            }
            size = strtoul(argv[i + 2], &end, 16);
            if (*end != '\0') {
                debug_printf(CONFIG, FATAL,
                        "--region: invalid size \"%s\"\n", argv[i + 2]);
                return 1;
            }
            if (do_region(cfg->mem, base, size, argv[i + 3])) {
                return 1;
            }
            i += 4;
        } else if (!strcmp(argv[i], "--pc") || !strcmp(argv[i], "-p")) {
            uint32_t pc;
            char *end;

            if (argc - i < 2) {
                debug_print(CONFIG, FATAL, "--pc: expected <initial-pc>\n");
                return 1;
            }
            pc = strtoul(argv[i + 1], &end, 16);
            if (*end != '\0') {
                debug_printf(CONFIG, FATAL,
                        "--pc: invalid pc \"%s\"\n", argv[i + 1]);
                return 1;
            }
            cfg->pc = pc;
            i += 2;
        } else if (!strcmp(argv[i], "--dump") || !strcmp(argv[i], "-d")) {
            if (argc - i < 1) {
                debug_print(CONFIG, FATAL, "--dump: expected <dump-file>\n");
                return 1;
            }
            if (saw_dump_file) {
                debug_print(CONFIG, FATAL,
                        "--dump: may not be specified multiple times\n");
                return 1;
            }
            cfg->dump_file = fopen(argv[i + 1], "w");
            if (!cfg->dump_file) {
                debug_printf(CONFIG, FATAL,
                        "%s: %s\n", argv[i + 1], strerror(errno));
                return 1;
            }
            saw_dump_file = 1;
            i += 2;
        } else if (!strcmp(argv[i], "--console") || !strcmp(argv[i], "-c")) {
            uint32_t addr;
            char *end;

            if (argc - i < 2) {
                debug_print(CONFIG, FATAL, "--console: expected <addr>\n");
                return 1;
            }
            addr = strtoul(argv[i + 1], &end, 16);
            if (*end != '\0') {
                debug_printf(CONFIG, FATAL,
                        "--console: invalid addr \"%s\"\n", argv[i + 1]);
                return 1;
            }
            mem_map(cfg->mem, addr, serial_create(0, 1));
            i += 2;
        } else if (!strcmp(argv[i], "--filter") || !strcmp(argv[i], "-f")) {
            if (argc - i < 2) {
                debug_print(CONFIG, FATAL, "--filter: expected <filter>\n");
                return 1;
            }
            cfg->filter = filter_find(argv[i + 1]);
            if (!cfg->filter) {
                debug_printf(CONFIG, FATAL,
                        "--filter: unknown filter \"%s\"\n", argv[i + 1]);
                return 1;
            }
            i += 2;
        } else if (!strncmp(argv[i], "--filter=", 9)) {
            cfg->filter = filter_find(argv[i] + 9);
            if (!cfg->filter) {
                debug_printf(CONFIG, FATAL,
                        "--filter: unknown filter \"%s\"\n", argv[i] + 9);
                return 1;
            }
            i += 1;
        } else if (!strcmp(argv[i], "--step") || !strcmp(argv[i], "-s")) {
            cfg->step = 1;
            i += 1;
        } else if (!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
            usage(argv[0]);
            return 1;
        } else if (!strcmp(argv[i], "--quiet") || !strcmp(argv[i], "-q")) {
            if (cfg->debug > 0) {
                debug_set_level(--cfg->debug);
            }
            i += 1;
        } else if (!strcmp(argv[i], "--verbose") || !strcmp(argv[i], "-v")) {
            if (cfg->debug < NUM_DEBUG_LEVELS - 1) {
                debug_set_level(++cfg->debug);
            }
            i += 1;
        } else if (!strcmp(argv[i], "--version") || !strcmp(argv[i], "-V")) {
            version();
            return 1;
        } else {
            debug_printf(CONFIG, FATAL, "Invalid argument \"%s\"\n", argv[i]);
            return 1;
        }
    }

    return 0;
}