1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 1998 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
10 * This software is licensed as described in the file COPYING, which
11 * you should have received as part of this distribution. The terms
12 * are also available at http://curl.haxx.se/docs/copyright.html.
14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell
15 * copies of the Software, and permit persons to whom the Software is
16 * furnished to do so, under the terms of the COPYING file.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
23 This is a simple example showing how a program on a non-ASCII platform
24 would invoke callbacks to do its own codeset conversions instead of
25 using the built-in iconv functions in libcurl.
27 The IBM-1047 EBCDIC codeset is used for this example but the code
28 would be similar for other non-ASCII codesets.
30 Three callback functions are created below:
31 my_conv_from_ascii_to_ebcdic,
32 my_conv_from_ebcdic_to_ascii, and
33 my_conv_from_utf8_to_ebcdic
35 The "platform_xxx" calls represent platform-specific conversion routines.
40 #include <curl/curl.h>
42 CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
44 char *tempptrin, *tempptrout;
45 size_t bytes = length;
47 tempptrin = tempptrout = buffer;
48 rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
49 if (rc == PLATFORM_CONV_OK) {
52 return(CURLE_CONV_FAILED);
56 CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
58 char *tempptrin, *tempptrout;
59 size_t bytes = length;
61 tempptrin = tempptrout = buffer;
62 rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
63 if (rc == PLATFORM_CONV_OK) {
66 return(CURLE_CONV_FAILED);
70 CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
72 char *tempptrin, *tempptrout;
73 size_t bytes = length;
75 tempptrin = tempptrout = buffer;
76 rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
77 if (rc == PLATFORM_CONV_OK) {
80 return(CURLE_CONV_FAILED);
89 curl = curl_easy_init();
91 curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
93 /* use platform-specific functions for codeset conversions */
94 curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
95 my_conv_from_ascii_to_ebcdic);
96 curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION,
97 my_conv_from_ebcdic_to_ascii);
98 curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
99 my_conv_from_utf8_to_ebcdic);
101 res = curl_easy_perform(curl);
104 curl_easy_cleanup(curl);