Asterisk - The Open Source Telephony Project  18.5.0
resource_asterisk.c
Go to the documentation of this file.
1 /* -*- C -*-
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 2012 - 2013, Digium, Inc.
5  *
6  * David M. Lee, II <[email protected]>
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 
19 /*! \file
20  *
21  * \brief Implementation for ARI stubs.
22  *
23  * \author David M. Lee, II <[email protected]>
24  */
25 
26 /*** MODULEINFO
27  <support_level>core</support_level>
28  ***/
29 
30 #include "asterisk.h"
31 
32 #include "asterisk/ast_version.h"
33 #include "asterisk/buildinfo.h"
34 #include "asterisk/logger.h"
35 #include "asterisk/module.h"
36 #include "asterisk/paths.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/sorcery.h"
39 #include "resource_asterisk.h"
40 
41 static void return_sorcery_object(struct ast_sorcery *sorcery, void *sorcery_obj,
42  struct ast_ari_response *response)
43 {
44  RAII_VAR(struct ast_json *, return_set, NULL, ast_json_unref);
45  struct ast_variable *change_set;
46  struct ast_variable *it_change_set;
47 
48  return_set = ast_json_array_create();
49  if (!return_set) {
51  return;
52  }
53 
54  /* Note that we can't use the sorcery JSON change set directly,
55  * as it will hand us back an Object (with fields), and we need
56  * a more generic representation of whatever the API call asked
57  * for, i.e., a list of tuples.
58  */
59  change_set = ast_sorcery_objectset_create(sorcery, sorcery_obj);
60  if (!change_set) {
62  return;
63  }
64 
65  for (it_change_set = change_set; it_change_set; it_change_set = it_change_set->next) {
66  struct ast_json *tuple;
67 
68  tuple = ast_json_pack("{s: s, s: s}",
69  "attribute", it_change_set->name,
70  "value", it_change_set->value);
71  if (!tuple) {
72  ast_variables_destroy(change_set);
74  return;
75  }
76 
77  if (ast_json_array_append(return_set, tuple)) {
78  ast_json_unref(tuple);
79  ast_variables_destroy(change_set);
81  return;
82  }
83  }
84  ast_variables_destroy(change_set);
85 
86  ast_ari_response_ok(response, ast_json_ref(return_set));
87 }
88 
91  struct ast_ari_response *response)
92 {
94  RAII_VAR(struct ast_sorcery_object_type *, object_type, NULL, ao2_cleanup);
95  RAII_VAR(void *, sorcery_obj, NULL, ao2_cleanup);
96 
97 
99  if (!sorcery) {
101  response, 404, "Not Found",
102  "configClass '%s' not found",
103  args->config_class);
104  return;
105  }
106 
107  object_type = ast_sorcery_get_object_type(sorcery, args->object_type);
108  if (!object_type) {
110  response, 404, "Not Found",
111  "objectType '%s' not found",
112  args->object_type);
113  return;
114  }
115 
116  sorcery_obj = ast_sorcery_retrieve_by_id(sorcery, args->object_type, args->id);
117  if (!sorcery_obj) {
119  response, 404, "Not Found",
120  "Object with id '%s' not found",
121  args->id);
122  return;
123  }
124 
125  return_sorcery_object(sorcery, sorcery_obj, response);
126 }
127 
129 {
131  RAII_VAR(struct ast_sorcery_object_type *, object_type, NULL, ao2_cleanup);
132  RAII_VAR(void *, sorcery_obj, NULL, ao2_cleanup);
133  struct ast_json *fields;
134  struct ast_variable *update_set = NULL;
135  int created = 0;
136 
138  if (!sorcery) {
140  response, 404, "Not Found",
141  "configClass '%s' not found",
142  args->config_class);
143  return;
144  }
145 
146  object_type = ast_sorcery_get_object_type(sorcery, args->object_type);
147  if (!object_type) {
149  response, 404, "Not Found",
150  "objectType '%s' not found",
151  args->object_type);
152  return;
153  }
154 
155  sorcery_obj = ast_sorcery_retrieve_by_id(sorcery, args->object_type, args->id);
156  if (!sorcery_obj) {
157  ast_debug(5, "Sorcery object '%s' does not exist; creating it\n", args->id);
158  sorcery_obj = ast_sorcery_alloc(sorcery, args->object_type, args->id);
159  if (!sorcery_obj) {
161  return;
162  }
163 
164  created = 1;
165  } else {
166  void *copy;
167 
168  copy = ast_sorcery_copy(sorcery, sorcery_obj);
169  if (!copy) {
171  return;
172  }
173 
174  ao2_ref(sorcery_obj, -1);
175  sorcery_obj = copy;
176  }
177 
178  fields = ast_json_object_get(args->fields, "fields");
179  if (!fields && !created) {
180  /* Whoops. We need data. */
182  response, 400, "Bad request",
183  "Fields must be provided to update object '%s'",
184  args->id);
185  return;
186  } else if (fields) {
187  size_t i;
188 
189  for (i = 0; i < ast_json_array_size(fields); i++) {
190  struct ast_variable *new_var;
191  struct ast_json *json_value = ast_json_array_get(fields, i);
192 
193  if (!json_value) {
194  continue;
195  }
196 
197  new_var = ast_variable_new(
198  ast_json_string_get(ast_json_object_get(json_value, "attribute")),
199  ast_json_string_get(ast_json_object_get(json_value, "value")),
200  "");
201  if (!new_var) {
202  ast_variables_destroy(update_set);
204  return;
205  }
206  ast_variable_list_append(&update_set, new_var);
207  }
208  }
209 
210  /* APPLY! Note that a NULL update_set is fine (and necessary), as it
211  * will force validation on a newly created object.
212  */
213  if (ast_sorcery_objectset_apply(sorcery, sorcery_obj, update_set)) {
214  ast_variables_destroy(update_set);
216  response, 400, "Bad request",
217  "%s of object '%s' failed field value validation",
218  created ? "Creation" : "Update",
219  args->id);
220  return;
221  }
222 
223  ast_variables_destroy(update_set);
224 
225  if (created) {
226  if (ast_sorcery_create(sorcery, sorcery_obj)) {
228  response, 403, "Forbidden",
229  "Cannot create sorcery objects of type '%s'",
230  args->object_type);
231  return;
232  }
233  } else {
234  if (ast_sorcery_update(sorcery, sorcery_obj)) {
236  response, 403, "Forbidden",
237  "Cannot update sorcery objects of type '%s'",
238  args->object_type);
239  return;
240  }
241  }
242 
243  return_sorcery_object(sorcery, sorcery_obj, response);
244 }
245 
246 
249  struct ast_ari_response *response)
250 {
252  RAII_VAR(struct ast_sorcery_object_type *, object_type, NULL, ao2_cleanup);
253  RAII_VAR(void *, sorcery_obj, NULL, ao2_cleanup);
254 
256  if (!sorcery) {
258  response, 404, "Not Found",
259  "configClass '%s' not found",
260  args->config_class);
261  return;
262  }
263 
264  object_type = ast_sorcery_get_object_type(sorcery, args->object_type);
265  if (!object_type) {
267  response, 404, "Not Found",
268  "objectType '%s' not found",
269  args->object_type);
270  return;
271  }
272 
273  sorcery_obj = ast_sorcery_retrieve_by_id(sorcery, args->object_type, args->id);
274  if (!sorcery_obj) {
276  response, 404, "Not Found",
277  "Object with id '%s' not found",
278  args->id);
279  return;
280  }
281 
282  if (ast_sorcery_delete(sorcery, sorcery_obj)) {
284  response, 403, "Forbidden",
285  "Could not delete object with id '%s'",
286  args->id);
287  return;
288  }
289 
290  ast_ari_response_no_content(response);
291 }
292 
293 
296  struct ast_ari_response *response)
297 {
298  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
299  int show_all = args->only_count == 0;
300  int show_build = show_all;
301  int show_system = show_all;
302  int show_config = show_all;
303  int show_status = show_all;
304  size_t i;
305  int res = 0;
306 
307  for (i = 0; i < args->only_count; ++i) {
308  if (strcasecmp("build", args->only[i]) == 0) {
309  show_build = 1;
310  } else if (strcasecmp("system", args->only[i]) == 0) {
311  show_system = 1;
312  } else if (strcasecmp("config", args->only[i]) == 0) {
313  show_config = 1;
314  } else if (strcasecmp("status", args->only[i]) == 0) {
315  show_status = 1;
316  } else {
317  ast_log(LOG_WARNING, "Unrecognized info section '%s'\n",
318  args->only[i]);
319  }
320  }
321 
322  json = ast_json_object_create();
323 
324  if (show_build) {
325  res |= ast_json_object_set(json, "build",
327  "{ s: s, s: s, s: s,"
328  " s: s, s: s, s: s }",
329 
330  "os", ast_build_os,
331  "kernel", ast_build_kernel,
332  "machine", ast_build_machine,
333 
334  "options", AST_BUILDOPTS,
335  "date", ast_build_date,
336  "user", ast_build_user));
337  }
338 
339  if (show_system) {
340  char eid_str[128];
341 
342  ast_eid_to_str(eid_str, sizeof(eid_str), &ast_eid_default);
343 
344  res |= ast_json_object_set(json, "system",
345  ast_json_pack("{ s: s, s: s }",
346  "version", ast_get_version(),
347  "entity_id", eid_str));
348  }
349 
350  if (show_config) {
351  struct ast_json *config = ast_json_pack(
352  "{ s: s, s: s,"
353  " s: { s: s, s: s } }",
354 
356  "default_language", ast_defaultlanguage,
357 
358  "setid",
359  "user", ast_config_AST_RUN_USER,
360  "group", ast_config_AST_RUN_GROUP);
361 
362  res |= ast_json_object_set(json, "config", config);
363 
364  if (ast_option_maxcalls) {
365  res |= ast_json_object_set(config, "max_channels",
367  }
368 
369  if (ast_option_maxfiles) {
370  res |= ast_json_object_set(config, "max_open_files",
372  }
373 
374  if (ast_option_maxload) {
375  res |= ast_json_object_set(config, "max_load",
377  }
378  }
379 
380  if (show_status) {
381  res |= ast_json_object_set(json, "status",
382  ast_json_pack("{ s: o, s: o }",
383  "startup_time",
385  "last_reload_time",
387  }
388 
389  if (res != 0) {
391  return;
392  }
393 
394  ast_ari_response_ok(response, ast_json_ref(json));
395 }
396 
397 /*!
398  * \brief Process module information and append to a json array
399  * \param module Resource name
400  * \param description Resource description
401  * \param usecnt Resource use count
402  * \param status Resource running status
403  * \param like
404  * \param support_level Resource support level
405  * \param module_data_list Resource array
406  *
407  * \retval 0 if no resource exists
408  * \retval 1 if resource exists
409  */
410 static int process_module_list(const char *module, const char *description, int usecnt,
411  const char *status, const char *like,
412  enum ast_module_support_level support_level, void *module_data_list)
413 {
414  struct ast_json *module_info;
415 
416  module_info = ast_json_pack("{s: s, s: s, s: i, s: s, s: s}",
417  "name", module,
418  "description", description,
419  "use_count", usecnt,
420  "status", status,
421  "support_level", ast_module_support_level_to_string(support_level));
422  if (!module_info) {
423  return 0;
424  }
425  ast_json_array_append(module_data_list, module_info);
426  return 1;
427 }
428 
431  struct ast_ari_response *response)
432 {
433  struct ast_json *json;
434 
435  json = ast_json_array_create();
436  if (!json) {
438  return;
439  }
441 
442  ast_ari_response_ok(response, json);
443 }
444 
445 /*!
446  * \brief Identify module by name and process resource information
447  * \param module Resource name
448  * \param description Resource description
449  * \param usecnt Resource use count
450  * \param status Resource running status
451  * \param like
452  * \param support_level Resource support level
453  * \param data JSON body for resource
454  * \param condition Name to match resource to
455  *
456  * \retval 0 if no resource exists
457  * \retval 1 if resource exists
458  */
459 static int identify_module(const char *module, const char *description, int usecnt,
460  const char *status, const char *like,
461  enum ast_module_support_level support_level, void *data,
462  const char *condition)
463 {
464  int json_obj_set = 0;
465 
466  if (strcmp(condition, module) != 0) {
467  return 0;
468  }
469 
470  json_obj_set += ast_json_object_set(data, "name", ast_json_string_create(module));
471  json_obj_set += ast_json_object_set(data, "description", ast_json_string_create(description));
472  json_obj_set += ast_json_object_set(data, "use_count", ast_json_integer_create(usecnt));
473  json_obj_set += ast_json_object_set(data, "status", ast_json_string_create(status));
474  json_obj_set += ast_json_object_set(data, "support_level", ast_json_string_create(
475  ast_module_support_level_to_string(support_level)));
476 
477  if (json_obj_set != 0) {
478  return 0;
479  }
480 
481  return 1;
482 }
483 
486  struct ast_ari_response *response)
487 {
488  struct ast_json *json;
489  int module_retrieved = 0;
490 
491  ast_assert(response != NULL);
492 
493  if (!ast_module_check(args->module_name)) {
495  response, 404, "Not Found",
496  "Module could not be found in running modules");
497  return;
498  }
499 
500  json = ast_json_object_create();
501  if (!json) {
503  return;
504  }
505 
506  module_retrieved = ast_update_module_list_condition(&identify_module, NULL, json,
507  args->module_name);
508  if (!module_retrieved) {
510  response, 409, "Conflict",
511  "Module information could not be retrieved");
512  ast_json_unref(json);
513  return;
514  }
515 
516  ast_ari_response_ok(response, json);
517 }
518 
521  struct ast_ari_response *response)
522 {
523  enum ast_module_load_result load_result;
524 
525  ast_assert(response != NULL);
526 
527  if (ast_module_check(args->module_name)) {
529  response, 409, "Conflict",
530  "Module is already loaded");
531  return;
532  }
533 
534  load_result = ast_load_resource(args->module_name);
535 
536  if (load_result == AST_MODULE_LOAD_DECLINE) {
538  response, 409, "Conflict",
539  "Module load declined");
540  return;
541  } else if (load_result == AST_MODULE_LOAD_SKIP) {
543  response, 409, "Conflict",
544  "Module was skipped");
545  return;
546  } else if (load_result == AST_MODULE_LOAD_FAILURE) {
548  response, 409, "Conflict",
549  "Module could not be loaded properly");
550  return;
551  }
552 
553  ast_ari_response_no_content(response);
554 }
555 
558  struct ast_ari_response *response)
559 {
560  int unload_result;
561  enum ast_module_unload_mode unload_mode = AST_FORCE_SOFT;
562 
563  ast_assert(response != NULL);
564 
565  if (!ast_module_check(args->module_name)) {
567  response, 404, "Not Found",
568  "Module not found in running modules");
569  return;
570  }
571 
572  unload_result = ast_unload_resource(args->module_name, unload_mode);
573 
574  if (unload_result != 0) {
576  response, 409, "Conflict",
577  "Module could not be unloaded");
578  return;
579  }
580 
581  ast_ari_response_no_content(response);
582 }
583 
586  struct ast_ari_response *response)
587 {
588  enum ast_module_reload_result reload_result;
589 
590  ast_assert(response != NULL);
591 
592  if (!ast_module_check(args->module_name)) {
594  response, 404, "Not Found",
595  "Module not found in running modules");
596  return;
597  }
598 
599  reload_result = ast_module_reload(args->module_name);
600 
601  if (reload_result == AST_MODULE_RELOAD_NOT_FOUND) {
603  response, 404, "Not Found",
604  "Module could not be found");
605  return;
606  } else if (reload_result == AST_MODULE_RELOAD_ERROR) {
608  response, 409, "Conflict",
609  "An unknown error occurred while reloading the module");
610  return;
611  } else if (reload_result == AST_MODULE_RELOAD_IN_PROGRESS) {
613  response, 409, "Conflict",
614  "Another reload is currently in progress");
615  return;
616  } else if (reload_result == AST_MODULE_RELOAD_UNINITIALIZED) {
618  response, 409, "Conflict",
619  "Module has not been initialized");
620  return;
621  } else if (reload_result == AST_MODULE_RELOAD_NOT_IMPLEMENTED) {
623  response, 409, "Conflict",
624  "Module does not support reloading");
625  return;
626  } else if (reload_result == AST_MODULE_RELOAD_QUEUED) {
627  ast_ari_response_accepted(response);
628  return;
629  }
630 
631  ast_ari_response_no_content(response);
632 }
633 
634 void ast_ari_asterisk_ping(struct ast_variable *headers,
636  struct ast_ari_response *response)
637 {
638  struct ast_json *json;
639  char eid[20];
640 
641  ast_assert(response != NULL);
642 
643  json = ast_json_pack("{s: s, s: o, s: s}",
644  "ping", "pong",
645  "timestamp", ast_json_timeval(ast_tvnow(), NULL),
646  "asterisk_id", ast_eid_to_str(eid, sizeof(eid), &ast_eid_default)
647  );
648 
649  ast_ari_response_ok(response, json);
650 }
651 
652 /*!
653  * \brief Process logger information and append to a json array
654  * \param channel Resource logger channel name path
655  * \param type Resource log type
656  * \param status Resource log status
657  * \param configuration Resource logger levels
658  * \param log_data_list Resource array
659  *
660  * \retval -1 if no resource exists
661  * \retval 0 if resource exists
662  */
663 static int process_log_list(const char *channel, const char *type,
664  const char *status, const char *configuration, void *log_data_list)
665 {
666  struct ast_json *logger_info;
667 
668  logger_info = ast_json_pack("{s: s, s: s, s: s, s: s}",
669  "channel", channel, "type", type, "status", status, "configuration",
670  configuration);
671 
672  if (!logger_info) {
673  return AST_LOGGER_FAILURE;
674  }
675 
676  ast_json_array_append(log_data_list, logger_info);
677  return AST_LOGGER_SUCCESS;
678 }
679 
682  struct ast_ari_response *response)
683 {
684  struct ast_json *json;
685  int res;
686 
687  json = ast_json_array_create();
689 
690  if (res == AST_LOGGER_FAILURE) {
691  ast_ari_response_error(response, 500, "Internal Server Error",
692  "Response body is not valid");
693  ast_json_unref(json);
694  return;
695  } else if (res == AST_LOGGER_ALLOC_ERROR) {
696  ast_ari_response_error(response, 500, "Internal Server Error",
697  "Allocation Failed");
698  ast_json_unref(json);
699  return;
700  }
701 
702  ast_ari_response_ok(response, json);
703 }
704 
707  struct ast_ari_response *response)
708 {
709  int res;
710 
711  ast_assert(response != NULL);
712 
714 
715  if (res == AST_LOGGER_DECLINE) {
716  ast_ari_response_error(response, 400, "Bad Request",
717  "Configuration levels are required");
718  return;
719  } else if (res == AST_LOGGER_FAILURE) {
720  ast_ari_response_error(response, 409, "Conflict",
721  "Log channel already exists");
722  return;
723  } else if (res == AST_LOGGER_ALLOC_ERROR) {
724  ast_ari_response_error(response, 500, "Internal Server Error",
725  "Allocation failed");
726  return;
727  }
728 
729  ast_ari_response_no_content(response);
730 }
731 
734  struct ast_ari_response *response)
735 {
736  int res;
737 
738  ast_assert(response != NULL);
739 
741 
742  if (res == AST_LOGGER_FAILURE) {
744  response, 404, "Not Found",
745  "Log channel does not exist");
746  return;
747  } else if (res == AST_LOGGER_ALLOC_ERROR) {
749  response, 500, "Internal Server Error",
750  "Allocation failed");
751  return;
752  }
753 
754  ast_ari_response_no_content(response);
755 }
756 
759  struct ast_ari_response *response)
760 {
761  int res;
762 
763  ast_assert(response != NULL);
764 
766 
767  if (res == AST_LOGGER_FAILURE) {
768  ast_ari_response_error(response, 404, "Not Found",
769  "Log channel does not exist");
770  return;
771  } else if (res == AST_LOGGER_ALLOC_ERROR) {
772  ast_ari_response_error(response, 500, "Internal Server Error",
773  "Allocation failed");
774  return;
775  }
776 
777  ast_ari_response_no_content(response);
778 }
779 
782  struct ast_ari_response *response)
783 {
784  RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
785  RAII_VAR(struct ast_str *, tmp, NULL, ast_free);
786 
787  const char *value;
788 
789  ast_assert(response != NULL);
790 
791  if (ast_strlen_zero(args->variable)) {
793  response, 400, "Bad Request",
794  "Variable name is required");
795  return;
796  }
797 
798  tmp = ast_str_create(32);
799  if (!tmp) {
801  return;
802  }
803 
804  value = ast_str_retrieve_variable(&tmp, 0, NULL, NULL, args->variable);
805 
806  if (!(json = ast_json_pack("{s: s}", "value", S_OR(value, "")))) {
808  return;
809  }
810 
811  ast_ari_response_ok(response, ast_json_ref(json));
812 }
813 
816  struct ast_ari_response *response)
817 {
818  ast_assert(response != NULL);
819 
820  if (ast_strlen_zero(args->variable)) {
822  response, 400, "Bad Request",
823  "Variable name is required");
824  return;
825  }
826 
828 
829  ast_ari_response_no_content(response);
830 }
struct ast_variable * next
static const char type[]
Definition: chan_ooh323.c:109
ast_module_load_result
Definition: module.h:68
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int ast_update_module_list_data(int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data), const char *like, void *data)
Ask for a list of modules, descriptions, use counts and status.
Definition: loader.c:2594
int ast_option_maxfiles
Definition: options.c:81
Asterisk main include file. File version handling, generic pbx functions.
const char * ast_build_user
Definition: buildinfo.c:34
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:591
enum ast_module_load_result ast_load_resource(const char *resource_name)
Load a module.
Definition: loader.c:1819
void ast_ari_asterisk_get_info(struct ast_variable *headers, struct ast_ari_asterisk_get_info_args *args, struct ast_ari_response *response)
Gets Asterisk system information.
void ast_ari_asterisk_delete_log(struct ast_variable *headers, struct ast_ari_asterisk_delete_log_args *args, struct ast_ari_response *response)
Deletes a log channel.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
char * config
Definition: conf2ael.c:66
Asterisk version information.
char * ast_eid_to_str(char *s, int maxlen, struct ast_eid *eid)
Convert an EID to a string.
Definition: main/utils.c:2587
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
const char * ast_get_version(void)
Retrieve the Asterisk version string.
Definition: version.c:16
int ast_logger_get_channels(int(*logentry)(const char *channel, const char *type, const char *status, const char *configuration, void *data), void *data)
Retrieve the existing log channels.
Definition: logger.c:1336
enum ast_module_reload_result ast_module_reload(const char *name)
Reload asterisk modules.
Definition: loader.c:1562
ast_module_reload_result
Possible return types for ast_module_reload.
Definition: module.h:109
#define LOG_WARNING
Definition: logger.h:274
const char * ast_module_support_level_to_string(enum ast_module_support_level support_level)
Definition: loader.c:2755
int ast_update_module_list_condition(int(*modentry)(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data, const char *condition), const char *like, void *data, const char *condition)
Ask for a list of modules, descriptions, use counts and status.
Definition: loader.c:2622
int ast_logger_rotate_channel(const char *log_channel)
Rotate the specified log channel.
Definition: logger.c:1259
static int tmp()
Definition: bt_open.c:389
const char * ast_build_date
Definition: buildinfo.c:33
Structure for variables, used for configurations and for channel variables.
void ast_ari_asterisk_get_global_var(struct ast_variable *headers, struct ast_ari_asterisk_get_global_var_args *args, struct ast_ari_response *response)
Get the value of a global variable.
const char * ast_build_os
Definition: buildinfo.c:32
Full structure for sorcery.
Definition: sorcery.c:230
void ast_ari_asterisk_list_modules(struct ast_variable *headers, struct ast_ari_asterisk_list_modules_args *args, struct ast_ari_response *response)
List Asterisk modules.
int ast_sorcery_objectset_apply(const struct ast_sorcery *sorcery, void *object, struct ast_variable *objectset)
Apply an object set (KVP list) to an object.
Definition: sorcery.c:1632
static int copy(char *infile, char *outfile)
Utility function to copy a file.
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ast_assert(a)
Definition: utils.h:695
double ast_option_maxload
Definition: options.c:77
const char * ast_config_AST_RUN_USER
Definition: options.c:168
Definition: muted.c:95
void ast_ari_asterisk_load_module(struct ast_variable *headers, struct ast_ari_asterisk_load_module_args *args, struct ast_ari_response *response)
Load an Asterisk module.
const char * args
#define NULL
Definition: resample.c:96
static int process_module_list(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *module_data_list)
Process module information and append to a json array.
int value
Definition: syslog.c:37
static void return_sorcery_object(struct ast_sorcery *sorcery, void *sorcery_obj, struct ast_ari_response *response)
void ast_ari_response_alloc_failed(struct ast_ari_response *response)
Fill in response with a 500 message for allocation failures.
Definition: res_ari.c:298
void ast_ari_asterisk_get_module(struct ast_variable *headers, struct ast_ari_asterisk_get_module_args *args, struct ast_ari_response *response)
Get Asterisk module information.
int ast_option_maxcalls
Definition: options.c:79
int ast_module_check(const char *name)
Check if module with the name given is loaded.
Definition: loader.c:2653
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:404
const char * ast_build_kernel
Definition: buildinfo.c:30
#define ast_strlen_zero(foo)
Definition: strings.h:52
void * ast_sorcery_retrieve_by_id(const struct ast_sorcery *sorcery, const char *type, const char *id)
Retrieve an object using its unique identifier.
Definition: sorcery.c:1853
#define ast_sorcery_unref(sorcery)
Decrease the reference count of a sorcery structure.
Definition: sorcery.h:1502
const char * ast_config_AST_SYSTEM_NAME
Definition: options.c:170
const char * ast_config_AST_RUN_GROUP
Definition: options.c:169
const char * ast_build_machine
Definition: buildinfo.c:31
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
int ast_sorcery_create(const struct ast_sorcery *sorcery, void *object)
Create and potentially persist an object using an available wizard.
Definition: sorcery.c:2057
Structure for registered object type.
Definition: sorcery.c:148
Asterisk file paths, configured in asterisk.conf.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:911
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:268
void ast_ari_asterisk_unload_module(struct ast_variable *headers, struct ast_ari_asterisk_unload_module_args *args, struct ast_ari_response *response)
Unload an Asterisk module.
char ast_defaultlanguage[]
Definition: options.c:98
void ast_ari_response_ok(struct ast_ari_response *response, struct ast_json *message)
Fill in an OK (200) ast_ari_response.
Definition: res_ari.c:276
#define ao2_ref(o, delta)
Definition: astobj2.h:464
ast_module_unload_mode
Definition: module.h:61
struct timeval ast_lastreloadtime
Definition: asterisk.c:337
static int process_log_list(const char *channel, const char *type, const char *status, const char *configuration, void *log_data_list)
Process logger information and append to a json array.
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:273
Generated file - declares stubs to be implemented in res/ari/resource_asterisk.c. ...
#define ast_variable_new(name, value, filename)
static int usecnt
Definition: chan_ooh323.c:332
int ast_logger_create_channel(const char *log_channel, const char *components)
Create a log channel.
Definition: logger.c:1419
Core PBX routines and definitions.
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:352
struct ast_json * ast_json_timeval(const struct timeval tv, const char *zone)
Construct a timeval as JSON.
Definition: json.c:649
struct ast_sorcery_object_type * ast_sorcery_get_object_type(const struct ast_sorcery *sorcery, const char *type)
Get the sorcery object type given a type name.
Definition: sorcery.c:2489
void ast_ari_asterisk_reload_module(struct ast_variable *headers, struct ast_ari_asterisk_reload_module_args *args, struct ast_ari_response *response)
Reload an Asterisk module.
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:368
int ast_sorcery_delete(const struct ast_sorcery *sorcery, void *object)
Delete an object.
Definition: sorcery.c:2233
void ast_ari_asterisk_ping(struct ast_variable *headers, struct ast_ari_asterisk_ping_args *args, struct ast_ari_response *response)
Response pong message.
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
void ast_ari_response_accepted(struct ast_ari_response *response)
Fill in a Accepted (202) ast_ari_response.
Definition: res_ari.c:291
int ast_unload_resource(const char *resource_name, enum ast_module_unload_mode)
Unload a module.
Definition: loader.c:1229
void ast_ari_asterisk_delete_object(struct ast_variable *headers, struct ast_ari_asterisk_delete_object_args *args, struct ast_ari_response *response)
Delete a dynamic configuration object.
void * ast_sorcery_alloc(const struct ast_sorcery *sorcery, const char *type, const char *id)
Allocate an object.
Definition: sorcery.c:1744
#define ast_sorcery_objectset_create(sorcery, object)
Create an object set (KVP list) for an object.
Definition: sorcery.h:1136
int ast_logger_remove_channel(const char *log_channel)
Delete the specified log channel.
Definition: logger.c:1485
#define ast_free(a)
Definition: astmm.h:182
void ast_ari_response_error(struct ast_ari_response *response, int response_code, const char *response_text, const char *message_fmt,...)
Fill in an error ast_ari_response.
Definition: res_ari.c:259
Module could not be loaded properly.
Definition: module.h:102
Module has failed to load, may be in an inconsistent state.
Definition: module.h:78
void ast_ari_asterisk_add_log(struct ast_variable *headers, struct ast_ari_asterisk_add_log_args *args, struct ast_ari_response *response)
Adds a log channel.
void ast_ari_response_no_content(struct ast_ari_response *response)
Fill in a No Content (204) ast_ari_response.
Definition: res_ari.c:284
void ast_ari_asterisk_list_log_channels(struct ast_variable *headers, struct ast_ari_asterisk_list_log_channels_args *args, struct ast_ari_response *response)
Gets Asterisk log channel information.
#define AST_BUILDOPTS
Definition: buildopts.h:11
Support for logging to various files, console and syslog Configuration in file logger.conf.
void ast_ari_asterisk_rotate_log(struct ast_variable *headers, struct ast_ari_asterisk_rotate_log_args *args, struct ast_ari_response *response)
Rotates a log channel.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
struct ast_eid ast_eid_default
Global EID.
Definition: options.c:93
struct timeval ast_startuptime
Definition: asterisk.c:336
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:389
void ast_ari_asterisk_get_object(struct ast_variable *headers, struct ast_ari_asterisk_get_object_args *args, struct ast_ari_response *response)
Retrieve a dynamic configuration object.
const char * ast_str_retrieve_variable(struct ast_str **buf, ssize_t maxlen, struct ast_channel *chan, struct varshead *headp, const char *var)
static struct ast_sorcery * sorcery
struct ast_json * ast_json_real_create(double value)
Create a JSON real number.
Definition: json.c:332
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:397
#define S_OR(a, b)
returns the equivalent of logic or for strings: first one if not empty, otherwise second one...
Definition: strings.h:79
void * ast_sorcery_copy(const struct ast_sorcery *sorcery, const void *object)
Create a copy of an object.
Definition: sorcery.c:1778
size_t ast_json_array_size(const struct ast_json *array)
Get the size of a JSON array.
Definition: json.c:356
Abstract JSON element (object, array, string, int, ...).
void ast_ari_asterisk_update_object(struct ast_variable *headers, struct ast_ari_asterisk_update_object_args *args, struct ast_ari_response *response)
Create or update a dynamic configuration object.
ast_module_support_level
Definition: module.h:119
Asterisk module definitions.
static int identify_module(const char *module, const char *description, int usecnt, const char *status, const char *like, enum ast_module_support_level support_level, void *data, const char *condition)
Identify module by name and process resource information.
struct ast_json * ast_json_array_get(const struct ast_json *array, size_t index)
Get an element from an array.
Definition: json.c:360
#define ast_variable_list_append(head, new_var)
struct ast_sorcery * ast_sorcery_retrieve_by_module_name(const char *module)
Retrieves an existing sorcery instance by module name.
Definition: sorcery.c:672
void ast_ari_asterisk_set_global_var(struct ast_variable *headers, struct ast_ari_asterisk_set_global_var_args *args, struct ast_ari_response *response)
Set the value of a global variable.
jack_status_t status
Definition: app_jack.c:146
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620
Sorcery Data Access Layer API.
int ast_sorcery_update(const struct ast_sorcery *sorcery, void *object)
Update an object.
Definition: sorcery.c:2145
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:317