1 | /*************************************************************************** |
2 | * _ _ ____ _ |
3 | * Project ___| | | | _ | | |
4 | * / __| | | | |_) | | |
5 | * | (__| |_| | _ <| |___ |
6 | * ___|___/|_| ______| |
7 | * |
8 | * Copyright (C) 1998 - 2020, Daniel Stenberg, <daniel.se>, et al. |
9 | * |
10 | * This software is licensed as described in the file COPYING, which |
11 | * you should have received as part of this distribution. The terms |
12 | * are also available at https://curl.se/docs/copyright.html. |
13 | * |
14 | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
15 | * copies of the Software, and permit persons to whom the Software is |
16 | * furnished to do so, under the terms of the COPYING file. |
17 | * |
18 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | * KIND, either express or implied. |
20 | * |
21 | ***************************************************************************/ |
22 | |
23 | #include "curl_setup.h" |
24 | #include "strcase.h" |
25 | #include "easyoptions.h" |
26 | |
27 | #ifndef CURL_DISABLE_GETOPTIONS |
28 | |
29 | /* Lookups easy options at runtime */ |
30 | static struct curl_easyoption *lookup(const char *name, CURLoption id) |
31 | { |
32 | DEBUGASSERT(name || id); |
33 | DEBUGASSERT(!Curl_easyopts_check()); |
34 | if(name || id) { |
35 | struct curl_easyoption *o = &Curl_easyopts[0]; |
36 | do { |
37 | if(name) { |
38 | if(strcasecompare(o->name, name)) |
39 | return o; |
40 | } |
41 | else { |
42 | if((o->id == id) && !(o->flags & CURLOT_FLAG_ALIAS)) |
43 | /* don't match alias options */ |
44 | return o; |
45 | } |
46 | o++; |
47 | } while(o->name); |
48 | } |
49 | return NULL; |
50 | } |
51 | |
52 | const struct curl_easyoption *curl_easy_option_by_name(const char *name) |
53 | { |
54 | /* when name is used, the id argument is ignored */ |
55 | return lookup(name, CURLOPT_LASTENTRY); |
56 | } |
57 | |
58 | const struct curl_easyoption *curl_easy_option_by_id(CURLoption id) |
59 | { |
60 | return lookup(NULL, id); |
61 | } |
62 | |
63 | /* Iterates over available options */ |
64 | const struct curl_easyoption * |
65 | curl_easy_option_next(const struct curl_easyoption *prev) |
66 | { |
67 | if(prev && prev->name) { |
68 | prev++; |
69 | if(prev->name) |
70 | return prev; |
71 | } |
72 | else if(!prev) |
73 | return &Curl_easyopts[0]; |
74 | return NULL; |
75 | } |
76 | |
77 | #else |
78 | const struct curl_easyoption *curl_easy_option_by_name(const char *name) |
79 | { |
80 | (void)name; |
81 | return NULL; |
82 | } |
83 | |
84 | const struct curl_easyoption *curl_easy_option_by_id (CURLoption id) |
85 | { |
86 | (void)id; |
87 | return NULL; |
88 | } |
89 | |
90 | const struct curl_easyoption * |
91 | curl_easy_option_next(const struct curl_easyoption *prev) |
92 | { |
93 | (void)prev; |
94 | return NULL; |
95 | } |
96 | #endif |
97 | |