CURLOPT_HSTSREADFUNCTION.3 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. .\" generated by cd2nroff 0.1 from CURLOPT_HSTSREADFUNCTION.md
  2. .TH CURLOPT_HSTSREADFUNCTION 3 "2025-01-17" libcurl
  3. .SH NAME
  4. CURLOPT_HSTSREADFUNCTION \- read 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. CURLSTScode hstsread(CURL *easy, struct curl_hstsentry *sts, void *clientp);
  15. CURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTSREADFUNCTION, hstsread);
  16. .fi
  17. .SH DESCRIPTION
  18. Pass a pointer to your callback function, as the prototype shows above.
  19. This callback function gets called by libcurl repeatedly when it populates the
  20. in\-memory HSTS cache.
  21. Set the \fIclientp\fP argument with the \fICURLOPT_HSTSREADDATA(3)\fP option
  22. or it is NULL.
  23. When this callback is invoked, the \fIsts\fP pointer points to a populated
  24. struct: Copy the hostname to \fIname\fP (no longer than \fInamelen\fP
  25. bytes). Make it null\-terminated. Set \fIincludeSubDomains\fP to TRUE or
  26. FALSE. Set \fIexpire\fP to a date stamp or a zero length string for \fIforever\fP
  27. (wrong date stamp format might cause the name to not get accepted)
  28. The callback should return \fICURLSTS_OK\fP if it returns a name and is
  29. prepared to be called again (for another host) or \fICURLSTS_DONE\fP if it has
  30. no entry to return. It can also return \fICURLSTS_FAIL\fP to signal
  31. error. Returning \fICURLSTS_FAIL\fP stops the transfer from being performed
  32. and make \fICURLE_ABORTED_BY_CALLBACK\fP get returned.
  33. This option does not enable HSTS, you need to use \fICURLOPT_HSTS_CTRL(3)\fP to
  34. do that.
  35. .SH DEFAULT
  36. NULL \- no callback.
  37. .SH PROTOCOLS
  38. This functionality affects http only
  39. .SH EXAMPLE
  40. .nf
  41. struct priv {
  42. void *custom;
  43. };
  44. static CURLSTScode hsts_cb(CURL *easy, struct curl_hstsentry *sts,
  45. void *clientp)
  46. {
  47. /* populate the struct as documented */
  48. return CURLSTS_OK;
  49. }
  50. int main(void)
  51. {
  52. CURL *curl = curl_easy_init();
  53. if(curl) {
  54. struct priv my_stuff;
  55. CURLcode res;
  56. /* set HSTS read callback */
  57. curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hsts_cb);
  58. /* pass in suitable argument to the callback */
  59. curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &my_stuff);
  60. res = curl_easy_perform(curl);
  61. }
  62. }
  63. .fi
  64. .SH AVAILABILITY
  65. Added in curl 7.74.0
  66. .SH RETURN VALUE
  67. This returns CURLE_OK.
  68. .SH SEE ALSO
  69. .BR CURLOPT_HSTS (3),
  70. .BR CURLOPT_HSTSREADDATA (3),
  71. .BR CURLOPT_HSTSWRITEFUNCTION (3),
  72. .BR CURLOPT_HSTS_CTRL (3)