make calls to iconv functions depend on HAVE_ICONV

This commit is contained in:
wbaumann 2010-11-07 10:31:40 +00:00
parent c01f625e79
commit 09fc39b814

View File

@ -25,7 +25,9 @@
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#endif #endif
#ifdef HAVE_ICONV_H
#include <iconv.h> #include <iconv.h>
#endif
#ifdef HAVE_LANGINFO_H #ifdef HAVE_LANGINFO_H
#include <langinfo.h> #include <langinfo.h>
#endif #endif
@ -199,6 +201,7 @@ static int initialized;
Needed by ssl_verify() which may be called at any time. */ Needed by ssl_verify() which may be called at any time. */
static int have_terminal; static int have_terminal;


#ifdef HAVE_ICONV
/* Handle to convert character encoding from utf-8 to LC_CTYPE. /* Handle to convert character encoding from utf-8 to LC_CTYPE.
If NULL no conversion is done. */ If NULL no conversion is done. */
static iconv_t from_utf_8; static iconv_t from_utf_8;
@ -214,6 +217,7 @@ static iconv_t from_server_enc;
/* Handle to convert from LC_CTYPE to character encoding of path names. /* Handle to convert from LC_CTYPE to character encoding of path names.
If NULL no conversion is done. */ If NULL no conversion is done. */
static iconv_t to_server_enc; static iconv_t to_server_enc;
#endif /* HAVE_ICONV */


/* A GNU custom stream, used to redirect neon debug messages to syslog. */ /* A GNU custom stream, used to redirect neon debug messages to syslog. */
static FILE *log_stream; static FILE *log_stream;
@ -230,8 +234,10 @@ static char *cookie;
/* Private function prototypes and inline functions */ /* Private function prototypes and inline functions */
/*==================================================*/ /*==================================================*/


#ifdef HAVE_ICONV
static void static void
convert(char **s, iconv_t conv); convert(char **s, iconv_t conv);
#endif


static int static int
get_error(int ret, const char *method); get_error(int ret, const char *method);
@ -315,6 +321,7 @@ dav_init_webdav(const dav_args *args)
if (args->neon_debug & ~NE_DBG_HTTPPLAIN) if (args->neon_debug & ~NE_DBG_HTTPPLAIN)
syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Initializing webdav"); syslog(LOG_MAKEPRI(LOG_DAEMON, LOG_DEBUG), "Initializing webdav");


#ifdef HAVE_ICONV
char *lc_charset = nl_langinfo(CODESET); char *lc_charset = nl_langinfo(CODESET);
if (lc_charset && strcasecmp(lc_charset, "UTF-8") != 0) { if (lc_charset && strcasecmp(lc_charset, "UTF-8") != 0) {
from_utf_8 = iconv_open(lc_charset, "UTF-8"); from_utf_8 = iconv_open(lc_charset, "UTF-8");
@ -339,6 +346,7 @@ dav_init_webdav(const dav_args *args)
to_server_enc = 0; to_server_enc = 0;
} }
} }
#endif /* HAVE_ICONV */


if (ne_sock_init() != 0) if (ne_sock_init() != 0)
error(EXIT_FAILURE, errno, _("socket library initialization failed")); error(EXIT_FAILURE, errno, _("socket library initialization failed"));
@ -541,8 +549,10 @@ char *
dav_conv_from_utf_8(const char *s) dav_conv_from_utf_8(const char *s)
{ {
char *new = ne_strdup(s); char *new = ne_strdup(s);
#ifdef HAVE_ICONV
if (from_utf_8) if (from_utf_8)
convert(&new, from_utf_8); convert(&new, from_utf_8);
#endif
return new; return new;
} }


@ -551,8 +561,10 @@ char *
dav_conv_to_utf_8(const char *s) dav_conv_to_utf_8(const char *s)
{ {
char *new = ne_strdup(s); char *new = ne_strdup(s);
#ifdef HAVE_ICONV
if (to_utf_8) if (to_utf_8)
convert(&new, to_utf_8); convert(&new, to_utf_8);
#endif
return new; return new;
} }


@ -561,8 +573,10 @@ char *
dav_conv_from_server_enc(const char *s) dav_conv_from_server_enc(const char *s)
{ {
char *new = ne_strdup(s); char *new = ne_strdup(s);
#ifdef HAVE_ICONV
if (from_server_enc) if (from_server_enc)
convert(&new, from_server_enc); convert(&new, from_server_enc);
#endif
return new; return new;
} }


@ -571,8 +585,10 @@ char *
dav_conv_to_server_enc(const char *s) dav_conv_to_server_enc(const char *s)
{ {
char *new = ne_strdup(s); char *new = ne_strdup(s);
#ifdef HAVE_ICONV
if (to_server_enc) if (to_server_enc)
convert(&new, to_server_enc); convert(&new, to_server_enc);
#endif
return new; return new;
} }


@ -1241,6 +1257,7 @@ dav_unlock(const char *path, time_t *expire)
/* Private functions */ /* Private functions */
/*===================*/ /*===================*/


#ifdef HAVE_ICONV
static void static void
convert(char **s, iconv_t conv) convert(char **s, iconv_t conv)
{ {
@ -1261,6 +1278,7 @@ convert(char **s, iconv_t conv)


free(buf); free(buf);
} }
#endif /* HAVE_ICONV */




/* Returns a file error code according to ret from the last WebDAV /* Returns a file error code according to ret from the last WebDAV
@ -1775,8 +1793,10 @@ prop_result(void *userdata, const ne_uri *uri, const ne_prop_result_set *set)
strlen(result->path) - strlen(ctx->path) strlen(result->path) - strlen(ctx->path)
- result->is_dir); - result->is_dir);
replace_slashes(&result->name); replace_slashes(&result->name);
#ifdef HAVE_ICONV
if (from_server_enc) if (from_server_enc)
convert(&result->name, from_server_enc); convert(&result->name, from_server_enc);
#endif
} }


data = ne_propset_value(set, &prop_names[ETAG]); data = ne_propset_value(set, &prop_names[ETAG]);