Skip to content

Commit

Permalink
options: API for meta-data about easy options
Browse files Browse the repository at this point in the history
 const struct curl_easyoption *curl_easy_option_by_name(const char *name);

 const struct curl_easyoption *curl_easy_option_by_id (CURLoption id);

 const struct curl_easyoption *
 curl_easy_option_next(const struct curl_easyoption *prev);

The purpose is to provide detailed enough information to allow for
example libcurl bindings to get option information at run-time about
what easy options that exist and what arguments they expect.

THIS IS WORK IN PROGRESS, MEANT AS A DISCUSSION STARTING POINT. Not the
final version.
  • Loading branch information
bagder committed May 11, 2020
1 parent 4b88ac7 commit 2e4847f
Show file tree
Hide file tree
Showing 9 changed files with 890 additions and 24 deletions.
4 changes: 2 additions & 2 deletions include/curl/Makefile.am
Expand Up @@ -5,7 +5,7 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
# Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
Expand All @@ -21,7 +21,7 @@
###########################################################################
pkginclude_HEADERS = \
curl.h curlver.h easy.h mprintf.h stdcheaders.h multi.h \
typecheck-gcc.h system.h urlapi.h
typecheck-gcc.h system.h urlapi.h options.h

pkgincludedir= $(includedir)/curl

