res_config_curl.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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. * 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 fields 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, const struct ast_variable *fields)
  54. {
  55. struct ast_str *query, *buffer;
  56. char buf1[256], buf2[256];
  57. const struct ast_variable *field;
  58. char *stringp, *pair, *key;
  59. unsigned int start = 1;
  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 (field = fields; field; field = field->next) {
  73. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  74. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  75. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  76. start = 0;
  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 fields 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, const struct ast_variable *fields)
  114. {
  115. struct ast_str *query, *buffer;
  116. char buf1[256], buf2[256];
  117. const struct ast_variable *field;
  118. char *stringp, *line, *pair, *key, *initfield = NULL;
  119. int start = 1;
  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 (field = fields; field; field = field->next) {
  135. if (start) {
  136. char *op;
  137. initfield = ast_strdupa(field->name);
  138. if ((op = strchr(initfield, ' ')))
  139. *op = '\0';
  140. }
  141. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  142. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  143. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  144. start = 0;
  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. cat = ast_category_new_anonymous();
  159. if (!cat) {
  160. continue;
  161. }
  162. while ((pair = strsep(&line, "&"))) {
  163. key = strsep(&pair, "=");
  164. ast_uri_decode(key, ast_uri_http);
  165. if (pair) {
  166. ast_uri_decode(pair, ast_uri_http);
  167. }
  168. if (!strcasecmp(key, initfield) && pair) {
  169. ast_category_rename(cat, pair);
  170. }
  171. if (!ast_strlen_zero(key)) {
  172. var = ast_variable_new(key, S_OR(pair, ""), "");
  173. ast_variable_append(cat, var);
  174. }
  175. }
  176. ast_category_append(cfg, cat);
  177. }
  178. return cfg;
  179. }
  180. /*!
  181. * \brief Execute an UPDATE query
  182. * \param url
  183. * \param unused
  184. * \param keyfield where clause field
  185. * \param lookup value of field for where clause
  186. * \param fields list containing one or more field/value set(s).
  187. *
  188. * Update a database table, prepare the sql statement using keyfield and lookup
  189. * control the number of records to change. All values to be changed are stored in ap list.
  190. * Sub-in the values to the prepared statement and execute it.
  191. *
  192. * \retval number of rows affected
  193. * \retval -1 on failure
  194. */
  195. static int update_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, const struct ast_variable *fields)
  196. {
  197. struct ast_str *query, *buffer;
  198. char buf1[256], buf2[256];
  199. const struct ast_variable *field;
  200. char *stringp;
  201. int start = 1, rowcount = -1;
  202. if (!ast_custom_function_find("CURL")) {
  203. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  204. return -1;
  205. }
  206. if (!(query = ast_str_thread_get(&query_buf, 16))) {
  207. return -1;
  208. }
  209. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  210. return -1;
  211. }
  212. ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
  213. ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
  214. ast_str_set(&query, 0, "${CURL(%s/update?%s=%s,", url, buf1, buf2);
  215. for (field = fields; field; field = field->next) {
  216. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  217. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  218. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  219. start = 0;
  220. }
  221. ast_str_append(&query, 0, ")}");
  222. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  223. /* Line oriented output */
  224. stringp = ast_str_buffer(buffer);
  225. while (*stringp <= ' ') {
  226. stringp++;
  227. }
  228. sscanf(stringp, "%30d", &rowcount);
  229. if (rowcount >= 0) {
  230. return (int)rowcount;
  231. }
  232. return -1;
  233. }
  234. static int update2_curl(const char *url, const char *unused, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
  235. {
  236. struct ast_str *query, *buffer;
  237. char buf1[200], buf2[200];
  238. const struct ast_variable *field;
  239. char *stringp;
  240. unsigned int start = 1;
  241. int rowcount = -1;
  242. if (!ast_custom_function_find("CURL")) {
  243. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  244. return -1;
  245. }
  246. if (!(query = ast_str_thread_get(&query_buf, 1000)))
  247. return -1;
  248. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  249. return -1;
  250. }
  251. ast_str_set(&query, 0, "${CURL(%s/update?", url);
  252. for (field = lookup_fields; field; field = field->next) {
  253. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  254. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  255. ast_str_append(&query, 0, "%s%s=%s", !start ? "" : "&", buf1, buf2);
  256. start = 0;
  257. }
  258. ast_str_append(&query, 0, ",");
  259. start = 1;
  260. for (field = update_fields; field; field = field->next) {
  261. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  262. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  263. ast_str_append(&query, 0, "%s%s=%s", !start ? "" : "&", buf1, buf2);
  264. start = 0;
  265. }
  266. ast_str_append(&query, 0, ")}");
  267. /* Proxies work, by setting CURLOPT options in the [globals] section of
  268. * extensions.conf. Unfortunately, this means preloading pbx_config.so
  269. * so that they have an opportunity to be set prior to startup realtime
  270. * queries. */
  271. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  272. /* Line oriented output */
  273. stringp = ast_str_buffer(buffer);
  274. while (*stringp <= ' ') {
  275. stringp++;
  276. }
  277. sscanf(stringp, "%30d", &rowcount);
  278. if (rowcount >= 0) {
  279. return (int)rowcount;
  280. }
  281. return -1;
  282. }
  283. /*!
  284. * \brief Execute an INSERT query
  285. * \param url
  286. * \param unused
  287. * \param fields list containing one or more field/value set(s)
  288. *
  289. * Insert a new record into database table, prepare the sql statement.
  290. * All values to be changed are stored in ap list.
  291. * Sub-in the values to the prepared statement and execute it.
  292. *
  293. * \retval number of rows affected
  294. * \retval -1 on failure
  295. */
  296. static int store_curl(const char *url, const char *unused, const struct ast_variable *fields)
  297. {
  298. struct ast_str *query, *buffer;
  299. char buf1[256], buf2[256];
  300. const struct ast_variable *field;
  301. char *stringp;
  302. int start = 1, rowcount = -1;
  303. if (!ast_custom_function_find("CURL")) {
  304. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  305. return -1;
  306. }
  307. if (!(query = ast_str_thread_get(&query_buf, 1000))) {
  308. return -1;
  309. }
  310. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  311. return -1;
  312. }
  313. ast_str_set(&query, 0, "${CURL(%s/store,", url);
  314. for (field = fields; field; field = field->next) {
  315. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  316. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  317. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  318. start = 0;
  319. }
  320. ast_str_append(&query, 0, ")}");
  321. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  322. stringp = ast_str_buffer(buffer);
  323. while (*stringp <= ' ') {
  324. stringp++;
  325. }
  326. sscanf(stringp, "%30d", &rowcount);
  327. if (rowcount >= 0) {
  328. return rowcount;
  329. }
  330. return -1;
  331. }
  332. /*!
  333. * \brief Execute an DELETE query
  334. * \param url
  335. * \param unused
  336. * \param keyfield where clause field
  337. * \param lookup value of field for where clause
  338. * \param fields list containing one or more field/value set(s)
  339. *
  340. * Delete a row from a database table, prepare the sql statement using keyfield and lookup
  341. * control the number of records to change. Additional params to match rows are stored in ap list.
  342. * Sub-in the values to the prepared statement and execute it.
  343. *
  344. * \retval number of rows affected
  345. * \retval -1 on failure
  346. */
  347. static int destroy_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, const struct ast_variable *fields)
  348. {
  349. struct ast_str *query, *buffer;
  350. char buf1[200], buf2[200];
  351. const struct ast_variable *field;
  352. char *stringp;
  353. int start = 1, rowcount = -1;
  354. if (!ast_custom_function_find("CURL")) {
  355. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  356. return -1;
  357. }
  358. if (!(query = ast_str_thread_get(&query_buf, 1000))) {
  359. return -1;
  360. }
  361. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  362. return -1;
  363. }
  364. ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
  365. ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
  366. ast_str_set(&query, 0, "${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
  367. for (field = fields; field; field = field->next) {
  368. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  369. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  370. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  371. start = 0;
  372. }
  373. ast_str_append(&query, 0, ")}");
  374. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  375. /* Line oriented output */
  376. stringp = ast_str_buffer(buffer);
  377. while (*stringp <= ' ') {
  378. stringp++;
  379. }
  380. sscanf(stringp, "%30d", &rowcount);
  381. if (rowcount >= 0) {
  382. return (int)rowcount;
  383. }
  384. return -1;
  385. }
  386. static int require_curl(const char *url, const char *unused, va_list ap)
  387. {
  388. struct ast_str *query, *buffer;
  389. char *elm, field[256];
  390. int type, size, i = 0;
  391. if (!ast_custom_function_find("CURL")) {
  392. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  393. return -1;
  394. }
  395. if (!(query = ast_str_thread_get(&query_buf, 100))) {
  396. return -1;
  397. }
  398. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  399. return -1;
  400. }
  401. ast_str_set(&query, 0, "${CURL(%s/require,", url);
  402. while ((elm = va_arg(ap, char *))) {
  403. type = va_arg(ap, require_type);
  404. size = va_arg(ap, int);
  405. ast_uri_encode(elm, field, sizeof(field), ast_uri_http);
  406. ast_str_append(&query, 0, "%s%s=%s%%3A%d",
  407. i > 0 ? "&" : "",
  408. 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. i++;
  425. }
  426. ast_str_append(&query, 0, ")}");
  427. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  428. return atoi(ast_str_buffer(buffer));
  429. }
  430. 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)
  431. {
  432. struct ast_str *query, *buffer;
  433. char buf1[200];
  434. char *stringp, *line, *pair, *key;
  435. int last_cat_metric = -1, cat_metric = -1;
  436. struct ast_category *cat = NULL;
  437. char *cur_cat = "";
  438. char *category = "", *var_name = "", *var_val = "";
  439. struct ast_flags loader_flags = { 0 };
  440. if (!ast_custom_function_find("CURL")) {
  441. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  442. return NULL;
  443. }
  444. if (!(query = ast_str_thread_get(&query_buf, 100))) {
  445. return NULL;
  446. }
  447. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  448. return NULL;
  449. }
  450. ast_uri_encode(file, buf1, sizeof(buf1), ast_uri_http);
  451. ast_str_set(&query, 0, "${CURL(%s/static?file=%s)}", url, buf1);
  452. /* Do the CURL query */
  453. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  454. /* Line oriented output */
  455. stringp = ast_str_buffer(buffer);
  456. cat = ast_config_get_current_category(cfg);
  457. while ((line = strsep(&stringp, "\r\n"))) {
  458. if (ast_strlen_zero(line)) {
  459. continue;
  460. }
  461. while ((pair = strsep(&line, "&"))) {
  462. key = strsep(&pair, "=");
  463. ast_uri_decode(key, ast_uri_http);
  464. if (pair) {
  465. ast_uri_decode(pair, ast_uri_http);
  466. }
  467. if (!strcasecmp(key, "category")) {
  468. category = S_OR(pair, "");
  469. } else if (!strcasecmp(key, "var_name")) {
  470. var_name = S_OR(pair, "");
  471. } else if (!strcasecmp(key, "var_val")) {
  472. var_val = S_OR(pair, "");
  473. } else if (!strcasecmp(key, "cat_metric")) {
  474. cat_metric = pair ? atoi(pair) : 0;
  475. }
  476. }
  477. if (!strcmp(var_name, "#include")) {
  478. if (!ast_config_internal_load(var_val, cfg, loader_flags, "", who_asked))
  479. return NULL;
  480. }
  481. if (!cat || strcmp(category, cur_cat) || last_cat_metric != cat_metric) {
  482. cat = ast_category_new_dynamic(category);
  483. if (!cat) {
  484. break;
  485. }
  486. cur_cat = category;
  487. last_cat_metric = cat_metric;
  488. ast_category_append(cfg, cat);
  489. }
  490. ast_variable_append(cat, ast_variable_new(var_name, var_val, ""));
  491. }
  492. return cfg;
  493. }
  494. static struct ast_config_engine curl_engine = {
  495. .name = "curl",
  496. .load_func = config_curl,
  497. .realtime_func = realtime_curl,
  498. .realtime_multi_func = realtime_multi_curl,
  499. .store_func = store_curl,
  500. .destroy_func = destroy_curl,
  501. .update_func = update_curl,
  502. .update2_func = update2_curl,
  503. .require_func = require_curl,
  504. };
  505. static int reload_module(void)
  506. {
  507. struct ast_flags flags = { CONFIG_FLAG_NOREALTIME };
  508. struct ast_config *cfg;
  509. struct ast_variable *var;
  510. if (!(cfg = ast_config_load("res_curl.conf", flags))) {
  511. return 0;
  512. } else if (cfg == CONFIG_STATUS_FILEINVALID) {
  513. ast_log(LOG_WARNING, "res_curl.conf could not be parsed!\n");
  514. return 0;
  515. }
  516. if (!(var = ast_variable_browse(cfg, "globals")) && !(var = ast_variable_browse(cfg, "global")) && !(var = ast_variable_browse(cfg, "general"))) {
  517. ast_log(LOG_WARNING, "[globals] not found in res_curl.conf\n");
  518. ast_config_destroy(cfg);
  519. return 0;
  520. }
  521. for (; var; var = var->next) {
  522. if (strncmp(var->name, "CURLOPT(", 8)) {
  523. char name[256];
  524. snprintf(name, sizeof(name), "CURLOPT(%s)", var->name);
  525. pbx_builtin_setvar_helper(NULL, name, var->value);
  526. } else {
  527. pbx_builtin_setvar_helper(NULL, var->name, var->value);
  528. }
  529. }
  530. ast_config_destroy(cfg);
  531. return 0;
  532. }
  533. static int unload_module(void)
  534. {
  535. ast_config_engine_deregister(&curl_engine);
  536. return 0;
  537. }
  538. static int load_module(void)
  539. {
  540. if (!ast_module_check("res_curl.so")) {
  541. if (ast_load_resource("res_curl.so") != AST_MODULE_LOAD_SUCCESS) {
  542. ast_log(LOG_ERROR, "Cannot load res_curl, so res_config_curl cannot be loaded\n");
  543. return AST_MODULE_LOAD_DECLINE;
  544. }
  545. }
  546. if (!ast_module_check("func_curl.so")) {
  547. if (ast_load_resource("func_curl.so") != AST_MODULE_LOAD_SUCCESS) {
  548. ast_log(LOG_ERROR, "Cannot load func_curl, so res_config_curl cannot be loaded\n");
  549. return AST_MODULE_LOAD_DECLINE;
  550. }
  551. }
  552. reload_module();
  553. ast_config_engine_register(&curl_engine);
  554. return 0;
  555. }
  556. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Realtime Curl configuration",
  557. .support_level = AST_MODULE_SUPPORT_CORE,
  558. .load = load_module,
  559. .unload = unload_module,
  560. .reload = reload_module,
  561. .load_pri = AST_MODPRI_REALTIME_DRIVER,
  562. );