コード例 #1
0
ファイル: plugin.c プロジェクト: aklein53/neard
static bool check_plugin(struct near_plugin_desc *desc,
				char **patterns, char **excludes)
{
	if (excludes) {
		for (; *excludes; excludes++)
			if (g_pattern_match_simple(*excludes, desc->name))
				break;
		if (*excludes) {
			near_info("Excluding %s", desc->description);
			return false;
		}
	}

	if (patterns) {
		for (; *patterns; patterns++)
			if (g_pattern_match_simple(*patterns, desc->name))
				break;
		if (!*patterns) {
			near_info("Ignoring %s", desc->description);
			return false;
		}
	}

	return true;
}
コード例 #2
0
ファイル: device.c プロジェクト: aldebaran/connman-stable
connman_bool_t __connman_device_isfiltered(const char *devname)
{
	char **pattern;

	if (device_filter == NULL)
		goto nodevice;

	for (pattern = device_filter; *pattern; pattern++) {
		if (g_pattern_match_simple(*pattern, devname) == FALSE) {
			DBG("ignoring device %s (match)", devname);
			return TRUE;
		}
	}

nodevice:
	if (g_pattern_match_simple("dummy*", devname) == TRUE) {
		DBG("ignoring dummy networking devices");
		return TRUE;
	}

	if (nodevice_filter == NULL)
		return FALSE;

	for (pattern = nodevice_filter; *pattern; pattern++) {
		if (g_pattern_match_simple(*pattern, devname) == TRUE) {
			DBG("ignoring device %s (no match)", devname);
			return TRUE;
		}
	}

	return FALSE;
}
コード例 #3
0
ファイル: plugin.c プロジェクト: 593141477/bluez-rda
static gboolean enable_plugin(const char *name, char **conf_disable,
					char **cli_enable, char **cli_disable)
{
	if (conf_disable) {
		for (; *conf_disable; conf_disable++)
			if (g_pattern_match_simple(*conf_disable, name))
				break;
		if (*conf_disable) {
			info("Excluding (conf) %s", name);
			return FALSE;
		}
	}

	if (cli_disable) {
		for (; *cli_disable; cli_disable++)
			if (g_pattern_match_simple(*cli_disable, name))
				break;
		if (*cli_disable) {
			info("Excluding (cli) %s", name);
			return FALSE;
		}
	}

	if (cli_enable) {
		for (; *cli_enable; cli_enable++)
			if (g_pattern_match_simple(*cli_enable, name))
				break;
		if (!*cli_enable) {
			info("Ignoring (cli) %s", name);
			return FALSE;
		}
	}

	return TRUE;
}
コード例 #4
0
ファイル: plugin.c プロジェクト: AndriusA/ofono
static gboolean check_plugin(struct ofono_plugin_desc *desc,
				char **patterns, char **excludes)
{
	if (excludes) {
		for (; *excludes; excludes++)
			if (g_pattern_match_simple(*excludes, desc->name))
				break;
		if (*excludes) {
			ofono_info("Excluding %s", desc->description);
			return FALSE;
		}
	}

	if (patterns) {
		for (; *patterns; patterns++)
			if (g_pattern_match_simple(*patterns, desc->name))
				break;
		if (*patterns == NULL) {
			ofono_info("Ignoring %s", desc->description);
			return FALSE;
		}
	}

	return TRUE;
}
コード例 #5
0
ファイル: device.c プロジェクト: drgogeta86/connman
bool __connman_device_isfiltered(const char *devname)
{
	char **pattern;
	char **blacklisted_interfaces;
	bool match;

	if (!device_filter)
		goto nodevice;

	for (pattern = device_filter, match = false; *pattern; pattern++) {
		if (g_pattern_match_simple(*pattern, devname)) {
			match = true;
			break;
		}
	}

	if (!match) {
//		DBG("ignoring device %s (match)", devname);
		return true;
	}

nodevice:
	if (g_pattern_match_simple("dummy*", devname)) {
//		DBG("ignoring dummy networking devices");
		return true;
	}

	if (!nodevice_filter)
		goto list;

	for (pattern = nodevice_filter; *pattern; pattern++) {
		if (g_pattern_match_simple(*pattern, devname)) {
//			DBG("ignoring device %s (no match)", devname);
			return true;
		}
	}

list:
	blacklisted_interfaces =
		connman_setting_get_string_list("NetworkInterfaceBlacklist");
	if (!blacklisted_interfaces)
		return false;

	for (pattern = blacklisted_interfaces; *pattern; pattern++) {
		if (g_str_has_prefix(devname, *pattern)) {
//			DBG("ignoring device %s (blacklist)", devname);
			return true;
		}
	}

	return false;
}
コード例 #6
0
static const char *
guess_upnp_class_for_mime_type (const char *mime_type)
{
        const char *upnp_class = NULL;

        if (g_pattern_match_simple ("audio/*", mime_type)) {
                upnp_class = "object.item.audioItem.musicTrack";
        } else if (g_pattern_match_simple ("video/*", mime_type)) {
                upnp_class = "object.item.videoItem";
        } else if (g_pattern_match_simple ("image/*", mime_type)) {
                upnp_class = "object.item.imageItem";
        }

        return upnp_class;
}
コード例 #7
0
ファイル: proxysslhostiface.c プロジェクト: kkovaacs/zorp
static gboolean
z_proxy_ssl_host_iface_check_wildcard(ZProxy *s, const gchar *host_name, const gchar *pattern)
{
  gchar **pattern_parts, **hostname_parts;
  gboolean success = FALSE;
  gint i;

  z_proxy_log(s, CORE_DEBUG, 6, "Checking certificate subject; host='%s', pattern='%s'", host_name, pattern);
  pattern_parts = g_strsplit(pattern, ".", 0);
  hostname_parts = g_strsplit(host_name, ".", 0);
  for (i = 0; pattern_parts[i]; i++)
    {
      if (!hostname_parts[i])
        {
          /* number of dot separated entries is not the same in the hostname and the pattern spec */
          goto exit;
        }
      if (!g_pattern_match_simple(pattern_parts[i], hostname_parts[i]))
        goto exit;
    }
  if (!hostname_parts[i])       /* if hostname_parts doesn't continue beyond pattern_parts */
    success = TRUE;
 exit:
  g_strfreev(pattern_parts);
  g_strfreev(hostname_parts);
  if (!success)
    {
      z_proxy_log(s, CORE_VIOLATION, 2, "Certificate subject does not match; host='%s', pattern='%s'",
                  host_name, pattern);
    }
  return success;
}
コード例 #8
0
ファイル: grouplistdialog.c プロジェクト: eworm-de/claws-mail
static GtkCMCTreeNode *grouplist_create_parent(const gchar *name,
					     const gchar *pattern)
{
	GtkCMCTreeNode *parent;
	GtkCMCTreeNode *node;
	gchar *cols[3];
	gchar *parent_name;

	if (*name == '\0') return NULL;
	node = grouplist_hash_get_branch_node(name);
	if (node != NULL) return node;

	cols[0] = (gchar *)name;
	cols[1] = cols[2] = "";

	parent_name = grouplist_get_parent_name(name);
	parent = grouplist_create_parent(parent_name, pattern);

	node = parent ? GTK_CMCTREE_ROW(parent)->children
		: GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
	node = gtk_sctree_insert_node(GTK_CMCTREE(ctree), parent, node,
				     cols, 0, NULL, NULL,
				     FALSE, FALSE);
	if (parent && g_pattern_match_simple(pattern, parent_name) == FALSE)
		gtk_cmctree_expand(GTK_CMCTREE(ctree), parent);
	gtk_cmctree_node_set_selectable(GTK_CMCTREE(ctree), node, FALSE);

	grouplist_hash_set_branch_node(name, node);

	g_free(parent_name);

	return node;
}
コード例 #9
0
static void
gst_validate_pipeline_monitor_create_scenarios (GstValidateBinMonitor * monitor)
{
  /* scenarios currently only make sense for pipelines */
  const gchar *scenario_name;

  if ((scenario_name = g_getenv ("GST_VALIDATE_SCENARIO"))) {
    gchar **scenario_v = g_strsplit (scenario_name, "->", 2);

    if (scenario_v[1] && GST_VALIDATE_MONITOR_GET_OBJECT (monitor)) {
      if (!g_pattern_match_simple (scenario_v[1],
              GST_OBJECT_NAME (GST_VALIDATE_MONITOR_GET_OBJECT (monitor)))) {
        GST_INFO_OBJECT (monitor, "Not attaching to pipeline %" GST_PTR_FORMAT
            " as not matching pattern %s",
            GST_VALIDATE_MONITOR_GET_OBJECT (monitor), scenario_v[1]);

        g_strfreev (scenario_v);
        return;
      }
    }
    monitor->scenario =
        gst_validate_scenario_factory_create (GST_VALIDATE_MONITOR_GET_RUNNER
        (monitor),
        GST_ELEMENT_CAST (GST_VALIDATE_MONITOR_GET_OBJECT (monitor)),
        scenario_v[0]);
    g_strfreev (scenario_v);
  }
}
コード例 #10
0
ファイル: test-checks.c プロジェクト: djmitche/libzcloud
gboolean
gerror_is_set(
    GError **error,
    const gchar *expected_message_glob,
    gint expected_code,
    const gchar *msg)
{
    gboolean success = TRUE;
    if (!error || !*error)
        return fail(msg);

    if (expected_message_glob) {
        if (!(*error)->message) {
            diag(" error is non-NULL but has message = NULL");
            success = FALSE;
        } else if (!g_pattern_match_simple(expected_message_glob, (*error)->message)) {
            diag(" message '%s' does not match pattern", (*error)->message);
            success = FALSE;
        }
    }

    if (expected_code != -1) {
        if (expected_code != (*error)->code) {
            diag(" got code %d; expected %d", (*error)->code, expected_code);
            success = FALSE;
        }
    }

    g_clear_error(error);
    return ok(success, msg);
}
コード例 #11
0
ファイル: tlscontext.c プロジェクト: batk0/syslog-ng
int
tls_session_verify_dn(X509_STORE_CTX *ctx)
{
  SSL *ssl = X509_STORE_CTX_get_app_data(ctx);
  TLSSession *self = SSL_get_app_data(ssl);
  gboolean match = FALSE;
  GList *current_dn = self->ctx->trusted_dn_list;
  X509 *cert = X509_STORE_CTX_get_current_cert(ctx);
  GString *dn;

  if (!current_dn || !cert)
    return TRUE;

  dn = g_string_sized_new(128);
  tls_x509_format_dn(X509_get_subject_name(cert), dn);

  do
    {
      if (g_pattern_match_simple((const gchar *) current_dn->data, dn->str))
        {
          match = TRUE;
          break;
        }
    }
  while ((current_dn = g_list_next(current_dn)) != NULL);
  return match;
}
コード例 #12
0
ファイル: pdbtool.c プロジェクト: Achint08/syslog-ng
static gboolean
pdbtool_merge_dir(const gchar *dir, gboolean recursive, GString *merged)
{
  GDir *pdb_dir;
  gboolean ok = TRUE;
  GError *error = NULL;
  const gchar *filename;

  if ((pdb_dir = g_dir_open(dir, 0, &error)) == NULL)
    {
      fprintf(stderr, "Error opening directory %s, error='%s'\n", merge_dir, error ? error->message : "Unknown error");
      g_clear_error(&error);
      return FALSE;
    }

  while ((filename = g_dir_read_name(pdb_dir)) != NULL && ok)
    {
      gchar *full_name = g_build_filename(dir, filename, NULL);

      if (recursive && is_file_directory(full_name))
        {
          ok = pdbtool_merge_dir(full_name, recursive, merged);
        }
      else if (is_file_regular(full_name) && (!merge_glob || g_pattern_match_simple(merge_glob, filename)))
        {
          ok = pdbtool_merge_file(full_name, merged);
        }
      g_free(full_name);
    }
  g_dir_close(pdb_dir);
  return TRUE;
}
コード例 #13
0
ファイル: player.c プロジェクト: johang/avmr
static gboolean
lookup_command_and_protocol(gchar *mimetype, gchar **command,
		gchar **protocol) {
	gsize number_of_groups;

	// Get all mime types in the config file
	gchar **groups = g_key_file_get_groups(keys, &number_of_groups);

	guint i = 0;

	for (; i < number_of_groups; i++) {
		if (g_pattern_match_simple(groups[i], mimetype)) {
			*command = g_key_file_get_string(keys, groups[i],
				"command", NULL);
			*protocol = g_key_file_get_string(keys, groups[i],
				"protocol", NULL);

			// Abort now since we found a match
			break;
		}
	}

	// Free the list of mime types
	g_strfreev(groups);

	return i != number_of_groups;
}
コード例 #14
0
ファイル: debug-helpers.c プロジェクト: Profit0004/mono
/*
 * namespace and class are supposed to match already if this function is used.
 */