Expand Down
48 changes: 28 additions & 20 deletions include/curl/curl.h
Expand Up @@ -957,10 +957,17 @@ typedef enum {

#define CURLOPT(na,t,nu) na = t + nu

/* handy aliases that make no run-time difference */
#define CURLOPTTYPE_STRINGPOINT CURLOPTTYPE_OBJECTPOINT
/* CURLOPT aliases that make no run-time difference */

/* 'char *' arguments to a string with a trailing zero */
#define CURLOPTTYPE_STRINGPOINT CURLOPTTYPE_OBJECTPOINT

/* 'struct curl_slist *' arguments */
#define CURLOPTTYPE_SLISTPOINT CURLOPTTYPE_OBJECTPOINT

/* 'long' argument with a set of values/bitmask */
#define CURLOPTTYPE_VALUES CURLOPTTYPE_LONG

/*
* All CURLOPT_* values.
*/
Expand Down Expand Up @@ -1083,10 +1090,10 @@ typedef enum {

/* What version to specifically try to use.
See CURL_SSLVERSION defines below. */
CURLOPT(CURLOPT_SSLVERSION, CURLOPTTYPE_LONG, 32),
CURLOPT(CURLOPT_SSLVERSION, CURLOPTTYPE_VALUES, 32),

/* What kind of HTTP time condition to use, see defines */
CURLOPT(CURLOPT_TIMECONDITION, CURLOPTTYPE_LONG, 33),
CURLOPT(CURLOPT_TIMECONDITION, CURLOPTTYPE_VALUES, 33),

/* Time to use with the above condition. Specified in number of seconds
since 1 Jan 1970 */
Expand Down Expand Up @@ -1140,7 +1147,7 @@ typedef enum {

/* Specify whether to read the user+password from the .netrc or the URL.
* This must be one of the CURL_NETRC_* enums below. */
CURLOPT(CURLOPT_NETRC, CURLOPTTYPE_LONG, 51),
CURLOPT(CURLOPT_NETRC, CURLOPTTYPE_VALUES, 51),

/* use Location: Luke! */
CURLOPT(CURLOPT_FOLLOWLOCATION, CURLOPTTYPE_LONG, 52),
Expand Down Expand Up @@ -1257,7 +1264,7 @@ typedef enum {

/* Specify which HTTP version to use! This must be set to one of the
CURL_HTTP_VERSION* enums set below. */
CURLOPT(CURLOPT_HTTP_VERSION, CURLOPTTYPE_LONG, 84),
CURLOPT(CURLOPT_HTTP_VERSION, CURLOPTTYPE_VALUES, 84),

/* Specifically switch on or off the FTP engine's use of the EPSV command. By
default, that one will always be attempted before the more traditional
Expand Down Expand Up @@ -1318,7 +1325,7 @@ typedef enum {
/* indicates type of proxy. accepted values are CURLPROXY_HTTP (default),
CURLPROXY_HTTPS, CURLPROXY_SOCKS4, CURLPROXY_SOCKS4A and
CURLPROXY_SOCKS5. */
CURLOPT(CURLOPT_PROXYTYPE, CURLOPTTYPE_LONG, 101),
CURLOPT(CURLOPT_PROXYTYPE, CURLOPTTYPE_VALUES, 101),

/* Set the Accept-Encoding string. Use this to tell a server you would like
the response to be compressed. Before 7.21.6, this was known as
Expand All @@ -1344,7 +1351,7 @@ typedef enum {
/* Set this to a bitmask value to enable the particular authentications
methods you like. Use this in combination with CURLOPT_USERPWD.
Note that setting multiple bits may cause extra network round-trips. */
CURLOPT(CURLOPT_HTTPAUTH, CURLOPTTYPE_LONG, 107),
CURLOPT(CURLOPT_HTTPAUTH, CURLOPTTYPE_VALUES, 107),

/* Set the ssl context callback function, currently only for OpenSSL or
WolfSSL ssl_ctx, or mbedTLS mbedtls_ssl_config in the second argument.
Expand All @@ -1364,7 +1371,7 @@ typedef enum {
/* Set this to a bitmask value to enable the particular authentications
methods you like. Use this in combination with CURLOPT_PROXYUSERPWD.
Note that setting multiple bits may cause extra network round-trips. */
CURLOPT(CURLOPT_PROXYAUTH, CURLOPTTYPE_LONG, 111),
CURLOPT(CURLOPT_PROXYAUTH, CURLOPTTYPE_VALUES, 111),

/* FTP option that changes the timeout, in seconds, associated with
getting a response. This is different from transfer timeout time and
Expand All @@ -1376,7 +1383,7 @@ typedef enum {
/* Set this option to one of the CURL_IPRESOLVE_* defines (see below) to
tell libcurl to resolve names to those IP versions only. This only has
affect on systems with support for more than one, i.e IPv4 _and_ IPv6. */
CURLOPT(CURLOPT_IPRESOLVE, CURLOPTTYPE_LONG, 113),
CURLOPT(CURLOPT_IPRESOLVE, CURLOPTTYPE_VALUES, 113),

/* Set this option to limit the size of a file that will be downloaded from
an HTTP or FTP server.
Expand Down Expand Up @@ -1411,7 +1418,7 @@ typedef enum {
CURLUSESSL_CONTROL - SSL for the control connection or fail
CURLUSESSL_ALL - SSL for all communication or fail
*/
CURLOPT(CURLOPT_USE_SSL, CURLOPTTYPE_LONG, 119),
CURLOPT(CURLOPT_USE_SSL, CURLOPTTYPE_VALUES, 119),

/* The _LARGE version of the standard POSTFIELDSIZE option */
CURLOPT(CURLOPT_POSTFIELDSIZE_LARGE, CURLOPTTYPE_OFF_T, 120),
Expand All @@ -1437,7 +1444,7 @@ typedef enum {
CURLFTPAUTH_SSL - try "AUTH SSL" first, then TLS
CURLFTPAUTH_TLS - try "AUTH TLS" first, then SSL
*/
CURLOPT(CURLOPT_FTPSSLAUTH, CURLOPTTYPE_LONG, 129),
CURLOPT(CURLOPT_FTPSSLAUTH, CURLOPTTYPE_VALUES, 129),

CURLOPT(CURLOPT_IOCTLFUNCTION, CURLOPTTYPE_FUNCTIONPOINT, 130),
CURLOPT(CURLOPT_IOCTLDATA, CURLOPTTYPE_OBJECTPOINT, 131),
Expand All @@ -1463,7 +1470,7 @@ typedef enum {

/* Select "file method" to use when doing FTP, see the curl_ftpmethod
above. */
CURLOPT(CURLOPT_FTP_FILEMETHOD, CURLOPTTYPE_LONG, 138),
CURLOPT(CURLOPT_FTP_FILEMETHOD, CURLOPTTYPE_VALUES, 138),

/* Local port number to bind the socket to */
CURLOPT(CURLOPT_LOCALPORT, CURLOPTTYPE_LONG, 139),
Expand Down Expand Up @@ -1507,7 +1514,7 @@ typedef enum {
CURLOPT(CURLOPT_SSL_SESSIONID_CACHE, CURLOPTTYPE_LONG, 150),

/* allowed SSH authentication methods */
CURLOPT(CURLOPT_SSH_AUTH_TYPES, CURLOPTTYPE_LONG, 151),
CURLOPT(CURLOPT_SSH_AUTH_TYPES, CURLOPTTYPE_VALUES, 151),

/* Used by scp/sftp to do public/private key authentication */
CURLOPT(CURLOPT_SSH_PUBLIC_KEYFILE, CURLOPTTYPE_STRINGPOINT, 152),
Expand All @@ -1532,7 +1539,7 @@ typedef enum {

/* Set the behaviour of POST when redirecting. Values must be set to one
of CURL_REDIR* defines below. This used to be called CURLOPT_POST301 */
CURLOPT(CURLOPT_POSTREDIR, CURLOPTTYPE_LONG, 161),
CURLOPT(CURLOPT_POSTREDIR, CURLOPTTYPE_VALUES, 161),

/* used by scp/sftp to verify the host's public key */
CURLOPT(CURLOPT_SSH_HOST_PUBLIC_KEY_MD5, CURLOPTTYPE_STRINGPOINT, 162),
Expand Down Expand Up @@ -1625,7 +1632,7 @@ typedef enum {
CURLOPT(CURLOPT_FTP_USE_PRET, CURLOPTTYPE_LONG, 188),

/* RTSP request method (OPTIONS, SETUP, PLAY, etc...) */
CURLOPT(CURLOPT_RTSP_REQUEST, CURLOPTTYPE_LONG, 189),
CURLOPT(CURLOPT_RTSP_REQUEST, CURLOPTTYPE_VALUES, 189),

/* The RTSP session identifier */
CURLOPT(CURLOPT_RTSP_SESSION_ID, CURLOPTTYPE_STRINGPOINT, 190),
Expand Down Expand Up @@ -1698,7 +1705,7 @@ typedef enum {
CURLOPT(CURLOPT_CLOSESOCKETDATA, CURLOPTTYPE_OBJECTPOINT, 209),

/* allow GSSAPI credential delegation */
CURLOPT(CURLOPT_GSSAPI_DELEGATION, CURLOPTTYPE_LONG, 210),
CURLOPT(CURLOPT_GSSAPI_DELEGATION, CURLOPTTYPE_VALUES, 210),

/* Set the name servers to use for DNS resolution */
CURLOPT(CURLOPT_DNS_SERVERS, CURLOPTTYPE_STRINGPOINT, 211),
Expand All @@ -1715,7 +1722,7 @@ typedef enum {
CURLOPT(CURLOPT_TCP_KEEPINTVL, CURLOPTTYPE_LONG, 215),

/* Enable/disable specific SSL features with a bitmask, see CURLSSLOPT_* */
CURLOPT(CURLOPT_SSL_OPTIONS, CURLOPTTYPE_LONG, 216),
CURLOPT(CURLOPT_SSL_OPTIONS, CURLOPTTYPE_VALUES, 216),

/* Set the SMTP auth originator */
CURLOPT(CURLOPT_MAIL_AUTH, CURLOPTTYPE_STRINGPOINT, 217),
Expand Down Expand Up @@ -1762,7 +1769,7 @@ typedef enum {
CURLOPT(CURLOPT_PROXYHEADER, CURLOPTTYPE_SLISTPOINT, 228),

/* Pass in a bitmask of "header options" */
CURLOPT(CURLOPT_HEADEROPT, CURLOPTTYPE_LONG, 229),
CURLOPT(CURLOPT_HEADEROPT, CURLOPTTYPE_VALUES, 229),

/* The public key in DER form used to validate the peer public key
this option is used only if SSL_VERIFYPEER is true */
Expand Down Expand Up @@ -1834,7 +1841,7 @@ typedef enum {

/* What version to specifically try to use for proxy.
See CURL_SSLVERSION defines below. */
CURLOPT(CURLOPT_PROXY_SSLVERSION, CURLOPTTYPE_LONG, 250),
CURLOPT(CURLOPT_PROXY_SSLVERSION, CURLOPTTYPE_VALUES, 250),

/* Set a username for authenticated TLS for proxy */
CURLOPT(CURLOPT_PROXY_TLSAUTH_USERNAME, CURLOPTTYPE_STRINGPOINT, 251),
Expand Down Expand Up @@ -2884,6 +2891,7 @@ CURL_EXTERN CURLcode curl_easy_pause(CURL *handle, int bitmask);
#include "easy.h" /* nothing in curl is fun without the easy stuff */
#include "multi.h"
#include "urlapi.h"
#include "options.h"

/* the typechecker doesn't work in C++ (yet) */
#if defined(__GNUC__) && defined(__GNUC_MINOR__) && \
Expand Down
54 changes: 54 additions & 0 deletions include/curl/options.h
@@ -0,0 +1,54 @@
#ifndef CURLINC_OPTIONS_H
#define CURLINC_OPTIONS_H
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2018 - 2020, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
CURLOT_LONG, /* long (a range of values) */
CURLOT_VALUES, /* long (a defined set or bitmask) */
CURLOT_OFF_T, /* curl_off_t */
CURLOT_OBJECT, /* void * */
CURLOT_STRING, /* char * */
CURLOT_SLIST, /* struct curl_slist * */
CURLOT_FUNCTION /* function pointer */
} curl_easytype;

struct curl_easyoption {
const char *name;
CURLoption id;
curl_easytype type;
};

const struct curl_easyoption *curl_easy_option_by_name(const char *name);
const struct curl_easyoption *curl_easy_option_by_id (CURLoption id);
const struct curl_easyoption *
curl_easy_option_next(const struct curl_easyoption *prev);

#ifdef __cplusplus
} /* end of extern "C" */
#endif
#endif /* CURLINC_OPTIONS_H */

3 changes: 3 additions & 0 deletions lib/Makefile.am
Expand Up @@ -153,3 +153,6 @@ TIDY:=clang-tidy

tidy:
$(TIDY) $(CSOURCES) $(TIDYFLAGS) -- $(AM_CPPFLAGS) $(CPPFLAGS) -DHAVE_CONFIG_H

optiontable:
perl optiontable.pl < $(top_srcdir)/include/curl/curl.h > easyoptions.c
5 changes: 3 additions & 2 deletions lib/Makefile.inc
Expand Up @@ -60,7 +60,8 @@ LIB_CFILES = altsvc.c amigaos.c asyn-ares.c asyn-thread.c base64.c \
sendf.c setopt.c sha256.c share.c slist.c smb.c smtp.c socketpair.c socks.c \
socks_gssapi.c socks_sspi.c speedcheck.c splay.c strcase.c strdup.c \
strerror.c strtok.c strtoofft.c system_win32.c telnet.c tftp.c timeval.c \
transfer.c urlapi.c version.c warnless.c wildcard.c x509asn1.c dynbuf.c
transfer.c urlapi.c version.c warnless.c wildcard.c x509asn1.c dynbuf.c \
easyoptions.c easygetopt.c

LIB_HFILES = altsvc.h amigaos.h arpa_telnet.h asyn.h conncache.h connect.h \
content_encoding.h cookie.h curl_addrinfo.h curl_base64.h curl_ctype.h \
Expand All @@ -79,7 +80,7 @@ LIB_HFILES = altsvc.h amigaos.h arpa_telnet.h asyn.h conncache.h connect.h \
smb.h smtp.h sockaddr.h socketpair.h socks.h speedcheck.h splay.h strcase.h \
strdup.h strerror.h strtok.h strtoofft.h system_win32.h telnet.h tftp.h \
timeval.h transfer.h urlapi-int.h urldata.h warnless.h wildcard.h \
x509asn1.h dynbuf.h
x509asn1.h dynbuf.h easyoptions.h

LIB_RCFILES = libcurl.rc

Expand Down
70 changes: 70 additions & 0 deletions lib/easygetopt.c
@@ -0,0 +1,70 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ | |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* ___|___/|_| ______|
*
* Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/

#include "curl_setup.h"
#include "strcase.h"
#include "easyoptions.h"

/* Lookups easy options at runtime */
static struct curl_easyoption *lookup(const char *name, CURLoption id)
{
DEBUGASSERT(name || id);
if(name || id) {
struct curl_easyoption *o = &Curl_easyopts[0];
do {
if(name) {
if(strcasecompare(o->name, name))
return o;
}
else {
if(o->id == id)
return o;
}
o++;
} while(o->name);
}
return NULL;
}

const struct curl_easyoption *curl_easy_option_by_name(const char *name)
{
return lookup(name, 0);
}

const struct curl_easyoption *curl_easy_option_by_id (CURLoption id)
{
return lookup(NULL, id);
}

/* Iterates over available options */
const struct curl_easyoption *
curl_easy_option_next(const struct curl_easyoption *prev)
{
if(prev && prev->name) {
prev++;
return prev;
}
else if(!prev)
return &Curl_easyopts[0];
return NULL;
}

0 comments on commit 2e4847f

Please sign in to comment.