Example #1
0
/**
 * as_pool_get_components_by_kind:
 * @pool: An instance of #AsDatabase.
 * @kind: An #AsComponentKind.
 *
 * Return a list of all components in the pool which are of a certain kind.
 *
 * Returns: (transfer container) (element-type AsComponent): an array of #AsComponent objects which have been found.
 */
GPtrArray*
as_pool_get_components_by_kind (AsPool *pool, AsComponentKind kind)
{
	AsPoolPrivate *priv = GET_PRIVATE (pool);
	GHashTableIter iter;
	gpointer value;
	GPtrArray *results;

	/* sanity check */
	g_return_val_if_fail ((kind < AS_COMPONENT_KIND_LAST) && (kind > AS_COMPONENT_KIND_UNKNOWN), NULL);

	results = g_ptr_array_new_with_free_func (g_object_unref);
	g_hash_table_iter_init (&iter, priv->cpt_table);
	while (g_hash_table_iter_next (&iter, NULL, &value)) {
		AsComponent *cpt = AS_COMPONENT (value);

		if (as_component_get_kind (cpt) == kind)
				g_ptr_array_add (results, g_object_ref (cpt));
	}

	return results;
}
Example #2
0
static void facq_display_matrix_constructed(GObject *self)
{
	FacqDisplayMatrix *mat = FACQ_DISPLAY_MATRIX(self);
	GtkWidget *table = NULL, *display = NULL, *scrolled_window = NULL;
	FacqDisplay *dis = NULL;
	guint i = 0, j = 0;

	table = gtk_table_new(mat->priv->rows,
			      mat->priv->cols,
			      TRUE);

	mat->priv->dis = 
		g_ptr_array_new_with_free_func((GDestroyNotify)facq_display_free);

	scrolled_window = gtk_scrolled_window_new(NULL,NULL);
	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
				       GTK_POLICY_AUTOMATIC,
				       GTK_POLICY_AUTOMATIC);

	for(j = 0;j < mat->priv->rows;j++){
		for(i = 0;i < mat->priv->cols;i++){
			dis = facq_display_new("Patient BPM",
					       "Unknown patient",
					       "Not connected",
					       j*mat->priv->cols+i);
			g_ptr_array_add(mat->priv->dis,dis);
			display = facq_display_get_widget(dis);
			gtk_table_attach_defaults(GTK_TABLE(table),display,i,i+1,j,j+1);
		}
	}

	gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
						table);

	gtk_widget_show_all(scrolled_window);

	mat->priv->table = table;
	mat->priv->scrolled_window = scrolled_window;
}
static GPtrArray *
get_data_forms (WockyNode *node)
{
  GPtrArray *out = g_ptr_array_new_with_free_func (g_object_unref);

  WockyNodeIter iter;
  WockyNode *x_node = NULL;

  wocky_node_iter_init (&iter, node, "x", WOCKY_XMPP_NS_DATA);
  while (wocky_node_iter_next (&iter, &x_node))
    {
      WockyDataForm *form  = wocky_data_form_new_from_node (x_node, NULL);

      /* we've already parsed the reply to check the hash matches, so
       * we can already guarantee these data forms will be parsed
       * fine */
      if (G_LIKELY (form != NULL))
        g_ptr_array_add (out, form);
   }

  return out;
}
Example #4
0
/**
 * as_pool_get_components_by_id:
 * @pool: An instance of #AsPool.
 * @cid: The AppStream-ID to look for.
 *
 * Get a specific component by its ID.
 * This function may contain multiple results if we have
 * data describing this component from multiple scopes/origin types.
 *
 * Returns: (transfer container) (element-type AsComponent): An #AsComponent
 */
