1*6236dae4SAndroid Build Coastguard Worker--- 2*6236dae4SAndroid Build Coastguard Workerc: Copyright (C) Daniel Stenberg, <[email protected]>, et al. 3*6236dae4SAndroid Build Coastguard WorkerSPDX-License-Identifier: curl 4*6236dae4SAndroid Build Coastguard WorkerTitle: CURLOPT_HSTSREADFUNCTION 5*6236dae4SAndroid Build Coastguard WorkerSection: 3 6*6236dae4SAndroid Build Coastguard WorkerSource: libcurl 7*6236dae4SAndroid Build Coastguard WorkerProtocol: 8*6236dae4SAndroid Build Coastguard Worker - HTTP 9*6236dae4SAndroid Build Coastguard WorkerSee-also: 10*6236dae4SAndroid Build Coastguard Worker - CURLOPT_HSTS (3) 11*6236dae4SAndroid Build Coastguard Worker - CURLOPT_HSTSREADDATA (3) 12*6236dae4SAndroid Build Coastguard Worker - CURLOPT_HSTSWRITEFUNCTION (3) 13*6236dae4SAndroid Build Coastguard Worker - CURLOPT_HSTS_CTRL (3) 14*6236dae4SAndroid Build Coastguard WorkerAdded-in: 7.74.0 15*6236dae4SAndroid Build Coastguard Worker--- 16*6236dae4SAndroid Build Coastguard Worker 17*6236dae4SAndroid Build Coastguard Worker# NAME 18*6236dae4SAndroid Build Coastguard Worker 19*6236dae4SAndroid Build Coastguard WorkerCURLOPT_HSTSREADFUNCTION - read callback for HSTS hosts 20*6236dae4SAndroid Build Coastguard Worker 21*6236dae4SAndroid Build Coastguard Worker# SYNOPSIS 22*6236dae4SAndroid Build Coastguard Worker 23*6236dae4SAndroid Build Coastguard Worker~~~c 24*6236dae4SAndroid Build Coastguard Worker#include <curl/curl.h> 25*6236dae4SAndroid Build Coastguard Worker 26*6236dae4SAndroid Build Coastguard Workerstruct curl_hstsentry { 27*6236dae4SAndroid Build Coastguard Worker char *name; 28*6236dae4SAndroid Build Coastguard Worker size_t namelen; 29*6236dae4SAndroid Build Coastguard Worker unsigned int includeSubDomains:1; 30*6236dae4SAndroid Build Coastguard Worker char expire[18]; /* YYYYMMDD HH:MM:SS [null-terminated] */ 31*6236dae4SAndroid Build Coastguard Worker}; 32*6236dae4SAndroid Build Coastguard Worker 33*6236dae4SAndroid Build Coastguard WorkerCURLSTScode hstsread(CURL *easy, struct curl_hstsentry *sts, void *clientp); 34*6236dae4SAndroid Build Coastguard Worker 35*6236dae4SAndroid Build Coastguard WorkerCURLcode curl_easy_setopt(CURL *handle, CURLOPT_HSTSREADFUNCTION, hstsread); 36*6236dae4SAndroid Build Coastguard Worker~~~ 37*6236dae4SAndroid Build Coastguard Worker 38*6236dae4SAndroid Build Coastguard Worker# DESCRIPTION 39*6236dae4SAndroid Build Coastguard Worker 40*6236dae4SAndroid Build Coastguard WorkerPass a pointer to your callback function, as the prototype shows above. 41*6236dae4SAndroid Build Coastguard Worker 42*6236dae4SAndroid Build Coastguard WorkerThis callback function gets called by libcurl repeatedly when it populates the 43*6236dae4SAndroid Build Coastguard Workerin-memory HSTS cache. 44*6236dae4SAndroid Build Coastguard Worker 45*6236dae4SAndroid Build Coastguard WorkerSet the *clientp* argument with the CURLOPT_HSTSREADDATA(3) option 46*6236dae4SAndroid Build Coastguard Workeror it is NULL. 47*6236dae4SAndroid Build Coastguard Worker 48*6236dae4SAndroid Build Coastguard WorkerWhen this callback is invoked, the *sts* pointer points to a populated 49*6236dae4SAndroid Build Coastguard Workerstruct: Copy the hostname to *name* (no longer than *namelen* 50*6236dae4SAndroid Build Coastguard Workerbytes). Make it null-terminated. Set *includeSubDomains* to TRUE or 51*6236dae4SAndroid Build Coastguard WorkerFALSE. Set *expire* to a date stamp or a zero length string for *forever* 52*6236dae4SAndroid Build Coastguard Worker(wrong date stamp format might cause the name to not get accepted) 53*6236dae4SAndroid Build Coastguard Worker 54*6236dae4SAndroid Build Coastguard WorkerThe callback should return *CURLSTS_OK* if it returns a name and is 55*6236dae4SAndroid Build Coastguard Workerprepared to be called again (for another host) or *CURLSTS_DONE* if it has 56*6236dae4SAndroid Build Coastguard Workerno entry to return. It can also return *CURLSTS_FAIL* to signal 57*6236dae4SAndroid Build Coastguard Workererror. Returning *CURLSTS_FAIL* stops the transfer from being performed 58*6236dae4SAndroid Build Coastguard Workerand make *CURLE_ABORTED_BY_CALLBACK* get returned. 59*6236dae4SAndroid Build Coastguard Worker 60*6236dae4SAndroid Build Coastguard WorkerThis option does not enable HSTS, you need to use CURLOPT_HSTS_CTRL(3) to 61*6236dae4SAndroid Build Coastguard Workerdo that. 62*6236dae4SAndroid Build Coastguard Worker 63*6236dae4SAndroid Build Coastguard Worker# DEFAULT 64*6236dae4SAndroid Build Coastguard Worker 65*6236dae4SAndroid Build Coastguard WorkerNULL - no callback. 66*6236dae4SAndroid Build Coastguard Worker 67*6236dae4SAndroid Build Coastguard Worker# %PROTOCOLS% 68*6236dae4SAndroid Build Coastguard Worker 69*6236dae4SAndroid Build Coastguard Worker# EXAMPLE 70*6236dae4SAndroid Build Coastguard Worker 71*6236dae4SAndroid Build Coastguard Worker~~~c 72*6236dae4SAndroid Build Coastguard Workerstruct priv { 73*6236dae4SAndroid Build Coastguard Worker void *custom; 74*6236dae4SAndroid Build Coastguard Worker}; 75*6236dae4SAndroid Build Coastguard Worker 76*6236dae4SAndroid Build Coastguard Workerstatic CURLSTScode hsts_cb(CURL *easy, struct curl_hstsentry *sts, 77*6236dae4SAndroid Build Coastguard Worker void *clientp) 78*6236dae4SAndroid Build Coastguard Worker{ 79*6236dae4SAndroid Build Coastguard Worker /* populate the struct as documented */ 80*6236dae4SAndroid Build Coastguard Worker return CURLSTS_OK; 81*6236dae4SAndroid Build Coastguard Worker} 82*6236dae4SAndroid Build Coastguard Worker 83*6236dae4SAndroid Build Coastguard Workerint main(void) 84*6236dae4SAndroid Build Coastguard Worker{ 85*6236dae4SAndroid Build Coastguard Worker CURL *curl = curl_easy_init(); 86*6236dae4SAndroid Build Coastguard Worker if(curl) { 87*6236dae4SAndroid Build Coastguard Worker struct priv my_stuff; 88*6236dae4SAndroid Build Coastguard Worker CURLcode res; 89*6236dae4SAndroid Build Coastguard Worker 90*6236dae4SAndroid Build Coastguard Worker /* set HSTS read callback */ 91*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_HSTSREADFUNCTION, hsts_cb); 92*6236dae4SAndroid Build Coastguard Worker 93*6236dae4SAndroid Build Coastguard Worker /* pass in suitable argument to the callback */ 94*6236dae4SAndroid Build Coastguard Worker curl_easy_setopt(curl, CURLOPT_HSTSREADDATA, &my_stuff); 95*6236dae4SAndroid Build Coastguard Worker 96*6236dae4SAndroid Build Coastguard Worker res = curl_easy_perform(curl); 97*6236dae4SAndroid Build Coastguard Worker } 98*6236dae4SAndroid Build Coastguard Worker} 99*6236dae4SAndroid Build Coastguard Worker~~~ 100*6236dae4SAndroid Build Coastguard Worker 101*6236dae4SAndroid Build Coastguard Worker# %AVAILABILITY% 102*6236dae4SAndroid Build Coastguard Worker 103*6236dae4SAndroid Build Coastguard Worker# RETURN VALUE 104*6236dae4SAndroid Build Coastguard Worker 105*6236dae4SAndroid Build Coastguard WorkerThis returns CURLE_OK. 106