tool_paramhlp.c 18 KB

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