2
0

easygetopt.c 2.5 KB

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