Exemple #1
0
int main(const int argc, char **argv)
{
	
	char *feed;
	Regexfilter *filterList = filter_new(NULL,".*");
	int i, j,
		timeout = 3;

	/* supply regex filter */
	if (argc > 1) {
		for (i = 1; i < argc; ++i) {
			if (strcmp(argv[i], "-e") == 0) {
				filter_set_pattern(filterList, argv[i+1]);
				
				for (j = i+2; j < argc ; j++) {

					if (argv[j][0] == '-')
						break;
					
					filter_new(filterList, argv[j]);
				}
				
			}
			if (strcmp(argv[i], "-t") == 0) {
				timeout = atoi(argv[i+1]);
			}
			if (strcmp(argv[i], "-h") == 0) {
				usage();
				return EXIT_SUCCESS;
			}
		}
	} 

	/* get feed from stdin */
	if (stdin_ready(fileno(stdin), timeout)) {
		feed = stdin_get(feed);
	} else {
		fprintf(stderr, "no feed\n");
		return EXIT_FAILURE;
	}
	
	
	/* run filters */
	feed = filter(feed, filterList);
	
	
	/* output filtered xml */
	printf("%s", feed);
	

	free(feed);
	filter_destroy(filterList);
	
	return EXIT_SUCCESS;
}
struct filter *
filter_chain_new(void)
{
	struct filter *filter = filter_new(&chain_filter_plugin, NULL, NULL);
	/* chain_filter_init() never fails */
	assert(filter != NULL);

	return filter;
}
static const struct audio_format *
autoconvert_filter_open(struct filter *_filter,
			struct audio_format *in_audio_format,
			GError **error_r)
{
	struct autoconvert_filter *filter =
		(struct autoconvert_filter *)_filter;
	const struct audio_format *out_audio_format;

	assert(audio_format_valid(in_audio_format));

	/* open the "real" filter */

	filter->in_audio_format = *in_audio_format;

	out_audio_format = filter_open(filter->filter,
				       &filter->in_audio_format, error_r);
	if (out_audio_format == NULL)
		return NULL;

	/* need to convert? */

	if (!audio_format_equals(&filter->in_audio_format, in_audio_format)) {
		/* yes - create a convert_filter */
		struct audio_format audio_format2 = *in_audio_format;
		const struct audio_format *audio_format3;

		filter->convert = filter_new(&convert_filter_plugin, NULL,
					     error_r);
		if (filter->convert == NULL) {
			filter_close(filter->filter);
			return NULL;
		}

		audio_format3 = filter_open(filter->convert, &audio_format2,
					    error_r);
		if (audio_format3 == NULL) {
			filter_free(filter->convert);
			filter_close(filter->filter);
			return NULL;
		}

		assert(audio_format_equals(&audio_format2, in_audio_format));

		convert_filter_set(filter->convert, &filter->in_audio_format);
	} else
		/* no */
		filter->convert = NULL;

	return out_audio_format;
}
PRIVATE int parseFilter(am_filters *filters, const char* filter_str) {
  am_filter filter = NULL;
  int32_t result = SUCCESS; /* be optimistic */
  simple_list option_list = NULL;
  NODE * current = NULL;
  suboption_t *opt_item = NULL;
  char *tmpStr = NULL;

  option_list = parseMultiOption(filter_str);
  current = option_list;

  while (current != NULL) {
    opt_item = (suboption_t*)current->data;
    if(opt_item != NULL) {
      if(!filter) {
        filter = filter_new();
        assert(filter && "filter_new() failed!");
      }

      if(!strncmp(opt_item->option, "pattern", 7)) {
        filter->pattern = trim(opt_item->value);
      } else if(!strncmp(opt_item->option, "folder", 6)) {
        tmpStr = trim(opt_item->value);
        set_path(tmpStr, &filter->folder);
        am_free(tmpStr);
      } else if(!strncmp(opt_item->option, "feedid", 6)) {
        filter->feedID = trim(opt_item->value);
      } else {
        dbg_printf(P_ERROR, "Unknown suboption '%s'!", opt_item->option);
      }
    } else {
      assert(0 && "opt_item == NULL");
    }

    current = current->next;
  }

  if(filter && filter->pattern) {
    filter_add(filter, filters);
  } else {
    dbg_printf(P_ERROR, "Invalid filter: '%s'", filter_str);
    filter_free(filter);
    result = FAILURE;
  }

  if(option_list != NULL) {
    freeList(&option_list, freeOptionItem);
  }

  return result;
}
Exemple #5
0
PRIVATE int addPatterns_old(am_filters *patlist, const char* strlist) {
  char *p = NULL;
  char *str = NULL;
  assert(patlist != NULL);
  str = shorten(strlist);
  p = strtok(str, AM_DELIMITER);
  while (p) {
    am_filter pat = filter_new();
    assert(pat != NULL);
    pat->pattern = strdup(p);
    filter_add(pat, patlist);
    p = strtok(NULL, AM_DELIMITER);
  }
  am_free(str);
  return SUCCESS;
}
Exemple #6
0
static Client* client_new()
{
    Filter* filter = 0;
    Client* client = 0;

    client = g_new(Client, 1);

    if (!(filter = filter_new(client, client_handle_message))) {
        g_free(client);
        client = 0;
    }

    if (client) {
        client->filter   = filter;
        client->handlers = dispatcher_list_new();
    }

    return client;
}
Exemple #7
0
PRIVATE int parseFilter(am_filters *patlist, const char* match) {
  char *line = NULL, *option = NULL, *param = NULL;
  char *saveptr;
  char *str = NULL;
  am_filter filter = NULL;
  int result = SUCCESS; /* be optimistic */

  str = shorten(match);

  line = strtok_r(str, AM_DELIMITER, &saveptr);
  while (line) {
    if(!filter) {
      filter = filter_new();
      assert(filter && "filter_new() failed!");
    }
    if(parseSubOption(line, &option, &param) == 0) {
      if(!strncmp(option, "pattern", 7)) {
        filter->pattern = shorten(param);
      } else if(!strncmp(option, "useragent", 9)) {
        filter->agent = shorten(param);
      } else {
        dbg_printf(P_ERROR, "Unknown suboption '%s'!", option);
      }
      am_free(option);
      am_free(param);
    } else {
      dbg_printf(P_ERROR, "Invalid suboption string: '%s'!", line);
    }
    line = strtok_r(NULL, AM_DELIMITER, &saveptr);
  }

  if(filter && filter->pattern) {
    filter_add(filter, patlist);
  } else {
    dbg_printf(P_ERROR, "Invalid filter: '%s'", str);
    result = FAILURE;
  }

  am_free(str);
  return result;
}
Exemple #8
0
static Service* service_new(const char* name)
{
  DBusError error;
  Filter*   filter  = 0;
  Service*  service = 0;

  dbus_error_init(&error);

  service = g_new(Service, 1);

  if (!(filter = filter_new(service, service_handle_message))) {
    g_free(service);
    service = 0;
  }

  if (service) {
    if (dbus_bus_request_name(filter->connection, name, 0, &error) !=
        DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
    {
      dsme_log(LOG_DEBUG, "dbus_request_name(): %s\n", error.message);
      dbus_error_free(&error);
      g_free(service);
      service = 0;
      filter_delete(filter);
      filter = 0;
    }
  }

  if (service) {
    service->filter  = filter;
    service->name    = name;
    service->methods = dispatcher_list_new();
  }

  return service;
}
Filter *filter_gauss_blur_new(void)
{
  Filter *filter = filter_new(&filter_core_gauss);
  Meta *in, *out, *channel, *bitdepth, *color[3], *setting, *bound;
  Meta *ch_out[3];
  _Data *data = calloc(sizeof(_Data), 1);
  data->sigma = calloc(sizeof(float), 1);
  data->buf1 = malloc(BLURBUF);
  data->buf2 = malloc(BLURBUF);
  filter->fixme_outcount = 3;
  ea_push(filter->data, data);
  
  *data->sigma = 5.0;
  
  filter->mode_buffer = filter_mode_buffer_new();
  filter->mode_buffer->worker = &_worker;
  filter->mode_buffer->threadsafe = 1;
  filter->mode_buffer->area_calc = &_area_calc;
  filter->mode_buffer->data_new = &_gauss_data_new;
  
  bitdepth = meta_new_data(MT_BITDEPTH, filter, malloc(sizeof(int)));
  *(int*)(bitdepth->data) = BD_U8;
  bitdepth->replace = bitdepth;
  
  out = meta_new(MT_BUNDLE, filter);
  eina_array_push(filter->out, out);
  
  channel = meta_new_channel(filter, 1);
  color[0] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(color[0]->data) = CS_LAB_L;
  meta_attach(channel, color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[0] = channel;
  
  channel = meta_new_channel(filter, 2);
  color[1] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(color[1]->data) = CS_LAB_A;
  meta_attach(channel, color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[1] = channel;
  
  channel = meta_new_channel(filter, 3);
  color[2] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(color[2]->data) = CS_LAB_B;
  meta_attach(channel, color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[2] = channel;
  
  in = meta_new(MT_BUNDLE, filter);
  in->replace = out;
  eina_array_push(filter->in, in);
  
  channel = meta_new_channel(filter, 1);
  color[0]->replace = color[0];
  channel->replace = ch_out[0];
  meta_attach(channel, color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 2);
  color[1]->replace = color[1];
  channel->replace = ch_out[1];
  meta_attach(channel, color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 3);
  color[2]->replace = color[2];
  color[2]->replace = color[2];
  channel->replace = ch_out[2];
  meta_attach(channel, color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
    
  setting = meta_new_data(MT_FLOAT, filter, data->sigma);
  meta_name_set(setting, "sigma");
  eina_array_push(filter->settings, setting);
  
  bound = meta_new_data(MT_FLOAT, filter, malloc(sizeof(int)));
  *(float*)bound->data = 0;
  meta_name_set(bound, "PARENT_SETTING_MIN");
  meta_attach(setting, bound);
  
  bound = meta_new_data(MT_FLOAT, filter, malloc(sizeof(int)));
  *(float*)bound->data = MAX_SIGMA;
  meta_name_set(bound, "PARENT_SETTING_MAX");
  meta_attach(setting, bound);
  
  return filter;
}
Exemple #10
0
bool
audio_output_init(struct audio_output *ao, const struct config_param *param,
		  GError **error_r)
{
	const struct audio_output_plugin *plugin = NULL;
	GError *error = NULL;

	if (param) {
		const char *p;

		p = config_get_block_string(param, AUDIO_OUTPUT_TYPE, NULL);
		if (p == NULL) {
			g_set_error(error_r, audio_output_quark(), 0,
				    "Missing \"type\" configuration");
			return false;
		}

		plugin = audio_output_plugin_get(p);
		if (plugin == NULL) {
			g_set_error(error_r, audio_output_quark(), 0,
				    "No such audio output plugin: %s", p);
			return false;
		}

		ao->name = config_get_block_string(param, AUDIO_OUTPUT_NAME,
						   NULL);
		if (ao->name == NULL) {
			g_set_error(error_r, audio_output_quark(), 0,
				    "Missing \"name\" configuration");
			return false;
		}

		p = config_get_block_string(param, AUDIO_OUTPUT_FORMAT,
						 NULL);
		if (p != NULL) {
			bool success =
				audio_format_parse(&ao->config_audio_format,
						   p, true, error_r);
			if (!success)
				return false;
		} else
			audio_format_clear(&ao->config_audio_format);
	} else {
		g_warning("No \"%s\" defined in config file\n",
			  CONF_AUDIO_OUTPUT);

		plugin = audio_output_detect(error_r);
		if (plugin == NULL)
			return false;

		g_message("Successfully detected a %s audio device",
			  plugin->name);

		ao->name = "default detected output";

		audio_format_clear(&ao->config_audio_format);
	}

	ao->plugin = plugin;
	ao->always_on = config_get_block_bool(param, "always_on", false);
	ao->enabled = config_get_block_bool(param, "enabled", true);
	ao->really_enabled = false;
	ao->open = false;
	ao->pause = false;
	ao->fail_timer = NULL;

	pcm_buffer_init(&ao->cross_fade_buffer);

	/* set up the filter chain */

	ao->filter = filter_chain_new();
	assert(ao->filter != NULL);

	/* create the replay_gain filter */

	const char *replay_gain_handler =
		config_get_block_string(param, "replay_gain_handler",
					"software");

	if (strcmp(replay_gain_handler, "none") != 0) {
		ao->replay_gain_filter = filter_new(&replay_gain_filter_plugin,
						    param, NULL);
		assert(ao->replay_gain_filter != NULL);

		ao->replay_gain_serial = 0;

		ao->other_replay_gain_filter = filter_new(&replay_gain_filter_plugin,
							  param, NULL);
		assert(ao->other_replay_gain_filter != NULL);

		ao->other_replay_gain_serial = 0;
	} else {
		ao->replay_gain_filter = NULL;
		ao->other_replay_gain_filter = NULL;
	}

	/* create the normalization filter (if configured) */

	if (config_get_bool(CONF_VOLUME_NORMALIZATION, false)) {
		struct filter *normalize_filter =
			filter_new(&normalize_filter_plugin, NULL, NULL);
		assert(normalize_filter != NULL);

		filter_chain_append(ao->filter,
				    autoconvert_filter_new(normalize_filter));
	}

	filter_chain_parse(ao->filter,
	                   config_get_block_string(param, AUDIO_FILTERS, ""),
	                   &error
	);

	// It's not really fatal - Part of the filter chain has been set up already
	// and even an empty one will work (if only with unexpected behaviour)
	if (error != NULL) {
		g_warning("Failed to initialize filter chain for '%s': %s",
			  ao->name, error->message);
		g_error_free(error);
	}

	ao->thread = NULL;
	ao->command = AO_COMMAND_NONE;
	ao->mutex = g_mutex_new();
	ao->cond = g_cond_new();

	ao->data = ao_plugin_init(plugin,
				  &ao->config_audio_format,
				  param, error_r);
	if (ao->data == NULL)
		return false;

	ao->mixer = audio_output_load_mixer(ao->data, param,
					    plugin->mixer_plugin,
					    ao->filter, &error);
	if (ao->mixer == NULL && error != NULL) {
		g_warning("Failed to initialize hardware mixer for '%s': %s",
			  ao->name, error->message);
		g_error_free(error);
	}

	/* use the hardware mixer for replay gain? */

	if (strcmp(replay_gain_handler, "mixer") == 0) {
		if (ao->mixer != NULL)
			replay_gain_filter_set_mixer(ao->replay_gain_filter,
						     ao->mixer, 100);
		else
			g_warning("No such mixer for output '%s'", ao->name);
	} else if (strcmp(replay_gain_handler, "software") != 0 &&
		   ao->replay_gain_filter != NULL) {
		g_set_error(error_r, audio_output_quark(), 0,
			    "Invalid \"replay_gain_handler\" value");
		return false;
	}

	/* the "convert" filter must be the last one in the chain */

	ao->convert_filter = filter_new(&convert_filter_plugin, NULL, NULL);
	assert(ao->convert_filter != NULL);

	filter_chain_append(ao->filter, ao->convert_filter);

	/* done */

	return true;
}
Filter *filter_down_new(void)
{
  Filter *filter = filter_new(&filter_core_down);
  Meta *in, *out, *channel, *bitdepth, *setting, *bound;
  Meta *ch_out[3];
  _Data *data = calloc(sizeof(_Data), 1);
  filter->fixme_outcount = 3;
  ea_push(filter->data, data);
  
  filter->mode_buffer = filter_mode_buffer_new();
  filter->mode_buffer->worker = &_worker_linear;
  filter->mode_buffer->area_calc = &_area_calc;
  filter->setting_changed = &_setting_changed;
  
  bitdepth = meta_new_data(MT_BITDEPTH, filter, malloc(sizeof(int)));
  *(int*)(bitdepth->data) = BD_U8;
  bitdepth->replace = bitdepth;
  
  out = meta_new(MT_BUNDLE, filter);
  eina_array_push(filter->out, out);
  
  channel = meta_new_channel(filter, 1);
  data->color[0] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(data->color[0]->data) = CS_LAB_L;
  meta_attach(channel, data->color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[0] = channel;
  
  channel = meta_new_channel(filter, 2);
  data->color[1] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(data->color[1]->data) = CS_LAB_A;
  meta_attach(channel, data->color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[1] = channel;
  
  channel = meta_new_channel(filter, 3);
  data->color[2] = meta_new_data(MT_COLOR, filter, malloc(sizeof(int)));
  *(int*)(data->color[2]->data) = CS_LAB_B;
  meta_attach(channel, data->color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(out, channel);
  ch_out[2] = channel;
  
  in = meta_new(MT_BUNDLE, filter);
  in->replace = out;
  eina_array_push(filter->in, in);
  
  channel = meta_new_channel(filter, 1);
  data->color[0]->replace = data->color[0];
  channel->replace = ch_out[0];
  meta_attach(channel, data->color[0]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 2);
  data->color[1]->replace = data->color[1];
  channel->replace = ch_out[1];
  meta_attach(channel, data->color[1]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
  
  channel = meta_new_channel(filter, 3);
  data->color[2]->replace = data->color[2];
  channel->replace = ch_out[2];
  meta_attach(channel, data->color[2]);
  meta_attach(channel, bitdepth);
  meta_attach(in, channel);
    
  setting = meta_new_data(MT_INT, filter, &data->colorspace);
  meta_name_set(setting, "colorspace");
  eina_array_push(filter->settings, setting);
  
  bound = meta_new_data(MT_INT, filter, malloc(sizeof(int)));
  *(int*)bound->data = 0;
  meta_name_set(bound, "PARENT_SETTING_MIN");
  meta_attach(setting, bound);
  
  bound = meta_new_data(MT_INT, filter, malloc(sizeof(int)));
  *(int*)bound->data = 1;
  meta_name_set(bound, "PARENT_SETTING_MAX");
  meta_attach(setting, bound);
  
  return filter;
}