Skip to content
Snippets Groups Projects
app_chanspy.c 35.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	int volfactor = 0;
    	int res;
    
    	AST_DECLARE_APP_ARGS(args,
    		AST_APP_ARG(context);
    		AST_APP_ARG(options);
    	);
    
    
    	data = ast_strdupa(data);
    
    
    	AST_STANDARD_APP_ARGS(args, data);
    	if (!ast_strlen_zero(args.context) && (ptr = strchr(args.context, '@'))) {
    		exten = args.context;
    		*ptr++ = '\0';
    		args.context = ptr;
    
    	if (ast_strlen_zero(args.context))
    		args.context = ast_strdupa(chan->context);
    
    	if (args.options) {
    
    		char *opts[OPT_ARG_ARRAY_SIZE];
    
    		ast_app_parse_options(spy_opts, &flags, opts, args.options);
    
    		if (ast_test_flag(&flags, OPTION_GROUP))
    			mygroup = opts[OPT_ARG_GROUP];
    
    		if (ast_test_flag(&flags, OPTION_RECORD) &&
    
    Michiel van Baak's avatar
    Michiel van Baak committed
    			!(recbase = opts[OPT_ARG_RECORD]))
    
    			recbase = "chanspy";
    
    
    		if (ast_test_flag(&flags, OPTION_VOLUME) && opts[OPT_ARG_VOLUME]) {
    			int vol;
    
    			if ((sscanf(opts[OPT_ARG_VOLUME], "%d", &vol) != 1) || (vol > 4) || (vol < -4))
    				ast_log(LOG_NOTICE, "Volume factor must be a number between -4 and 4\n");
    			else
    				volfactor = vol;
    		}
    
    
    		if (ast_test_flag(&flags, OPTION_PRIVATE))
    			ast_set_flag(&flags, OPTION_WHISPER);
    
    
    		
    		if (ast_test_flag(&flags, OPTION_NAME)) {
    			if (!ast_strlen_zero(opts[OPT_ARG_NAME])) {
    				char *delimiter;
    				if ((delimiter = strchr(opts[OPT_ARG_NAME], '@'))) {
    					mailbox = opts[OPT_ARG_NAME];
    					*delimiter++ = '\0';
    					name_context = delimiter;
    				} else {
    					mailbox = opts[OPT_ARG_NAME];
    				}
    			}
    		}
    
    
    	} else
    		ast_clear_flag(&flags, AST_FLAGS_ALL);
    
    
    	oldwf = chan->writeformat;
    	if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) {
    		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
    		return -1;
    	}
    
    	if (recbase) {
    
    		char filename[PATH_MAX];
    
    
    		snprintf(filename, sizeof(filename), "%s/%s.%d.raw", ast_config_AST_MONITOR_DIR, recbase, (int) time(NULL));
    
    		if ((fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, AST_FILE_MODE)) <= 0) {
    
    			ast_log(LOG_WARNING, "Cannot open '%s' for recording\n", filename);
    			fd = 0;
    		}
    	}
    
    
    	res = common_exec(chan, &flags, volfactor, fd, mygroup, NULL, NULL, exten, args.context, mailbox, name_context);
    
    Kevin P. Fleming's avatar
    Kevin P. Fleming committed
    	if (fd)
    
    Kevin P. Fleming's avatar
    Kevin P. Fleming committed
    	if (oldwf && ast_set_write_format(chan, oldwf) < 0)
    
    		ast_log(LOG_ERROR, "Could Not Set Write Format.\n");
    
    
    Kevin P. Fleming's avatar
    Kevin P. Fleming committed
    	return res;
    
    static int unload_module(void)
    
    	int res = 0;
    
    	res |= ast_unregister_application(app_chan);
    	res |= ast_unregister_application(app_ext);
    
    static int load_module(void)
    
    	int res = 0;
    
    	res |= ast_register_application(app_chan, chanspy_exec, tdesc, desc_chan);
    	res |= ast_register_application(app_ext, extenspy_exec, tdesc, desc_ext);
    
    	return res;
    
    AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Listen to the audio of an active channel");