gint checksum_file_list_parse_checksum_file (CheckcopyFileList * list, GFile *root, GFile *file) { CheckcopyFileListPrivate *priv = GET_PRIVATE (list); GDataInputStream * in; gchar * line; gsize length; GCancellable *cancel; GError * error = NULL; GFile * parent; gchar * prefix; gint n = 0; cancel = checkcopy_get_cancellable (); parent = g_file_get_parent (file); prefix = g_file_get_relative_path (root, parent); in = g_data_input_stream_new (G_INPUT_STREAM (g_file_read (file, cancel, &error))); while ((line = g_data_input_stream_read_line (in, &length, cancel, &error)) != NULL) { gchar *c; if (*line == ';' || *line == '#') { /* skip comment lines */ continue; } /* find the end of the first column */ for (c = line; *c != ' ' && *c != '\0'; c++); /* make sure we found some chars and we don't just have one column */ if (c != line && *c != '\0') { gchar * checksum = NULL; gchar * filename = NULL; CheckcopyFileInfo * info; CheckcopyChecksumType checksum_type; /* found a checksum, parse the line into * checksum and filename */ n++; *c = '\0'; c++; checksum = g_strdup (line); checksum_type = checkcopy_file_info_get_checksum_type (line); /* skip spaces */ while (*c == ' ' && *c != '\0') c++; /* some programs mark filenames with a star */ if (*c == '*') c++; /* rest of the line is the file name */ if (prefix != NULL && *prefix != '\0') filename = g_strconcat (prefix, G_DIR_SEPARATOR_S, c, NULL); else filename = g_strdup (c); info = checkcopy_file_list_grab_info (list, filename); if (info->status == CHECKCOPY_STATUS_NONE) { info->checksum = checksum; info->checksum_type = checksum_type; checkcopy_file_list_transition (list, info, CHECKCOPY_STATUS_VERIFIABLE); DBG ("Parsed checksum for %s", info->relname); if (priv->verify_only) { checkcopy_worker_add_file (g_file_resolve_relative_path (root, filename)); } } else { /* We saw the file before the checksum. * * Verify it now. */ DBG ("%s was copied already, verifying it immediately", filename); if (!g_str_equal (info->checksum, checksum)) { /* Verification failed. We want to display the checksum * the file is supposed to have in the gui, so switch * the two variables. */ gchar * ts; ts = info->checksum; info->checksum = checksum; checksum = ts; /* TODO: display the checksum which the file actually has */ g_free (checksum); checkcopy_file_list_transition (list, info, CHECKCOPY_STATUS_VERIFICATION_FAILED); } } } g_free (line); } g_object_unref (parent); g_free (prefix); g_input_stream_close (G_INPUT_STREAM (in), cancel, &error); return n; }
/** * Read content of file or create file list from directory * @param aBuf read destination buffer * @param aCount length of destination buffer * @param aCountRead number of read characters * @return NS_OK when read successfully, NS_BASE_STREAM_CLOSED when end of file, * error code otherwise */ nsresult nsGIOInputStream::DoRead(char *aBuf, uint32_t aCount, uint32_t *aCountRead) { nsresult rv = NS_ERROR_NOT_AVAILABLE; if (mStream) { // file read GError *error = nullptr; uint32_t bytes_read = g_input_stream_read(G_INPUT_STREAM(mStream), aBuf, aCount, nullptr, &error); if (error) { rv = MapGIOResult(error); *aCountRead = 0; g_warning("Cannot read from file: %s", error->message); g_error_free(error); return rv; } *aCountRead = bytes_read; mBytesRemaining -= *aCountRead; return NS_OK; } else if (mDirOpen) { // directory read while (aCount && rv != NS_BASE_STREAM_CLOSED) { // Copy data out of our buffer uint32_t bufLen = mDirBuf.Length() - mDirBufCursor; if (bufLen) { uint32_t n = std::min(bufLen, aCount); memcpy(aBuf, mDirBuf.get() + mDirBufCursor, n); *aCountRead += n; aBuf += n; aCount -= n; mDirBufCursor += n; } if (!mDirListPtr) // Are we at the end of the directory list? { rv = NS_BASE_STREAM_CLOSED; } else if (aCount) // Do we need more data? { GFileInfo *info = (GFileInfo *) mDirListPtr->data; // Prune '.' and '..' from directory listing. const char * fname = g_file_info_get_name(info); if (fname && fname[0] == '.' && (fname[1] == '\0' || (fname[1] == '.' && fname[2] == '\0'))) { mDirListPtr = mDirListPtr->next; continue; } mDirBuf.AssignLiteral("201: "); // The "filename" field nsCString escName; nsCOMPtr<nsINetUtil> nu = do_GetService(NS_NETUTIL_CONTRACTID); if (nu && fname) { nu->EscapeString(nsDependentCString(fname), nsINetUtil::ESCAPE_URL_PATH, escName); mDirBuf.Append(escName); mDirBuf.Append(' '); } // The "content-length" field // XXX truncates size from 64-bit to 32-bit mDirBuf.AppendInt(int32_t(g_file_info_get_size(info))); mDirBuf.Append(' '); // The "last-modified" field // // NSPR promises: PRTime is compatible with time_t // we just need to convert from seconds to microseconds GTimeVal gtime; g_file_info_get_modification_time(info, >ime); PRExplodedTime tm; PRTime pt = ((PRTime) gtime.tv_sec) * 1000000; PR_ExplodeTime(pt, PR_GMTParameters, &tm); { char buf[64]; PR_FormatTimeUSEnglish(buf, sizeof(buf), "%a,%%20%d%%20%b%%20%Y%%20%H:%M:%S%%20GMT ", &tm); mDirBuf.Append(buf); } // The "file-type" field switch (g_file_info_get_file_type(info)) { case G_FILE_TYPE_REGULAR: mDirBuf.AppendLiteral("FILE "); break; case G_FILE_TYPE_DIRECTORY: mDirBuf.AppendLiteral("DIRECTORY "); break; case G_FILE_TYPE_SYMBOLIC_LINK: mDirBuf.AppendLiteral("SYMBOLIC-LINK "); break; default: break; } mDirBuf.Append('\n'); mDirBufCursor = 0; mDirListPtr = mDirListPtr->next; } } } return rv; }
void scrollback_load (session *sess) { GInputStream *stream; GDataInputStream *istream; gchar *buf, *text; gint lines = 0; time_t stamp = 0; if (sess->text_scrollback == SET_DEFAULT) { if (!prefs.hex_text_replay) return; } else { if (sess->text_scrollback != SET_ON) return; } if (!sess->scrollfile) { if ((buf = scrollback_get_filename (sess)) == NULL) return; sess->scrollfile = g_file_new_for_path (buf); g_free (buf); } stream = G_INPUT_STREAM(g_file_read (sess->scrollfile, NULL, NULL)); if (!stream) return; istream = g_data_input_stream_new (stream); /* * This is to avoid any issues moving between windows/unix * but the docs mention an invalid \r without a following \n * can lock up the program... (Our write() always adds \n) */ g_data_input_stream_set_newline_type (istream, G_DATA_STREAM_NEWLINE_TYPE_ANY); g_object_unref (stream); while (1) { GError *err = NULL; gsize n_bytes; buf = g_data_input_stream_read_line_utf8 (istream, &n_bytes, NULL, &err); if (!err && buf) { /* * Some scrollback lines have three blanks after the timestamp and a newline * Some have only one blank and a newline * Some don't even have a timestamp * Some don't have any text at all */ if (buf[0] == 'T' && buf[1] == ' ') { if (sizeof (time_t) == 4) stamp = strtoul (buf + 2, NULL, 10); else stamp = g_ascii_strtoull (buf + 2, NULL, 10); /* in case time_t is 64 bits */ if (G_UNLIKELY(stamp == 0)) { g_warning ("Invalid timestamp in scrollback file"); continue; } text = strchr (buf + 3, ' '); if (text && text[1]) { if (prefs.hex_text_stripcolor_replay) { text = strip_color (text + 1, -1, STRIP_COLOR); } fe_print_text (sess, text, stamp, TRUE); if (prefs.hex_text_stripcolor_replay) { g_free (text); } } else { fe_print_text (sess, " ", stamp, TRUE); } } else { if (strlen (buf)) fe_print_text (sess, buf, 0, TRUE); else fe_print_text (sess, " ", 0, TRUE); } lines++; g_free (buf); } else if (err) { /* If its only an encoding error it may be specific to the line */ if (g_error_matches (err, G_CONVERT_ERROR, G_CONVERT_ERROR_ILLEGAL_SEQUENCE)) { g_warning ("Invalid utf8 in scrollback file"); g_clear_error (&err); continue; } /* For general errors just give up */ g_clear_error (&err); break; } else /* No new line */ { break; } } g_object_unref (istream); sess->scrollwritten = lines; if (lines) { text = ctime (&stamp); buf = g_strdup_printf ("\n*\t%s %s\n", _("Loaded log from"), text); fe_print_text (sess, buf, 0, TRUE); g_free (buf); /*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/ } }
/** * gimp_scanner_new_gfile: * @file: a #GFile * @error: return location for #GError, or %NULL * * Return value: The new #GScanner. * * Since: 2.10 **/ GScanner * gimp_scanner_new_gfile (GFile *file, GError **error) { GScanner *scanner; gchar *path; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); path = g_file_get_path (file); if (path) { GMappedFile *mapped; mapped = g_mapped_file_new (path, FALSE, error); g_free (path); if (! mapped) { if (error) { (*error)->domain = GIMP_CONFIG_ERROR; (*error)->code = ((*error)->code == G_FILE_ERROR_NOENT ? GIMP_CONFIG_ERROR_OPEN_ENOENT : GIMP_CONFIG_ERROR_OPEN); } return NULL; } /* gimp_scanner_new() takes a "name" for the scanner, not a filename */ scanner = gimp_scanner_new (gimp_file_get_utf8_name (file), mapped, NULL, error); g_scanner_input_text (scanner, g_mapped_file_get_contents (mapped), g_mapped_file_get_length (mapped)); } else { GInputStream *input; input = G_INPUT_STREAM (g_file_read (file, NULL, error)); if (! input) { if (error) { (*error)->domain = GIMP_CONFIG_ERROR; (*error)->code = ((*error)->code == G_IO_ERROR_NOT_FOUND ? GIMP_CONFIG_ERROR_OPEN_ENOENT : GIMP_CONFIG_ERROR_OPEN); } return NULL; } g_object_set_data (G_OBJECT (input), "gimp-data", file); scanner = gimp_scanner_new_stream (input, error); g_object_unref (input); } return scanner; }
/** * as_validator_validate_file: * @validator: An instance of #AsValidator. * @metadata_file: An AppStream XML file. * * Validate an AppStream XML file **/ gboolean as_validator_validate_file (AsValidator *validator, GFile *metadata_file) { g_autoptr(GFileInfo) info = NULL; g_autoptr(GInputStream) file_stream = NULL; g_autoptr(GInputStream) stream_data = NULL; g_autoptr(GConverter) conv = NULL; g_autoptr(GString) asxmldata = NULL; g_autofree gchar *fname = NULL; gssize len; const gsize buffer_size = 1024 * 32; g_autofree gchar *buffer = NULL; const gchar *content_type = NULL; g_autoptr(GError) tmp_error = NULL; gboolean ret; info = g_file_query_info (metadata_file, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) content_type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE); fname = g_file_get_basename (metadata_file); as_validator_set_current_fname (validator, fname); file_stream = G_INPUT_STREAM (g_file_read (metadata_file, NULL, &tmp_error)); if (tmp_error != NULL) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_READ_ERROR, "Unable to read file: %s", tmp_error->message); return FALSE; } if (file_stream == NULL) return FALSE; if ((g_strcmp0 (content_type, "application/gzip") == 0) || (g_strcmp0 (content_type, "application/x-gzip") == 0)) { /* decompress the GZip stream */ conv = G_CONVERTER (g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP)); stream_data = g_converter_input_stream_new (file_stream, conv); } else { stream_data = g_object_ref (file_stream); } asxmldata = g_string_new (""); buffer = g_malloc (buffer_size); while ((len = g_input_stream_read (stream_data, buffer, buffer_size, NULL, &tmp_error)) > 0) { g_string_append_len (asxmldata, buffer, len); } if (tmp_error != NULL) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_READ_ERROR, "Unable to read file: %s", tmp_error->message); return FALSE; } /* check if there was an error */ if (len < 0) return FALSE; ret = as_validator_validate_data (validator, asxmldata->str); as_validator_clear_current_fname (validator); return ret; }
static gboolean xmms_gvfs_init (xmms_xform_t *xform) { xmms_gvfs_data_t *data; GFile *file; GFileInfo *info; GFileInputStream *handle; GError *error = NULL; const gchar *url; url = xmms_xform_indata_get_str (xform, XMMS_STREAM_TYPE_URL); g_return_val_if_fail (url, FALSE); /* This is an ugly hack to handle files with chars needing url encoding */ if (!g_ascii_strncasecmp (url, "file://", 7)) { file = g_file_new_for_path (url+7); } else { file = g_file_new_for_uri (url); } handle = g_file_read (file, NULL, &error); g_object_unref (file); if (!handle) { xmms_log_error ("Failed to upen url %s for reading: %s", url, error->message); return FALSE; } data = g_new (xmms_gvfs_data_t, 1); data->handle = G_INPUT_STREAM (handle); xmms_xform_private_data_set (xform, data); info = g_file_input_stream_query_info (handle, (char *)query_attributes, NULL, &error); if (!info) { xmms_log_info ("failed to query information for %s", url); } else { int i; for (i = 0; i < G_N_ELEMENTS (attr_map); i++) { if (!g_file_info_has_attribute (info, attr_map[i].gvfs)) { continue; } switch (attr_map[i].type) { case XMMSV_TYPE_STRING: { gchar *attr = g_file_info_get_attribute_as_string (info, attr_map[i].gvfs); xmms_xform_metadata_set_str (xform, attr_map[i].mlib, attr); g_free (attr); break; } case XMMSV_TYPE_INT32: { /* right now the xform metadata api only handles strings * and 32 bit ints. however the gvfs api returns uint64 for * the numeric attributes we're interested in and we just * pass that to the xform and pray that it doesn't overflow * as we know it's unsafe. */ gint64 attr = g_file_info_get_attribute_uint64 (info, attr_map[i].gvfs); xmms_xform_metadata_set_int (xform, attr_map[i].mlib, attr); break; } default: g_assert_not_reached (); } } g_object_unref (info); } xmms_xform_outdata_type_add (xform, XMMS_STREAM_TYPE_MIMETYPE, "application/octet-stream", XMMS_STREAM_TYPE_END); return TRUE; }
static void render_card_init (char *card_fname) { int i; if (render_init) { for (i = 0; i < 52; i++) g_object_unref (card_pixbuf[i]); cairo_surface_destroy (grey_surface); render_init = 0; } /* gdk_pixbuf_new_from_file doesn't seem to support .svgz (while * librsvg does), so decompress it here. Code from aisleriot * src/lib/ar-svg.c */ GFile *cf = g_file_new_for_path (card_fname); GFileInfo *info; GError *error = NULL; if (!(info = g_file_query_info (cf, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL, &error))) { printf ("%s: %s\n", card_fname, error->message); g_object_unref (cf); g_error_free (error); return; } const char *type = g_file_info_get_attribute_string (info, G_FILE_ATTRIBUTE_STANDARD_FAST_CONTENT_TYPE); char *gz_type = g_content_type_from_mime_type ("application/x-gzip"); gboolean is_gzip = (type != NULL && g_content_type_is_a (type, gz_type)); g_free (gz_type); g_object_unref (info); GInputStream *stream; if (!(stream = G_INPUT_STREAM (g_file_read (cf, NULL, &error)))) { printf ("%s: %s\n", card_fname, error->message); g_object_unref (cf); g_error_free (error); return; } g_object_unref (cf); if (is_gzip) { GZlibDecompressor *decompressor; GInputStream *converter_stream; decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP); converter_stream = g_converter_input_stream_new (stream, G_CONVERTER (decompressor)); g_object_unref (stream); stream = converter_stream; } /* file contains cards in 13 columns (A/2..10/J/Q/K) and 5 rows (C/D/H/S/Jokers) */ /* actual card height is computed from resulting actual size */ GdkPixbuf *pb = gdk_pixbuf_new_from_stream_at_scale (stream, card_width * 13, -1, TRUE, NULL, &error); g_object_unref (stream); if (!pb) { printf ("%s: %s.\n", card_fname, error->message); g_error_free (error); return; } int buf_width = gdk_pixbuf_get_width (pb); int buf_height = gdk_pixbuf_get_height (pb); card_width = ceil (gdk_pixbuf_get_width (pb) / 13.0); card_height = ceil (gdk_pixbuf_get_height (pb) / 5.0); for (i = 0; i < 52; i++) { card_pixbuf[i] = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, card_width, card_height); if (!card_pixbuf[i]) { printf ("%s: rendering card_pixbuf failed\n", card_fname); return; } int col = (i + 1) % 13; int row = i / 13; gdk_pixbuf_copy_area (pb, buf_width * col / 13.0, buf_height * row / 5.0, //gdk_pixbuf_copy_area (pb, card_width * col, card_height * row, card_width, card_height, card_pixbuf[i], 0, 0); } g_object_unref (pb); /* construct a alpha channel in card shape for greying out cards */ grey_surface = cairo_image_surface_create (CAIRO_FORMAT_A8, card_width, card_height); cairo_t *ct = cairo_create (grey_surface); gdk_cairo_set_source_pixbuf (ct, card_pixbuf[0], 0, 0); cairo_paint_with_alpha (ct, 0.3); cairo_destroy (ct); render_init = 1; }
static GimpValueArray * xcf_load_invoker (GimpProcedure *procedure, Gimp *gimp, GimpContext *context, GimpProgress *progress, const GimpValueArray *args, GError **error) { XcfInfo info = { 0, }; GimpValueArray *return_vals; GimpImage *image = NULL; const gchar *uri; gchar *filename; GFile *file; gboolean success = FALSE; gchar id[14]; GError *my_error = NULL; gimp_set_busy (gimp); uri = g_value_get_string (gimp_value_array_index (args, 1)); #ifdef GIO_IS_FIXED file = g_file_new_for_uri (uri); #else file = g_file_new_for_path (uri); #endif filename = g_file_get_parse_name (file); info.input = G_INPUT_STREAM (g_file_read (file, NULL, &my_error)); if (info.input) { info.gimp = gimp; info.seekable = G_SEEKABLE (info.input); info.progress = progress; info.filename = filename; info.compression = COMPRESS_NONE; if (progress) { gchar *name = g_filename_display_name (filename); gchar *msg = g_strdup_printf (_("Opening '%s'"), name); gimp_progress_start (progress, msg, FALSE); g_free (msg); g_free (name); } success = TRUE; info.cp += xcf_read_int8 (info.input, (guint8 *) id, 14); if (! g_str_has_prefix (id, "gimp xcf ")) { success = FALSE; } else if (strcmp (id + 9, "file") == 0) { info.file_version = 0; } else if (id[9] == 'v') { info.file_version = atoi (id + 10); } else { success = FALSE; } if (success) { if (info.file_version >= 0 && info.file_version < G_N_ELEMENTS (xcf_loaders)) { image = (*(xcf_loaders[info.file_version])) (gimp, &info, error); if (! image) success = FALSE; } else { g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_FAILED, _("XCF error: unsupported XCF file version %d " "encountered"), info.file_version); success = FALSE; } } g_object_unref (info.input); if (progress) gimp_progress_end (progress); } else { g_propagate_prefixed_error (error, my_error, _("Could not open '%s' for reading: "), filename); } g_free (filename); g_object_unref (file); return_vals = gimp_procedure_get_return_values (procedure, success, error ? *error : NULL); if (success) gimp_value_set_image (gimp_value_array_index (return_vals, 1), image); gimp_unset_busy (gimp); return return_vals; }
static GstylePalette * gstyle_palette_new_from_xml (GFile *file, GCancellable *cancellable, GError **error) { g_autoptr(GInputStream) stream = NULL; g_autofree gchar *uri = NULL; GstylePalette *palette = NULL; xmlTextReaderPtr reader; GError *tmp_error = NULL; gboolean has_colors = FALSE; gint ret = -1; g_assert (G_IS_FILE (file)); uri = g_file_get_uri (file); if (!(stream = G_INPUT_STREAM (g_file_read (file, cancellable, &tmp_error)))) goto finish; reader = xmlReaderForIO (gstyle_palette_io_read_cb, gstyle_palette_io_close_cb, stream, uri, NULL, XML_PARSE_RECOVER | XML_PARSE_NOBLANKS | XML_PARSE_COMPACT); if (reader != NULL) { GstyleColor *color; g_autofree gchar *id = NULL; g_autofree gchar *name = NULL; g_autofree gchar *domain = NULL; xmlTextReaderSetErrorHandler (reader, gstyle_palette_error_cb, NULL); if (xmlTextReaderRead(reader) && gstyle_palette_xml_get_header (reader, &id, &name, &domain)) { palette = g_object_new (GSTYLE_TYPE_PALETTE, "id", id, "domain", domain, "name", name, "file", file, NULL); ret = xmlTextReaderRead(reader); while (ret == 1) { if (xmlTextReaderNodeType (reader) == XML_READER_TYPE_END_ELEMENT) { ret = 0; break; } /* TODO: better naming */ color = gstyle_palette_xml_get_color (reader); if (color == NULL) { ret = -1; break; } gstyle_palette_add (palette, color, &tmp_error); g_object_unref (color); has_colors = TRUE; ret = xmlTextReaderRead(reader); } } if (ret != 0 || !has_colors) { g_clear_object (&palette); g_set_error (&tmp_error, GSTYLE_PALETTE_ERROR, GSTYLE_PALETTE_ERROR_PARSE, _("%s: failed to parse\n"), uri); } xmlTextReaderClose(reader); xmlFreeTextReader(reader); } else g_set_error (&tmp_error, GSTYLE_PALETTE_ERROR, GSTYLE_PALETTE_ERROR_FILE, _("Unable to open %s\n"), uri); finish: if (tmp_error) g_propagate_error (error, tmp_error); return palette; }
/* * info_mpc_read: * @file: file from which to read a header * @stream_info: stream information to fill * @error: a #Gerror, or %NULL * * Read header from the given MusePack @file. * * Returns: %TRUE on success, %FALSE and with @error set on failure */ gboolean info_mpc_read (GFile *file, StreamInfoMpc *stream_info, GError **error) { GFileInfo *info; GFileInputStream *istream; guint32 header_buffer[MPC_HEADER_LENGTH]; gsize bytes_read; gsize id3_size; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); if (!info) { return FALSE; } stream_info->FileSize = g_file_info_get_size (info); g_object_unref (info); { gchar *path; FILE *fp; path = g_file_get_path (file); fp = g_fopen (path, "rb"); g_free (path); if (!fp) { /* TODO: Add specific error domain and message. */ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s", g_strerror (EINVAL)); return FALSE; } /* Skip id3v2. */ /* FIXME: is_id3v2 (and is_id3v1 and is_ape) should accept an istream * or GFile. */ id3_size = is_id3v2 (fp); fseek (fp, 0, SEEK_END); stream_info->FileSize = ftell (fp); /* Stream size. */ stream_info->ByteLength = stream_info->FileSize - is_id3v1 (fp) - is_ape (fp) - id3_size; fclose (fp); } istream = g_file_read (file, NULL, error); if (!istream) { return FALSE; } if (!g_seekable_seek (G_SEEKABLE (istream), id3_size, G_SEEK_SET, NULL, error)) { return FALSE; } /* Read 16 guint32. */ if (!g_input_stream_read_all (G_INPUT_STREAM (istream), header_buffer, MPC_HEADER_LENGTH * 4, &bytes_read, NULL, error)) { g_debug ("Only %" G_GSIZE_FORMAT "bytes out of 16 bytes of data were " "read", bytes_read); return FALSE; } /* FIXME: Read 4 bytes, take as a uint32, then byteswap if necessary. (The * official Musepack decoder expects the user(!) to request the * byteswap.) */ if (memcmp (header_buffer, "MP+", 3) != 0) { /* TODO: Add specific error domain and message. */ g_set_error (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "%s", g_strerror (EINVAL)); return FALSE; } stream_info->StreamVersion = header_buffer[0] >> 24; if (stream_info->StreamVersion >= 7) { const long samplefreqs[4] = { 44100, 48000, 37800, 32000 }; // read the file-header (SV7 and above) stream_info->Bitrate = 0; stream_info->Frames = header_buffer[1]; stream_info->SampleFreq = samplefreqs[(header_buffer[2] >> 16) & 0x0003]; stream_info->MaxBand = (header_buffer[2] >> 24) & 0x003F; stream_info->MS = (header_buffer[2] >> 30) & 0x0001; stream_info->Profile = (header_buffer[2] << 8) >> 28; stream_info->IS = (header_buffer[2] >> 31) & 0x0001; stream_info->BlockSize = 1; stream_info->EncoderVersion = (header_buffer[6] >> 24) & 0x00FF; stream_info->Channels = 2; // gain stream_info->EstPeakTitle = header_buffer[2] & 0xFFFF; // read the ReplayGain data stream_info->GainTitle = (header_buffer[3] >> 16) & 0xFFFF; stream_info->PeakTitle = header_buffer[3] & 0xFFFF; stream_info->GainAlbum = (header_buffer[4] >> 16) & 0xFFFF; stream_info->PeakAlbum = header_buffer[4] & 0xFFFF; // gaples stream_info->IsTrueGapless = (header_buffer[5] >> 31) & 0x0001; // true gapless: used? stream_info->LastFrameSamples = (header_buffer[5] >> 20) & 0x07FF; // true gapless: valid samples for last frame if (stream_info->EncoderVersion == 0) { sprintf (stream_info->Encoder, "<= 1.05"); // Buschmann 1.7.x, Klemm <= 1.05 } else { switch (stream_info->EncoderVersion % 10) { case 0: sprintf (stream_info->Encoder, "%u.%u", stream_info->EncoderVersion / 100, stream_info->EncoderVersion / 10 % 10); break; case 2: case 4: case 6: case 8: sprintf (stream_info->Encoder, "%u.%02u Beta", stream_info->EncoderVersion / 100, stream_info->EncoderVersion % 100); break; default: sprintf (stream_info->Encoder, "%u.%02u Alpha", stream_info->EncoderVersion / 100, stream_info->EncoderVersion % 100); break; } } // estimation, exact value needs too much time stream_info->Bitrate = (long) (stream_info->ByteLength) * 8. * stream_info->SampleFreq / (1152 * stream_info->Frames - 576); } else {
/** * gimp_color_profile_new_from_file: * @file: a #GFile * @error: return location for #GError * * This function opens an ICC color profile from @file. * * Return value: the #GimpColorProfile, or %NULL. On error, %NULL is * returned and @error is set. * * Since: 2.10 **/ GimpColorProfile * gimp_color_profile_new_from_file (GFile *file, GError **error) { GimpColorProfile *profile = NULL; cmsHPROFILE lcms_profile = NULL; guint8 *data = NULL; gsize length = 0; gchar *path; g_return_val_if_fail (G_IS_FILE (file), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); path = g_file_get_path (file); if (path) { GMappedFile *mapped; mapped = g_mapped_file_new (path, FALSE, error); if (! mapped) return NULL; length = g_mapped_file_get_length (mapped); data = g_memdup (g_mapped_file_get_contents (mapped), length); lcms_profile = cmsOpenProfileFromMem (data, length); g_mapped_file_unref (mapped); } else { GFileInfo *info; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, error); if (info) { GInputStream *input; length = g_file_info_get_size (info); data = g_malloc (length); g_object_unref (info); input = G_INPUT_STREAM (g_file_read (file, NULL, error)); if (input) { gsize bytes_read; if (g_input_stream_read_all (input, data, length, &bytes_read, NULL, error) && bytes_read == length) { lcms_profile = cmsOpenProfileFromMem (data, length); } g_object_unref (input); } } } if (lcms_profile) { profile = g_object_new (GIMP_TYPE_COLOR_PROFILE, NULL); profile->priv->lcms_profile = lcms_profile; profile->priv->data = data; profile->priv->length = length; } else { if (data) g_free (data); if (error && *error == NULL) { g_set_error (error, gimp_color_profile_error_quark (), 0, _("'%s' does not appear to be an ICC color profile"), gimp_file_get_utf8_name (file)); } } return profile; }
static void web_handler (ShpHttpRequest request, const gchar * path, const gchar * query, GSocketConnection * connection, gpointer user_data) { ShpRest *self = SHP_REST (user_data); GFile *file; GFileInputStream *input_stream; GDataInputStream *data; GError *error = NULL; GOutputStream *out; gchar *line; ShpJsonNode *node; out = g_io_stream_get_output_stream (G_IO_STREAM (connection)); if (request != SHP_HTTP_GET) { g_debug ("rest: unsupported request type"); send_error (out, 400, "Invalid request"); return; } if (self->config_file == NULL) { g_warning ("rest: config file not specified"); send_error (out, 500, "Internal server error"); return; } /* FIXME: load file at start */ file = g_file_new_for_path (self->config_file); input_stream = g_file_read (file, NULL, &error); if (!input_stream) { g_warning ("rest: error reading config file: %s", error->message); g_clear_error (&error); send_error (out, 500, "Internal server error"); return; } data = g_data_input_stream_new (G_INPUT_STREAM (input_stream)); node = shp_json_node_new_object (NULL); while (TRUE) { guint i; gchar **options_list; ShpJsonNode *obj = NULL; ShpJsonNode *arr = NULL; //plugin:device-type:type1,option1:type2,option2 line = g_data_input_stream_read_line (data, NULL, NULL, NULL); if (!line) break; g_debug ("rest: config file line: %s", line); options_list = g_strsplit (line, ":", 0); for (i = 0; options_list[i] != NULL; i++) { ShpJsonNode *child; ShpJsonNode *grand_child; gchar **params; switch (i) { case 0: obj = shp_json_node_new_object (options_list[i]); break; case 1: child = shp_json_node_new_string ("device-type", options_list[i]); shp_json_node_append_element (obj, child); break; case 2: arr = shp_json_node_new_array ("display-options"); /* fall trhough */ default: params = g_strsplit (options_list[i], " ", 0); if (params && params[0] && params[1] && !params[2]) { child = shp_json_node_new_object (NULL); grand_child = shp_json_node_new_string ("option", params[0]); shp_json_node_append_element (child, grand_child); grand_child = shp_json_node_new_string ("type", params[1]); shp_json_node_append_element (child, grand_child); shp_json_node_append_element (arr, child); } g_strfreev (params); break; } } g_strfreev (options_list); if (obj != NULL) { if (arr != NULL) shp_json_node_append_element (obj, arr); shp_json_node_append_element (node, obj); } g_free (line); } g_object_unref (input_stream); g_object_unref (file); send_ok (out, node); shp_json_node_free (node); }
* * Returns: a #GFileInfo, or %NULL on error. **/ GFileInfo * g_file_input_stream_query_info (GFileInputStream *stream, const char *attributes, GCancellable *cancellable, GError **error) { GFileInputStreamClass *class; GInputStream *input_stream; GFileInfo *info; g_return_val_if_fail (G_IS_FILE_INPUT_STREAM (stream), NULL); input_stream = G_INPUT_STREAM (stream); if (!g_input_stream_set_pending (input_stream, error)) return NULL; info = NULL; if (cancellable) g_cancellable_push_current (cancellable); class = G_FILE_INPUT_STREAM_GET_CLASS (stream); if (class->query_info) info = class->query_info (stream, attributes, cancellable, error); else g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED, _("Stream doesn't support query_info"));
void MainWindow::dragDataRecived(GtkWidget * widget, GdkDragContext * dragContext, gint x, gint y, GtkSelectionData * data, guint info, guint time, MainWindow * win) { GtkWidget * source = gtk_drag_get_source_widget(dragContext); if (source && widget == gtk_widget_get_toplevel(source)) { gtk_drag_finish(dragContext, false, false, time); return; } guchar * text = gtk_selection_data_get_text(data); if (text) { win->control->clipboardPasteText((const char *) text); g_free(text); gtk_drag_finish(dragContext, true, false, time); return; } GdkPixbuf * image = gtk_selection_data_get_pixbuf(data); if (image) { win->control->clipboardPasteImage(image); gdk_pixbuf_unref(image); gtk_drag_finish(dragContext, true, false, time); return; } // TODO LOW PRIO: use x and y for insert location! gchar ** uris = gtk_selection_data_get_uris(data); if (uris) { for (int i = 0; uris[i] != NULL && i < 3; i++) { const char * uri = uris[i]; // TODO LOW PRIO: check first if its an image // GSList * imageFormats = gdk_pixbuf_get_formats(); // for(GSList * l = imageFormats; l != NULL; l = l->next) { // GdkPixbufFormat * f = (GdkPixbufFormat *)l->data; // printf("", f); // } // // g_slist_free(imageFormats); GFile * file = g_file_new_for_uri(uri); GError * err = NULL; GCancellable * cancel = g_cancellable_new(); int cancelTimeout = g_timeout_add(3000, (GSourceFunc) cancellable_cancel, cancel); GFileInputStream * in = g_file_read(file, cancel, &err); if (g_cancellable_is_cancelled(cancel)) { continue; } g_object_unref(file); if (err == NULL) { GdkPixbuf * pixbuf = gdk_pixbuf_new_from_stream(G_INPUT_STREAM(in), cancel, NULL); if (g_cancellable_is_cancelled(cancel)) { continue; } g_input_stream_close(G_INPUT_STREAM(in), cancel, NULL); if (g_cancellable_is_cancelled(cancel)) { continue; } if (pixbuf) { win->control->clipboardPasteImage(pixbuf); gdk_pixbuf_unref(pixbuf); } } else { g_error_free(err); } if (!g_cancellable_is_cancelled(cancel)) { g_source_remove(cancelTimeout); } g_object_unref(cancel); //TODO LOW PRIO: handle .xoj, .pdf and Images printf("open uri: %s\n", uris[i]); } gtk_drag_finish(dragContext, true, false, time); g_strfreev(uris); } gtk_drag_finish(dragContext, false, false, time); }
static void on_input_stream_close_ready (GObject * object, GAsyncResult * res, gpointer data) { GError * error = NULL; g_input_stream_close_finish (G_INPUT_STREAM(object), res, &error); handle_critical_error (error); }
static gboolean ensure_thumbnail_job (GIOSchedulerJob *job, GCancellable *cancellable, gpointer user_data) { LoadThumbnailData *data = user_data; gboolean thumb_failed; const gchar *thumb_path; GError *error = NULL; GFile *thumb_file = NULL; GFileInputStream *is = NULL; GFileInfo *info = NULL; info = g_file_query_info (data->font_file, ATTRIBUTES_FOR_EXISTING_THUMBNAIL, G_FILE_QUERY_INFO_NONE, NULL, &error); if (error != NULL) { g_debug ("Can't query info for file %s: %s\n", data->font_path, error->message); goto out; } thumb_failed = g_file_info_get_attribute_boolean (info, G_FILE_ATTRIBUTE_THUMBNAILING_FAILED); if (thumb_failed) goto out; thumb_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH); if (thumb_path != NULL) { thumb_file = g_file_new_for_path (thumb_path); is = g_file_read (thumb_file, NULL, &error); if (error != NULL) { g_debug ("Can't read file %s: %s\n", thumb_path, error->message); goto out; } data->pixbuf = gdk_pixbuf_new_from_stream_at_scale (G_INPUT_STREAM (is), 128, 128, TRUE, NULL, &error); if (error != NULL) { g_debug ("Can't read thumbnail pixbuf %s: %s\n", thumb_path, error->message); goto out; } } else { data->pixbuf = create_thumbnail (data); } out: g_clear_error (&error); g_clear_object (&is); g_clear_object (&thumb_file); g_clear_object (&info); g_io_scheduler_job_send_to_mainloop_async (job, ensure_thumbnail_job_done, data, NULL); return FALSE; }
static GstFlowReturn gst_gio_base_src_create (GstBaseSrc * base_src, guint64 offset, guint size, GstBuffer ** buf_return) { GstGioBaseSrc *src = GST_GIO_BASE_SRC (base_src); GstBuffer *buf; GstFlowReturn ret = GST_FLOW_OK; g_return_val_if_fail (G_IS_INPUT_STREAM (src->stream), GST_FLOW_ERROR); /* If we have the requested part in our cache take a subbuffer of that, * otherwise fill the cache again with at least 4096 bytes from the * requested offset and return a subbuffer of that. * * We need caching because every read/seek operation will need to go * over DBus if our backend is GVfs and this is painfully slow. */ if (src->cache && offset >= GST_BUFFER_OFFSET (src->cache) && offset + size <= GST_BUFFER_OFFSET_END (src->cache)) { GST_DEBUG_OBJECT (src, "Creating subbuffer from cached buffer: offset %" G_GUINT64_FORMAT " length %u", offset, size); buf = gst_buffer_copy_region (src->cache, GST_BUFFER_COPY_ALL, offset - GST_BUFFER_OFFSET (src->cache), size); GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + size; } else { guint cachesize = MAX (4096, size); GstMapInfo map; gssize read, res; gboolean success, eos; GError *err = NULL; if (src->cache) { gst_buffer_unref (src->cache); src->cache = NULL; } if (G_UNLIKELY (offset != src->position)) { if (!GST_GIO_STREAM_IS_SEEKABLE (src->stream)) return GST_FLOW_NOT_SUPPORTED; GST_DEBUG_OBJECT (src, "Seeking to position %" G_GUINT64_FORMAT, offset); ret = gst_gio_seek (src, G_SEEKABLE (src->stream), offset, src->cancel); if (ret == GST_FLOW_OK) src->position = offset; else return ret; } src->cache = gst_buffer_new_and_alloc (cachesize); if (G_UNLIKELY (src->cache == NULL)) { GST_ERROR_OBJECT (src, "Failed to allocate %u bytes", cachesize); return GST_FLOW_ERROR; } GST_LOG_OBJECT (src, "Reading %u bytes from offset %" G_GUINT64_FORMAT, cachesize, offset); /* GIO sometimes gives less bytes than requested although * it's not at the end of file. SMB for example only * supports reads up to 64k. So we loop here until we get at * at least the requested amount of bytes or a read returns * nothing. */ gst_buffer_map (src->cache, &map, GST_MAP_WRITE); read = 0; while (size - read > 0 && (res = g_input_stream_read (G_INPUT_STREAM (src->stream), map.data + read, cachesize - read, src->cancel, &err)) > 0) { read += res; } gst_buffer_unmap (src->cache, &map); success = (read >= 0); eos = (cachesize > 0 && read == 0); if (!success && !gst_gio_error (src, "g_input_stream_read", &err, &ret)) { GST_ELEMENT_ERROR (src, RESOURCE, READ, (NULL), ("Could not read from stream: %s", err->message)); g_clear_error (&err); } if (success && !eos) { src->position += read; GST_BUFFER_OFFSET (src->cache) = offset; GST_BUFFER_OFFSET_END (src->cache) = offset + read; GST_DEBUG_OBJECT (src, "Read successful"); GST_DEBUG_OBJECT (src, "Creating subbuffer from new " "cached buffer: offset %" G_GUINT64_FORMAT " length %u", offset, size); buf = gst_buffer_copy_region (src->cache, GST_BUFFER_COPY_ALL, 0, MIN (size, read)); GST_BUFFER_OFFSET (buf) = offset; GST_BUFFER_OFFSET_END (buf) = offset + MIN (size, read); } else { GST_DEBUG_OBJECT (src, "Read not successful"); gst_buffer_unref (src->cache); src->cache = NULL; buf = NULL; } if (eos) ret = GST_FLOW_EOS; } *buf_return = buf; return ret; }
static void avatar_chooser_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, EmpathyAvatarChooser *chooser) { gchar *target_type; gboolean handled = FALSE; target_type = gdk_atom_name (selection_data->target); if (!strcmp (target_type, URI_LIST_TYPE)) { GFile *file; GFileInputStream *input_stream; gchar *nl; gchar *data = NULL; nl = strstr (selection_data->data, "\r\n"); if (nl) { gchar *uri; uri = g_strndup (selection_data->data, nl - (gchar *) selection_data->data); file = g_file_new_for_uri (uri); g_free (uri); } else { file = g_file_new_for_uri (selection_data->data); } input_stream = g_file_read (file, NULL, NULL); if (input_stream != NULL) { GFileInfo *info; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, NULL, NULL); if (info != NULL) { goffset size; gssize bytes_read; size = g_file_info_get_size (info); data = g_malloc (size); bytes_read = g_input_stream_read (G_INPUT_STREAM (input_stream), data, size, NULL, NULL); if (bytes_read != -1) { avatar_chooser_set_image_from_data ( chooser, data, (gsize) bytes_read, TRUE); handled = TRUE; } g_free (data); g_object_unref (info); } g_object_unref (input_stream); } g_object_unref (file); } gtk_drag_finish (context, handled, FALSE, time); }
gboolean check_bundle(const gchar *bundlename, gsize *size, gboolean verify, GError **error) { GError *ierror = NULL; GBytes *sig = NULL; GFile *bundlefile = NULL; GFileInputStream *bundlestream = NULL; guint64 sigsize; goffset offset; gboolean res = FALSE; r_context_begin_step("check_bundle", "Checking bundle", verify); if (!r_context()->config->keyring_path) { g_set_error(error, G_FILE_ERROR, G_FILE_ERROR_EXIST, "No keyring file provided"); goto out; } g_message("Reading bundle: %s", bundlename); bundlefile = g_file_new_for_path(bundlename); bundlestream = g_file_read(bundlefile, NULL, &ierror); if (bundlestream == NULL) { g_propagate_prefixed_error( error, ierror, "failed to open bundle for reading: "); goto out; } offset = sizeof(sigsize); res = g_seekable_seek(G_SEEKABLE(bundlestream), -offset, G_SEEK_END, NULL, &ierror); if (!res) { g_propagate_prefixed_error( error, ierror, "failed to seek to end of bundle: "); goto out; } offset = g_seekable_tell((GSeekable *)bundlestream); res = input_stream_read_uint64_all(G_INPUT_STREAM(bundlestream), &sigsize, NULL, &ierror); if (!res) { g_propagate_prefixed_error( error, ierror, "failed to read signature size from bundle: "); goto out; } offset -= sigsize; if (size) *size = offset; res = g_seekable_seek(G_SEEKABLE(bundlestream), offset, G_SEEK_SET, NULL, &ierror); if (!res) { g_propagate_prefixed_error( error, ierror, "failed to seek to start of bundle signature: "); goto out; } res = input_stream_read_bytes_all(G_INPUT_STREAM(bundlestream), &sig, sigsize, NULL, &ierror); if (!res) { g_propagate_prefixed_error( error, ierror, "failed to read signature from bundle: "); goto out; } if (verify) { g_message("Verifying bundle... "); /* the squashfs image size is in offset */ res = cms_verify_file(bundlename, sig, offset, &ierror); if (!res) { g_propagate_error(error, ierror); goto out; } } res = TRUE; out: g_clear_object(&bundlestream); g_clear_object(&bundlefile); g_clear_pointer(&sig, g_bytes_unref); r_context_end_step("check_bundle", res); return res; }
static void file_read_callback (GObject *object, GAsyncResult *res, gpointer data) { NemoImagePropertiesPage *page; GInputStream *stream; gssize count_read; GError *error; int exif_still_loading; gboolean done_reading; page = NEMO_IMAGE_PROPERTIES_PAGE (data); stream = G_INPUT_STREAM (object); error = NULL; done_reading = FALSE; count_read = g_input_stream_read_finish (stream, res, &error); if (count_read > 0) { g_assert (count_read <= sizeof(page->details->buffer)); #ifdef HAVE_EXIF exif_still_loading = exif_loader_write (page->details->exifldr, page->details->buffer, count_read); #else exif_still_loading = 0; #endif if (page->details->pixbuf_still_loading) { if (!gdk_pixbuf_loader_write (page->details->loader, page->details->buffer, count_read, NULL)) { page->details->pixbuf_still_loading = FALSE; } } if (page->details->pixbuf_still_loading || (exif_still_loading == 1)) { g_input_stream_read_async (G_INPUT_STREAM (stream), page->details->buffer, sizeof (page->details->buffer), 0, page->details->cancellable, file_read_callback, page); } else { done_reading = TRUE; } } else { /* either EOF, cancelled or an error occurred */ done_reading = TRUE; } if (done_reading) { load_finished (page); g_input_stream_close_async (stream, 0, page->details->cancellable, file_close_callback, page); } }
ipset_node_id_t ipset_node_cache_load(GInputStream *stream, ipset_node_cache_t *cache, GError **err) { g_return_val_if_fail(err == NULL || *err == NULL, FALSE); ipset_node_id_t result; gsize bytes_read; /* * Create a GDataInputStream to read in the binary data. */ GDataInputStream *dstream = g_data_input_stream_new(stream); g_data_input_stream_set_byte_order (dstream, G_DATA_STREAM_BYTE_ORDER_BIG_ENDIAN); /* * First, read in the magic number from the stream to ensure that * this is an IP set. */ guint8 magic[MAGIC_NUMBER_LENGTH]; g_debug("Reading IP set magic number"); TRY_OR_RETURN(0, g_input_stream_read_all, G_INPUT_STREAM(dstream), magic, MAGIC_NUMBER_LENGTH, &bytes_read, NULL); if (bytes_read != MAGIC_NUMBER_LENGTH) { /* * We reached EOF before reading the entire magic number. */ g_set_error(err, IPSET_ERROR, IPSET_ERROR_PARSE_ERROR, "Unexpected end of file"); return 0; } if (memcmp(magic, MAGIC_NUMBER, MAGIC_NUMBER_LENGTH) != 0) { /* * The magic number doesn't match, so this isn't a BDD. */ g_set_error(err, IPSET_ERROR, IPSET_ERROR_PARSE_ERROR, "Magic number doesn't match; " "this isn't an IP set."); return 0; } /* * Read in the version number and dispatch to the right reading * function. */ guint16 version; g_debug("Reading IP set version"); TRY_OR_RETURN(0, version = g_data_input_stream_read_uint16, dstream, NULL); switch (version) { case 0x0001: TRY_OR_RETURN(0, result = load_v1, dstream, cache); return result; default: /* * We don't know how to read this version number. */ g_set_error(err, IPSET_ERROR, IPSET_ERROR_PARSE_ERROR, "Unknown version number %" G_GUINT16_FORMAT, version); return 0; } error: /* * If there's an error, clean up the objects that we've created * before returning. */ if (dstream != NULL) g_object_unref(dstream); return result; }
/** * tmp_picasaweb_upload_async: * * Temporary solution to provide asynchronous uploading and stop * blocking the UI until gdata_picasaweb_service_upload_file_async() * becomes available (bgo #600262). This method does the synchronous * file upload, but is run asynchronously via * g_simple_async_result_run_in_thread(). * * This sets up a minimal #GDataPicasaWebFile entry, using the * basename of the filepath for the file's title (which is not the * caption, but might be something we would consider doing). The * image file and the minimal entry are then uploaded to PicasaWeb's * default album of "Drop Box". In the future, we might consider * adding an Album Chooser to the Preferences/login window, but only * if there's demand. **/ static void tmp_picasaweb_upload_async (GSimpleAsyncResult *result, GObject *source_object, GCancellable *cancellable) { GDataPicasaWebFile *new_file = NULL; XviewerPostasaPlugin *plugin = XVIEWER_POSTASA_PLUGIN (source_object); GDataPicasaWebService *service = plugin->priv->service; GDataPicasaWebFile *file_entry; PicasaWebUploadFileAsyncData *data; #ifdef HAVE_LIBGDATA_0_8 GDataUploadStream *upload_stream; GFileInputStream *in_stream; GFileInfo *file_info; #endif gchar *filename; GError *error = NULL; data = (PicasaWebUploadFileAsyncData*)g_async_result_get_user_data (G_ASYNC_RESULT (result)); /* get filename to set image title */ file_entry = gdata_picasaweb_file_new (NULL); filename = g_file_get_basename (data->imgfile); gdata_entry_set_title (GDATA_ENTRY (file_entry), filename); g_free (filename); #ifdef HAVE_LIBGDATA_0_8 file_info = g_file_query_info (data->imgfile, G_FILE_ATTRIBUTE_STANDARD_DISPLAY_NAME "," G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, cancellable, &error); if (file_info == NULL) goto got_err; upload_stream = gdata_picasaweb_service_upload_file (service, NULL /* Upload to Dropbox */, file_entry, g_file_info_get_display_name (file_info), g_file_info_get_content_type (file_info), cancellable, &error); g_object_unref (file_info); if (upload_stream == NULL) goto got_err; in_stream = g_file_read (data->imgfile, cancellable, &error); if (in_stream == NULL) { g_object_unref (upload_stream); goto got_err; } if (g_output_stream_splice (G_OUTPUT_STREAM (upload_stream), G_INPUT_STREAM (in_stream), G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, &error) == -1) { g_object_unref (upload_stream); g_object_unref (in_stream); goto got_err; } new_file = gdata_picasaweb_service_finish_file_upload (service, upload_stream, &error); g_object_unref (upload_stream); g_object_unref (in_stream); got_err: /* Jump here if any GIO/GData call doesn't return successfully. * Error handling happens below. */ #else /* libgdata-0.6 */ new_file = gdata_picasaweb_service_upload_file (service, NULL /* Uploading to Drop Box */, file_entry, data->imgfile, cancellable, &error); #endif g_object_unref (file_entry); if (new_file == NULL || error) { if (g_cancellable_is_cancelled (cancellable) == FALSE) { g_simple_async_result_set_from_error (result, error); } /* Clear errors always as cancelling creates errors too */ g_clear_error (&error); } else { g_simple_async_result_set_op_res_gboolean (result, TRUE); } if (new_file != NULL) g_object_unref (new_file); }
/** * as_validator_validate_tree: * @validator: An instance of #AsValidator. * @root_dir: The root directory of the filesystem tree that should be validated. * * Validate a full directory tree for issues in AppStream metadata. **/ gboolean as_validator_validate_tree (AsValidator *validator, const gchar *root_dir) { g_autofree gchar *metainfo_dir = NULL; g_autofree gchar *legacy_metainfo_dir = NULL; g_autofree gchar *apps_dir = NULL; g_autoptr(GPtrArray) mfiles = NULL; g_autoptr(GPtrArray) mfiles_legacy = NULL; g_autoptr(GPtrArray) dfiles = NULL; GHashTable *dfilenames = NULL; GHashTable *validated_cpts = NULL; guint i; gboolean ret = TRUE; g_autoptr(AsXMLData) xdt = NULL; struct MInfoCheckData ht_helper; /* cleanup */ as_validator_clear_issues (validator); metainfo_dir = g_build_filename (root_dir, "usr", "share", "metainfo", NULL); legacy_metainfo_dir = g_build_filename (root_dir, "usr", "share", "appdata", NULL); apps_dir = g_build_filename (root_dir, "usr", "share", "applications", NULL); /* check if we actually have a directory which could hold metadata */ if ((!g_file_test (metainfo_dir, G_FILE_TEST_IS_DIR)) && (!g_file_test (legacy_metainfo_dir, G_FILE_TEST_IS_DIR))) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_FILE_MISSING, "No AppStream metadata was found."); goto out; } /* check if we actually have a directory which could hold application information */ if (!g_file_test (apps_dir, G_FILE_TEST_IS_DIR)) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_PEDANTIC, /* pedantic because not everything which has metadata is an application */ AS_ISSUE_KIND_FILE_MISSING, "No XDG applications directory found."); } /* holds a filename -> component mapping */ validated_cpts = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); /* set up XML parser */ xdt = as_xmldata_new (); as_xmldata_initialize (xdt, AS_CURRENT_FORMAT_VERSION, "C", NULL, NULL, NULL, 0); as_xmldata_set_format_style (xdt, AS_FORMAT_STYLE_METAINFO); /* validate all metainfo files */ mfiles = as_utils_find_files_matching (metainfo_dir, "*.xml", FALSE, NULL); mfiles_legacy = as_utils_find_files_matching (legacy_metainfo_dir, "*.xml", FALSE, NULL); /* in case we only have legacy files */ if (mfiles == NULL) mfiles = g_ptr_array_new_with_free_func (g_free); if (mfiles_legacy != NULL) { for (i = 0; i < mfiles_legacy->len; i++) { const gchar *fname; g_autofree gchar *fname_basename = NULL; /* process metainfo files in legacy paths */ fname = (const gchar*) g_ptr_array_index (mfiles_legacy, i); fname_basename = g_path_get_basename (fname); as_validator_set_current_fname (validator, fname_basename); as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_INFO, AS_ISSUE_KIND_LEGACY, "The metainfo file is stored in a legacy path. Please place it in '/usr/share/metainfo'."); g_ptr_array_add (mfiles, g_strdup (fname)); } } for (i = 0; i < mfiles->len; i++) { const gchar *fname; g_autoptr(GFile) file = NULL; g_autoptr(GInputStream) file_stream = NULL; g_autoptr(GError) tmp_error = NULL; g_autoptr(GString) asdata = NULL; gssize len; const gsize buffer_size = 1024 * 24; g_autofree gchar *buffer = NULL; xmlNode *root; xmlDoc *doc; g_autofree gchar *fname_basename = NULL; fname = (const gchar*) g_ptr_array_index (mfiles, i); file = g_file_new_for_path (fname); if (!g_file_query_exists (file, NULL)) { g_warning ("File '%s' suddenly vanished.", fname); g_object_unref (file); continue; } fname_basename = g_path_get_basename (fname); as_validator_set_current_fname (validator, fname_basename); /* load a plaintext file */ file_stream = G_INPUT_STREAM (g_file_read (file, NULL, &tmp_error)); if (tmp_error != NULL) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_READ_ERROR, "Unable to read file: %s", tmp_error->message); continue; } asdata = g_string_new (""); buffer = g_malloc (buffer_size); while ((len = g_input_stream_read (file_stream, buffer, buffer_size, NULL, &tmp_error)) > 0) { g_string_append_len (asdata, buffer, len); } /* check if there was an error */ if (tmp_error != NULL) { as_validator_add_issue (validator, NULL, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_READ_ERROR, "Unable to read file: %s", tmp_error->message); continue; } /* now read the XML */ doc = as_validator_open_xml_document (validator, xdt, asdata->str); if (doc == NULL) { as_validator_clear_current_fname (validator); continue; } root = xmlDocGetRootElement (doc); if (g_strcmp0 ((gchar*) root->name, "component") == 0) { AsComponent *cpt; cpt = as_validator_validate_component_node (validator, xdt, root); if (cpt != NULL) g_hash_table_insert (validated_cpts, g_strdup (fname_basename), cpt); } else if (g_strcmp0 ((gchar*) root->name, "components") == 0) { as_validator_add_issue (validator, root, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_TAG_NOT_ALLOWED, "The metainfo file specifies multiple components. This is not allowed."); ret = FALSE; } else if (g_str_has_prefix ((gchar*) root->name, "application")) { as_validator_add_issue (validator, root, AS_ISSUE_IMPORTANCE_ERROR, AS_ISSUE_KIND_LEGACY, "The metainfo file uses an ancient version of the AppStream specification, which can not be validated. Please migrate it to version 0.6 (or higher)."); ret = FALSE; } as_validator_clear_current_fname (validator); xmlFreeDoc (doc); } /* check if we have matching .desktop files */ dfilenames = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); dfiles = as_utils_find_files_matching (apps_dir, "*.desktop", FALSE, NULL); if (dfiles != NULL) { for (i = 0; i < dfiles->len; i++) { const gchar *fname; fname = (const gchar*) g_ptr_array_index (dfiles, i); g_hash_table_add (dfilenames, g_path_get_basename (fname)); } } /* validate the component-id <-> filename relations and availability of other metadata */ ht_helper.validator = validator; ht_helper.desktop_fnames = dfilenames; ht_helper.apps_dir = apps_dir; g_hash_table_foreach (validated_cpts, (GHFunc) as_validator_analyze_component_metainfo_relation_cb, &ht_helper); out: if (dfilenames != NULL) g_hash_table_unref (dfilenames); if (validated_cpts != NULL) g_hash_table_unref (validated_cpts); return ret; }
inline static void www_closeStream_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) { g_input_stream_close_finish (G_INPUT_STREAM (source_object), res, NULL); g_object_unref (G_INPUT_STREAM (source_object)); }
static void image_drag_data_received_cb (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *selection_data, guint info, guint time, EImageChooser *chooser) { char *target_type; gboolean handled = FALSE; target_type = gdk_atom_name (gtk_selection_data_get_target (selection_data)); if (!strcmp (target_type, URI_LIST_TYPE)) { const char *data = gtk_selection_data_get_data (selection_data); char *uri; GFile *file; GInputStream *istream; char *nl = strstr (data, "\r\n"); if (nl) uri = g_strndup (data, nl - (char *) data); else uri = g_strdup (data); file = g_file_new_for_uri (uri); istream = G_INPUT_STREAM (g_file_read (file, NULL, NULL)); if (istream != NULL) { GFileInfo *info; info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, G_FILE_QUERY_INFO_NONE, NULL, NULL); if (info != NULL) { gsize size; gboolean success; gchar *buf; size = g_file_info_get_size (info); g_object_unref (info); buf = g_malloc (size); success = g_input_stream_read_all (istream, buf, size, &size, NULL, NULL); g_input_stream_close (istream, NULL, NULL); if (success && set_image_from_data (chooser, buf, size)) handled = TRUE; else g_free (buf); } g_object_unref (istream); } g_object_unref (file); g_free (uri); } gtk_drag_finish (context, handled, FALSE, time); }
static gboolean pk_backend_config_parse (PkBackendConfig *config, const gchar *filename, PkBackendConfigSection *section, GError **error) { GFile *file; GFileInputStream *is; GDataInputStream *input; gchar *key, *str, *line = NULL; guint num = 1; GError *e = NULL; g_return_val_if_fail (config != NULL, FALSE); g_return_val_if_fail (filename != NULL, FALSE); file = g_file_new_for_path (filename); is = g_file_read (file, NULL, &e); if (is == NULL) { g_propagate_error (error, e); g_object_unref (file); return FALSE; } input = g_data_input_stream_new (G_INPUT_STREAM (is)); for (;; g_free (line), ++num) { line = g_data_input_stream_read_line (input, NULL, NULL, &e); if (line != NULL) { g_strstrip (line); } else { break; } /* skip empty lines */ if (*line == '\0' || *line == '#') { continue; } /* remove trailing comments */ for (str = line; *str != '\0' && *str != '#'; ++str); *str-- = '\0'; /* change sections */ if (*line == '[' && *str == ']') { *str = '\0'; str = line + 1; if (*str == '\0') { g_set_error (&e, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID, "empty section name"); break; } section = pk_backend_config_enter_section (config, str); continue; } /* parse a directive */ if (section == NULL) { g_set_error (&e, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID, "directive must belong to a section"); break; } str = line; key = strsep (&str, "="); g_strchomp (key); if (str != NULL) { g_strchug (str); } if (str == NULL) { /* set a boolean directive */ if (pk_backend_config_section_match (section, "options") == 0 && pk_backend_config_set_boolean (config, key)) { continue; } /* report error below */ } else if (g_strcmp0 (key, "Include") == 0) { gsize i; glob_t match = { 0 }; /* ignore globbing errors */ if (glob (str, GLOB_NOCHECK, NULL, &match) != 0) { continue; } /* parse the files that matched */ for (i = 0; i < match.gl_pathc; ++i) { if (!pk_backend_config_parse (config, match.gl_pathv[i], section, &e)) { break; } } globfree (&match); if (e != NULL) { break; } else { continue; } } else if (pk_backend_config_section_match (section, "options") == 0) { /* set a string or list directive */ if (pk_backend_config_set_string (config, key, str) || pk_backend_config_set_list (config, key, str)) { continue; } /* report error below */ } else if (g_strcmp0 (key, "Server") == 0) { if (!pk_backend_config_add_server (config, section, str, &e)) { break; } else { continue; } } if (g_strcmp0 (key, "SigLevel") == 0 && str != NULL) { pk_backend_config_add_siglevel (config, section, str); continue; } /* report errors from above */ g_set_error (&e, ALPM_ERROR, ALPM_ERR_CONFIG_INVALID, "unrecognised directive '%s'", key); break; } g_object_unref (input); g_object_unref (is); g_object_unref (file); if (e != NULL) { g_propagate_prefixed_error (error, e, "%s:%u", filename, num); return FALSE; } else { return TRUE; } }
gboolean gimp_help_locale_parse (GimpHelpLocale *locale, const gchar *uri, const gchar *help_domain, GimpHelpProgress *progress, GError **error) { GMarkupParseContext *context; GFile *file; GFileInputStream *stream; GCancellable *cancellable = NULL; LocaleParser parser = { NULL, }; goffset size = 0; gboolean success; g_return_val_if_fail (locale != NULL, FALSE); g_return_val_if_fail (uri != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); if (locale->help_id_mapping) { g_hash_table_destroy (locale->help_id_mapping); locale->help_id_mapping = NULL; } if (locale->help_missing) { g_free (locale->help_missing); locale->help_missing = NULL; } #ifdef GIMP_HELP_DEBUG g_printerr ("help (%s): parsing '%s' for \"%s\"\n", locale->locale_id, uri, help_domain); #endif file = g_file_new_for_uri (uri); if (progress) { gchar *name = g_file_get_parse_name (file); cancellable = g_cancellable_new (); _gimp_help_progress_start (progress, cancellable, _("Loading index from '%s'"), name); g_object_unref (cancellable); g_free (name); } if (progress) { GFileInfo *info = g_file_query_info (file, G_FILE_ATTRIBUTE_STANDARD_SIZE, 0, cancellable, error); if (! info) { locale_set_error (error, _("Could not open '%s' for reading: %s"), file); g_object_unref (file); return FALSE; } size = g_file_info_get_size (info); g_object_unref (info); } stream = g_file_read (file, cancellable, error); if (! stream) { locale_set_error (error, _("Could not open '%s' for reading: %s"), file); g_object_unref (file); return FALSE; } parser.file = file; parser.value = g_string_new (NULL); parser.locale = locale; parser.help_domain = help_domain; parser.id_attr_name = g_strdup ("id"); context = g_markup_parse_context_new (&markup_parser, 0, &parser, NULL); success = locale_parser_parse (context, progress, G_INPUT_STREAM (stream), size, cancellable, error); if (progress) _gimp_help_progress_finish (progress); g_markup_parse_context_free (context); g_object_unref (stream); g_string_free (parser.value, TRUE); g_free (parser.id_attr_name); if (! success) locale_set_error (error, _("Parse error in '%s':\n%s"), file); g_object_unref (file); return success; }
int main (int argc, char **argv) { GOptionContext* context; GError *error = NULL; GFile *infile; GFile *outfile; GInputStream *instream; GOutputStream *outstream; GMainLoop *loop; ByzanzEncoder *encoder; g_set_prgname (argv[0]); #ifdef GETTEXT_PACKAGE bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif context = g_option_context_new (_("process a Byzanz debug recording")); #ifdef GETTEXT_PACKAGE g_option_context_set_translation_domain(context, GETTEXT_PACKAGE); #endif g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_print (_("Wrong option: %s\n"), error->message); usage (); g_error_free (error); return 1; } if (argc != 3) { usage (); return 0; } infile = g_file_new_for_commandline_arg (argv[1]); outfile = g_file_new_for_commandline_arg (argv[2]); loop = g_main_loop_new (NULL, FALSE); instream = G_INPUT_STREAM (g_file_read (infile, NULL, &error)); if (instream == NULL) { g_print ("%s\n", error->message); g_error_free (error); return 1; } outstream = G_OUTPUT_STREAM (g_file_replace (outfile, NULL, FALSE, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &error)); if (outstream == NULL) { g_print ("%s\n", error->message); g_error_free (error); return 1; } encoder = byzanz_encoder_new (byzanz_encoder_get_type_from_file (outfile), instream, outstream, FALSE, NULL); g_signal_connect (encoder, "notify", G_CALLBACK (encoder_notify), loop); g_main_loop_run (loop); g_main_loop_unref (loop); g_object_unref (encoder); g_object_unref (instream); g_object_unref (outstream); g_object_unref (infile); g_object_unref (outfile); return 0; }
void decrypt_file (const gchar *input_file_path, const gchar *pwd) { GError *err = NULL; goffset file_size = get_file_size (input_file_path); if (file_size == -1) { return; } if (file_size < (goffset) (sizeof (Metadata) + SHA512_DIGEST_SIZE)) { g_printerr ("The selected file is not encrypted.\n"); return; } GFile *in_file = g_file_new_for_path (input_file_path); GFileInputStream *in_stream = g_file_read (in_file, NULL, &err); if (err != NULL) { g_printerr ("%s\n", err->message); // TODO return; } gchar *output_file_path; if (!g_str_has_suffix (input_file_path, ".enc")) { g_printerr ("The selected file may not be encrypted\n"); output_file_path = g_strconcat (input_file_path, ".decrypted", NULL); } else { output_file_path = g_strndup (input_file_path, (gsize) g_utf8_strlen (input_file_path, -1) - 4); // remove .enc } GFile *out_file = g_file_new_for_path (output_file_path); GFileOutputStream *out_stream = g_file_append_to (out_file, G_FILE_CREATE_REPLACE_DESTINATION, NULL, &err); if (err != NULL) { g_printerr ("%s\n", err->message); // TODO return; } Metadata *header_metadata = g_new0 (Metadata, 1); CryptoKeys *decryption_keys = g_new0 (CryptoKeys, 1); gssize rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), header_metadata, sizeof (Metadata), NULL, &err); if (rw_len == -1) { g_printerr ("%s\n", err->message); // TODO return; } guchar *original_hmac = g_malloc (SHA512_DIGEST_SIZE); if (!g_seekable_seek (G_SEEKABLE (in_stream), file_size - SHA512_DIGEST_SIZE, G_SEEK_SET, NULL, &err)) { g_printerr ("Couldn't set the position, exiting...\n"); //TODO return; } rw_len = g_input_stream_read (G_INPUT_STREAM (in_stream), original_hmac, SHA512_DIGEST_SIZE, NULL, &err); if (rw_len == -1) { g_printerr ("%s\n", err->message); // TODO return; } if (!g_seekable_seek (G_SEEKABLE (in_stream), 0, G_SEEK_SET, NULL, &err)) { g_printerr ("Couldn't set the position, exiting...\n"); //TODO return; } GFile *file_encrypted_data = get_g_file_with_encrypted_data (in_stream, file_size); if (file_encrypted_data == NULL) { // TODO return; } if (!setup_keys (pwd, gcry_cipher_get_algo_keylen (header_metadata->algo), header_metadata, decryption_keys)) { g_printerr ("Error during key derivation or during memory allocation\n"); //TODO return; } if (!compare_hmac (decryption_keys->hmac_key, original_hmac, file_encrypted_data)) { g_printerr ("HMAC differs from the one stored inside the file.\nEither the password is wrong or the file has been corrupted.\n"); // TODO return; } decrypt (header_metadata, decryption_keys, file_encrypted_data, file_size - sizeof (Metadata) - SHA512_DIGEST_SIZE, out_stream); g_unlink (g_file_get_path (file_encrypted_data)); // TODO remove encrypted file? Give option to the user multiple_unref (5, (gpointer) &file_encrypted_data, (gpointer) &in_stream, (gpointer) &out_stream, (gpointer) &in_file, (gpointer) &out_file); multiple_gcry_free (3, (gpointer) &decryption_keys->crypto_key, (gpointer) &decryption_keys->derived_key, (gpointer) &decryption_keys->hmac_key); multiple_free (4, (gpointer) &header_metadata, (gpointer) &output_file_path, (gpointer) &original_hmac, (gpointer) &decryption_keys); }
gboolean Ogg_Header_Read_File_Info (const gchar *filename, ET_File_Info *ETFileInfo) { OggVorbis_File vf; vorbis_info *vi; gint encoder_version = 0; gint channels = 0; glong rate = 0; glong bitrate_nominal = 0; gdouble duration = 0; gulong filesize; gint res; ov_callbacks callbacks = { et_ogg_read_func, et_ogg_seek_func, et_ogg_close_func, et_ogg_tell_func }; EtOggState state; gchar *filename_utf8; g_return_val_if_fail (filename != NULL && ETFileInfo != NULL, FALSE); state.file = g_file_new_for_path (filename); state.error = NULL; state.istream = G_INPUT_STREAM (g_file_read (state.file, NULL, &state.error)); filename_utf8 = filename_to_display (filename); if (!state.istream) { /* FIXME: Pass error back to calling function. */ Log_Print (LOG_ERROR, _("Error while opening file: '%s' (%s)"), filename_utf8, state.error->message); g_free (filename_utf8); return FALSE; } if ((res = ov_open_callbacks (&state, &vf, NULL, 0, callbacks)) == 0) { if ( (vi=ov_info(&vf,0)) != NULL ) { encoder_version = vi->version; // Vorbis encoder version used to create this bitstream. channels = vi->channels; // Number of channels in bitstream. rate = vi->rate; // (Hz) Sampling rate of the bitstream. bitrate_nominal = vi->bitrate_nominal; // (b/s) Specifies the average bitrate for a VBR bitstream. }else { Log_Print(LOG_ERROR,_("Ogg Vorbis: The specified bitstream does not exist or the " "file has been initialized improperly (file: '%s')."),filename_utf8); } duration = ov_time_total(&vf,-1); // (s) Total time. //g_print("play time: %ld s\n",(long)ov_time_total(&vf,-1)); //g_print("serialnumber: %ld\n",(long)ov_serialnumber(&vf,-1)); //g_print("compressed length: %ld bytes\n",(long)(ov_raw_total(&vf,-1))); /***{ // Test for displaying comments vorbis_comment *vc = ov_comment(&vf,-1); Log_Print(LOG_OK,">>> %s",filename_utf8); Log_Print(LOG_OK,"Nbr comments : %d",vc->comments); Log_Print(LOG_OK,"Vendor : %s",vc->vendor); char **ptr = vc->user_comments; while(*ptr){ Log_Print(LOG_OK,"> %s",*ptr); ++ptr; } }***/ ov_clear(&vf); // This close also the file }else { /* On error. */ if (state.error) { g_debug ("Ogg Vorbis: error reading header information (%s)", state.error->message); } et_ogg_close_func (&state); switch (res) { case OV_EREAD: Log_Print(LOG_ERROR,_("Ogg Vorbis: Read from media returned an error (file: '%s')."),filename_utf8); break; case OV_ENOTVORBIS: Log_Print(LOG_ERROR,_("Ogg Vorbis: Bitstream is not Vorbis data (file: '%s')."),filename_utf8); break; case OV_EVERSION: Log_Print(LOG_ERROR,_("Ogg Vorbis: Vorbis version mismatch (file: '%s')."),filename_utf8); break; case OV_EBADHEADER: Log_Print(LOG_ERROR,_("Ogg Vorbis: Invalid Vorbis bitstream header (file: '%s')."),filename_utf8); break; case OV_EFAULT: Log_Print(LOG_ERROR,_("Ogg Vorbis: Internal logic fault, indicates a bug or heap/stack corruption (file: '%s')."),filename_utf8); break; default: break; } } filesize = Get_File_Size(filename); ETFileInfo->version = encoder_version; ETFileInfo->bitrate = bitrate_nominal/1000; ETFileInfo->samplerate = rate; ETFileInfo->mode = channels; ETFileInfo->size = filesize; ETFileInfo->duration = duration; g_free(filename_utf8); return TRUE; }