Sun, 27 Oct 2024 16:08:28 +0100
move ssl version parser to new function
libidav/config.c | file | annotate | diff | comparison | revisions | |
libidav/config.h | file | annotate | diff | comparison | revisions |
--- a/libidav/config.c Sun Oct 27 15:39:23 2024 +0100 +++ b/libidav/config.c Sun Oct 27 16:08:28 2024 +0100 @@ -336,30 +336,12 @@ dav_cfg_bool_set_node_value(config, &repo->verification, node); } else if(xstreq(key, "ssl-version")) { repo->ssl_version.node = node; - if(xstrEQ(value, "TLSv1")) { - repo->ssl_version.value = CURL_SSLVERSION_TLSv1; - } else if(xstrEQ(value, "SSLv2")) { - repo->ssl_version.value = CURL_SSLVERSION_SSLv2; - } else if(xstrEQ(value, "SSLv3")) { - repo->ssl_version.value = CURL_SSLVERSION_SSLv3; - } -#if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7034 - else if(xstrEQ(value, "TLSv1.0")) { - repo->ssl_version.value = CURL_SSLVERSION_TLSv1_0; - } else if(xstrEQ(value, "TLSv1.1")) { - repo->ssl_version.value = CURL_SSLVERSION_TLSv1_1; - } else if(xstrEQ(value, "TLSv1.2")) { - repo->ssl_version.value = CURL_SSLVERSION_TLSv1_2; - } -#endif -#if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7052 - else if(xstrEQ(value, "TLSv1.3")) { - repo->ssl_version.value = CURL_SSLVERSION_TLSv1_3; - } -#endif - else { + int ssl_version = dav_str2ssl_version((const char*)value); + if(ssl_version == -1) { print_warning(lineno, "unknown ssl version: %s\n", value); repo->ssl_version.value = CURL_SSLVERSION_DEFAULT; + } else { + repo->ssl_version.value = ssl_version; } } else if(xstreq(key, "authmethods")) { repo->authmethods.node = node; @@ -394,6 +376,31 @@ return 0; } +int dav_str2ssl_version(const char *value) { + if(xstrEQ(value, "TLSv1")) { + return CURL_SSLVERSION_TLSv1; + } else if(xstrEQ(value, "SSLv2")) { + return CURL_SSLVERSION_SSLv2; + } else if(xstrEQ(value, "SSLv3")) { + return CURL_SSLVERSION_SSLv3; + } +#if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7034 + else if(xstrEQ(value, "TLSv1.0")) { + return CURL_SSLVERSION_TLSv1_0; + } else if(xstrEQ(value, "TLSv1.1")) { + return CURL_SSLVERSION_TLSv1_1; + } else if(xstrEQ(value, "TLSv1.2")) { + return CURL_SSLVERSION_TLSv1_2; + } +#endif +#if LIBCURL_VERSION_MAJOR * 1000 + LIBCURL_VERSION_MINOR >= 7052 + else if(xstrEQ(value, "TLSv1.3")) { + return CURL_SSLVERSION_TLSv1_3; + } +#endif + return -1; +} + static int load_repository( DavConfig *config, DavCfgRepository **list_begin,
--- a/libidav/config.h Sun Oct 27 15:39:23 2024 +0100 +++ b/libidav/config.h Sun Oct 27 16:08:28 2024 +0100 @@ -178,6 +178,8 @@ void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password); cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo); +int dav_str2ssl_version(const char *str); + int dav_cfg_string_set_node_value(DavConfig *config, CfgString *str, xmlNode *node); void dav_cfg_bool_set_node_value(DavConfig *config, CfgBool *cbool, xmlNode *node);