changeset 11132:a4611130e3eb

[gaim-migrate @ 13189] A bit more dewarnification. I also think I found a memleak in sametime. siege, could you please check that out sometime? committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Wed, 20 Jul 2005 02:43:09 +0000
parents ece127d56c14
children 1081735edc10
files src/mime.c src/mime.h src/protocols/sametime/sametime.c src/util.c src/util.h
diffstat 5 files changed, 33 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/mime.c	Tue Jul 19 10:16:32 2005 +0000
+++ b/src/mime.c	Wed Jul 20 02:43:09 2005 +0000
@@ -304,7 +304,7 @@
 
 
 void gaim_mime_part_get_data_decoded(GaimMimePart *part,
-				     char **data, gsize *len) {
+				     guint8 **data, gsize *len) {
   const char *enc;
 
   g_return_if_fail(part != NULL);
@@ -316,15 +316,15 @@
   enc = gaim_mime_part_get_field(part, "content-transfer-encoding");
 
   if(! enc) {
-    *data = g_strdup(part->data->str);
+    *data = (guint8 *)g_strdup(part->data->str);
     *len = part->data->len;
 
   } else if(! g_ascii_strcasecmp(enc, "7bit")) {
-    *data = g_strdup(part->data->str);
+    *data = (guint8 *)g_strdup(part->data->str);
     *len = part->data->len;
 
   } else if(! g_ascii_strcasecmp(enc, "8bit")) {
-    *data = g_strdup(part->data->str);
+    *data = (guint8 *)g_strdup(part->data->str);
     *len = part->data->len;
 
   } else if(! g_ascii_strcasecmp(enc, "base16")) {
@@ -334,7 +334,7 @@
 	*data = gaim_base64_decode(part->data->str, len);
 
   } else if(! g_ascii_strcasecmp(enc, "quoted-printable")) {
-    gaim_quotedp_decode(part->data->str, data, len);
+    *data = gaim_quotedp_decode(part->data->str, len);
 
   } else {
     gaim_debug_warning("mime", "gaim_mime_part_get_data_decoded:"
--- a/src/mime.h	Tue Jul 19 10:16:32 2005 +0000
+++ b/src/mime.h	Wed Jul 20 02:43:09 2005 +0000
@@ -183,7 +183,7 @@
     @param len  The length of the buffer
 */
 void gaim_mime_part_get_data_decoded(GaimMimePart *part,
-				     char **data, gsize *len);
+				     guint8 **data, gsize *len);
 
 
 /** Get the length of the data portion of a MIME document part
--- a/src/protocols/sametime/sametime.c	Tue Jul 19 10:16:32 2005 +0000
+++ b/src/protocols/sametime/sametime.c	Wed Jul 20 02:43:09 2005 +0000
@@ -2304,7 +2304,7 @@
     } else if(g_str_has_prefix(type, "image")) {
       /* put images into the image store */
 
-      char *d_dat;
+      guint8 *d_dat;
       gsize d_len;
       char *cid;
       int img;
@@ -2325,16 +2325,20 @@
       /* recall the image for dereferencing later */
       images = g_list_append(images, GINT_TO_POINTER(img));
       
+      /* TODO: Don't we need to g_free 'd_dat'?! */
+
     } else if(g_str_has_prefix(type, "text")) {
 
       /* concatenate all the text parts together */
-      char *data, *txt;
+      guint8 *data;
+      char *txt;
       gsize len;
 
       gaim_mime_part_get_data_decoded(part, &data, &len);
-      txt = gaim_utf8_try_convert(data);
+      txt = gaim_utf8_try_convert((const char *)data);
       g_string_append(str, txt);
       g_free(txt);
+      /* TODO: Don't we need to g_free 'data'?! */
     }
   }
 
--- a/src/util.c	Tue Jul 19 10:16:32 2005 +0000
+++ b/src/util.c	Wed Jul 20 02:43:09 2005 +0000
@@ -247,10 +247,10 @@
 }
 
 /**************************************************************************
- * Quoted Printable Functions (see RFC 1341)
+ * Quoted Printable Functions (see RFC 2045).
  **************************************************************************/
-void
-gaim_quotedp_decode(const char *str, char **ret_str, int *ret_len)
+guint8 *
+gaim_quotedp_decode(const char *str, gsize *ret_len)
 {
 	char *n, *new;
 	const char *end, *p;
@@ -287,13 +287,13 @@
 
 	*n = '\0';
 
-	if (ret_len)
+	if (ret_len != NULL)
 		*ret_len = n - new;
 
 	/* Resize to take less space */
 	/* new = realloc(new, n - new); */
 
-	*ret_str = new;
+	return (guint8 *)new;
 }
 
 /**************************************************************************
@@ -413,14 +413,14 @@
 				guint8 *decoded = NULL;
 				gsize dec_len;
 				if (g_ascii_strcasecmp(encoding, "Q") == 0)
-					gaim_quotedp_decode(encoded_text, &decoded, &dec_len);
+					decoded = gaim_quotedp_decode(encoded_text, &dec_len);
 				else if (g_ascii_strcasecmp(encoding, "B") == 0)
 					decoded = gaim_base64_decode(encoded_text, &dec_len);
 				else
 					decoded = NULL;
 				if (decoded) {
 					gsize len;
-					char *converted = g_convert(decoded, dec_len, "utf-8", charset, NULL, &len, NULL);
+					char *converted = g_convert((const gchar *)decoded, dec_len, "utf-8", charset, NULL, &len, NULL);
 
 					if (converted) {
 						n = strncpy(n, converted, len) + len;
--- a/src/util.h	Tue Jul 19 10:16:32 2005 +0000
+++ b/src/util.h	Wed Jul 20 02:43:09 2005 +0000
@@ -119,12 +119,22 @@
 
 /**
  * Converts a quoted printable string back to its readable equivalent.
+ * What is a quoted printable string, you ask?  It's an encoding used
+ * to transmit binary data as ASCII.  It's intended purpose is to send
+ * e-mails containing non-ASCII characters.  Wikipedia has a pretty good
+ * explanation.  Also see RFC 2045.
  *
- * @param str     The string to convert back.
+ * @param str     The quoted printable ASCII string to convert to raw data.
  * @param ret_str The returned, readable string.
- * @param ret_len The returned string length.
+ * @param ret_len The length of the returned data.  You can
+ *                pass in NULL if you're sure that you know
+ *                the length of the decoded data, or if you
+ *                know you'll be able to use strlen to
+ *                determine the length, etc.
+ *
+ * @return The raw data.  Must be g'free'd when no longer needed.
  */
-void gaim_quotedp_decode (const char *str, char **ret_str, int *ret_len);
+guint8 *gaim_quotedp_decode(const char *str, gsize *ret_len);
 
 /*@}*/