gboolean
mono_method_desc_match (MonoMethodDesc *desc, MonoMethod *method)
{
	char *sig;
	gboolean name_match;

	name_match = strcmp (desc->name, method->name) == 0;
#ifndef _EGLIB_MAJOR
	if (!name_match && desc->name_glob)
		name_match = g_pattern_match_simple (desc->name, method->name);
#endif
	if (!name_match)
		return FALSE;
	if (!desc->args)
		return TRUE;
	if (desc->num_args != mono_method_signature (method)->param_count)
		return FALSE;
	sig = mono_signature_get_desc (mono_method_signature (method), desc->include_namespace);
	if (strcmp (sig, desc->args)) {
		g_free (sig);
		return FALSE;
	}
	g_free (sig);
	return TRUE;
}
コード例 #15
0
ファイル: gtktestutils.c プロジェクト: grubersjoe/adwaita
/**
 * gtk_test_find_label:
 * @widget:        Valid label or container widget.
 * @label_pattern: Shell-glob pattern to match a label string.
 *
 * This function will search @widget and all its descendants for a GtkLabel
 * widget with a text string matching @label_pattern.
 * The @label_pattern may contain asterisks “*” and question marks “?” as
 * placeholders, g_pattern_match() is used for the matching.
 * Note that locales other than "C“ tend to alter (translate” label strings,
 * so this function is genrally only useful in test programs with
 * predetermined locales, see gtk_test_init() for more details.
 *
 * Returns: (transfer none): a GtkLabel widget if any is found.
 *
 * Since: 2.14
 **/
