Make sure paging can be duplex if necessary
[asterisk/asterisk.git] / apps / app_page.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (c) 2004 - 2005 Digium, Inc.  All rights reserved.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * This code is released under the GNU General Public License
9  * version 2.0.  See LICENSE for more information.
10  *
11  * See http://www.asterisk.org for more information about
12  * the Asterisk project. Please do not directly contact
13  * any of the maintainers of this project for assistance;
14  * the project provides a web site, mailing lists and IRC
15  * channels for your use.
16  *
17  */
18
19 /*
20  *
21  * Page application
22  *
23  */
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <string.h>
29
30 #include "asterisk.h"
31
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33
34 #include "asterisk/options.h"
35 #include "asterisk/logger.h"
36 #include "asterisk/channel.h"
37 #include "asterisk/pbx.h"
38 #include "asterisk/module.h"
39 #include "asterisk/app.h"
40
41
42 static char *tdesc = "Page Multiple Phones";
43
44 static char *app_page= "Page";
45
46 static char *page_synopsis = "Pages phones";
47
48 static char *page_descrip =
49 "Page(Technology/Resource&Technology2/Resource2[|options])\n"
50 "  Places outbound calls to the given technology / resource and dumps\n"
51 "them into a conference bridge as muted participants.  The original\n"
52 "caller is dumped into the conference as a speaker and the room is\n"
53 "destroyed when the original caller leaves.  Valid options are:\n"
54 "        d - full duplex audio\n"
55 "Always returns -1.\n";
56
57 STANDARD_LOCAL_USER;
58
59 LOCAL_USER_DECL;
60
61 #define PAGE_DUPLEX (1 << 0)
62
63 AST_DECLARE_OPTIONS(page_opts,{
64         ['d'] = { PAGE_DUPLEX },
65 });
66
67 static int page_exec(struct ast_channel *chan, void *data)
68 {
69         char *options;
70         char *tech, *resource;
71         char meetmeopts[80];
72         struct ast_flags flags = { 0 };
73         unsigned int confid = rand();
74         struct ast_app *app;
75
76         if (data) {
77                 options = ast_strdupa((char *)data);
78                 if (options) {
79                         char *tmp = strsep(&options, "|,");
80                         if (options) {
81                                 ast_parseoptions(page_opts, &flags, NULL, options);
82                         }
83                         snprintf(meetmeopts, sizeof(meetmeopts), "%ud|%sqxdw", confid, ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m");
84                         while(tmp && !ast_strlen_zero(tmp)) {
85                                 tech = strsep(&tmp, "&");
86                                 if (tech) {
87                                         resource = strchr(tech, '/');
88                                         if (resource) {
89                                                 *resource = '\0';
90                                                 resource++;
91                                                 ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, resource, 30000, "MeetMe", meetmeopts, NULL, 0, chan->cid.cid_num, chan->cid.cid_name, NULL, NULL);
92                                         }
93                                 }
94                         }
95                         snprintf(meetmeopts, sizeof(meetmeopts), "%ud|A%sqxd", confid, ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t");
96                         app = pbx_findapp("Meetme");
97                         if (app) {
98                                 pbx_exec(chan, app, meetmeopts, 1);
99                         } else
100                                 ast_log(LOG_WARNING, "Whoa, meetme doesn't exist!\n");
101                 } else {
102                         ast_log(LOG_ERROR, "Out of memory\n");
103                 }
104         }
105
106         return -1;
107 }
108
109 int unload_module(void)
110 {
111         STANDARD_HANGUP_LOCALUSERS;
112         return ast_unregister_application(app_page);
113 }
114
115 int load_module(void)
116 {
117         return ast_register_application(app_page, page_exec, page_synopsis, page_descrip);
118 }
119
120 char *description(void)
121 {
122         return tdesc;
123 }
124
125 int usecount(void)
126 {
127         int res;
128         STANDARD_USECOUNT(res);
129         return res;
130 }
131
132 char *key()
133 {
134         return ASTERISK_GPL_KEY;
135 }