gmime r1220 - in trunk: . docs/reference gmime



Author: fejj
Date: Sun Feb 10 00:34:28 2008
New Revision: 1220
URL: http://svn.gnome.org/viewvc/gmime?rev=1220&view=rev

Log:
2008-02-09  Jeffrey Stedfast  <fejj novell com>

	* gmime/gmime-filter-basic.c (filter_filter): Use the new macros
	defined below.

	* gmime/gmime-utils.c (rfc2047_encode_word): Use the new macros.

	* gmime/gmime-utils.h: Added more accurate encoding-length macros
	for base64, quoted-printable, and uuencode which are try to
	minimize over-calculating the amount of output data that we
	need. Also namespaced them.



Modified:
   trunk/ChangeLog
   trunk/docs/reference/gmime-sections.txt
   trunk/gmime/gmime-filter-basic.c
   trunk/gmime/gmime-utils.c
   trunk/gmime/gmime-utils.h

Modified: trunk/docs/reference/gmime-sections.txt
==============================================================================
--- trunk/docs/reference/gmime-sections.txt	(original)
+++ trunk/docs/reference/gmime-sections.txt	Sun Feb 10 00:34:28 2008
@@ -893,15 +893,18 @@
 g_mime_utils_8bit_header_encode_phrase
 g_mime_utils_structured_header_fold
 g_mime_utils_unstructured_header_fold
+GMIME_BASE64_ENCODE_LEN
 g_mime_utils_base64_decode_step
 g_mime_utils_base64_encode_step
 g_mime_utils_base64_encode_close
 GMIME_UUDECODE_STATE_INIT
 GMIME_UUDECODE_STATE_BEGIN
 GMIME_UUDECODE_STATE_END
+GMIME_UUENCODE_LEN
 g_mime_utils_uudecode_step
 g_mime_utils_uuencode_step
 g_mime_utils_uuencode_close
+GMIME_QP_ENCODE_LEN
 g_mime_utils_quoted_decode_step
 g_mime_utils_quoted_encode_step
 g_mime_utils_quoted_encode_close

