res_config_curl.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2008, Digium, Inc.
  5. *
  6. * Tilghman Lesher <res_config_curl_v1@the-tilghman.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. *
  20. * \brief curl plugin for portable configuration engine
  21. *
  22. * \author Tilghman Lesher <res_config_curl_v1@the-tilghman.com>
  23. *
  24. * \extref Depends on the CURL library - http://curl.haxx.se/
  25. *
  26. */
  27. /*** MODULEINFO
  28. <depend>curl</depend>
  29. <support_level>core</support_level>
  30. ***/
  31. #include "asterisk.h"
  32. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  33. #include <curl/curl.h>
  34. #include "asterisk/file.h"
  35. #include "asterisk/channel.h"
  36. #include "asterisk/pbx.h"
  37. #include "asterisk/config.h"
  38. #include "asterisk/module.h"
  39. #include "asterisk/lock.h"
  40. #include "asterisk/utils.h"
  41. #include "asterisk/threadstorage.h"
  42. AST_THREADSTORAGE(query_buf);
  43. AST_THREADSTORAGE(result_buf);
  44. /*!
  45. * \brief Execute a curl query and return ast_variable list
  46. * \param url The base URL from which to retrieve data
  47. * \param unused Not currently used
  48. * \param ap list containing one or more field/operator/value set.
  49. *
  50. * \retval var on success
  51. * \retval NULL on failure
  52. */
  53. static struct ast_variable *realtime_curl(const char *url, const char *unused, va_list ap)
  54. {
  55. struct ast_str *query, *buffer;
  56. char buf1[256], buf2[256];
  57. const char *newparam, *newval;
  58. char *stringp, *pair, *key;
  59. int i;
  60. struct ast_variable *var = NULL, *prev = NULL;
  61. if (!ast_custom_function_find("CURL")) {
  62. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  63. return NULL;
  64. }
  65. if (!(query = ast_str_thread_get(&query_buf, 16))) {
  66. return NULL;
  67. }
  68. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  69. return NULL;
  70. }
  71. ast_str_set(&query, 0, "${CURL(%s/single,", url);
  72. for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
  73. newval = va_arg(ap, const char *);
  74. ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
  75. ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
  76. ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
  77. }
  78. ast_str_append(&query, 0, ")}");
  79. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  80. /* Remove any trailing newline characters */
  81. if ((stringp = strchr(ast_str_buffer(buffer), '\r')) || (stringp = strchr(ast_str_buffer(buffer), '\n'))) {
  82. *stringp = '\0';
  83. }
  84. stringp = ast_str_buffer(buffer);
  85. while ((pair = strsep(&stringp, "&"))) {
  86. key = strsep(&pair, "=");
  87. ast_uri_decode(key, ast_uri_http);
  88. if (pair) {
  89. ast_uri_decode(pair, ast_uri_http);
  90. }
  91. if (!ast_strlen_zero(key)) {
  92. if (prev) {
  93. prev->next = ast_variable_new(key, S_OR(pair, ""), "");
  94. if (prev->next) {
  95. prev = prev->next;
  96. }
  97. } else {
  98. prev = var = ast_variable_new(key, S_OR(pair, ""), "");
  99. }
  100. }
  101. }
  102. return var;
  103. }
  104. /*!
  105. * \brief Excute an Select query and return ast_config list
  106. * \param url
  107. * \param unused
  108. * \param ap list containing one or more field/operator/value set.
  109. *
  110. * \retval struct ast_config pointer on success
  111. * \retval NULL on failure
  112. */
  113. static struct ast_config *realtime_multi_curl(const char *url, const char *unused, va_list ap)
  114. {
  115. struct ast_str *query, *buffer;
  116. char buf1[256], buf2[256];
  117. const char *newparam, *newval;
  118. char *stringp, *line, *pair, *key, *initfield = NULL;
  119. int i;
  120. struct ast_variable *var = NULL;
  121. struct ast_config *cfg = NULL;
  122. struct ast_category *cat = NULL;
  123. if (!ast_custom_function_find("CURL")) {
  124. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  125. return NULL;
  126. }
  127. if (!(query = ast_str_thread_get(&query_buf, 16))) {
  128. return NULL;
  129. }
  130. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  131. return NULL;
  132. }
  133. ast_str_set(&query, 0, "${CURL(%s/multi,", url);
  134. for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
  135. newval = va_arg(ap, const char *);
  136. if (i == 0) {
  137. char *op;
  138. initfield = ast_strdupa(newparam);
  139. if ((op = strchr(initfield, ' ')))
  140. *op = '\0';
  141. }
  142. ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
  143. ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
  144. ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
  145. }
  146. ast_str_append(&query, 0, ")}");
  147. /* Do the CURL query */
  148. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  149. if (!(cfg = ast_config_new())) {
  150. return NULL;
  151. }
  152. /* Line oriented output */
  153. stringp = ast_str_buffer(buffer);
  154. while ((line = strsep(&stringp, "\r\n"))) {
  155. if (ast_strlen_zero(line)) {
  156. continue;
  157. }
  158. if (!(cat = ast_category_new("", "", 99999))) {
  159. continue;
  160. }
  161. while ((pair = strsep(&line, "&"))) {
  162. key = strsep(&pair, "=");
  163. ast_uri_decode(key, ast_uri_http);
  164. if (pair) {
  165. ast_uri_decode(pair, ast_uri_http);
  166. }
  167. if (!strcasecmp(key, initfield) && pair) {
  168. ast_category_rename(cat, pair);
  169. }
  170. if (!ast_strlen_zero(key)) {
  171. var = ast_variable_new(key, S_OR(pair, ""), "");
  172. ast_variable_append(cat, var);
  173. }
  174. }
  175. ast_category_append(cfg, cat);
  176. }
  177. return cfg;
  178. }
  179. /*!
  180. * \brief Execute an UPDATE query
  181. * \param url
  182. * \param unused
  183. * \param keyfield where clause field
  184. * \param lookup value of field for where clause
  185. * \param ap list containing one or more field/value set(s).
  186. *
  187. * Update a database table, prepare the sql statement using keyfield and lookup
  188. * control the number of records to change. All values to be changed are stored in ap list.
  189. * Sub-in the values to the prepared statement and execute it.
  190. *
  191. * \retval number of rows affected
  192. * \retval -1 on failure
  193. */
  194. static int update_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, va_list ap)
  195. {
  196. struct ast_str *query, *buffer;
  197. char buf1[256], buf2[256];
  198. const char *newparam, *newval;
  199. char *stringp;
  200. int i, rowcount = -1;
  201. if (!ast_custom_function_find("CURL")) {
  202. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  203. return -1;
  204. }
  205. if (!(query = ast_str_thread_get(&query_buf, 16))) {
  206. return -1;
  207. }
  208. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  209. return -1;
  210. }
  211. ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
  212. ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
  213. ast_str_set(&query, 0, "${CURL(%s/update?%s=%s,", url, buf1, buf2);
  214. for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
  215. newval = va_arg(ap, const char *);
  216. ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
  217. ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
  218. ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
  219. }
  220. ast_str_append(&query, 0, ")}");
  221. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  222. /* Line oriented output */
  223. stringp = ast_str_buffer(buffer);
  224. while (*stringp <= ' ') {
  225. stringp++;
  226. }
  227. sscanf(stringp, "%30d", &rowcount);
  228. if (rowcount >= 0) {
  229. return (int)rowcount;
  230. }
  231. return -1;
  232. }
  233. static int update2_curl(const char *url, const char *unused, va_list ap)
  234. {
  235. struct ast_str *query, *buffer;
  236. char buf1[200], buf2[200];
  237. const char *newparam, *newval;
  238. char *stringp;
  239. int rowcount = -1, lookup = 1, first = 1;
  240. if (!ast_custom_function_find("CURL")) {
  241. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  242. return -1;
  243. }
  244. if (!(query = ast_str_thread_get(&query_buf, 1000)))
  245. return -1;
  246. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  247. return -1;
  248. }
  249. ast_str_set(&query, 0, "${CURL(%s/update?", url);
  250. for (;;) {
  251. if ((newparam = va_arg(ap, const char *)) == SENTINEL) {
  252. if (lookup) {
  253. lookup = 0;
  254. ast_str_append(&query, 0, ",");
  255. /* Back to the first parameter; we don't need a starting '&' */
  256. first = 1;
  257. continue;
  258. } else {
  259. break;
  260. }
  261. }
  262. newval = va_arg(ap, const char *);
  263. ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
  264. ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
  265. ast_str_append(&query, 0, "%s%s=%s", first ? "" : "&", buf1, buf2);
  266. first = 0;
  267. }
  268. ast_str_append(&query, 0, ")}");
  269. /* Proxies work, by setting CURLOPT options in the [globals] section of
  270. * extensions.conf. Unfortunately, this means preloading pbx_config.so
  271. * so that they have an opportunity to be set prior to startup realtime
  272. * queries. */
  273. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  274. /* Line oriented output */
  275. stringp = ast_str_buffer(buffer);
  276. while (*stringp <= ' ') {
  277. stringp++;
  278. }
  279. sscanf(stringp, "%30d", &rowcount);
  280. if (rowcount >= 0) {
  281. return (int)rowcount;
  282. }
  283. return -1;
  284. }
  285. /*!
  286. * \brief Execute an INSERT query
  287. * \param url
  288. * \param unused
  289. * \param ap list containing one or more field/value set(s)
  290. *
  291. * Insert a new record into database table, prepare the sql statement.
  292. * All values to be changed are stored in ap list.
  293. * Sub-in the values to the prepared statement and execute it.
  294. *
  295. * \retval number of rows affected
  296. * \retval -1 on failure
  297. */
  298. static int store_curl(const char *url, const char *unused, va_list ap)
  299. {
  300. struct ast_str *query, *buffer;
  301. char buf1[256], buf2[256];
  302. const char *newparam, *newval;
  303. char *stringp;
  304. int i, rowcount = -1;
  305. if (!ast_custom_function_find("CURL")) {
  306. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  307. return -1;
  308. }
  309. if (!(query = ast_str_thread_get(&query_buf, 1000))) {
  310. return -1;
  311. }
  312. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  313. return -1;
  314. }
  315. ast_str_set(&query, 0, "${CURL(%s/store,", url);
  316. for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
  317. newval = va_arg(ap, const char *);
  318. ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
  319. ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
  320. ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
  321. }
  322. ast_str_append(&query, 0, ")}");
  323. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  324. stringp = ast_str_buffer(buffer);
  325. while (*stringp <= ' ') {
  326. stringp++;
  327. }
  328. sscanf(stringp, "%30d", &rowcount);
  329. if (rowcount >= 0) {
  330. return rowcount;
  331. }
  332. return -1;
  333. }
  334. /*!
  335. * \brief Execute an DELETE query
  336. * \param url
  337. * \param unused
  338. * \param keyfield where clause field
  339. * \param lookup value of field for where clause
  340. * \param ap list containing one or more field/value set(s)
  341. *
  342. * Delete a row from a database table, prepare the sql statement using keyfield and lookup
  343. * control the number of records to change. Additional params to match rows are stored in ap list.
  344. * Sub-in the values to the prepared statement and execute it.
  345. *
  346. * \retval number of rows affected
  347. * \retval -1 on failure
  348. */
  349. static int destroy_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, va_list ap)
  350. {
  351. struct ast_str *query, *buffer;
  352. char buf1[200], buf2[200];
  353. const char *newparam, *newval;
  354. char *stringp;
  355. int i, rowcount = -1;
  356. if (!ast_custom_function_find("CURL")) {
  357. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  358. return -1;
  359. }
  360. if (!(query = ast_str_thread_get(&query_buf, 1000))) {
  361. return -1;
  362. }
  363. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  364. return -1;
  365. }
  366. ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
  367. ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
  368. ast_str_set(&query, 0, "${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
  369. for (i = 0; (newparam = va_arg(ap, const char *)); i++) {
  370. newval = va_arg(ap, const char *);
  371. ast_uri_encode(newparam, buf1, sizeof(buf1), ast_uri_http);
  372. ast_uri_encode(newval, buf2, sizeof(buf2), ast_uri_http);
  373. ast_str_append(&query, 0, "%s%s=%s", i > 0 ? "&" : "", buf1, buf2);
  374. }
  375. ast_str_append(&query, 0, ")}");
  376. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  377. /* Line oriented output */
  378. stringp = ast_str_buffer(buffer);
  379. while (*stringp <= ' ') {
  380. stringp++;
  381. }
  382. sscanf(stringp, "%30d", &rowcount);
  383. if (rowcount >= 0) {
  384. return (int)rowcount;
  385. }
  386. return -1;
  387. }
  388. static int require_curl(const char *url, const char *unused, va_list ap)
  389. {
  390. struct ast_str *query, *buffer;
  391. char *elm, field[256];
  392. int type, size;
  393. if (!ast_custom_function_find("CURL")) {
  394. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  395. return -1;
  396. }
  397. if (!(query = ast_str_thread_get(&query_buf, 100))) {
  398. return -1;
  399. }
  400. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  401. return -1;
  402. }
  403. ast_str_set(&query, 0, "${CURL(%s/require,", url);
  404. while ((elm = va_arg(ap, char *))) {
  405. type = va_arg(ap, require_type);
  406. size = va_arg(ap, int);
  407. ast_uri_encode(elm, field, sizeof(field), ast_uri_http);
  408. ast_str_append(&query, 0, "%s=%s%%3A%d", field,
  409. type == RQ_CHAR ? "char" :
  410. type == RQ_INTEGER1 ? "integer1" :
  411. type == RQ_UINTEGER1 ? "uinteger1" :
  412. type == RQ_INTEGER2 ? "integer2" :
  413. type == RQ_UINTEGER2 ? "uinteger2" :
  414. type == RQ_INTEGER3 ? "integer3" :
  415. type == RQ_UINTEGER3 ? "uinteger3" :
  416. type == RQ_INTEGER4 ? "integer4" :
  417. type == RQ_UINTEGER4 ? "uinteger4" :
  418. type == RQ_INTEGER8 ? "integer8" :
  419. type == RQ_UINTEGER8 ? "uinteger8" :
  420. type == RQ_DATE ? "date" :
  421. type == RQ_DATETIME ? "datetime" :
  422. type == RQ_FLOAT ? "float" :
  423. "unknown", size);
  424. }
  425. ast_str_append(&query, 0, ")}");
  426. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  427. return atoi(ast_str_buffer(buffer));
  428. }
  429. static struct ast_config *config_curl(const char *url, const char *unused, const char *file, struct ast_config *cfg, struct ast_flags flags, const char *sugg_incl, const char *who_asked)
  430. {
  431. struct ast_str *query, *buffer;
  432. char buf1[200];
  433. char *stringp, *line, *pair, *key;
  434. int last_cat_metric = -1, cat_metric = -1;
  435. struct ast_category *cat = NULL;
  436. char *cur_cat = "";
  437. char *category = "", *var_name = "", *var_val = "";
  438. struct ast_flags loader_flags = { 0 };
  439. if (!ast_custom_function_find("CURL")) {
  440. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  441. return NULL;
  442. }
  443. if (!(query = ast_str_thread_get(&query_buf, 100))) {
  444. return NULL;
  445. }
  446. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  447. return NULL;
  448. }
  449. ast_uri_encode(file, buf1, sizeof(buf1), ast_uri_http);
  450. ast_str_set(&query, 0, "${CURL(%s/static?file=%s)}", url, buf1);
  451. /* Do the CURL query */
  452. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  453. /* Line oriented output */
  454. stringp = ast_str_buffer(buffer);
  455. cat = ast_config_get_current_category(cfg);
  456. while ((line = strsep(&stringp, "\r\n"))) {
  457. if (ast_strlen_zero(line)) {
  458. continue;
  459. }
  460. while ((pair = strsep(&line, "&"))) {
  461. key = strsep(&pair, "=");
  462. ast_uri_decode(key, ast_uri_http);
  463. if (pair) {
  464. ast_uri_decode(pair, ast_uri_http);
  465. }
  466. if (!strcasecmp(key, "category")) {
  467. category = S_OR(pair, "");
  468. } else if (!strcasecmp(key, "var_name")) {
  469. var_name = S_OR(pair, "");
  470. } else if (!strcasecmp(key, "var_val")) {
  471. var_val = S_OR(pair, "");
  472. } else if (!strcasecmp(key, "cat_metric")) {
  473. cat_metric = pair ? atoi(pair) : 0;
  474. }
  475. }
  476. if (!strcmp(var_name, "#include")) {
  477. if (!ast_config_internal_load(var_val, cfg, loader_flags, "", who_asked))
  478. return NULL;
  479. }
  480. if (!cat || strcmp(category, cur_cat) || last_cat_metric != cat_metric) {
  481. if (!(cat = ast_category_new(category, "", 99999)))
  482. break;
  483. cur_cat = category;
  484. last_cat_metric = cat_metric;
  485. ast_category_append(cfg, cat);
  486. }
  487. ast_variable_append(cat, ast_variable_new(var_name, var_val, ""));
  488. }
  489. return cfg;
  490. }
  491. static struct ast_config_engine curl_engine = {
  492. .name = "curl",
  493. .load_func = config_curl,
  494. .realtime_func = realtime_curl,
  495. .realtime_multi_func = realtime_multi_curl,
  496. .store_func = store_curl,
  497. .destroy_func = destroy_curl,
  498. .update_func = update_curl,
  499. .update2_func = update2_curl,
  500. .require_func = require_curl,
  501. };
  502. static int reload_module(void)
  503. {
  504. struct ast_flags flags = { CONFIG_FLAG_NOREALTIME };
  505. struct ast_config *cfg;
  506. struct ast_variable *var;
  507. if (!(cfg = ast_config_load("res_curl.conf", flags))) {
  508. return 0;
  509. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  510. ast_log(LOG_WARNING, "res_curl.conf could not be parsed!\n");
  511. return 0;
  512. }
  513. if (!(var = ast_variable_browse(cfg, "globals")) && !(var = ast_variable_browse(cfg, "global")) && !(var = ast_variable_browse(cfg, "general"))) {
  514. ast_log(LOG_WARNING, "[globals] not found in res_curl.conf\n");
  515. ast_config_destroy(cfg);
  516. return 0;
  517. }
  518. for (; var; var = var->next) {
  519. if (strncmp(var->name, "CURLOPT(", 8)) {
  520. char name[256];
  521. snprintf(name, sizeof(name), "CURLOPT(%s)", var->name);
  522. pbx_builtin_setvar_helper(NULL, name, var->value);
  523. } else {
  524. pbx_builtin_setvar_helper(NULL, var->name, var->value);
  525. }
  526. }
  527. ast_config_destroy(cfg);
  528. return 0;
  529. }
  530. static int unload_module(void)
  531. {
  532. ast_config_engine_deregister(&curl_engine);
  533. ast_verb(1, "res_config_curl unloaded.\n");
  534. return 0;
  535. }
  536. static int load_module(void)
  537. {
  538. if (!ast_module_check("res_curl.so")) {
  539. if (ast_load_resource("res_curl.so") != AST_MODULE_LOAD_SUCCESS) {
  540. ast_log(LOG_ERROR, "Cannot load res_curl, so res_config_curl cannot be loaded\n");
  541. return AST_MODULE_LOAD_DECLINE;
  542. }
  543. }
  544. if (!ast_module_check("func_curl.so")) {
  545. if (ast_load_resource("func_curl.so") != AST_MODULE_LOAD_SUCCESS) {
  546. ast_log(LOG_ERROR, "Cannot load func_curl, so res_config_curl cannot be loaded\n");
  547. return AST_MODULE_LOAD_DECLINE;
  548. }
  549. }
  550. reload_module();
  551. ast_config_engine_register(&curl_engine);
  552. ast_verb(1, "res_config_curl loaded.\n");
  553. return 0;
  554. }
  555. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Realtime Curl configuration",
  556. .load = load_module,
  557. .unload = unload_module,
  558. .reload = reload_module,
  559. .load_pri = AST_MODPRI_REALTIME_DRIVER,
  560. );