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:
Daniel Stenberg
2011-04-20 00:48:20 +02:00
parent eb65a49bef
commit c828646f60
25 changed files with 469 additions and 420 deletions

View File

@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -31,10 +31,9 @@
#include <stdlib.h>
#include <string.h>
#include "curl_memory.h"
/* urldata.h and easyif.h are included for Curl_convert_... prototypes */
#include "urldata.h"
#include "easyif.h"
#include "warnless.h"
#include "non-ascii.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -91,10 +90,6 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
int strindex=0;
size_t length;
#ifndef CURL_DOES_CONVERSIONS
/* avoid compiler warnings */
(void)handle;
#endif
ns = malloc(alloc);
if(!ns)
return NULL;
@@ -122,15 +117,11 @@ char *curl_easy_escape(CURL *handle, const char *string, int inlength)
}
}
#ifdef CURL_DOES_CONVERSIONS
/* escape sequences are always in ASCII so convert them on non-ASCII hosts */
if(!handle ||
(Curl_convert_to_network(handle, &in, 1) != CURLE_OK)) {
if(Curl_convert_to_network(handle, &in, 1)) {
/* Curl_convert_to_network calls failf if unsuccessful */
free(ns);
return NULL;
}
#endif /* CURL_DOES_CONVERSIONS */
snprintf(&ns[strindex], 4, "%%%02X", in);
@@ -157,11 +148,7 @@ char *curl_easy_unescape(CURL *handle, const char *string, int length,
int strindex=0;
unsigned long hex;
#ifndef CURL_DOES_CONVERSIONS
/* avoid compiler warnings */
(void)handle;
#endif
if( !ns )
if(!ns)
return NULL;
while(--alloc > 0) {
@@ -178,15 +165,11 @@ char *curl_easy_unescape(CURL *handle, const char *string, int length,
in = curlx_ultouc(hex); /* this long is never bigger than 255 anyway */
#ifdef CURL_DOES_CONVERSIONS
/* escape sequences are always in ASCII so convert them on non-ASCII hosts */
if(!handle ||
(Curl_convert_from_network(handle, &in, 1) != CURLE_OK)) {
if(Curl_convert_from_network(handle, &in, 1)) {
/* Curl_convert_from_network calls failf if unsuccessful */
free(ns);
return NULL;
}
#endif /* CURL_DOES_CONVERSIONS */
string+=2;
alloc-=2;