1/*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ | | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * ___|___/|_| ______| 7 * 8 * Copyright (C) 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 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24 25#include "curl_setup.h" 26#include "strcase.h" 27#include "easyoptions.h" 28 29#ifndef CURL_DISABLE_GETOPTIONS 30 31/* Lookups easy options at runtime */ 32static struct curl_easyoption *lookup(const char *name, CURLoption id) 33{ 34 DEBUGASSERT(name || id); 35 DEBUGASSERT(!Curl_easyopts_check()); 36 if(name || id) { 37 struct curl_easyoption *o = &Curl_easyopts[0]; 38 do { 39 if(name) { 40 if(strcasecompare(o->name, name)) 41 return o; 42 } 43 else { 44 if((o->id == id) && !(o->flags & CURLOT_FLAG_ALIAS)) 45 /* don't match alias options */ 46 return o; 47 } 48 o++; 49 } while(o->name); 50 } 51 return NULL; 52} 53 54const struct curl_easyoption *curl_easy_option_by_name(const char *name) 55{ 56 /* when name is used, the id argument is ignored */ 57 return lookup(name, CURLOPT_LASTENTRY); 58} 59 60const struct curl_easyoption *curl_easy_option_by_id(CURLoption id) 61{ 62 return lookup(NULL, id); 63} 64 65/* Iterates over available options */ 66const struct curl_easyoption * 67curl_easy_option_next(const struct curl_easyoption *prev) 68{ 69 if(prev && prev->name) { 70 prev++; 71 if(prev->name) 72 return prev; 73 } 74 else if(!prev) 75 return &Curl_easyopts[0]; 76 return NULL; 77} 78 79#else 80const struct curl_easyoption *curl_easy_option_by_name(const char *name) 81{ 82 (void)name; 83 return NULL; 84} 85 86const struct curl_easyoption *curl_easy_option_by_id (CURLoption id) 87{ 88 (void)id; 89 return NULL; 90} 91 92const struct curl_easyoption * 93curl_easy_option_next(const struct curl_easyoption *prev) 94{ 95 (void)prev; 96 return NULL; 97} 98#endif 99