sampleconv.c
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                  _   _ ____  _
00003  *  Project                     ___| | | |  _ \| |
00004  *                             / __| | | | |_) | |
00005  *                            | (__| |_| |  _ <| |___
00006  *                             \___|\___/|_| \_\_____|
00007  *
00008  * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
00009  *
00010  * This software is licensed as described in the file COPYING, which
00011  * you should have received as part of this distribution. The terms
00012  * are also available at https://curl.haxx.se/docs/copyright.html.
00013  *
00014  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
00015  * copies of the Software, and permit persons to whom the Software is
00016  * furnished to do so, under the terms of the COPYING file.
00017  *
00018  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
00019  * KIND, either express or implied.
00020  *
00021  ***************************************************************************/
00022 /* <DESC>
00023  * This is a simple example showing how a program on a non-ASCII platform
00024  * would invoke callbacks to do its own codeset conversions instead of
00025  * using the built-in iconv functions in libcurl.
00026  * </DESC>
00027  */
00028 /*
00029 
00030    The IBM-1047 EBCDIC codeset is used for this example but the code
00031    would be similar for other non-ASCII codesets.
00032 
00033    Three callback functions are created below:
00034         my_conv_from_ascii_to_ebcdic,
00035         my_conv_from_ebcdic_to_ascii, and
00036         my_conv_from_utf8_to_ebcdic
00037 
00038    The "platform_xxx" calls represent platform-specific conversion routines.
00039 
00040  */
00041 
00042 #include <stdio.h>
00043 #include <curl/curl.h>
00044 
00045 CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
00046 {
00047     char *tempptrin, *tempptrout;
00048     size_t bytes = length;
00049     int rc;
00050     tempptrin = tempptrout = buffer;
00051     rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
00052     if(rc == PLATFORM_CONV_OK) {
00053       return CURLE_OK;
00054     }
00055     else {
00056       return CURLE_CONV_FAILED;
00057     }
00058 }
00059 
00060 CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
00061 {
00062     char *tempptrin, *tempptrout;
00063     size_t bytes = length;
00064     int rc;
00065     tempptrin = tempptrout = buffer;
00066     rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
00067     if(rc == PLATFORM_CONV_OK) {
00068       return CURLE_OK;
00069     }
00070     else {
00071       return CURLE_CONV_FAILED;
00072     }
00073 }
00074 
00075 CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
00076 {
00077     char *tempptrin, *tempptrout;
00078     size_t bytes = length;
00079     int rc;
00080     tempptrin = tempptrout = buffer;
00081     rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
00082     if(rc == PLATFORM_CONV_OK) {
00083       return CURLE_OK;
00084     }
00085     else {
00086       return CURLE_CONV_FAILED;
00087     }
00088 }
00089 
00090 int main(void)
00091 {
00092   CURL *curl;
00093   CURLcode res;
00094 
00095   curl = curl_easy_init();
00096   if(curl) {
00097     curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
00098 
00099     /* use platform-specific functions for codeset conversions */
00100     curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
00101                      my_conv_from_ascii_to_ebcdic);
00102     curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION,
00103                      my_conv_from_ebcdic_to_ascii);
00104     curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
00105                      my_conv_from_utf8_to_ebcdic);
00106 
00107     res = curl_easy_perform(curl);
00108 
00109     /* always cleanup */
00110     curl_easy_cleanup(curl);
00111   }
00112   return 0;
00113 }


rc_visard_driver
Author(s): Heiko Hirschmueller , Christian Emmerich , Felix Ruess
autogenerated on Thu Jun 6 2019 20:43:06