CURLOPT_HSTSWRITEFUNCTION.3 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 CURLOPT_HSTSWRITEFUNCTION 3 "February 07, 2023" "libcurl 7.88.1" "curl_easy_setopt options"
  26. .SH NAME
  27. CURLOPT_HSTSWRITEFUNCTION \- write callback for HSTS hosts
  28. .SH SYNOPSIS
  29. .nf
  30. #include <curl/curl.h>
  31. struct curl_hstsentry {
  32. char *name;
  33. size_t namelen;
  34. unsigned int includeSubDomains:1;
  35. char expire[18]; /* YYYYMMDD HH:MM:SS [null-terminated] */
  36. };
  37. struct curl_index {
  38. size_t index; /* the provided entry's "index" or count */
  39. size_t total; /* total number of entries to save */
  40. };
  41. CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *sts,
  42. struct curl_index *count, void *clientp);
  43. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
  44. .fi
  45. .SH DESCRIPTION
  46. Pass a pointer to your callback function, as the prototype shows above.
  47. This callback function gets called by libcurl repeatedly to allow the
  48. application to store the in-memory HSTS cache when libcurl is about to discard
  49. it.
  50. Set the \fIclientp\fP argument with the \fICURLOPT_HSTSWRITEDATA(3)\fP option
  51. or it will be NULL.
  52. When the callback is invoked, the \fIsts\fP pointer points to a populated
  53. struct: Read the host name to 'name' (it is \fInamelen\fP bytes long and null
  54. terminated. The \fIincludeSubDomains\fP field is non-zero if the entry matches
  55. subdomains. The \fIexpire\fP string is a date stamp null-terminated string
  56. using the syntax YYYYMMDD HH:MM:SS.
  57. The callback should return \fICURLSTS_OK\fP if it succeeded and is prepared to
  58. be called again (for another host) or \fICURLSTS_DONE\fP if there's nothing
  59. more to do. It can also return \fICURLSTS_FAIL\fP to signal error.
  60. This option does not enable HSTS, you need to use \fICURLOPT_HSTS_CTRL(3)\fP to
  61. do that.
  62. .SH DEFAULT
  63. NULL - no callback.
  64. .SH PROTOCOLS
  65. This feature is only used for HTTP(S) transfer.
  66. .SH EXAMPLE
  67. .nf
  68. {
  69. /* set HSTS read callback */
  70. curl_easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
  71. /* pass in suitable argument to the callback */
  72. curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &hstspreload[0]);
  73. result = curl_easy_perform(curl);
  74. }
  75. .fi
  76. .SH AVAILABILITY
  77. Added in 7.74.0
  78. .SH RETURN VALUE
  79. This will return CURLE_OK.
  80. .SH "SEE ALSO"
  81. .BR CURLOPT_HSTSWRITEDATA "(3), " CURLOPT_HSTSWRITEFUNCTION "(3), "
  82. .BR CURLOPT_HSTS "(3), " CURLOPT_HSTS_CTRL "(3), "