1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
10 This is a simple example showing how a program on a non-ASCII platform
11 would invoke callbacks to do its own codeset conversions instead of
12 using the built-in iconv functions in libcurl.
14 The IBM-1047 EBCDIC codeset is used for this example but the code
15 would be similar for other non-ASCII codesets.
17 Three callback functions are created below:
18 my_conv_from_ascii_to_ebcdic,
19 my_conv_from_ebcdic_to_ascii, and
20 my_conv_from_utf8_to_ebcdic
22 The "platform_xxx" calls represent platform-specific conversion routines.
27 #include <curl/curl.h>
29 CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
31 char *tempptrin, *tempptrout;
32 size_t bytes = length;
34 tempptrin = tempptrout = buffer;
35 rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
36 if (rc == PLATFORM_CONV_OK) {
39 return(CURLE_CONV_FAILED);
43 CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
45 char *tempptrin, *tempptrout;
46 size_t bytes = length;
48 tempptrin = tempptrout = buffer;
49 rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
50 if (rc == PLATFORM_CONV_OK) {
53 return(CURLE_CONV_FAILED);
57 CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
59 char *tempptrin, *tempptrout;
60 size_t bytes = length;
62 tempptrin = tempptrout = buffer;
63 rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
64 if (rc == PLATFORM_CONV_OK) {
67 return(CURLE_CONV_FAILED);
76 curl = curl_easy_init();
78 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
80 /* use platform-specific functions for codeset conversions */
81 curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
82 my_conv_from_ascii_to_ebcdic);
83 curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION,
84 my_conv_from_ebcdic_to_ascii);
85 curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
86 my_conv_from_utf8_to_ebcdic);
88 res = curl_easy_perform(curl);
91 curl_easy_cleanup(curl);