diff options
author | Martin Willi <martin@revosec.ch> | 2014-08-28 11:11:12 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-09-24 11:35:59 +0200 |
commit | d717b42b51efa3c4ad201aa739b46b76c6173321 (patch) | |
tree | 300c473dc4a04696f8ab865f358d924037c90108 | |
parent | 6eaec1e349922974fcc82c697a505feb93f23714 (diff) | |
download | strongswan-d717b42b51efa3c4ad201aa739b46b76c6173321.tar.bz2 strongswan-d717b42b51efa3c4ad201aa739b46b76c6173321.tar.xz |
curl: Dynamically query supported protocols and register appropriate features
-rw-r--r-- | src/libstrongswan/plugins/curl/curl_plugin.c | 74 |
1 files changed, 64 insertions, 10 deletions
diff --git a/src/libstrongswan/plugins/curl/curl_plugin.c b/src/libstrongswan/plugins/curl/curl_plugin.c index ab63a50cc..30bc5a634 100644 --- a/src/libstrongswan/plugins/curl/curl_plugin.c +++ b/src/libstrongswan/plugins/curl/curl_plugin.c @@ -32,8 +32,61 @@ struct private_curl_plugin_t { * public functions */ curl_plugin_t public; + + /** + * Supported features, CURL protocols + 1 + */ + plugin_feature_t *features; + + /** + * Number of supported features + */ + int count; }; +/** + * Append a feature to supported feature list + */ +static void add_feature(private_curl_plugin_t *this, plugin_feature_t f) +{ + this->features = realloc(this->features, ++this->count * sizeof(f)); + this->features[this->count - 1] = f; +} + +/** + * Get supported protocols, build plugin feature set + */ +static bool query_protocols(private_curl_plugin_t *this) +{ + static char *protos[] = { + /* protocols we are interested in, suffixed with "://" */ + "file://", "http://", "https://", "ftp://", + }; + curl_version_info_data *info; + int i, j; + + add_feature(this, PLUGIN_REGISTER(FETCHER, curl_fetcher_create)); + + info = curl_version_info(CURLVERSION_NOW); + + for (i = 0; info->protocols[i]; i++) + { + for (j = 0; j < countof(protos); j++) + { + if (strlen(info->protocols[i]) == strlen(protos[j]) - strlen("://")) + { + if (strneq(info->protocols[i], protos[j], + strlen(protos[j]) - strlen("://"))) + { + add_feature(this, PLUGIN_PROVIDE(FETCHER, protos[j])); + } + } + } + } + + return this->count > 1; +} + METHOD(plugin_t, get_name, char*, private_curl_plugin_t *this) { @@ -43,21 +96,15 @@ METHOD(plugin_t, get_name, char*, METHOD(plugin_t, get_features, int, private_curl_plugin_t *this, plugin_feature_t *features[]) { - static plugin_feature_t f[] = { - PLUGIN_REGISTER(FETCHER, curl_fetcher_create), - PLUGIN_PROVIDE(FETCHER, "file://"), - PLUGIN_PROVIDE(FETCHER, "http://"), - PLUGIN_PROVIDE(FETCHER, "https://"), - PLUGIN_PROVIDE(FETCHER, "ftp://"), - }; - *features = f; - return countof(f); + *features = this->features; + return this->count; } METHOD(plugin_t, destroy, void, private_curl_plugin_t *this) { curl_global_cleanup(); + free(this->features); free(this); } @@ -92,6 +139,13 @@ plugin_t *curl_plugin_create() destroy(this); return NULL; } + + if (!query_protocols(this)) + { + DBG1(DBG_LIB, "no usable CURL protocols found, curl disabled"); + destroy(this); + return NULL; + } + return &this->public.plugin; } - |