CURL_DOES_CONVERSIONS: cleanup
Massively reduce #ifdefs all over (23 #ifdef lines less so far) Moved conversion-specific code to non-ascii.c
This commit is contained in:
32
lib/base64.c
32
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 ---- */
|
||||
|
Reference in New Issue
Block a user