Fix "bug" of not being able to page multiple phones
[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
40
41 static char *tdesc = "Page Multiple Phones";
42
43 static char *app_page= "Page";
44
45 static char *page_synopsis = "Pages phones";
46
47 static char *page_descrip =
48 "Page(Technology/Resource&Technology2/Resource2)\n"
49 "  Places outbound calls to the given technology / resource and dumps\n"
50 "them into a conference bridge as muted participants.  The original\n"
51 "caller is dumped into the conference as a speaker and the room is\n"
52 "destroyed when the original caller leaves.  Always returns -1.\n";
53
54 STANDARD_LOCAL_USER;
55
56 LOCAL_USER_DECL;
57
58 static int page_exec(struct ast_channel *chan, void *data)
59 {
60         char *options;
61         char *tech, *resource;
62         char meetmeopts[80];
63         unsigned int confid = rand();
64         struct ast_app *app;
65
66         if (data) {
67                 options = ast_strdupa((char *)data);
68                 if (options) {
69                         char *tmp = strsep(&options, "|,");
70                         if (options) {
71                                 /* XXX Parse options if we had any XXX */
72                         }
73                         snprintf(meetmeopts, sizeof(meetmeopts), "%ud|mqxdw", confid);
74                         while(tmp && !ast_strlen_zero(tmp)) {
75                                 tech = strsep(&tmp, "&");
76                                 if (tech) {
77                                         resource = strchr(tech, '/');
78                                         if (resource) {
79                                                 *resource = '\0';
80                                                 resource++;
81                                                 ast_pbx_outgoing_app(tech, AST_FORMAT_SLINEAR, resource, 30000, "MeetMe", meetmeopts, NULL, 0, chan->cid.cid_num, chan->cid.cid_name, NULL, NULL);
82                                         }
83                                 }
84                         }
85                         snprintf(meetmeopts, sizeof(meetmeopts), "%ud|Atqxd", confid);
86                         app = pbx_findapp("Meetme");
87                         if (app) {
88                                 pbx_exec(chan, app, meetmeopts, 1);
89                         } else
90                                 ast_log(LOG_WARNING, "Whoa, meetme doesn't exist!\n");
91                 } else {
92                         ast_log(LOG_ERROR, "Out of memory\n");
93                 }
94         }
95
96         return -1;
97 }
98
99 int unload_module(void)
100 {
101         STANDARD_HANGUP_LOCALUSERS;
102         return ast_unregister_application(app_page);
103 }
104
105 int load_module(void)
106 {
107         return ast_register_application(app_page, page_exec, page_synopsis, page_descrip);
108 }
109
110 char *description(void)
111 {
112         return tdesc;
113 }
114
115 int usecount(void)
116 {
117         int res;
118         STANDARD_USECOUNT(res);
119         return res;
120 }
121
122 char *key()
123 {
124         return ASTERISK_GPL_KEY;
125 }