curl-library
[PATCH] Added userptr (CURLOPT_FNMATCH_DATA) to curl_fnmatch_callback
From: Pavel Raiskup <pavel_at_raiskup.cz>
Date: Sat, 15 May 2010 09:30:43 +0200
Date: Sat, 15 May 2010 09:30:43 +0200
---
docs/libcurl/curl_easy_setopt.3 | 3 +++
include/curl/curl.h | 6 +++++-
lib/curl_fnmatch.c | 4 +++-
lib/curl_fnmatch.h | 2 +-
lib/ftplistparser.c | 2 +-
lib/url.c | 4 +++-
lib/urldata.h | 1 +
tests/libtest/lib577.c | 2 +-
8 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/docs/libcurl/curl_easy_setopt.3 b/docs/libcurl/curl_easy_setopt.3
index 7fa4f72..b2ca1c7 100644
--- a/docs/libcurl/curl_easy_setopt.3
+++ b/docs/libcurl/curl_easy_setopt.3
@@ -514,6 +514,9 @@ the wildcard matching feature.
Return \fICURL_FNMATCHFUNC_MATCH\fP if pattern matches the string,
\fICURL_FNMATCHFUNC_NOMATCH\fP if not or \fICURL_FNMATCHFUNC_FAIL\fP if an
error occurred. (This was added in 7.21.0)
+.IP CURLOPT_FNMATCH_DATA
+Pass a pointer that will be untouched by libcurl and passed as the ptr argument
+to the \fICURL_FNMATCH_FUNCTION\fP. (This was added in 7.21.0)
.SH ERROR OPTIONS
.IP CURLOPT_ERRORBUFFER
Pass a char * to a buffer that the libcurl may store human readable error
diff --git a/include/curl/curl.h b/include/curl/curl.h
index d59e01d..42f2d3c 100644
--- a/include/curl/curl.h
+++ b/include/curl/curl.h
@@ -285,7 +285,8 @@ typedef long (*curl_chunk_end_callback)(void *ptr);
/* callback type for wildcard downloading pattern matching. If the
string matches the pattern, return CURL_FNMATCHFUNC_MATCH value, etc. */
-typedef int (*curl_fnmatch_callback)(const char *pattern,
+typedef int (*curl_fnmatch_callback)(void *ptr,
+ const char *pattern,
const char *string);
/* These are the return codes for the seek callbacks */
@@ -1431,6 +1432,9 @@ typedef enum {
/* Let the application define custom chunk data pointer */
CINIT(CHUNK_DATA, OBJECTPOINT, 201),
+ /* FNMATCH_FUNCTION user pointer */
+ CINIT(FNMATCH_DATA, OBJECTPOINT, 202),
+
CURLOPT_LASTENTRY /* the last unused */
} CURLoption;
diff --git a/lib/curl_fnmatch.c b/lib/curl_fnmatch.c
index 9628844..a2cc6f4 100644
--- a/lib/curl_fnmatch.c
+++ b/lib/curl_fnmatch.c
@@ -401,8 +401,10 @@ static int loop(const unsigned char *pattern, const unsigned char *string)
}
}
-int Curl_fnmatch(const char *pattern, const char *string)
+int Curl_fnmatch(void *unused, const char *pattern, const char *string)
{
+ (void)unused; /* this param was added to corresponding with
+ curl_fnmatch_callback prototype */
if(!pattern || !string) {
return CURL_FNMATCH_FAIL;
}
diff --git a/lib/curl_fnmatch.h b/lib/curl_fnmatch.h
index 3ffbc45..3335e37 100644
--- a/lib/curl_fnmatch.h
+++ b/lib/curl_fnmatch.h
@@ -39,6 +39,6 @@
* keywords: alnum, digit, xdigit, alpha, print, blank, lower, graph, space
* and upper (use as "[[:alnum:]]")
*/
-int Curl_fnmatch(const char *pattern, const char *string);
+int Curl_fnmatch(void *unused, const char *pattern, const char *string);
#endif /* HEADER_CURL_FNMATCH_H */
diff --git a/lib/ftplistparser.c b/lib/ftplistparser.c
index 9d42e8f..cd9b22c 100644
--- a/lib/ftplistparser.c
+++ b/lib/ftplistparser.c
@@ -330,7 +330,7 @@ static CURLcode ftp_pl_insert_finfo(struct connectdata *conn,
compare = Curl_fnmatch;
/* filter pattern-corresponding filenames */
- if(compare(wc->pattern, finfo->filename) == 0) {
+ if(compare(conn->data->set.fnmatch_data, wc->pattern, finfo->filename) == 0) {
/* discard symlink which is containing multiple " -> " */
if((finfo->filetype == CURLFILETYPE_SYMLINK) &&
(strstr(finfo->strings.target, " -> "))) {
diff --git a/lib/url.c b/lib/url.c
index cc73750..1a9b13b 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -2478,7 +2478,9 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
case CURLOPT_CHUNK_DATA:
data->wildcard.customptr = va_arg(param, void *);
break;
-
+ case CURLOPT_FNMATCH_DATA:
+ data->set.fnmatch_data = va_arg(param, void *);
+ break;
default:
/* unknown tag and its companion, just ignore: */
result = CURLE_FAILED_INIT; /* correct this */
diff --git a/lib/urldata.h b/lib/urldata.h
index 2c1b2fc..9db0640 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1424,6 +1424,7 @@ struct UserDefined {
stopped */
curl_fnmatch_callback fnmatch; /* callback to decide which file corresponds
to pattern (e.g. if WILDCARDMATCH is on) */
+ void *fnmatch_data;
};
struct Names {
diff --git a/tests/libtest/lib577.c b/tests/libtest/lib577.c
index ac995c3..fdab361 100644
--- a/tests/libtest/lib577.c
+++ b/tests/libtest/lib577.c
@@ -231,7 +231,7 @@ int test(char *URL)
printf("===========================\n");
for(i = 0; i < testnum; i++) {
- rc = Curl_fnmatch(tests[i].pattern, tests[i].string);
+ rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
if(rc != tests[i].result) {
printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n",
tests[i].pattern, tests[i].string, tests[i].result, rc);
--
1.7.1
------------sd3ed3IV45FNBwuwx9lyUx
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
------------sd3ed3IV45FNBwuwx9lyUx--
Received on 2001-09-17