cURL / Mailing Lists / curl-users / Single Mail


advice for building test suite with libcurl

From: Raphael Bauduin <>
Date: Wed, 28 Jan 2015 11:28:11 +0100


I'm building a small network test suite using libcurl. The code for every
test is quite similar, all setting multiple CURLOPT_*,
possibly with different options set to different values for each test.
Due to the similarity of the code structure, I thought about defining the
tests in a config file (currently testing with libconfig).
This would enable me to have one code performing all tests, and also replace

     curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8080"
     curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
     curl_easy_setopt(curl, CURLOPT_HEADER, 1L );

with something like this pseudo code to be translated in C:

for (i=0; i<options.length; i++) {
   curl_easy_setopt(curl, get_symbol_value_from_name(options[i].name),

And my question is how do you advise me to solve the translation from a
string to its symbol value,
eg from "CURLOPT_URL" to CURLOPT_URL ( get_symbol_value_from_name in the
pseudo code)?

One possibility is defining a mapping from the string to the symbol,
possibly with the help of a macro:

struct mapping {
char name;
int code;
char type;
mapping arr[] = {
#define add_mapping(tab,code,type) tab[(code)] = {#code, code, type}

Is this the way to go? Is there a way to define a mapping for all curl
options? Or is there something in libcurl's code that can help me?

Thanks in advance for your feedback!


List admin:
Received on 2015-01-28