easygetopt.c 2.5 KB

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