config-file.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823
  1. /*
  2. * Copyright (c) 2023 Lain Bailey <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <inttypes.h>
  17. #include <stdio.h>
  18. #include <wchar.h>
  19. #include "config-file.h"
  20. #include "threading.h"
  21. #include "platform.h"
  22. #include "base.h"
  23. #include "bmem.h"
  24. #include "lexer.h"
  25. #include "dstr.h"
  26. #include "uthash.h"
  27. struct config_item {
  28. char *name;
  29. char *value;
  30. UT_hash_handle hh;
  31. };
  32. static inline void config_item_free(struct config_item *item)
  33. {
  34. bfree(item->name);
  35. bfree(item->value);
  36. bfree(item);
  37. }
  38. struct config_section {
  39. char *name;
  40. struct config_item *items;
  41. UT_hash_handle hh;
  42. };
  43. static inline void config_section_free(struct config_section *section)
  44. {
  45. struct config_item *item;
  46. struct config_item *temp;
  47. HASH_ITER (hh, section->items, item, temp) {
  48. HASH_DELETE(hh, section->items, item);
  49. config_item_free(item);
  50. }
  51. bfree(section->name);
  52. bfree(section);
  53. }
  54. struct config_data {
  55. char *file;
  56. struct config_section *sections;
  57. struct config_section *defaults;
  58. pthread_mutex_t mutex;
  59. };
  60. config_t *config_create(const char *file)
  61. {
  62. struct config_data *config;
  63. FILE *f;
  64. f = os_fopen(file, "wb");
  65. if (!f)
  66. return NULL;
  67. fclose(f);
  68. config = bzalloc(sizeof(struct config_data));
  69. if (pthread_mutex_init_recursive(&config->mutex) != 0) {
  70. bfree(config);
  71. return NULL;
  72. }
  73. config->file = bstrdup(file);
  74. return config;
  75. }
  76. static bool config_parse_string(struct lexer *lex, struct strref *ref, char end)
  77. {
  78. bool success = end != 0;
  79. struct base_token token;
  80. base_token_clear(&token);
  81. while (lexer_getbasetoken(lex, &token, PARSE_WHITESPACE)) {
  82. if (end) {
  83. if (*token.text.array == end) {
  84. success = true;
  85. break;
  86. } else if (is_newline(*token.text.array)) {
  87. success = false;
  88. break;
  89. }
  90. } else {
  91. if (is_newline(*token.text.array)) {
  92. success = true;
  93. break;
  94. }
  95. }
  96. strref_add(ref, &token.text);
  97. }
  98. //remove_ref_whitespace(ref);
  99. return success;
  100. }
  101. static void unescape(struct dstr *str)
  102. {
  103. char *read = str->array;
  104. char *write = str->array;
  105. for (; *read; read++, write++) {
  106. char cur = *read;
  107. if (cur == '\\') {
  108. char next = read[1];
  109. if (next == '\\') {
  110. read++;
  111. } else if (next == 'r') {
  112. cur = '\r';
  113. read++;
  114. } else if (next == 'n') {
  115. cur = '\n';
  116. read++;
  117. }
  118. }
  119. if (read != write)
  120. *write = cur;
  121. }
  122. if (read != write)
  123. *write = '\0';
  124. }
  125. static void config_add_item(struct config_item **items, struct strref *name,
  126. struct strref *value)
  127. {
  128. struct config_item *item;
  129. struct dstr item_value;
  130. item = bzalloc(sizeof(struct config_item));
  131. item->name = bstrdup_n(name->array, name->len);
  132. if (!strref_is_empty(value)) {
  133. dstr_init_copy_strref(&item_value, value);
  134. unescape(&item_value);
  135. item->value = bstrdup_n(item_value.array, item_value.len);
  136. dstr_free(&item_value);
  137. } else {
  138. item->value = bzalloc(1);
  139. }
  140. HASH_ADD_STR(*items, name, item);
  141. }
  142. static void config_parse_section(struct config_section *section,
  143. struct lexer *lex)
  144. {
  145. struct base_token token;
  146. while (lexer_getbasetoken(lex, &token, PARSE_WHITESPACE)) {
  147. struct strref name, value;
  148. while (token.type == BASETOKEN_WHITESPACE) {
  149. if (!lexer_getbasetoken(lex, &token, PARSE_WHITESPACE))
  150. return;
  151. }
  152. if (token.type == BASETOKEN_OTHER) {
  153. if (*token.text.array == '#') {
  154. do {
  155. if (!lexer_getbasetoken(
  156. lex, &token,
  157. PARSE_WHITESPACE))
  158. return;
  159. } while (!is_newline(*token.text.array));
  160. continue;
  161. } else if (*token.text.array == '[') {
  162. lex->offset--;
  163. return;
  164. }
  165. }
  166. strref_copy(&name, &token.text);
  167. if (!config_parse_string(lex, &name, '='))
  168. continue;
  169. strref_clear(&value);
  170. config_parse_string(lex, &value, 0);
  171. config_add_item(&section->items, &name, &value);
  172. }
  173. }
  174. static void parse_config_data(struct config_section **sections,
  175. struct lexer *lex)
  176. {
  177. struct strref section_name;
  178. struct base_token token;
  179. base_token_clear(&token);
  180. while (lexer_getbasetoken(lex, &token, PARSE_WHITESPACE)) {
  181. struct config_section *section;
  182. while (token.type == BASETOKEN_WHITESPACE) {
  183. if (!lexer_getbasetoken(lex, &token, PARSE_WHITESPACE))
  184. return;
  185. }
  186. if (*token.text.array != '[') {
  187. while (!is_newline(*token.text.array)) {
  188. if (!lexer_getbasetoken(lex, &token,
  189. PARSE_WHITESPACE))
  190. return;
  191. }
  192. continue;
  193. }
  194. strref_clear(&section_name);
  195. config_parse_string(lex, &section_name, ']');
  196. if (!section_name.len)
  197. return;
  198. section = bzalloc(sizeof(struct config_section));
  199. section->name = bstrdup_n(section_name.array, section_name.len);
  200. config_parse_section(section, lex);
  201. HASH_ADD_STR(*sections, name, section);
  202. }
  203. }
  204. static int config_parse_file(struct config_section **sections, const char *file,
  205. bool always_open)
  206. {
  207. char *file_data;
  208. struct lexer lex;
  209. FILE *f;
  210. f = os_fopen(file, "rb");
  211. if (always_open && !f)
  212. f = os_fopen(file, "w+");
  213. if (!f)
  214. return CONFIG_FILENOTFOUND;
  215. os_fread_utf8(f, &file_data);
  216. fclose(f);
  217. if (!file_data)
  218. return CONFIG_SUCCESS;
  219. lexer_init(&lex);
  220. lexer_start_move(&lex, file_data);
  221. parse_config_data(sections, &lex);
  222. lexer_free(&lex);
  223. return CONFIG_SUCCESS;
  224. }
  225. int config_open(config_t **config, const char *file,
  226. enum config_open_type open_type)
  227. {
  228. int errorcode;
  229. bool always_open = open_type == CONFIG_OPEN_ALWAYS;
  230. if (!config)
  231. return CONFIG_ERROR;
  232. *config = bzalloc(sizeof(struct config_data));
  233. if (!*config)
  234. return CONFIG_ERROR;
  235. if (pthread_mutex_init_recursive(&(*config)->mutex) != 0) {
  236. bfree(*config);
  237. return CONFIG_ERROR;
  238. }
  239. (*config)->file = bstrdup(file);
  240. errorcode = config_parse_file(&(*config)->sections, file, always_open);
  241. if (errorcode != CONFIG_SUCCESS) {
  242. config_close(*config);
  243. *config = NULL;
  244. }
  245. return errorcode;
  246. }
  247. int config_open_string(config_t **config, const char *str)
  248. {
  249. struct lexer lex;
  250. if (!config)
  251. return CONFIG_ERROR;
  252. *config = bzalloc(sizeof(struct config_data));
  253. if (!*config)
  254. return CONFIG_ERROR;
  255. if (pthread_mutex_init_recursive(&(*config)->mutex) != 0) {
  256. bfree(*config);
  257. return CONFIG_ERROR;
  258. }
  259. (*config)->file = NULL;
  260. lexer_init(&lex);
  261. lexer_start(&lex, str);
  262. parse_config_data(&(*config)->sections, &lex);
  263. lexer_free(&lex);
  264. return CONFIG_SUCCESS;
  265. }
  266. int config_open_defaults(config_t *config, const char *file)
  267. {
  268. if (!config)
  269. return CONFIG_ERROR;
  270. return config_parse_file(&config->defaults, file, false);
  271. }
  272. int config_save(config_t *config)
  273. {
  274. FILE *f;
  275. struct dstr str, tmp;
  276. int ret = CONFIG_ERROR;
  277. if (!config)
  278. return CONFIG_ERROR;
  279. if (!config->file)
  280. return CONFIG_ERROR;
  281. dstr_init(&str);
  282. dstr_init(&tmp);
  283. pthread_mutex_lock(&config->mutex);
  284. f = os_fopen(config->file, "wb");
  285. if (!f) {
  286. pthread_mutex_unlock(&config->mutex);
  287. return CONFIG_FILENOTFOUND;
  288. }
  289. struct config_section *section, *stmp;
  290. struct config_item *item, *itmp;
  291. int idx = 0;
  292. HASH_ITER (hh, config->sections, section, stmp) {
  293. if (idx++)
  294. dstr_cat(&str, "\n");
  295. dstr_cat(&str, "[");
  296. dstr_cat(&str, section->name);
  297. dstr_cat(&str, "]\n");
  298. HASH_ITER (hh, section->items, item, itmp) {
  299. dstr_copy(&tmp, item->value ? item->value : "");
  300. dstr_replace(&tmp, "\\", "\\\\");
  301. dstr_replace(&tmp, "\r", "\\r");
  302. dstr_replace(&tmp, "\n", "\\n");
  303. dstr_cat(&str, item->name);
  304. dstr_cat(&str, "=");
  305. dstr_cat(&str, tmp.array);
  306. dstr_cat(&str, "\n");
  307. }
  308. }
  309. #ifdef _WIN32
  310. if (fwrite("\xEF\xBB\xBF", 3, 1, f) != 1)
  311. goto cleanup;
  312. #endif
  313. if (fwrite(str.array, str.len, 1, f) != 1)
  314. goto cleanup;
  315. ret = CONFIG_SUCCESS;
  316. cleanup:
  317. fclose(f);
  318. pthread_mutex_unlock(&config->mutex);
  319. dstr_free(&tmp);
  320. dstr_free(&str);
  321. return ret;
  322. }
  323. int config_save_safe(config_t *config, const char *temp_ext,
  324. const char *backup_ext)
  325. {
  326. struct dstr temp_file = {0};
  327. struct dstr backup_file = {0};
  328. char *file = config->file;
  329. int ret;
  330. if (!temp_ext || !*temp_ext) {
  331. blog(LOG_ERROR, "config_save_safe: invalid "
  332. "temporary extension specified");
  333. return CONFIG_ERROR;
  334. }
  335. pthread_mutex_lock(&config->mutex);
  336. dstr_copy(&temp_file, config->file);
  337. if (*temp_ext != '.')
  338. dstr_cat(&temp_file, ".");
  339. dstr_cat(&temp_file, temp_ext);
  340. config->file = temp_file.array;
  341. ret = config_save(config);
  342. config->file = file;
  343. if (ret != CONFIG_SUCCESS) {
  344. blog(LOG_ERROR,
  345. "config_save_safe: failed to "
  346. "write to %s",
  347. temp_file.array);
  348. goto cleanup;
  349. }
  350. if (backup_ext && *backup_ext) {
  351. dstr_copy(&backup_file, config->file);
  352. if (*backup_ext != '.')
  353. dstr_cat(&backup_file, ".");
  354. dstr_cat(&backup_file, backup_ext);
  355. }
  356. if (os_safe_replace(file, temp_file.array, backup_file.array) != 0)
  357. ret = CONFIG_ERROR;
  358. cleanup:
  359. pthread_mutex_unlock(&config->mutex);
  360. dstr_free(&temp_file);
  361. dstr_free(&backup_file);
  362. return ret;
  363. }
  364. void config_close(config_t *config)
  365. {
  366. struct config_section *section, *temp;
  367. if (!config)
  368. return;
  369. HASH_ITER (hh, config->sections, section, temp) {
  370. HASH_DELETE(hh, config->sections, section);
  371. config_section_free(section);
  372. }
  373. HASH_ITER (hh, config->defaults, section, temp) {
  374. HASH_DELETE(hh, config->defaults, section);
  375. config_section_free(section);
  376. }
  377. bfree(config->file);
  378. pthread_mutex_destroy(&config->mutex);
  379. bfree(config);
  380. }
  381. size_t config_num_sections(config_t *config)
  382. {
  383. return HASH_CNT(hh, config->sections);
  384. }
  385. const char *config_get_section(config_t *config, size_t idx)
  386. {
  387. struct config_section *section;
  388. struct config_section *temp;
  389. const char *name = NULL;
  390. size_t ctr = 0;
  391. pthread_mutex_lock(&config->mutex);
  392. if (idx >= config_num_sections(config))
  393. goto unlock;
  394. HASH_ITER (hh, config->sections, section, temp) {
  395. if (idx == ctr++) {
  396. name = section->name;
  397. break;
  398. }
  399. }
  400. unlock:
  401. pthread_mutex_unlock(&config->mutex);
  402. return name;
  403. }
  404. static const struct config_item *
  405. config_find_item(const struct config_section *sections, const char *section,
  406. const char *name)
  407. {
  408. struct config_section *sec;
  409. struct config_item *res;
  410. HASH_FIND_STR(sections, section, sec);
  411. if (!sec)
  412. return NULL;
  413. HASH_FIND_STR(sec->items, name, res);
  414. return res;
  415. }
  416. static void config_set_item(config_t *config, struct config_section **sections,
  417. const char *section, const char *name, char *value)
  418. {
  419. struct config_section *sec;
  420. struct config_item *item;
  421. pthread_mutex_lock(&config->mutex);
  422. HASH_FIND_STR(*sections, section, sec);
  423. if (!sec) {
  424. sec = bzalloc(sizeof(struct config_section));
  425. sec->name = bstrdup(section);
  426. HASH_ADD_STR(*sections, name, sec);
  427. }
  428. HASH_FIND_STR(sec->items, name, item);
  429. if (!item) {
  430. item = bzalloc(sizeof(struct config_item));
  431. item->name = bstrdup(name);
  432. item->value = value;
  433. HASH_ADD_STR(sec->items, name, item);
  434. } else {
  435. bfree(item->value);
  436. item->value = value;
  437. }
  438. pthread_mutex_unlock(&config->mutex);
  439. }
  440. static void config_set_item_default(config_t *config, const char *section,
  441. const char *name, char *value)
  442. {
  443. config_set_item(config, &config->defaults, section, name, value);
  444. if (!config_has_user_value(config, section, name))
  445. config_set_item(config, &config->sections, section, name,
  446. bstrdup(value));
  447. }
  448. void config_set_string(config_t *config, const char *section, const char *name,
  449. const char *value)
  450. {
  451. if (!value)
  452. value = "";
  453. config_set_item(config, &config->sections, section, name,
  454. bstrdup(value));
  455. }
  456. void config_set_int(config_t *config, const char *section, const char *name,
  457. int64_t value)
  458. {
  459. struct dstr str;
  460. dstr_init(&str);
  461. dstr_printf(&str, "%" PRId64, value);
  462. config_set_item(config, &config->sections, section, name, str.array);
  463. }
  464. void config_set_uint(config_t *config, const char *section, const char *name,
  465. uint64_t value)
  466. {
  467. struct dstr str;
  468. dstr_init(&str);
  469. dstr_printf(&str, "%" PRIu64, value);
  470. config_set_item(config, &config->sections, section, name, str.array);
  471. }
  472. void config_set_bool(config_t *config, const char *section, const char *name,
  473. bool value)
  474. {
  475. char *str = bstrdup(value ? "true" : "false");
  476. config_set_item(config, &config->sections, section, name, str);
  477. }
  478. void config_set_double(config_t *config, const char *section, const char *name,
  479. double value)
  480. {
  481. char *str = bzalloc(64);
  482. os_dtostr(value, str, 64);
  483. config_set_item(config, &config->sections, section, name, str);
  484. }
  485. void config_set_default_string(config_t *config, const char *section,
  486. const char *name, const char *value)
  487. {
  488. if (!value)
  489. value = "";
  490. config_set_item_default(config, section, name, bstrdup(value));
  491. }
  492. void config_set_default_int(config_t *config, const char *section,
  493. const char *name, int64_t value)
  494. {
  495. struct dstr str;
  496. dstr_init(&str);
  497. dstr_printf(&str, "%" PRId64, value);
  498. config_set_item_default(config, section, name, str.array);
  499. }
  500. void config_set_default_uint(config_t *config, const char *section,
  501. const char *name, uint64_t value)
  502. {
  503. struct dstr str;
  504. dstr_init(&str);
  505. dstr_printf(&str, "%" PRIu64, value);
  506. config_set_item_default(config, section, name, str.array);
  507. }
  508. void config_set_default_bool(config_t *config, const char *section,
  509. const char *name, bool value)
  510. {
  511. char *str = bstrdup(value ? "true" : "false");
  512. config_set_item_default(config, section, name, str);
  513. }
  514. void config_set_default_double(config_t *config, const char *section,
  515. const char *name, double value)
  516. {
  517. struct dstr str;
  518. dstr_init(&str);
  519. dstr_printf(&str, "%g", value);
  520. config_set_item_default(config, section, name, str.array);
  521. }
  522. const char *config_get_string(config_t *config, const char *section,
  523. const char *name)
  524. {
  525. const struct config_item *item;
  526. const char *value = NULL;
  527. pthread_mutex_lock(&config->mutex);
  528. item = config_find_item(config->sections, section, name);
  529. if (!item)
  530. item = config_find_item(config->defaults, section, name);
  531. if (item)
  532. value = item->value;
  533. pthread_mutex_unlock(&config->mutex);
  534. return value;
  535. }
  536. static inline int64_t str_to_int64(const char *str)
  537. {
  538. if (!str || !*str)
  539. return 0;
  540. if (str[0] == '0' && str[1] == 'x')
  541. return strtoll(str + 2, NULL, 16);
  542. else
  543. return strtoll(str, NULL, 10);
  544. }
  545. static inline uint64_t str_to_uint64(const char *str)
  546. {
  547. if (!str || !*str)
  548. return 0;
  549. if (str[0] == '0' && str[1] == 'x')
  550. return strtoull(str + 2, NULL, 16);
  551. else
  552. return strtoull(str, NULL, 10);
  553. }
  554. int64_t config_get_int(config_t *config, const char *section, const char *name)
  555. {
  556. const char *value = config_get_string(config, section, name);
  557. if (value)
  558. return str_to_int64(value);
  559. return 0;
  560. }
  561. uint64_t config_get_uint(config_t *config, const char *section,
  562. const char *name)
  563. {
  564. const char *value = config_get_string(config, section, name);
  565. if (value)
  566. return str_to_uint64(value);
  567. return 0;
  568. }
  569. bool config_get_bool(config_t *config, const char *section, const char *name)
  570. {
  571. const char *value = config_get_string(config, section, name);
  572. if (value)
  573. return astrcmpi(value, "true") == 0 || !!str_to_uint64(value);
  574. return false;
  575. }
  576. double config_get_double(config_t *config, const char *section,
  577. const char *name)
  578. {
  579. const char *value = config_get_string(config, section, name);
  580. if (value)
  581. return os_strtod(value);
  582. return 0.0;
  583. }
  584. bool config_remove_value(config_t *config, const char *section,
  585. const char *name)
  586. {
  587. struct config_section *sec;
  588. struct config_item *item;
  589. bool success = false;
  590. pthread_mutex_lock(&config->mutex);
  591. HASH_FIND_STR(config->sections, section, sec);
  592. if (sec) {
  593. HASH_FIND_STR(sec->items, name, item);
  594. if (item) {
  595. HASH_DELETE(hh, sec->items, item);
  596. config_item_free(item);
  597. success = true;
  598. }
  599. }
  600. pthread_mutex_unlock(&config->mutex);
  601. return success;
  602. }
  603. const char *config_get_default_string(config_t *config, const char *section,
  604. const char *name)
  605. {
  606. const struct config_item *item;
  607. const char *value = NULL;
  608. pthread_mutex_lock(&config->mutex);
  609. item = config_find_item(config->defaults, section, name);
  610. if (item)
  611. value = item->value;
  612. pthread_mutex_unlock(&config->mutex);
  613. return value;
  614. }
  615. int64_t config_get_default_int(config_t *config, const char *section,
  616. const char *name)
  617. {
  618. const char *value = config_get_default_string(config, section, name);
  619. if (value)
  620. return str_to_int64(value);
  621. return 0;
  622. }
  623. uint64_t config_get_default_uint(config_t *config, const char *section,
  624. const char *name)
  625. {
  626. const char *value = config_get_default_string(config, section, name);
  627. if (value)
  628. return str_to_uint64(value);
  629. return 0;
  630. }
  631. bool config_get_default_bool(config_t *config, const char *section,
  632. const char *name)
  633. {
  634. const char *value = config_get_default_string(config, section, name);
  635. if (value)
  636. return astrcmpi(value, "true") == 0 || !!str_to_uint64(value);
  637. return false;
  638. }
  639. double config_get_default_double(config_t *config, const char *section,
  640. const char *name)
  641. {
  642. const char *value = config_get_default_string(config, section, name);
  643. if (value)
  644. return os_strtod(value);
  645. return 0.0;
  646. }
  647. bool config_has_user_value(config_t *config, const char *section,
  648. const char *name)
  649. {
  650. bool success;
  651. pthread_mutex_lock(&config->mutex);
  652. success = config_find_item(config->sections, section, name) != NULL;
  653. pthread_mutex_unlock(&config->mutex);
  654. return success;
  655. }
  656. bool config_has_default_value(config_t *config, const char *section,
  657. const char *name)
  658. {
  659. bool success;
  660. pthread_mutex_lock(&config->mutex);
  661. success = config_find_item(config->defaults, section, name) != NULL;
  662. pthread_mutex_unlock(&config->mutex);
  663. return success;
  664. }