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