app_skel.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) <Year>, <Your Name Here>
  5. *
  6. * <Your Name Here> <<Your Email Here>>
  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 Skeleton application
  21. *
  22. * \author\verbatim <Your Name Here> <<Your Email Here>> \endverbatim
  23. *
  24. * This is a skeleton for development of an Asterisk application
  25. * \ingroup applications
  26. */
  27. /*** MODULEINFO
  28. <defaultenabled>no</defaultenabled>
  29. ***/
  30. #include "asterisk.h"
  31. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  32. #include "asterisk/file.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. #include "asterisk/lock.h"
  37. #include "asterisk/app.h"
  38. static char *app = "Skel";
  39. static char *synopsis =
  40. "Skeleton application.";
  41. static char *descrip = "This application is a template to build other applications from.\n"
  42. " It shows you the basic structure to create your own Asterisk applications.\n";
  43. enum {
  44. OPTION_A = (1 << 0),
  45. OPTION_B = (1 << 1),
  46. OPTION_C = (1 << 2),
  47. } option_flags;
  48. enum {
  49. OPTION_ARG_B = 0,
  50. OPTION_ARG_C = 1,
  51. /* This *must* be the last value in this enum! */
  52. OPTION_ARG_ARRAY_SIZE = 2,
  53. } option_args;
  54. AST_APP_OPTIONS(app_opts,{
  55. AST_APP_OPTION('a', OPTION_A),
  56. AST_APP_OPTION_ARG('b', OPTION_B, OPTION_ARG_B),
  57. AST_APP_OPTION_ARG('c', OPTION_C, OPTION_ARG_C),
  58. });
  59. static int app_exec(struct ast_channel *chan, void *data)
  60. {
  61. int res = 0;
  62. struct ast_flags flags;
  63. char *parse, *opts[OPTION_ARG_ARRAY_SIZE];
  64. AST_DECLARE_APP_ARGS(args,
  65. AST_APP_ARG(dummy);
  66. AST_APP_ARG(options);
  67. );
  68. if (ast_strlen_zero(data)) {
  69. ast_log(LOG_WARNING, "%s requires an argument (dummy[,options])\n", app);
  70. return -1;
  71. }
  72. /* Do our thing here */
  73. /* We need to make a copy of the input string if we are going to modify it! */
  74. parse = ast_strdupa(data);
  75. AST_STANDARD_APP_ARGS(args, parse);
  76. if (args.argc == 2)
  77. ast_app_parse_options(app_opts, &flags, opts, args.options);
  78. if (!ast_strlen_zero(args.dummy))
  79. ast_log(LOG_NOTICE, "Dummy value is : %s\n", args.dummy);
  80. if (ast_test_flag(&flags, OPTION_A))
  81. ast_log(LOG_NOTICE, "Option A is set\n");
  82. if (ast_test_flag(&flags, OPTION_B))
  83. ast_log(LOG_NOTICE, "Option B is set with : %s\n", opts[OPTION_ARG_B] ? opts[OPTION_ARG_B] : "<unspecified>");
  84. if (ast_test_flag(&flags, OPTION_C))
  85. ast_log(LOG_NOTICE, "Option C is set with : %s\n", opts[OPTION_ARG_C] ? opts[OPTION_ARG_C] : "<unspecified>");
  86. return res;
  87. }
  88. static int unload_module(void)
  89. {
  90. int res;
  91. res = ast_unregister_application(app);
  92. return res;
  93. }
  94. static int load_module(void)
  95. {
  96. if (ast_register_application(app, app_exec, synopsis, descrip))
  97. return AST_MODULE_LOAD_DECLINE;
  98. return AST_MODULE_LOAD_SUCCESS;
  99. }
  100. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Skeleton (sample) Application");