easygetopt.c 2.5 KB

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