curl_easy_escape.3 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .\" **************************************************************************
  2. .\" * _ _ ____ _
  3. .\" * Project ___| | | | _ \| |
  4. .\" * / __| | | | |_) | |
  5. .\" * | (__| |_| | _ <| |___
  6. .\" * \___|\___/|_| \_\_____|
  7. .\" *
  8. .\" * Copyright (C) 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.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. .\" * SPDX-License-Identifier: curl
  22. .\" *
  23. .\" **************************************************************************
  24. .\"
  25. .TH curl_easy_escape 3 "7 April 2006" "libcurl" "libcurl"
  26. .SH NAME
  27. curl_easy_escape - URL encodes the given string
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. char *curl_easy_escape(CURL *curl, const char *string, int length);
  32. .fi
  33. .SH DESCRIPTION
  34. This function converts the given input \fIstring\fP to a URL encoded string
  35. and returns that as a new allocated string. All input characters that are not
  36. a-z, A-Z, 0-9, '-', '.', '_' or '~' are converted to their "URL escaped"
  37. version (\fB%NN\fP where \fBNN\fP is a two-digit hexadecimal number).
  38. If \fIlength\fP is set to 0 (zero), \fIcurl_easy_escape(3)\fP uses strlen() on
  39. the input \fIstring\fP to find out the size. This function does not accept
  40. input strings longer than \fBCURL_MAX_INPUT_LENGTH\fP (8 MB).
  41. Since 7.82.0, the \fBcurl\fP parameter is ignored. Prior to that there was
  42. per-handle character conversion support for some very old operating systems
  43. such as TPF, but it was otherwise ignored.
  44. You must \fIcurl_free(3)\fP the returned string when you are done with it.
  45. .SH ENCODING
  46. libcurl is typically not aware of, nor does it care about, character
  47. encodings. \fIcurl_easy_escape(3)\fP encodes the data byte-by-byte into the
  48. URL encoded version without knowledge or care for what particular character
  49. encoding the application or the receiving server may assume that the data
  50. uses.
  51. The caller of \fIcurl_easy_escape(3)\fP must make sure that the data passed in
  52. to the function is encoded correctly.
  53. .SH EXAMPLE
  54. .nf
  55. CURL *curl = curl_easy_init();
  56. if(curl) {
  57. char *output = curl_easy_escape(curl, "data to convert", 15);
  58. if(output) {
  59. printf("Encoded: %s\\n", output);
  60. curl_free(output);
  61. }
  62. curl_easy_cleanup(curl);
  63. }
  64. .fi
  65. .SH AVAILABILITY
  66. Added in 7.15.4 and replaces the old \fIcurl_escape(3)\fP function.
  67. .SH RETURN VALUE
  68. A pointer to a null-terminated string or NULL if it failed.
  69. .SH "SEE ALSO"
  70. .BR curl_easy_unescape "(3), " curl_free "(3), " RFC 3986