tool_paramhlp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Daniel Stenberg, <daniel@haxx.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 "tool_setup.h"
  25. #include "strcase.h"
  26. #define ENABLE_CURLX_PRINTF
  27. /* use our own printf() functions */
  28. #include "curlx.h"
  29. #include "tool_cfgable.h"
  30. #include "tool_getparam.h"
  31. #include "tool_getpass.h"
  32. #include "tool_msgs.h"
  33. #include "tool_paramhlp.h"
  34. #include "tool_libinfo.h"
  35. #include "tool_util.h"
  36. #include "tool_version.h"
  37. #include "dynbuf.h"
  38. #include "memdebug.h" /* keep this as LAST include */
  39. struct getout *new_getout(struct OperationConfig *config)
  40. {
  41. struct getout *node = calloc(1, sizeof(struct getout));
  42. struct getout *last = config->url_last;
  43. if(node) {
  44. static int outnum = 0;
  45. /* append this new node last in the list */
  46. if(last)
  47. last->next = node;
  48. else
  49. config->url_list = node; /* first node */
  50. /* move the last pointer */
  51. config->url_last = node;
  52. node->flags = config->default_node_flags;
  53. node->num = outnum++;
  54. }
  55. return node;
  56. }
  57. #define MAX_FILE2STRING (256*1024*1024) /* big enough ? */
  58. ParameterError file2string(char **bufp, FILE *file)
  59. {
  60. struct curlx_dynbuf dyn;
  61. DEBUGASSERT(MAX_FILE2STRING < INT_MAX); /* needs to fit in an int later */
  62. curlx_dyn_init(&dyn, MAX_FILE2STRING);
  63. if(file) {
  64. char buffer[256];
  65. while(fgets(buffer, sizeof(buffer), file)) {
  66. char *ptr = strchr(buffer, '\r');
  67. if(ptr)
  68. *ptr = '\0';
  69. ptr = strchr(buffer, '\n');
  70. if(ptr)
  71. *ptr = '\0';
  72. if(curlx_dyn_add(&dyn, buffer))
  73. return PARAM_NO_MEM;
  74. }
  75. }
  76. *bufp = curlx_dyn_ptr(&dyn);
  77. return PARAM_OK;
  78. }
  79. #define MAX_FILE2MEMORY (1024*1024*1024) /* big enough ? */
  80. ParameterError file2memory(char **bufp, size_t *size, FILE *file)
  81. {
  82. if(file) {
  83. size_t nread;
  84. struct curlx_dynbuf dyn;
  85. /* The size needs to fit in an int later */
  86. DEBUGASSERT(MAX_FILE2MEMORY < INT_MAX);
  87. curlx_dyn_init(&dyn, MAX_FILE2MEMORY);
  88. do {
  89. char buffer[4096];
  90. nread = fread(buffer, 1, sizeof(buffer), file);
  91. if(ferror(file)) {
  92. curlx_dyn_free(&dyn);
  93. *size = 0;
  94. *bufp = NULL;
  95. return PARAM_READ_ERROR;
  96. }
  97. if(nread)
  98. if(curlx_dyn_addn(&dyn, buffer, nread))
  99. return PARAM_NO_MEM;
  100. } while(!feof(file));
  101. *size = curlx_dyn_len(&dyn);
  102. *bufp = curlx_dyn_ptr(&dyn);
  103. }
  104. else {
  105. *size = 0;
  106. *bufp = NULL;
  107. }
  108. return PARAM_OK;
  109. }
  110. /*
  111. * Parse the string and write the long in the given address. Return PARAM_OK
  112. * on success, otherwise a parameter specific error enum.
  113. *
  114. * Since this function gets called with the 'nextarg' pointer from within the
  115. * getparameter a lot, we must check it for NULL before accessing the str
  116. * data.
  117. */
  118. static ParameterError getnum(long *val, const char *str, int base)
  119. {
  120. if(str) {
  121. char *endptr = NULL;
  122. long num;
  123. errno = 0;
  124. num = strtol(str, &endptr, base);
  125. if(errno == ERANGE)
  126. return PARAM_NUMBER_TOO_LARGE;
  127. if((endptr != str) && (endptr == str + strlen(str))) {
  128. *val = num;
  129. return PARAM_OK; /* Ok */
  130. }
  131. }
  132. return PARAM_BAD_NUMERIC; /* badness */
  133. }
  134. ParameterError str2num(long *val, const char *str)
  135. {
  136. return getnum(val, str, 10);
  137. }
  138. ParameterError oct2nummax(long *val, const char *str, long max)
  139. {
  140. ParameterError result = getnum(val, str, 8);
  141. if(result != PARAM_OK)
  142. return result;
  143. else if(*val > max)
  144. return PARAM_NUMBER_TOO_LARGE;
  145. else if(*val < 0)
  146. return PARAM_NEGATIVE_NUMERIC;
  147. return PARAM_OK;
  148. }
  149. /*
  150. * Parse the string and write the long in the given address. Return PARAM_OK
  151. * on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
  152. *
  153. * Since this function gets called with the 'nextarg' pointer from within the
  154. * getparameter a lot, we must check it for NULL before accessing the str
  155. * data.
  156. */
  157. ParameterError str2unum(long *val, const char *str)
  158. {
  159. ParameterError result = getnum(val, str, 10);
  160. if(result != PARAM_OK)
  161. return result;
  162. if(*val < 0)
  163. return PARAM_NEGATIVE_NUMERIC;
  164. return PARAM_OK;
  165. }
  166. /*
  167. * Parse the string and write the long in the given address if it is below the
  168. * maximum allowed value. Return PARAM_OK on success, otherwise a parameter
  169. * error enum. ONLY ACCEPTS POSITIVE NUMBERS!
  170. *
  171. * Since this function gets called with the 'nextarg' pointer from within the
  172. * getparameter a lot, we must check it for NULL before accessing the str
  173. * data.
  174. */
  175. ParameterError str2unummax(long *val, const char *str, long max)
  176. {
  177. ParameterError result = str2unum(val, str);
  178. if(result != PARAM_OK)
  179. return result;
  180. if(*val > max)
  181. return PARAM_NUMBER_TOO_LARGE;
  182. return PARAM_OK;
  183. }
  184. /*
  185. * Parse the string and write the double in the given address. Return PARAM_OK
  186. * on success, otherwise a parameter specific error enum.
  187. *
  188. * The 'max' argument is the maximum value allowed, as the numbers are often
  189. * multiplied when later used.
  190. *
  191. * Since this function gets called with the 'nextarg' pointer from within the
  192. * getparameter a lot, we must check it for NULL before accessing the str
  193. * data.
  194. */
  195. static ParameterError str2double(double *val, const char *str, double max)
  196. {
  197. if(str) {
  198. char *endptr;
  199. double num;
  200. errno = 0;
  201. num = strtod(str, &endptr);
  202. if(errno == ERANGE)
  203. return PARAM_NUMBER_TOO_LARGE;
  204. if(num > max) {
  205. /* too large */
  206. return PARAM_NUMBER_TOO_LARGE;
  207. }
  208. if((endptr != str) && (endptr == str + strlen(str))) {
  209. *val = num;
  210. return PARAM_OK; /* Ok */
  211. }
  212. }
  213. return PARAM_BAD_NUMERIC; /* badness */
  214. }
  215. /*
  216. * Parse the string as seconds with decimals, and write the number of
  217. * milliseconds that corresponds in the given address. Return PARAM_OK on
  218. * success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
  219. *
  220. * The 'max' argument is the maximum value allowed, as the numbers are often
  221. * multiplied when later used.
  222. *
  223. * Since this function gets called with the 'nextarg' pointer from within the
  224. * getparameter a lot, we must check it for NULL before accessing the str
  225. * data.
  226. */
  227. ParameterError secs2ms(long *valp, const char *str)
  228. {
  229. double value;
  230. ParameterError result = str2double(&value, str, (double)LONG_MAX/1000);
  231. if(result != PARAM_OK)
  232. return result;
  233. if(value < 0)
  234. return PARAM_NEGATIVE_NUMERIC;
  235. *valp = (long)(value*1000);
  236. return PARAM_OK;
  237. }
  238. /*
  239. * Implement protocol sets in null-terminated array of protocol name pointers.
  240. */
  241. /* Return index of prototype token in set, card(set) if not found.
  242. Can be called with proto == NULL to get card(set). */
  243. static size_t protoset_index(const char * const *protoset, const char *proto)
  244. {
  245. const char * const *p = protoset;
  246. DEBUGASSERT(proto == proto_token(proto)); /* Ensure it is tokenized. */
  247. for(; *p; p++)
  248. if(proto == *p)
  249. break;
  250. return p - protoset;
  251. }
  252. /* Include protocol token in set. */
  253. static void protoset_set(const char **protoset, const char *proto)
  254. {
  255. if(proto) {
  256. size_t n = protoset_index(protoset, proto);
  257. if(!protoset[n]) {
  258. DEBUGASSERT(n < proto_count);
  259. protoset[n] = proto;
  260. protoset[n + 1] = NULL;
  261. }
  262. }
  263. }
  264. /* Exclude protocol token from set. */
  265. static void protoset_clear(const char **protoset, const char *proto)
  266. {
  267. if(proto) {
  268. size_t n = protoset_index(protoset, proto);
  269. if(protoset[n]) {
  270. size_t m = protoset_index(protoset, NULL) - 1;
  271. protoset[n] = protoset[m];
  272. protoset[m] = NULL;
  273. }
  274. }
  275. }
  276. /*
  277. * Parse the string and provide an allocated libcurl compatible protocol
  278. * string output. Return non-zero on failure, zero on success.
  279. *
  280. * The string is a list of protocols
  281. *
  282. * Since this function gets called with the 'nextarg' pointer from within the
  283. * getparameter a lot, we must check it for NULL before accessing the str
  284. * data.
  285. */
  286. #define MAX_PROTOSTRING (64*11) /* Enough room for 64 10-chars proto names. */
  287. ParameterError proto2num(struct OperationConfig *config,
  288. const char * const *val, char **ostr, const char *str)
  289. {
  290. char *buffer;
  291. const char *sep = ",";
  292. char *token;
  293. const char **protoset;
  294. struct curlx_dynbuf obuf;
  295. size_t proto;
  296. CURLcode result;
  297. curlx_dyn_init(&obuf, MAX_PROTOSTRING);
  298. if(!str)
  299. return PARAM_OPTION_AMBIGUOUS;
  300. buffer = strdup(str); /* because strtok corrupts it */
  301. if(!buffer)
  302. return PARAM_NO_MEM;
  303. protoset = malloc((proto_count + 1) * sizeof(*protoset));
  304. if(!protoset) {
  305. free(buffer);
  306. return PARAM_NO_MEM;
  307. }
  308. /* Preset protocol set with default values. */
  309. protoset[0] = NULL;
  310. for(; *val; val++) {
  311. const char *p = proto_token(*val);
  312. if(p)
  313. protoset_set(protoset, p);
  314. }
  315. /* Allow strtok() here since this isn't used threaded */
  316. /* !checksrc! disable BANNEDFUNC 2 */
  317. for(token = strtok(buffer, sep);
  318. token;
  319. token = strtok(NULL, sep)) {
  320. enum e_action { allow, deny, set } action = allow;
  321. /* Process token modifiers */
  322. while(!ISALNUM(*token)) { /* may be NULL if token is all modifiers */
  323. switch (*token++) {
  324. case '=':
  325. action = set;
  326. break;
  327. case '-':
  328. action = deny;
  329. break;
  330. case '+':
  331. action = allow;
  332. break;
  333. default: /* Includes case of terminating NULL */
  334. free(buffer);
  335. free((char *) protoset);
  336. return PARAM_BAD_USE;
  337. }
  338. }
  339. if(curl_strequal(token, "all")) {
  340. switch(action) {
  341. case deny:
  342. protoset[0] = NULL;
  343. break;
  344. case allow:
  345. case set:
  346. memcpy((char *) protoset,
  347. built_in_protos, (proto_count + 1) * sizeof(*protoset));
  348. break;
  349. }
  350. }
  351. else {
  352. const char *p = proto_token(token);
  353. if(p)
  354. switch(action) {
  355. case deny:
  356. protoset_clear(protoset, p);
  357. break;
  358. case set:
  359. protoset[0] = NULL;
  360. /* FALLTHROUGH */
  361. case allow:
  362. protoset_set(protoset, p);
  363. break;
  364. }
  365. else { /* unknown protocol */
  366. /* If they have specified only this protocol, we say treat it as
  367. if no protocols are allowed */
  368. if(action == set)
  369. protoset[0] = NULL;
  370. warnf(config->global, "unrecognized protocol '%s'\n", token);
  371. }
  372. }
  373. }
  374. free(buffer);
  375. /* We need the protocols in alphabetic order for CI tests requirements. */
  376. qsort((char *) protoset, protoset_index(protoset, NULL), sizeof(*protoset),
  377. struplocompare4sort);
  378. result = curlx_dyn_addn(&obuf, "", 0);
  379. for(proto = 0; protoset[proto] && !result; proto++)
  380. result = curlx_dyn_addf(&obuf, "%s,", protoset[proto]);
  381. free((char *) protoset);
  382. curlx_dyn_setlen(&obuf, curlx_dyn_len(&obuf) - 1);
  383. free(*ostr);
  384. *ostr = curlx_dyn_ptr(&obuf);
  385. return *ostr ? PARAM_OK : PARAM_NO_MEM;
  386. }
  387. /**
  388. * Check if the given string is a protocol supported by libcurl
  389. *
  390. * @param str the protocol name
  391. * @return PARAM_OK protocol supported
  392. * @return PARAM_LIBCURL_UNSUPPORTED_PROTOCOL protocol not supported
  393. * @return PARAM_REQUIRES_PARAMETER missing parameter
  394. */
  395. ParameterError check_protocol(const char *str)
  396. {
  397. if(!str)
  398. return PARAM_REQUIRES_PARAMETER;
  399. if(proto_token(str))
  400. return PARAM_OK;
  401. return PARAM_LIBCURL_UNSUPPORTED_PROTOCOL;
  402. }
  403. /**
  404. * Parses the given string looking for an offset (which may be a
  405. * larger-than-integer value). The offset CANNOT be negative!
  406. *
  407. * @param val the offset to populate
  408. * @param str the buffer containing the offset
  409. * @return PARAM_OK if successful, a parameter specific error enum if failure.
  410. */
  411. ParameterError str2offset(curl_off_t *val, const char *str)
  412. {
  413. char *endptr;
  414. if(str[0] == '-')
  415. /* offsets aren't negative, this indicates weird input */
  416. return PARAM_NEGATIVE_NUMERIC;
  417. #if(SIZEOF_CURL_OFF_T > SIZEOF_LONG)
  418. {
  419. CURLofft offt = curlx_strtoofft(str, &endptr, 10, val);
  420. if(CURL_OFFT_FLOW == offt)
  421. return PARAM_NUMBER_TOO_LARGE;
  422. else if(CURL_OFFT_INVAL == offt)
  423. return PARAM_BAD_NUMERIC;
  424. }
  425. #else
  426. errno = 0;
  427. *val = strtol(str, &endptr, 0);
  428. if((*val == LONG_MIN || *val == LONG_MAX) && errno == ERANGE)
  429. return PARAM_NUMBER_TOO_LARGE;
  430. #endif
  431. if((endptr != str) && (endptr == str + strlen(str)))
  432. return PARAM_OK;
  433. return PARAM_BAD_NUMERIC;
  434. }
  435. #define MAX_USERPWDLENGTH (100*1024)
  436. static CURLcode checkpasswd(const char *kind, /* for what purpose */
  437. const size_t i, /* operation index */
  438. const bool last, /* TRUE if last operation */
  439. char **userpwd) /* pointer to allocated string */
  440. {
  441. char *psep;
  442. char *osep;
  443. if(!*userpwd)
  444. return CURLE_OK;
  445. /* Attempt to find the password separator */
  446. psep = strchr(*userpwd, ':');
  447. /* Attempt to find the options separator */
  448. osep = strchr(*userpwd, ';');
  449. if(!psep && **userpwd != ';') {
  450. /* no password present, prompt for one */
  451. char passwd[2048] = "";
  452. char prompt[256];
  453. struct curlx_dynbuf dyn;
  454. curlx_dyn_init(&dyn, MAX_USERPWDLENGTH);
  455. if(osep)
  456. *osep = '\0';
  457. /* build a nice-looking prompt */
  458. if(!i && last)
  459. curlx_msnprintf(prompt, sizeof(prompt),
  460. "Enter %s password for user '%s':",
  461. kind, *userpwd);
  462. else
  463. curlx_msnprintf(prompt, sizeof(prompt),
  464. "Enter %s password for user '%s' on URL #%zu:",
  465. kind, *userpwd, i + 1);
  466. /* get password */
  467. getpass_r(prompt, passwd, sizeof(passwd));
  468. if(osep)
  469. *osep = ';';
  470. if(curlx_dyn_addf(&dyn, "%s:%s", *userpwd, passwd))
  471. return CURLE_OUT_OF_MEMORY;
  472. /* return the new string */
  473. free(*userpwd);
  474. *userpwd = curlx_dyn_ptr(&dyn);
  475. }
  476. return CURLE_OK;
  477. }
  478. ParameterError add2list(struct curl_slist **list, const char *ptr)
  479. {
  480. struct curl_slist *newlist = curl_slist_append(*list, ptr);
  481. if(newlist)
  482. *list = newlist;
  483. else
  484. return PARAM_NO_MEM;
  485. return PARAM_OK;
  486. }
  487. int ftpfilemethod(struct OperationConfig *config, const char *str)
  488. {
  489. if(curl_strequal("singlecwd", str))
  490. return CURLFTPMETHOD_SINGLECWD;
  491. if(curl_strequal("nocwd", str))
  492. return CURLFTPMETHOD_NOCWD;
  493. if(curl_strequal("multicwd", str))
  494. return CURLFTPMETHOD_MULTICWD;
  495. warnf(config->global, "unrecognized ftp file method '%s', using default\n",
  496. str);
  497. return CURLFTPMETHOD_MULTICWD;
  498. }
  499. int ftpcccmethod(struct OperationConfig *config, const char *str)
  500. {
  501. if(curl_strequal("passive", str))
  502. return CURLFTPSSL_CCC_PASSIVE;
  503. if(curl_strequal("active", str))
  504. return CURLFTPSSL_CCC_ACTIVE;
  505. warnf(config->global, "unrecognized ftp CCC method '%s', using default\n",
  506. str);
  507. return CURLFTPSSL_CCC_PASSIVE;
  508. }
  509. long delegation(struct OperationConfig *config, const char *str)
  510. {
  511. if(curl_strequal("none", str))
  512. return CURLGSSAPI_DELEGATION_NONE;
  513. if(curl_strequal("policy", str))
  514. return CURLGSSAPI_DELEGATION_POLICY_FLAG;
  515. if(curl_strequal("always", str))
  516. return CURLGSSAPI_DELEGATION_FLAG;
  517. warnf(config->global, "unrecognized delegation method '%s', using none\n",
  518. str);
  519. return CURLGSSAPI_DELEGATION_NONE;
  520. }
  521. /*
  522. * my_useragent: returns allocated string with default user agent
  523. */
  524. static char *my_useragent(void)
  525. {
  526. return strdup(CURL_NAME "/" CURL_VERSION);
  527. }
  528. #define isheadersep(x) ((((x)==':') || ((x)==';')))
  529. /*
  530. * inlist() returns true if the given 'checkfor' header is present in the
  531. * header list.
  532. */
  533. static bool inlist(const struct curl_slist *head,
  534. const char *checkfor)
  535. {
  536. size_t thislen = strlen(checkfor);
  537. DEBUGASSERT(thislen);
  538. DEBUGASSERT(checkfor[thislen-1] != ':');
  539. for(; head; head = head->next) {
  540. if(curl_strnequal(head->data, checkfor, thislen) &&
  541. isheadersep(head->data[thislen]) )
  542. return TRUE;
  543. }
  544. return FALSE;
  545. }
  546. CURLcode get_args(struct OperationConfig *config, const size_t i)
  547. {
  548. CURLcode result = CURLE_OK;
  549. bool last = (config->next ? FALSE : TRUE);
  550. if(config->jsoned) {
  551. ParameterError err = PARAM_OK;
  552. /* --json also implies json Content-Type: and Accept: headers - if
  553. they are not set with -H */
  554. if(!inlist(config->headers, "Content-Type"))
  555. err = add2list(&config->headers, "Content-Type: application/json");
  556. if(!err && !inlist(config->headers, "Accept"))
  557. err = add2list(&config->headers, "Accept: application/json");
  558. if(err)
  559. return CURLE_OUT_OF_MEMORY;
  560. }
  561. /* Check we have a password for the given host user */
  562. if(config->userpwd && !config->oauth_bearer) {
  563. result = checkpasswd("host", i, last, &config->userpwd);
  564. if(result)
  565. return result;
  566. }
  567. /* Check we have a password for the given proxy user */
  568. if(config->proxyuserpwd) {
  569. result = checkpasswd("proxy", i, last, &config->proxyuserpwd);
  570. if(result)
  571. return result;
  572. }
  573. /* Check we have a user agent */
  574. if(!config->useragent) {
  575. config->useragent = my_useragent();
  576. if(!config->useragent) {
  577. errorf(config->global, "out of memory\n");
  578. result = CURLE_OUT_OF_MEMORY;
  579. }
  580. }
  581. return result;
  582. }
  583. /*
  584. * Parse the string and modify ssl_version in the val argument. Return PARAM_OK
  585. * on success, otherwise a parameter error enum. ONLY ACCEPTS POSITIVE NUMBERS!
  586. *
  587. * Since this function gets called with the 'nextarg' pointer from within the
  588. * getparameter a lot, we must check it for NULL before accessing the str
  589. * data.
  590. */
  591. ParameterError str2tls_max(long *val, const char *str)
  592. {
  593. static struct s_tls_max {
  594. const char *tls_max_str;
  595. long tls_max;
  596. } const tls_max_array[] = {
  597. { "default", CURL_SSLVERSION_MAX_DEFAULT },
  598. { "1.0", CURL_SSLVERSION_MAX_TLSv1_0 },
  599. { "1.1", CURL_SSLVERSION_MAX_TLSv1_1 },
  600. { "1.2", CURL_SSLVERSION_MAX_TLSv1_2 },
  601. { "1.3", CURL_SSLVERSION_MAX_TLSv1_3 }
  602. };
  603. size_t i = 0;
  604. if(!str)
  605. return PARAM_REQUIRES_PARAMETER;
  606. for(i = 0; i < sizeof(tls_max_array)/sizeof(tls_max_array[0]); i++) {
  607. if(!strcmp(str, tls_max_array[i].tls_max_str)) {
  608. *val = tls_max_array[i].tls_max;
  609. return PARAM_OK;
  610. }
  611. }
  612. return PARAM_BAD_USE;
  613. }