res_config_curl.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667
  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. 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 fields 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, const struct ast_variable *fields)
  195. {
  196. struct ast_str *query, *buffer;
  197. char buf1[256], buf2[256];
  198. const struct ast_variable *field;
  199. char *stringp;
  200. int start = 1, 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 (field = fields; field; field = field->next) {
  215. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  216. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  217. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  218. start = 0;
  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, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
  234. {
  235. struct ast_str *query, *buffer;
  236. char buf1[200], buf2[200];
  237. const struct ast_variable *field;
  238. char *stringp;
  239. unsigned int start = 1;
  240. int rowcount = -1;
  241. if (!ast_custom_function_find("CURL")) {
  242. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  243. return -1;
  244. }
  245. if (!(query = ast_str_thread_get(&query_buf, 1000)))
  246. return -1;
  247. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  248. return -1;
  249. }
  250. ast_str_set(&query, 0, "${CURL(%s/update?", url);
  251. for (field = lookup_fields; field; field = field->next) {
  252. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  253. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  254. ast_str_append(&query, 0, "%s%s=%s", !start ? "" : "&", buf1, buf2);
  255. start = 0;
  256. }
  257. ast_str_append(&query, 0, ",");
  258. start = 1;
  259. for (field = update_fields; field; field = field->next) {
  260. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  261. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  262. ast_str_append(&query, 0, "%s%s=%s", !start ? "" : "&", buf1, buf2);
  263. start = 0;
  264. }
  265. ast_str_append(&query, 0, ")}");
  266. /* Proxies work, by setting CURLOPT options in the [globals] section of
  267. * extensions.conf. Unfortunately, this means preloading pbx_config.so
  268. * so that they have an opportunity to be set prior to startup realtime
  269. * queries. */
  270. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  271. /* Line oriented output */
  272. stringp = ast_str_buffer(buffer);
  273. while (*stringp <= ' ') {
  274. stringp++;
  275. }
  276. sscanf(stringp, "%30d", &rowcount);
  277. if (rowcount >= 0) {
  278. return (int)rowcount;
  279. }
  280. return -1;
  281. }
  282. /*!
  283. * \brief Execute an INSERT query
  284. * \param url
  285. * \param unused
  286. * \param fields list containing one or more field/value set(s)
  287. *
  288. * Insert a new record into database table, prepare the sql statement.
  289. * All values to be changed are stored in ap list.
  290. * Sub-in the values to the prepared statement and execute it.
  291. *
  292. * \retval number of rows affected
  293. * \retval -1 on failure
  294. */
  295. static int store_curl(const char *url, const char *unused, const struct ast_variable *fields)
  296. {
  297. struct ast_str *query, *buffer;
  298. char buf1[256], buf2[256];
  299. const struct ast_variable *field;
  300. char *stringp;
  301. int start = 1, rowcount = -1;
  302. if (!ast_custom_function_find("CURL")) {
  303. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  304. return -1;
  305. }
  306. if (!(query = ast_str_thread_get(&query_buf, 1000))) {
  307. return -1;
  308. }
  309. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  310. return -1;
  311. }
  312. ast_str_set(&query, 0, "${CURL(%s/store,", url);
  313. for (field = fields; field; field = field->next) {
  314. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  315. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  316. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  317. start = 0;
  318. }
  319. ast_str_append(&query, 0, ")}");
  320. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  321. stringp = ast_str_buffer(buffer);
  322. while (*stringp <= ' ') {
  323. stringp++;
  324. }
  325. sscanf(stringp, "%30d", &rowcount);
  326. if (rowcount >= 0) {
  327. return rowcount;
  328. }
  329. return -1;
  330. }
  331. /*!
  332. * \brief Execute an DELETE query
  333. * \param url
  334. * \param unused
  335. * \param keyfield where clause field
  336. * \param lookup value of field for where clause
  337. * \param fields list containing one or more field/value set(s)
  338. *
  339. * Delete a row from a database table, prepare the sql statement using keyfield and lookup
  340. * control the number of records to change. Additional params to match rows are stored in ap list.
  341. * Sub-in the values to the prepared statement and execute it.
  342. *
  343. * \retval number of rows affected
  344. * \retval -1 on failure
  345. */
  346. static int destroy_curl(const char *url, const char *unused, const char *keyfield, const char *lookup, const struct ast_variable *fields)
  347. {
  348. struct ast_str *query, *buffer;
  349. char buf1[200], buf2[200];
  350. const struct ast_variable *field;
  351. char *stringp;
  352. int start = 1, rowcount = -1;
  353. if (!ast_custom_function_find("CURL")) {
  354. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  355. return -1;
  356. }
  357. if (!(query = ast_str_thread_get(&query_buf, 1000))) {
  358. return -1;
  359. }
  360. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  361. return -1;
  362. }
  363. ast_uri_encode(keyfield, buf1, sizeof(buf1), ast_uri_http);
  364. ast_uri_encode(lookup, buf2, sizeof(buf2), ast_uri_http);
  365. ast_str_set(&query, 0, "${CURL(%s/destroy,%s=%s&", url, buf1, buf2);
  366. for (field = fields; field; field = field->next) {
  367. ast_uri_encode(field->name, buf1, sizeof(buf1), ast_uri_http);
  368. ast_uri_encode(field->value, buf2, sizeof(buf2), ast_uri_http);
  369. ast_str_append(&query, 0, "%s%s=%s", !start ? "&" : "", buf1, buf2);
  370. start = 0;
  371. }
  372. ast_str_append(&query, 0, ")}");
  373. ast_str_substitute_variables(&buffer, 0, NULL, ast_str_buffer(query));
  374. /* Line oriented output */
  375. stringp = ast_str_buffer(buffer);
  376. while (*stringp <= ' ') {
  377. stringp++;
  378. }
  379. sscanf(stringp, "%30d", &rowcount);
  380. if (rowcount >= 0) {
  381. return (int)rowcount;
  382. }
  383. return -1;
  384. }
  385. static int require_curl(const char *url, const char *unused, va_list ap)
  386. {
  387. struct ast_str *query, *buffer;
  388. char *elm, field[256];
  389. int type, size, i = 0;
  390. if (!ast_custom_function_find("CURL")) {
  391. ast_log(LOG_ERROR, "func_curl.so must be loaded in order to use res_config_curl.so!!\n");
  392. return -1;
  393. }
  394. if (!(query = ast_str_thread_get(&query_buf, 100))) {
  395. return -1;
  396. }
  397. if (!(buffer = ast_str_thread_get(&result_buf, 16))) {
  398. return -1;
  399. }
  400. ast_str_set(&query, 0, "${CURL(%s/require,", url);
  401. while ((elm = va_arg(ap, char *))) {
  402. type = va_arg(ap, require_type);
  403. size = va_arg(ap, int);
  404. ast_uri_encode(elm, field, sizeof(field), ast_uri_http);
  405. ast_str_append(&query, 0, "%s%s=%s%%3A%d",
  406. i > 0 ? "&" : "",
  407. field,
  408. type == RQ_CHAR ? "char" :
  409. type == RQ_INTEGER1 ? "integer1" :
  410. type == RQ_UINTEGER1 ? "uinteger1" :
  411. type == RQ_INTEGER2 ? "integer2" :
  412. type == RQ_UINTEGER2 ? "uinteger2" :
  413. type == RQ_INTEGER3 ? "integer3" :
  414. type == RQ_UINTEGER3 ? "uinteger3" :
  415. type == RQ_INTEGER4 ? "integer4" :
  416. type == RQ_UINTEGER4 ? "uinteger4" :
  417. type == RQ_INTEGER8 ? "integer8" :
  418. type == RQ_UINTEGER8 ? "uinteger8" :
  419. type == RQ_DATE ? "date" :
  420. type == RQ_DATETIME ? "datetime" :
  421. type == RQ_FLOAT ? "float" :
  422. "unknown", size);
  423. i++;
  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. return 0;
  534. }
  535. static int load_module(void)
  536. {
  537. if (!ast_module_check("res_curl.so")) {
  538. if (ast_load_resource("res_curl.so") != AST_MODULE_LOAD_SUCCESS) {
  539. ast_log(LOG_ERROR, "Cannot load res_curl, so res_config_curl cannot be loaded\n");
  540. return AST_MODULE_LOAD_DECLINE;
  541. }
  542. }
  543. if (!ast_module_check("func_curl.so")) {
  544. if (ast_load_resource("func_curl.so") != AST_MODULE_LOAD_SUCCESS) {
  545. ast_log(LOG_ERROR, "Cannot load func_curl, so res_config_curl cannot be loaded\n");
  546. return AST_MODULE_LOAD_DECLINE;
  547. }
  548. }
  549. reload_module();
  550. ast_config_engine_register(&curl_engine);
  551. return 0;
  552. }
  553. AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Realtime Curl configuration",
  554. .support_level = AST_MODULE_SUPPORT_CORE,
  555. .load = load_module,
  556. .unload = unload_module,
  557. .reload = reload_module,
  558. .load_pri = AST_MODPRI_REALTIME_DRIVER,
  559. );