GtkWidget*
gtk_test_find_label (GtkWidget    *widget,
                     const gchar  *label_pattern)
{
  GtkWidget *label = NULL;

  if (GTK_IS_LABEL (widget))
    {
      const gchar *text = gtk_label_get_text (GTK_LABEL (widget));
      if (g_pattern_match_simple (label_pattern, text))
        return widget;
    }

  if (GTK_IS_CONTAINER (widget))
    {
      GList *node, *list;

      list = gtk_container_get_children (GTK_CONTAINER (widget));
      for (node = list; node; node = node->next)
        {
          label = gtk_test_find_label (node->data, label_pattern);
          if (label)
            break;
        }
      g_list_free (list);
    }
  return label;
}
コード例 #16
0
ファイル: tlscontext.c プロジェクト: batk0/syslog-ng
static gboolean
tls_wildcard_match(const gchar *host_name, const gchar *pattern)
{
  gchar **pattern_parts, **hostname_parts;
  gboolean success = FALSE;
  gchar *lower_pattern = NULL;
  gchar *lower_hostname = NULL;
  gint i;

  pattern_parts = g_strsplit(pattern, ".", 0);
  hostname_parts = g_strsplit(host_name, ".", 0);
  for (i = 0; pattern_parts[i]; i++)
    {
      if (!hostname_parts[i])
        {
          /* number of dot separated entries is not the same in the hostname and the pattern spec */
          goto exit;
        }

      lower_pattern = g_ascii_strdown(pattern_parts[i],-1);
      lower_hostname = g_ascii_strdown(hostname_parts[i],-1);

      if (!g_pattern_match_simple(lower_pattern, lower_hostname))
        goto exit;
    }
  success = TRUE;
 exit:
  g_free(lower_pattern);
  g_free(lower_hostname);
  g_strfreev(pattern_parts);
  g_strfreev(hostname_parts);
  return success;
}
コード例 #17
0
ファイル: list.c プロジェクト: alistair23/qemu
static bool qauthz_list_is_allowed(QAuthZ *authz,
                                   const char *identity,
                                   Error **errp)
{
    QAuthZList *lauthz = QAUTHZ_LIST(authz);
    QAuthZListRuleList *rules = lauthz->rules;

    while (rules) {
        QAuthZListRule *rule = rules->value;
        QAuthZListFormat format = rule->has_format ? rule->format :
            QAUTHZ_LIST_FORMAT_EXACT;

        trace_qauthz_list_check_rule(authz, rule->match, identity,
                                     format, rule->policy);
        switch (format) {
        case QAUTHZ_LIST_FORMAT_EXACT:
            if (g_str_equal(rule->match, identity)) {
                return rule->policy == QAUTHZ_LIST_POLICY_ALLOW;
            }
            break;
        case QAUTHZ_LIST_FORMAT_GLOB:
            if (g_pattern_match_simple(rule->match, identity)) {
                return rule->policy == QAUTHZ_LIST_POLICY_ALLOW;
            }
            break;
        default:
            g_warn_if_reached();
            return false;
        }
        rules = rules->next;
    }

    trace_qauthz_list_default_policy(authz, identity, lauthz->policy);
    return lauthz->policy == QAUTHZ_LIST_POLICY_ALLOW;
}
コード例 #18
0
ファイル: debug-helpers.c プロジェクト: Profit0004/mono
static gboolean
match_class (MonoMethodDesc *desc, int pos, MonoClass *klass)
{
	const char *p;

	if (desc->klass_glob && !strcmp (desc->klass, "*"))
		return TRUE;
#ifndef _EGLIB_MAJOR
	if (desc->klass_glob && g_pattern_match_simple (desc->klass, klass->name))
		return TRUE;
#endif
	p = my_strrchr (desc->klass, '/', &pos);
	if (!p) {
		if (strncmp (desc->klass, klass->name, pos))
			return FALSE;
		if (desc->name_space && strcmp (desc->name_space, klass->name_space))
			return FALSE;
		return TRUE;
	}

	if (strcmp (p+1, klass->name))
		return FALSE;
	if (!klass->nested_in)
		return FALSE;

	return match_class (desc, pos, klass->nested_in);
}
コード例 #19
0
static gboolean
gst_validate_runner_should_monitor (GstValidateRunner * self,
    GstElement * element)
{
  gint i;
  GstValidateMonitor *monitor;

  if (!GST_IS_PIPELINE (element)) {
    return FALSE;
  }

  if (self->priv->user_created)
    return FALSE;

  if (!self->priv->pipeline_names_strv)
    return TRUE;

  monitor = gst_validate_get_monitor (G_OBJECT (element));

  if (monitor) {
    GST_ERROR_OBJECT (self, "Pipeline %" GST_PTR_FORMAT " is already"
        " monitored by %" GST_PTR_FORMAT " using runner: %" GST_PTR_FORMAT
        " NOT monitoring again.",
        element, monitor,
        gst_validate_reporter_get_runner (GST_VALIDATE_REPORTER (monitor)));
  }

  for (i = 0; self->priv->pipeline_names_strv[i]; i++) {
    if (g_pattern_match_simple (self->priv->pipeline_names_strv[i],
            GST_OBJECT_NAME (element)))
      return TRUE;
  }

  return FALSE;
}
コード例 #20
0
ファイル: plugin.c プロジェクト: wenhann/chromiumos
static gboolean check_plugin(struct connman_plugin_desc *desc,
				const char *pattern, const char *exclude)
{
	if (exclude != NULL &&
			g_pattern_match_simple(exclude, desc->name) == TRUE) {
		connman_info("Excluding %s", desc->description);
		return FALSE;
	}

	if (pattern != NULL &&
			g_pattern_match_simple(pattern, desc->name) == FALSE) {
		connman_info("Ignoring %s", desc->description);
		return FALSE;
	}

	return TRUE;
}
コード例 #21
0
ファイル: device.c プロジェクト: roland-wilhelm/connman
connman_bool_t __connman_device_isfiltered(const char *devname)
{
	char **pattern;
	char **blacklisted_interfaces;

	if (device_filter == NULL)
		goto nodevice;

	for (pattern = device_filter; *pattern; pattern++) {
		if (g_pattern_match_simple(*pattern, devname) == FALSE) {
			DBG("ignoring device %s (match)", devname);
			return TRUE;
		}
	}

nodevice:
	if (g_pattern_match_simple("dummy*", devname) == TRUE) {
		DBG("ignoring dummy networking devices");
		return TRUE;
	}

	if (nodevice_filter == NULL)
		goto list;

	for (pattern = nodevice_filter; *pattern; pattern++) {
		if (g_pattern_match_simple(*pattern, devname) == TRUE) {
			DBG("ignoring device %s (no match)", devname);
			return TRUE;
		}
	}

list:
	blacklisted_interfaces =
		connman_setting_get_string_list("NetworkInterfaceBlacklist");
	if (blacklisted_interfaces == NULL)
		return FALSE;

	for (pattern = blacklisted_interfaces; *pattern; pattern++) {
		if (g_str_has_prefix(devname, *pattern) == TRUE) {
			DBG("ignoring device %s (blacklist)", devname);
			return TRUE;
		}
	}

	return FALSE;
}
コード例 #22
0
ファイル: log.c プロジェクト: Fiend90/obex
static gboolean is_enabled(struct obex_debug_desc *desc)
{
	int i;

	if (enabled == NULL)
		return 0;

	for (i = 0; enabled[i] != NULL; i++) {
		if (desc->name != NULL && g_pattern_match_simple(enabled[i],
							desc->name) == TRUE)
			return 1;
		if (desc->file != NULL && g_pattern_match_simple(enabled[i],
							desc->file) == TRUE)
			return 1;
	}

	return 0;
}
コード例 #23
0
ファイル: log.c プロジェクト: intgr/connman
static connman_bool_t is_enabled(struct connman_debug_desc *desc)
{
	int i;

	if (enabled == NULL)
		return FALSE;

	for (i = 0; enabled[i] != NULL; i++) {
		if (desc->name != NULL && g_pattern_match_simple(enabled[i],
							desc->name) == TRUE)
			return TRUE;
		if (desc->file != NULL && g_pattern_match_simple(enabled[i],
							desc->file) == TRUE)
			return TRUE;
	}

	return FALSE;
}
コード例 #24
0
ファイル: log.c プロジェクト: rzr/connman
static bool is_enabled(struct connman_debug_desc *desc)
{
	int i;

	if (!enabled)
		return false;

	for (i = 0; enabled[i]; i++) {
		if (desc->name && g_pattern_match_simple(enabled[i],
							desc->name))
			return true;
		if (desc->file && g_pattern_match_simple(enabled[i],
							desc->file))
			return true;
	}

	return false;
}
コード例 #25
0
ファイル: cockpittest.c プロジェクト: pdonlon/cockpit
static void
expected_message_handler (const gchar *log_domain,
                          GLogLevelFlags log_level,
                          const gchar *message,
                          gpointer user_data)
{
  gint level = log_level & G_LOG_LEVEL_MASK;
  ExpectedMessage *expected = NULL;
  gchar *expected_message;
  gboolean skip = FALSE;

  G_LOCK (expected);

  if (level && expected_messages &&
      (level & G_LOG_LEVEL_DEBUG) == 0)
    {
      expected = expected_messages->data;

      if (log_level & G_LOG_FLAG_FATAL)
        {
          ignore_fatal_count = 1;

          /* This handler is reset for each test, so set it right before we need it */
          g_test_log_set_fatal_handler (expected_fatal_handler, NULL);
        }

      if (g_strcmp0 (expected->log_domain, log_domain) == 0 &&
          ((log_level & expected->log_level) == expected->log_level) &&
          g_pattern_match_simple (expected->pattern, message))
        {
          expected_messages = g_slist_delete_link (expected_messages,
                                                   expected_messages);
          g_free (expected->log_domain);
          g_free (expected->pattern);
          g_free (expected);
          skip = TRUE;
        }
    }

  G_UNLOCK (expected);

  if (skip)
    return;

  gtest_default_log_handler (log_domain, log_level, message, NULL);

  if (expected)
    {
      expected_message = g_strdup_printf ("Did not see expected %s-%s: %s",
                                          expected->log_domain,
                                          calc_prefix (expected->log_level),
                                          expected->pattern);
      g_assertion_message (expected->log_domain, expected->file, expected->line,
                           expected->func, expected_message);
      g_free (expected_message);
    }
}
コード例 #26
0
osync_bool osync_plugin_env_load(OSyncPluginEnv *env, const char *path, OSyncError **error)
{
	osync_bool must_exist = TRUE;
	GDir *dir = NULL;
	GError *gerror = NULL;
	char *filename = NULL;
	const gchar *de = NULL;
	
	osync_trace(TRACE_ENTRY, "%s(%p, %s, %p)", __func__, env, __NULLSTR(path), error);
	
	if (!path) {
		path = OPENSYNC_PLUGINDIR;
		must_exist = FALSE;
	}
	
	//Load all available shared libraries (plugins)
	if (!g_file_test(path, G_FILE_TEST_IS_DIR)) {
		if (must_exist) {
			osync_error_set(error, OSYNC_ERROR_GENERIC, "Path is not loadable");
			goto error;
		} else {
			osync_trace(TRACE_EXIT, "%s: Directory %s does not exist (non-fatal)", __func__, path);
			return TRUE;
		}
	}
	
	dir = g_dir_open(path, 0, &gerror);
	if (!dir) {
		osync_error_set(error, OSYNC_ERROR_IO_ERROR, "Unable to open directory %s: %s", path, gerror->message);
		g_error_free(gerror);
		goto error;
	}
	
	while ((de = g_dir_read_name(dir))) {
		filename = g_strdup_printf ("%s%c%s", path, G_DIR_SEPARATOR, de);
		
		if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR) || !g_pattern_match_simple("*."G_MODULE_SUFFIX, filename)) {
			g_free(filename);
			continue;
		}
		
		if (!osync_plugin_env_load_module(env, filename, error)) {
			osync_trace(TRACE_ERROR, "Unable to load module: %s", osync_error_print(error));
		}
		
		g_free(filename);
	}
	
	g_dir_close(dir);
	
	osync_trace(TRACE_EXIT, "%s", __func__);
	return TRUE;

