summaryrefslogtreecommitdiff
path: root/lib/base64.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2011-04-20 00:48:20 +0200
committerDaniel Stenberg <daniel@haxx.se>2011-04-20 00:50:07 +0200
commitc828646f60b5bffb2bfcf924eba36da767bf08bf (patch)
treea13db5750b3927a2dea67364fbafba4b91fa7e9f /lib/base64.c
parenteb65a49befa040746b222e693bba19ee56814e85 (diff)
downloadcurl-c828646f60b5bffb2bfcf924eba36da767bf08bf.tar.gz
CURL_DOES_CONVERSIONS: cleanup
Massively reduce #ifdefs all over (23 #ifdef lines less so far) Moved conversion-specific code to non-ascii.c
Diffstat (limited to 'lib/base64.c')
-rw-r--r--lib/base64.c32
1 files changed, 8 insertions, 24 deletions
diff --git a/lib/base64.c b/lib/base64.c
index 66ddb329c..0c492dc45 100644
--- a/lib/base64.c
+++ b/lib/base64.c
@@ -31,10 +31,10 @@
#include <curl/mprintf.h>
#include "urldata.h" /* for the SessionHandle definition */
-#include "easyif.h" /* for Curl_convert_... prototypes */
#include "warnless.h"
#include "curl_base64.h"
#include "curl_memory.h"
+#include "non-ascii.h"
/* include memdebug.h last */
#include "memdebug.h"
@@ -146,9 +146,7 @@ size_t Curl_base64_encode(struct SessionHandle *data,
int inputparts;
char *output;
char *base64data;
-#ifdef CURL_DOES_CONVERSIONS
char *convbuf = NULL;
-#endif
const char *indata = inputbuff;
@@ -161,29 +159,16 @@ size_t Curl_base64_encode(struct SessionHandle *data,
if(NULL == output)
return 0;
-#ifdef CURL_DOES_CONVERSIONS
/*
* The base64 data needs to be created using the network encoding
* not the host encoding. And we can't change the actual input
* so we copy it to a buffer, translate it, and use that instead.
*/
- if(data) {
- convbuf = malloc(insize);
- if(!convbuf) {
- free(output);
- return 0;
- }
- memcpy(convbuf, indata, insize);
- if(CURLE_OK != Curl_convert_to_network(data, convbuf, insize)) {
- free(convbuf);
- free(output);
- return 0;
- }
- indata = convbuf; /* switch to the converted buffer */
- }
-#else
- (void)data;
-#endif
+ if(Curl_convert_clone(data, indata, insize, &convbuf))
+ return 0;
+
+ if(convbuf)
+ indata = (char *)convbuf;
while(insize > 0) {
for (i = inputparts = 0; i < 3; i++) {
@@ -229,10 +214,9 @@ size_t Curl_base64_encode(struct SessionHandle *data,
*output=0;
*outptr = base64data; /* make it return the actual data memory */
-#ifdef CURL_DOES_CONVERSIONS
- if(data)
+ if(convbuf)
free(convbuf);
-#endif
+
return strlen(base64data); /* return the length of the new data */
}
/* ---- End of Base64 Encoding ---- */