static gboolean is_valid_nonce_tcp (const gchar *address_entry, GHashTable *key_value_pairs, GError **error) { gboolean ret; GList *keys; GList *l; const gchar *host; const gchar *port; const gchar *family; const gchar *nonce_file; gint port_num; gchar *endp; ret = FALSE; keys = NULL; host = NULL; port = NULL; family = NULL; nonce_file = NULL; keys = g_hash_table_get_keys (key_value_pairs); for (l = keys; l != NULL; l = l->next) { const gchar *key = l->data; if (g_strcmp0 (key, "host") == 0) host = g_hash_table_lookup (key_value_pairs, key); else if (g_strcmp0 (key, "port") == 0) port = g_hash_table_lookup (key_value_pairs, key); else if (g_strcmp0 (key, "family") == 0) family = g_hash_table_lookup (key_value_pairs, key); else if (g_strcmp0 (key, "noncefile") == 0) nonce_file = g_hash_table_lookup (key_value_pairs, key); else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Unsupported key `%s' in address entry `%s'"), key, address_entry); goto out; } } if (port != NULL) { port_num = strtol (port, &endp, 10); if ((*port == '\0' || *endp != '\0') || port_num < 0 || port_num >= 65536) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Error in address `%s' - the port attribute is malformed"), address_entry); goto out; } } if (family != NULL && !(g_strcmp0 (family, "ipv4") == 0 || g_strcmp0 (family, "ipv6") == 0)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Error in address `%s' - the family attribute is malformed"), address_entry); goto out; } ret= TRUE; out: g_list_free (keys); return ret; }
static gboolean is_valid_unix (const gchar *address_entry, GHashTable *key_value_pairs, GError **error) { gboolean ret; GList *keys; GList *l; const gchar *path; const gchar *tmpdir; const gchar *abstract; ret = FALSE; keys = NULL; path = NULL; tmpdir = NULL; abstract = NULL; keys = g_hash_table_get_keys (key_value_pairs); for (l = keys; l != NULL; l = l->next) { const gchar *key = l->data; if (g_strcmp0 (key, "path") == 0) path = g_hash_table_lookup (key_value_pairs, key); else if (g_strcmp0 (key, "tmpdir") == 0) tmpdir = g_hash_table_lookup (key_value_pairs, key); else if (g_strcmp0 (key, "abstract") == 0) abstract = g_hash_table_lookup (key_value_pairs, key); else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Unsupported key `%s' in address entry `%s'"), key, address_entry); goto out; } } if (path != NULL) { if (tmpdir != NULL || abstract != NULL) goto meaningless; /* TODO: validate path */ } else if (tmpdir != NULL) { if (path != NULL || abstract != NULL) goto meaningless; /* TODO: validate tmpdir */ } else if (abstract != NULL) { if (path != NULL || tmpdir != NULL) goto meaningless; /* TODO: validate abstract */ } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Address `%s' is invalid (need exactly one of path, tmpdir or abstract keys"), address_entry); goto out; } ret= TRUE; goto out; meaningless: g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, _("Meaningless key/value pair combination in address entry `%s'"), address_entry); out: g_list_free (keys); return ret; }
static void gimp_tag_popup_constructed (GObject *object) { GimpTagPopup *popup = GIMP_TAG_POPUP (object); GimpTaggedContainer *container; GtkWidget *entry; GtkAllocation entry_allocation; GtkStyle *frame_style; gint x; gint y; gint width; gint height; gint popup_height; GHashTable *tag_hash; GList *tag_list; GList *tag_iterator; gint i; gint max_height; gint screen_height; gchar **current_tags; gint current_count; GdkRectangle popup_rects[2]; /* variants of popup placement */ GdkRectangle popup_rect; /* best popup rect in screen coordinates */ if (G_OBJECT_CLASS (parent_class)->constructed) G_OBJECT_CLASS (parent_class)->constructed (object); entry = GTK_WIDGET (popup->combo_entry); gtk_window_set_screen (GTK_WINDOW (popup), gtk_widget_get_screen (entry)); popup->context = gtk_widget_create_pango_context (GTK_WIDGET (popup)); popup->layout = pango_layout_new (popup->context); gtk_widget_get_allocation (entry, &entry_allocation); gtk_widget_style_get (GTK_WIDGET (popup), "scroll-arrow-vlength", &popup->scroll_arrow_height, NULL); pango_layout_set_attributes (popup->layout, popup->combo_entry->normal_item_attr); current_tags = gimp_tag_entry_parse_tags (GIMP_TAG_ENTRY (popup->combo_entry)); current_count = g_strv_length (current_tags); container = GIMP_TAG_ENTRY (popup->combo_entry)->container; tag_hash = container->tag_ref_counts; tag_list = g_hash_table_get_keys (tag_hash); tag_list = g_list_sort (tag_list, gimp_tag_compare_func); popup->tag_count = g_list_length (tag_list); popup->tag_data = g_new0 (PopupTagData, popup->tag_count); for (i = 0, tag_iterator = tag_list; i < popup->tag_count; i++, tag_iterator = g_list_next (tag_iterator)) { PopupTagData *tag_data = &popup->tag_data[i]; gint j; tag_data->tag = tag_iterator->data; tag_data->state = GTK_STATE_NORMAL; g_object_ref (tag_data->tag); for (j = 0; j < current_count; j++) { if (! gimp_tag_compare_with_string (tag_data->tag, current_tags[j])) { tag_data->state = GTK_STATE_SELECTED; break; } } } g_list_free (tag_list); g_strfreev (current_tags); if (GIMP_TAG_ENTRY (popup->combo_entry)->mode == GIMP_TAG_ENTRY_MODE_QUERY) { for (i = 0; i < popup->tag_count; i++) { if (popup->tag_data[i].state != GTK_STATE_SELECTED) { popup->tag_data[i].state = GTK_STATE_INSENSITIVE; } } gimp_container_foreach (GIMP_CONTAINER (container), (GFunc) gimp_tag_popup_check_can_toggle, popup); } frame_style = gtk_widget_get_style (popup->frame); width = (entry_allocation.width - 2 * frame_style->xthickness); height = (gimp_tag_popup_layout_tags (popup, width) + 2 * frame_style->ythickness); gdk_window_get_origin (gtk_widget_get_window (entry), &x, &y); max_height = entry_allocation.height * 10; screen_height = gdk_screen_get_height (gtk_widget_get_screen (entry)); popup_height = MIN (height, max_height); popup_rects[0].x = x; popup_rects[0].y = 0; popup_rects[0].width = entry_allocation.width; popup_rects[0].height = y + entry_allocation.height; popup_rects[1].x = x; popup_rects[1].y = y; popup_rects[1].width = popup_rects[0].width; popup_rects[1].height = screen_height - popup_rects[0].height; if (popup_rects[0].height >= popup_height) { popup_rect = popup_rects[0]; popup_rect.y += popup_rects[0].height - popup_height; popup_rect.height = popup_height; } else if (popup_rects[1].height >= popup_height) { popup_rect = popup_rects[1]; popup_rect.height = popup_height; } else { if (popup_rects[0].height >= popup_rects[1].height) { popup_rect = popup_rects[0]; popup_rect.y += popup->scroll_arrow_height + frame_style->ythickness; } else { popup_rect = popup_rects[1]; popup_rect.y -= popup->scroll_arrow_height + frame_style->ythickness; } popup_height = popup_rect.height; } if (popup_height < height) { popup->arrows_visible = TRUE; popup->upper_arrow_state = GTK_STATE_INSENSITIVE; gtk_alignment_set_padding (GTK_ALIGNMENT (popup->alignment), popup->scroll_arrow_height + 2, popup->scroll_arrow_height + 2, 0, 0); popup_height -= 2 * popup->scroll_arrow_height + 4; popup->scroll_height = height - popup_rect.height; popup->scroll_y = 0; popup->scroll_step = 0; } gtk_widget_set_size_request (popup->tag_area, width, popup_height); gtk_window_move (GTK_WINDOW (popup), popup_rect.x, popup_rect.y); gtk_window_resize (GTK_WINDOW (popup), popup_rect.width, popup_rect.height); }
GHashTable* p_gpg_list_keys(void) { gpgme_error_t error; GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)_p_gpg_free_key); gpgme_ctx_t ctx; error = gpgme_new(&ctx); if (error) { log_error("GPG: Could not list keys. %s %s", gpgme_strsource(error), gpgme_strerror(error)); return NULL; } error = gpgme_op_keylist_start(ctx, NULL, 0); if (error == GPG_ERR_NO_ERROR) { gpgme_key_t key; error = gpgme_op_keylist_next(ctx, &key); while (!error) { gpgme_subkey_t sub = key->subkeys; ProfPGPKey *p_pgpkey = _p_gpg_key_new(); p_pgpkey->id = strdup(sub->keyid); p_pgpkey->name = strdup(key->uids->uid); p_pgpkey->fp = strdup(sub->fpr); if (sub->can_encrypt) p_pgpkey->encrypt = TRUE; if (sub->can_authenticate) p_pgpkey->authenticate = TRUE; if (sub->can_certify) p_pgpkey->certify = TRUE; if (sub->can_sign) p_pgpkey->sign = TRUE; sub = sub->next; while (sub) { if (sub->can_encrypt) p_pgpkey->encrypt = TRUE; if (sub->can_authenticate) p_pgpkey->authenticate = TRUE; if (sub->can_certify) p_pgpkey->certify = TRUE; if (sub->can_sign) p_pgpkey->sign = TRUE; sub = sub->next; } g_hash_table_insert(result, strdup(p_pgpkey->name), p_pgpkey); gpgme_key_unref(key); error = gpgme_op_keylist_next(ctx, &key); } } error = gpgme_op_keylist_start(ctx, NULL, 1); if (error == GPG_ERR_NO_ERROR) { gpgme_key_t key; error = gpgme_op_keylist_next(ctx, &key); while (!error) { gpgme_subkey_t sub = key->subkeys; while (sub) { if (sub->secret) { ProfPGPKey *p_pgpkey = g_hash_table_lookup(result, key->uids->uid); if (p_pgpkey) { p_pgpkey->secret = TRUE; } } sub = sub->next; } gpgme_key_unref(key); error = gpgme_op_keylist_next(ctx, &key); } } gpgme_release(ctx); autocomplete_clear(key_ac); GList *ids = g_hash_table_get_keys(result); GList *curr = ids; while (curr) { ProfPGPKey *key = g_hash_table_lookup(result, curr->data); autocomplete_add(key_ac, key->id); curr = curr->next; } g_list_free(ids); return result; }
static void tracker_evt_update_orphans (tracker_evt_update_t *evt) { gboolean first = TRUE; GString *request_str; GList *subject, *subjects; GList *source, *sources; GRL_DEBUG ("%s: evt=%p", __FUNCTION__, evt); if (g_hash_table_size (evt->orphan_items) < 1) { tracker_evt_postupdate_sources (evt); return; } sources = grl_registry_get_sources (grl_registry_get_default (), FALSE); request_str = g_string_new (""); subjects = g_hash_table_get_keys (evt->orphan_items); subject = subjects; while (subject != NULL) { guint id = GPOINTER_TO_INT (subject->data); if (GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items, subject->data)) != GRL_CONTENT_REMOVED) { if (first) { g_string_append_printf (request_str, "%u", id); first = FALSE; } else { g_string_append_printf (request_str, ", %u", id); } } else { /* Notify all sources that a media been removed */ source = sources; while (source != NULL) { if (GRL_IS_TRACKER_SOURCE (source->data)) { GRL_DEBUG ("\tNotify id=%u source=%s p=%p", id, grl_source_get_name (GRL_SOURCE (source->data)), source->data); if (grl_tracker_source_can_notify (GRL_TRACKER_SOURCE (source->data))) { GrlMedia *media = grl_media_new (); gchar *str_id = g_strdup_printf ("%u", id); grl_media_set_id (media, str_id); g_free (str_id); grl_source_notify_change (GRL_SOURCE (source->data), media, GRL_CONTENT_REMOVED, FALSE); g_object_unref (media); } } source = source->next; } } subject = subject->next; } g_list_free (subjects); if (request_str->len > 0) { gchar *sparql_final = g_strdup_printf (TRACKER_MEDIA_ITEM, request_str->str); GRL_DEBUG ("\trequest : '%s'", sparql_final); tracker_sparql_connection_query_async (grl_tracker_connection, sparql_final, NULL, (GAsyncReadyCallback) tracker_evt_update_orphans_cb, evt); g_free (sparql_final); } else { tracker_evt_postupdate_sources (evt); } g_string_free (request_str, TRUE); }
APULSE_EXPORT int pa_mainloop_prepare(pa_mainloop *m, int timeout) { trace_info("P %s m=%p, timeout=%d\n", __func__, m, timeout); m->timeout = timeout; if (m->recreate_fds) { GList *keys = g_hash_table_get_keys(m->events_ht); GList *it; struct pollfd *tmp; m->nfds = g_list_length(keys) + 1; tmp = realloc(m->fds, m->nfds * sizeof(*m->fds)); if (!tmp) return -1; m->fds = tmp; m->fds[0].fd = m->wakeup_pipe[0]; m->fds[0].events = POLLIN; m->fds[0].revents = 0; /* special case for alsa pollfds */ int k = 1; m->alsa_special_cnt = 0; it = keys; while (it) { struct pa_io_event *ioe = it->data; if (ioe->events & 0x80000000u) { m->fds[k].fd = ioe->fd; m->fds[k].events = ioe->events & (~0x80000000u); m->fds[k].revents = 0; ioe->pollfd = &m->fds[k]; k ++; m->alsa_special_cnt ++; } it = g_list_next(it); } /* normal file descriptors */ it = keys; while (it) { struct pa_io_event *ioe = it->data; if ((ioe->events & 0x80000000u) == 0) { m->fds[k].fd = ioe->fd; m->fds[k].events = from_pa_io_event_flags(ioe->events); m->fds[k].revents = 0; ioe->pollfd = &m->fds[k]; k ++; } it = g_list_next(it); } m->nfds = k; g_list_free(keys); m->recreate_fds = 0; } return 0; }