GPtrArray*
as_pool_get_components_by_id (AsPool *pool, const gchar *cid)
{
	AsPoolPrivate *priv = GET_PRIVATE (pool);
	GPtrArray *result;
	GHashTableIter iter;
	gpointer value;

	result = g_ptr_array_new_with_free_func (g_object_unref);
	if (cid == NULL)
		return result;

	g_hash_table_iter_init (&iter, priv->cpt_table);
	while (g_hash_table_iter_next (&iter, NULL, &value)) {
		AsComponent *cpt = AS_COMPONENT (value);
		if (g_strcmp0 (as_component_get_id (cpt), cid) == 0)
			g_ptr_array_add (result,
					 g_object_ref (cpt));
	}

	return result;
}
static GPtrArray *
data2groupents (const char *data)
{
  struct group *ent = NULL;
  _cleanup_stdio_file_ FILE *mf = NULL;
  GPtrArray *ret = g_ptr_array_new_with_free_func (conv_group_ent_free);
  
  mf = fmemopen ((void *)data, strlen (data), "r");
  
  while ((ent = fgetgrent (mf)))
    {
      struct conv_group_ent *convent = g_new (struct conv_group_ent, 1);

      convent->name = g_strdup (ent->gr_name);
      convent->gid  = ent->gr_gid;
      /* Want to add anymore, like users? */

      g_ptr_array_add (ret, convent);
    }

  return ret;
}
static void
ide_recent_projects_init (IdeRecentProjects *self)
{
  GIOExtensionPoint *extension_point;
  GList *extensions;

  self->projects = g_sequence_new (g_object_unref);
  self->miners = g_ptr_array_new_with_free_func (g_object_unref);
  self->cancellable = g_cancellable_new ();
  self->recent_uris = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
  self->file_uri = g_build_filename (g_get_user_data_dir (),
                                     ide_get_program_name (),
                                     IDE_RECENT_PROJECTS_BOOKMARK_FILENAME,
                                     NULL);


  extension_point = g_io_extension_point_lookup (IDE_PROJECT_MINER_EXTENSION_POINT);
  extensions = g_io_extension_point_get_extensions (extension_point);

  for (; extensions; extensions = extensions->next)
    {
      IdeProjectMiner *miner;
      GIOExtension *extension = extensions->data;
      GType type_id;

      type_id = g_io_extension_get_type (extension);

      if (!g_type_is_a (type_id, IDE_TYPE_PROJECT_MINER))
        {
          g_warning ("%s is not an IdeProjectMiner", g_type_name (type_id));
          continue;
        }

      miner = g_object_new (type_id, NULL);
      ide_recent_projects_add_miner (self, miner);
      g_object_unref (miner);
    }
}
Example #7
0
static GPtrArray *
saved_history (void)
{
  gchar *filename, *file_contents = NULL;
  gchar **history_from_file = NULL, **list;
  gboolean success;
  gint len;
  GPtrArray *array;

  array = g_ptr_array_new_with_free_func (g_free);

  filename = history_filename ();
  success = g_file_get_contents (filename,
				 &file_contents,
				 NULL,
				 NULL);

  if (success)
    {
      history_from_file = g_strsplit (file_contents, "\n", 0);
      len = g_strv_length (history_from_file);
      if (len > 0 && strlen (history_from_file[len-1]) == 0)
	{
	  g_free (history_from_file[len-1]);
	  history_from_file[len-1] = NULL;
	}

      list = history_from_file;

      while (*list != NULL)
	g_ptr_array_add (array, *list++);
    }

  g_free (filename);
  g_free (file_contents);
  g_free (history_from_file);
  return array;
}
Example #8
0
/**
 * as_pool_search:
 * @pool: An instance of #AsPool
 * @search: A search string
 *
 * Search for a list of components matching the search terms.
 * The list will be unordered.
 *
 * Returns: (transfer container) (element-type AsComponent): an array of the found #AsComponent objects.
 *
 * Since: 0.9.7
 */
GPtrArray*
as_pool_search (AsPool *pool, const gchar *search)
{
	AsPoolPrivate *priv = GET_PRIVATE (pool);
	g_auto(GStrv) terms = NULL;
	GPtrArray *results;
	GHashTableIter iter;
	gpointer value;

	/* sanitize user's search term */
	terms = as_pool_build_search_terms (pool, search);
	results = g_ptr_array_new_with_free_func (g_object_unref);

	if (terms == NULL) {
		g_debug ("Search term invalid. Matching everything.");
	} else {
		g_autofree gchar *tmp_str = NULL;
		tmp_str = g_strjoinv (" ", terms);
		g_debug ("Searching for: %s", tmp_str);
	}

	g_hash_table_iter_init (&iter, priv->cpt_table);
	while (g_hash_table_iter_next (&iter, NULL, &value)) {
		guint score;
		AsComponent *cpt = AS_COMPONENT (value);

		score = as_component_search_matches_all (cpt, terms);
		if (score == 0)
			continue;

		g_ptr_array_add (results, g_object_ref (cpt));
	}

	/* sort the results by their priority */
	g_ptr_array_sort (results, as_sort_components_by_score_cb);

	return results;
}
Example #9
0
/**
 * sw_item_stream_add_items
 * @item_stream: A #SwItemStream
 * @items: A list of #SwItem objects
 * 
 * Add the items supplied in the list from the #SwItemStream. This will cause
 * signal emissions over the bus.
 *
 */
