Ejemplo n.º 1
0
/**
 * xmp_model_parse_buffer:
 * @xmp_model: pointer to the #XMPModel in which the results will be stored
 * @buffer: buffer to be parsed
 * @buffer_length: length of the @buffer
 * @skip_other_data: if %TRUE, allow arbitrary data before XMP packet marker
 * @error: return location for a #GError
 *
 * Parse a buffer containing XMP metadata and merge the parsed contents into
 * the supplied @xmp_model.  If @skip_other_data is %TRUE, then the parser
 * will try to find the <?xpacket...?> marker in the buffer, skipping any
 * unknown data found before it.
 *
 * (Note: this calls the functions from xmp_parse.c, which will call the
 *  functions in this file through the xmp_parser structure defined above.)
 *
 * Return value: %TRUE on success, %FALSE if an error was set
 **/
gboolean
xmp_model_parse_buffer (XMPModel     *xmp_model,
                        const gchar  *buffer,
                        gssize        buffer_length,
                        gboolean      skip_other_data,
                        GError      **error)
{
  XMPParseFlags    flags;
  XMPParseContext *context;

  flags = XMP_FLAG_DEFER_VALUE_FREE; /* we will free the array ourselves */
  if (skip_other_data)
    flags |= XMP_FLAG_FIND_XPACKET;

  context = xmp_parse_context_new (&xmp_parser, flags, xmp_model, NULL);

  if (! xmp_parse_context_parse (context, buffer, buffer_length, error))
    {
      xmp_parse_context_free (context);
      return FALSE;
    }

  if (! xmp_parse_context_end_parse (context, error))
    {
      xmp_parse_context_free (context);
      return FALSE;
    }

  xmp_parse_context_free (context);

  return TRUE;
}
Ejemplo n.º 2
0
static int
scan_file (const gchar *filename)
{
  gchar *contents;
  gsize  length;
  GError *error;
  XMPParseContext *context;

  g_print ("\nFile: %s\n", filename);
  error = NULL;
  if (!g_file_get_contents (filename,
                            &contents,
                            &length,
                            &error))
    {
      print_error (NULL, error, (gpointer) filename);
      g_error_free (error);
      return 1;
    }

  context = xmp_parse_context_new (&xmp_parser,
                                   XMP_FLAG_FIND_XPACKET,
                                   (gpointer) filename,
                                   NULL);

  if (! xmp_parse_context_parse (context, contents, length, NULL))
    {
      xmp_parse_context_free (context);
      return 1;
    }

  if (! xmp_parse_context_end_parse (context, NULL))
    {
      xmp_parse_context_free (context);
      return 1;
    }

  xmp_parse_context_free (context);
  return 0;
}