diff --exclude '.depend*' --exclude '.svn*' --exclude '*.o' --exclude '*.so' -rNu trunk_orig/res/Makefile trunk/res/Makefile --- trunk_orig/res/Makefile 2005-12-12 09:37:45.000000000 +0100 +++ trunk/res/Makefile 2005-12-10 19:55:51.000000000 +0100 @@ -11,7 +11,7 @@ # the GNU General Public License # -MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so +MODS=res_indications.so res_monitor.so res_adsi.so res_agi.so res_features.so res_testphone.so ifneq ($(wildcard $(CROSS_COMPILE_TARGET)/usr/include/odbcinst.h)$(wildcard $(CROSS_COMPILE_TARGET)/usr/local/include/odbcinst.h),) ifneq (${OSARCH},FreeBSD) diff --exclude '.depend*' --exclude '.svn*' --exclude '*.o' --exclude '*.so' -rNu trunk_orig/res/res_testphone.c trunk/res/res_testphone.c --- trunk_orig/res/res_testphone.c 1970-01-01 01:00:00.000000000 +0100 +++ trunk/res/res_testphone.c 2005-12-12 09:42:13.000000000 +0100 @@ -0,0 +1,202 @@ +/* + * Asterisk -- An open source telephony toolkit. + * + * Copyright (C) 2005 Christian Richter + * + * + * See http://www.asterisk.org for more information about + * the Asterisk project. Please do not directly contact + * any of the maintainers of this project for assistance; + * the project provides a web site, mailing lists and IRC + * channels for your use. + * + * This program is free software, distributed under the terms of + * the GNU General Public License Version 2. See the LICENSE file + * at the top of the source tree. + */ + +/*! \file res_testphone.c + * + * \brief Make test calls from the cli + * + * \author Christian Richter + * + * Adds Cli commands to create calls to test extensions. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "asterisk.h" + +ASTERISK_FILE_VERSION(__FILE__, "$Revision: 7221 $") + +#include "asterisk/lock.h" +#include "asterisk/file.h" +#include "asterisk/cli.h" +#include "asterisk/logger.h" +#include "asterisk/config.h" +#include "asterisk/channel.h" +#include "asterisk/pbx.h" +#include "asterisk/module.h" +#include "asterisk/utils.h" + + +char *dtext="Adds Cli commands to create calls, to test extensions."; + +/* + * Help for commands provided by this module ... + */ +static char help_testphone_call[] = +"Usage: testphone call []\n" +" Create a Channel of type with CID \n"; + +struct parms { + char *data; + char *cid; +}; + +static void *testphone_make_call(void *arg) +{ + char *type; + char *data; + struct parms *parms = (struct parms *) arg; + char *orig; + int ret; + + struct ast_channel *chan; + + orig=parms->data; + + type=strsep(&parms->data,"/"); + data=strsep(&parms->data,"/"); + + + chan=ast_request(type, AST_FORMAT_ALAW , data, &ret); + + if (!chan) { + ast_log(LOG_WARNING,"Couldn't create call to %s/%s\n",type,data); + free(orig); + return 0; + } + + free(orig); + free(parms); + + ast_log(LOG_NOTICE,"Calling %s/%s\n",type,data); + ast_call(chan, data, 0); + + struct ast_frame *frame; + while ( (frame=ast_read(chan)) ) { + + ast_log(LOG_NOTICE,"Got frame: %d:%d\n", + frame->frametype, + frame->subclass ); + + if ( (frame->frametype == AST_FRAME_CONTROL) && + (frame->subclass == AST_CONTROL_HANGUP) ) { + + ast_hangup(chan); + break; + } + + + if ( frame->frametype == AST_FRAME_NULL) { + ast_hangup(chan); + break; + } + } + + ast_log(LOG_NOTICE,"Call finished\n"); + return 0; +} + + +/* + * Implementation of functions provided by this module + */ + +/* + * Call command stuff + */ +static int handle_testphone_call(int fd, int argc, char *argv[]) +{ + struct parms *parms=malloc(sizeof(struct parms)); + + pthread_t thread; + + ast_log(LOG_NOTICE,"argc: %d\n",argc); + + if (argc < 3) return RESULT_SHOWUSAGE; + + parms->data=strdup(argv[2]); + + if ( argc == 4) { + parms->cid=strdup(argv[3]); + ast_log(LOG_NOTICE,"CID: %s\n",parms->cid); + } + + ast_log(LOG_NOTICE,"Channel: %s\n",parms->data); + + + if (ast_pthread_create(&thread, NULL, testphone_make_call, parms )<0) { + ast_log(LOG_WARNING,"Couldn't create thread\n"); + } + + + + return 0; +} + +/* + * CLI entries for commands provided by this module + */ +static struct ast_cli_entry testphone_call_cli = + { { "testphone", "call", NULL }, handle_testphone_call, + "create a testcall", help_testphone_call, + NULL }; + + +/* + * Standard module functions ... + */ +int unload_module(void) +{ + /* unload clis */ + ast_cli_unregister(&testphone_call_cli); + return 0; +} + + +int load_module(void) +{ + ast_cli_register(&testphone_call_cli); + return 0; +} + +int reload(void) +{ + return 0; +} + +char *description(void) +{ + /* that the following cast is needed, is yuk! */ + return (char*)dtext; +} + +int usecount(void) +{ + return 0; +} + +char *key() +{ + return ASTERISK_GPL_KEY; +}