CURLOPT_HSTSWRITEFUNCTION.3 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HSTSWRITEFUNCTION.md
  2. .TH CURLOPT_HSTSWRITEFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HSTSWRITEFUNCTION \- write callback for HSTS hosts
  5. .SH SYNOPSIS
  6. .nf
  7. #include <curl/curl.h>
  8. struct curl_hstsentry {
  9. char *name;
  10. size_t namelen;
  11. unsigned int includeSubDomains:1;
  12. char expire[18]; /* YYYYMMDD HH:MM:SS [null-terminated] */
  13. };
  14. struct curl_index {
  15. size_t index; /* the provided entry's "index" or count */
  16. size_t total; /* total number of entries to save */
  17. };
  18. CURLSTScode hstswrite(CURL *easy, struct curl_hstsentry *sts,
  19. struct curl_index *count, void *clientp);
  20. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTSWRITEFUNCTION, hstswrite);
  21. .fi
  22. .SH DESCRIPTION
  23. Pass a pointer to your callback function, as the prototype shows above.
  24. This callback function gets called by libcurl repeatedly to allow the
  25. application to store the in\-memory HSTS cache when libcurl is about to discard
  26. it.
  27. Set the \fIclientp\fP argument with the \fICURLOPT_HSTSWRITEDATA(3)\fP option
  28. or it is NULL.
  29. When the callback is invoked, the \fIsts\fP pointer points to a populated
  30. struct: Read the hostname to \(aqname\(aq (it is \fInamelen\fP bytes long and null
  31. terminated. The \fIincludeSubDomains\fP field is non\-zero if the entry matches
  32. subdomains. The \fIexpire\fP string is a date stamp null\-terminated string
  33. using the syntax YYYYMMDD HH:MM:SS.
  34. The callback should return \fICURLSTS_OK\fP if it succeeded and is prepared to
  35. be called again (for another host) or \fICURLSTS_DONE\fP if there is nothing
  36. more to do. It can also return \fICURLSTS_FAIL\fP to signal error.
  37. This option does not enable HSTS, you need to use \fICURLOPT_HSTS_CTRL(3)\fP to
  38. do that.
  39. .SH DEFAULT
  40. NULL \- no callback.
  41. .SH PROTOCOLS
  42. This functionality affects http only
  43. .SH EXAMPLE
  44. .nf
  45. struct priv {
  46. void *custom;
  47. };
  48. static CURLSTScode hswr_cb(CURL *easy, struct curl_hstsentry *sts,
  49. struct curl_index *count, void *clientp)
  50. {
  51. /* save the passed in HSTS data somewhere */
  52. return CURLSTS_OK;
  53. }
  54. int main(void)
  55. {
  56. CURL *curl = curl_easy_init();
  57. if(curl) {
  58. struct priv my_stuff;
  59. CURLcode res;
  60. /* set HSTS read callback */
  61. curl_easy_setopt(curl, CURLOPT_HSTSWRITEFUNCTION, hswr_cb);
  62. /* pass in suitable argument to the callback */
  63. curl_easy_setopt(curl, CURLOPT_HSTSWRITEDATA, &my_stuff);
  64. res = curl_easy_perform(curl);
  65. }
  66. }
  67. .fi
  68. .SH AVAILABILITY
  69. Added in curl 7.74.0
  70. .SH RETURN VALUE
  71. This returns CURLE_OK.
  72. .SH SEE ALSO
  73. .BR CURLOPT_HSTS (3),
  74. .BR CURLOPT_HSTSWRITEDATA (3),
  75. .BR CURLOPT_HSTSWRITEFUNCTION (3),
  76. .BR CURLOPT_HSTS_CTRL (3)