void
sw_item_stream_add_items (SwItemStream *item_stream,
                          GList        *items)
{
  SwItemStreamPrivate *priv = GET_PRIVATE (item_stream);
  GValueArray *value_array;
  GPtrArray *ptr_array;
  GList *l;

  ptr_array = g_ptr_array_new_with_free_func ((GDestroyNotify)g_value_array_free);

  for (l = items; l; l = l->next)
  {
    SwItem *item = SW_ITEM (l->data);

    if (sw_item_get_ready (item))
    {
      SW_DEBUG (VIEWS, "Item ready: %s",
                sw_item_get (item, "id"));
      value_array = _sw_item_to_value_array (item);
      g_ptr_array_add (ptr_array, value_array);
    } else {
      SW_DEBUG (VIEWS, "Item not ready, setting up handler: %s",
                sw_item_get (item, "id"));
      _setup_ready_handler (item, item_stream);
      sw_set_add (priv->pending_items_set, (GObject *)item);
    }

    _setup_changed_handler (item, item_stream);
  }

  SW_DEBUG (VIEWS, "Number of items to be added: %d", ptr_array->len);

  sw_item_view_iface_emit_items_added (item_stream,
                                       ptr_array);

  g_ptr_array_free (ptr_array, TRUE);
}
Example #10
0
/**
 * main:
 **/
