curl_easy_escape.3 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 old operating systems such as
  43. 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. int main(void)
  56. {
  57. CURL *curl = curl_easy_init();
  58. if(curl) {
  59. char *output = curl_easy_escape(curl, "data to convert", 15);
  60. if(output) {
  61. printf("Encoded: %s\\n", output);
  62. curl_free(output);
  63. }
  64. curl_easy_cleanup(curl);
  65. }
  66. }
  67. .fi
  68. .SH AVAILABILITY
  69. Added in 7.15.4 and replaces the old \fIcurl_escape(3)\fP function.
  70. .SH RETURN VALUE
  71. A pointer to a null-terminated string or NULL if it failed.
  72. .SH "SEE ALSO"
  73. .BR curl_easy_unescape (3),
  74. .BR curl_free (3)