Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Utilities / cmcurl-7.19.0 / docs / examples / sampleconv.c
blob5ef5268b1011ea2b60e10770f7459449cd1b559e
1 /*****************************************************************************
2 * _ _ ____ _
3 * Project ___| | | | _ \| |
4 * / __| | | | |_) | |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * $Id: sampleconv.c,v 1.1.1.1 2008-09-23 16:32:05 hoffman Exp $
9 */
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.
27 #include <stdio.h>
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;
34 int rc;
35 tempptrin = tempptrout = buffer;
36 rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
37 if (rc == PLATFORM_CONV_OK) {
38 return(CURLE_OK);
39 } else {
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;
48 int rc;
49 tempptrin = tempptrout = buffer;
50 rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
51 if (rc == PLATFORM_CONV_OK) {
52 return(CURLE_OK);
53 } else {
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;
62 int rc;
63 tempptrin = tempptrout = buffer;
64 rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
65 if (rc == PLATFORM_CONV_OK) {
66 return(CURLE_OK);
67 } else {
68 return(CURLE_CONV_FAILED);
72 int main(void)
74 CURL *curl;
75 CURLcode res;
77 curl = curl_easy_init();
78 if(curl) {
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);
91 /* always cleanup */
92 curl_easy_cleanup(curl);
94 return 0;