error:
	osync_trace(TRACE_EXIT_ERROR, "%s: %s", __func__, osync_error_print(error));
	return FALSE;
}
コード例 #27
0
int
_xdg_glob_hash_lookup_file_name (XdgGlobHash * glob_hash,
    const char *file_name, const char *mime_types[], int n_mime_types)
{
  XdgGlobList *list;
  int i, n;
  MimeWeight mimes[10];
  int n_mimes = 10;
  xdg_unichar_t *ucs4;
  int len;

  /* First, check the literals */

  assert (file_name != NULL && n_mime_types > 0);

  n = 0;

  for (list = glob_hash->literal_list; list; list = list->next) {
    if (strcmp ((const char *) list->data, file_name) == 0) {
      mime_types[0] = list->mime_type;
      return 1;
    }
  }

  ucs4 = _xdg_convert_to_ucs4 (file_name, &len);
  n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, ucs4, len,
      FALSE, mimes, n_mimes);
  if (n == 0)
    n = _xdg_glob_hash_node_lookup_file_name (glob_hash->simple_node, ucs4, len,
        TRUE, mimes, n_mimes);
  free (ucs4);

  /* FIXME: Not UTF-8 safe */
  if (n == 0) {
    for (list = glob_hash->full_list; list && n < n_mime_types;
        list = list->next) {
      if (g_pattern_match_simple ((const char *) list->data, file_name) != 0) {
        mimes[n].mime = list->mime_type;
        mimes[n].weight = list->weight;
        n++;
      }
    }
  }

  qsort (mimes, n, sizeof (MimeWeight), compare_mime_weight);

  if (n_mime_types < n)
    n = n_mime_types;

  for (i = 0; i < n; i++)
    mime_types[i] = mimes[i].mime;

  return n;
}
コード例 #28
0
ファイル: mega-filesystem.c プロジェクト: 0day1day/megatools
/**
 * mega_filesystem_glob:
 * @filesystem: a #MegaFilesystem
 * @glob: A glob pattern
 *
 * Get list of nodes matching glob pattern.
 *
 * Returns: (transfer full) (element-type MegaNode): List of nodes.
 */
