Annotation of embedaddon/curl/docs/examples/sampleconv.c, revision 1.1
1.1 ! misho 1: /***************************************************************************
! 2: * _ _ ____ _
! 3: * Project ___| | | | _ \| |
! 4: * / __| | | | |_) | |
! 5: * | (__| |_| | _ <| |___
! 6: * \___|\___/|_| \_\_____|
! 7: *
! 8: * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
! 9: *
! 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 https://curl.haxx.se/docs/copyright.html.
! 13: *
! 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.
! 17: *
! 18: * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
! 19: * KIND, either express or implied.
! 20: *
! 21: ***************************************************************************/
! 22: /* <DESC>
! 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.
! 26: * </DESC>
! 27: */
! 28: /*
! 29:
! 30: The IBM-1047 EBCDIC codeset is used for this example but the code
! 31: would be similar for other non-ASCII codesets.
! 32:
! 33: Three callback functions are created below:
! 34: my_conv_from_ascii_to_ebcdic,
! 35: my_conv_from_ebcdic_to_ascii, and
! 36: my_conv_from_utf8_to_ebcdic
! 37:
! 38: The "platform_xxx" calls represent platform-specific conversion routines.
! 39:
! 40: */
! 41:
! 42: #include <stdio.h>
! 43: #include <curl/curl.h>
! 44:
! 45: static CURLcode my_conv_from_ascii_to_ebcdic(char *buffer, size_t length)
! 46: {
! 47: char *tempptrin, *tempptrout;
! 48: size_t bytes = length;
! 49: int rc;
! 50: tempptrin = tempptrout = buffer;
! 51: rc = platform_a2e(&tempptrin, &bytes, &tempptrout, &bytes);
! 52: if(rc == PLATFORM_CONV_OK) {
! 53: return CURLE_OK;
! 54: }
! 55: else {
! 56: return CURLE_CONV_FAILED;
! 57: }
! 58: }
! 59:
! 60: static CURLcode my_conv_from_ebcdic_to_ascii(char *buffer, size_t length)
! 61: {
! 62: char *tempptrin, *tempptrout;
! 63: size_t bytes = length;
! 64: int rc;
! 65: tempptrin = tempptrout = buffer;
! 66: rc = platform_e2a(&tempptrin, &bytes, &tempptrout, &bytes);
! 67: if(rc == PLATFORM_CONV_OK) {
! 68: return CURLE_OK;
! 69: }
! 70: else {
! 71: return CURLE_CONV_FAILED;
! 72: }
! 73: }
! 74:
! 75: static CURLcode my_conv_from_utf8_to_ebcdic(char *buffer, size_t length)
! 76: {
! 77: char *tempptrin, *tempptrout;
! 78: size_t bytes = length;
! 79: int rc;
! 80: tempptrin = tempptrout = buffer;
! 81: rc = platform_u2e(&tempptrin, &bytes, &tempptrout, &bytes);
! 82: if(rc == PLATFORM_CONV_OK) {
! 83: return CURLE_OK;
! 84: }
! 85: else {
! 86: return CURLE_CONV_FAILED;
! 87: }
! 88: }
! 89:
! 90: int main(void)
! 91: {
! 92: CURL *curl;
! 93:
! 94: curl = curl_easy_init();
! 95: if(curl) {
! 96: curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
! 97:
! 98: /* use platform-specific functions for codeset conversions */
! 99: curl_easy_setopt(curl, CURLOPT_CONV_FROM_NETWORK_FUNCTION,
! 100: my_conv_from_ascii_to_ebcdic);
! 101: curl_easy_setopt(curl, CURLOPT_CONV_TO_NETWORK_FUNCTION,
! 102: my_conv_from_ebcdic_to_ascii);
! 103: curl_easy_setopt(curl, CURLOPT_CONV_FROM_UTF8_FUNCTION,
! 104: my_conv_from_utf8_to_ebcdic);
! 105:
! 106: curl_easy_perform(curl);
! 107:
! 108: /* always cleanup */
! 109: curl_easy_cleanup(curl);
! 110: }
! 111: return 0;
! 112: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>