Commit 15da1112 authored by Raphael Quinet's avatar Raphael Quinet Committed by Raphaël Quinet
Browse files

Added definition of properties from IPTC Core XMP schema (Iptc4xmpCore).

2005-04-23  Raphael Quinet  <raphael@gimp.org>

	* plug-ins/metadata/xmp-schemas.[ch]: Added definition of
	properties from IPTC Core XMP schema (Iptc4xmpCore).

	* plug-ins/metadata/base64.[ch]: Added option to ignore invalid
	characters in base64 encoded text.

	* plug-ins/metadata/xmp-parse.c
	* plug-ins/metadata/testbase64.c: Updated accordingly.
parent b450547a
2005-04-23 Raphaël Quinet <raphael@gimp.org>
* plug-ins/metadata/xmp-schemas.[ch]: Added definition of
properties from IPTC Core XMP schema (Iptc4xmpCore).
* plug-ins/metadata/base64.[ch]: Added option to ignore invalid
characters in base64 encoded text.
* plug-ins/metadata/xmp-parse.c
* plug-ins/metadata/testbase64.c: Updated accordingly.
2005-04-22 Sven Neumann <sven@gimp.org>
* configure.in
......
......@@ -74,6 +74,7 @@ static const gint base64_6bits[256] =
* @src_size: input buffer size (in bytes) or -1 if @src_b64 is nul-terminated
* @dest: buffer in which the decoded data should be stored
* @dest_size: size of the destination buffer
* @ignore_errors: if #TRUE, skip all invalid characters (no data validation)
*
* Read base64-encoded data from the input buffer @src_b64 and write
* the decoded data into @dest.
......@@ -94,7 +95,8 @@ gssize
base64_decode (const gchar *src_b64,
gsize src_size,
gchar *dest,
gsize dest_size)
gsize dest_size,
gboolean ignore_errors)
{
gint32 decoded;
gssize i;
......@@ -111,8 +113,10 @@ base64_decode (const gchar *src_b64,
bits = base64_6bits[(int) *src_b64 & 0xff];
if (bits < 0)
{
if (bits < -1)
if (bits == -2)
break;
else if ((bits == -3) && !ignore_errors)
return -1;
else
continue;
}
......@@ -128,8 +132,6 @@ base64_decode (const gchar *src_b64,
n = 0;
}
}
if (bits < -2)
return -1;
if ((n == 3) && (i + 2 <= dest_size))
{
/* 3 source chars (+ 1 padding "=") => 16 bits of output (2 chars) */
......
......@@ -28,7 +28,8 @@ G_BEGIN_DECLS
gssize base64_decode (const gchar *src_b64,
gsize src_size,
gchar *dest,
gsize dest_size);
gsize dest_size,
gboolean ignore_errors);
gssize base64_encode (const gchar *src,
gsize src_size,
......
......@@ -23,7 +23,8 @@ string_encode_decode (char *s)
return 1;
}
g_print ("'%s' -> '%s' (%d) ", s, encoded, n);
n = base64_decode (encoded, strlen (encoded), decoded, sizeof (decoded) - 1);
n = base64_decode (encoded, strlen (encoded), decoded, sizeof (decoded) - 1,
FALSE);
if (n < 0)
{
g_print ("\nbase64 decoding failed for '%s'", s);
......@@ -57,13 +58,14 @@ buffer_encode_decode (char *buf,
}
g_print ("buffer length %d -> encoded %d (columns: %d) ", buf_len, n,
columns);
n = base64_decode (encoded, strlen (encoded), decoded, sizeof (decoded) - 1);
n = base64_decode (encoded, strlen (encoded), decoded, sizeof (decoded) - 1,
FALSE);
if (n < 0)
{
g_print ("\nbase64 decoding failed");
return 1;
}
if ((n == buf_len) && ! memcmp (buf, decoded, buf_len))
if ((n == buf_len) && ! memcmp (buf, decoded, n))
g_print ("-> decoded %d match OK\n", n);
else
{
......@@ -74,6 +76,44 @@ buffer_encode_decode (char *buf,
return 0;
}
static int
test_decode (char *encoded,
char *expected,
gint expected_len,
gboolean ignore_errors)
{
int n;
char decoded[4000];
n = base64_decode (encoded, strlen (encoded), decoded, sizeof (decoded) - 1,
ignore_errors);
if (n < 0)
{
if (expected_len < 0)
g_print ("'%s' failed as expected\n", encoded);
else
{
g_print ("'%s' could not be decoded (length: %d, expected %d)\n",
encoded, n, expected_len);
return 1;
}
}
else if ((n == expected_len) && ! memcmp (expected, decoded, n))
{
if (ignore_errors)
g_print ("'%s' decoded OK (%d) - invalid chars ignored\n", encoded, n);
else
g_print ("'%s' decoded OK (%d)\n", encoded, n);
}
else
{
g_print ("'%s' not decoded as expected (length: %d, expected %d)\n",
encoded, n, expected_len);
return 1;
}
return 0;
}
int
main (int argc,
char *argv[])
......@@ -107,6 +147,15 @@ main (int argc,
failed += buffer_encode_decode (buf, 600, 0);
failed += buffer_encode_decode (buf, 500, 0);
failed += buffer_encode_decode (buf, 400, 0);
failed += test_decode ("QUJD", "ABC", 3, FALSE);
failed += test_decode (" Q\tU J\nDR\rA==", "ABCD", 4, FALSE);
failed += test_decode ("?", "", -1, FALSE);
failed += test_decode ("?", "", 0, TRUE);
failed += test_decode ("////", "\377\377\377", 3, FALSE);
failed += test_decode ("---/./(/)/*", "", -1, FALSE);
failed += test_decode ("---/./(/)/*", "\377\377\377", 3, TRUE);
failed += test_decode ("AA==", "\0", 1, FALSE);
failed += test_decode ("AAA=", "\0\0", 2, FALSE);
if (failed > 0)
{
g_print ("%d test(s) failed!\n", failed);
......
......@@ -987,7 +987,8 @@ text_handler (GMarkupParseContext *markup_context,
#endif
max_size = text_len - text_len / 4 + 1;
decoded = g_malloc (max_size);
decoded_size = base64_decode (text, text_len, decoded, max_size);
decoded_size = base64_decode (text, text_len, decoded, max_size,
FALSE);
#ifdef DEBUG_XMP_PARSER
if (decoded_size > 0)
{
......
This diff is collapsed.
......@@ -51,6 +51,7 @@ typedef enum
XMP_TYPE_OECF_SFR, /* (?) */
XMP_TYPE_CFA_PATTERN, /* (?) */
XMP_TYPE_DEVICE_SETTINGS, /* (?) */
XMP_TYPE_CONTACT_INFO, /* STRUCTURE */
XMP_TYPE_GENERIC_STRUCTURE, /* STRUCTURE */
XMP_TYPE_UNKNOWN
} XMPType;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment