add slinfactory object, and change app_chanspy to use it (bug #4724)
[asterisk/asterisk.git] / apps / app_chanspy.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * ChanSpy Listen in on any channel.
5  * 
6  * Copyright (C) 2005 Anthony Minessale II (anthmct@yahoo.com)
7  *
8  * Disclaimed to Digium
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <stdlib.h>
15 #include <unistd.h>
16 #include <string.h>
17 #include <ctype.h>
18
19 #include "asterisk.h"
20
21 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
22
23 #include "asterisk/file.h"
24 #include "asterisk/logger.h"
25 #include "asterisk/channel.h"
26 #include "asterisk/features.h"
27 #include "asterisk/options.h"
28 #include "asterisk/slinfactory.h"
29 #include "asterisk/app.h"
30 #include "asterisk/utils.h"
31 #include "asterisk/say.h"
32 #include "asterisk/pbx.h"
33 #include "asterisk/translate.h"
34 #include "asterisk/module.h"
35 #include "asterisk/lock.h"
36
37 AST_MUTEX_DEFINE_STATIC(modlock);
38
39 #define AST_NAME_STRLEN 256
40 #define ALL_DONE(u, ret) LOCAL_USER_REMOVE(u); return ret;
41 #define get_volfactor(x) x ? ((x > 0) ? (1 << x) : ((1 << abs(x)) * -1)) : 0
42 #define minmax(x,y) x ? (x > y) ? y : ((x < (y * -1)) ? (y * -1) : x) : 0
43
44
45 static char *synopsis = "Tap into any type of asterisk channel and listen to audio";
46 static char *app = "ChanSpy";
47 static char *desc = "   Chanspy([<scanspec>][|<options>])\n\n"
48 "Valid Options:\n"
49 " - q: quiet, don't announce channels beep, etc.\n"
50 " - b: bridged, only spy on channels involved in a bridged call.\n"
51 " - v([-4..4]): adjust the initial volume. (negative is quieter)\n"
52 " - g(grp): enforce group.  Match only calls where their ${SPYGROUP} is 'grp'.\n"
53 " - r[(basename)]: Record session to monitor spool dir (with optional basename, default is 'chanspy')\n\n"
54 "If <scanspec> is specified, only channel names *beginning* with that string will be scanned.\n"
55 "('all' or an empty string are also both valid <scanspec>)\n\n"
56 "While Spying:\n\n"
57 "Dialing # cycles the volume level.\n"
58 "Dialing * will stop spying and look for another channel to spy on.\n"
59 "Dialing a series of digits followed by # builds a channel name to append to <scanspec>\n"
60 "(e.g. run Chanspy(Agent) and dial 1234# while spying to jump to channel Agent/1234)\n\n"
61 "";
62
63 #define OPTION_QUIET     (1 << 0)       /* Quiet, no announcement */
64 #define OPTION_BRIDGED   (1 << 1)       /* Only look at bridged calls */
65 #define OPTION_VOLUME    (1 << 2)       /* Specify initial volume */
66 #define OPTION_GROUP     (1 << 3)   /* Only look at channels in group */
67 #define OPTION_RECORD    (1 << 4)   /* Record */
68
69 AST_DECLARE_OPTIONS(chanspy_opts,{
70         ['q'] = { OPTION_QUIET },
71         ['b'] = { OPTION_BRIDGED },
72         ['v'] = { OPTION_VOLUME, 1 },
73         ['g'] = { OPTION_GROUP, 2 },
74         ['r'] = { OPTION_RECORD, 3 },
75 });
76
77 STANDARD_LOCAL_USER;
78 LOCAL_USER_DECL;
79
80 struct chanspy_translation_helper {
81         /* spy data */
82         struct ast_channel_spy spy;
83         int volfactor;
84         int fd;
85         struct ast_slinfactory slinfactory[2];
86 };
87
88 /* Prototypes */
89 static struct ast_channel *local_get_channel_begin_name(char *name);
90 static struct ast_channel *local_channel_walk(struct ast_channel *chan);
91 static void spy_release(struct ast_channel *chan, void *data);
92 static void *spy_alloc(struct ast_channel *chan, void *params);
93 static struct ast_frame *spy_queue_shift(struct ast_channel_spy *spy, int qnum);
94 static void ast_flush_spy_queue(struct ast_channel_spy *spy);
95 static int spy_generate(struct ast_channel *chan, void *data, int len, int samples);
96 static void start_spying(struct ast_channel *chan, struct ast_channel *spychan, struct ast_channel_spy *spy);
97 static void stop_spying(struct ast_channel *chan, struct ast_channel_spy *spy);
98 static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int *volfactor, int fd);
99 static int chanspy_exec(struct ast_channel *chan, void *data);
100
101
102 #if 0
103 static struct ast_channel *local_get_channel_by_name(char *name) 
104 {
105         struct ast_channel *ret;
106         ast_mutex_lock(&modlock);
107         if ((ret = ast_get_channel_by_name_locked(name))) {
108                 ast_mutex_unlock(&ret->lock);
109         }
110         ast_mutex_unlock(&modlock);
111
112         return ret;
113 }
114 #endif
115
116 static struct ast_channel *local_channel_walk(struct ast_channel *chan) 
117 {
118         struct ast_channel *ret;
119         ast_mutex_lock(&modlock);       
120         if ((ret = ast_channel_walk_locked(chan))) {
121                 ast_mutex_unlock(&ret->lock);
122         }
123         ast_mutex_unlock(&modlock);                     
124         return ret;
125 }
126
127 static struct ast_channel *local_get_channel_begin_name(char *name) 
128 {
129         struct ast_channel *chan, *ret = NULL;
130         ast_mutex_lock(&modlock);
131         chan = local_channel_walk(NULL);
132         while (chan) {
133                 if (!strncmp(chan->name, name, strlen(name))) {
134                         ret = chan;
135                         break;
136                 }
137                 chan = local_channel_walk(chan);
138         }
139         ast_mutex_unlock(&modlock);
140         
141         return ret;
142 }
143
144
145 static void spy_release(struct ast_channel *chan, void *data) 
146 {
147         struct chanspy_translation_helper *csth = data;
148
149         ast_slinfactory_destroy(&csth->slinfactory[0]);
150         ast_slinfactory_destroy(&csth->slinfactory[1]);
151
152         return;
153 }
154
155 static void *spy_alloc(struct ast_channel *chan, void *params) 
156 {
157         struct chanspy_translation_helper *csth = params;
158         ast_slinfactory_init(&csth->slinfactory[0]);
159         ast_slinfactory_init(&csth->slinfactory[1]);
160         return params;
161 }
162
163 static struct ast_frame *spy_queue_shift(struct ast_channel_spy *spy, int qnum) 
164 {
165         struct ast_frame *f;
166         
167         if (qnum < 0 || qnum > 1)
168                 return NULL;
169
170         f = spy->queue[qnum];
171         if (f) {
172                 spy->queue[qnum] = f->next;
173                 return f;
174         }
175         return NULL;
176 }
177
178
179 static void ast_flush_spy_queue(struct ast_channel_spy *spy) 
180 {
181         struct ast_frame *f=NULL;
182         int x = 0;
183         ast_mutex_lock(&spy->lock);
184         for(x=0;x<2;x++) {
185                 f = NULL;
186                 while((f = spy_queue_shift(spy, x))) 
187                         ast_frfree(f);
188         }
189         ast_mutex_unlock(&spy->lock);
190 }
191
192
193 #if 0
194 static int extract_audio(short *buf, size_t len, struct ast_trans_pvt *trans, struct ast_frame *fr, int *maxsamp)
195 {
196         struct ast_frame *f;
197         int size, retlen = 0;
198         
199         if (trans) {
200                 if ((f = ast_translate(trans, fr, 0))) {
201                         size = (f->datalen > len) ? len : f->datalen;
202                         memcpy(buf, f->data, size);
203                         retlen = f->datalen;
204                         ast_frfree(f);
205                 } else {
206                         /* your guess is as good as mine why this will happen but it seems to only happen on iax and appears harmless */
207                         ast_log(LOG_DEBUG, "Failed to translate frame from %s\n", ast_getformatname(fr->subclass));
208                 }
209         } else {
210                 size = (fr->datalen > len) ? len : fr->datalen;
211                 memcpy(buf, fr->data, size);
212                 retlen = fr->datalen;
213         }
214
215         if (retlen > 0 && (size = retlen / 2)) {
216                 if (size > *maxsamp) {
217                         *maxsamp = size;
218                 }
219         }
220         
221         return retlen;
222 }
223
224
225 static int spy_queue_ready(struct ast_channel_spy *spy)
226 {
227         int res = 0;
228
229         ast_mutex_lock(&spy->lock);
230         if (spy->status == CHANSPY_RUNNING) {
231                 res = (spy->queue[0] && spy->queue[1]) ? 1 : 0;
232         } else {
233                 res = (spy->queue[0] || spy->queue[1]) ? 1 : -1;
234         }
235         ast_mutex_unlock(&spy->lock);
236         return res;
237 }
238 #endif
239
240
241 static int spy_generate(struct ast_channel *chan, void *data, int len, int samples) 
242 {
243
244                 struct chanspy_translation_helper *csth = data;
245                 struct ast_frame frame, *f;
246                 int len0 = 0, len1 = 0, samp0 = 0, samp1 = 0, x, vf, maxsamp;
247                 short buf0[1280], buf1[1280], buf[1280];
248                 
249                 if (csth->spy.status == CHANSPY_DONE) {
250             return -1;
251         }
252
253                 ast_mutex_lock(&csth->spy.lock);
254                 while((f = csth->spy.queue[0])) {
255                         csth->spy.queue[0] = f->next;
256                         ast_slinfactory_feed(&csth->slinfactory[0], f);
257                         ast_frfree(f);
258                 }
259                 ast_mutex_unlock(&csth->spy.lock);
260                 ast_mutex_lock(&csth->spy.lock);
261                 while((f = csth->spy.queue[1])) {
262                         csth->spy.queue[1] = f->next;
263                         ast_slinfactory_feed(&csth->slinfactory[1], f);
264                         ast_frfree(f);
265                 }
266                 ast_mutex_unlock(&csth->spy.lock);
267                 
268                 if (csth->slinfactory[0].size < len || csth->slinfactory[1].size < len) {
269                         return 0;
270                 }
271                 
272                 if ((len0 = ast_slinfactory_read(&csth->slinfactory[0], buf0, len))) {
273                         samp0 = len0 / 2;
274                 } 
275                 if((len1 = ast_slinfactory_read(&csth->slinfactory[1], buf1, len))) {
276                         samp1 = len1 / 2;
277                 }
278
279                 maxsamp = (samp0 > samp1) ? samp0 : samp1;
280                 vf = get_volfactor(csth->volfactor);
281         vf = minmax(vf, 16);
282                 
283                 for(x=0; x < maxsamp; x++) {
284                         if (vf < 0) {
285                                 if (samp0) {
286                                         buf0[x] /= abs(vf);
287                                 }
288                                 if (samp1) {
289                                         buf1[x] /= abs(vf);
290                                 }
291                         } else if (vf > 0) {
292                                 if (samp0) {
293                                         buf0[x] *= vf;
294                                 }
295                                 if (samp1) {
296                                         buf1[x] *= vf;
297                                 }
298                         }
299                         if (samp0 && samp1) {
300                                 if (x < samp0 && x < samp1) {
301                                         buf[x] = buf0[x] + buf1[x];
302                                 } else if (x < samp0) {
303                                         buf[x] = buf0[x];
304                                 } else if (x < samp1) {
305                                         buf[x] = buf1[x];
306                                 }
307                         } else if (x < samp0) {
308                                 buf[x] = buf0[x];
309                         } else if (x < samp1) {
310                                 buf[x] = buf1[x];
311                         }
312                 }
313                 
314                 memset(&frame, 0, sizeof(frame));
315                 frame.frametype = AST_FRAME_VOICE;
316                 frame.subclass = AST_FORMAT_SLINEAR;
317                 frame.data = buf;
318                 frame.samples = x;
319                 frame.datalen = x * 2;
320
321                 if (ast_write(chan, &frame)) {
322                         csth->spy.status = CHANSPY_DONE;
323                         return -1;
324                 }
325
326                 if (csth->fd) {
327                         write(csth->fd, buf1, len1);
328                 }
329
330                 return 0;
331 }
332
333
334 static struct ast_generator spygen = {
335     alloc: spy_alloc, 
336     release: spy_release, 
337     generate: spy_generate, 
338 };
339
340 static void start_spying(struct ast_channel *chan, struct ast_channel *spychan, struct ast_channel_spy *spy) 
341 {
342
343         struct ast_channel_spy *cptr=NULL;
344         struct ast_channel *peer;
345
346
347         ast_log(LOG_WARNING, "Attaching %s to %s\n", spychan->name, chan->name);
348
349
350         ast_mutex_lock(&chan->lock);
351         if (chan->spiers) {
352                 for(cptr=chan->spiers;cptr && cptr->next;cptr=cptr->next);
353                 cptr->next = spy;
354         } else {
355                 chan->spiers = spy;
356         }
357         ast_mutex_unlock(&chan->lock);
358         if ( ast_test_flag(chan, AST_FLAG_NBRIDGE) && (peer = ast_bridged_channel(chan))) {
359                 ast_softhangup(peer, AST_SOFTHANGUP_UNBRIDGE);  
360         }
361
362 }
363
364 static void stop_spying(struct ast_channel *chan, struct ast_channel_spy *spy) 
365 {
366         struct ast_channel_spy *cptr=NULL, *prev=NULL;
367         int count = 0;
368
369         while(ast_mutex_trylock(&chan->lock)) {
370                 /* if its locked already it's almost surely hanging up and we are too late 
371                    we can safely remove the head pointer if it points at us without needing a lock.
372                    since everybody spying will be in the same boat whomever is pointing at the head
373                    will surely erase it which is all we really need since it's a linked list of
374                    staticly declared structs that belong to each spy.
375                 */
376                 if (chan->spiers == spy) {
377                         chan->spiers = NULL;
378                         return;
379                 }
380                 count++;
381                 if (count > 10) {
382                         return;
383                 }
384                 sched_yield();
385         }
386
387         for(cptr=chan->spiers; cptr; cptr=cptr->next) {
388                 if (cptr == spy) {
389                         if (prev) {
390                                 prev->next = cptr->next;
391                                 cptr->next = NULL;
392                         } else
393                                 chan->spiers = NULL;
394                 }
395                 prev = cptr;
396         }
397         ast_mutex_unlock(&chan->lock);
398
399 }
400
401 static int channel_spy(struct ast_channel *chan, struct ast_channel *spyee, int *volfactor, int fd) 
402 {
403         struct chanspy_translation_helper csth;
404         int running = 1, res = 0, x = 0;
405         char inp[24];
406         char *name=NULL;
407         struct ast_frame *f;
408
409         if (chan && !ast_check_hangup(chan) && spyee && !ast_check_hangup(spyee)) {
410                 memset(inp, 0, sizeof(inp));
411                 name = ast_strdupa(spyee->name);
412                 if (option_verbose >= 2)
413                         ast_verbose(VERBOSE_PREFIX_2 "Spying on channel %s\n", name);
414
415                 memset(&csth, 0, sizeof(csth));
416                 csth.spy.status = CHANSPY_RUNNING;
417                 ast_mutex_init(&csth.spy.lock);
418                 csth.volfactor = *volfactor;
419                 
420                 if (fd) {
421                         csth.fd = fd;
422                 }
423                 start_spying(spyee, chan, &csth.spy);
424                 ast_activate_generator(chan, &spygen, &csth);
425
426                 while(csth.spy.status == CHANSPY_RUNNING && 
427                           chan && !ast_check_hangup(chan) && 
428                           spyee && 
429                           !ast_check_hangup(spyee) 
430                           && running == 1 && 
431                           (res = ast_waitfor(chan, -1) > -1)) {
432                         if ((f = ast_read(chan))) {
433                                 res = 0;
434                                 if (f->frametype == AST_FRAME_DTMF) {
435                                         res = f->subclass;
436                                 }
437                                 ast_frfree(f);
438                                 if (!res) {
439                                         continue;
440                                 }
441                         } else {
442                                 break;
443                         }
444                         if (x == sizeof(inp)) {
445                                 x = 0;
446                         }
447                         if (res < 0) {
448                                 running = -1;
449                         }
450                         if (res == 0) {
451                                 continue;
452                         } else if (res == '*') {
453                                 running = 0; 
454                         } else if (res == '#') {
455                                 if (!ast_strlen_zero(inp)) {
456                                         running = x ? atoi(inp) : -1;
457                                         break;
458                                 } else {
459                                         csth.volfactor++;
460                                         if (csth.volfactor > 4) {
461                                                 csth.volfactor = -4;
462                                         }
463                                         if (option_verbose > 2) {
464                                                 ast_verbose(VERBOSE_PREFIX_3"Setting spy volume on %s to %d\n", chan->name, csth.volfactor);
465                                         }
466                                         *volfactor = csth.volfactor;
467                                 }
468                         } else if (res >= 48 && res <= 57) {
469                                 inp[x++] = res;
470                         }
471                 }
472                 ast_deactivate_generator(chan);
473                 stop_spying(spyee, &csth.spy);
474
475                 if (option_verbose >= 2) {
476                         ast_verbose(VERBOSE_PREFIX_2 "Done Spying on channel %s\n", name);
477                 }
478                 ast_flush_spy_queue(&csth.spy);
479         } else {
480                 running = 0;
481         }
482         ast_mutex_destroy(&csth.spy.lock);
483         return running;
484 }
485
486
487
488 static int chanspy_exec(struct ast_channel *chan, void *data)
489 {
490         struct localuser *u;
491         struct ast_channel *peer=NULL, *prev=NULL;
492         char name[AST_NAME_STRLEN],
493                 peer_name[AST_NAME_STRLEN],
494                 *args,
495                 *ptr = NULL,
496                 *options = NULL,
497                 *spec = NULL,
498                 *argv[5],
499                 *mygroup = NULL,
500                 *recbase = NULL;
501         int res = -1,
502                 volfactor = 0,
503                 silent = 0,
504                 argc = 0,
505                 bronly = 0,
506                 chosen = 0,
507                 count=0,
508                 waitms = 100,
509                 num = 0,
510                 oldrf = 0,
511                 oldwf = 0,
512                 fd = 0;
513         struct ast_flags flags;
514
515
516         if (!(args = ast_strdupa((char *)data))) {
517                 ast_log(LOG_ERROR, "Out of memory!\n");
518                 return -1;
519         }
520
521         oldrf = chan->readformat;
522         oldwf = chan->writeformat;
523         if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) {
524                 ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
525                 return -1;
526         }
527         
528         if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
529                 ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
530                 return -1;
531         }
532
533         LOCAL_USER_ADD(u);
534         ast_answer(chan);
535
536         ast_set_flag(chan, AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */
537
538
539         if ((argc = ast_separate_app_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
540                 spec = argv[0];
541                 if ( argc > 1) {
542                         options = argv[1];
543                 }
544                 if (ast_strlen_zero(spec) || !strcmp(spec, "all")) {
545                         spec = NULL;
546                 }
547         }
548         
549         if (options) {
550                 char *opts[3];
551                 ast_parseoptions(chanspy_opts, &flags, opts, options);
552                 if (ast_test_flag(&flags, OPTION_GROUP)) {
553                         mygroup = opts[1];
554                 }
555                 if (ast_test_flag(&flags, OPTION_RECORD)) {
556                         if (!(recbase = opts[2])) {
557                                 recbase = "chanspy";
558                         }
559                 }
560                 silent = ast_test_flag(&flags, OPTION_QUIET);
561                 bronly = ast_test_flag(&flags, OPTION_BRIDGED);
562                 if (ast_test_flag(&flags, OPTION_VOLUME) && opts[1]) {
563                         if (sscanf(opts[0], "%d", &volfactor) != 1)
564                                 ast_log(LOG_NOTICE, "volfactor must be a number between -4 and 4\n");
565                         else {
566                                 volfactor = minmax(volfactor, 4);
567                         }
568                 }
569         }
570
571         if (recbase) {
572                 char filename[512];
573                 snprintf(filename,sizeof(filename),"%s/%s.%ld.raw",ast_config_AST_MONITOR_DIR, recbase, time(NULL));
574                 if ((fd = open(filename, O_CREAT | O_WRONLY, O_TRUNC)) <= 0) {
575                         ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename);
576                         fd = 0;
577                 }
578         }
579
580         for(;;) {
581                 if (!silent) {
582                         res = ast_streamfile(chan, "beep", chan->language);
583                         if (!res)
584                                 res = ast_waitstream(chan, "");
585                         if (res < 0) {
586                                 ast_clear_flag(chan, AST_FLAG_SPYING);
587                                 break;
588                         }
589                 }
590
591                 count = 0;
592                 res = ast_waitfordigit(chan, waitms);
593                 if (res < 0) {
594                         ast_clear_flag(chan, AST_FLAG_SPYING);
595                         break;
596                 }
597                                 
598                 peer = local_channel_walk(NULL);
599                 prev=NULL;
600                 while(peer) {
601                         if (peer != chan) {
602                                 char *group = NULL;
603                                 int igrp = 1;
604
605                                 if (peer == prev && !chosen) {
606                                         break;
607                                 }
608                                 chosen = 0;
609                                 group = pbx_builtin_getvar_helper(peer, "SPYGROUP");
610                                 if (mygroup) {
611                                         if (!group || strcmp(mygroup, group)) {
612                                                 igrp = 0;
613                                         }
614                                 }
615                                 
616                                 if (igrp && (!spec || ((strlen(spec) < strlen(peer->name) &&
617                                                                            !strncasecmp(peer->name, spec, strlen(spec)))))) {
618                                         if (peer && (!bronly || ast_bridged_channel(peer)) &&
619                                                 !ast_check_hangup(peer) && !ast_test_flag(peer, AST_FLAG_SPYING)) {
620                                                 int x = 0;
621
622                                                 strncpy(peer_name, peer->name, AST_NAME_STRLEN);
623                                                 ptr = strchr(peer_name, '/');
624                                                 *ptr = '\0';
625                                                 ptr++;
626                                                 for (x = 0 ; x < strlen(peer_name) ; x++) {
627                                                         if (peer_name[x] == '/') {
628                                                                 break;
629                                                         }
630                                                         peer_name[x] = tolower(peer_name[x]);
631                                                 }
632
633                                                 if (!silent) {
634                                                         if (ast_fileexists(peer_name, NULL, NULL) != -1) {
635                                                                 res = ast_streamfile(chan, peer_name, chan->language);
636                                                                 if (!res)
637                                                                         res = ast_waitstream(chan, "");
638                                                                 if (res)
639                                                                         break;
640                                                         } else
641                                                                 res = ast_say_character_str(chan, peer_name, "", chan->language);
642                                                         if ((num=atoi(ptr))) 
643                                                                 ast_say_digits(chan, atoi(ptr), "", chan->language);
644                                                 }
645                                                 count++;
646                                                 prev = peer;
647                                                 res = channel_spy(chan, peer, &volfactor, fd);
648                                                 if (res == -1) {
649                                                         break;
650                                                 } else if (res > 1 && spec) {
651                                                         snprintf(name, AST_NAME_STRLEN, "%s/%d", spec, res);
652                                                         if ((peer = local_get_channel_begin_name(name))) {
653                                                                 chosen = 1;
654                                                         }
655                                                         continue;
656                                                 }
657                                         }
658                                 }
659                         }
660                         if ((peer = local_channel_walk(peer)) == NULL) {
661                                 break;
662                         }
663                 }
664                 waitms = count ? 100 : 5000;
665         }
666         
667
668         if (fd > 0) {
669                 close(fd);
670         }
671
672         if (oldrf && ast_set_read_format(chan, oldrf) < 0) {
673                 ast_log(LOG_ERROR, "Could Not Set Read Format.\n");
674         }
675         
676         if (oldwf && ast_set_write_format(chan, oldwf) < 0) {
677                 ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
678         }
679
680         ast_clear_flag(chan, AST_FLAG_SPYING);
681         ALL_DONE(u, res);
682 }
683
684 int unload_module(void)
685 {
686         STANDARD_HANGUP_LOCALUSERS;
687         return ast_unregister_application(app);
688 }
689
690 int load_module(void)
691 {
692         return ast_register_application(app, chanspy_exec, synopsis, desc);
693 }
694
695 char *description(void)
696 {
697         return synopsis;
698 }
699
700 int usecount(void)
701 {
702         int res;
703         STANDARD_USECOUNT(res);
704         return res;
705 }
706
707 char *key()
708 {
709         return ASTERISK_GPL_KEY;
710 }