int
main (int argc, char *argv[])
{
	CdMainPrivate *priv = NULL;
	guint retval = 1;

	/* We need to init DBus' threading support as libSANE uses raw DBus */
	dbus_threads_init_default ();

	/* create new objects */
	priv = g_new0 (CdMainPrivate, 1);
	priv->loop = g_main_loop_new (NULL, FALSE);
	priv->client = cd_client_new ();
	priv->argv0 = g_strdup (argv[0]);
	priv->array = g_ptr_array_new_with_free_func ((GDestroyNotify) cd_main_dev_free);

	/* connect to daemon */
	cd_client_connect (priv->client,
			   NULL,
			   cd_main_colord_connect_cb,
			   priv);

	/* process */
	g_main_loop_run (priv->loop);

	/* success */
	retval = 0;

	if (priv != NULL) {
		g_free (priv->argv0);
		if (priv->array != NULL)
			g_ptr_array_unref (priv->array);
		if (priv->client != NULL)
			g_object_unref (priv->client);
		g_main_loop_unref (priv->loop);
	}
	return retval;
}
Example #11
0
static GPtrArray *
query_all_packages_in_sack (RpmOstreeRefSack *rsack)
{
  _cleanup_hyquery_ HyQuery hquery = NULL;
  _cleanup_hypackagelist_ HyPackageList pkglist = NULL;
  GPtrArray *result;
  int i, c;

  hquery = hy_query_create (rsack->sack);
  hy_query_filter (hquery, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
  pkglist = hy_query_run (hquery);

  result = g_ptr_array_new_with_free_func (g_object_unref);
  
  c = hy_packagelist_count (pkglist);
  for (i = 0; i < c; i++)
    {
      HyPackage pkg = hy_packagelist_get (pkglist, i);
      g_ptr_array_add (result, _rpm_ostree_package_new (rsack, pkg));
    }
  
  return g_steal_pointer (&result);
}
void
_ostree_kernel_args_replace_take (OstreeKernelArgs   *kargs,
                                  char               *arg)
{
  gboolean existed;
  GPtrArray *values = g_ptr_array_new_with_free_func (g_free);
  const char *value = split_keyeq (arg);
  gpointer old_key;

  g_ptr_array_add (values, g_strdup (value));
  existed = g_hash_table_lookup_extended (kargs->table, arg, &old_key, NULL);

  if (existed)
    {
      g_hash_table_replace (kargs->table, old_key, values);
      g_free (arg);
    }
  else
    {
      g_ptr_array_add (kargs->order, arg);
      g_hash_table_replace (kargs->table, arg, values);
    }
}
Example #13
0
static
struct bt_ctf_field *bt_ctf_field_structure_create(
	struct bt_ctf_field_type *type)
{
	struct bt_ctf_field_type_structure *structure_type = container_of(type,
		struct bt_ctf_field_type_structure, parent);
	struct bt_ctf_field_structure *structure = g_new0(
		struct bt_ctf_field_structure, 1);
	struct bt_ctf_field *field = NULL;

	if (!structure || !structure_type->fields->len) {
		goto end;
	}

	structure->field_name_to_index = structure_type->field_name_to_index;
	structure->fields = g_ptr_array_new_with_free_func(
		(GDestroyNotify)bt_ctf_field_put);
	g_ptr_array_set_size(structure->fields,
		g_hash_table_size(structure->field_name_to_index));
	field = &structure->parent;
end:
	return field;
}
Example #14
0
static GPtrArray *
ot_split_string_ptrarray (const char *str,
                          char        c)
{
  GPtrArray *ret = g_ptr_array_new_with_free_func (g_free);

  const char *p;
  do {
    p = strchr (str, '/');
    if (!p)
      {
        g_ptr_array_add (ret, g_strdup (str));
        str = NULL;
      }
    else
      {
        g_ptr_array_add (ret, g_strndup (str, p - str));
        str = p + 1;
      }
  } while (str && *str);

  return ret;
}
Example #15
0
YamlNode_t *moloch_rules_add_node(YamlNode_t *parent, char *key, char *value) 
{
    YamlNode_t *node = MOLOCH_TYPE_ALLOC(YamlNode_t);
    node->key = key;
    node->value = value;

    if (value) {
        node->values = NULL;
    } else {
        node->values = g_ptr_array_new_with_free_func((GDestroyNotify)moloch_rules_free_node);
    }

    if (parent) {
        if (!key) {
            char str[10];
            sprintf(str, "%d", parent->values->len);
            node->key = g_strdup(str);
        }
        g_ptr_array_add(parent->values, node);
    }

    return node;
}
/**
 * pk_plugin_get_existing_prepared_updates:
 **/
static GPtrArray *
pk_plugin_get_existing_prepared_updates (const gchar *filename)
{
    gboolean ret;
    gchar **package_ids = NULL;
    gchar *packages_data = NULL;
    GError *error = NULL;
    GPtrArray *packages;
    guint i;

    /* always return a valid array, even for failure */
    packages = g_ptr_array_new_with_free_func (g_free);

    /* does the file exist ? */
    if (!g_file_test (filename, G_FILE_TEST_EXISTS))
        goto out;

    /* get the list of packages to update */
    ret = g_file_get_contents (filename,
                               &packages_data,
                               NULL,
                               &error);
    if (!ret) {
        g_warning ("failed to read: %s", error->message);
        g_error_free (error);
        goto out;
    }

    /* add them to the new array */
    package_ids = g_strsplit (packages_data, "\n", -1);
    for (i = 0; package_ids[i] != NULL; i++)
        g_ptr_array_add (packages, g_strdup (package_ids[i]));
out:
    g_free (packages_data);
    g_strfreev (package_ids);
    return packages;
}
Example #17
0
static void
new_linux_md_array_callback (GtkAction *action, gpointer user_data)
{
        MduShell *shell = MDU_SHELL (user_data);
        GtkWidget *dialog;
        gint response;
        MduPool *pool;

        //g_debug ("New Linux MD Array!");

        pool = mdu_shell_get_pool_for_selected_presentable (shell);

        dialog = mdu_create_linux_md_dialog_new (GTK_WINDOW (shell->priv->app_window), pool);

        gtk_widget_show_all (dialog);
        response = gtk_dialog_run (GTK_DIALOG (dialog));
        gtk_widget_hide (dialog);

        if (response == GTK_RESPONSE_OK) {
                CreateLinuxMdData *data;

                data = g_new0 (CreateLinuxMdData, 1);
                data->pool           = g_object_ref (pool);
                data->shell          = g_object_ref (shell);
                data->level          = mdu_create_linux_md_dialog_get_level (MDU_CREATE_LINUX_MD_DIALOG (dialog));
                data->name           = mdu_create_linux_md_dialog_get_name (MDU_CREATE_LINUX_MD_DIALOG (dialog));
                data->size           = mdu_create_linux_md_dialog_get_size (MDU_CREATE_LINUX_MD_DIALOG (dialog));
                data->component_size = mdu_create_linux_md_dialog_get_component_size (MDU_CREATE_LINUX_MD_DIALOG (dialog));
                data->stripe_size    = mdu_create_linux_md_dialog_get_stripe_size (MDU_CREATE_LINUX_MD_DIALOG (dialog));
                data->drives         = mdu_create_linux_md_dialog_get_drives (MDU_CREATE_LINUX_MD_DIALOG (dialog));

                data->components  = g_ptr_array_new_with_free_func (g_object_unref);

                create_linux_md_do (data);
        }
        gtk_widget_destroy (dialog);
}
Example #18
0
static void
add_to_list (GList **list, RBExtDBField **multi, const char *name, const char *value)
{
	RBExtDBField *f;
	GList *l;
	int i;

	for (l = *list; l != NULL; l = l->next) {
		f = l->data;
		if (strcmp (f->name, name) == 0) {
			g_assert (multi != NULL);

			if (value != NULL) {
				for (i = 0; i < f->values->len; i++) {
					if (strcmp (g_ptr_array_index (f->values, i), value) == 0) {
						/* duplicate value */
						return;
					}
				}
				g_assert (*multi == NULL || *multi == f);
				g_ptr_array_add (f->values, g_strdup (value));
				*multi = f;
			} else {
				g_assert (*multi == NULL || *multi == f);
				f->match_null = TRUE;
				*multi = f;
			}
			return;
		}
	}

	f = g_slice_new0 (RBExtDBField);
	f->name = g_strdup (name);
	f->values = g_ptr_array_new_with_free_func (g_free);
	g_ptr_array_add (f->values, g_strdup (value));
	*list = g_list_append (*list, f);
}
static void
gbp_gcc_toolchain_provider_search_init (GbpGccToolchainProvider *self,
                                        GCancellable            *cancellable,
                                        GAsyncReadyCallback      callback,
                                        gpointer                 user_data)
{
  g_autoptr(IdeTask) task = NULL;
  g_auto(GStrv) environ_ = NULL;
  g_auto(GStrv) paths = NULL;
  const gchar *path_env;
  FileSearching *fs;
  GList *folders = NULL;

  g_assert (GBP_IS_GCC_TOOLCHAIN_PROVIDER (self));

  environ_ = g_get_environ ();
  path_env = g_environ_getenv (environ_, "PATH");
  paths = g_strsplit (path_env, ":", -1);
  for (guint i = 0; paths[i] != NULL; i++)
    folders = g_list_append (folders, g_file_new_for_path (paths[i]));

  task = ide_task_new (self, cancellable, callback, user_data);
  ide_task_set_source_tag (task, gbp_gcc_toolchain_provider_search_init);
  ide_task_set_priority (task, G_PRIORITY_LOW);

  fs = g_slice_new0 (FileSearching);
  fs->found_files = g_ptr_array_new_with_free_func (g_object_unref);
  fs->folders = g_steal_pointer (&folders);
  ide_task_set_task_data (task, fs, file_searching_free);

  /* GCC */
  ide_g_file_find_async (fs->folders->data,
                         "*-gcc",
                         cancellable,
                         gbp_gcc_toolchain_provider_search_iterate,
                         g_steal_pointer (&task));
}
Example #20
0
/**
 * as_data_pool_get_components_by_kind:
 * @dpool: An instance of #AsDatabase.
 * @kind: An #AsComponentKind.
 * @error: A #GError or %NULL.
 *
 * Return a list of all components in the pool which are of a certain kind.
 *
 * Returns: (element-type AsComponent) (transfer full): an array of #AsComponent objects which have been found.
 */
GPtrArray*
as_data_pool_get_components_by_kind (AsDataPool *dpool,
				     AsComponentKind kind,
				     GError **error)
{
	AsDataPoolPrivate *priv = GET_PRIVATE (dpool);
	GHashTableIter iter;
	gpointer value;
	GPtrArray *results;

	if (kind >= AS_COMPONENT_KIND_LAST) {
		g_set_error_literal (error,
					AS_DATA_POOL_ERROR,
					AS_DATA_POOL_ERROR_TERM_INVALID,
					_("Can not search for unknown component type."));
		return NULL;
	}

	if (kind == AS_COMPONENT_KIND_UNKNOWN) {
		g_set_error_literal (error,
					AS_DATA_POOL_ERROR,
					AS_DATA_POOL_ERROR_TERM_INVALID,
					_("Can not search for unknown component type."));
		return NULL;
	}

	results = g_ptr_array_new_with_free_func (g_object_unref);
	g_hash_table_iter_init (&iter, priv->cpt_table);
	while (g_hash_table_iter_next (&iter, NULL, &value)) {
		AsComponent *cpt = AS_COMPONENT (value);

		if (as_component_get_kind (cpt) == kind)
				g_ptr_array_add (results, g_object_ref (cpt));
	}

	return results;
}
Example #21
0
GPtrArray* search_user_env(uid_t uid, const char *name, int update) {
    GPtrArray* rv = g_ptr_array_new_with_free_func(g_free);
    u_proc *proc = NULL;
    GHashTableIter iter;
    char *val;
    int i, found;

    gpointer ikey, value;

    g_hash_table_iter_init (&iter, processes);
    while (g_hash_table_iter_next (&iter, &ikey, &value)) 
    {
        proc = (u_proc *)value;
        if(proc->proc->euid != uid)
            continue;

        if (!u_proc_ensure (proc, ENVIRONMENT,
                            update ? UPDATE_NOW : UPDATE_DEFAULT))
          continue;

        val = g_hash_table_lookup(proc->environ, name);
        if(val) {
            found = FALSE;
            for(i = 0; i < rv->len; i++) {
                if(g_strcmp0((char *)g_ptr_array_index(rv, i), val) == 0) {
                    found = TRUE;
                    break;
                }
            }
            if(!found)
                 g_ptr_array_add(rv, g_strdup(val));

        }
    }
    return rv;
}
static void
ide_ctags_completion_provider_init (IdeCtagsCompletionProvider *self)
{
  GtkSettings *settings;

  self->minimum_word_size = 3;
  self->indexes = g_ptr_array_new_with_free_func (g_object_unref);
  self->settings = g_settings_new ("org.gnome.builder.code-insight");
  self->icons = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref);

  settings = gtk_settings_get_default ();

  g_signal_connect_object (settings,
                           "notify::gtk-theme-name",
                           G_CALLBACK (theme_changed_cb),
                           self,
                           G_CONNECT_SWAPPED);

  g_signal_connect_object (settings,
                           "notify::gtk-application-prefer-dark-theme",
                           G_CALLBACK (theme_changed_cb),
                           self,
                           G_CONNECT_SWAPPED);
}
Example #23
0
/**
 * as_pool_get_components_by_provided_item:
 * @pool: An instance of #AsPool.
 * @kind: An #AsProvidesKind
 * @item: The value of the provided item.
 *
 * Find components in the AppStream data pool whcih provide a certain item.
 *
 * Returns: (transfer container) (element-type AsComponent): an array of #AsComponent objects which have been found.
 */
