1 /*****************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: sampleconv.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
11 This is a simple example showing how a program on a non-ASCII platform
12 would invoke callbacks to do its own codeset conversions instead of
13 using the built-in iconv functions in libcurl.
15 The IBM-1047 EBCDIC codeset is used for this example but the code
16 would be similar for other non-ASCII codesets.
18 Three callback functions are created below:
19 my_conv_from_ascii_to_ebcdic,
20 my_conv_from_ebcdic_to_ascii, and
21 my_conv_from_utf8_to_ebcdic
23 The "platform_xxx" calls represent platform-specific conversion routines.
28 #include <curl/curl.h>
30 CURLcode
my_conv_from_ascii_to_ebcdic(char *buffer
, size_t length
)
32 char *tempptrin
, *tempptrout
;
33 size_t bytes
= length
;
35 tempptrin
= tempptrout
= buffer
;
36 rc
= platform_a2e(&tempptrin
, &bytes
, &tempptrout
, &bytes
);
37 if (rc
== PLATFORM_CONV_OK
) {
40 return(CURLE_CONV_FAILED
);
44 CURLcode
my_conv_from_ebcdic_to_ascii(char *buffer
, size_t length
)
46 char *tempptrin
, *tempptrout
;
47 size_t bytes
= length
;
49 tempptrin
= tempptrout
= buffer
;
50 rc
= platform_e2a(&tempptrin
, &bytes
, &tempptrout
, &bytes
);
51 if (rc
== PLATFORM_CONV_OK
) {
54 return(CURLE_CONV_FAILED
);
58 CURLcode
my_conv_from_utf8_to_ebcdic(char *buffer
, size_t length
)
60 char *tempptrin
, *tempptrout
;
61 size_t bytes
= length
;
63 tempptrin
= tempptrout
= buffer
;
64 rc
= platform_u2e(&tempptrin
, &bytes
, &tempptrout
, &bytes
);
65 if (rc
== PLATFORM_CONV_OK
) {
68 return(CURLE_CONV_FAILED
);
77 curl
= curl_easy_init();
79 curl_easy_setopt(curl
, CURLOPT_URL
, "curl.haxx.se");
81 /* use platform-specific functions for codeset conversions */
82 curl_easy_setopt(curl
, CURLOPT_CONV_FROM_NETWORK_FUNCTION
,
83 my_conv_from_ascii_to_ebcdic
);
84 curl_easy_setopt(curl
, CURLOPT_CONV_TO_NETWORK_FUNCTION
,
85 my_conv_from_ebcdic_to_ascii
);
86 curl_easy_setopt(curl
, CURLOPT_CONV_FROM_UTF8_FUNCTION
,
87 my_conv_from_utf8_to_ebcdic
);
89 res
= curl_easy_perform(curl
);
92 curl_easy_cleanup(curl
);