GSList* mega_filesystem_glob(MegaFilesystem* filesystem, const gchar* glob)
{
  gchar** glob_parts;
  gchar** next_pattern;

  g_return_val_if_fail(MEGA_IS_FILESYSTEM(filesystem), NULL);
  g_return_val_if_fail(glob != NULL, NULL);

  // skip relative glob paterns
  next_pattern = glob_parts = remotepath_split(glob);
  if (glob_parts == NULL)
    return NULL;

  // create list of root nodes filtered by pattern
  GSList *full_list = NULL, *filtered_list = NULL, *iter;
  while (*next_pattern)  
  {
    // create list of nodes for filtering
    g_slist_free_full(full_list, g_object_unref);
    if (next_pattern == glob_parts)
    {
      full_list = mega_filesystem_get_root_nodes(filesystem);
    }
    else
    {
      full_list = NULL;
      for (iter = filtered_list; iter; iter = iter->next)
      {
        MegaNode* node = iter->data;

        full_list = g_slist_concat(full_list, mega_node_get_children(node));
      }
    }

    // clear fitlered list
    g_slist_free_full(filtered_list, g_object_unref);
    filtered_list = NULL;

    for (iter = full_list; iter; iter = iter->next)
    {
      MegaNode* node = iter->data;

      if (g_pattern_match_simple(*next_pattern, mega_node_get_name(node)))
        filtered_list = g_slist_prepend(filtered_list, g_object_ref(node));
    }

    next_pattern++;
  }

  g_slist_free_full(full_list, g_object_unref);
  g_strfreev(glob_parts);

  return g_slist_reverse(filtered_list);
}
コード例 #29
0
ファイル: grouplistdialog.c プロジェクト: eworm-de/claws-mail
static GtkCMCTreeNode *grouplist_create_branch(NewsGroupInfo *ginfo,
					     const gchar *pattern)
{
	GtkCMCTreeNode *node;
	GtkCMCTreeNode *parent;
	gchar *name = (gchar *)ginfo->name;
	gchar *parent_name;
	gchar *count_str;
	gchar *cols[3];
	gint count;

	count = ginfo->last - ginfo->first;
	if (count < 0)
		count = 0;
	count_str = itos(count);

	cols[0] = ginfo->name;
	cols[1] = count_str;
	if (ginfo->type == 'y')
		cols[2] = "";
	else if (ginfo->type == 'm')
		cols[2] = _("moderated");
	else if (ginfo->type == 'n')
		cols[2] = _("readonly");
	else
		cols[2] = _("unknown");

	parent_name = grouplist_get_parent_name(name);
	parent = grouplist_create_parent(parent_name, pattern);
	node = grouplist_hash_get_branch_node(name);
	if (node) {
		gtk_cmctree_set_node_info(GTK_CMCTREE(ctree), node, cols[0], 0,
					NULL, NULL, FALSE, FALSE);
		gtk_cmctree_node_set_text(GTK_CMCTREE(ctree), node, 1, cols[1]);
		gtk_cmctree_node_set_text(GTK_CMCTREE(ctree), node, 2, cols[2]);
	} else {
		node = parent ? GTK_CMCTREE_ROW(parent)->children
			: GTK_CMCTREE_NODE(GTK_CMCLIST(ctree)->row_list);
		node = gtk_sctree_insert_node(GTK_CMCTREE(ctree), parent, node,
					     cols, 0, NULL, NULL,
					     TRUE, FALSE);
		if (parent &&
		    g_pattern_match_simple(pattern, parent_name) == FALSE)
			gtk_cmctree_expand(GTK_CMCTREE(ctree), parent);
	}
	gtk_cmctree_node_set_selectable(GTK_CMCTREE(ctree), node, TRUE);
	if (node)
		gtk_cmctree_node_set_row_data(GTK_CMCTREE(ctree), node, ginfo);

	g_free(parent_name);

	return node;
}
コード例 #30
0
ファイル: gui-library-window.c プロジェクト: thequux/pcb
/*! \brief Determines visibility of items of the library treeview.
 *  \par Function Description
 *  This is the function used to filter entries of the footprint
 *  selection tree.
 *
 *  \param [in] model The current selection in the treeview.
 *  \param [in] iter  An iterator on a footprint or folder in the tree.
 *  \param [in] data  The library dialog.
 *  \returns TRUE if item should be visible, FALSE otherwise.
 */