GPtrArray*
as_pool_get_components_by_provided_item (AsPool *pool,
					      AsProvidedKind kind,
					      const gchar *item)
{
	AsPoolPrivate *priv = GET_PRIVATE (pool);
	GHashTableIter iter;
	gpointer value;
	GPtrArray *results;

	/* sanity check */
	g_return_val_if_fail (item != NULL, NULL);

	results = g_ptr_array_new_with_free_func (g_object_unref);
	g_hash_table_iter_init (&iter, priv->cpt_table);
	while (g_hash_table_iter_next (&iter, NULL, &value)) {
		GPtrArray *provided = NULL;
		guint i;
		AsComponent *cpt = AS_COMPONENT (value);

		provided = as_component_get_provided (cpt);
		for (i = 0; i < provided->len; i++) {
			AsProvided *prov = AS_PROVIDED (g_ptr_array_index (provided, i));
			if (kind != AS_PROVIDED_KIND_UNKNOWN) {
				/* check if the kind matches. an unknown kind matches all provides types */
				if (as_provided_get_kind (prov) != kind)
					continue;
			}

			if (as_provided_has_item (prov, item))
				g_ptr_array_add (results, g_object_ref (cpt));
		}
	}

	return results;
}
Example #24
0
static struct RpmHeaders *
rpmhdrs_new (RpmOstreeRefTs *refts, const GPtrArray *patterns)
{
  rpmdbMatchIterator iter;
  Header h1;
  GPtrArray *hs = NULL;
  struct RpmHeaders *ret = NULL;
  gsize patprefixlen = pat_fnmatch_prefix (patterns);

  /* iter = rpmtsInitIterator (ts, RPMTAG_NAME, "yum", 0); */
  iter = rpmtsInitIterator (refts->ts, RPMDBI_PACKAGES, NULL, 0);

  hs = g_ptr_array_new_with_free_func (header_free_p);
  while ((h1 = rpmdbNextIterator (iter)))
    {
      const char*    name = headerGetString (h1, RPMTAG_NAME);

      if (g_str_equal (name, "gpg-pubkey")) continue; /* rpmdb abstraction leak */

      if (!pat_fnmatch_match (h1, name, patprefixlen, patterns))
        continue;

      h1 = headerLink (h1);
      g_ptr_array_add (hs, h1);
    }
  iter = rpmdbFreeIterator (iter);

  g_ptr_array_sort (hs, header_cmp_p);

  ret = g_malloc0 (sizeof (struct RpmHeaders));

  ret->refts = rpmostree_refts_ref (refts);
  ret->hs = hs;

  return ret;
}
Example #25
0
static void
ip6_dns_parser (NMSetting *setting, const char *key, GKeyFile *keyfile, const char *keyfile_path)
{
	const char *setting_name = nm_setting_get_name (setting);
	GPtrArray *array = NULL;
	gsize length;
	char **list, **iter;
	int ret;

	list = g_key_file_get_string_list (keyfile, setting_name, key, &length, NULL);
	if (!list || !g_strv_length (list))
		return;

	array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_byte_array_unref);

	for (iter = list; *iter; iter++) {
		GByteArray *byte_array;
		struct in6_addr addr;

		ret = inet_pton (AF_INET6, *iter, &addr);
		if (ret <= 0) {
			g_warning ("%s: ignoring invalid DNS server IPv6 address '%s'", __func__, *iter);
			continue;
		}
		byte_array = g_byte_array_new ();
		g_byte_array_append (byte_array, (guint8 *) addr.s6_addr, 16);

		g_ptr_array_add (array, byte_array);
	}
	g_strfreev (list);

	if (array) {
		g_object_set (setting, key, array, NULL);
		g_ptr_array_unref (array);
	}
}
Example #26
0
static gchar *
fwupd_build_user_agent_system (void)
{
	struct utsname name_tmp;
	g_autofree gchar *locale = NULL;
	g_autofree gchar *os_release = NULL;
	g_autoptr(GPtrArray) ids = g_ptr_array_new_with_free_func (g_free);

	/* system, architecture and kernel, e.g. "Linux i686 4.14.5" */
	memset (&name_tmp, 0, sizeof(struct utsname));
	if (uname (&name_tmp) >= 0) {
		g_ptr_array_add (ids, g_strdup_printf ("%s %s %s",
						       name_tmp.sysname,
						       name_tmp.machine,
						       name_tmp.release));
	}

	/* current locale, e.g. "en-gb" */
	locale = g_strdup (setlocale (LC_MESSAGES, NULL));
	if (locale != NULL) {
		g_strdelimit (locale, ".", '\0');
		g_strdelimit (locale, "_", '-');
		g_ptr_array_add (ids, g_steal_pointer (&locale));
	}

	/* OS release, e.g. "Fedora 27 Workstation" */
	os_release = fwupd_build_user_agent_os_release ();
	if (os_release != NULL)
		g_ptr_array_add (ids, g_steal_pointer (&os_release));

	/* convert to string */
	if (ids->len == 0)
		return NULL;
	g_ptr_array_add (ids, NULL);
	return g_strjoinv ("; ", (gchar **) ids->pdata);
}
/**
 * asb_package_deb_ensure_filelists:
 **/
