int main (int argc, char **argv) { GOptionContext *context; GError *error = NULL; GDBusConnection *bus; GDBusProxy *mpris; GDBusProxy *queue; GApplication *app; gboolean loaded; gboolean scanned; GVariant *state; #ifdef ENABLE_NLS /* initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif /* setup */ setlocale (LC_ALL, ""); g_type_init (); g_set_prgname ("rhythmbox-client"); /* parse arguments */ context = g_option_context_new (NULL); g_option_context_add_main_entries (context, args, NULL); g_option_context_parse (context, &argc, &argv, &error); if (annoy (&error)) exit (1); rb_debug_init (debug); app = g_application_new ("org.gnome.Rhythmbox3", G_APPLICATION_IS_LAUNCHER); if (g_application_register (app, NULL, &error) == FALSE) { if (check_running) { rb_debug ("no running instance found"); exit (2); } else if (quit) { rb_debug ("no existing instance to quit"); exit (0); } rb_debug ("uh.. what?"); exit (0); } /* are we just checking if it's running? */ if (check_running) { rb_debug ("running instance found"); exit (0); } /* wait until it's ready to accept control */ state = g_action_group_get_action_state (G_ACTION_GROUP (app), "LoadURI"); if (state == NULL) { rb_debug ("couldn't get app startup state"); exit (0); } bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL); g_variant_get (state, "(bb)", &loaded, &scanned); if ((loaded && scanned) == FALSE) { GMainLoop *loop; GDBusProxy *app_proxy; rb_debug ("waiting for app startup"); loop = g_main_loop_new (NULL, FALSE); g_signal_connect (app, "action-state-changed", G_CALLBACK (state_changed_cb), loop); /* dbus implementation of GApplication doesn't do action state updates yet */ app_proxy = g_dbus_proxy_new_sync (bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, "org.gnome.Rhythmbox3", "/org/gnome/Rhythmbox3", "org.gtk.Actions", NULL, &error); if (app_proxy == NULL || proxy_has_name_owner (app_proxy) == FALSE) { g_warning ("unable to wait for app startup: %s", error->message); g_clear_error (&error); } else { g_object_set_data (G_OBJECT (app_proxy), "actual-app", app); g_signal_connect (app_proxy, "g-signal", G_CALLBACK (state_changed_signal_cb), loop); g_main_loop_run (loop); rb_debug ("app is now started enough"); } } /* create proxies */ mpris = g_dbus_proxy_new_sync (bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, "org.mpris.MediaPlayer2.rhythmbox", "/org/mpris/MediaPlayer2", "org.mpris.MediaPlayer2.Player", NULL, &error); if (mpris == NULL || proxy_has_name_owner (mpris) == FALSE) { g_warning ("MPRIS D-Bus interface not available, some things won't work"); if (next || previous || (seek != 0) || play || do_pause || play_pause || stop || volume_up || volume_down || (set_volume > -0.01)) { exit (1); } } queue = g_dbus_proxy_new_sync (bus, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, NULL, "org.gnome.Rhythmbox3", "/org/gnome/Rhythmbox3/PlayQueue", "org.gnome.Rhythmbox3.PlayQueue", NULL, &error); if (queue == NULL || proxy_has_name_owner (queue) == FALSE) { g_warning ("Play queue interface not available, some things won't work"); if (enqueue || clear_queue) { exit (1); } } /* activate or quit */ if (quit) { rb_debug ("quitting existing instance"); g_action_group_activate_action (G_ACTION_GROUP (app), "Quit", NULL); exit (0); } /* don't present if we're doing something else */ if (next || previous || (seek != 0) || clear_queue || play_uri || other_stuff || play || do_pause || play_pause || stop || print_playing || print_playing_format || (set_volume > -0.01) || volume_up || volume_down || print_volume /*|| mute || unmute*/ || (set_rating > -0.01)) no_present = TRUE; /* present */ if (!no_present) { g_application_activate (app); } /* set song rating */ if (set_rating >= 0.0 && set_rating <= 5.0) { rb_debug ("rate song"); rate_song (mpris, set_rating); } /* skip to next or previous track */ if (next) { rb_debug ("next track"); g_dbus_proxy_call_sync (mpris, "Next", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } else if (previous) { rb_debug ("previous track"); g_dbus_proxy_call_sync (mpris, "Previous", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } /* seek in track */ if (seek != 0) { GHashTable *properties; rb_debug ("seek"); properties = get_playing_song_info (mpris); if (properties != NULL) { GVariant *v = g_hash_table_lookup (properties, "mpris:trackid"); if (v != NULL) { g_dbus_proxy_call_sync (mpris, "SetPosition", g_variant_new ("(ox)", g_variant_get_string (v, NULL), seek), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } } } /* add/enqueue */ if (clear_queue) { g_dbus_proxy_call_sync (queue, "ClearQueue", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } if (other_stuff) { int i; for (i = 0; other_stuff[i] != NULL; i++) { GFile *file; char *fileuri; file = g_file_new_for_commandline_arg (other_stuff[i]); fileuri = g_file_get_uri (file); if (fileuri == NULL) { g_warning ("couldn't convert \"%s\" to a URI", other_stuff[i]); continue; } if (enqueue) { rb_debug ("enqueueing %s", fileuri); g_dbus_proxy_call_sync (queue, "AddToQueue", g_variant_new ("(s)", fileuri), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } else { rb_debug ("importing %s", fileuri); g_action_group_activate_action (G_ACTION_GROUP (app), "LoadURI", g_variant_new ("(sb)", fileuri, FALSE)); } g_free (fileuri); g_object_unref (file); } } /* select/activate/play source */ if (select_source) { rb_debug ("selecting source %s", select_source); g_action_group_activate_action (G_ACTION_GROUP (app), "ActivateSource", g_variant_new ("(su)", select_source, 0)); } else if (activate_source) { rb_debug ("activating source %s", activate_source); g_action_group_activate_action (G_ACTION_GROUP (app), "ActivateSource", g_variant_new ("(su)", activate_source, 1)); } else if (play_source) { rb_debug ("playing source %s", play_source); g_action_group_activate_action (G_ACTION_GROUP (app), "ActivateSource", g_variant_new ("(su)", play_source, 2)); } /* play uri */ if (play_uri) { GFile *file; char *fileuri; file = g_file_new_for_commandline_arg (play_uri); fileuri = g_file_get_uri (file); if (fileuri == NULL) { g_warning ("couldn't convert \"%s\" to a URI", play_uri); } else { rb_debug ("loading and playing %s", fileuri); g_action_group_activate_action (G_ACTION_GROUP (app), "LoadURI", g_variant_new ("(sb)", fileuri, TRUE)); annoy (&error); } g_free (fileuri); g_object_unref (file); } /* play/pause/stop */ if (mpris) { GVariant *v; gboolean is_playing = FALSE; v = g_dbus_proxy_get_cached_property (mpris, "PlaybackStatus"); if (v != NULL) { is_playing = (g_strcmp0 (g_variant_get_string (v, NULL), "Playing") == 0); g_variant_unref (v); } if (play || do_pause || play_pause) { if (is_playing != play || play_pause) { rb_debug ("calling PlayPause to change playback state"); g_dbus_proxy_call_sync (mpris, "PlayPause", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } else { rb_debug ("no need to change playback state"); } } else if (stop) { g_warning ("not implemented yet"); } } /* get/set volume, mute/unmute */ if (set_volume > -0.01) { g_dbus_proxy_call_sync (mpris, "org.freedesktop.DBus.Properties.Set", g_variant_new ("(ssv)", "org.mpris.MediaPlayer2.Player", "Volume", g_variant_new_double (set_volume)), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); } else if (volume_up || volume_down) { GVariant *v; v = g_dbus_proxy_get_cached_property (mpris, "Volume"); if (v != NULL) { set_volume = g_variant_get_double (v) + (volume_up ? 0.1 : -0.1); g_dbus_proxy_call_sync (mpris, "org.freedesktop.DBus.Properties.Set", g_variant_new ("(ssv)", "org.mpris.MediaPlayer2.Player", "Volume", g_variant_new_double (set_volume)), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); annoy (&error); g_variant_unref (v); } } /* no mute for now? */ /* } else if (unmute || mute) { org_gnome_Rhythmbox_Player_set_mute (player_proxy, unmute ? FALSE : TRUE, &error); annoy (&error); } */ if (print_volume) { gdouble volume = 1.0; GVariant *v = g_dbus_proxy_get_cached_property (mpris, "Volume"); if (v != NULL) { volume = g_variant_get_double (v); g_variant_unref (v); } g_print (_("Playback volume is %f.\n"), volume); } /* print playing song */ if (print_playing_format) { print_playing_song (mpris, print_playing_format); } else if (print_playing) { print_playing_song_default (mpris); } if (mpris) { g_object_unref (mpris); } g_dbus_connection_flush_sync (bus, NULL, NULL); g_option_context_free (context); return 0; }
static gboolean is_current_locale (const gchar *locale) { return g_strcmp0 (setlocale (LC_CTYPE, NULL), locale) == 0; }
static void set_default_gateway(struct gateway_data *data, enum connman_ipconfig_type type) { int index; int status4 = 0, status6 = 0; bool do_ipv4 = false, do_ipv6 = false; if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) do_ipv6 = true; else do_ipv4 = do_ipv6 = true; DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway, data->ipv6_gateway); if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn) { connman_inet_set_gateway_interface(data->index); data->ipv4_gateway->active = true; DBG("set %p index %d vpn %s index %d phy %s", data, data->index, data->ipv4_gateway->vpn_ip, data->ipv4_gateway->vpn_phy_index, data->ipv4_gateway->vpn_phy_ip); __connman_service_indicate_default(data->service); return; } if (do_ipv6 && data->ipv6_gateway && data->ipv6_gateway->vpn) { connman_inet_set_ipv6_gateway_interface(data->index); data->ipv6_gateway->active = true; DBG("set %p index %d vpn %s index %d phy %s", data, data->index, data->ipv6_gateway->vpn_ip, data->ipv6_gateway->vpn_phy_index, data->ipv6_gateway->vpn_phy_ip); __connman_service_indicate_default(data->service); return; } index = __connman_service_get_index(data->service); if (do_ipv4 && data->ipv4_gateway && g_strcmp0(data->ipv4_gateway->gateway, "0.0.0.0") == 0) { if (connman_inet_set_gateway_interface(index) < 0) return; goto done; } if (do_ipv6 && data->ipv6_gateway && g_strcmp0(data->ipv6_gateway->gateway, "::") == 0) { if (connman_inet_set_ipv6_gateway_interface(index) < 0) return; goto done; } if (do_ipv6 && data->ipv6_gateway) status6 = __connman_inet_add_default_to_table(RT_TABLE_MAIN, index, data->ipv6_gateway->gateway); if (do_ipv4 && data->ipv4_gateway) status4 = __connman_inet_add_default_to_table(RT_TABLE_MAIN, index, data->ipv4_gateway->gateway); if (status4 < 0 || status6 < 0) return; done: __connman_service_indicate_default(data->service); }
void roster_set_handler(xmpp_stanza_t *const stanza) { xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY); xmpp_stanza_t *item = xmpp_stanza_get_child_by_name(query, STANZA_NAME_ITEM); if (item == NULL) { return; } // if from attribute exists and it is not current users barejid, ignore push Jid *my_jid = jid_create(connection_get_fulljid()); const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); if (from && (strcmp(from, my_jid->barejid) != 0)) { jid_destroy(my_jid); return; } jid_destroy(my_jid); const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID); gchar *barejid_lower = g_utf8_strdown(barejid, -1); const char *name = xmpp_stanza_get_attribute(item, STANZA_ATTR_NAME); const char *sub = xmpp_stanza_get_attribute(item, STANZA_ATTR_SUBSCRIPTION); const char *ask = xmpp_stanza_get_attribute(item, STANZA_ATTR_ASK); // do not set nickname to empty string, set to NULL instead if (name && (strlen(name) == 0)) { name = NULL; } // remove from roster if (g_strcmp0(sub, "remove") == 0) { // remove barejid and name if (name == NULL) { name = barejid_lower; } roster_remove(name, barejid_lower); ui_roster_remove(barejid_lower); // otherwise update local roster } else { // check for pending out subscriptions gboolean pending_out = FALSE; if (ask && (strcmp(ask, "subscribe") == 0)) { pending_out = TRUE; } GSList *groups = _get_groups_from_item(item); // update the local roster PContact contact = roster_get_contact(barejid_lower); if (contact == NULL) { gboolean added = roster_add(barejid_lower, name, groups, sub, pending_out); if (added) { ui_roster_add(barejid_lower, name); } } else { sv_ev_roster_update(barejid_lower, name, groups, sub, pending_out); } } g_free(barejid_lower); return; }
void flickr_account_set_is_pro (FlickrAccount *self, const char *value) { self->is_pro = (g_strcmp0 (value, "1") == 0); }
/** Used in g_slist as a custom comparator */ static int linkpathcmp(struct link_pair *a, char *b) { return g_strcmp0(a->path, b); }
/* returns TRUE if OK was pressed. */ static gboolean georef_layer_dialog ( VikGeorefLayer *vgl, gpointer vp, GtkWindow *w, gboolean have_apply_button ) { GtkWidget *dialog = gtk_dialog_new_with_buttons (_("Layer Properties"), w, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL ); if ( have_apply_button ) gtk_dialog_add_button ( GTK_DIALOG(dialog), GTK_STOCK_APPLY, GTK_RESPONSE_APPLY ); gtk_dialog_add_button ( GTK_DIALOG(dialog), GTK_STOCK_OK, GTK_RESPONSE_ACCEPT ); /* Default to reject as user really needs to specify map file first */ gtk_dialog_set_default_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT ); GtkWidget *response_w = NULL; #if GTK_CHECK_VERSION (2, 20, 0) response_w = gtk_dialog_get_widget_for_response ( GTK_DIALOG(dialog), GTK_RESPONSE_REJECT ); #endif GtkWidget *table, *wfp_hbox, *wfp_label, *wfp_button, *ce_label, *cn_label, *xlabel, *ylabel, *imagelabel; changeable_widgets cw; GtkBox *dgbox = GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))); table = gtk_table_new ( 4, 2, FALSE ); gtk_box_pack_start ( dgbox, table, TRUE, TRUE, 0 ); wfp_hbox = gtk_hbox_new ( FALSE, 0 ); wfp_label = gtk_label_new ( _("World File Parameters:") ); wfp_button = gtk_button_new_with_label ( _("Load From File...") ); gtk_box_pack_start ( GTK_BOX(wfp_hbox), wfp_label, TRUE, TRUE, 0 ); gtk_box_pack_start ( GTK_BOX(wfp_hbox), wfp_button, FALSE, FALSE, 3 ); ce_label = gtk_label_new ( _("Corner pixel easting:") ); cw.ce_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, -15000000.0, 1500000.0, 1, 5, 0 ), 1, 4 ); gtk_widget_set_tooltip_text ( GTK_WIDGET(cw.ce_spin), _("the UTM \"easting\" value of the upper-left corner pixel of the map") ); cn_label = gtk_label_new ( _("Corner pixel northing:") ); cw.cn_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, -15000000.0, 15000000.0, 1, 5, 0 ), 1, 4 ); gtk_widget_set_tooltip_text ( GTK_WIDGET(cw.cn_spin), _("the UTM \"northing\" value of the upper-left corner pixel of the map") ); xlabel = gtk_label_new ( _("X (easting) scale (mpp): ")); ylabel = gtk_label_new ( _("Y (northing) scale (mpp): ")); cw.x_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 ); gtk_widget_set_tooltip_text ( GTK_WIDGET(cw.x_spin), _("the scale of the map in the X direction (meters per pixel)") ); cw.y_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new ( 4, VIK_VIEWPORT_MIN_ZOOM, VIK_VIEWPORT_MAX_ZOOM, 1, 5, 0 ), 1, 8 ); gtk_widget_set_tooltip_text ( GTK_WIDGET(cw.y_spin), _("the scale of the map in the Y direction (meters per pixel)") ); imagelabel = gtk_label_new ( _("Map Image:") ); cw.imageentry = vik_file_entry_new (GTK_FILE_CHOOSER_ACTION_OPEN, VF_FILTER_IMAGE, maybe_read_world_file, &cw); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.ce_spin), vgl->corner.easting ); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.cn_spin), vgl->corner.northing ); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.x_spin), vgl->mpp_easting ); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.y_spin), vgl->mpp_northing ); if ( vgl->image ) vik_file_entry_set_filename ( VIK_FILE_ENTRY(cw.imageentry), vgl->image ); gtk_table_attach_defaults ( GTK_TABLE(table), imagelabel, 0, 1, 0, 1 ); gtk_table_attach_defaults ( GTK_TABLE(table), cw.imageentry, 1, 2, 0, 1 ); gtk_table_attach_defaults ( GTK_TABLE(table), wfp_hbox, 0, 2, 1, 2 ); gtk_table_attach_defaults ( GTK_TABLE(table), xlabel, 0, 1, 2, 3 ); gtk_table_attach_defaults ( GTK_TABLE(table), cw.x_spin, 1, 2, 2, 3 ); gtk_table_attach_defaults ( GTK_TABLE(table), ylabel, 0, 1, 3, 4 ); gtk_table_attach_defaults ( GTK_TABLE(table), cw.y_spin, 1, 2, 3, 4 ); cw.tabs = gtk_notebook_new(); GtkWidget *table_utm = gtk_table_new ( 3, 2, FALSE ); gtk_table_attach_defaults ( GTK_TABLE(table_utm), ce_label, 0, 1, 0, 1 ); gtk_table_attach_defaults ( GTK_TABLE(table_utm), cw.ce_spin, 1, 2, 0, 1 ); gtk_table_attach_defaults ( GTK_TABLE(table_utm), cn_label, 0, 1, 1, 2 ); gtk_table_attach_defaults ( GTK_TABLE(table_utm), cw.cn_spin, 1, 2, 1, 2 ); GtkWidget *utm_hbox = gtk_hbox_new ( FALSE, 0 ); cw.utm_zone_spin = gtk_spin_button_new ((GtkAdjustment*)gtk_adjustment_new( vgl->corner.zone, 1, 60, 1, 5, 0 ), 1, 0 ); gtk_box_pack_start ( GTK_BOX(utm_hbox), gtk_label_new(_("Zone:")), TRUE, TRUE, 0 ); gtk_box_pack_start ( GTK_BOX(utm_hbox), cw.utm_zone_spin, TRUE, TRUE, 0 ); gtk_box_pack_start ( GTK_BOX(utm_hbox), gtk_label_new(_("Letter:")), TRUE, TRUE, 0 ); cw.utm_letter_entry = gtk_entry_new (); gtk_entry_set_max_length ( GTK_ENTRY(cw.utm_letter_entry), 1 ); gtk_entry_set_width_chars ( GTK_ENTRY(cw.utm_letter_entry), 2 ); gchar tmp_letter[2]; tmp_letter[0] = vgl->corner.letter; tmp_letter[1] = '\0'; gtk_entry_set_text ( GTK_ENTRY(cw.utm_letter_entry), tmp_letter ); gtk_box_pack_start ( GTK_BOX(utm_hbox), cw.utm_letter_entry, TRUE, TRUE, 0 ); gtk_table_attach_defaults ( GTK_TABLE(table_utm), utm_hbox, 0, 2, 2, 3 ); // Lat/Lon GtkWidget *table_ll = gtk_table_new ( 5, 2, FALSE ); GtkWidget *lat_tl_label = gtk_label_new ( _("Upper left latitude:") ); cw.lat_tl_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new (0.0,-90,90.0,0.05,0.1,0), 0.1, 6 ); GtkWidget *lon_tl_label = gtk_label_new ( _("Upper left longitude:") ); cw.lon_tl_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new (0.0,-180,180.0,0.05,0.1,0), 0.1, 6 ); GtkWidget *lat_br_label = gtk_label_new ( _("Lower right latitude:") ); cw.lat_br_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new (0.0,-90,90.0,0.05,0.1,0), 0.1, 6 ); GtkWidget *lon_br_label = gtk_label_new ( _("Lower right longitude:") ); cw.lon_br_spin = gtk_spin_button_new ( (GtkAdjustment *) gtk_adjustment_new (0.0,-180.0,180.0,0.05,0.1,0), 0.1, 6 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), lat_tl_label, 0, 1, 0, 1 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), cw.lat_tl_spin, 1, 2, 0, 1 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), lon_tl_label, 0, 1, 1, 2 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), cw.lon_tl_spin, 1, 2, 1, 2 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), lat_br_label, 0, 1, 2, 3 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), cw.lat_br_spin, 1, 2, 2, 3 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), lon_br_label, 0, 1, 3, 4 ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), cw.lon_br_spin, 1, 2, 3, 4 ); GtkWidget *calc_mpp_button = gtk_button_new_with_label ( _("Calculate MPP values from coordinates") ); gtk_widget_set_tooltip_text ( calc_mpp_button, _("Enter all corner coordinates before calculating the MPP values from the image size") ); gtk_table_attach_defaults ( GTK_TABLE(table_ll), calc_mpp_button, 0, 2, 4, 5 ); VikCoord vc; vik_coord_load_from_utm (&vc, VIK_COORD_LATLON, &(vgl->corner)); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.lat_tl_spin), vc.north_south ); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.lon_tl_spin), vc.east_west ); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.lat_br_spin), vgl->ll_br.lat ); gtk_spin_button_set_value ( GTK_SPIN_BUTTON(cw.lon_br_spin), vgl->ll_br.lon ); gtk_notebook_append_page(GTK_NOTEBOOK(cw.tabs), GTK_WIDGET(table_utm), gtk_label_new(_("UTM"))); gtk_notebook_append_page(GTK_NOTEBOOK(cw.tabs), GTK_WIDGET(table_ll), gtk_label_new(_("Latitude/Longitude"))); gtk_box_pack_start ( dgbox, cw.tabs, TRUE, TRUE, 0 ); GtkWidget *alpha_hbox = gtk_hbox_new ( FALSE, 0 ); // GTK3 => GtkWidget *alpha_scale = gtk_scale_new_with_range ( GTK_ORIENTATION_HORIZONTAL, 0, 255, 1 ); GtkWidget *alpha_scale = gtk_hscale_new_with_range ( 0, 255, 1 ); gtk_scale_set_digits ( GTK_SCALE(alpha_scale), 0 ); gtk_range_set_value ( GTK_RANGE(alpha_scale), vgl->alpha ); gtk_box_pack_start ( GTK_BOX(alpha_hbox), gtk_label_new(_("Alpha:")), TRUE, TRUE, 0 ); gtk_box_pack_start ( GTK_BOX(alpha_hbox), alpha_scale, TRUE, TRUE, 0 ); gtk_box_pack_start ( dgbox, alpha_hbox, TRUE, TRUE, 0 ); vgl->cw = cw; g_signal_connect ( G_OBJECT(vgl->cw.tabs), "switch-page", G_CALLBACK(switch_tab), vgl ); g_signal_connect ( G_OBJECT(calc_mpp_button), "clicked", G_CALLBACK(calculate_mpp_from_coords), vgl ); g_signal_connect_swapped ( G_OBJECT(wfp_button), "clicked", G_CALLBACK(georef_layer_dialog_load), &cw ); if ( response_w ) gtk_widget_grab_focus ( response_w ); gtk_widget_show_all ( dialog ); // Remember setting the notebook page must be done after the widget is visible. gint page_num = 0; if ( a_settings_get_integer ( VIK_SETTINGS_GEOREF_TAB, &page_num ) ) if ( page_num < 0 || page_num > 1 ) page_num = 0; gtk_notebook_set_current_page ( GTK_NOTEBOOK(cw.tabs), page_num ); gboolean answer = FALSE; gint resp = GTK_RESPONSE_APPLY; while ( resp == GTK_RESPONSE_APPLY ) { resp = gtk_dialog_run ( GTK_DIALOG(dialog) ); if ( resp == GTK_RESPONSE_ACCEPT || resp == GTK_RESPONSE_APPLY ) { align_coords ( vgl ); vgl->corner.easting = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(cw.ce_spin) ); vgl->corner.northing = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(cw.cn_spin) ); vgl->corner.zone = gtk_spin_button_get_value_as_int ( GTK_SPIN_BUTTON(cw.utm_zone_spin) ); const gchar *letter = gtk_entry_get_text ( GTK_ENTRY(cw.utm_letter_entry) ); if (*letter) vgl->corner.letter = toupper(*letter); vgl->mpp_easting = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(cw.x_spin) ); vgl->mpp_northing = gtk_spin_button_get_value ( GTK_SPIN_BUTTON(cw.y_spin) ); vgl->ll_br = get_ll_br (vgl); check_br_is_good_or_msg_user ( vgl ); // TODO check if image has changed otherwise no need to regenerate pixbuf if ( !vgl->pixbuf ) { if ( g_strcmp0 (vgl->image, vik_file_entry_get_filename(VIK_FILE_ENTRY(cw.imageentry)) ) != 0 ) { georef_layer_set_image ( vgl, vik_file_entry_get_filename(VIK_FILE_ENTRY(cw.imageentry)) ); georef_layer_load_image ( vgl, VIK_VIEWPORT(vp), FALSE ); } } vgl->alpha = (guint8) gtk_range_get_value ( GTK_RANGE(alpha_scale) ); if ( vgl->pixbuf && vgl->alpha <= 255 ) vgl->pixbuf = ui_pixbuf_set_alpha ( vgl->pixbuf, vgl->alpha ); if ( vgl->scaled && vgl->alpha <= 255 ) vgl->scaled = ui_pixbuf_set_alpha ( vgl->scaled, vgl->alpha ); a_settings_set_integer ( VIK_SETTINGS_GEOREF_TAB, gtk_notebook_get_current_page(GTK_NOTEBOOK(cw.tabs)) ); if ( resp == GTK_RESPONSE_APPLY ) { vik_layer_emit_update ( VIK_LAYER(vgl) ); answer = FALSE; } else answer = TRUE; } } gtk_widget_destroy ( GTK_WIDGET(dialog) ); return answer; }
static void sensor_changes (GUdevClient *client, gchar *action, GUdevDevice *device, SensorData *data) { guint i; if (g_strcmp0 (action, "remove") == 0) { for (i = 0; i < NUM_SENSOR_TYPES; i++) { GUdevDevice *dev = DEVICE_FOR_TYPE(i); if (!dev) continue; if (g_strcmp0 (g_udev_device_get_sysfs_path (device), g_udev_device_get_sysfs_path (dev)) == 0) { g_debug ("Sensor type %s got removed (%s)", driver_type_to_str (i), g_udev_device_get_sysfs_path (dev)); g_clear_object (&DEVICE_FOR_TYPE(i)); DRIVER_FOR_TYPE(i) = NULL; g_clear_pointer (&data->clients[i], g_hash_table_unref); data->clients[i] = create_clients_hash_table (); send_driver_changed_dbus_event (data, i); } } if (!any_sensors_left (data)) g_main_loop_quit (data->loop); } else if (g_strcmp0 (action, "add") == 0) { guint i; for (i = 0; i < G_N_ELEMENTS(drivers); i++) { SensorDriver *driver = (SensorDriver *) drivers[i]; if (!driver_type_exists (data, driver->type) && driver_discover (driver, device)) { g_debug ("Found hotplugged device %s of type %s at %s", g_udev_device_get_sysfs_path (device), driver_type_to_str (driver->type), driver->name); if (driver_open (driver, device, driver_type_to_callback_func (driver->type), data)) { GHashTable *ht; DEVICE_FOR_TYPE(driver->type) = g_object_ref (device); DRIVER_FOR_TYPE(driver->type) = (SensorDriver *) driver; send_driver_changed_dbus_event (data, driver->type); ht = data->clients[driver->type]; if (g_hash_table_size (ht) > 0) driver_set_polling (DRIVER_FOR_TYPE(driver->type), TRUE); } break; } } } }
static GDBusAuthMechanism * client_choose_mech_and_send_initial_response (GDBusAuth *auth, GCredentials *credentials_that_were_sent, const gchar* const *supported_auth_mechs, GPtrArray *attempted_auth_mechs, GDataOutputStream *dos, GCancellable *cancellable, GError **error) { GDBusAuthMechanism *mech; GType auth_mech_to_use_gtype; guint n; guint m; gchar *initial_response; gsize initial_response_len; gchar *encoded; gchar *s; again: mech = NULL; debug_print ("CLIENT: Trying to choose mechanism"); /* find an authentication mechanism to try, if any */ auth_mech_to_use_gtype = (GType) 0; for (n = 0; supported_auth_mechs[n] != NULL; n++) { gboolean attempted_already; attempted_already = FALSE; for (m = 0; m < attempted_auth_mechs->len; m++) { if (g_strcmp0 (supported_auth_mechs[n], attempted_auth_mechs->pdata[m]) == 0) { attempted_already = TRUE; break; } } if (!attempted_already) { auth_mech_to_use_gtype = find_mech_by_name (auth, supported_auth_mechs[n]); if (auth_mech_to_use_gtype != (GType) 0) break; } } if (auth_mech_to_use_gtype == (GType) 0) { guint n; gchar *available; GString *tried_str; debug_print ("CLIENT: Exhausted all available mechanisms"); available = g_strjoinv (", ", (gchar **) supported_auth_mechs); tried_str = g_string_new (NULL); for (n = 0; n < attempted_auth_mechs->len; n++) { if (n > 0) g_string_append (tried_str, ", "); g_string_append (tried_str, attempted_auth_mechs->pdata[n]); } g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Exhausted all available authentication mechanisms (tried: %s) (available: %s)"), tried_str->str, available); g_string_free (tried_str, TRUE); g_free (available); goto out; } /* OK, decided on a mechanism - let's do this thing */ mech = g_object_new (auth_mech_to_use_gtype, "stream", auth->priv->stream, "credentials", credentials_that_were_sent, NULL); debug_print ("CLIENT: Trying mechanism `%s'", _g_dbus_auth_mechanism_get_name (auth_mech_to_use_gtype)); g_ptr_array_add (attempted_auth_mechs, (gpointer) _g_dbus_auth_mechanism_get_name (auth_mech_to_use_gtype)); /* the auth mechanism may not be supported * (for example, EXTERNAL only works if credentials were exchanged) */ if (!_g_dbus_auth_mechanism_is_supported (mech)) { debug_print ("CLIENT: Mechanism `%s' says it is not supported", _g_dbus_auth_mechanism_get_name (auth_mech_to_use_gtype)); g_object_unref (mech); mech = NULL; goto again; } initial_response_len = -1; initial_response = _g_dbus_auth_mechanism_client_initiate (mech, &initial_response_len); #if 0 g_printerr ("using auth mechanism with name `%s' of type `%s' with initial response `%s'\n", _g_dbus_auth_mechanism_get_name (auth_mech_to_use_gtype), g_type_name (G_TYPE_FROM_INSTANCE (mech)), initial_response); #endif if (initial_response != NULL) { //g_printerr ("initial_response = `%s'\n", initial_response); encoded = hexencode (initial_response); s = g_strdup_printf ("AUTH %s %s\r\n", _g_dbus_auth_mechanism_get_name (auth_mech_to_use_gtype), encoded); g_free (initial_response); g_free (encoded); } else { s = g_strdup_printf ("AUTH %s\r\n", _g_dbus_auth_mechanism_get_name (auth_mech_to_use_gtype)); } debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_object_unref (mech); mech = NULL; g_free (s); goto out; } g_free (s); out: return mech; }
/** * as_app_validate: * @app: a #AsApp instance. * @flags: the #AsAppValidateFlags to use, e.g. %AS_APP_VALIDATE_FLAG_NONE * @error: A #GError or %NULL. * * Validates data in the instance for style and consitency. * * Returns: (transfer container) (element-type AsProblem): A list of problems, or %NULL * * Since: 0.1.4 **/ GPtrArray * as_app_validate (AsApp *app, AsAppValidateFlags flags, GError **error) { AsAppProblems problems; AsAppValidateHelper helper; GError *error_local = NULL; GHashTable *urls; GList *l; GPtrArray *probs = NULL; const gchar *description; const gchar *id_full; const gchar *key; const gchar *license; const gchar *name; const gchar *summary; const gchar *tmp; const gchar *update_contact; gboolean deprectated_failure = FALSE; gboolean require_contactdetails = TRUE; gboolean require_copyright = FALSE; gboolean require_project_license = FALSE; gboolean require_translations = FALSE; gboolean require_url = TRUE; gboolean ret; guint length_name_max = 30; guint length_name_min = 3; guint length_summary_max = 100; guint length_summary_min = 8; guint number_para_max = 4; guint number_para_min = 2; guint str_len; _cleanup_list_free_ GList *keys = NULL; /* relax the requirements a bit */ if ((flags & AS_APP_VALIDATE_FLAG_RELAX) > 0) { length_name_max = 100; length_summary_max = 200; require_contactdetails = FALSE; require_url = FALSE; number_para_max = 10; number_para_min = 1; } /* make the requirements more strict */ if ((flags & AS_APP_VALIDATE_FLAG_STRICT) > 0) { deprectated_failure = TRUE; require_copyright = TRUE; require_translations = TRUE; require_project_license = TRUE; } /* set up networking */ helper.probs = g_ptr_array_new_with_free_func ((GDestroyNotify) g_object_unref); helper.screenshot_urls = g_ptr_array_new_with_free_func (g_free); helper.flags = flags; helper.previous_para_was_short = FALSE; helper.para_chars_before_list = 0; helper.number_paragraphs = 0; ret = as_app_validate_setup_networking (&helper, error); if (!ret) goto out; /* success, enough */ probs = helper.probs; /* id */ ret = FALSE; id_full = as_app_get_id_full (app); switch (as_app_get_id_kind (app)) { case AS_ID_KIND_DESKTOP: if (g_str_has_suffix (id_full, ".desktop")) ret = TRUE; break; case AS_ID_KIND_FONT: if (g_str_has_suffix (id_full, ".ttf")) ret = TRUE; else if (g_str_has_suffix (id_full, ".otf")) ret = TRUE; break; case AS_ID_KIND_INPUT_METHOD: if (g_str_has_suffix (id_full, ".xml")) ret = TRUE; else if (g_str_has_suffix (id_full, ".db")) ret = TRUE; break; case AS_ID_KIND_CODEC: if (g_str_has_prefix (id_full, "gstreamer")) ret = TRUE; break; case AS_ID_KIND_UNKNOWN: ai_app_validate_add (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID, "<id> has invalid type attribute"); break; case AS_ID_KIND_ADDON: /* anything goes */ ret = TRUE; default: break; } if (!ret) { ai_app_validate_add (probs, AS_PROBLEM_KIND_MARKUP_INVALID, "<id> does not have correct extension for kind"); } /* metadata_license */ license = as_app_get_metadata_license (app); if (license != NULL) { if (g_strcmp0 (license, "CC0-1.0") != 0 && g_strcmp0 (license, "CC-BY-3.0") != 0 && g_strcmp0 (license, "CC-BY-SA-3.0") != 0 && g_strcmp0 (license, "GFDL-1.3") != 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, "<metadata_license> is not valid"); } } if (license == NULL) { switch (as_app_get_source_kind (app)) { case AS_APP_SOURCE_KIND_APPDATA: case AS_APP_SOURCE_KIND_METAINFO: ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_MISSING, "<metadata_license> is not present"); break; default: break; } } /* project_license */ license = as_app_get_project_license (app); if (license != NULL) { ret = as_app_validate_license (license, &error_local); if (!ret) { g_prefix_error (&error_local, "<project_license> is not valid: "); ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, error_local->message); g_clear_error (&error_local); } } if (require_project_license && license == NULL) { switch (as_app_get_source_kind (app)) { case AS_APP_SOURCE_KIND_APPDATA: case AS_APP_SOURCE_KIND_METAINFO: ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_MISSING, "<project_license> is not present"); break; default: break; } } /* updatecontact */ update_contact = as_app_get_update_contact (app); if (g_strcmp0 (update_contact, "someone_who_cares@upstream_project.org") == 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, "<update_contact> is still set to a dummy value"); } if (update_contact != NULL && strlen (update_contact) < 6) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<update_contact> is too short"); } if (require_contactdetails && update_contact == NULL) { switch (as_app_get_source_kind (app)) { case AS_APP_SOURCE_KIND_APPDATA: case AS_APP_SOURCE_KIND_METAINFO: ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_MISSING, "<updatecontact> is not present"); break; default: break; } } /* only found for files */ problems = as_app_get_problems (app); if (as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_APPDATA || as_app_get_source_kind (app) == AS_APP_SOURCE_KIND_METAINFO) { if ((problems & AS_APP_PROBLEM_NO_XML_HEADER) > 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_MARKUP_INVALID, "<?xml> header not found"); } if (require_copyright && (problems & AS_APP_PROBLEM_NO_COPYRIGHT_INFO) > 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_VALUE_MISSING, "<!-- Copyright [year] [name] --> is not present"); } } /* check for things that have to exist */ if (as_app_get_id_full (app) == NULL) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_MISSING, "<id> is not present"); } /* url */ urls = as_app_get_urls (app); keys = g_hash_table_get_keys (urls); for (l = keys; l != NULL; l = l->next) { key = l->data; if (g_strcmp0 (key, "unknown") == 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, "<url> type invalid"); } tmp = g_hash_table_lookup (urls, key); if (!g_str_has_prefix (tmp, "http://") && !g_str_has_prefix (tmp, "https://")) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_INVALID, "<url> does not start with 'http://'"); } } /* screenshots */ as_app_validate_screenshots (app, &helper); /* releases */ ret = as_app_validate_releases (app, &helper, error); if (!ret) goto out; /* name */ name = as_app_get_name (app, "C"); if (name != NULL) { str_len = strlen (name); if (str_len < length_name_min) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<name> is too short"); } if (str_len > length_name_max) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<name> is too long"); } if (ai_app_validate_fullstop_ending (name)) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<name> cannot end in '.'"); } if (as_app_validate_has_hyperlink (name)) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<name> cannot contain a hyperlink"); } } /* comment */ summary = as_app_get_comment (app, "C"); if (summary != NULL) { str_len = strlen (summary); if (str_len < length_summary_min) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<summary> is too short"); } if (str_len > length_summary_max) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<summary> is too long"); } if (ai_app_validate_fullstop_ending (summary)) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<summary> cannot end in '.'"); } if (as_app_validate_has_hyperlink (summary)) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<summary> cannot contain a hyperlink"); } } if (summary != NULL && name != NULL && strlen (summary) < strlen (name)) { ai_app_validate_add (probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<summary> is shorter than <name>"); } description = as_app_get_description (app, "C"); if (description != NULL) { ret = as_app_validate_description (description, &helper, number_para_min, number_para_max, &error_local); if (!ret) { ai_app_validate_add (probs, AS_PROBLEM_KIND_MARKUP_INVALID, error_local->message); g_error_free (error_local); } } if (require_translations) { if (name != NULL && as_app_get_name_size (app) == 1 && (problems & AS_APP_PROBLEM_INTLTOOL_NAME) == 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TRANSLATIONS_REQUIRED, "<name> has no translations"); } if (summary != NULL && as_app_get_comment_size (app) == 1 && (problems & AS_APP_PROBLEM_INTLTOOL_SUMMARY) == 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TRANSLATIONS_REQUIRED, "<summary> has no translations"); } if (description != NULL && as_app_get_description_size (app) == 1 && (problems & AS_APP_PROBLEM_INTLTOOL_DESCRIPTION) == 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_TRANSLATIONS_REQUIRED, "<description> has no translations"); } } /* using deprecated names */ if (deprectated_failure && (problems & AS_APP_PROBLEM_DEPRECATED_LICENCE) > 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_ATTRIBUTE_INVALID, "<licence> is deprecated, use " "<metadata_license> instead"); } if ((problems & AS_APP_PROBLEM_MULTIPLE_ENTRIES) > 0) { ai_app_validate_add (probs, AS_PROBLEM_KIND_MARKUP_INVALID, "<application> used more than once"); } /* require homepage */ if (require_url && as_app_get_url_item (app, AS_URL_KIND_HOMEPAGE) == NULL) { switch (as_app_get_source_kind (app)) { case AS_APP_SOURCE_KIND_APPDATA: case AS_APP_SOURCE_KIND_METAINFO: ai_app_validate_add (probs, AS_PROBLEM_KIND_TAG_MISSING, "<url> is not present"); break; default: break; } } out: g_ptr_array_unref (helper.screenshot_urls); if (helper.session != NULL) g_object_unref (helper.session); return probs; }
static GVariant * _get_player_property_cb (GDBusConnection *connection, const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *property_name, GError **error, gpointer user_data) { MexMprisPluginPrivate *priv = MEX_MPRIS_PLUGIN (user_data)->priv; ClutterMedia *media; GVariant *v = NULL; media = priv->media; if (g_strcmp0 ("PlaybackStatus", property_name) == 0) { /* Doesn't map to ClutterMedia straight away so try to emulate. * Playback could theoretically be paused at progress 0.0 but well ...*/ gdouble progress = clutter_media_get_progress (media); gboolean playing = clutter_media_get_playing (media); if (playing) v = g_variant_new_string ("Playing"); else if (progress != 0) v = g_variant_new_string ("Paused"); else v = g_variant_new_string ("Stopped"); } else if (g_strcmp0 ("LoopStatus", property_name) == 0) v = g_variant_new_string ("None"); else if (g_strcmp0 ("Rate", property_name) == 0 || g_strcmp0 ("MinimumRate", property_name) == 0 || g_strcmp0 ("MinimumRate", property_name) == 0 ) v = g_variant_new_double (1.0); else if (g_strcmp0 ("Shuffle", property_name) == 0) v = g_variant_new_boolean (FALSE); else if (g_strcmp0 ("Volume", property_name) == 0) v = g_variant_new_double (clutter_media_get_audio_volume (media)); else if (g_strcmp0 ("Position", property_name) == 0) { gdouble duration_s = clutter_media_get_duration (media); gdouble progress_rel = clutter_media_get_progress (media); gint64 position_ms = duration_s * 1000000 * progress_rel; v = g_variant_new_int64 (position_ms); } else if (g_strcmp0 ("CanGoNext", property_name) == 0 || g_strcmp0 ("CanGoPrevious", property_name) == 0 || g_strcmp0 ("CanPlay", property_name) == 0 || g_strcmp0 ("CanControl", property_name) == 0 || g_strcmp0 ("CanPause", property_name) == 0) v = g_variant_new_boolean (TRUE); else if (g_strcmp0 ("CanSeek", property_name) == 0) v = g_variant_new_boolean (clutter_media_get_can_seek (media)); if (v) return v; g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_NOT_SUPPORTED, "Property %s.%s not supported", interface_name, property_name); return NULL; }
/** * as_app_validate_description: **/ static gboolean as_app_validate_description (const gchar *xml, AsAppValidateHelper *helper, guint number_para_min, guint number_para_max, GError **error) { GNode *l; GNode *l2; _cleanup_node_unref_ GNode *node; /* parse xml */ node = as_node_from_xml (xml, -1, AS_NODE_FROM_XML_FLAG_NONE, error); if (node == NULL) return FALSE; helper->number_paragraphs = 0; helper->previous_para_was_short = FALSE; for (l = node->children; l != NULL; l = l->next) { if (g_strcmp0 (as_node_get_name (l), "p") == 0) { if (as_node_get_attribute (l, "xml:lang") != NULL) continue; as_app_validate_description_para (as_node_get_data (l), helper); } else if (g_strcmp0 (as_node_get_name (l), "ul") == 0 || g_strcmp0 (as_node_get_name (l), "ol") == 0) { as_app_validate_description_list (as_node_get_data (l), helper); for (l2 = l->children; l2 != NULL; l2 = l2->next) { if (g_strcmp0 (as_node_get_name (l2), "li") == 0) { if (as_node_get_attribute (l2, "xml:lang") != NULL) continue; as_app_validate_description_li (as_node_get_data (l2), helper); } else { /* only <li> supported */ g_set_error (error, AS_APP_ERROR, AS_APP_ERROR_FAILED, "invalid markup: <%s> follows <%s>", as_node_get_name (l2), as_node_get_name (l)); return FALSE; } } } else { /* only <p>, <ol> and <ul> supported */ g_set_error (error, AS_APP_ERROR, AS_APP_ERROR_FAILED, "invalid markup: tag <%s> invalid here", as_node_get_name (l)); return FALSE; } } /* previous paragraph wasn't long enough */ if (helper->previous_para_was_short) { ai_app_validate_add (helper->probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "<p> is too short"); } if (helper->number_paragraphs < number_para_min) { ai_app_validate_add (helper->probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "Not enough <p> tags for a good description"); } if (helper->number_paragraphs > number_para_max) { ai_app_validate_add (helper->probs, AS_PROBLEM_KIND_STYLE_INCORRECT, "Too many <p> tags for a good description"); } return TRUE; }
/** * @brief Parse the entity string and resolve all static light sources. Sources which * are very close to each other are merged. Their colors are blended according * to their light value (intensity). */ void R_LoadBspLights(r_bsp_model_t *bsp) { vec3_t origin, color; vec_t radius; memset(&r_bsp_light_state, 0, sizeof(r_bsp_light_state)); const r_bsp_light_state_t *s = &r_bsp_light_state; R_ResolveBspLightParameters(); // iterate the world surfaces for surface lights const r_bsp_surface_t *surf = bsp->surfaces; for (uint16_t i = 0; i < bsp->num_surfaces; i++, surf++) { // light-emitting surfaces are of course lights if ((surf->texinfo->flags & SURF_LIGHT) && surf->texinfo->value) { VectorMA(surf->center, 1.0, surf->normal, origin); radius = sqrt(surf->texinfo->light * sqrt(surf->area) * BSP_LIGHT_SURFACE_RADIUS_SCALE); R_AddBspLight(bsp, origin, surf->texinfo->emissive, radius * s->brightness); } } // parse the entity string for point lights const char *ents = Cm_EntityString(); VectorClear(origin); radius = BSP_LIGHT_POINT_DEFAULT_RADIUS * s->brightness; VectorSet(color, 1.0, 1.0, 1.0); char class_name[MAX_QPATH]; _Bool entity = false, light = false; while (true) { const char *c = ParseToken(&ents); if (!strlen(c)) { break; } if (*c == '{') { entity = true; } if (!entity) { // skip any whitespace between ents continue; } if (*c == '}') { entity = false; if (light) { // add it R_AddBspLight(bsp, origin, color, radius * BSP_LIGHT_POINT_RADIUS_SCALE); radius = BSP_LIGHT_POINT_DEFAULT_RADIUS; VectorSet(color, 1.0, 1.0, 1.0); light = false; } } if (!g_strcmp0(c, "classname")) { c = ParseToken(&ents); g_strlcpy(class_name, c, sizeof(class_name)); if (!strncmp(c, "light", 5)) { // light, light_spot, etc.. light = true; } continue; } if (!g_strcmp0(c, "origin")) { sscanf(ParseToken(&ents), "%f %f %f", &origin[0], &origin[1], &origin[2]); continue; } if (!g_strcmp0(c, "light")) { radius = atof(ParseToken(&ents)) * s->brightness; continue; } if (!g_strcmp0(c, "_color")) { sscanf(ParseToken(&ents), "%f %f %f", &color[0], &color[1], &color[2]); ColorFilter(color, color, s->brightness, s->saturation, s->contrast); continue; } } // allocate the lights array and copy them in bsp->num_bsp_lights = g_slist_length(r_bsp_light_state.lights); bsp->bsp_lights = Mem_LinkMalloc(sizeof(r_bsp_light_t) * bsp->num_bsp_lights, bsp); GSList *e = r_bsp_light_state.lights; r_bsp_light_t *bl = bsp->bsp_lights; while (e) { *bl++ = *((r_bsp_light_t *) e->data); e = e->next; } // reset state g_slist_free_full(r_bsp_light_state.lights, Mem_Free); r_bsp_light_state.lights = NULL; Com_Debug(DEBUG_RENDERER, "Loaded %d bsp lights\n", bsp->num_bsp_lights); }
static void feature_setup (CEPageDcb *self, NMSettingDcb *s_dcb, const Feature *f) { CEPage *parent = CE_PAGE (self); GtkWidget *widget; NMSettingDcbFlags flags = NM_SETTING_DCB_FLAG_NONE; gboolean enabled; EnableInfo *info; if (s_dcb) g_object_get (G_OBJECT (s_dcb), f->flags_prop, (guint32 *) &flags, NULL); enabled = flags & NM_SETTING_DCB_FLAG_ENABLE; /* Enable */ widget = get_widget (parent->builder, f->prefix, "_enable_checkbutton"); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), enabled); info = g_malloc0 (sizeof (EnableInfo)); info->f = f; info->page = parent; g_signal_connect_data (widget, "toggled", G_CALLBACK (enable_toggled_cb), info, free_enable_info, 0); /* Advertise */ widget = get_widget (parent->builder, f->prefix, "_advertise_checkbutton"); gtk_widget_set_sensitive (widget, enabled); if (enabled) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), flags & NM_SETTING_DCB_FLAG_ADVERTISE); g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), self); /* Willing */ widget = get_widget (parent->builder, f->prefix, "_willing_checkbutton"); gtk_widget_set_sensitive (widget, enabled); if (enabled) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), flags & NM_SETTING_DCB_FLAG_WILLING); g_signal_connect_swapped (widget, "toggled", G_CALLBACK (ce_page_changed), self); if (f->priority_prop) { gint priority = -1; if (s_dcb) g_object_get (G_OBJECT (s_dcb), f->priority_prop, &priority, NULL); priority = CLAMP (priority, -1, 7); widget = get_widget (parent->builder, f->prefix, "_priority_combo"); gtk_widget_set_sensitive (widget, enabled); gtk_combo_box_set_active (GTK_COMBO_BOX (widget), priority + 1); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), self); } if (f->options_func) { widget = get_widget (parent->builder, f->prefix, "_options_button"); gtk_widget_set_sensitive (widget, enabled); g_signal_connect_swapped (widget, "clicked", G_CALLBACK (f->options_func), self); } /* Set up the FCoE mode combo */ if (!strcmp (f->prefix, "fcoe")) { const char *mode = s_dcb ? nm_setting_dcb_get_app_fcoe_mode (s_dcb) : NULL; guint idx = 0; widget = get_widget (info->page->builder, info->f->prefix, "_mode_combo"); if (g_strcmp0 (mode, NM_SETTING_DCB_FCOE_MODE_VN2VN) == 0) idx = 1; gtk_combo_box_set_active (GTK_COMBO_BOX (widget), idx); gtk_widget_set_sensitive (widget, enabled); g_signal_connect_swapped (widget, "changed", G_CALLBACK (ce_page_changed), self); } }
static gboolean gnc_reconcile_view_tooltip_cb (GNCQueryView *qview, gint x, gint y, gboolean keyboard_mode, GtkTooltip *tooltip, gpointer *user_data) { GtkTreeModel* model; GtkTreeIter iter; if (gtk_tree_view_get_tooltip_context (GTK_TREE_VIEW (qview), &x, &y, keyboard_mode, &model, NULL, &iter)) { GtkTreeViewColumn *col; GList *cols; gint col_pos, col_width; gchar* desc_text = NULL; /* Are we in keyboard tooltip mode, CTRL+F1 */ if (keyboard_mode == FALSE) { if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (qview), x, y, NULL, &col, NULL, NULL) == FALSE) return FALSE; } else gtk_tree_view_get_cursor (GTK_TREE_VIEW (qview), NULL, &col); cols = gtk_tree_view_get_columns (GTK_TREE_VIEW (qview)); col_width = gtk_tree_view_column_get_width (col); col_pos = g_list_index (cols, col); g_list_free (cols); /* If column is not description, do not show tooltip */ if (col_pos != 2) return FALSE; gtk_tree_model_get (model, &iter, 3, &desc_text, -1); if (desc_text) { PangoLayout* layout; gint text_width; gint root_x, root_y; gint cur_x, cur_y; layout = gtk_widget_create_pango_layout (GTK_WIDGET (qview), desc_text); pango_layout_get_pixel_size (layout, &text_width, NULL); g_object_unref (layout); /* If text_width + 10 <= column_width, do not show tooltip */ if ((text_width + 10) <= col_width) { g_free (desc_text); return FALSE; } if (keyboard_mode == FALSE) { GdkScreen *screen; GtkWindow *tip_win = NULL; GdkWindow *parent_window, *temp_window; GList *win_list, *node; parent_window = gtk_widget_get_parent_window (GTK_WIDGET (qview)); temp_window = gdk_window_get_pointer (parent_window, &cur_x, &cur_y, NULL); gdk_window_get_origin (parent_window, &root_x, &root_y); screen = gtk_widget_get_screen (GTK_WIDGET (qview)); /* Get a list of toplevel windows */ win_list = gtk_window_list_toplevels (); /* Look for the gtk-tooltip window, we do this as gtk_widget_get_tooltip_window does not seem to work for the default tooltip window, custom yes */ for (node = win_list; node != NULL; node = node->next) { if (g_strcmp0 (gtk_widget_get_name (node->data), "gtk-tooltip") == 0) tip_win = node->data; } g_list_free (win_list); gtk_tooltip_set_text (tooltip, desc_text); if (GTK_IS_WINDOW (tip_win)) { GdkRectangle monitor; GtkRequisition requisition; gint monitor_num; gint x, y; gtk_widget_size_request (GTK_WIDGET (tip_win), &requisition); x = root_x + cur_x + 10; y = root_y + cur_y + 10; monitor_num = gdk_screen_get_monitor_at_point (screen, x, y); gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); if (x + requisition.width > monitor.x + monitor.width) x -= x - (monitor.x + monitor.width) + requisition.width; else if (x < monitor.x) x = monitor.x; if (y + requisition.height > monitor.y + monitor.height) y -= y - (monitor.y + monitor.height) + requisition.height; gtk_window_move (tip_win, x, y); } } gtk_tooltip_set_text (tooltip, desc_text); g_free (desc_text); return TRUE; } } return FALSE; }
gchar * _g_dbus_auth_run_client (GDBusAuth *auth, GDBusCapabilityFlags offered_capabilities, GDBusCapabilityFlags *out_negotiated_capabilities, GCancellable *cancellable, GError **error) { gchar *s; GDataInputStream *dis; GDataOutputStream *dos; GCredentials *credentials; gchar *ret_guid; gchar *line; gsize line_length; gchar **supported_auth_mechs; GPtrArray *attempted_auth_mechs; GDBusAuthMechanism *mech; ClientState state; GDBusCapabilityFlags negotiated_capabilities; debug_print ("CLIENT: initiating"); ret_guid = NULL; supported_auth_mechs = NULL; attempted_auth_mechs = g_ptr_array_new (); mech = NULL; negotiated_capabilities = 0; credentials = NULL; dis = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (auth->priv->stream))); dos = G_DATA_OUTPUT_STREAM (g_data_output_stream_new (g_io_stream_get_output_stream (auth->priv->stream))); g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (dis), FALSE); g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (dos), FALSE); g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF); #ifdef G_OS_UNIX if (G_IS_UNIX_CONNECTION (auth->priv->stream) && g_unix_credentials_message_is_supported ()) { credentials = g_credentials_new (); if (!g_unix_connection_send_credentials (G_UNIX_CONNECTION (auth->priv->stream), cancellable, error)) goto out; } else { if (!g_data_output_stream_put_byte (dos, '\0', cancellable, error)) goto out; } #else if (!g_data_output_stream_put_byte (dos, '\0', cancellable, error)) goto out; #endif if (credentials != NULL) { if (G_UNLIKELY (_g_dbus_debug_authentication ())) { s = g_credentials_to_string (credentials); debug_print ("CLIENT: sent credentials `%s'", s); g_free (s); } } else { debug_print ("CLIENT: didn't send any credentials"); } /* TODO: to reduce roundtrips, try to pick an auth mechanism to start with */ /* Get list of supported authentication mechanisms */ s = "AUTH\r\n"; debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; state = CLIENT_STATE_WAITING_FOR_REJECT; while (TRUE) { switch (state) { case CLIENT_STATE_WAITING_FOR_REJECT: debug_print ("CLIENT: WaitingForReject"); line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error); if (line == NULL) goto out; debug_print ("CLIENT: WaitingForReject, read '%s'", line); foobar: if (!g_str_has_prefix (line, "REJECTED ")) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "In WaitingForReject: Expected `REJECTED am1 am2 ... amN', got `%s'", line); g_free (line); goto out; } if (supported_auth_mechs == NULL) { supported_auth_mechs = g_strsplit (line + sizeof ("REJECTED ") - 1, " ", 0); #if 0 for (n = 0; supported_auth_mechs != NULL && supported_auth_mechs[n] != NULL; n++) g_printerr ("supported_auth_mechs[%d] = `%s'\n", n, supported_auth_mechs[n]); #endif } g_free (line); mech = client_choose_mech_and_send_initial_response (auth, credentials, (const gchar* const *) supported_auth_mechs, attempted_auth_mechs, dos, cancellable, error); if (mech == NULL) goto out; if (_g_dbus_auth_mechanism_client_get_state (mech) == G_DBUS_AUTH_MECHANISM_STATE_WAITING_FOR_DATA) state = CLIENT_STATE_WAITING_FOR_DATA; else state = CLIENT_STATE_WAITING_FOR_OK; break; case CLIENT_STATE_WAITING_FOR_OK: debug_print ("CLIENT: WaitingForOK"); line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error); if (line == NULL) goto out; debug_print ("CLIENT: WaitingForOK, read `%s'", line); if (g_str_has_prefix (line, "OK ")) { if (!g_dbus_is_guid (line + 3)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Invalid OK response `%s'", line); g_free (line); goto out; } ret_guid = g_strdup (line + 3); g_free (line); if (offered_capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING) { s = "NEGOTIATE_UNIX_FD\r\n"; debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; state = CLIENT_STATE_WAITING_FOR_AGREE_UNIX_FD; } else { s = "BEGIN\r\n"; debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; /* and we're done! */ goto out; } } else if (g_str_has_prefix (line, "REJECTED ")) { goto foobar; } else { /* TODO: handle other valid responses */ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "In WaitingForOk: unexpected response `%s'", line); g_free (line); goto out; } break; case CLIENT_STATE_WAITING_FOR_AGREE_UNIX_FD: debug_print ("CLIENT: WaitingForAgreeUnixFD"); line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error); if (line == NULL) goto out; debug_print ("CLIENT: WaitingForAgreeUnixFD, read=`%s'", line); if (g_strcmp0 (line, "AGREE_UNIX_FD") == 0) { g_free (line); negotiated_capabilities |= G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING; s = "BEGIN\r\n"; debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; /* and we're done! */ goto out; } else if (g_str_has_prefix (line, "ERROR") && (line[5] == 0 || g_ascii_isspace (line[5]))) { //g_strstrip (line + 5); g_debug ("bah, no unix_fd: `%s'", line + 5); g_free (line); s = "BEGIN\r\n"; debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; /* and we're done! */ goto out; } else { /* TODO: handle other valid responses */ g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "In WaitingForAgreeUnixFd: unexpected response `%s'", line); g_free (line); goto out; } break; case CLIENT_STATE_WAITING_FOR_DATA: debug_print ("CLIENT: WaitingForData"); line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error); if (line == NULL) goto out; debug_print ("CLIENT: WaitingForData, read=`%s'", line); if (g_str_has_prefix (line, "DATA ")) { gchar *encoded; gchar *decoded_data; gsize decoded_data_len; encoded = g_strdup (line + 5); g_free (line); g_strstrip (encoded); decoded_data = hexdecode (encoded, &decoded_data_len, error); g_free (encoded); if (decoded_data == NULL) { g_prefix_error (error, "DATA response is malformed: "); /* invalid encoding, disconnect! */ goto out; } _g_dbus_auth_mechanism_client_data_receive (mech, decoded_data, decoded_data_len); g_free (decoded_data); if (_g_dbus_auth_mechanism_client_get_state (mech) == G_DBUS_AUTH_MECHANISM_STATE_HAVE_DATA_TO_SEND) { gchar *data; gsize data_len; gchar *encoded_data; data = _g_dbus_auth_mechanism_client_data_send (mech, &data_len); encoded_data = hexencode (data); s = g_strdup_printf ("DATA %s\r\n", encoded_data); g_free (encoded_data); g_free (data); debug_print ("CLIENT: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_free (s); goto out; } g_free (s); } state = CLIENT_STATE_WAITING_FOR_OK; } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "In WaitingForData: unexpected response `%s'", line); g_free (line); goto out; } break; default: g_assert_not_reached (); break; } }; /* main authentication client loop */ out: if (mech != NULL) g_object_unref (mech); g_ptr_array_unref (attempted_auth_mechs); g_strfreev (supported_auth_mechs); g_object_unref (dis); g_object_unref (dos); /* ensure return value is NULL if error is set */ if (error != NULL && *error != NULL) { g_free (ret_guid); ret_guid = NULL; } if (ret_guid != NULL) { if (out_negotiated_capabilities != NULL) *out_negotiated_capabilities = negotiated_capabilities; } if (credentials != NULL) g_object_unref (credentials); debug_print ("CLIENT: Done, authenticated=%d", ret_guid != NULL); return ret_guid; }
static gint ptr_strcmp (const gchar **a, const gchar **b) { return g_strcmp0 (*a, *b); }
gboolean _g_dbus_auth_run_server (GDBusAuth *auth, GDBusAuthObserver *observer, const gchar *guid, gboolean allow_anonymous, GDBusCapabilityFlags offered_capabilities, GDBusCapabilityFlags *out_negotiated_capabilities, GCredentials **out_received_credentials, GCancellable *cancellable, GError **error) { gboolean ret; ServerState state; GDataInputStream *dis; GDataOutputStream *dos; GError *local_error; guchar byte; gchar *line; gsize line_length; GDBusAuthMechanism *mech; gchar *s; GDBusCapabilityFlags negotiated_capabilities; GCredentials *credentials; debug_print ("SERVER: initiating"); ret = FALSE; dis = NULL; dos = NULL; mech = NULL; negotiated_capabilities = 0; credentials = NULL; if (!g_dbus_is_guid (guid)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "The given guid `%s' is not valid", guid); goto out; } dis = G_DATA_INPUT_STREAM (g_data_input_stream_new (g_io_stream_get_input_stream (auth->priv->stream))); dos = G_DATA_OUTPUT_STREAM (g_data_output_stream_new (g_io_stream_get_output_stream (auth->priv->stream))); g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (dis), FALSE); g_filter_output_stream_set_close_base_stream (G_FILTER_OUTPUT_STREAM (dos), FALSE); g_data_input_stream_set_newline_type (dis, G_DATA_STREAM_NEWLINE_TYPE_CR_LF); /* first read the NUL-byte (TODO: read credentials if using a unix domain socket) */ #ifdef G_OS_UNIX if (G_IS_UNIX_CONNECTION (auth->priv->stream) && g_unix_credentials_message_is_supported ()) { local_error = NULL; credentials = g_unix_connection_receive_credentials (G_UNIX_CONNECTION (auth->priv->stream), cancellable, &local_error); if (credentials == NULL) { g_propagate_error (error, local_error); goto out; } } else { local_error = NULL; byte = g_data_input_stream_read_byte (dis, cancellable, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); goto out; } } #else local_error = NULL; byte = g_data_input_stream_read_byte (dis, cancellable, &local_error); if (local_error != NULL) { g_propagate_error (error, local_error); goto out; } #endif if (credentials != NULL) { if (G_UNLIKELY (_g_dbus_debug_authentication ())) { s = g_credentials_to_string (credentials); debug_print ("SERVER: received credentials `%s'", s); g_free (s); } } else { debug_print ("SERVER: didn't receive any credentials"); } state = SERVER_STATE_WAITING_FOR_AUTH; while (TRUE) { switch (state) { case SERVER_STATE_WAITING_FOR_AUTH: debug_print ("SERVER: WaitingForAuth"); line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error); debug_print ("SERVER: WaitingForAuth, read `%s'", line); if (line == NULL) goto out; if (g_strcmp0 (line, "AUTH") == 0) { s = get_auth_mechanisms (auth, allow_anonymous, "REJECTED ", "\r\n", " "); debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_free (s); goto out; } g_free (s); g_free (line); } else if (g_str_has_prefix (line, "AUTH ")) { gchar **tokens; const gchar *encoded; const gchar *mech_name; GType auth_mech_to_use_gtype; tokens = g_strsplit (line, " ", 0); g_free (line); switch (g_strv_length (tokens)) { case 2: /* no initial response */ mech_name = tokens[1]; encoded = NULL; break; case 3: /* initial response */ mech_name = tokens[1]; encoded = tokens[2]; break; default: g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unexpected line `%s' while in WaitingForAuth state", line); g_strfreev (tokens); goto out; } /* TODO: record that the client has attempted to use this mechanism */ //g_debug ("client is trying `%s'", mech_name); auth_mech_to_use_gtype = find_mech_by_name (auth, mech_name); if ((auth_mech_to_use_gtype == (GType) 0) || (!allow_anonymous && g_strcmp0 (mech_name, "ANONYMOUS") == 0)) { /* We don't support this auth mechanism */ g_strfreev (tokens); s = get_auth_mechanisms (auth, allow_anonymous, "REJECTED ", "\r\n", " "); debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_free (s); goto out; } g_free (s); /* stay in WAITING FOR AUTH */ state = SERVER_STATE_WAITING_FOR_AUTH; } else { gchar *initial_response; gsize initial_response_len; mech = g_object_new (auth_mech_to_use_gtype, "stream", auth->priv->stream, "credentials", credentials, NULL); initial_response = NULL; initial_response_len = 0; if (encoded != NULL) { initial_response = hexdecode (encoded, &initial_response_len, error); if (initial_response == NULL) { g_prefix_error (error, "Initial response is malformed: "); /* invalid encoding, disconnect! */ g_strfreev (tokens); goto out; } } _g_dbus_auth_mechanism_server_initiate (mech, initial_response, initial_response_len); g_free (initial_response); g_strfreev (tokens); change_state: switch (_g_dbus_auth_mechanism_server_get_state (mech)) { case G_DBUS_AUTH_MECHANISM_STATE_ACCEPTED: if (observer != NULL && !g_dbus_auth_observer_authorize_authenticated_peer (observer, auth->priv->stream, credentials)) { /* disconnect */ g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, _("Cancelled via GDBusAuthObserver::authorize-authenticated-peer")); goto out; } else { s = g_strdup_printf ("OK %s\r\n", guid); debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_free (s); goto out; } g_free (s); state = SERVER_STATE_WAITING_FOR_BEGIN; } break; case G_DBUS_AUTH_MECHANISM_STATE_REJECTED: s = get_auth_mechanisms (auth, allow_anonymous, "REJECTED ", "\r\n", " "); debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_free (s); goto out; } g_free (s); state = SERVER_STATE_WAITING_FOR_AUTH; break; case G_DBUS_AUTH_MECHANISM_STATE_WAITING_FOR_DATA: state = SERVER_STATE_WAITING_FOR_DATA; break; case G_DBUS_AUTH_MECHANISM_STATE_HAVE_DATA_TO_SEND: { gchar *data; gsize data_len; gchar *encoded_data; data = _g_dbus_auth_mechanism_server_data_send (mech, &data_len); encoded_data = hexencode (data); s = g_strdup_printf ("DATA %s\r\n", encoded_data); g_free (encoded_data); g_free (data); debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) { g_free (s); goto out; } g_free (s); } goto change_state; break; default: /* TODO */ g_assert_not_reached (); break; } } } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unexpected line `%s' while in WaitingForAuth state", line); g_free (line); goto out; } break; case SERVER_STATE_WAITING_FOR_DATA: debug_print ("SERVER: WaitingForData"); line = _my_g_data_input_stream_read_line (dis, &line_length, cancellable, error); debug_print ("SERVER: WaitingForData, read `%s'", line); if (line == NULL) goto out; if (g_str_has_prefix (line, "DATA ")) { gchar *encoded; gchar *decoded_data; gsize decoded_data_len; encoded = g_strdup (line + 5); g_free (line); g_strstrip (encoded); decoded_data = hexdecode (encoded, &decoded_data_len, error); g_free (encoded); if (decoded_data == NULL) { g_prefix_error (error, "DATA response is malformed: "); /* invalid encoding, disconnect! */ goto out; } _g_dbus_auth_mechanism_server_data_receive (mech, decoded_data, decoded_data_len); g_free (decoded_data); /* oh man, this goto-crap is so ugly.. really need to rewrite the state machine */ goto change_state; } else { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Unexpected line `%s' while in WaitingForData state", line); g_free (line); } goto out; case SERVER_STATE_WAITING_FOR_BEGIN: debug_print ("SERVER: WaitingForBegin"); /* Use extremely slow (but reliable) line reader - this basically * does a recvfrom() system call per character * * (the problem with using GDataInputStream's read_line is that because of * buffering it might start reading into the first D-Bus message that * appears after "BEGIN\r\n"....) */ line = _my_g_input_stream_read_line_safe (g_io_stream_get_input_stream (auth->priv->stream), &line_length, cancellable, error); debug_print ("SERVER: WaitingForBegin, read `%s'", line); if (line == NULL) goto out; if (g_strcmp0 (line, "BEGIN") == 0) { /* YAY, done! */ ret = TRUE; g_free (line); goto out; } else if (g_strcmp0 (line, "NEGOTIATE_UNIX_FD") == 0) { g_free (line); if (offered_capabilities & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING) { negotiated_capabilities |= G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING; s = "AGREE_UNIX_FD\r\n"; debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; } else { s = "ERROR \"fd passing not offered\"\r\n"; debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; } } else { g_debug ("Unexpected line `%s' while in WaitingForBegin state", line); g_free (line); s = "ERROR \"Unknown Command\"\r\n"; debug_print ("SERVER: writing `%s'", s); if (!g_data_output_stream_put_string (dos, s, cancellable, error)) goto out; } break; default: g_assert_not_reached (); break; } } g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Not implemented (server)"); out: if (mech != NULL) g_object_unref (mech); if (dis != NULL) g_object_unref (dis); if (dos != NULL) g_object_unref (dos); /* ensure return value is FALSE if error is set */ if (error != NULL && *error != NULL) { ret = FALSE; } if (ret) { if (out_negotiated_capabilities != NULL) *out_negotiated_capabilities = negotiated_capabilities; if (out_received_credentials != NULL) *out_received_credentials = credentials != NULL ? g_object_ref (credentials) : NULL; } if (credentials != NULL) g_object_unref (credentials); debug_print ("SERVER: Done, authenticated=%d", ret); return ret; }
/** Get file attributes. * * Similar to stat(). The 'st_dev' and 'st_blksize' fields are * ignored. The 'st_ino' field is ignored except if the 'use_ino' * mount option is given. * * struct stat { * dev_t st_dev; // ID of device containing file * ino_t st_ino; // inode number * mode_t st_mode; // protection * nlink_t st_nlink; // number of hard links * uid_t st_uid; // user ID of owner * gid_t st_gid; // group ID of owner * dev_t st_rdev; // device ID (if special file) * off_t st_size; // total size, in bytes * blksize_t st_blksize; // blocksize for file system I/O * blkcnt_t st_blocks; // number of 512B blocks allocated * time_t st_atime; // time of last access * time_t st_mtime; // time of last modification * time_t st_ctime; // time of last status change * }; */ static int fuse_getattr(const char *path, struct stat *buf) { #ifndef HIDE_COMPLETED tolog(path); tolog(" - getattr\n"); #endif struct timeval tv; if (gettimeofday(&tv, NULL) == 0) { buf->st_atime = tv.tv_sec; buf->st_mtime = tv.tv_sec; buf->st_ctime = tv.tv_sec; } buf->st_uid = FILE_UID; buf->st_gid = FILE_GID; if (isDirectory(path)) { buf->st_mode = S_IFDIR | S_IRWXU; buf->st_nlink = 2; return 0; } if (isSymlink(path)) { buf->st_mode = S_IFLNK | S_IRWXU; buf->st_nlink = 1; return 0; } if (isOffset(path)) { // Even though it's read-only, the write flag is there in case // a library we use requires write access. It won't be able to write to // the file of course, but it will think it can. buf->st_mode = S_IFREG | S_IRUSR | S_IWUSR; buf->st_nlink = 1; off_t offset = -1; off_t length = -1; sscanf(path + 1, "%llu-%llu", (unsigned long long *) &offset, (unsigned long long *) &length); if ((length == -1) || (length > (mappedFile_size - offset))) { if (mappedFile_size < offset) { length = 0; } else { length = mappedFile_size - offset; } } buf->st_size = length; buf->st_blocks = (buf->st_size + 511) / 512; return 0; } if (isMetaFilename(path)) { // While we are aware of such a beast, these are all zero sized. buf->st_mode = S_IFREG | S_IRUSR | S_IWUSR; buf->st_nlink = 1; buf->st_size = 0; buf->st_blocks = 0; return 0; } // They might be enquiring about the usage file. if (g_strcmp0(path, "/" USAGE_FILE) == 0) { buf->st_mode = S_IFREG | S_IRUSR | S_IWUSR; buf->st_nlink = 1; buf->st_size = strlen(USAGE_FILE_CONTENT); buf->st_blocks = (buf->st_size + 511) / 512; return 0; } return -ENOENT; }
gboolean flatpak_builtin_build_update_repo (int argc, char **argv, GCancellable *cancellable, GError **error) { g_autoptr(GOptionContext) context = NULL; g_autoptr(GFile) repofile = NULL; g_autoptr(OstreeRepo) repo = NULL; const char *location; g_autoptr(GPtrArray) unwanted_deltas = NULL; context = g_option_context_new (_("LOCATION - Update repository metadata")); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); if (!flatpak_option_context_parse (context, options, &argc, &argv, FLATPAK_BUILTIN_FLAG_NO_DIR, NULL, cancellable, error)) return FALSE; if (argc < 2) return usage_error (context, _("LOCATION must be specified"), error); if (opt_static_delta_jobs <= 0) opt_static_delta_jobs = g_get_num_processors (); location = argv[1]; repofile = g_file_new_for_commandline_arg (location); repo = ostree_repo_new (repofile); if (!ostree_repo_open (repo, cancellable, error)) return FALSE; if (opt_generate_delta_to) { if (!generate_one_delta (repo, opt_generate_delta_from, opt_generate_delta_to, opt_generate_delta_ref, cancellable, error)) return FALSE; return TRUE; } if (opt_title && !flatpak_repo_set_title (repo, opt_title[0] ? opt_title : NULL, error)) return FALSE; if (opt_comment && !flatpak_repo_set_comment (repo, opt_comment[0] ? opt_comment : NULL, error)) return FALSE; if (opt_description && !flatpak_repo_set_description (repo, opt_description[0] ? opt_description : NULL, error)) return FALSE; if (opt_homepage && !flatpak_repo_set_homepage (repo, opt_homepage[0] ? opt_homepage : NULL, error)) return FALSE; if (opt_icon && !flatpak_repo_set_icon (repo, opt_icon[0] ? opt_icon : NULL, error)) return FALSE; if (opt_redirect_url && !flatpak_repo_set_redirect_url (repo, opt_redirect_url[0] ? opt_redirect_url : NULL, error)) return FALSE; if (opt_default_branch && !flatpak_repo_set_default_branch (repo, opt_default_branch[0] ? opt_default_branch : NULL, error)) return FALSE; if (opt_collection_id != NULL) { /* Only allow a transition from no collection ID to a non-empty collection ID. * Changing the collection ID between two different non-empty values is too * dangerous: it will break all clients who have previously pulled from the repository. * Require the user to recreate the repository from scratch in that case. */ const char *old_collection_id = ostree_repo_get_collection_id (repo); const char *new_collection_id = opt_collection_id[0] ? opt_collection_id : NULL; if (old_collection_id != NULL && g_strcmp0 (old_collection_id, new_collection_id) != 0) return flatpak_fail (error, "The collection ID of an existing repository cannot be changed. " "Recreate the repository to change or clear its collection ID."); if (!flatpak_repo_set_collection_id (repo, new_collection_id, error)) return FALSE; } if (opt_deploy_collection_id && !flatpak_repo_set_deploy_collection_id (repo, TRUE, error)) return FALSE; if (opt_gpg_import) { g_autoptr(GBytes) gpg_data = flatpak_load_gpg_keys (opt_gpg_import, cancellable, error); if (gpg_data == NULL) return FALSE; if (!flatpak_repo_set_gpg_keys (repo, gpg_data, error)) return FALSE; } if (!opt_no_update_appstream) { g_print (_("Updating appstream branch\n")); if (!flatpak_repo_generate_appstream (repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, 0, cancellable, error)) return FALSE; } if (opt_generate_deltas && !generate_all_deltas (repo, &unwanted_deltas, cancellable, error)) return FALSE; if (unwanted_deltas != NULL) { int i; for (i = 0; i < unwanted_deltas->len; i++) { const char *delta = g_ptr_array_index (unwanted_deltas, i); g_print ("Deleting unwanted delta: %s\n", delta); g_autoptr(GError) my_error = NULL; if (!_ostree_repo_static_delta_delete (repo, delta, cancellable, &my_error)) g_printerr ("Unable to delete delta %s: %s\n", delta, my_error->message); } } if (!opt_no_update_summary) { g_print (_("Updating summary\n")); if (!flatpak_repo_update (repo, (const char **) opt_gpg_key_ids, opt_gpg_homedir, cancellable, error)) return FALSE; } if (opt_prune) { gint n_objects_total; gint n_objects_pruned; guint64 objsize_total; g_autofree char *formatted_freed_size = NULL; g_print ("Pruning old commits\n"); if (!ostree_repo_prune (repo, OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY, opt_prune_depth, &n_objects_total, &n_objects_pruned, &objsize_total, cancellable, error)) return FALSE; formatted_freed_size = g_format_size_full (objsize_total, 0); g_print (_("Total objects: %u\n"), n_objects_total); if (n_objects_pruned == 0) g_print (_("No unreachable objects\n")); else g_print (_("Deleted %u objects, %s freed\n"), n_objects_pruned, formatted_freed_size); } return TRUE; }
void MessageListener::handleMessage(CcnetMessage *message) { // qWarning("got a message: %s %s.", message->app, message->body); char *type = NULL; char *content = NULL; if (IS_APP_MSG(message, kAppletCommandsMQ)) { if (g_strcmp0(message->body, "quit") == 0) { qWarning("[Message Listener] Got a quit command. Quit now."); QCoreApplication::exit(0); return; } if (g_strcmp0(message->body, "syn_activate") == 0) { qWarning("[Message Listener] Got an activate command."); CcnetMessage *ack_message; ack_message = ccnet_message_new(async_client_->base.id, async_client_->base.id, kAppletCommandsMQ, "ack_activate", 0); ccnet_mqclient_proc_put_message(mqclient_proc_, ack_message); ccnet_message_free(ack_message); seafApplet->mainWindow()->showWindow(); } const char *kOpenLocalFilePrefix = "open-local-file\t"; if (strstr(message->body, kOpenLocalFilePrefix) == message->body) { OpenLocalHelper::instance()->openLocalFile(QUrl::fromEncoded(message->body + strlen(kOpenLocalFilePrefix))); } } else if (IS_APP_MSG(message, kSeafileNotificationsMQ)) { if (parse_seafile_notification (message->body, &type, &content) < 0) return; if (strcmp(type, "transfer") == 0) { // empty } else if (strcmp(type, "repo.deleted_on_relay") == 0) { QString buf = tr("\"%1\" is unsynced. \nReason: Deleted on server").arg(QString::fromUtf8(content)); seafApplet->trayIcon()->showMessage(getBrand(), buf); } else if (strcmp(type, "sync.done") == 0) { /* format: repo_name \t repo_id \t description */ QStringList slist = QString::fromUtf8(content).split("\t"); if (slist.count() != 3) { qWarning("Bad sync.done message format"); return; } QString title = tr("\"%1\" is synchronized").arg(slist.at(0)); QString repo_id = slist.at(1).trimmed(); QString buf = slist.at(2).trimmed(); seafApplet->trayIcon()->showMessageWithRepo(repo_id, title, translateCommitDesc(buf)); } else if (strcmp(type, "sync.conflict") == 0) { json_error_t error; json_t *object = json_loads(content, 0, &error); if (!object) { qWarning("Failed to parse json: %s", error.text); return; } QString title = QString::fromUtf8(json_string_value(json_object_get(object, "repo_name"))); QString path = QString::fromUtf8(json_string_value(json_object_get(object, "path"))); QString msg = tr("File %1 conflict").arg(path); seafApplet->trayIcon()->showMessage(title, msg); json_decref(object); } else if (strcmp(type, "sync.access_denied") == 0) { /* format: <repo_name\trepo_id> */ QStringList slist = QString::fromUtf8(content).split("\t"); if (slist.count() != 2) { qWarning("Bad sync.access_denied message format"); return; } QString buf = tr("\"%1\" failed to sync. \nAccess denied to service").arg(slist.at(0)); seafApplet->trayIcon()->showMessage(getBrand(), buf); } else if (strcmp(type, "sync.quota_full") == 0) { /* format: <repo_name\trepo_id> */ QStringList slist = QString::fromUtf8(content).split("\t"); if (slist.count() != 2) { qWarning("Bad sync.quota_full message format"); return; } QString buf = tr("\"%1\" failed to sync.\nThe library owner's storage space is used up.").arg(slist.at(0)); seafApplet->trayIcon()->showMessage(getBrand(), buf); #if defined(Q_OS_MAC) } else if (strcmp(type, "repo.setwktree") == 0) { //seafile_set_repofolder_icns (content); } else if (strcmp(type, "repo.unsetwktree") == 0) { //seafile_unset_repofolder_icns (content); #endif } } }
static void nmt_page_ip6_constructed (GObject *object) { NmtPageIP6 *ip6 = NMT_PAGE_IP6 (object); gboolean show_by_default; NmtEditorSection *section; NmtEditorGrid *grid; NMSettingIPConfig *s_ip6; NmtNewtWidget *widget, *button; NMConnection *conn; conn = nmt_editor_page_get_connection (NMT_EDITOR_PAGE (ip6)); s_ip6 = nm_connection_get_setting_ip6_config (conn); if (!s_ip6) { s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new (); g_object_set (G_OBJECT (s_ip6), NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO, NULL); nm_connection_add_setting (conn, (NMSetting *) s_ip6); } widget = nmt_newt_popup_new (ip6methods); g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_METHOD, widget, "active-id", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); if (!g_strcmp0 (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_MANUAL)) show_by_default = TRUE; else if (nm_setting_ip_config_get_num_addresses (s_ip6)) show_by_default = TRUE; else show_by_default = FALSE; section = nmt_editor_section_new (_("IPv6 CONFIGURATION"), widget, show_by_default); grid = nmt_editor_section_get_body (section); widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6_WITH_PREFIX); nm_editor_bind_ip_addresses_with_prefix_to_strv (AF_INET6, s_ip6, NM_SETTING_IP_CONFIG_ADDRESSES, widget, "strings", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("Addresses"), widget, NULL); widget = nmt_ip_entry_new (25, AF_INET6, FALSE, TRUE); nm_editor_bind_ip_gateway_to_string (AF_INET6, s_ip6, widget, "text", "sensitive", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("Gateway"), widget, NULL); widget = nmt_address_list_new (NMT_ADDRESS_LIST_IP6); nm_editor_bind_ip_addresses_to_strv (AF_INET6, s_ip6, NM_SETTING_IP_CONFIG_DNS, widget, "strings", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("DNS servers"), widget, NULL); widget = nmt_address_list_new (NMT_ADDRESS_LIST_HOSTNAME); g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_DNS_SEARCH, widget, "strings", G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE); nmt_editor_grid_append (grid, _("Search domains"), widget, NULL); widget = g_object_new (NMT_TYPE_NEWT_LABEL, "text", "", "style", NMT_NEWT_LABEL_PLAIN, NULL); g_object_bind_property_full (s_ip6, NM_SETTING_IP_CONFIG_ROUTES, widget, "text", G_BINDING_SYNC_CREATE, ip6_routes_transform_to_description, NULL, NULL, NULL); button = nmt_newt_button_new (_("Edit...")); g_signal_connect (button, "clicked", G_CALLBACK (edit_routes), s_ip6); nmt_editor_grid_append (grid, _("Routing"), widget, button); widget = nmt_newt_checkbox_new (_("Never use this network for default route")); g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_NEVER_DEFAULT, widget, "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL); nmt_editor_grid_append (grid, NULL, widget, NULL); nmt_editor_grid_append (grid, NULL, nmt_newt_separator_new (), NULL); widget = nmt_newt_checkbox_new (_("Require IPv6 addressing for this connection")); g_object_bind_property (s_ip6, NM_SETTING_IP_CONFIG_MAY_FAIL, widget, "active", G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL | G_BINDING_INVERT_BOOLEAN); nmt_editor_grid_append (grid, NULL, widget, NULL); nmt_editor_page_add_section (NMT_EDITOR_PAGE (ip6), section); G_OBJECT_CLASS (nmt_page_ip6_parent_class)->constructed (object); }
/** * zif_compare_evr_full: * @a: The first version string, or %NULL * @b: The second version string, or %NULL * @compare_mode: the way the versions are compared * * Compare two [epoch:]version[-release] strings * * Return value: 1 for a>b, 0 for a==b, -1 for b>a * * Since: 0.2.1 **/ gint zif_compare_evr_full (const gchar *a, const gchar *b, ZifPackageCompareMode compare_mode) { gint val = 0; gchar a_tmp[128]; /* 128 bytes should be enough for anybody, heh */ gchar b_tmp[128]; const gchar *ae, *av, *ar, *ad; const gchar *be, *bv, *br, *bd; /* exactly the same, optimise */ if (g_strcmp0 (a, b) == 0) goto out; /* deal with one evr being NULL and the other a value */ if (a != NULL && b == NULL) { val = 1; goto out; } if (a == NULL && b != NULL) { val = -1; goto out; } /* copy */ g_strlcpy (a_tmp, a, 128); g_strlcpy (b_tmp, b, 128); /* split */ zif_package_convert_evr_full (a_tmp, &ae, &av, &ar, &ad); zif_package_convert_evr_full (b_tmp, &be, &bv, &br, &bd); /* compare distro */ if (ad != NULL && bd != NULL && compare_mode == ZIF_PACKAGE_COMPARE_MODE_DISTRO) { val = rpmvercmp (ad, bd); if (val != 0) goto out; } /* compare epoch */ if (ae != NULL && be != NULL) { val = rpmvercmp (ae, be); if (val != 0) goto out; } else if (ae != NULL && atoi (ae) > 0) { val = 1; goto out; } else if (be != NULL && atoi (be) > 0) { val = -1; goto out; } /* compare version */ val = rpmvercmp (av, bv); if (val != 0) goto out; /* compare release */ if (ar != NULL && br != NULL) { val = rpmvercmp (ar, br); if (val != 0) goto out; } /* compare distro */ if (ad != NULL && bd != NULL) { val = rpmvercmp (ad, bd); if (val != 0) goto out; } out: return val; }
static void add_model (MexTrackerPlugin *self, GrlMediaPlugin *plugin, MexTrackerCategory category) { GList *metadata_keys, *query_keys; MexFeed *feed, *dir_feed; GrlMedia *box; gchar *query, *cat_name; GHashTable *models; const gchar *source_name = grl_metadata_source_get_name (GRL_METADATA_SOURCE (plugin)); gint priority; switch (category) { case MEX_TRACKER_CATEGORY_IMAGE: cat_name = "pictures"; query = "?urn a nfo:FileDataObject . " "?urn tracker:available true . " "FILTER (fn:starts-with(nie:mimeType(?urn),'image/'))"; models = self->priv->image_models; metadata_keys = self->priv->image_keys; query_keys = self->priv->query_image_keys; box = grl_media_image_new (); break; case MEX_TRACKER_CATEGORY_VIDEO: cat_name = "videos"; query = "?urn a nfo:FileDataObject . " "?urn tracker:available true . " "FILTER (fn:starts-with(nie:mimeType(?urn),'video/'))"; models = self->priv->video_models; metadata_keys = self->priv->video_keys; query_keys = self->priv->query_video_keys; box = grl_media_video_new (); break; case MEX_TRACKER_CATEGORY_MUSIC: cat_name = "music"; query = "?urn a nfo:FileDataObject . " "?urn tracker:available true . " "FILTER (fn:starts-with(nie:mimeType(?urn),'audio/'))"; models = self->priv->music_models; metadata_keys = self->priv->music_keys; query_keys = self->priv->query_music_keys; box = grl_media_audio_new (); break; } grl_media_set_id (GRL_MEDIA (box), NULL); feed = mex_grilo_tracker_feed_new (GRL_MEDIA_SOURCE (plugin), query_keys, metadata_keys, NULL, box); mex_model_set_sort_func (MEX_MODEL (feed), mex_model_sort_time_cb, GINT_TO_POINTER (TRUE)); mex_grilo_feed_query (MEX_GRILO_FEED (feed), query, 0, MAX_TRACKER_RESULTS); g_hash_table_insert (models, plugin, feed); /* set the local files source to appear first */ if (!g_strcmp0 (source_name, "Local files")) priority = -100; else priority = 0; dir_feed = mex_grilo_tracker_feed_new (GRL_MEDIA_SOURCE (plugin), query_keys, metadata_keys, query, NULL); mex_model_set_sort_func (MEX_MODEL (dir_feed), mex_model_sort_alpha_cb, GINT_TO_POINTER (FALSE)); mex_grilo_feed_browse (MEX_GRILO_FEED (dir_feed), 0, G_MAXINT); g_object_set (G_OBJECT (feed), "category", cat_name, "priority", priority, "alt-model", dir_feed, "alt-model-string", _("Show Folders"), NULL); mex_model_manager_add_model (self->priv->manager, MEX_MODEL (feed)); }
/** * as_distro_details_construct: * * Construct a new #AsDistroDetails instance. * * Returns: (transfer full): a new #AsDistroDetails instance. **/ AsDistroDetails* as_distro_details_construct (GType object_type) { AsDistroDetails * self = NULL; GFile* f = NULL; gchar *line; GError *error = NULL; self = (AsDistroDetails*) g_object_new (object_type, NULL); as_distro_details_set_distro_id (self, "unknown"); as_distro_details_set_distro_name (self, ""); as_distro_details_set_distro_version (self, ""); /* load configuration */ self->priv->keyf = g_key_file_new (); g_key_file_load_from_file (self->priv->keyf, AS_CONFIG_NAME, G_KEY_FILE_NONE, NULL); /* get details about the distribution we are running on */ f = g_file_new_for_path ("/etc/os-release"); if (g_file_query_exists (f, NULL)) { GDataInputStream *dis; GFileInputStream* fis; fis = g_file_read (f, NULL, &error); if (error != NULL) goto out; dis = g_data_input_stream_new ((GInputStream*) fis); g_object_unref (fis); while ((line = g_data_input_stream_read_line (dis, NULL, NULL, &error)) != NULL) { gchar **data; gchar *dvalue; if (error != NULL) { g_object_unref (dis); goto out; } data = g_strsplit (line, "=", 2); if (g_strv_length (data) != 2) { g_strfreev (data); g_free (line); continue; } dvalue = data[1]; if (g_str_has_prefix (dvalue, "\"")) { gchar *tmpstr; tmpstr = g_strndup (dvalue + 1, strlen(dvalue) - 2); g_free (dvalue); dvalue = tmpstr; } if (g_strcmp0 (data[0], "ID") == 0) as_distro_details_set_distro_id (self, dvalue); else if (g_strcmp0 (data[0], "NAME") == 0) as_distro_details_set_distro_name (self, dvalue); else if (g_strcmp0 (data[0], "VERSION_ID") == 0) as_distro_details_set_distro_version (self, dvalue); g_free (line); } } out: if (error != NULL) g_error_free (error); g_object_unref (f); return self; }
gboolean gs_plugin_url_to_app (GsPlugin *plugin, GsAppList *list, const gchar *url, GCancellable *cancellable, GError **error) { GsPluginData *priv = gs_plugin_get_data (plugin); g_autofree gchar *scheme = NULL; g_autofree gchar *path = NULL; const gchar *id = NULL; const gchar * const *id_like = NULL; g_auto(GStrv) package_ids = NULL; g_autoptr(PkResults) results = NULL; g_autoptr(GsApp) app = NULL; g_autoptr(GsOsRelease) os_release = NULL; g_autoptr(GPtrArray) packages = NULL; g_autoptr(GPtrArray) details = NULL; g_autoptr(GsPackagekitHelper) helper = gs_packagekit_helper_new (plugin); path = gs_utils_get_url_path (url); /* only do this for apt:// on debian or debian-like distros */ os_release = gs_os_release_new (error); if (os_release == NULL) { g_prefix_error (error, "failed to determine OS information:"); return FALSE; } else { id = gs_os_release_get_id (os_release); id_like = gs_os_release_get_id_like (os_release); scheme = gs_utils_get_url_scheme (url); if (!(g_strcmp0 (scheme, "apt") == 0 && (g_strcmp0 (id, "debian") == 0 || g_strv_contains (id_like, "debian")))) { return TRUE; } } app = gs_app_new (NULL); gs_plugin_packagekit_set_packaging_format (plugin, app); gs_app_add_source (app, path); gs_app_set_kind (app, AS_APP_KIND_GENERIC); gs_app_set_bundle_kind (app, AS_BUNDLE_KIND_PACKAGE); package_ids = g_new0 (gchar *, 2); package_ids[0] = g_strdup (path); g_mutex_lock (&priv->client_mutex); results = pk_client_resolve (priv->client, pk_bitfield_from_enums (PK_FILTER_ENUM_NEWEST, PK_FILTER_ENUM_ARCH, -1), package_ids, cancellable, gs_packagekit_helper_cb, helper, error); g_mutex_unlock (&priv->client_mutex); if (!gs_plugin_packagekit_results_valid (results, error)) { g_prefix_error (error, "failed to resolve package_ids: "); return FALSE; } /* get results */ packages = pk_results_get_package_array (results); details = pk_results_get_details_array (results); if (packages->len >= 1) { if (gs_app_get_local_file (app) != NULL) return TRUE; gs_plugin_packagekit_resolve_packages_app (plugin, packages, app); gs_plugin_packagekit_refine_details_app (plugin, details, app); gs_app_list_add (list, app); } else { g_warning ("no results returned"); } return TRUE; }
static void set_vpn_routes(struct gateway_data *new_gateway, struct connman_service *service, const char *gateway, enum connman_ipconfig_type type, const char *peer, struct gateway_data *active_gateway) { struct gateway_config *config; struct connman_ipconfig *ipconfig; char *dest; DBG("new %p service %p gw %s type %d peer %s active %p", new_gateway, service, gateway, type, peer, active_gateway); if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { ipconfig = __connman_service_get_ip4config(service); config = new_gateway->ipv4_gateway; } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) { ipconfig = __connman_service_get_ip6config(service); config = new_gateway->ipv6_gateway; } else return; if (config) { int index = __connman_ipconfig_get_index(ipconfig); struct get_gateway_params *params; config->vpn = true; if (peer) config->vpn_ip = g_strdup(peer); else if (gateway) config->vpn_ip = g_strdup(gateway); params = g_try_malloc(sizeof(struct get_gateway_params)); if (!params) return; params->vpn_index = index; params->vpn_gateway = g_strdup(gateway); /* * Find the gateway that is serving the VPN link */ __connman_inet_get_route(gateway, get_gateway_cb, params); } if (!active_gateway) return; if (type == CONNMAN_IPCONFIG_TYPE_IPV4) { /* * Special route to VPN server via gateway. This * is needed so that we can access hosts behind * the VPN. The route might already exist depending * on network topology. */ if (!active_gateway->ipv4_gateway) return; DBG("active gw %s", active_gateway->ipv4_gateway->gateway); if (g_strcmp0(active_gateway->ipv4_gateway->gateway, "0.0.0.0") != 0) dest = active_gateway->ipv4_gateway->gateway; else dest = NULL; connman_inet_add_host_route(active_gateway->index, gateway, dest); } else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) { if (!active_gateway->ipv6_gateway) return; DBG("active gw %s", active_gateway->ipv6_gateway->gateway); if (g_strcmp0(active_gateway->ipv6_gateway->gateway, "::") != 0) dest = active_gateway->ipv6_gateway->gateway; else dest = NULL; connman_inet_add_ipv6_host_route(active_gateway->index, gateway, dest); } }
static void handle_getcapabilities_req(struct unix_client *client, struct bt_get_capabilities_req *req) { struct audio_device *dev; bdaddr_t src, dst; int err = EIO; const char *interface; if (!check_nul(req->source) || !check_nul(req->destination) || !check_nul(req->object)) { err = EINVAL; goto failed; } str2ba(req->source, &src); str2ba(req->destination, &dst); if (!manager_find_device(req->object, &src, &dst, NULL, FALSE)) goto failed; if (req->transport == BT_CAPABILITIES_TRANSPORT_SCO) interface = AUDIO_HEADSET_INTERFACE; else if (req->transport == BT_CAPABILITIES_TRANSPORT_A2DP) interface = AUDIO_SINK_INTERFACE; else interface = client->interface; dev = manager_find_device(req->object, &src, &dst, interface, TRUE); if (!dev && (req->flags & BT_FLAG_AUTOCONNECT)) dev = manager_find_device(req->object, &src, &dst, interface, FALSE); if (!dev) { if (req->transport == BT_CAPABILITIES_TRANSPORT_SCO) interface = AUDIO_GATEWAY_INTERFACE; else if (req->transport == BT_CAPABILITIES_TRANSPORT_A2DP) interface = AUDIO_SOURCE_INTERFACE; else interface = NULL; dev = manager_find_device(req->object, &src, &dst, interface, TRUE); if (!dev && (req->flags & BT_FLAG_AUTOCONNECT)) dev = manager_find_device(req->object, &src, &dst, interface, FALSE); } if (!dev) { error("Unable to find a matching device"); goto failed; } client->type = select_service(dev, interface); if (client->type == TYPE_NONE) { error("No matching service found"); goto failed; } if (g_strcmp0(interface, client->interface) != 0) { g_free(client->interface); client->interface = g_strdup(interface); } client->seid = req->seid; start_discovery(dev, client); return; failed: unix_ipc_error(client, BT_GET_CAPABILITIES, err); }
static void unset_default_gateway(struct gateway_data *data, enum connman_ipconfig_type type) { int index; bool do_ipv4 = false, do_ipv6 = false; if (type == CONNMAN_IPCONFIG_TYPE_IPV4) do_ipv4 = true; else if (type == CONNMAN_IPCONFIG_TYPE_IPV6) do_ipv6 = true; else do_ipv4 = do_ipv6 = true; DBG("type %d gateway ipv4 %p ipv6 %p", type, data->ipv4_gateway, data->ipv6_gateway); if (do_ipv4 && data->ipv4_gateway && data->ipv4_gateway->vpn) { connman_inet_clear_gateway_interface(data->index); data->ipv4_gateway->active = false; DBG("unset %p index %d vpn %s index %d phy %s", data, data->index, data->ipv4_gateway->vpn_ip, data->ipv4_gateway->vpn_phy_index, data->ipv4_gateway->vpn_phy_ip); return; } if (do_ipv6 && data->ipv6_gateway && data->ipv6_gateway->vpn) { connman_inet_clear_ipv6_gateway_interface(data->index); data->ipv6_gateway->active = false; DBG("unset %p index %d vpn %s index %d phy %s", data, data->index, data->ipv6_gateway->vpn_ip, data->ipv6_gateway->vpn_phy_index, data->ipv6_gateway->vpn_phy_ip); return; } index = __connman_service_get_index(data->service); if (do_ipv4 && data->ipv4_gateway && g_strcmp0(data->ipv4_gateway->gateway, "0.0.0.0") == 0) { connman_inet_clear_gateway_interface(index); return; } if (do_ipv6 && data->ipv6_gateway && g_strcmp0(data->ipv6_gateway->gateway, "::") == 0) { connman_inet_clear_ipv6_gateway_interface(index); return; } if (do_ipv6 && data->ipv6_gateway) connman_inet_clear_ipv6_gateway_address(index, data->ipv6_gateway->gateway); if (do_ipv4 && data->ipv4_gateway) connman_inet_clear_gateway_address(index, data->ipv4_gateway->gateway); }
static void exred_getsupportedtypes_ready_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { GDBusProxy *proxy; GVariant *values; GError *error = NULL; proxy = G_DBUS_PROXY (source_object); values = g_dbus_proxy_call_finish (proxy, res, &error); if (values == NULL) { g_error ("%s\n", error->message); g_clear_error (&error); } else { GVariantIter argument_iter; GVariant *array_of_types; GVariantIter type_iter; GVariant *supported_type; int n = 0; g_variant_iter_init (&argument_iter, values); array_of_types = g_variant_iter_next_value (&argument_iter); g_variant_iter_init (&type_iter, array_of_types); while ((supported_type = g_variant_iter_next_value (&type_iter))) { char *mime_type = NULL; char *default_ext = NULL; char *description = NULL; char *key; char *value; GVariantIter value_iter; g_variant_iter_init (&value_iter, supported_type); while (g_variant_iter_next (&value_iter, "{ss}", &key, &value)) { if (g_strcmp0 (key, "mime-type") == 0) mime_type = g_strdup (value); else if (g_strcmp0 (key, "default-extension") == 0) default_ext = g_strdup (value); else if (g_strcmp0 (key, "description") == 0) description = g_strdup (value); g_free (key); g_free (value); } n++; g_print ("%d)\tmime-type: %s\n\tdefault-extension: %s\n\tdescription: %s\n", n, mime_type, default_ext, description); g_free (description); g_free (default_ext); g_free (mime_type); g_variant_unref (supported_type); } g_variant_unref (array_of_types); } g_object_unref (proxy); g_main_loop_quit (loop); }