Index: apps/app_chanspy.c =================================================================== --- apps/app_chanspy.c (revision 74812) +++ apps/app_chanspy.c (working copy) @@ -142,12 +142,14 @@ OPTION_PRIVATE = (1 << 6), /* Private Whisper mode */ OPTION_READONLY = (1 << 7), /* Don't mix the two channels */ OPTION_EXIT = (1 << 8), /* Exit to a valid single digit extension */ + OPTION_ENFORCED = (1 << 9), /* Enforced mode */ } chanspy_opt_flags; enum { OPT_ARG_VOLUME = 0, OPT_ARG_GROUP, OPT_ARG_RECORD, + OPT_ARG_ENFORCED, OPT_ARG_ARRAY_SIZE, } chanspy_opt_args; @@ -159,6 +161,7 @@ AST_APP_OPTION_ARG('v', OPTION_VOLUME, OPT_ARG_VOLUME), AST_APP_OPTION_ARG('g', OPTION_GROUP, OPT_ARG_GROUP), AST_APP_OPTION_ARG('r', OPTION_RECORD, OPT_ARG_RECORD), + AST_APP_OPTION_ARG('e', OPTION_ENFORCED, OPT_ARG_ENFORCED), AST_APP_OPTION('o', OPTION_READONLY), AST_APP_OPTION('X', OPTION_EXIT), }); @@ -464,7 +467,7 @@ } static int common_exec(struct ast_channel *chan, const struct ast_flags *flags, - int volfactor, const int fd, const char *mygroup, const char *spec, + int volfactor, const int fd, const char *mygroup, const char *myenforced, const char *spec, const char *exten, const char *context) { struct ast_channel *peer, *prev, *next; @@ -541,6 +544,10 @@ char *groups[25]; int num_groups = 0; char *dup_group; + char *form_enforced; + int ienf = !myenforced; + char *ext; + char *end; int x; char *s; @@ -573,7 +580,32 @@ if (!igrp) continue; + + if (myenforced) { + ext = alloca(strlen(peer->name)); + form_enforced = alloca(strlen(myenforced) + 3); + + strcpy(form_enforced, ":"); + strcat(form_enforced, myenforced); + strcat(form_enforced, ":"); + + ext = ast_strdupa(peer->name); + ext = strchr(ext, '/'); + *ext = ':'; + if ((end = strchr(ext, '-'))) { + *end++ = ':'; + *end = '\0'; + } + + if (strstr(form_enforced, ext)) + ienf = 1; + + } + + if (!ienf) + continue; + strcpy(peer_name, "spy-"); strncat(peer_name, peer->name, AST_NAME_STRLEN); ptr = strchr(peer_name, '/'); @@ -631,6 +663,7 @@ char *spec = NULL; char *argv[2]; char *mygroup = NULL; + char *myenforced = NULL; char *recbase = NULL; int fd = 0; struct ast_flags flags; @@ -674,6 +707,10 @@ if (ast_test_flag(&flags, OPTION_PRIVATE)) ast_set_flag(&flags, OPTION_WHISPER); + + if (ast_test_flag(&flags, OPTION_ENFORCED)) + myenforced = opts[OPT_ARG_ENFORCED]; + } oldwf = chan->writeformat; @@ -693,7 +730,7 @@ } } - res = common_exec(chan, &flags, volfactor, fd, mygroup, spec, NULL, NULL); + res = common_exec(chan, &flags, volfactor, fd, mygroup, myenforced, spec, NULL, NULL); if (fd) close(fd); @@ -777,7 +814,7 @@ } } - res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, exten, context); + res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, NULL, exten, context); if (fd) close(fd);