static gboolean
asb_package_deb_ensure_filelists (AsbPackage *pkg, GError **error)
{
	const gchar *argv[4] = { "dpkg", "--contents", "fn", NULL };
	const gchar *fn;
	guint i;
	_cleanup_free_ gchar *output = NULL;
	_cleanup_ptrarray_unref_ GPtrArray *files = NULL;
	_cleanup_strv_free_ gchar **lines = NULL;

	/* spawn sync */
	argv[2] = asb_package_get_filename (pkg);
	if (!g_spawn_sync (NULL, (gchar **) argv, NULL,
			   G_SPAWN_SEARCH_PATH,
			   NULL, NULL,
			   &output, NULL, NULL, error))
		return FALSE;

	/* parse output */
	files = g_ptr_array_new_with_free_func (g_free);
	lines = g_strsplit (output, "\n", -1);
	for (i = 0; lines[i] != NULL; i++) {
		fn = g_strrstr (lines[i], " ");
		if (fn == NULL)
			continue;
		/* ignore directories */
		if (g_str_has_suffix (fn, "/"))
			continue;
		g_ptr_array_add (files, g_strdup (fn + 2));
	}

	/* save */
	g_ptr_array_add (files, NULL);
	asb_package_set_filelist (pkg, (gchar **) files->pdata);
	return TRUE;
}
Example #28
0
static dlr_host_file_t *prv_host_file_new(const gchar *file, unsigned int id,
					  GError **error)
{
	dlr_host_file_t *hf = NULL;
	gchar *extension;

	if (!g_file_test(file, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) {
		*error = g_error_new(DLEYNA_SERVER_ERROR,
				     DLEYNA_ERROR_OBJECT_NOT_FOUND,
				     "File %s does not exist or is not a regular file",
				     file);
		goto on_error;
	}

	hf = g_new0(dlr_host_file_t, 1);
	hf->id = id;
	hf->clients = g_ptr_array_new_with_free_func(g_free);

	extension = strrchr(file, '.');
	hf->path = g_strdup_printf(DLR_HOST_SERVICE_ROOT"/%d%s",
				   hf->id, extension ? extension : "");

	prv_compute_mime_and_dlna_header(file, &hf->mime_type, &hf->dlna_header,
					 error);

	if (*error != NULL)
		goto on_error;

	return hf;

on_error:

	prv_host_file_delete(hf);

	return NULL;
}
Example #29
0
File: lua.c Project: Cynede/hexchat
G_MODULE_EXPORT int hexchat_plugin_init(hexchat_plugin *plugin_handle, char **name, char **description, char **version, char *arg)
{
	if(initialized != 0)
	{
		hexchat_print(plugin_handle, "Lua interface already loaded\n");
		return 0;
	}

	if (g_str_has_prefix(LUA_VERSION, "Lua "))
	{
		strcat(plugin_version, "/");
		g_strlcat(plugin_version, LUA_VERSION + 4, sizeof(plugin_version));
	}

	*name = plugin_name;
	*description = plugin_description;
	*version = plugin_version;

	ph = plugin_handle;
	initialized = 1;

	hexchat_hook_command(ph, "", HEXCHAT_PRI_NORM, command_console_exec, NULL, NULL);
	hexchat_hook_command(ph, "LOAD", HEXCHAT_PRI_NORM, command_load, NULL, NULL);
	hexchat_hook_command(ph, "UNLOAD", HEXCHAT_PRI_NORM, command_unload, NULL, NULL);
	hexchat_hook_command(ph, "RELOAD", HEXCHAT_PRI_NORM, command_reload, NULL, NULL);
	hexchat_hook_command(ph, "lua", HEXCHAT_PRI_NORM, command_lua, command_help, NULL);

	hexchat_printf(ph, "%s version %s loaded.\n", plugin_name, plugin_version);

	scripts = g_ptr_array_new_with_free_func((GDestroyNotify)destroy_script);
	create_interpreter();

	if(!arg)
		autoload_scripts();
	return 1;
}
Example #30
0
/**
 * rpm_ostree_db_diff:
 * @repo: An OSTree repository
 * @orig_ref: Original ref (branch or commit)
 * @new_ref: New ref (branch or commit)
 * @out_removed: (out) (transfer container) (element-type RpmOstreePackage): Return location for removed packages
 * @out_added: (out) (transfer container) (element-type RpmOstreePackage): Return location for added packages
 * @out_modified_old: (out) (transfer container) (element-type RpmOstreePackage): Return location for modified old packages
 * @out_modified_new: (out) (transfer container) (element-type RpmOstreePackage): Return location for modified new packages
 *
 * Compute the RPM package delta between two commits.  Currently you
 * must use %NULL for the @query parameter; in a future version this
 * function may allow looking at a subset of the packages.
 *
 * The @out_modified_old and @out_modified_new arrays will always be
 * the same length, and indicies will refer to the same base package
 * name.  It is possible in RPM databases to have multiple packages
 * installed with the same name; in this case, the behavior will
 * depend on whether the package set is transitioning from 1 -> N or N
 * -> 1.  In the former case, an arbitrary single instance of one of
 * the new packages will be in @out_modified_new.  If the latter, then
 * multiple entries with the same name will be returned in
 * the array @out_modified_old, with each having a reference to the
 * single corresponding new package.
 */
gboolean
rpm_ostree_db_diff (OstreeRepo               *repo,
                    const char               *orig_ref,
                    const char               *new_ref,
                    GPtrArray               **out_removed,
                    GPtrArray               **out_added,
                    GPtrArray               **out_modified_old,
                    GPtrArray               **out_modified_new,
                    GCancellable             *cancellable,
                    GError                  **error)
{
  gboolean ret = FALSE;
  g_autoptr(RpmOstreeRefSack) orig_sack = NULL;
  g_autoptr(RpmOstreeRefSack) new_sack = NULL;
  _cleanup_hypackagelist_ HyPackageList orig_pkglist = NULL;
  _cleanup_hypackagelist_ HyPackageList new_pkglist = NULL;
  g_autoptr(GPtrArray) ret_removed = g_ptr_array_new_with_free_func (g_object_unref);
  g_autoptr(GPtrArray) ret_added = g_ptr_array_new_with_free_func (g_object_unref);
  g_autoptr(GPtrArray) ret_modified_old = g_ptr_array_new_with_free_func (g_object_unref);
  g_autoptr(GPtrArray) ret_modified_new = g_ptr_array_new_with_free_func (g_object_unref);
  guint i;
  HyPackage pkg;

  g_return_val_if_fail (out_removed != NULL && out_added != NULL &&
                        out_modified_old != NULL && out_modified_new != NULL, FALSE);

  orig_sack = _rpm_ostree_get_refsack_for_commit (repo, orig_ref, cancellable, error);
  if (!orig_sack)
    goto out;

  { _cleanup_hyquery_ HyQuery query = hy_query_create (orig_sack->sack);
    hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
    orig_pkglist = hy_query_run (query);
  }

  new_sack = _rpm_ostree_get_refsack_for_commit (repo, new_ref, cancellable, error);
  if (!new_sack)
    goto out;

  { _cleanup_hyquery_ HyQuery query = hy_query_create (new_sack->sack);
    hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
    new_pkglist = hy_query_run (query);
  }

  FOR_PACKAGELIST(pkg, new_pkglist, i)
    {
      _cleanup_hyquery_ HyQuery query = NULL;
      _cleanup_hypackagelist_ HyPackageList pkglist = NULL;
      guint count;
      HyPackage oldpkg;
      
      query = hy_query_create (orig_sack->sack);
      hy_query_filter (query, HY_PKG_NAME, HY_EQ, hy_package_get_name (pkg));
      hy_query_filter (query, HY_PKG_EVR, HY_NEQ, hy_package_get_evr (pkg));
      hy_query_filter (query, HY_PKG_REPONAME, HY_EQ, HY_SYSTEM_REPO_NAME);
      pkglist = hy_query_run (query);

      count = hy_packagelist_count (pkglist);
      if (count > 0)
        {
          /* See comment above about transitions from N -> 1 */
          oldpkg = hy_packagelist_get (pkglist, 0);
          
          g_ptr_array_add (ret_modified_old, _rpm_ostree_package_new (orig_sack, oldpkg));
          g_ptr_array_add (ret_modified_new, _rpm_ostree_package_new (new_sack, pkg));
        }
    }