Modified: trunk/gmime/gmime-filter-basic.c
==============================================================================
--- trunk/gmime/gmime-filter-basic.c	(original)
+++ trunk/gmime/gmime-filter-basic.c	Sun Feb 10 00:34:28 2008
@@ -131,29 +131,26 @@
 	
 	switch (basic->type) {
 	case GMIME_FILTER_BASIC_BASE64_ENC:
-		/* wont go to more than 2x size (overly conservative) */
-		g_mime_filter_set_size (filter, len * 2 + 6, FALSE);
+		g_mime_filter_set_size (filter, GMIME_BASE64_ENCODE_LEN (len), FALSE);
 		outbuf = (unsigned char *) filter->outbuf;
 		inbuf = (const unsigned char *) in;
 		newlen = g_mime_utils_base64_encode_step (inbuf, len, outbuf, &basic->state, &basic->save);
-		g_assert (newlen <= len * 2 + 6);
+		g_assert (newlen <= GMIME_BASE64_ENCODE_LEN (len));
 		break;
 	case GMIME_FILTER_BASIC_QP_ENC:
-		/* *4 is overly conservative, but will do */
-		g_mime_filter_set_size (filter, len * 4 + 4, FALSE);
+		g_mime_filter_set_size (filter, GMIME_QP_ENCODE_LEN (len), FALSE);
 		outbuf = (unsigned char *) filter->outbuf;
 		inbuf = (const unsigned char *) in;
 		newlen = g_mime_utils_quoted_encode_step (inbuf, len, outbuf, &basic->state, &basic->save);
-		g_assert (newlen <= len * 4 + 4);
+		g_assert (newlen <= GMIME_QP_ENCODE_LEN (len));
 		break;
 	case GMIME_FILTER_BASIC_UU_ENC:
-		/* won't go to more than 2 * (x + 2) + 62 */
-		g_mime_filter_set_size (filter, (len + 2) * 2 + 62, FALSE);
+		g_mime_filter_set_size (filter, GMIME_UUENCODE_LEN (len), FALSE);
 		outbuf = (unsigned char *) filter->outbuf;
 		inbuf = (const unsigned char *) in;
 		newlen = g_mime_utils_uuencode_step (inbuf, len, outbuf, basic->uubuf, &basic->state,
 						     &basic->save);
-		g_assert (newlen <= (len + 2) * 2 + 62);
+		g_assert (newlen <= GMIME_UUENCODE_LEN (len));
 		break;
 	case GMIME_FILTER_BASIC_BASE64_DEC:
 		/* output can't possibly exceed the input size */

Modified: trunk/gmime/gmime-utils.c
==============================================================================
--- trunk/gmime/gmime-utils.c	(original)
+++ trunk/gmime/gmime-utils.c	Sun Feb 10 00:34:28 2008
@@ -2066,7 +2066,7 @@
 	
 	switch (g_mime_utils_best_encoding ((const unsigned char *) word, len)) {
 	case GMIME_PART_ENCODING_BASE64:
-		enclen = BASE64_ENCODE_LEN (len);
+		enclen = GMIME_BASE64_ENCODE_LEN (len);
 		encoded = g_alloca (enclen + 1);
 		
 		encoding = 'b';
@@ -2089,7 +2089,7 @@
 		
 		break;
 	case GMIME_PART_ENCODING_QUOTEDPRINTABLE:
-		enclen = QP_ENCODE_LEN (len);
+		enclen = GMIME_QP_ENCODE_LEN (len);
 		encoded = g_alloca (enclen + 1);
 		
 		encoding = 'q';
@@ -2613,7 +2613,7 @@
 	const register unsigned char *inptr;
 	register unsigned char *outptr;
 	
-	if (inlen <= 0)
+	if (inlen == 0)
 		return 0;
 	
 	inptr = in;

Modified: trunk/gmime/gmime-utils.h
==============================================================================
--- trunk/gmime/gmime-utils.h	(original)
+++ trunk/gmime/gmime-utils.h	Sun Feb 10 00:34:28 2008
@@ -70,8 +70,43 @@
 };
 
 
-#define BASE64_ENCODE_LEN(x) ((size_t) ((x) * 5 / 3) + 4)  /* conservative would be ((x * 4 / 3) + 4) */
-#define QP_ENCODE_LEN(x)     ((size_t) ((x) * 7 / 2) + 4)  /* conservative would be ((x * 3) + 4) */
+/**
+ * GMIME_BASE64_ENCODE_LEN:
+ * @x: Length of the input data to encode
+ *
+ * Calculates the maximum number of bytes needed to base64 encode the
+ * full input buffer of length @x.
+ *
+ * Returns the number of output bytes needed to base64 encode an input
+ * buffer of size @x.
+ **/
+#define GMIME_BASE64_ENCODE_LEN(x) ((size_t) (((((x) + 2) / 57) * 77) + 77))
+
+
+/**
+ * GMIME_QP_ENCODE_LEN:
+ * @x: Length of the input data to encode
+ *
+ * Calculates the maximum number of bytes needed to encode the full
+ * input buffer of length @x using the quoted-printable encoding.
+ *
+ * Returns the number of output bytes needed to encode an input buffer
+ * of size @x using the quoted-printable encoding.
+ **/
+#define GMIME_QP_ENCODE_LEN(x)     ((size_t) (((x) + 1) * 3))
+
+
+/**
+ * GMIME_UUENCODE_LEN:
+ * @x: Length of the input data to encode
+ *
+ * Calculates the maximum number of bytes needed to uuencode the full
+ * input buffer of length @x.
+ *
+ * Returns the number of output bytes needed to uuencode an input
+ * buffer of size @x.
+ **/
+#define GMIME_UUENCODE_LEN(x)      ((size_t) (((((x) + 2) / 45) * 62) + 62))
 
 
 /**



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]