Removed libb64's behavior of automatically appending a newline to everything
authorArt Cancro <ajc@citadel.org>
Fri, 22 Jan 2016 19:40:10 +0000 (14:40 -0500)
committerArt Cancro <ajc@citadel.org>
Fri, 22 Jan 2016 19:40:10 +0000 (14:40 -0500)
it encodes.  This is what broke listsub and probably other things as well.
I deliberately changed the calling syntax of base64_encode_blockend() to make
it break if someone tries to upgrade it later, so it will call their attention
to this difference.

libcitadel/lib/b64/cencode.c
libcitadel/lib/b64/cencode.h
libcitadel/lib/tools.c

index 64720f6cf678a149e93cf659f853680d410b7bd2..150125af95064f2a95f0ce527c5d295376c1b9c4 100644 (file)
@@ -1,9 +1,14 @@
-/*
-cencoder.c - c source to a base64 encoding algorithm implementation
-
-This is part of the libb64 project, and has been placed in the public domain.
-For details, see http://sourceforge.net/projects/libb64
-*/
+// 
+// cencoder.c - c source to a base64 encoding algorithm implementation
+// 
+// This is part of the libb64 project, and has been placed in the public domain.
+// For details, see http://sourceforge.net/projects/libb64
+// 
+// ** NOTE: MODIFIED BY AJC 2016JAN22 **
+// The libb64 distribution always places a newline at the end of an encoded block.
+// We have removed that behavior.  If libb64 is updated, make that change again.
+// 
+// 
 
 #include "b64/cencode.h"
 
@@ -74,7 +79,7 @@ int base64_encode_block(const char* plaintext_in, int length_in, char* code_out,
        return codechar - code_out;
 }
 
-int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
+int base64_encode_blockend(char* code_out, base64_encodestate* state_in, int with_newline)
 {
        char* codechar = code_out;
        
@@ -92,8 +97,10 @@ int base64_encode_blockend(char* code_out, base64_encodestate* state_in)
        case step_A:
                break;
        }
-       *codechar++ = '\r';
-       *codechar++ = '\n';
+       if (with_newline) {                     // added by ajc on 2016jan22, normally citadel doesn't want this
+               *codechar++ = '\r';
+               *codechar++ = '\n';
+       }
        
        return codechar - code_out;
 }
index c1e3464af3bb7798c0f4b05dba25f84a58fa7490..81ea3b9bcfd2de82d028f09674e5c55a3851fac1 100644 (file)
@@ -26,6 +26,6 @@ char base64_encode_value(char value_in);
 
 int base64_encode_block(const char* plaintext_in, int length_in, char* code_out, base64_encodestate* state_in);
 
-int base64_encode_blockend(char* code_out, base64_encodestate* state_in);
+int base64_encode_blockend(char* code_out, base64_encodestate* state_in, int with_newline);
 
 #endif /* BASE64_CENCODE_H */
index 14e43071a1761d6c02ed248ae6fdc6e70d82c7c7..ad541ddf1a0ca08726a2dca123c52182395a0864 100644 (file)
@@ -317,12 +317,12 @@ size_t CtdlEncodeBase64(char *dest, const char *source, size_t sourcelen, int li
                        dest[destoffset++] = '\n';
                }
 
-               destoffset += base64_encode_blockend(&(dest[destoffset]), &_state);
+               destoffset += base64_encode_blockend(&(dest[destoffset]), &_state, 0);
        }
        else {
                destoffset = base64_encode_block(source, sourcelen, dest, &_state);
 
-               destoffset += base64_encode_blockend(&(dest[destoffset]), &_state);
+               destoffset += base64_encode_blockend(&(dest[destoffset]), &_state, 0);
        }
        dest[destoffset] = 0;
        return destoffset;