static gboolean
lib_model_filter_visible_func (GtkTreeModel * model,
			       GtkTreeIter * iter, gpointer data)
{
  GhidLibraryWindow *library_window = (GhidLibraryWindow *) data;
  const gchar *compname;
  gchar *compname_upper, *text_upper, *pattern;
  const gchar *text;
  gboolean ret;

  g_assert (GHID_IS_LIBRARY_WINDOW (data));

  text = gtk_entry_get_text (library_window->entry_filter);
  if (g_ascii_strcasecmp (text, "") == 0)
    {
      return TRUE;
    }

  /* If this is a source, only display it if it has children that
   * match */
  if (gtk_tree_model_iter_has_child (model, iter))
    {
      GtkTreeIter iter2;

      gtk_tree_model_iter_children (model, &iter2, iter);
      ret = FALSE;
      do
	{
	  if (lib_model_filter_visible_func (model, &iter2, data))
	    {
	      ret = TRUE;
	      break;
	    }
	}
      while (gtk_tree_model_iter_next (model, &iter2));
    }
  else
    {
      gtk_tree_model_get (model, iter, MENU_NAME_COLUMN, &compname, -1);
      /* Do a case insensitive comparison, converting the strings
         to uppercase */
      compname_upper = g_ascii_strup (compname, -1);
      text_upper = g_ascii_strup (text, -1);
      pattern = g_strconcat ("*", text_upper, "*", NULL);
      ret = g_pattern_match_simple (pattern, compname_upper);
      g_free (compname_upper);
      g_free (text_upper);
      g_free (pattern);
    }

  return ret;
}