1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_CONV_FROM_NETWORK_FUNCTION
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_CONV_FROM_UTF8_FUNCTION (3)
9  - CURLOPT_CONV_TO_NETWORK_FUNCTION (3)
10Protocol:
11  - All
12Added-in: 7.15.4
13---
14
15# NAME
16
17CURLOPT_CONV_FROM_NETWORK_FUNCTION - convert data from network to host encoding
18
19# SYNOPSIS
20
21~~~c
22#include <curl/curl.h>
23
24CURLcode conv_callback(char *ptr, size_t length);
25
26CURLcode curl_easy_setopt(CURL *handle, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
27                          conv_callback);
28~~~
29
30# DESCRIPTION
31
32Pass a pointer to your callback function, which should match the prototype
33shown above.
34
35Applies to non-ASCII platforms. curl_version_info(3) returns the
36**CURL_VERSION_CONV** feature bit set if this option is provided.
37
38The data to be converted is in a buffer pointed to by the *ptr* parameter.
39The amount of data to convert is indicated by the *length* parameter. The
40converted data overlays the input data in the buffer pointed to by the ptr
41parameter. *CURLE_OK* must be returned upon successful conversion. A
42CURLcode return value defined by curl.h, such as *CURLE_CONV_FAILED*,
43should be returned if an error was encountered.
44
45CURLOPT_CONV_FROM_NETWORK_FUNCTION(3) converts to host encoding from the
46network encoding. It is used when commands or ASCII data are received over the
47network.
48
49If you set a callback pointer to NULL, or do not set it at all, the built-in
50libcurl iconv functions are used. If HAVE_ICONV was not defined when libcurl
51was built, and no callback has been established, the conversion returns the
52**CURLE_CONV_REQD** error code.
53
54If **HAVE_ICONV** is defined, **CURL_ICONV_CODESET_OF_HOST** must also be
55defined. For example:
56
57~~~c
58#define CURL_ICONV_CODESET_OF_HOST "IBM-1047"
59~~~
60
61The iconv code in libcurl defaults the network and UTF8 codeset names as
62follows:
63
64~~~
65#define CURL_ICONV_CODESET_OF_NETWORK "ISO8859-1"
66
67#define CURL_ICONV_CODESET_FOR_UTF8  "UTF-8"
68~~~
69
70You need to override these definitions if they are different on your system.
71
72# DEFAULT
73
74NULL
75
76# %PROTOCOLS%
77
78# EXAMPLE
79
80~~~c
81static CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
82{
83  int rc = 0;
84
85  /* in-place convert 'buffer' from ASCII to EBCDIC */
86
87  if(rc == 0) {
88    /* success */
89    return CURLE_OK;
90  }
91  else {
92    return CURLE_CONV_FAILED;
93  }
94}
95
96int main(void)
97{
98  CURL *curl = curl_easy_init();
99
100  /* use platform-specific functions for codeset conversions */
101  curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
102                   my_conv_from_ascii_to_ebcdic);
103}
104~~~
105
106# DEPRECATED
107
108Not available and deprecated since 7.82.0.
109
110Available only if **CURL_DOES_CONVERSIONS** was defined when libcurl was
111built.
112
113# %AVAILABILITY%
114
115# RETURN VALUE
116
117Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
118