cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Welcome to the "curl-library" mailing list

From: Aaron Meriwether <me_at_ameriwether.com>
Date: Thu, 13 Aug 2015 11:19:34 -0600

> On Aug 13, 2015, at 10:20 AM, Elia Pinto <gitter.spiros_at_gmail.com> wrote:
> For the C standard is not possible to use #if or #ifdef with an enum
> like CURL_SSLVERSION_SSLv2. The code compile but it is borken (the
> compiler skip the #ifdef with the CURL_SSLVERSION_xxx)

Sorry, you're right, the #if silently fails because CURL_SSLVERSION_xxx is an enum not a #define symbol.
Unfortunately, I can't think of a way to do this that doesn't feel a bit hackish, but the following does work:

#include <curl/curl.h>

// These may not exist in some versions of the enum.
#define CURL_SSLVERSION_TLSv1_0 (CURL_SSLVERSION_SSLv3 + 1)
#define CURL_SSLVERSION_TLSv1_1 (CURL_SSLVERSION_SSLv3 + 2)
#define CURL_SSLVERSION_TLSv1_2 (CURL_SSLVERSION_SSLv3 + 3)
static struct {
   const char * name;
   long ssl_version;
} Sslversions [] = {
   {"SSLv2", CURL_SSLVERSION_SSLv2},
   {"SSLv3", CURL_SSLVERSION_SSLv3},
   {"TLSv1", CURL_SSLVERSION_TLSv1},
   {CURL_SSLVERSION_TLSv1_0<CURL_SSLVERSION_LAST?"Tlsv1.0":NULL, CURL_SSLVERSION_TLSv1_0},
   {CURL_SSLVERSION_TLSv1_1<CURL_SSLVERSION_LAST?"Tlsv1.1":NULL, CURL_SSLVERSION_TLSv1_1},
   {CURL_SSLVERSION_TLSv1_2<CURL_SSLVERSION_LAST?"Tlsv1.2":NULL, CURL_SSLVERSION_TLSv1_2},
   {NULL}
};

int main(void) {
   int i;
   for(i = 0; Sslversions[i].name; i++) {
      printf("Name: %s, Const: %d\n", Sslversions[i].name, Sslversions[i].ssl_version);
   }
}
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-08-13