| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
#include "asterisk.h" |
| 31 |
|
| 32 |
#include "asterisk/module.h" |
| 33 |
#include "asterisk/app.h" |
| 34 |
#include "asterisk/channel.h" |
| 35 |
#include "asterisk/cel.h" |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
static char *app = "CELGenUserEvent"; |
| 61 |
|
| 62 |
static int celgenuserevent_exec(struct ast_channel *chan, const char *data) |
| 63 |
{ |
| 64 |
int res = 0; |
| 65 |
char *parse; |
| 66 |
RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref); |
| 67 |
AST_DECLARE_APP_ARGS(args, |
| 68 |
AST_APP_ARG(event); |
| 69 |
AST_APP_ARG(extra); |
| 70 |
); |
| 71 |
|
| 72 |
if (ast_strlen_zero(data)) { |
| 73 |
return 0; |
| 74 |
} |
| 75 |
|
| 76 |
parse = ast_strdupa(data); |
| 77 |
AST_STANDARD_APP_ARGS(args, parse); |
| 78 |
|
| 79 |
blob = ast_json_pack("{s: s, s: {s: s}}", |
| 80 |
"event", args.event, |
| 81 |
"extra", "extra", S_OR(args.extra, "")); |
| 82 |
if (!blob) { |
| 83 |
return res; |
| 84 |
} |
| 85 |
ast_cel_publish_event(chan, AST_CEL_USER_DEFINED, blob); |
| 86 |
return res; |
| 87 |
} |
| 88 |
|
| 89 |
static int unload_module(void) |
| 90 |
{ |
| 91 |
ast_unregister_application(app); |
| 92 |
return 0; |
| 93 |
} |
| 94 |
|
| 95 |
static int load_module(void) |
| 96 |
{ |
| 97 |
int res = ast_register_application_xml(app, celgenuserevent_exec); |
| 98 |
if (res) { |
| 99 |
return AST_MODULE_LOAD_DECLINE; |
| 100 |
} else { |
| 101 |
return AST_MODULE_LOAD_SUCCESS; |
| 102 |
} |
| 103 |
} |
| 104 |
|
| 105 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Generate an User-Defined CEL event", |
| 106 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 107 |
.load = load_module, |
| 108 |
.unload = unload_module, |
| 109 |
.requires = "cel", |
| 110 |
); |