1---
2c: Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_FNMATCH_FUNCTION
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_DEBUGFUNCTION (3)
9  - CURLOPT_FNMATCH_DATA (3)
10  - CURLOPT_WILDCARDMATCH (3)
11Protocol:
12  - FTP
13Added-in: 7.21.0
14---
15
16# NAME
17
18CURLOPT_FNMATCH_FUNCTION - wildcard match callback
19
20# SYNOPSIS
21
22~~~c
23#include <curl/curl.h>
24
25int fnmatch_callback(void *ptr,
26                     const char *pattern,
27                     const char *string);
28
29CURLcode curl_easy_setopt(CURL *handle, CURLOPT_FNMATCH_FUNCTION,
30                          fnmatch_callback);
31~~~
32
33# DESCRIPTION
34
35Pass a pointer to your callback function, which should match the prototype
36shown above.
37
38This callback is used for wildcard matching.
39
40Return *CURL_FNMATCHFUNC_MATCH* if pattern matches the string,
41*CURL_FNMATCHFUNC_NOMATCH* if not or *CURL_FNMATCHFUNC_FAIL* if an
42error occurred.
43
44# DEFAULT
45
46NULL == an internal function for wildcard matching.
47
48# %PROTOCOLS%
49
50# EXAMPLE
51
52~~~c
53extern int string_match(const char *s1, const char *s2);
54
55struct local_stuff {
56  void *custom;
57};
58static 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
69int 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
87Returns CURLE_OK if the option is supported, and CURLE_UNKNOWN_OPTION if not.
88