app_celgenuserevent.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2008, Digium, Inc
00005  *
00006  * See http://www.asterisk.org for more information about
00007  * the Asterisk project. Please do not directly contact
00008  * any of the maintainers of this project for assistance;
00009  * the project provides a web site, mailing lists and IRC
00010  * channels for your use.
00011  *
00012  * This program is free software, distributed under the terms of
00013  * the GNU General Public License Version 2. See the LICENSE file
00014  * at the top of the source tree.
00015  */
00016 
00017 /*! \file
00018  *
00019  * \brief Generate User-Defined CEL event
00020  *
00021  * \author Steve Murphy
00022  *
00023  * \ingroup applications
00024  */
00025 
00026 /*** MODULEINFO
00027    <support_level>core</support_level>
00028  ***/
00029 
00030 #include "asterisk.h"
00031 
00032 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 419592 $")
00033 
00034 #include "asterisk/module.h"
00035 #include "asterisk/app.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/cel.h"
00038 
00039 /*** DOCUMENTATION
00040    <application name="CELGenUserEvent" language="en_US">
00041       <synopsis>
00042          Generates a CEL User Defined Event.
00043       </synopsis>
00044       <syntax>
00045          <parameter name="event-name" required="true">
00046             <argument name="event-name" required="true">
00047             </argument>
00048             <argument name="extra" required="false">
00049                <para>Extra text to be included with the event.</para>
00050             </argument>
00051          </parameter>
00052       </syntax>
00053       <description>
00054          <para>A CEL event will be immediately generated by this channel, with the supplied name for a type.</para>
00055       </description>
00056    </application>
00057  ***/
00058 
00059 static char *app = "CELGenUserEvent";
00060 
00061 static int celgenuserevent_exec(struct ast_channel *chan, const char *data)
00062 {
00063    int res = 0;
00064    char *parse;
00065    RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
00066    AST_DECLARE_APP_ARGS(args,
00067       AST_APP_ARG(event);
00068       AST_APP_ARG(extra);
00069    );
00070 
00071    if (ast_strlen_zero(data)) {
00072       return 0;
00073    }
00074 
00075    parse = ast_strdupa(data);
00076    AST_STANDARD_APP_ARGS(args, parse);
00077 
00078    blob = ast_json_pack("{s: s, s: {s: s}}",
00079       "event", args.event,
00080       "extra", "extra", S_OR(args.extra, ""));
00081    if (!blob) {
00082       return res;
00083    }
00084    ast_cel_publish_event(chan, AST_CEL_USER_DEFINED, blob);
00085    return res;
00086 }
00087 
00088 static int unload_module(void)
00089 {
00090    ast_unregister_application(app);
00091    return 0;
00092 }
00093 
00094 static int load_module(void)
00095 {
00096    int res = ast_register_application_xml(app, celgenuserevent_exec);
00097    if (res) {
00098       return AST_MODULE_LOAD_DECLINE;
00099    } else {
00100       return AST_MODULE_LOAD_SUCCESS;
00101    }
00102 }
00103 
00104 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Generate an User-Defined CEL event",
00105       .support_level = AST_MODULE_SUPPORT_CORE,
00106             .load = load_module,
00107             .unload = unload_module,
00108    );

Generated on Thu Apr 16 06:27:08 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6