Created
October 22, 2012 11:53
-
-
Save leedm777/3931190 to your computer and use it in GitHub Desktop.
Asterisk's simplest application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Asterisk -- An open source telephony toolkit. | |
* | |
* Copyright (C) 2012, Digium, Inc. | |
* | |
* David M. Lee, II <[email protected]> | |
* | |
* See http://www.asterisk.org for more information about | |
* the Asterisk project. Please do not directly contact | |
* any of the maintainers of this project for assistance; | |
* the project provides a web site, mailing lists and IRC | |
* channels for your use. | |
* | |
* This program is free software, distributed under the terms of | |
* the GNU General Public License Version 2. See the LICENSE file | |
* at the top of the source tree. | |
*/ | |
/*! \file | |
* | |
* \brief Hello - Asterisk's simplest dialplan application. | |
* | |
* \author David M. Lee, II <[email protected]> | |
*/ | |
#include "asterisk.h" | |
#include "asterisk/module.h" | |
#include "asterisk/app.h" | |
/*** MODULEINFO | |
<support_level>extended</support_level> | |
<defaulteanbled>no</defaulteanbled> | |
***/ | |
static char *app_hello = "Hello"; | |
static char *app_goodbye = "Goodbye"; | |
/* | |
* DOCUMENTATION block contains docs that are generated into the the docbook | |
* help document, and regularly generated on wiki.asterisk.org. | |
*/ | |
/*** DOCUMENTATION | |
<application name="Hello" language="en_US"> | |
<synopsis> | |
Says hello. | |
</synopsis> | |
<syntax> | |
<parameter name="who"> | |
<para>To whom to say hello. In not specified, defaults to Asterisk.</para> | |
</parameter> | |
</syntax> | |
<description> | |
<para>Says hello. If there was anything else to say, it would be said here.</para> | |
</description> | |
</application> | |
<application name="Goodbye" language="en_US"> | |
<synopsis> | |
Says goodbye. | |
</synopsis> | |
<syntax> | |
<parameter name="who"> | |
<para>To whom to say goodbye. In not specified, defaults to Asterisk.</para> | |
</parameter> | |
</syntax> | |
<description> | |
<para>Says goodbye. If there was anything else to say, it would be said here.</para> | |
</description> | |
</application> | |
***/ | |
/*! | |
* /brief It's certainly okay to extra common code into a shared function. | |
* | |
* Don't repeat yourself. | |
*/ | |
static int hello_goobye(struct ast_channel *chan, const char *data, const char *hg) | |
{ | |
char *parse; | |
AST_DECLARE_APP_ARGS(args, | |
AST_APP_ARG(who); | |
); | |
parse = ast_strdupa(data); | |
AST_STANDARD_APP_ARGS(args, parse); | |
if (args.argc == 0) { | |
args.who = "Asterisk"; | |
} | |
ast_log(AST_LOG_NOTICE, "%s, %s\n", hg, args.who); | |
return 0; | |
} | |
/*! | |
* \brief Hello, Asterisk! | |
*/ | |
static int hello_exec(struct ast_channel *chan, const char *data) | |
{ | |
return hello_goobye(chan, data, "Hello"); | |
} | |
/*! | |
* \brief Goodbye, Asterisk! | |
*/ | |
static int goodbye_exec(struct ast_channel *chan, const char *data) | |
{ | |
return hello_goobye(chan, data, "Goodbye"); | |
} | |
/*! | |
* \brief Load the app_hello.so module. | |
*/ | |
static int load_module(void) | |
{ | |
int r = 0; | |
r |= ast_register_application_xml(app_hello, hello_exec); | |
r |= ast_register_application_xml(app_goodbye, goodbye_exec); | |
return r; | |
} | |
/*! | |
* /brief Unloaad the app_hello.so module. | |
*/ | |
static int unload_module(void) | |
{ | |
int r = 0; | |
r |= ast_unregister_application(app_hello); | |
r |= ast_unregister_application(app_goodbye); | |
return r; | |
} | |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Hello, Asterisk! (application style)"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment