static void update_timezone (CcDateTimePanel *self) { CcDateTimePanelPrivate *priv = self->priv; GtkWidget *widget; gchar **split; GtkTreeIter iter; GtkTreeModel *model; /* tz.c updates the local timezone, which means the spin buttons can be * updated with the current time of the new location */ split = g_strsplit (priv->current_location->zone, "/", 2); /* remove underscores */ g_strdelimit (split[1], "_", ' '); /* update region combo */ widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "region_combobox"); model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_tree_model_get_iter_first (model, &iter); do { gchar *string; gtk_tree_model_get (model, &iter, CITY_COL_CITY, &string, -1); if (!g_strcmp0 (string, split[0])) { g_free (string); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter); break; } g_free (string); } while (gtk_tree_model_iter_next (model, &iter)); /* update city combo */ widget = (GtkWidget *) gtk_builder_get_object (priv->builder, "city_combobox"); model = gtk_combo_box_get_model (GTK_COMBO_BOX (widget)); gtk_tree_model_filter_refilter ((GtkTreeModelFilter *) gtk_builder_get_object (priv->builder, "city-modelfilter")); gtk_tree_model_get_iter_first (model, &iter); do { gchar *string; gtk_tree_model_get (model, &iter, CITY_COL_CITY, &string, -1); if (!g_strcmp0 (string, split[1])) { g_free (string); gtk_combo_box_set_active_iter (GTK_COMBO_BOX (widget), &iter); break; } g_free (string); } while (gtk_tree_model_iter_next (model, &iter)); g_strfreev (split); }
static int dcc_send_one_file(int queue, const char *target, const char *fname, IRC_SERVER_REC *server, CHAT_DCC_REC *chat) { struct stat st; char *str; char host[MAX_IP_LEN]; int hfile, port; SEND_DCC_REC *dcc; IPADDR own_ip; GIOChannel *handle; if (dcc_find_request(DCC_SEND_TYPE, target, fname)) { signal_emit("dcc error send exists", 2, target, fname); return FALSE; } str = dcc_send_get_file(fname); hfile = open(str, O_RDONLY); g_free(str); if (hfile == -1) { signal_emit("dcc error file open", 3, target, fname, GINT_TO_POINTER(errno)); return FALSE; } if (fstat(hfile, &st) < 0) { g_warning("fstat() failed: %s", strerror(errno)); close(hfile); return FALSE; } /* start listening */ handle = dcc_listen(chat != NULL ? chat->handle : net_sendbuffer_handle(server->handle), &own_ip, &port); if (handle == NULL) { close(hfile); g_warning("dcc_listen() failed: %s", strerror(errno)); return FALSE; } fname = g_basename(fname); /* Replace all the spaces with underscore so that lesser intellgent clients can communicate.. */ if (!settings_get_bool("dcc_send_replace_space_with_underscore")) str = NULL; else { str = g_strdup(fname); g_strdelimit(str, " ", '_'); fname = str; } dcc = dcc_send_create(server, chat, target, fname); g_free(str); dcc->handle = handle; dcc->port = port; dcc->size = st.st_size; dcc->fhandle = hfile; dcc->queue = queue; dcc->file_quoted = strchr(fname, ' ') != NULL; dcc->tagconn = g_input_add(handle, G_INPUT_READ, (GInputFunction) dcc_send_connected, dcc); /* send DCC request */ signal_emit("dcc request send", 1, dcc); dcc_ip2str(&own_ip, host); str = g_strdup_printf(dcc->file_quoted ? "DCC SEND \"%s\" %s %d %"PRIuUOFF_T : "DCC SEND %s %s %d %"PRIuUOFF_T, dcc->arg, host, port, dcc->size); dcc_ctcp_message(server, target, chat, FALSE, str); g_free(str); return TRUE; }
/* open/merge the dnd file */ void dnd_open_file_cmd(gchar *cf_names_freeme) { int err; gchar *cf_name; int in_files; GString *dialog_text; int files_work; char **in_filenames; /* DND_TARGET_URL on Win32: * The cf_name_freeme is a single string, containing one or more URI's, * seperated by CR/NL chars. The length of the whole field can be found * in the selection_data->length field. If it contains one file, simply open it, * If it contains more than one file, ask to merge these files. */ /* count the number of input files */ cf_name = cf_names_freeme; for(in_files = 0; (cf_name = strstr(cf_name, "\r\n")) != NULL; ) { cf_name += 2; in_files++; } in_filenames = g_malloc(sizeof(char*) * in_files); /* store the starts of the file entries in a gchar array */ cf_name = cf_names_freeme; in_filenames[0] = cf_name; for(files_work = 1; (cf_name = strstr(cf_name, "\r\n")) != NULL && files_work < in_files; ) { cf_name += 2; in_filenames[files_work] = cf_name; files_work++; } /* replace trailing CR NL simply with zeroes (in place), so we get valid terminated strings */ cf_name = cf_names_freeme; g_strdelimit(cf_name, "\r\n", '\0'); /* convert all filenames from URI to local filename (in place) */ for(files_work = 0; files_work < in_files; files_work++) { in_filenames[files_work] = dnd_uri2filename(in_filenames[files_work]); } switch(in_files) { case(0): /* shouldn't happen */ break; case(1): /* open and read the capture file (this will close an existing file) */ if (cf_open(&cfile, in_filenames[0], FALSE, &err) == CF_OK) { /* XXX - add this to the menu if the read fails? */ cf_read(&cfile, FALSE); add_menu_recent_capture_file(in_filenames[0]); } else { /* the capture file couldn't be read (doesn't exist, file format unknown, ...) */ } break; default: /* build and show the info dialog */ dialog_text = g_string_sized_new(200); g_string_printf(dialog_text, "%sMerging the following files:%s\n\n", simple_dialog_primary_start(), simple_dialog_primary_end()); for(files_work = 0; files_work < in_files; files_work++) { g_string_append(dialog_text, in_filenames[files_work]); g_string_append(dialog_text, "\n"); } g_string_append(dialog_text, "\nThe packets in these files will be merged chronologically into a new temporary file."); simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTN_OK, "%s", dialog_text->str); g_string_free(dialog_text, TRUE); /* actually merge the files now */ dnd_merge_files(in_files, in_filenames); } g_free(in_filenames); g_free(cf_names_freeme); }
gboolean gst_ffmpegauddec_register (GstPlugin * plugin) { GTypeInfo typeinfo = { sizeof (GstFFMpegAudDecClass), (GBaseInitFunc) gst_ffmpegauddec_base_init, NULL, (GClassInitFunc) gst_ffmpegauddec_class_init, NULL, NULL, sizeof (GstFFMpegAudDec), 0, (GInstanceInitFunc) gst_ffmpegauddec_init, }; GType type; AVCodec *in_plugin; gint rank; in_plugin = av_codec_next (NULL); GST_LOG ("Registering decoders"); while (in_plugin) { gchar *type_name; /* only decoders */ if (!av_codec_is_decoder (in_plugin) || in_plugin->type != AVMEDIA_TYPE_AUDIO) { goto next; } /* no quasi codecs, please */ if (in_plugin->id == AV_CODEC_ID_PCM_S16LE_PLANAR || (in_plugin->id >= AV_CODEC_ID_PCM_S16LE && in_plugin->id <= AV_CODEC_ID_PCM_BLURAY) || (in_plugin->id >= AV_CODEC_ID_PCM_S8_PLANAR && #if AV_VERSION_INT (LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR, LIBAVCODEC_VERSION_MICRO) >= AV_VERSION_INT (57,54,0) in_plugin->id <= AV_CODEC_ID_PCM_S64BE)) { #else in_plugin->id <= AV_CODEC_ID_PCM_S16BE_PLANAR)) { #endif goto next; } /* No decoders depending on external libraries (we don't build them, but * people who build against an external ffmpeg might have them. * We have native gstreamer plugins for all of those libraries anyway. */ if (!strncmp (in_plugin->name, "lib", 3)) { GST_DEBUG ("Not using external library decoder %s. Use the gstreamer-native ones instead.", in_plugin->name); goto next; } GST_DEBUG ("Trying plugin %s [%s]", in_plugin->name, in_plugin->long_name); /* no codecs for which we're GUARANTEED to have better alternatives */ /* MP1 : Use MP3 for decoding */ /* MP2 : Use MP3 for decoding */ /* Theora: Use libtheora based theoradec */ if (!strcmp (in_plugin->name, "vorbis") || !strcmp (in_plugin->name, "wavpack") || !strcmp (in_plugin->name, "mp1") || !strcmp (in_plugin->name, "mp2") || !strcmp (in_plugin->name, "libfaad") || !strcmp (in_plugin->name, "mpeg4aac") || !strcmp (in_plugin->name, "ass") || !strcmp (in_plugin->name, "srt") || !strcmp (in_plugin->name, "pgssub") || !strcmp (in_plugin->name, "dvdsub") || !strcmp (in_plugin->name, "dvbsub")) { GST_LOG ("Ignoring decoder %s", in_plugin->name); goto next; } /* construct the type */ type_name = g_strdup_printf ("avdec_%s", in_plugin->name); g_strdelimit (type_name, ".,|-<> ", '_'); type = g_type_from_name (type_name); if (!type) { /* create the gtype now */ type = g_type_register_static (GST_TYPE_AUDIO_DECODER, type_name, &typeinfo, 0); g_type_set_qdata (type, GST_FFDEC_PARAMS_QDATA, (gpointer) in_plugin); } /* (Ronald) MPEG-4 gets a higher priority because it has been well- * tested and by far outperforms divxdec/xviddec - so we prefer it. * msmpeg4v3 same, as it outperforms divxdec for divx3 playback. * VC1/WMV3 are not working and thus unpreferred for now. */ switch (in_plugin->id) { case AV_CODEC_ID_RA_144: case AV_CODEC_ID_RA_288: case AV_CODEC_ID_COOK: case AV_CODEC_ID_AAC: rank = GST_RANK_PRIMARY; break; /* SIPR: decoder should have a higher rank than realaudiodec. */ case AV_CODEC_ID_SIPR: rank = GST_RANK_SECONDARY; break; default: rank = GST_RANK_MARGINAL; break; } if (!gst_element_register (plugin, type_name, rank, type)) { g_warning ("Failed to register %s", type_name); g_free (type_name); return FALSE; } g_free (type_name); next: in_plugin = av_codec_next (in_plugin); } GST_LOG ("Finished Registering decoders"); return TRUE; }
void spop_mpris2_player_update_properties(Mpris2Player* obj) { g_debug("mpris2: update properties"); g_object_freeze_notify(G_OBJECT(obj)); queue_status qs; sp_track* cur_track; int cur_track_nb, tot_tracks; qs = queue_get_status(&cur_track, &cur_track_nb, &tot_tracks); /* Easy ones first */ mpris2_player_set_shuffle(obj, queue_get_shuffle()); mpris2_player_set_loop_status(obj, queue_get_repeat() ? "Playlist" : "None"); mpris2_player_set_playback_status(obj, ((qs == PLAYING) ? "Playing" : ((qs == PAUSED) ? "Paused" : "Stopped"))); mpris2_player_set_can_go_next(obj, (cur_track_nb < tot_tracks)); mpris2_player_set_can_go_previous(obj, (cur_track_nb > 0)); mpris2_player_set_can_play(obj, cur_track != NULL); mpris2_player_set_can_pause(obj, cur_track != NULL); /* Then boring ones */ spop_mpris2_player_update_position(obj); /* And finally interesting ones */ if (cur_track) { gchar* track_name; gchar* track_artist; gchar* track_album; gchar* track_link; int duration; track_get_data(cur_track, &track_name, &track_artist, &track_album, &track_link, &duration, NULL); /* Turn artist into a GVariant array of strings */ gchar* artists[] = {track_artist, NULL}; GVariant* va = g_variant_new_strv((const gchar* const*) artists, 1); /* Turn Spotify URI into a D-Bus object path */ gchar* trackid = g_strdup_printf("/net/schnouki/spop/%s", track_link); g_strdelimit(trackid, ":", '/'); /* Get filename for the image and turn it into an URI */ gchar* image_filename; track_get_image_file(cur_track, &image_filename); gchar* image_uri = NULL; if (image_filename) image_uri = g_filename_to_uri(image_filename, NULL, NULL); /* Add all relevant metadata to a dictionary */ GVariantBuilder* vb; vb = g_variant_builder_new(G_VARIANT_TYPE_VARDICT); g_variant_builder_add_parsed(vb, "{'mpris:trackid', <%o>}", trackid); g_variant_builder_add_parsed(vb, "{'mpris:length', <%x>}", duration*1000); g_variant_builder_add_parsed(vb, "{'xesam:album', <%s>}", track_album); g_variant_builder_add_parsed(vb, "{'xesam:artist', %v}", va); g_variant_builder_add_parsed(vb, "{'xesam:title', <%s>}", track_name); g_variant_builder_add_parsed(vb, "{'xesam:url', <%s>}", track_link); if (image_uri) g_variant_builder_add_parsed(vb, "{'mpris:artUrl', <%s>}", image_uri); GVariant* metadata = g_variant_builder_end(vb); mpris2_player_set_metadata(obj, metadata); /* Cleanup time */ g_variant_builder_unref(vb); g_free(trackid); g_free(image_filename); if (image_uri) g_free(image_uri); g_free(track_name); g_free(track_artist); g_free(track_album); g_free(track_link); } g_object_thaw_notify(G_OBJECT(obj)); }
/** * cd_plugin_add: **/ static void cd_plugin_add (CdPlugin *plugin, GUdevDevice *udev_device) { CdDevice *device = NULL; const gchar *kind = "webcam"; const gchar *seat; gboolean embedded; gboolean ret; gchar *id = NULL; gchar *model = NULL; gchar *vendor = NULL; /* is a scanner? */ ret = g_udev_device_has_property (udev_device, "COLORD_DEVICE"); if (!ret) goto out; /* replace underscores with spaces */ model = g_strdup (g_udev_device_get_property (udev_device, "ID_MODEL")); if (model != NULL) { g_strdelimit (model, "_\r\n", ' '); g_strchomp (model); } vendor = g_strdup (g_udev_device_get_property (udev_device, "ID_VENDOR")); if (vendor != NULL) { g_strdelimit (vendor, "_\r\n", ' '); g_strchomp (vendor); } /* is a proper camera and not a webcam */ ret = g_udev_device_has_property (udev_device, "ID_GPHOTO2"); if (ret) kind = "camera"; /* generate ID */ id = cd_plugin_get_camera_id_for_udev_device (udev_device); /* assume device belongs to "seat0" if not tagged */ seat = g_udev_device_get_property (udev_device, "ID_SEAT"); if (seat == NULL) seat = "seat0"; /* find if the device is embedded */ embedded = cd_plugin_is_device_embedded (udev_device); /* create new device */ device = cd_device_new (); cd_device_set_id (device, id); cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_KIND, kind, FALSE, NULL); if (model != NULL) { cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_MODEL, model, FALSE, NULL); } if (vendor != NULL) { cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_VENDOR, vendor, FALSE, NULL); } cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_COLORSPACE, "rgb", FALSE, NULL); cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_SERIAL, g_udev_device_get_sysfs_path (udev_device), FALSE, NULL); cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_SEAT, seat, FALSE, NULL); if (embedded) { cd_device_set_property_internal (device, CD_DEVICE_PROPERTY_EMBEDDED, NULL, FALSE, NULL); } /* keep track so we can remove with the same device */ g_hash_table_insert (plugin->priv->devices, g_strdup (g_udev_device_get_sysfs_path (udev_device)), g_object_ref (device)); g_debug ("CdPlugin: emit add: %s", id); cd_plugin_device_added (plugin, device); out: if (device != NULL) g_object_unref (device); g_free (id); g_free (model); g_free (vendor); }
/** * pk_backend_spawn_parse_stdout: **/ static gboolean pk_backend_spawn_parse_stdout (PkBackendSpawn *backend_spawn, const gchar *line, GError **error) { gchar **sections; guint size; gchar *command; gchar *text; gboolean ret = TRUE; guint64 speed; PkInfoEnum info; PkRestartEnum restart; PkGroupEnum group; gulong package_size; gint percentage; PkErrorEnum error_enum; PkStatusEnum status_enum; PkMessageEnum message_enum; PkRestartEnum restart_enum; PkSigTypeEnum sig_type; PkUpdateStateEnum update_state_enum; PkMediaTypeEnum media_type_enum; PkDistroUpgradeEnum distro_upgrade_enum; PkBackendSpawnPrivate *priv = backend_spawn->priv; g_return_val_if_fail (PK_IS_BACKEND_SPAWN (backend_spawn), FALSE); /* check if output line */ if (line == NULL) return FALSE; /* split by tab */ sections = g_strsplit (line, "\t", 0); command = sections[0]; /* get size */ size = g_strv_length (sections); if (g_strcmp0 (command, "package") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (pk_package_id_check (sections[2]) == FALSE) { g_set_error_literal (error, 1, 0, "invalid package_id"); ret = FALSE; goto out; } info = pk_info_enum_from_string (sections[1]); if (info == PK_INFO_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Info enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } pk_backend_package (priv->backend, info, sections[2], sections[3]); } else if (g_strcmp0 (command, "details") == 0) { if (size != 7) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } group = pk_group_enum_from_string (sections[3]); /* ITS4: ignore, checked for overflow */ package_size = atol (sections[6]); if (package_size > 1073741824) { g_set_error_literal (error, 1, 0, "package size cannot be larger than one Gb"); ret = FALSE; goto out; } text = g_strdup (sections[4]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); pk_backend_details (priv->backend, sections[1], sections[2], group, text, sections[5], package_size); g_free (text); } else if (g_strcmp0 (command, "finished") == 0) { if (size != 1) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } pk_backend_finished (priv->backend); /* from this point on, we can start the kill timer */ pk_backend_spawn_start_kill_timer (backend_spawn); } else if (g_strcmp0 (command, "files") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } pk_backend_files (priv->backend, sections[1], sections[2]); } else if (g_strcmp0 (command, "repo-detail") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (g_strcmp0 (sections[3], "true") == 0) { pk_backend_repo_detail (priv->backend, sections[1], sections[2], TRUE); } else if (g_strcmp0 (sections[3], "false") == 0) { pk_backend_repo_detail (priv->backend, sections[1], sections[2], FALSE); } else { g_set_error (error, 1, 0, "invalid qualifier '%s'", sections[3]); ret = FALSE; goto out; } } else if (g_strcmp0 (command, "updatedetail") == 0) { if (size != 13) { g_set_error (error, 1, 0, "invalid command '%s', size %i", command, size); ret = FALSE; goto out; } restart = pk_restart_enum_from_string (sections[7]); if (restart == PK_RESTART_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Restart enum not recognised, and hence ignored: '%s'", sections[7]); ret = FALSE; goto out; } update_state_enum = pk_update_state_enum_from_string (sections[10]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (sections[8], ";", '\n'); g_strdelimit (sections[9], ";", '\n'); pk_backend_update_detail (priv->backend, sections[1], sections[2], sections[3], sections[4], sections[5], sections[6], restart, sections[8], sections[9], update_state_enum, sections[11], sections[12]); } else if (g_strcmp0 (command, "percentage") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } ret = pk_strtoint (sections[1], &percentage); if (!ret) { g_set_error (error, 1, 0, "invalid percentage value %s", sections[1]); ret = FALSE; } else if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid percentage value %i", percentage); ret = FALSE; } else { pk_backend_set_percentage (priv->backend, percentage); } } else if (g_strcmp0 (command, "subpercentage") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } ret = pk_strtoint (sections[1], &percentage); if (!ret) { g_set_error (error, 1, 0, "invalid subpercentage value %s", sections[1]); ret = FALSE; } else if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid subpercentage value %i", percentage); ret = FALSE; } else { pk_backend_set_sub_percentage (priv->backend, percentage); } } else if (g_strcmp0 (command, "item-percentage") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (!pk_package_id_check (sections[1])) { g_set_error (error, 1, 0, "invalid package_id"); ret = FALSE; goto out; } ret = pk_strtoint (sections[2], &percentage); if (!ret) { g_set_error (error, 1, 0, "invalid item-percentage value %s", sections[1]); ret = FALSE; } else if (percentage < 0 || percentage > 100) { g_set_error (error, 1, 0, "invalid item-percentage value %i", percentage); ret = FALSE; } else { pk_backend_set_item_progress (priv->backend, sections[1], percentage); } } else if (g_strcmp0 (command, "error") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } error_enum = pk_error_enum_from_string (sections[1]); if (error_enum == PK_ERROR_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Error enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } /* convert back all the ;'s to newlines */ text = g_strdup (sections[2]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); /* convert % else we try to format them */ g_strdelimit (text, "%", '$'); pk_backend_error_code (priv->backend, error_enum, text); g_free (text); } else if (g_strcmp0 (command, "requirerestart") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } restart_enum = pk_restart_enum_from_string (sections[1]); if (restart_enum == PK_RESTART_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Restart enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } if (!pk_package_id_check (sections[2])) { g_set_error (error, 1, 0, "invalid package_id"); ret = FALSE; goto out; } pk_backend_require_restart (priv->backend, restart_enum, sections[2]); } else if (g_strcmp0 (command, "message") == 0) { if (size != 3) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } message_enum = pk_message_enum_from_string (sections[1]); if (message_enum == PK_MESSAGE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Message enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } text = g_strdup (sections[2]); /* convert ; to \n as we can't emit them on stdout */ g_strdelimit (text, ";", '\n'); pk_backend_message (priv->backend, message_enum, text); g_free (text); } else if (g_strcmp0 (command, "change-transaction-data") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } pk_backend_set_transaction_data (priv->backend, sections[1]); } else if (g_strcmp0 (command, "status") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } status_enum = pk_status_enum_from_string (sections[1]); if (status_enum == PK_STATUS_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Status enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } pk_backend_set_status (priv->backend, status_enum); } else if (g_strcmp0 (command, "speed") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } ret = pk_strtouint64 (sections[1], &speed); if (!ret) { g_set_error (error, 1, 0, "failed to parse speed: '%s'", sections[1]); ret = FALSE; goto out; } pk_backend_set_speed (priv->backend, speed); } else if (g_strcmp0 (command, "allow-cancel") == 0) { if (size != 2) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (g_strcmp0 (sections[1], "true") == 0) { pk_backend_set_allow_cancel (priv->backend, TRUE); } else if (g_strcmp0 (sections[1], "false") == 0) { pk_backend_set_allow_cancel (priv->backend, FALSE); } else { g_set_error (error, 1, 0, "invalid section '%s'", sections[1]); ret = FALSE; goto out; } } else if (g_strcmp0 (command, "no-percentage-updates") == 0) { if (size != 1) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } pk_backend_set_percentage (priv->backend, PK_BACKEND_PERCENTAGE_INVALID); } else if (g_strcmp0 (command, "repo-signature-required") == 0) { if (size != 9) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } sig_type = pk_sig_type_enum_from_string (sections[8]); if (sig_type == PK_SIGTYPE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "Sig enum not recognised, and hence ignored: '%s'", sections[8]); ret = FALSE; goto out; } if (pk_strzero (sections[1])) { g_set_error (error, 1, 0, "package_id blank, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } if (pk_strzero (sections[2])) { g_set_error (error, 1, 0, "repository name blank, and hence ignored: '%s'", sections[2]); ret = FALSE; goto out; } /* pass _all_ of the data */ ret = pk_backend_repo_signature_required (priv->backend, sections[1], sections[2], sections[3], sections[4], sections[5], sections[6], sections[7], sig_type); goto out; } else if (g_strcmp0 (command, "eula-required") == 0) { if (size != 5) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (pk_strzero (sections[1])) { g_set_error (error, 1, 0, "eula_id blank, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } if (pk_strzero (sections[2])) { g_set_error (error, 1, 0, "package_id blank, and hence ignored: '%s'", sections[2]); ret = FALSE; goto out; } if (pk_strzero (sections[4])) { g_set_error (error, 1, 0, "agreement name blank, and hence ignored: '%s'", sections[4]); ret = FALSE; goto out; } ret = pk_backend_eula_required (priv->backend, sections[1], sections[2], sections[3], sections[4]); goto out; } else if (g_strcmp0 (command, "media-change-required") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } media_type_enum = pk_media_type_enum_from_string (sections[1]); if (media_type_enum == PK_MEDIA_TYPE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "media type enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } ret = pk_backend_media_change_required (priv->backend, media_type_enum, sections[2], sections[3]); goto out; } else if (g_strcmp0 (command, "distro-upgrade") == 0) { if (size != 4) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } distro_upgrade_enum = pk_distro_upgrade_enum_from_string (sections[1]); if (distro_upgrade_enum == PK_DISTRO_UPGRADE_ENUM_UNKNOWN) { g_set_error (error, 1, 0, "distro upgrade enum not recognised, and hence ignored: '%s'", sections[1]); ret = FALSE; goto out; } ret = pk_backend_distro_upgrade (priv->backend, distro_upgrade_enum, sections[2], sections[3]); goto out; } else if (g_strcmp0 (command, "category") == 0) { if (size != 6) { g_set_error (error, 1, 0, "invalid command'%s', size %i", command, size); ret = FALSE; goto out; } if (g_strcmp0 (sections[1], sections[2]) == 0) { g_set_error_literal (error, 1, 0, "cat_id cannot be the same as parent_id"); ret = FALSE; goto out; } if (pk_strzero (sections[2])) { g_set_error_literal (error, 1, 0, "cat_id cannot not blank"); ret = FALSE; goto out; } if (pk_strzero (sections[3])) { g_set_error_literal (error, 1, 0, "name cannot not blank"); ret = FALSE; goto out; } if (pk_strzero (sections[5])) { g_set_error_literal (error, 1, 0, "icon cannot not blank"); ret = FALSE; goto out; } if (g_str_has_prefix (sections[5], "/")) { g_set_error (error, 1, 0, "icon '%s' should be a named icon, not a path", sections[5]); ret = FALSE; goto out; } ret = pk_backend_category (priv->backend, sections[1], sections[2], sections[3], sections[4], sections[5]); goto out; } else { ret = FALSE; g_set_error (error, 1, 0, "invalid command '%s'", command); } out: g_strfreev (sections); return ret; }
/** * Create a tempfile with the given prefix (e.g. "wireshark"). * * @param namebuf If not NULL, receives the full path of the temp file. * Should NOT be freed. * @param pfx A prefix for the temporary file. * @param sfx [in] A file extension for the temporary file. NULL can be passed * if no file extension is needed * @return The file descriptor of the new tempfile, from mkstemps(). */ int create_tempfile(char **namebuf, const char *pfx, const char *sfx) { static struct _tf { char *path; size_t len; } tf[MAX_TEMPFILES]; static int idx; const char *tmp_dir; int old_umask; int fd; time_t current_time; char timestr[14 + 1]; gchar *tmp_file; gchar *safe_pfx; gchar sep[2] = {0, 0}; /* The characters in "delimiters" come from: * http://msdn.microsoft.com/en-us/library/aa365247%28VS.85%29.aspx. * Add to the list as necessary for other OS's. */ const gchar *delimiters = "<>:\"/\\|?*" "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a" "\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14" "\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"; /* Sanitize the pfx to resolve bug 7877 */ safe_pfx = g_strdup(pfx); safe_pfx = g_strdelimit(safe_pfx, delimiters, '-'); idx = (idx + 1) % MAX_TEMPFILES; /* * Allocate the buffer if it's not already allocated. */ if (tf[idx].path == NULL) { tf[idx].len = INITIAL_PATH_SIZE; tf[idx].path = (char *)g_malloc(tf[idx].len); } tmp_dir = g_get_tmp_dir(); #ifdef _WIN32 _tzset(); #endif current_time = time(NULL); strftime(timestr, sizeof(timestr), "%Y%m%d%H%M%S", localtime(¤t_time)); sep[0] = G_DIR_SEPARATOR; tmp_file = g_strconcat(tmp_dir, sep, safe_pfx, "_", timestr, "_", TMP_FILE_SUFFIX, sfx, NULL); g_free(safe_pfx); if (strlen(tmp_file) > tf[idx].len) { tf[idx].len = strlen(tmp_file) + 1; tf[idx].path = (char *)g_realloc(tf[idx].path, tf[idx].len); } g_strlcpy(tf[idx].path, tmp_file, tf[idx].len); g_free(tmp_file); if (namebuf) { *namebuf = tf[idx].path; } /* The Single UNIX Specification doesn't say that "mkstemps()" creates the temporary file with mode rw-------, so we won't assume that all UNIXes will do so; instead, we set the umask to 0077 to take away all group and other permissions, attempt to create the file, and then put the umask back. */ old_umask = ws_umask(0077); fd = mkstemps(tf[idx].path, sfx ? (int) strlen(sfx) : 0); ws_umask(old_umask); return fd; }
gboolean athena_link_local_create (const char *directory_uri, const char *base_name, const char *display_name, const char *image, const char *target_uri, const GdkPoint *point, int screen, gboolean unique_filename) { char *real_directory_uri; char *uri, *contents; GFile *file; GList dummy_list; AthenaFileChangesQueuePosition item; g_return_val_if_fail (directory_uri != NULL, FALSE); g_return_val_if_fail (base_name != NULL, FALSE); g_return_val_if_fail (display_name != NULL, FALSE); g_return_val_if_fail (target_uri != NULL, FALSE); if (eel_uri_is_trash (directory_uri) || eel_uri_is_search (directory_uri)) { return FALSE; } if (eel_uri_is_desktop (directory_uri)) { real_directory_uri = athena_get_desktop_directory_uri (); } else { real_directory_uri = g_strdup (directory_uri); } if (unique_filename) { uri = athena_ensure_unique_file_name (real_directory_uri, base_name, ".desktop"); if (uri == NULL) { g_free (real_directory_uri); return FALSE; } file = g_file_new_for_uri (uri); g_free (uri); } else { char *link_name; GFile *dir; link_name = g_strdup_printf ("%s.desktop", base_name); /* replace '/' with '-', just in case */ g_strdelimit (link_name, "/", '-'); dir = g_file_new_for_uri (directory_uri); file = g_file_get_child (dir, link_name); g_free (link_name); g_object_unref (dir); } g_free (real_directory_uri); contents = g_strdup_printf ("[Desktop Entry]\n" "Encoding=UTF-8\n" "Name=%s\n" "Type=Link\n" "URL=%s\n" "%s%s\n", display_name, target_uri, image != NULL ? "Icon=" : "", image != NULL ? image : ""); if (!g_file_replace_contents (file, contents, strlen (contents), NULL, FALSE, G_FILE_CREATE_NONE, NULL, NULL, NULL)) { g_free (contents); g_object_unref (file); return FALSE; } g_free (contents); dummy_list.data = file; dummy_list.next = NULL; dummy_list.prev = NULL; athena_directory_notify_files_added (&dummy_list); if (point != NULL) { item.location = file; item.set = TRUE; item.point.x = point->x; item.point.y = point->y; item.screen = screen; dummy_list.data = &item; dummy_list.next = NULL; dummy_list.prev = NULL; athena_directory_schedule_position_set (&dummy_list); } g_object_unref (file); return TRUE; }
/** * rb_sanitize_path_for_msdos_filesystem: * @path: a path to sanitize (modified in place) * * Modifies @path such that it represents a legal path for MS DOS * filesystems. */ void rb_sanitize_path_for_msdos_filesystem (char *path) { g_strdelimit (path, "\"", '\''); g_strdelimit (path, ":|<>*?\\", '_'); }
/* * MUST BE CALLED AFTER WIDGETS ARE INITIALIZED!! * Fills keycodes into comboboxes */ int keycodes_parse(void) { FILE *fp; gchar buffer[512]; gchar *code; int mod; if ((fp = fopen(KEYCODE_FILE_PATH, "r")) == 0) { fprintf(stderr, "Error: keycodes_parse could not open %s: %s\n", KEYCODE_FILE_PATH, g_strerror(errno)); return -1; } mods = (gchar **) malloc(sizeof(gchar *)); keycodes = (gchar **) malloc(sizeof(gchar *)); mods[0] = g_strdup("NONE"); keycodes[0] = g_strdup("NONE"); keycodes_entry_add(keycodes[0]); num_mods++; num_keycodes++; while (fgets(buffer, 511, fp) != NULL) { mod = 0; g_strchug(buffer); if (strlen(buffer) == 0) continue; g_strdelimit(buffer, " \t", '\0'); code = g_strndup(buffer, 60); /* -------- Add the keycodes straight to the comboboxes --------- */ if (strcasecmp("KEY_LEFTCTRL", code) == 0) mod=1; else if (strcasecmp("KEY_RIGHTCTRL", code) == 0) mod=1; else if (strcasecmp("KEY_LEFTSHIFT", code) == 0) mod=1; else if (strcasecmp("KEY_RIGHTSHIFT", code) == 0) mod=1; else if (strcasecmp("KEY_LEFTALT", code) == 0) mod=1; else if (strcasecmp("KEY_RIGHTALT", code) == 0) mod=1; else if (strcasecmp("KEY_RIGHTCTRL", code) == 0) mod=1; else if (strcasecmp("KEY_LEFTMETA", code) == 0) mod=1; else if (strcasecmp("KEY_RIGHTMETA", code) == 0) mod=1; if (mod == 1) { gtk_combo_box_append_text(GTK_COMBO_BOX(GET_WIDGET(COMBOBOX_MOD1_CONFIG)), code); gtk_combo_box_append_text(GTK_COMBO_BOX(GET_WIDGET(COMBOBOX_MOD2_CONFIG)), code); gtk_combo_box_append_text(GTK_COMBO_BOX(GET_WIDGET(COMBOBOX_MOD3_CONFIG)), code); mods = (gchar **) realloc(mods, (num_mods+1) * sizeof(gchar *)); mods[num_mods++] = code; } else { keycodes_entry_add(code); //gtk_combo_box_append_text(GTK_COMBO_BOX(GET_WIDGET(COMBOBOX_KEYCODE_CONFIG)), code); keycodes = (gchar **) realloc(keycodes, (num_keycodes+1) * sizeof(gchar *)); keycodes[num_keycodes++] = code; } /* ---------------------------------------------------------------*/ } fclose(fp); return 1; }
/* open/merge the dnd file */ void dnd_open_file_cmd(gchar *cf_names_freeme) { int err; gchar *cf_name; int in_file_count; int files_work; char **in_filenames; char *tmpname; if (cf_names_freeme == NULL) return; /* DND_TARGET_URL: * The cf_name_freeme is a single string, containing one or more URI's, * terminated by CR/NL chars. The length of the whole field can be found * in the selection_data->length field. If it contains one file, simply open it, * If it contains more than one file, ask to merge these files. */ /* count the number of input files */ cf_name = cf_names_freeme; for(in_file_count = 0; (cf_name = strstr(cf_name, "\r\n")) != NULL; ) { cf_name += 2; in_file_count++; } if (in_file_count == 0) { g_free(cf_names_freeme); return; } in_filenames = (char **)g_malloc(sizeof(char*) * in_file_count); /* store the starts of the file entries in a gchar array */ cf_name = cf_names_freeme; in_filenames[0] = cf_name; for(files_work = 1; (cf_name = strstr(cf_name, "\r\n")) != NULL && files_work < in_file_count; ) { cf_name += 2; in_filenames[files_work] = cf_name; files_work++; } /* replace trailing CR NL simply with zeroes (in place), so we get valid terminated strings */ cf_name = cf_names_freeme; g_strdelimit(cf_name, "\r\n", '\0'); /* convert all filenames from URI to local filename (in place) */ for(files_work = 0; files_work < in_file_count; files_work++) { in_filenames[files_work] = dnd_uri2filename(in_filenames[files_work]); } if (in_file_count == 1) { /* open and read the capture file (this will close an existing file) */ if (cf_open(&cfile, in_filenames[0], FALSE, &err) == CF_OK) { /* XXX - add this to the menu if the read fails? */ cf_read(&cfile, FALSE); add_menu_recent_capture_file(in_filenames[0]); } else { /* the capture file couldn't be read (doesn't exist, file format unknown, ...) */ } } else { /* merge the files in chronological order */ tmpname = NULL; if (cf_merge_files(&tmpname, in_file_count, in_filenames, WTAP_FILE_PCAP, FALSE) == CF_OK) { /* Merge succeeded; close the currently-open file and try to open the merged capture file. */ cf_close(&cfile); if (cf_open(&cfile, tmpname, TRUE /* temporary file */, &err) == CF_OK) { g_free(tmpname); cf_read(&cfile, FALSE); } else { /* The merged file couldn't be read. */ g_free(tmpname); } } else { /* merge failed */ g_free(tmpname); } } g_free(in_filenames); g_free(cf_names_freeme); }