| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-01-21 07:06:25 +00:00
										 |  |  |  * Copyright (c) 2004 - 2005 Tilghman Lesher.  All rights reserved. | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Tilghman Lesher <app_verbose_v001@the-tilghman.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This code is released by the author with no restrictions on usage. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * 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. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Verbose logging application | 
					
						
							| 
									
										
										
										
											2005-09-15 15:44:26 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * \author Tilghman Lesher <app_verbose_v001@the-tilghman.com> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | #include <stdio.h>
 | 
					
						
							|  |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <unistd.h>
 | 
					
						
							|  |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-21 06:02:45 +00:00
										 |  |  | #include "asterisk/options.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static char *app_verbose = "Verbose"; | 
					
						
							|  |  |  | static char *verbose_synopsis = "Send arbitrary text to verbose output"; | 
					
						
							|  |  |  | static char *verbose_descrip = | 
					
						
							|  |  |  | "Verbose([<level>|]<message>)\n" | 
					
						
							| 
									
										
										
										
											2005-11-07 22:01:22 +00:00
										 |  |  | "  level must be an integer value.  If not specified, defaults to 0.\n"; | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | static char *app_log = "Log"; | 
					
						
							|  |  |  | static char *log_synopsis = "Send arbitrary text to a selected log level"; | 
					
						
							|  |  |  | static char *log_descrip = | 
					
						
							|  |  |  | "Log(<level>|<message>)\n" | 
					
						
							|  |  |  | "  level must be one of ERROR, WARNING, NOTICE, DEBUG, VERBOSE, DTMF\n"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static int verbose_exec(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *vtext; | 
					
						
							|  |  |  | 	int vsize; | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	struct ast_module_user *u; | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	u = ast_module_user_add(chan); | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (data) { | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 		char *tmp; | 
					
						
							|  |  |  | 		vtext = ast_strdupa(data); | 
					
						
							|  |  |  | 		tmp = strsep(&vtext, "|"); | 
					
						
							|  |  |  | 		if (vtext) { | 
					
						
							|  |  |  | 			if (sscanf(tmp, "%d", &vsize) != 1) { | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 				vsize = 0; | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a verboser number\n", vtext); | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			vtext = tmp; | 
					
						
							|  |  |  | 			vsize = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (option_verbose >= vsize) { | 
					
						
							|  |  |  | 			switch (vsize) { | 
					
						
							|  |  |  | 			case 0: | 
					
						
							|  |  |  | 				ast_verbose("%s\n", vtext); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 1: | 
					
						
							|  |  |  | 				ast_verbose(VERBOSE_PREFIX_1 "%s\n", vtext); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 2: | 
					
						
							|  |  |  | 				ast_verbose(VERBOSE_PREFIX_2 "%s\n", vtext); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			case 3: | 
					
						
							|  |  |  | 				ast_verbose(VERBOSE_PREFIX_3 "%s\n", vtext); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			default: | 
					
						
							|  |  |  | 				ast_verbose(VERBOSE_PREFIX_4 "%s\n", vtext); | 
					
						
							| 
									
										
										
										
											2006-01-21 08:13:12 +00:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_user_remove(u); | 
					
						
							| 
									
										
										
										
											2005-10-19 18:19:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | static int log_exec(struct ast_channel *chan, void *data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	char *level, *ltext; | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	struct ast_module_user *u; | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 	int lnum = -1; | 
					
						
							|  |  |  | 	char extension[AST_MAX_EXTENSION + 5], context[AST_MAX_EXTENSION + 2]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	u = ast_module_user_add(chan); | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 	if (ast_strlen_zero(data)) { | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 		ast_module_user_remove(u); | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-05-10 13:22:15 +00:00
										 |  |  | 	ltext = ast_strdupa(data); | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	level = strsep(<ext, "|"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!strcasecmp(level, "ERROR")) { | 
					
						
							|  |  |  | 		lnum = __LOG_ERROR; | 
					
						
							|  |  |  | 	} else if (!strcasecmp(level, "WARNING")) { | 
					
						
							|  |  |  | 		lnum = __LOG_WARNING; | 
					
						
							|  |  |  | 	} else if (!strcasecmp(level, "NOTICE")) { | 
					
						
							|  |  |  | 		lnum = __LOG_NOTICE; | 
					
						
							|  |  |  | 	} else if (!strcasecmp(level, "DEBUG")) { | 
					
						
							|  |  |  | 		lnum = __LOG_DEBUG; | 
					
						
							|  |  |  | 	} else if (!strcasecmp(level, "VERBOSE")) { | 
					
						
							|  |  |  | 		lnum = __LOG_VERBOSE; | 
					
						
							|  |  |  | 	} else if (!strcasecmp(level, "DTMF")) { | 
					
						
							|  |  |  | 		lnum = __LOG_DTMF; | 
					
						
							|  |  |  | 	} else if (!strcasecmp(level, "EVENT")) { | 
					
						
							|  |  |  | 		lnum = __LOG_EVENT; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		ast_log(LOG_ERROR, "Unknown log level: '%s'\n", level); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (lnum > -1) { | 
					
						
							|  |  |  | 		snprintf(context, sizeof(context), "@ %s", chan->context); | 
					
						
							|  |  |  | 		snprintf(extension, sizeof(extension), "Ext. %s", chan->exten); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ast_log(lnum, extension, chan->priority, context, "%s\n", ltext); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_user_remove(u); | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res = ast_unregister_application(app_verbose); | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 	res |= ast_unregister_application(app_log); | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | 	ast_module_user_hangup_all(); | 
					
						
							| 
									
										
										
										
											2005-10-18 22:52:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return res;	 | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2005-12-21 09:33:41 +00:00
										 |  |  | 	int res; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	res = ast_register_application(app_log, log_exec, log_synopsis, log_descrip); | 
					
						
							|  |  |  | 	res |= ast_register_application(app_verbose, verbose_exec, verbose_synopsis, verbose_descrip); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return res; | 
					
						
							| 
									
										
										
										
											2004-08-06 02:12:54 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send verbose output"); |