CURLOPT_FNMATCH_FUNCTION.md (2007B)
1 --- 2 c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 3 SPDX-License-Identifier: curl 4 Title: CURLOPT_FNMATCH_FUNCTION 5 Section: 3 6 Source: libcurl 7 See-also: 8 - CURLOPT_DEBUGFUNCTION (3) 9 - CURLOPT_FNMATCH_DATA (3) 10 - CURLOPT_WILDCARDMATCH (3) 11 Protocol: 12 - FTP 13 Added-in: 7.21.0 14 --- 15 16 # NAME 17 18 CURLOPT_FNMATCH_FUNCTION - wildcard match callback 19 20 # SYNOPSIS 21 22 ~~~c 23 #include <curl/curl.h> 24 25 int fnmatch_callback(void *ptr, 26 const char *pattern, 27 const char *string); 28 29 CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FNMATCH_FUNCTION, 30 fnmatch_callback); 31 ~~~ 32 33 # DESCRIPTION 34 35 Pass a pointer to your callback function, which should match the prototype 36 shown above. 37 38 This callback is used for wildcard matching. 39 40 Return *CURL_FNMATCHFUNC_MATCH* if pattern matches the string, 41 *CURL_FNMATCHFUNC_NOMATCH* if not or *CURL_FNMATCHFUNC_FAIL* if an 42 error occurred. 43 44 # DEFAULT 45 46 NULL == an internal function for wildcard matching. 47 48 # %PROTOCOLS% 49 50 # EXAMPLE 51 52 ~~~c 53 extern int string_match(const char *s1, const char *s2); 54 55 struct local_stuff { 56 void *custom; 57 }; 58 static int my_fnmatch(void *clientp, 59 const char *pattern, const char *string) 60 { 61 struct local_stuff *data = clientp; 62 printf("my pointer: %p\n", data->custom); 63 if(string_match(pattern, string)) 64 return CURL_FNMATCHFUNC_MATCH; 65 else 66 return CURL_FNMATCHFUNC_NOMATCH; 67 } 68 69 int main(void) 70 { 71 struct local_stuff local_data; 72 CURL *curl = curl_easy_init(); 73 if(curl) { 74 curl_easy_setopt(curl, CURLOPT_URL, "ftp://ftp.example.com/file*"); 75 curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L); 76 curl_easy_setopt(curl, CURLOPT_FNMATCH_FUNCTION, my_fnmatch); 77 curl_easy_setopt(curl, CURLOPT_FNMATCH_DATA, &local_data); 78 curl_easy_perform(curl); 79 } 80 } 81 ~~~ 82 83 # %AVAILABILITY% 84 85 # RETURN VALUE 86 87 curl_easy_setopt(3) returns a CURLcode indicating success or error. 88 89 CURLE_OK (0) means everything was OK, non-zero means an error occurred, see 90 libcurl-errors(3).