2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Asterisk  - -  An  open  source  telephony  toolkit . 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 22:16:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Copyright  ( C )  1999  -  2006 ,  Digium ,  Inc . 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2004-08-31 00:08:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Mark  Spencer  < markster @ digium . com > 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +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 . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  This  program  is  free  software ,  distributed  under  the  terms  of 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  the  GNU  General  Public  License  Version  2.  See  the  LICENSE  file 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  at  the  top  of  the  source  tree . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 20:12:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \file
 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-24 20:12:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ brief  The  Asterisk  Management  Interface  -  AMI 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-14 20:46:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-30 21:18:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ author  Mark  Spencer  < markster @ digium . com > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-24 19:49:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ extref  OpenSSL  http : //www.openssl.org - for AMI/SSL 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  At  the  moment  this  file  contains  a  number  of  functions ,  namely : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  data  structures  storing  AMI  state 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  AMI - related  API  functions ,  used  by  internal  asterisk  components 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  handlers  for  AMI - related  CLI  functions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  handlers  for  AMI  functions  ( available  through  the  AMI  socket ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  the  code  for  the  main  AMI  listener  thread  and  individual  session  threads 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  the  http  handlers  invoked  for  AMI - over - HTTP  by  the  threads  in  main / http . c 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 23:11:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ ref  amiconf 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \addtogroup Group_AMI AMI functions
 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								*/ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! @{
 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 Doxygen  group  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-07 18:54:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								ASTERISK_FILE_VERSION ( __FILE__ ,  " $Revision$ " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-11-20 22:18:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/_private.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-20 23:16:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/paths.h"	/* use various ast_config_AST_* */ 
 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <ctype.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								# include  <sys/time.h> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  <signal.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:52:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  <sys/mman.h> 
 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-21 06:02:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/channel.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/file.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/manager.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/module.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-21 06:02:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/config.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/callerid.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/lock.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/cli.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/app.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/pbx.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/md5.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/acl.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "asterisk/utils.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-18 22:04:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/tcptls.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/http.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-26 20:02:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/ast_version.h" 
 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
  ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
  lives in threadstorage.h, with one function being implemented in utils.c.
  This new API includes generic thread storage as well as special functions
  for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
  4096 characters as the workspace for building the manager event, use a thread
  local dynamic string.  Now there is no length limitation on the length of the
  body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
  - Instead of using a static char buffer and a lock to make sure only one
    thread can be using ast_verbose() at a time, use a thread local dynamic
    string as the workspace for preparing the verbose message. Instead of
    locking around the entire function, the only locking done now is when the
    message has been built and is being deliviered to the list of registered
    verbose message handlers.
  - This function was doing a strdup() on every message passed to it and
    keeping a queue of the last 200 messages in memory. This has been
    completely removed. The only place this was used was that if there were
    any messages in the verbose queue when a verbose handler was registered,
    all of the messages in the queue would be fed to it.  So, I just made sure
    that the console verbose handler and the network verbose handler (for
    remote asterisk consoles) were registered before any verbose messages.
    pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
    startup, but I didn't feel the performance hit of this message queue was
    worth saving the initial verbose output for these very rarely used modules.
  - I have removed the last three arguments to the verbose handlers, leaving
    only the string itself because they aren't needed anymore. For example,
    ast_verbose had some logic for telling the verbose handler to add
    a newline if the buffer was completely full. Now that the buffer can grow
    as needed, this doesn't matter anymore.
  - remove unused function, ast_verbose_dmesg() which was to dispatch the
    message queue
  - Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
  for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
  system) allocated on the stack.  The dynamic string in this case is limited
  to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-08-08 06:32:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/threadstorage.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/linkedlists.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/version.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-10 22:25:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/term.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/astobj2.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# include  "asterisk/features.h" 
 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								enum  error_type  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									UNKNOWN_ACTION  =  1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									UNKNOWN_CATEGORY , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									UNSPECIFIED_CATEGORY , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									UNSPECIFIED_ARGUMENT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FAILURE_ALLOCATION , 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									FAILURE_NEWCAT , 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									FAILURE_DELCAT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FAILURE_EMPTYCAT , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FAILURE_UPDATE , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FAILURE_DELETE , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FAILURE_APPEND 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Linked  list  of  events . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Global  events  are  appended  to  the  list  by  append_event ( ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  usecount  is  the  number  of  stored  pointers  to  the  element , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  excluding  the  list  pointers .  So  an  element  that  is  only  in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  the  list  has  a  usecount  of  0 ,  not  1. 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Clients  have  a  pointer  to  the  last  event  processed ,  and  for  each 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  of  these  clients  we  track  the  usecount  of  the  elements . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  If  we  have  a  pointer  to  an  entry  in  the  list ,  it  is  safe  to  navigate 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  it  forward  because  elements  will  not  be  deleted ,  but  only  appended . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  worst  that  can  happen  is  seeing  the  pointer  still  NULL . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  When  the  usecount  of  an  element  drops  to  0 ,  and  the  element  is  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  first  in  the  list ,  we  can  remove  it .  Removal  is  done  within  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  main  thread ,  which  is  woken  up  for  the  purpose . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  For  simplicity  of  implementation ,  we  make  sure  the  list  is  never  empty . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  eventqent  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  usecount ; 		/*!< # of clients who still need the event */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  category ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									unsigned  int  seq ; 	/*!< sequence number */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_ENTRY ( eventqent )  eq_next ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  eventdata [ 1 ] ; 	/*!< really variable size, allocated by append_event() */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  AST_LIST_HEAD_STATIC ( all_events ,  eventqent ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-01-05 06:24:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  displayconnects  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-05 17:47:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  allowmultiplelogin  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-27 22:14:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  timestampevents ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  httptimeout  =  60 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-14 20:22:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  manager_enabled  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  webmanager_enabled  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-01-05 06:24:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-27 22:14:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  block_sockets ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  num_sessions ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  manager_debug ; 	/*!< enable some debugging code in the manager */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-02-24 19:49:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief
 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 09:27:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Descriptor  for  a  manager  session ,  either  on  the  AMI  socket  or  over  HTTP . 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-24 19:49:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  \ note 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 09:27:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  AMI  session  have  managerid  = =  0 ;  the  entry  is  created  upon  a  connect , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  and  destroyed  with  the  socket . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  HTTP  sessions  have  managerid  ! =  0 ,  the  value  is  used  as  a  search  key 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  to  lookup  sessions  ( using  the  mansession_id  cookie ) . 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:53:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-02 14:41:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define MAX_BLACKLIST_CMD_LEN 2 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * words [ AST_MAX_CMD_LEN ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  command_blacklist [ ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ {  " module " ,  " load " ,  NULL  } } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{ {  " module " ,  " unload " ,  NULL  } } , 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-16 20:44:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{ {  " restart " ,  " gracefully " ,  NULL  } } , 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-24 15:30:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* In order to understand what the heck is going on with the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  mansession_session  and  mansession  structs ,  we  need  to  have  a  bit  of  a  history 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  lesson . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  In  the  beginning ,  there  was  the  mansession .  The  mansession  contained  data  that  was 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  intrinsic  to  a  manager  session ,  such  as  the  time  that  it  started ,  the  name  of  the  logged - in 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  user ,  etc .  In  addition  to  these  parameters  were  the  f  and  fd  parameters .  For  typical  manager 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  sessions ,  these  were  used  to  represent  the  TCP  socket  over  which  the  AMI  session  was  taking 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  place .  It  makes  perfect  sense  for  these  fields  to  be  a  part  of  the  session - specific  data  since 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  the  session  actually  defines  this  information . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Then  came  the  HTTP  AMI  sessions .  With  these ,  the  f  and  fd  fields  need  to  be  opened  and  closed 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  for  every  single  action  that  occurs .  Thus  the  f  and  fd  fields  aren ' t  really  specific  to  the  session 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  but  rather  to  the  action  that  is  being  executed .  Because  a  single  session  may  execute  many  commands 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  at  once ,  some  sort  of  safety  needed  to  be  added  in  order  to  be  sure  that  we  did  not  end  up  with  fd 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  leaks  from  one  action  overwriting  the  f  and  fd  fields  used  by  a  previous  action  before  the  previous  action 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  has  had  a  chance  to  properly  close  its  handles . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  initial  idea  to  solve  this  was  to  use  thread  synchronization ,  but  this  prevented  multiple  actions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  from  being  run  at  the  same  time  in  a  single  session .  Some  manager  actions  may  block  for  a  long  time ,  thus 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  creating  a  large  queue  of  actions  to  execute .  In  addition ,  this  fix  did  not  address  the  basic  architectural 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  issue  that  for  HTTP  manager  sessions ,  the  f  and  fd  variables  are  not  really  a  part  of  the  session ,  but  are 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  part  of  the  action  instead . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  new  idea  was  to  create  a  structure  on  the  stack  for  each  HTTP  Manager  action .  This  structure  would 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  contain  the  action - specific  information ,  such  as  which  file  to  write  to .  In  order  to  maintain  expectations 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  of  action  handlers  and  not  have  to  change  the  public  API  of  the  manager  code ,  we  would  need  to  name  this 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  new  stacked  structure  ' mansession '  and  contain  within  it  the  old  mansession  struct  that  we  used  to  use . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  We  renamed  the  old  mansession  struct  ' mansession_session '  to  hopefully  convey  that  what  is  in  this  structure 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  is  session - specific  data .  The  structure  that  it  is  wrapped  in ,  called  a  ' mansession '  really  contains  action - specific 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  data . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  mansession_session  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									pthread_t  ms_t ; 		/*!< Execution thread, basically useless */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_mutex_t  __lock ; 	/*!< Thread lock -- don't use in action callbacks, it's already taken care of  */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:53:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												/* XXX need to document which fields it is protecting */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  sockaddr_in  sin ; 	/*!< address we are connecting from */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 18:45:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									FILE  * f ; 		/*!< fdopen() on the underlying fd */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  fd ; 			/*!< descriptor used for output. Either the socket (AMI) or a temporary file (HTTP) */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  inuse ; 		/*!< number of HTTP sessions using this entry */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  needdestroy ; 	/*!< Whether an HTTP session should be destroyed */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									pthread_t  waiting_thread ; 	/*!< Sleeping thread using this descriptor */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-23 18:01:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									uint32_t  managerid ; 	/*!< Unique manager identifier, 0 for AMI sessions */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-19 13:30:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									time_t  sessionstart ;     /*!< Session start time */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									time_t  sessiontimeout ; 	/*!< Session timeout if HTTP */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  username [ 80 ] ; 	/*!< Logged in username */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  challenge [ 10 ] ; 	/*!< Authentication challenge */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  authenticated ; 	/*!< Authentication status */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  readperm ; 		/*!< Authorization for reading */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  writeperm ; 		/*!< Authorization for writing */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  inbuf [ 1025 ] ; 	/*!< Buffer */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												/* we use the extra byte to add a '\0' and simplify parsing */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  inlen ; 		/*!< number of buffered bytes */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  send_events ; 	/*!<  XXX what ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 11:24:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  eventqent  * last_ev ; 	/*!< last event processed. */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  writetimeout ; 	/*!< Timeout for ast_carefulwrite() */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 17:36:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  pending_event ;          /*!< Pending events indicator in case when waiting_thread is NULL */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_HEAD_NOLOCK ( mansession_datastores ,  ast_datastore )  datastores ;  /*!< Data stores on the session */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_ENTRY ( mansession_session )  list ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* In case you didn't read that giant block of text above the mansession_session struct, the
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ' mansession '  struct  is  named  this  solely  to  keep  the  API  the  same  in  Asterisk .  This  structure  really 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  represents  data  that  is  different  from  Manager  action  to  Manager  action .  The  mansession_session  pointer 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  contained  within  points  to  session - specific  data . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  mansession  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FILE  * f ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  fd ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define NEW_EVENT(m)	(AST_LIST_NEXT(m->session->last_ev, eq_next)) 
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 11:24:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  AST_LIST_HEAD_STATIC ( sessions ,  mansession_session ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief user descriptor, as read from the config file.
 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-24 19:49:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ note  It  is  still  missing  some  fields  - -  e . g .  we  can  have  multiple  permit  and  deny 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:53:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  lines  which  are  not  supported  here ,  and  readperm / writeperm / writetimeout 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  are  not  stored . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  ast_manager_user  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  username [ 80 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * secret ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_ha  * ha ; 		/*!< ACL setting */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  readperm ; 			/*! Authorization for reading */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  writeperm ; 			/*! Authorization for writing */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  writetimeout ; 		/*! Per user Timeout for ast_carefulwrite() */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  displayconnects ; 	/*!< XXX unused */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  keep ; 	/*!< mark entries created on a reload */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_ENTRY ( ast_manager_user )  list ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief list of users found in the config file */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  AST_RWLIST_HEAD_STATIC ( users ,  ast_manager_user ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief list of actions registered */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  AST_RWLIST_HEAD_STATIC ( actions ,  manager_action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief list of hooks registered */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-06 17:05:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  AST_RWLIST_HEAD_STATIC ( manager_hooks ,  manager_custom_hook ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*! \brief Add a custom hook to be called when an event is fired */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  ast_manager_register_hook ( struct  manager_custom_hook  * hook ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_WRLOCK ( & manager_hooks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_INSERT_TAIL ( & manager_hooks ,  hook ,  list ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & manager_hooks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*! \brief Delete a custom hook to be called when an event is fired */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  ast_manager_unregister_hook ( struct  manager_custom_hook  * hook ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_WRLOCK ( & manager_hooks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_REMOVE ( & manager_hooks ,  hook ,  list ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & manager_hooks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Event  list  management  functions . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  We  assume  that  the  event  list  always  has  at  least  one  element , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  and  the  delete  code  will  not  remove  the  last  entry  even  if  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								#if 0 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  time_t  __deb ( time_t  start ,  const  char  * msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									time_t  now  =  time ( NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_verbose ( " %4d th %p %s \n " ,  ( int ) ( now  %  3600 ) ,  pthread_self ( ) ,  msg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( start  ! =  0  & &  now  -  start  >  5 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_verbose ( " +++ WOW, %s took %d seconds \n " ,  msg ,  ( int ) ( now  -  start ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  now ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  LOCK_EVENTS ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									time_t  start  =  __deb ( 0 ,  " about to lock events " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									__deb ( start ,  " done lock events " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  UNLOCK_EVENTS ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									__deb ( 0 ,  " about to unlock events " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  LOCK_SESS ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									time_t  start  =  __deb ( 0 ,  " about to lock sessions " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									__deb ( start ,  " done lock sessions " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  UNLOCK_SESS ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									__deb ( 0 ,  " about to unlock sessions " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# endif 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-02-14 20:22:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  check_manager_enabled ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  manager_enabled ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								int  check_webmanager_enabled ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  ( webmanager_enabled  & &  manager_enabled ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Grab  a  reference  to  the  last  event ,  update  usecount  as  needed . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Can  handle  a  NULL  pointer . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  struct  eventqent  * grab_last ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  eventqent  * ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ret  =  AST_LIST_LAST ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* the list is never empty now, but may become so when
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 *  we  optimize  it  in  the  future ,  so  be  prepared . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ret ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_atomic_fetchadd_int ( & ret - > usecount ,  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Purge  unused  events .  Remove  elements  from  the  head 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  as  long  as  their  usecount  is  0  and  there  is  a  next  element . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  purge_events ( void ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  eventqent  * ev ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									while  (  ( ev  =  AST_LIST_FIRST ( & all_events ) )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									    ev - > usecount  = =  0  & &  AST_LIST_NEXT ( ev ,  eq_next ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_LIST_REMOVE_HEAD ( & all_events ,  eq_next ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free ( ev ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  helper  functions  to  convert  back  and  forth  between 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  string  and  numeric  representation  of  set  of  flags 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  struct  permalias  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  num ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * label ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  perms [ ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_SYSTEM ,  " system "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_CALL ,  " call "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_LOG ,  " log "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_VERBOSE ,  " verbose "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_COMMAND ,  " command "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_AGENT ,  " agent "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_USER ,  " user "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_CONFIG ,  " config "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-10 23:55:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_DTMF ,  " dtmf "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-21 23:07:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_REPORTING ,  " reporting "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-05 16:46:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_CDR ,  " cdr "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 00:12:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_DIALPLAN ,  " dialplan "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-22 22:55:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_ORIGINATE ,  " originate "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-24 22:05:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  EVENT_FLAG_AGI ,  " agi "  } , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									{  - 1 ,  " all "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									{  0 ,  " none "  } , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 18:08:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Convert authority code to a list of options */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * authority_to_str ( int  authority ,  struct  ast_str  * * res ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-30 20:27:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 21:09:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  i ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * sep  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									( * res ) - > used  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-08 16:40:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( i  =  0 ;  i  <  ARRAY_LEN ( perms )  -  1 ;  i + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-30 20:27:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( authority  &  perms [ i ] . num )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_str_append ( res ,  0 ,  " %s%s " ,  sep ,  perms [ i ] . label ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 18:08:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											sep  =  " , " ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-30 20:27:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ( * res ) - > used  = =  0 ) 	/* replace empty string with something sensible */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_str_append ( res ,  0 ,  " <none> " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  ( * res ) - > str ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-30 20:27:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! Tells you if smallstr exists inside bigstr
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   which  is  delim  by  delim  and  uses  no  buf  or  stringsep 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   ast_instring ( " this|that|more " , " this " , ' | ' )  = =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   feel  free  to  move  this  to  app . c  - anthm  */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  ast_instring ( const  char  * bigstr ,  const  char  * smallstr ,  const  char  delim ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * val  =  bigstr ,  * next ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									do  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ( next  =  strchr ( val ,  delim ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! strncmp ( val ,  smallstr ,  ( next  -  val ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  ! strcmp ( smallstr ,  val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  while  ( * ( val  =  ( next  +  1 ) ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  get_perm ( const  char  * instr ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  x  =  0 ,  ret  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 17:19:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! instr ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-07-08 16:40:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  ARRAY_LEN ( perms ) ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ast_instring ( instr ,  perms [ x ] . label ,  ' , ' ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ret  | =  perms [ x ] . num ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-03 18:38:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  A  number  returns  itself ,  false  returns  0 ,  true  returns  all  flags , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  other  strings  return  the  flags  that  are  set . 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 06:28:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  strings_to_mask ( const  char  * string ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * p ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 05:31:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( string ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Improve the XML formatting of responses coming from web interface.
Normal responses are sequences of lines of the form "Name: value",
with \r\n as line terminators and an empty line as a response
terminator.
Generi CLI commands, however, do not have such a clean formatting,
and the existing code failed to generate valid XML for them.
Obviously we can only use heuristics here, and we do the following:
- accept either \r or \n as a line terminator, trimming trailing whitespace;
- if a line does not have a ":" in it, assume that from this point on
  we have unformatted data, and use "Opaque-data:" as a name;
- if a line does have a ":" in it, the Name field is not always
  a legal identifier, so replace non-alphanum characters with underscores;
All the above is to be refined as we improve the formatting of
responses from the CLI.
And, all the above ought to go as a comment in the code rather than
just in a commit message...
  
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@45334 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-10-17 17:51:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( p  =  string ;  * p ;  p + + ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( * p  <  ' 0 '  | |  * p  >  ' 9 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! p ) 	/* all digits */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  atoi ( string ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_false ( string ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_true ( string ) )  { 	/* all permissions */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										int  x ,  ret  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-08 16:40:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										for  ( x  =  0 ;  x  <  ARRAY_LEN ( perms ) ;  x + + ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ret  | =  perms [ x ] . num ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  get_perm ( string ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  check_manager_session_inuse ( const  char  * name ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( session - > username ,  name ) )  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  session  ?  1  :  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 08:00:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 07:43:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  lookup  an  entry  in  the  list  of  registered  users . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  must  be  called  with  the  list  lock  held . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  struct  ast_manager_user  * get_manager_by_name_locked ( const  char  * name ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_manager_user  * user  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & users ,  user ,  list ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( user - > username ,  name ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  user ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-06-11 22:07:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Get displayconnects config option.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *   \ param  s  manager  session  to  get  parameter  from . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *   \ return  displayconnects  config  option  value . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  manager_displayconnects  ( struct  mansession_session  * session ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-11 22:07:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_manager_user  * user  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  ret  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ( user  =  get_manager_by_name_locked  ( session - > username ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-11 22:07:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ret  =  user - > displayconnects ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-11 22:07:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_showmancmd ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * authority ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  num ,  l ,  which ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * ret  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager show command " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Usage: manager show command <actionname> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" 	Shows the detailed description for a specific Asterisk manager interface command. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										l  =  strlen ( a - > word ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										which  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_RDLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_TRAVERSE ( & actions ,  cur ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! strncasecmp ( a - > word ,  cur - > action ,  l )  & &  + + which  >  a - > n )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ret  =  ast_strdup ( cur - > action ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 	/* make sure we exit even if ast_strdup() returns NULL */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									authority  =  ast_str_alloca ( 80 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( a - > argc  ! =  4 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & actions ,  cur ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										for  ( num  =  3 ;  num  <  a - > argc ;  num + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! strcasecmp ( cur - > action ,  a - > argv [ num ] ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_cli ( a - > fd ,  " Action: %s \n Synopsis: %s \n Privilege: %s \n %s \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 11:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													cur - > action ,  cur - > synopsis , 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													authority_to_str ( cur - > authority ,  & authority ) , 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													S_OR ( cur - > description ,  " " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_mandebug ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager debug [on|off] " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  " Usage: manager debug [on|off] \n 	Show, enable, disable debugging of the manager code. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( a - > argc  = =  2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " manager debug is %s \n " ,  manager_debug ?  " on "  :  " off " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else  if  ( a - > argc  = =  3 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( a - > argv [ 2 ] ,  " on " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											manager_debug  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else  if  ( ! strcasecmp ( a - > argv [ 2 ] ,  " off " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											manager_debug  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_showmanager ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_manager_user  * user  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  l ,  which ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * ret  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-08 18:52:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * rauthority  =  ast_str_alloca ( 128 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_str  * wauthority  =  ast_str_alloca ( 128 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager show user " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											"  Usage: manager show user <user> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											"         Display all information related to the manager user specified. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										l  =  strlen ( a - > word ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										which  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( a - > pos  ! =  3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_RDLOCK ( & users ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_TRAVERSE ( & users ,  user ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  (  ! strncasecmp ( a - > word ,  user - > username ,  l )  & &  + + which  >  a - > n  )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ret  =  ast_strdup ( user - > username ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( a - > argc  ! =  4 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( user  =  get_manager_by_name_locked ( a - > argv [ 3 ] ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " There is no manager called %s \n " ,  a - > argv [ 3 ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  " \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd , 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										"        username: %s \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										"          secret: %s \n " 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										"             acl: %s \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										"       read perm: %s \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										"      write perm: %s \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" displayconnects: %s \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										( user - > username  ?  user - > username  :  " (N/A) " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-11 20:16:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										( user - > secret  ?  " <Set> "  :  " (N/A) " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										( user - > ha  ?  " yes "  :  " no " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										authority_to_str ( user - > readperm ,  & rauthority ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										authority_to_str ( user - > writeperm ,  & wauthority ) , 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										( user - > displayconnects  ?  " yes "  :  " no " ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_showmanagers ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_manager_user  * user  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  count_amu  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager show users " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Usage: manager show users \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											"        Prints a listing of all managers that are currently configured on that \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											"  system. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( a - > argc  ! =  3 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* If there are no users, print out something along those lines */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( AST_RWLIST_EMPTY ( & users ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " There are no manager users. \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  " \n username \n -------- \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & users ,  user ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " %s \n " ,  user - > username ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										count_amu + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  " ------------------- \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  " %d manager users configured. \n " ,  count_amu ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 18:08:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief  CLI command  manager list commands */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_showmancmds ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * authority ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:43:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define HSMC_FORMAT "  %-15.15s  %-15.15s  %-55.55s\n" 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager show commands " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Usage: manager show commands \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" 	Prints a listing of all the available Asterisk manager interface commands. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									authority  =  ast_str_alloca ( 80 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:43:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  HSMC_FORMAT ,  " Action " ,  " Privilege " ,  " Synopsis " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  HSMC_FORMAT ,  " ------ " ,  " --------- " ,  " -------- " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & actions ,  cur ,  list ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:43:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  HSMC_FORMAT ,  cur - > action ,  authority_to_str ( cur - > authority ,  & authority ) ,  cur - > synopsis ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 18:08:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief CLI command manager list connected */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_showmanconn ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-02-21 06:00:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-19 13:30:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									time_t  now  =  time ( NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:43:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define HSMCONN_FORMAT1 "  %-15.15s  %-15.15s  %-10.10s  %-10.10s  %-8.8s  %-8.8s  %-5.5s  %-5.5s\n" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define HSMCONN_FORMAT2 "  %-15.15s  %-15.15s  %-10d  %-10d  %-8d  %-8d  %-5.5d  %-5.5d\n" 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-11 13:15:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  count  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager show connected " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Usage: manager show connected \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" 	Prints a listing of the users that are currently connected to the \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Asterisk manager interface. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-19 13:30:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:43:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  HSMCONN_FORMAT1 ,  " Username " ,  " IP Address " ,  " Start " ,  " Elapsed " ,  " FileDes " ,  " HttpCnt " ,  " Read " ,  " Write " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  HSMCONN_FORMAT2 ,  session - > username ,  ast_inet_ntoa ( session - > sin . sin_addr ) ,  ( int ) ( session - > sessionstart ) ,  ( int ) ( now  -  session - > sessionstart ) ,  session - > fd ,  session - > inuse ,  session - > readperm ,  session - > writeperm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-11 13:15:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										count + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-02-21 06:00:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli ( a - > fd ,  " %d users connected. \n " ,  count ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-11 13:15:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-02-21 06:00:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 11:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief CLI command manager list eventq */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* Should change to "manager show connected" */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  * handle_showmaneventq ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  eventqent  * s ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager show eventq " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Usage: manager show eventq \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" 	Prints a listing of all events pending in the Asterisk manger \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" event queue. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & all_events ,  s ,  eq_next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " Usecount: %d \n " ,  s - > usecount ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " Category: %d \n " ,  s - > category ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_cli ( a - > fd ,  " Event: \n %s " ,  s - > eventdata ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & all_events ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 22:43:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:35:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief CLI command manager reload */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  char  * handle_manager_reload ( struct  ast_cli_entry  * e ,  int  cmd ,  struct  ast_cli_args  * a ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									switch  ( cmd )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_INIT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > command  =  " manager reload " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										e - > usage  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Usage: manager reload \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											"        Reloads the manager configuration. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									case  CLI_GENERATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( a - > argc  >  2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  CLI_SHOWUSAGE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									reload_manager ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  CLI_SUCCESS ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 19:58:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_cli_entry  cli_manager [ ]  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-22 20:05:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_showmancmd ,  " Show a manager interface command " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_showmancmds ,  " List manager interface commands " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_showmanconn ,  " List connected manager interface users " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_showmaneventq ,  " List manager interface queued events " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_showmanagers ,  " List configured manager users " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_showmanager ,  " Display information on a specific manager user " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_mandebug ,  " Show, enable, disable debugging of the manager code " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:35:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_CLI_DEFINE ( handle_manager_reload ,  " Reload manager configurations " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 19:58:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 07:43:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Decrement  the  usecount  for  the  event ;  if  it  goes  to  zero , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( why  check  for  e - > next  ? )  wakeup  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  main  thread ,  which  is  in  charge  of  freeing  the  record . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Returns  the  next  record . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  struct  eventqent  * unref_event ( struct  eventqent  * e ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-04 21:40:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_atomic_fetchadd_int ( & e - > usecount ,  - 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  AST_LIST_NEXT ( e ,  eq_next ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  ref_event ( struct  eventqent  * e ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_atomic_fetchadd_int ( & e - > usecount ,  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  destroy  a  session ,  leaving  the  usecount 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  free_session ( struct  mansession_session  * session ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-28 23:10:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  eventqent  * eqe  =  session - > last_ev ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_datastore  * datastore ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* Get rid of each of the data stores on the session */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									while  ( ( datastore  =  AST_LIST_REMOVE_HEAD ( & session - > datastores ,  entry ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* Free the data store */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_datastore_free ( datastore ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( session - > f  ! =  NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										fclose ( session - > f ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_mutex_destroy ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_free ( session ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									unref_event ( eqe ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-28 23:10:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  destroy_session ( struct  mansession_session  * session ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_REMOVE ( & sessions ,  session ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 20:59:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_atomic_fetchadd_int ( & num_sessions ,  - 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									free_session ( session ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-19 15:11:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Generic  function  to  return  either  the  first  or  the  last  matching  header 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  from  a  list  of  variables ,  possibly  skipping  empty  strings . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  At  the  moment  there  is  only  one  use  of  this  function  in  this  file , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  so  we  make  it  static . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define	GET_HEADER_FIRST_MATCH	0 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define	GET_HEADER_LAST_MATCH	1 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define	GET_HEADER_SKIP_EMPTY	2 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  const  char  * __astman_get_header ( const  struct  message  * m ,  char  * var ,  int  mode ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 11:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  x ,  l  =  strlen ( var ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * result  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  m - > hdrcount ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										const  char  * h  =  m - > headers [ x ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! strncasecmp ( var ,  h ,  l )  & &  h [ l ]  = =  ' : '  & &  h [ l + 1 ]  = =  '   ' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											const  char  * value  =  h  +  l  +  2 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											/* found a potential candidate */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( mode  &  GET_HEADER_SKIP_EMPTY  & &  ast_strlen_zero ( value ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												continue ; 	/* not interesting */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( mode  &  GET_HEADER_LAST_MATCH ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												result  =  value ; 	/* record the last match so far */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											else 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												return  value ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Return  the  first  matching  variable  from  an  array . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  This  is  the  legacy  function  and  is  implemented  in  therms  of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  __astman_get_header ( ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								const  char  * astman_get_header ( const  struct  message  * m ,  char  * var ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  __astman_get_header ( m ,  var ,  GET_HEADER_FIRST_MATCH ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  ast_variable  * astman_get_variables ( const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:24:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 02:11:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  varlen ,  x ,  y ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:24:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_variable  * head  =  NULL ,  * cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-23 18:07:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_DECLARE_APP_ARGS ( args , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_APP_ARG ( vars ) [ 32 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									varlen  =  strlen ( " Variable:  " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:24:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  m - > hdrcount ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 11:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										char  * parse ,  * var ,  * val ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 02:11:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( strncasecmp ( " Variable:  " ,  m - > headers [ x ] ,  varlen ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-10 13:22:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										parse  =  ast_strdupa ( m - > headers [ x ]  +  varlen ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 02:11:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-01-23 18:07:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_STANDARD_APP_ARGS ( args ,  parse ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 11:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! args . argc ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										for  ( y  =  0 ;  y  <  args . argc ;  y + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! args . vars [ y ] ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  =  val  =  ast_strdupa ( args . vars [ y ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											strsep ( & val ,  " = " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! val  | |  ast_strlen_zero ( var ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-29 20:55:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											cur  =  ast_variable_new ( var ,  val ,  " " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 11:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											cur - > next  =  head ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											head  =  cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:24:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  head ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 10:23:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  helper  function  to  send  a  string  to  the  socket . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Return  - 1  on  error  ( e . g .  buffer  full ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  send_string ( struct  mansession  * s ,  char  * string ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( s - > f )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ast_careful_fwrite ( s - > f ,  s - > fd ,  string ,  strlen ( string ) ,  s - > session - > writetimeout ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ast_careful_fwrite ( s - > session - > f ,  s - > session - > fd ,  string ,  strlen ( string ) ,  s - > session - > writetimeout ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 10:23:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-30 19:31:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  \ brief  thread  local  buffer  for  astman_append 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  \ note  This  can  not  be  defined  within  the  astman_append ( )  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *        because  it  declares  a  couple  of  functions  that  get  used  to 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *        initialize  the  thread  local  storage  key . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								AST_THREADSTORAGE ( astman_append_buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-19 20:10:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								AST_THREADSTORAGE ( userevent_buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-30 19:31:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief initial allocated size for the astman_append_buf */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define ASTMAN_APPEND_BUF_INITSIZE   256 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  utility  functions  for  creating  AMI  replies 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  astman_append ( struct  mansession  * s ,  const  char  * fmt ,  . . . ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									va_list  ap ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * buf ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( buf  =  ast_str_thread_get ( & astman_append_buf ,  ASTMAN_APPEND_BUF_INITSIZE ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									va_start ( ap ,  fmt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_str_set_va ( & buf ,  0 ,  fmt ,  ap ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									va_end ( ap ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( s - > f  ! =  NULL  | |  s - > session - > f  ! =  NULL )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 10:23:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										send_string ( s ,  buf - > str ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 10:23:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_verbose ( " fd == -1 in astman_append, should not happen \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 11:43:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \note NOTE: XXX this comment is unclear and possibly wrong.
 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-30 23:52:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								   Callers  of  astman_send_error ( ) ,  astman_send_response ( )  or  astman_send_ack ( )  must  EITHER 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								   hold  the  session  lock  _or_  be  running  in  an  action  callback  ( in  which  case  s - > session - > busy  will 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-30 23:52:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								   be  non - zero ) .  In  either  of  these  cases ,  there  is  no  need  to  lock - protect  the  session ' s 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   fd ,  since  no  other  output  will  be  sent  ( events  will  be  queued ) ,  and  no  input  will 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   be  read  until  either  the  current  action  finishes  or  get_input ( )  obtains  the  session 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   lock . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief send a response with an optional message,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  and  terminate  it  with  an  empty  line . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  m  is  used  only  to  grab  the  ' ActionID '  field . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Use  the  explicit  constant  MSG_MOREDATA  to  remove  the  empty  line . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  XXX  MSG_MOREDATA  should  go  to  a  header  file . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define MSG_MOREDATA	((char *)astman_send_response) 
 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  astman_send_response_full ( struct  mansession  * s ,  const  struct  message  * m ,  char  * resp ,  char  * msg ,  char  * listflag ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * id  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Response: %s \r \n " ,  resp ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " ActionID: %s \r \n " ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 21:18:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( listflag ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Eventlist: %s \r \n " ,  listflag ) ; 	/* Start, complete, cancelled */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( msg  = =  MSG_MOREDATA ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else  if  ( msg ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Message: %s \r \n \r \n " ,  msg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  astman_send_response ( struct  mansession  * s ,  const  struct  message  * m ,  char  * resp ,  char  * msg ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 21:18:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_send_response_full ( s ,  m ,  resp ,  msg ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  astman_send_error ( struct  mansession  * s ,  const  struct  message  * m ,  char  * error ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 21:18:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_response_full ( s ,  m ,  " Error " ,  error ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  astman_send_ack ( struct  mansession  * s ,  const  struct  message  * m ,  char  * msg ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 21:18:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_response_full ( s ,  m ,  " Success " ,  msg ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  astman_start_ack ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 17:08:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 21:18:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_response_full ( s ,  m ,  " Success " ,  MSG_MOREDATA ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								void  astman_send_listack ( struct  mansession  * s ,  const  struct  message  * m ,  char  * msg ,  char  * listflag ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-30 21:18:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_send_response_full ( s ,  m ,  " Success " ,  msg ,  listflag ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-22 15:34:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								   Rather  than  braindead  on , off  this  now  can  also  accept  a  specific  int  mask  value 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								   or  a  ' , '  delim  list  of  mask  strings  ( the  same  as  manager . conf )  - anthm 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*/ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  set_eventmask ( struct  mansession  * s ,  const  char  * eventmask ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-02 08:45:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  maskint  =  strings_to_mask ( eventmask ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( maskint  > =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										s - > session - > send_events  =  maskint ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-07-25 23:01:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  maskint ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-02 08:45:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Here  we  start  with  action_  handlers  for  AMI  actions , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  and  the  internal  functions  used  by  them . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Generally ,  the  handlers  are  called  action_foo ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* helper function for action_login() */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  authenticate ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * username  =  astman_get_header ( m ,  " Username " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * password  =  astman_get_header ( m ,  " Secret " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  error  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_manager_user  * user  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 08:48:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( username ) ) 	/* missing username */ 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-18 18:54:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* locate user in locked state */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_WRLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( user  =  get_manager_by_name_locked ( username ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_log ( LOG_NOTICE ,  " %s tried to authenticate with nonexistent user '%s' \n " ,  ast_inet_ntoa ( s - > session - > sin . sin_addr ) ,  username ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  if  ( user - > ha  & &  ! ast_apply_ha ( user - > ha ,  & ( s - > session - > sin ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_log ( LOG_NOTICE ,  " %s failed to pass IP ACL as '%s' \n " ,  ast_inet_ntoa ( s - > session - > sin . sin_addr ) ,  username ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  if  ( ! strcasecmp ( astman_get_header ( m ,  " AuthType " ) ,  " MD5 " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										const  char  * key  =  astman_get_header ( m ,  " Key " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ast_strlen_zero ( key )  & &  ! ast_strlen_zero ( s - > session - > challenge )  & &  user - > secret )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											int  x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											int  len  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											char  md5key [ 256 ]  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											struct  MD5Context  md5 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											unsigned  char  digest [ 16 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											MD5Init ( & md5 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											MD5Update ( & md5 ,  ( unsigned  char  * )  s - > session - > challenge ,  strlen ( s - > session - > challenge ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-12 18:12:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											MD5Update ( & md5 ,  ( unsigned  char  * )  user - > secret ,  strlen ( user - > secret ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											MD5Final ( digest ,  & md5 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-11 18:27:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											for  ( x  =  0 ;  x  <  16 ;  x + + ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												len  + =  sprintf ( md5key  +  len ,  " %2.2x " ,  digest [ x ] ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! strcmp ( md5key ,  key ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												error  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-11 16:21:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_debug ( 1 ,  " MD5 authentication is not possible.  challenge: '%s' \n " ,  
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												S_OR ( s - > session - > challenge ,  " " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  if  ( password  & &  user - > secret  & &  ! strcmp ( password ,  user - > secret ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										error  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( error )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_log ( LOG_NOTICE ,  " %s failed to authenticate as '%s' \n " ,  ast_inet_ntoa ( s - > session - > sin . sin_addr ) ,  username ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* auth complete */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_copy_string ( s - > session - > username ,  username ,  sizeof ( s - > session - > username ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									s - > session - > readperm  =  user - > readperm ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									s - > session - > writeperm  =  user - > writeperm ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									s - > session - > writetimeout  =  user - > writetimeout ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									s - > session - > sessionstart  =  time ( NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									set_eventmask ( s ,  astman_get_header ( m ,  " Events " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:38:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-22 15:34:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Manager PING */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_ping [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: A 'Ping' action will ellicit a 'Pong' response.  Used to keep the \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"   manager connection open. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: NONE \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_ping ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-22 15:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Response: Success \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-14 17:04:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" Ping: Pong \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_getconfig [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: A 'GetConfig' action will dump the contents of a configuration \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" file by category and contents or optionally by specified category only. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    *Filename: Configuration filename (e.g. foo.conf) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    Category: Category in configuration file \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_getconfig ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_config  * cfg ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * fn  =  astman_get_header ( m ,  " Filename " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * category  =  astman_get_header ( m ,  " Category " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  catcount  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  lineno  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * cur_category  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_variable  * v ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_flags  config_flags  =  {  CONFIG_FLAG_WITHCOMMENTS  |  CONFIG_FLAG_NOCACHE  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( fn ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Filename not specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 18:39:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( cfg  =  ast_config_load2 ( fn ,  " manager " ,  config_flags ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Config file not found " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									while  ( ( cur_category  =  ast_category_browse ( cfg ,  cur_category ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( category )  | |  ( ! ast_strlen_zero ( category )  & &  ! strcmp ( category ,  cur_category ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											lineno  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_append ( s ,  " Category-%06d: %s \r \n " ,  catcount ,  cur_category ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											for  ( v  =  ast_variable_browse ( cfg ,  cur_category ) ;  v ;  v  =  v - > next ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												astman_append ( s ,  " Line-%06d-%06d: %s=%s \r \n " ,  catcount ,  lineno + + ,  v - > name ,  v - > value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											catcount + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( category )  & &  catcount  = =  0 )  /* TODO: actually, a config with no categories doesn't even get loaded */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-03 20:36:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " No categories found \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_config_destroy ( cfg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " \r \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  char  mandescr_listcategories [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: A 'ListCategories' action will dump the categories in \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" a given file. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    Filename: Configuration filename (e.g. foo.conf) \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_listcategories ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_config  * cfg ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * fn  =  astman_get_header ( m ,  " Filename " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * category  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_flags  config_flags  =  {  CONFIG_FLAG_WITHCOMMENTS  |  CONFIG_FLAG_NOCACHE  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  catcount  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( fn ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Filename not specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 18:39:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( cfg  =  ast_config_load2 ( fn ,  " manager " ,  config_flags ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Config file not found or file has invalid syntax " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									while  ( ( category  =  ast_category_browse ( cfg ,  category ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Category-%06d: %s \r \n " ,  catcount ,  category ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										catcount + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( catcount  = =  0 )  /* TODO: actually, a config with no categories doesn't even get loaded */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-03 20:36:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Error: no categories found \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_config_destroy ( cfg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-04-23 18:49:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! The amount of space in out must be at least ( 2 * strlen(in) + 1 ) */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  json_escape ( char  * out ,  const  char  * in ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( ;  * in ;  in + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( * in  = =  ' \\ '  | |  * in  = =  ' \" ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											* out + +  =  ' \\ ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										* out + +  =  * in ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									* out  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-02-23 00:45:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_getconfigjson [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: A 'GetConfigJSON' action will dump the contents of a configuration \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" file by category and contents in JSON format.  This only makes sense to be used \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" using rawman over the HTTP interface. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    Filename: Configuration filename (e.g. foo.conf) \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_getconfigjson ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_config  * cfg ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * fn  =  astman_get_header ( m ,  " Filename " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * category  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_variable  * v ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  comma1  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-23 18:49:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * buf  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									unsigned  int  buf_len  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_flags  config_flags  =  {  CONFIG_FLAG_WITHCOMMENTS  |  CONFIG_FLAG_NOCACHE  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-23 00:45:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( fn ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Filename not specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 18:39:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( cfg  =  ast_config_load2 ( fn ,  " manager " ,  config_flags ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-23 00:45:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Config file not found " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-04-23 18:49:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									buf_len  =  512 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									buf  =  alloca ( buf_len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-02-23 00:45:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " JSON: { " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									while  ( ( category  =  ast_category_browse ( cfg ,  category ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										int  comma2  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-23 18:49:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( buf_len  <  2  *  strlen ( category )  +  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											buf_len  * =  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											buf  =  alloca ( buf_len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										json_escape ( buf ,  category ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " %s \" %s \" :[ " ,  comma1  ?  " , "  :  " " ,  buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-23 00:45:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! comma1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											comma1  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										for  ( v  =  ast_variable_browse ( cfg ,  category ) ;  v ;  v  =  v - > next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-23 18:49:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( comma2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												astman_append ( s ,  " , " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( buf_len  <  2  *  strlen ( v - > name )  +  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												buf_len  * =  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												buf  =  alloca ( buf_len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											json_escape ( buf ,  v - > name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_append ( s ,  " \" %s " ,  buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( buf_len  <  2  *  strlen ( v - > value )  +  1 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												buf_len  * =  2 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												buf  =  alloca ( buf_len ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											json_escape ( buf ,  v - > value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_append ( s ,  " %s \" " ,  buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-23 00:45:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! comma2 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												comma2  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " ] " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " } \r \n \r \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_config_destroy ( cfg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* helper function for action_updateconfig */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  enum  error_type  handle_updates ( struct  mansession  * s ,  const  struct  message  * m ,  struct  ast_config  * cfg ,  const  char  * dfn ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  hdr [ 40 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-25 19:12:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * action ,  * cat ,  * var ,  * value ,  * match ,  * line ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_category  * category ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_variable  * v ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * str1  =  ast_str_create ( 16 ) ,  * str2  =  ast_str_create ( 16 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									enum  error_type  result  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  100000 ;  x + + )  { 	/* 100000 = the max number of allowed updates + 1 */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-20 18:23:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										unsigned  int  object  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( hdr ,  sizeof ( hdr ) ,  " Action-%06d " ,  x ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										action  =  astman_get_header ( m ,  hdr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( action ) ) 		/* breaks the for loop if no action header */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 				/* this could cause problems if actions come in misnumbered */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( hdr ,  sizeof ( hdr ) ,  " Cat-%06d " ,  x ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										cat  =  astman_get_header ( m ,  hdr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( cat ) )  { 		/* every action needs a category */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											result  =   UNSPECIFIED_CATEGORY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( hdr ,  sizeof ( hdr ) ,  " Var-%06d " ,  x ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-25 19:12:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										var  =  astman_get_header ( m ,  hdr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( hdr ,  sizeof ( hdr ) ,  " Value-%06d " ,  x ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-25 19:12:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										value  =  astman_get_header ( m ,  hdr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-04-20 18:23:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ast_strlen_zero ( value )  & &  * value  = =  ' > ' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											object  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											value + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
									
										
										
										
											2006-07-29 22:02:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( hdr ,  sizeof ( hdr ) ,  " Match-%06d " ,  x ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										match  =  astman_get_header ( m ,  hdr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( hdr ,  sizeof ( hdr ) ,  " Line-%06d " ,  x ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										line  =  astman_get_header ( m ,  hdr ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( action ,  " newcat " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_category_get ( cfg , cat ) )  { 	/* check to make sure the cat doesn't */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_NEWCAT ; 	/* already exist */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( category  =  ast_category_new ( cat ,  dfn ,  - 1 ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_ALLOCATION ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( match ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_category_append ( cfg ,  category ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_category_insert ( cfg ,  category ,  match ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " renamecat " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( value ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												result  =  UNSPECIFIED_ARGUMENT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( category  =  ast_category_get ( cfg ,  cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  UNKNOWN_CATEGORY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_category_rename ( category ,  value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " delcat " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_category_delete ( cfg ,  cat ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_DELCAT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " emptycat " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_category_empty ( cfg ,  cat ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_EMPTYCAT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " update " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( var ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												result  =  UNSPECIFIED_ARGUMENT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( category  =  ast_category_get ( cfg , cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  UNKNOWN_CATEGORY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ast_variable_update ( category ,  var ,  value ,  match ,  object ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_UPDATE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " delete " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ( ast_strlen_zero ( var )  & &  ast_strlen_zero ( line ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												result  =  UNSPECIFIED_ARGUMENT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( category  =  ast_category_get ( cfg ,  cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  UNKNOWN_CATEGORY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ast_variable_delete ( category ,  var ,  match ,  line ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_DELETE ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " append " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( var ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												result  =  UNSPECIFIED_ARGUMENT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( category  =  ast_category_get ( cfg ,  cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  UNKNOWN_CATEGORY ; 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( v  =  ast_variable_new ( var ,  value ,  dfn ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_ALLOCATION ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( object  | |  ( match  & &  ! strcasecmp ( match ,  " object " ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												v - > object  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_variable_append ( category ,  v ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( action ,  " insert " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( var )  | |  ast_strlen_zero ( line ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												result  =  UNSPECIFIED_ARGUMENT ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( category  =  ast_category_get ( cfg ,  cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  UNKNOWN_CATEGORY ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! ( v  =  ast_variable_new ( var ,  value ,  dfn ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												result  =  FAILURE_ALLOCATION ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_variable_insert ( category ,  v ,  line ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_log ( LOG_WARNING ,  " Action-%06d: %s not handled \n " ,  x ,  action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											result  =  UNKNOWN_ACTION ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 20:57:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_free ( str1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_free ( str2 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  char  mandescr_updateconfig [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-05 01:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: A 'UpdateConfig' action will modify, create, or delete \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" configuration elements in Asterisk configuration files. \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Variables (X's represent 6 digit number beginning with 000000): \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    SrcFilename:   Configuration filename to read(e.g. foo.conf) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    DstFilename:   Configuration filename to write(e.g. foo.conf) \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-16 23:53:58 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"    Reload:        Whether or not a reload should take place (or name of specific module) \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"    Action-XXXXXX: Action to Take (NewCat,RenameCat,DelCat,EmptyCat,Update,Delete,Append,Insert) \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"    Cat-XXXXXX:    Category to operate on \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    Var-XXXXXX:    Variable to work on \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-29 22:02:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"    Value-XXXXXX:  Value to work on \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"    Match-XXXXXX:  Extra match required to match line \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    Line-XXXXXX:   Line in category to operate on (used with delete and insert actions) \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_updateconfig ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_config  * cfg ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * sfn  =  astman_get_header ( m ,  " SrcFilename " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * dfn  =  astman_get_header ( m ,  " DstFilename " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * rld  =  astman_get_header ( m ,  " Reload " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_flags  config_flags  =  {  CONFIG_FLAG_WITHCOMMENTS  |  CONFIG_FLAG_NOCACHE  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									enum  error_type  result ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( sfn )  | |  ast_strlen_zero ( dfn ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Filename not specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 18:39:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( cfg  =  ast_config_load2 ( sfn ,  " manager " ,  config_flags ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:04:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Config file not found " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									result  =  handle_updates ( s ,  m ,  cfg ,  dfn ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! result )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_include_rename ( cfg ,  sfn ,  dfn ) ;  /* change the include references from dfn to sfn, so things match up */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										res  =  config_text_file_save ( dfn ,  cfg ,  " Manager " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_config_destroy ( cfg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Save of config failed " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_ack ( s ,  m ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! ast_strlen_zero ( rld ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ast_true ( rld ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												rld  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_module_reload ( rld ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_config_destroy ( cfg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										switch ( result )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  UNKNOWN_ACTION : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Unknown action command " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  UNKNOWN_CATEGORY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Given category does not exist " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  UNSPECIFIED_CATEGORY : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Category not specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  UNSPECIFIED_ARGUMENT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Problem with category, value, or line (if required) " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  FAILURE_ALLOCATION : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Memory allocation failure, this should not happen " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 19:29:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										case  FAILURE_NEWCAT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Create category did not complete successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										case  FAILURE_DELCAT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Delete category did not complete successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  FAILURE_EMPTYCAT : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Empty category did not complete successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  FAILURE_UPDATE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Update did not complete successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  FAILURE_DELETE : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Delete did not complete successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  FAILURE_APPEND : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Append did not complete successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-16 23:53:58 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_createconfig [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: A 'CreateConfig' action will create an empty file in the \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" configuration directory. This action is intended to be used before an \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" UpdateConfig action. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"    Filename:   The configuration filename to create (e.g. foo.conf) \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_createconfig ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  fd ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * fn  =  astman_get_header ( m ,  " Filename " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_str  * filepath  =  ast_str_alloca ( PATH_MAX ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_str_set ( & filepath ,  0 ,  " %s/ " ,  ast_config_AST_CONFIG_DIR ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_str_append ( & filepath ,  0 ,  " %s " ,  fn ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 20:27:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ( fd  =  open ( filepath - > str ,  O_CREAT  |  O_EXCL ,  AST_FILE_MODE ) )  ! =  - 1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										close ( fd ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_ack ( s ,  m ,  " New configuration file created successfully " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  strerror ( errno ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-22 15:34:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Manager WAITEVENT */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_waitevent [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: A 'WaitEvent' action will ellicit a 'Success' response.  Whenever \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" a manager event is queued.  Once WaitEvent has been called on an HTTP manager \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" session, events will be generated and queued. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables:  \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								"    Timeout: Maximum time (in seconds) to wait for events, -1 means forever. \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_waitevent ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * timeouts  =  astman_get_header ( m ,  " Timeout " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  timeout  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  needexit  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * id  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  idText [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( idText ,  sizeof ( idText ) ,  " ActionID: %s \r \n " ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										idText [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( timeouts ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										sscanf ( timeouts ,  " %i " ,  & timeout ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( timeout  <  - 1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											timeout  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										/* XXX maybe put an upper bound, or prevent the use of 0 ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( s - > session - > waiting_thread  ! =  AST_PTHREADT_NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										pthread_kill ( s - > session - > waiting_thread ,  SIGURG ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( s - > session - > managerid )  {  /* AMI-over-HTTP session */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  Make  sure  the  timeout  is  within  the  expire  time  of  the  session , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  as  the  client  will  likely  abort  the  request  if  it  does  not  see 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  data  coming  after  some  amount  of  time . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										time_t  now  =  time ( NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										int  max  =  s - > session - > sessiontimeout  -  now  -  10 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( max  <  0 ) 	/* We are already late. Strange but possible. */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											max  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( timeout  <  0  | |  timeout  >  max ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											timeout  =  max ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! s - > session - > send_events ) 	/* make sure we record events */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											s - > session - > send_events  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* XXX should this go inside the lock ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s - > session - > waiting_thread  =  pthread_self ( ) ; 	/* let new events wake up this thread */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_debug ( 1 ,  " Starting waiting for an event! \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-02-11 18:27:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  timeout  | |  timeout  <  0 ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( NEW_EVENT ( s ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											needexit  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* We can have multiple HTTP session point to the same mansession entry.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  The  way  we  deal  with  it  is  not  very  nice :  newcomers  kick  out  the  previous 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  HTTP  session .  XXX  this  needs  to  be  improved . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( s - > session - > waiting_thread  ! =  pthread_self ( ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											needexit  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( s - > session - > needdestroy ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											needexit  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( needexit ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( s - > session - > managerid  = =  0 )  { 	/* AMI session */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ast_wait_for_input ( s - > session - > fd ,  1000 ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 17:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  { 	/* HTTP session */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											sleep ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_debug ( 1 ,  " Finished waiting for an event! \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( s - > session - > waiting_thread  = =  pthread_self ( ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 11:24:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										struct  eventqent  * eqe ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 12:05:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_response ( s ,  m ,  " Success " ,  " Waiting for Event completed. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 11:24:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										while  (  ( eqe  =  NEW_EVENT ( s ) )  )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ref_event ( eqe ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ( ( s - > session - > readperm  &  eqe - > category )  = =  eqe - > category )  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											    ( ( s - > session - > send_events  &  eqe - > category )  = =  eqe - > category ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												astman_append ( s ,  " %s " ,  eqe - > eventdata ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											s - > session - > last_ev  =  unref_event ( s - > session - > last_ev ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Event: WaitEventComplete \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" \r \n " ,  idText ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										s - > session - > waiting_thread  =  AST_PTHREADT_NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_debug ( 1 ,  " Abandoning event request! \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_listcommands [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 22:30:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Returns the action name and synopsis for every \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   action that is available to the user \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: NONE \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-29 20:51:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \note The actionlock is read-locked by the caller of this function */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_listcommands ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 22:30:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * temp  =  ast_str_alloca ( BUFSIZ ) ;  /* XXX very large ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 22:30:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & actions ,  cur ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( s - > session - > writeperm  &  cur - > authority  | |  cur - > authority  = =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_append ( s ,  " %s: %s (Priv: %s) \r \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												cur - > action ,  cur - > synopsis ,  authority_to_str ( cur - > authority ,  & temp ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 22:30:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 22:30:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_events [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-29 05:04:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Enable/Disable sending of events to this manager \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   client. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 15:39:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	EventMask: 'on' if all events should be sent, \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-08 17:08:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 		'off' if no events should be sent, \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 		'system,call,log' to select which flags events should have to be sent. \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-29 05:04:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_events ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-01 21:12:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * mask  =  astman_get_header ( m ,  " EventMask " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-01 21:12:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-02 08:45:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									res  =  set_eventmask ( s ,  mask ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( res  >  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-22 15:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Response: Success \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												 " Events: On \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-02 08:45:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else  if  ( res  = =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-22 15:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Response: Success \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												 " Events: Off \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-01 21:12:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_logoff [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-29 05:04:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Logoff this manager session \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: NONE \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_logoff ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_response ( s ,  m ,  " Goodbye " ,  " Thanks for all the fish. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_login ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( authenticate ( s ,  m ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										sleep ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Authentication failed " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s - > session - > authenticated  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( manager_displayconnects ( s - > session ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_verb ( 2 ,  " %sManager '%s' logged on from %s \n " ,  ( s - > session - > managerid  ?  " HTTP  "  :  " " ) ,  s - > session - > username ,  ast_inet_ntoa ( s - > session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_log ( LOG_EVENT ,  " %sManager '%s' logged on from %s \n " ,  ( s - > session - > managerid  ?  " HTTP  "  :  " " ) ,  s - > session - > username ,  ast_inet_ntoa ( s - > session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_ack ( s ,  m ,  " Authentication accepted " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_challenge ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * authtype  =  astman_get_header ( m ,  " AuthType " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! strcasecmp ( authtype ,  " MD5 " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( s - > session - > challenge ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											snprintf ( s - > session - > challenge ,  sizeof ( s - > session - > challenge ) ,  " %ld " ,  ast_random ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " Challenge: %s \r \n \r \n " ,  s - > session - > challenge ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Must specify AuthType " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_hangup [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-29 05:04:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Hangup a channel \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables:  \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Channel: The channel name to be hungup \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_hangup ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No channel specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-06-06 02:29:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									c  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! c )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No such channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_softhangup ( c ,  AST_SOFTHANGUP_EXPLICIT ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_ack ( s ,  m ,  " Channel Hungup " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_setvar [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 03:35:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Set a global or local channel variable. \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 03:35:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	Channel: Channel to set variable for \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	*Variable: Variable name \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Value: Value \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_setvar ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 20:35:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * varname  =  astman_get_header ( m ,  " Variable " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * varval  =  astman_get_header ( m ,  " Value " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 03:35:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( varname ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No variable specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 03:35:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										c  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! c )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " No such channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 17:42:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									pbx_builtin_setvar_helper ( c ,  varname ,  S_OR ( varval ,  " " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-11-15 18:35:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-15 18:35:30 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_ack ( s ,  m ,  " Variable Set " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-08 03:35:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_getvar [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-13 20:30:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Get the value of a global or local channel variable. \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-13 20:30:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	Channel: Channel to read variable from \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	*Variable: Variable name \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional Action id for message matching. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_getvar ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * varname  =  astman_get_header ( m ,  " Variable " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * varval ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-19 04:37:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  workspace [ 1024 ]  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( varname ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No variable specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-13 20:30:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										c  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! c )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " No such channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-01-15 05:50:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( varname [ strlen ( varname )  -  1 ]  = =  ' ) ' )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-18 02:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! c )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-12-01 23:53:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c  =  ast_channel_alloc ( 0 ,  0 ,  " " ,  " " ,  " " ,  " " ,  " " ,  0 ,  " Bogus/manager " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-18 02:29:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( c )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_func_read ( c ,  ( char  * )  varname ,  workspace ,  sizeof ( workspace ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_channel_free ( c ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_log ( LOG_ERROR ,  " Unable to allocate bogus channel for variable substitution.  Function results may be blank. \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_func_read ( c ,  ( char  * )  varname ,  workspace ,  sizeof ( workspace ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-19 04:37:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										varval  =  workspace ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-15 05:50:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										pbx_retrieve_variable ( c ,  varname ,  & varval ,  workspace ,  sizeof ( workspace ) ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-13 20:30:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( c ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Variable: %s \r \n Value: %s \r \n \r \n " ,  varname ,  varval ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_status [ ]  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Lists channel status along with requested channel vars. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Channel: Name of the channel to query for status \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Variables: Comma ',' separated list of variables to include \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional ID for this transaction \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Will return the status information of each channel along with the \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" value for the specified channel variables. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-03 15:42:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-22 15:34:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Manager "status" command to show channels */ 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* Needs documentation... */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_status ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * cvariables  =  astman_get_header ( m ,  " Variables " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * variables  =  ast_strdupa ( S_OR ( cvariables ,  " " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  bridge [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:00:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  timeval  now  =  ast_tvnow ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									long  elapsed_seconds  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  channels  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  all  =  ast_strlen_zero ( name ) ;  /* set if we want all channels */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * id  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  idText [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_DECLARE_APP_ARGS ( vars , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_APP_ARG ( name ) [ 100 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_str  * str  =  ast_str_create ( 1000 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-08-03 17:48:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( idText ,  sizeof ( idText ) ,  " ActionID: %s \r \n " ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										idText [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-06-06 02:29:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( all ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										c  =  ast_channel_walk_locked ( NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										c  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-26 14:31:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! c )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " No such channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-06 10:26:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_free ( str ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-26 14:31:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-06 07:07:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_ack ( s ,  m ,  " Channel status will follow " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( cvariables ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_STANDARD_APP_ARGS ( vars ,  variables ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-06-06 02:29:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* if we look by name, we break after the first iteration */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									while  ( c )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ast_strlen_zero ( cvariables ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											int  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_str_reset ( str ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											for  ( i  =  0 ;  i  <  vars . argc ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												char  valbuf [ 512 ] ,  * ret  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( vars . name [ i ] [ strlen ( vars . name [ i ] )  -  1 ]  = =  ' ) ' )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( ast_func_read ( c ,  vars . name [ i ] ,  valbuf ,  sizeof ( valbuf ) )  <  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														valbuf [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													ret  =  valbuf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													pbx_retrieve_variable ( c ,  vars . name [ i ] ,  & ret ,  valbuf ,  sizeof ( valbuf ) ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_str_append ( & str ,  0 ,  " Variable: %s=%s \r \n " ,  vars . name [ i ] ,  ret ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										channels + + ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-23 12:19:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( c - > _bridge ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											snprintf ( bridge ,  sizeof ( bridge ) ,  " BridgedChannel: %s \r \n BridgedUniqueid: %s \r \n " ,  c - > _bridge - > name ,  c - > _bridge - > uniqueid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 07:44:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											bridge [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										if  ( c - > pbx )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-08-03 17:48:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( c - > cdr )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												elapsed_seconds  =  now . tv_sec  -  c - > cdr - > start . tv_sec ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_append ( s , 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" Event: Status \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-04 16:18:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Privilege: Call \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" Channel: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-11 23:23:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" CallerIDNum: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-02 00:58:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" CallerIDName: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Accountcode: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" ChannelState: %d \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" ChannelStateDesc: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" Context: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Extension: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Priority: %d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-08-03 17:48:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Seconds: %ld \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-14 14:57:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Uniqueid: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-14 14:57:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > name , 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											S_OR ( c - > cid . cid_num ,  " " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											S_OR ( c - > cid . cid_name ,  " " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-26 14:31:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > accountcode , 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > _state , 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											ast_state2str ( c - > _state ) ,  c - > context , 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > exten ,  c - > priority ,  ( long ) elapsed_seconds ,  bridge ,  c - > uniqueid ,  str - > str ,  idText ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_append ( s , 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" Event: Status \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-04 16:18:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Privilege: Call \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" Channel: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-11 23:23:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" CallerIDNum: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-02 00:58:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" CallerIDName: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-26 14:31:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Account: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											" State: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2003-08-12 23:08:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Uniqueid: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2003-08-12 23:08:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > name , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											S_OR ( c - > cid . cid_num ,  " <unknown> " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											S_OR ( c - > cid . cid_name ,  " <unknown> " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-26 14:31:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > accountcode , 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_state2str ( c - > _state ) ,  bridge ,  c - > uniqueid ,  str - > str ,  idText ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-06-06 02:29:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! all ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-26 14:31:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-20 16:30:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										c  =  ast_channel_walk_locked ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s , 
							 
						 
					
						
							
								
									
										
										
										
											2004-01-29 00:28:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									" Event: StatusComplete \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									" %s " 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									" Items: %d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									" \r \n " ,  idText ,  channels ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_free ( str ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_sendtext [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Sends A Text Message while in a call. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *Channel: Channel to send message to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *Message: Message to send \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        ActionID: Optional Action id for message matching. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_sendtext ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * textmsg  =  astman_get_header ( m ,  " Message " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  res  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 15:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No channel specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 15:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( textmsg ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No Message specified " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									c  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! c )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No such channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									res  =  ast_sendtext ( c ,  textmsg ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-15 16:20:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 15:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( res  >  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_ack ( s ,  m ,  " Success " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 15:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Failure " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 15:22:28 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_redirect [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Redirect (transfer) a call. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Channel: Channel to redirect \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ExtraChannel: Second call leg to transfer (optional) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Exten: Extension to transfer to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Context: Context to transfer to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Priority: Priority to transfer to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional Action id for message matching. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 13:03:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief  action_redirect: The redirect manager command */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_redirect ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * name2  =  astman_get_header ( m ,  " ExtraChannel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * exten  =  astman_get_header ( m ,  " Exten " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * context  =  astman_get_header ( m ,  " Context " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * priority  =  astman_get_header ( m ,  " Priority " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-10-01 21:31:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_channel  * chan ,  * chan2  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									int  pi  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Channel not specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( priority )  & &  ( sscanf ( priority ,  " %d " ,  & pi )  ! =  1 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ( pi  =  ast_findlabel_extension ( NULL ,  context ,  exten ,  priority ,  NULL ) )  <  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Invalid priority " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* XXX watch out, possible deadlock - we are trying to get two channels!!! */ 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									chan  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-24 15:28:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! chan )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:24:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										char  buf [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( buf ,  sizeof ( buf ) ,  " Channel does not exist: %s " ,  name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-24 15:28:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-04 17:41:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_check_hangup ( chan ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Redirect failed, channel not up. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-03-07 00:26:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( name2 ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										chan2  =  ast_get_channel_by_name_locked ( name2 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-04 17:41:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( chan2  & &  ast_check_hangup ( chan2 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Redirect failed, extra channel not up. " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-03-07 00:26:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan2 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 172063 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
  r172063 | murf | 2009-01-28 13:31:06 -0700 (Wed, 28 Jan 2009) | 52 lines
  
  Merged revisions 172030 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r172030 | murf | 2009-01-28 11:51:16 -0700 (Wed, 28 Jan 2009) | 46 lines
    
    This patch fixes h-exten running misbehavior in manager-redirected 
    situations.
    
    What it does:
    1. A new Flag value is defined in include/asterisk/channel.h,
     AST_FLAG_BRIDGE_HANGUP_DONT, which used as a messenge to the
     bridge hangup exten code not to run the h-exten there (nor
     publish the bridge cdr there). It will done at the pbx-loop
     level instead.
    2. In the manager Redirect code, I set this flag on the channel
     if the channel has a non-null pbx pointer. I did the same for the
     second (chan2) channel, which gets run if name2 is set...
     and the first succeeds.
    3. I restored the ending of the cdr for the pbx loop h-exten
     running code. Don't know why it was removed in the first place.
    4. The first attempt at the fix for this bug was to place code
       directly in the async_goto routine, which was called from a
       large number of places, and could affect a large number of
       cases, so I tested that fix against a fair number of transfer
       scenarios, both with and without the patch. In the process,
       I saw that putting the fix in async_goto seemed not to affect
       any of the blind or attended scenarios, but still, I was
       was highly concerned that some other scenarios I had not tested
       might be negatively impacted, so I refined the patch to 
       its current scope, and jmls tested both. In the process, tho,
       I saw that blind xfers in one situation, when the one-touch
       blind-xfer feature is used by the peer, we got strange 
       h-exten behavior.  So, I  inserted code to swap CDRs and
       to set the HANGUP_DONT field, to get uniform behavior.
    5. I added code to the bridge to obey the HANGUP_DONT flag,
       skipping both publishing the bridge CDR, and running
       the h-exten; they will be done at the pbx-loop (higher)
       level instead.
    6. I removed all the debug logs from the patch before committing.
    7. I moved the AUTOLOOP set/reset in the h-exten code in res_features
       so it's only done if the h-exten is going to be run. A very
       minor performance improvement, but technically correct.
    
    
    (closes issue #14241)
    Reported by: jmls
    Patches:
          14241_redirect_no_bridgeCDR_or_h_exten_via_transfer uploaded by murf (license 17)
    Tested by: murf, jmls
  ........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@172067 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2009-01-28 20:56:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( chan - > pbx )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_channel_lock ( chan ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_set_flag ( chan ,  AST_FLAG_BRIDGE_HANGUP_DONT ) ;  /* don't let the after-bridge code run the h-exten */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									res  =  ast_async_goto ( chan ,  context ,  exten ,  pi ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! res )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ast_strlen_zero ( name2 ) )  { 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 172063 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
  r172063 | murf | 2009-01-28 13:31:06 -0700 (Wed, 28 Jan 2009) | 52 lines
  
  Merged revisions 172030 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r172030 | murf | 2009-01-28 11:51:16 -0700 (Wed, 28 Jan 2009) | 46 lines
    
    This patch fixes h-exten running misbehavior in manager-redirected 
    situations.
    
    What it does:
    1. A new Flag value is defined in include/asterisk/channel.h,
     AST_FLAG_BRIDGE_HANGUP_DONT, which used as a messenge to the
     bridge hangup exten code not to run the h-exten there (nor
     publish the bridge cdr there). It will done at the pbx-loop
     level instead.
    2. In the manager Redirect code, I set this flag on the channel
     if the channel has a non-null pbx pointer. I did the same for the
     second (chan2) channel, which gets run if name2 is set...
     and the first succeeds.
    3. I restored the ending of the cdr for the pbx loop h-exten
     running code. Don't know why it was removed in the first place.
    4. The first attempt at the fix for this bug was to place code
       directly in the async_goto routine, which was called from a
       large number of places, and could affect a large number of
       cases, so I tested that fix against a fair number of transfer
       scenarios, both with and without the patch. In the process,
       I saw that putting the fix in async_goto seemed not to affect
       any of the blind or attended scenarios, but still, I was
       was highly concerned that some other scenarios I had not tested
       might be negatively impacted, so I refined the patch to 
       its current scope, and jmls tested both. In the process, tho,
       I saw that blind xfers in one situation, when the one-touch
       blind-xfer feature is used by the peer, we got strange 
       h-exten behavior.  So, I  inserted code to swap CDRs and
       to set the HANGUP_DONT field, to get uniform behavior.
    5. I added code to the bridge to obey the HANGUP_DONT flag,
       skipping both publishing the bridge CDR, and running
       the h-exten; they will be done at the pbx-loop (higher)
       level instead.
    6. I removed all the debug logs from the patch before committing.
    7. I moved the AUTOLOOP set/reset in the h-exten code in res_features
       so it's only done if the h-exten is going to be run. A very
       minor performance improvement, but technically correct.
    
    
    (closes issue #14241)
    Reported by: jmls
    Patches:
          14241_redirect_no_bridgeCDR_or_h_exten_via_transfer uploaded by murf (license 17)
    Tested by: murf, jmls
  ........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@172067 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2009-01-28 20:56:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( chan2 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( chan2 - > pbx )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													ast_channel_lock ( chan2 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													ast_set_flag ( chan2 ,  AST_FLAG_BRIDGE_HANGUP_DONT ) ;  /* don't let the after-bridge code run the h-exten */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													ast_channel_unlock ( chan2 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res  =  ast_async_goto ( chan2 ,  context ,  exten ,  pi ) ; 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 172063 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
  r172063 | murf | 2009-01-28 13:31:06 -0700 (Wed, 28 Jan 2009) | 52 lines
  
  Merged revisions 172030 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r172030 | murf | 2009-01-28 11:51:16 -0700 (Wed, 28 Jan 2009) | 46 lines
    
    This patch fixes h-exten running misbehavior in manager-redirected 
    situations.
    
    What it does:
    1. A new Flag value is defined in include/asterisk/channel.h,
     AST_FLAG_BRIDGE_HANGUP_DONT, which used as a messenge to the
     bridge hangup exten code not to run the h-exten there (nor
     publish the bridge cdr there). It will done at the pbx-loop
     level instead.
    2. In the manager Redirect code, I set this flag on the channel
     if the channel has a non-null pbx pointer. I did the same for the
     second (chan2) channel, which gets run if name2 is set...
     and the first succeeds.
    3. I restored the ending of the cdr for the pbx loop h-exten
     running code. Don't know why it was removed in the first place.
    4. The first attempt at the fix for this bug was to place code
       directly in the async_goto routine, which was called from a
       large number of places, and could affect a large number of
       cases, so I tested that fix against a fair number of transfer
       scenarios, both with and without the patch. In the process,
       I saw that putting the fix in async_goto seemed not to affect
       any of the blind or attended scenarios, but still, I was
       was highly concerned that some other scenarios I had not tested
       might be negatively impacted, so I refined the patch to 
       its current scope, and jmls tested both. In the process, tho,
       I saw that blind xfers in one situation, when the one-touch
       blind-xfer feature is used by the peer, we got strange 
       h-exten behavior.  So, I  inserted code to swap CDRs and
       to set the HANGUP_DONT field, to get uniform behavior.
    5. I added code to the bridge to obey the HANGUP_DONT flag,
       skipping both publishing the bridge CDR, and running
       the h-exten; they will be done at the pbx-loop (higher)
       level instead.
    6. I removed all the debug logs from the patch before committing.
    7. I moved the AUTOLOOP set/reset in the h-exten code in res_features
       so it's only done if the h-exten is going to be run. A very
       minor performance improvement, but technically correct.
    
    
    (closes issue #14241)
    Reported by: jmls
    Patches:
          14241_redirect_no_bridgeCDR_or_h_exten_via_transfer uploaded by murf (license 17)
    Tested by: murf, jmls
  ........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@172067 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2009-01-28 20:56:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res  =  - 1 ; 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 172063 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
  r172063 | murf | 2009-01-28 13:31:06 -0700 (Wed, 28 Jan 2009) | 52 lines
  
  Merged revisions 172030 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r172030 | murf | 2009-01-28 11:51:16 -0700 (Wed, 28 Jan 2009) | 46 lines
    
    This patch fixes h-exten running misbehavior in manager-redirected 
    situations.
    
    What it does:
    1. A new Flag value is defined in include/asterisk/channel.h,
     AST_FLAG_BRIDGE_HANGUP_DONT, which used as a messenge to the
     bridge hangup exten code not to run the h-exten there (nor
     publish the bridge cdr there). It will done at the pbx-loop
     level instead.
    2. In the manager Redirect code, I set this flag on the channel
     if the channel has a non-null pbx pointer. I did the same for the
     second (chan2) channel, which gets run if name2 is set...
     and the first succeeds.
    3. I restored the ending of the cdr for the pbx loop h-exten
     running code. Don't know why it was removed in the first place.
    4. The first attempt at the fix for this bug was to place code
       directly in the async_goto routine, which was called from a
       large number of places, and could affect a large number of
       cases, so I tested that fix against a fair number of transfer
       scenarios, both with and without the patch. In the process,
       I saw that putting the fix in async_goto seemed not to affect
       any of the blind or attended scenarios, but still, I was
       was highly concerned that some other scenarios I had not tested
       might be negatively impacted, so I refined the patch to 
       its current scope, and jmls tested both. In the process, tho,
       I saw that blind xfers in one situation, when the one-touch
       blind-xfer feature is used by the peer, we got strange 
       h-exten behavior.  So, I  inserted code to swap CDRs and
       to set the HANGUP_DONT field, to get uniform behavior.
    5. I added code to the bridge to obey the HANGUP_DONT flag,
       skipping both publishing the bridge CDR, and running
       the h-exten; they will be done at the pbx-loop (higher)
       level instead.
    6. I removed all the debug logs from the patch before committing.
    7. I moved the AUTOLOOP set/reset in the h-exten code in res_features
       so it's only done if the h-exten is going to be run. A very
       minor performance improvement, but technically correct.
    
    
    (closes issue #14241)
    Reported by: jmls
    Patches:
          14241_redirect_no_bridgeCDR_or_h_exten_via_transfer uploaded by murf (license 17)
    Tested by: murf, jmls
  ........
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.1@172067 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2009-01-28 20:56:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! res ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												astman_send_ack ( s ,  m ,  " Dual Redirect successful " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
											else 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												astman_send_error ( s ,  m ,  " Secondary redirect failed " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										}  else 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_send_ack ( s ,  m ,  " Redirect successful " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									}  else 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Redirect failed " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( chan ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-22 04:11:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( chan2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan2 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_atxfer [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Attended transfer. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Channel: Transferer's channel \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Exten: Extension to transfer to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Context: Context to transfer to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Priority: Priority to transfer to \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional Action id for message matching. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_atxfer ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * exten  =  astman_get_header ( m ,  " Exten " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * context  =  astman_get_header ( m ,  " Context " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_channel  * chan  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_call_feature  * atxfer_feature  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * feature_code  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( name ) )  {  
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No channel specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( exten ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No extension specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ( atxfer_feature  =  ast_find_call_feature ( " atxfer " ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No attended transfer feature found " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ( chan  =  ast_get_channel_by_name_locked ( name ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Channel specified does not exist " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-10-09 23:55:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( context ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										pbx_builtin_setvar_helper ( chan ,  " TRANSFER_CONTEXT " ,  context ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( feature_code  =  atxfer_feature - > exten ;  feature_code  & &  * feature_code ;  + + feature_code )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										struct  ast_frame  f  =  { AST_FRAME_DTMF ,  * feature_code } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_queue_frame ( chan ,  & f ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( feature_code  =  ( char  * ) exten ;  feature_code  & &  * feature_code ;  + + feature_code )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										struct  ast_frame  f  =  { AST_FRAME_DTMF ,  * feature_code } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_queue_frame ( chan ,  & f ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_ack ( s ,  m ,  " Atxfer successfully queued " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_channel_unlock ( chan ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-06-02 14:41:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  check_blacklist ( const  char  * cmd ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * cmd_copy ,  * cur_cmd ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * cmd_words [ MAX_BLACKLIST_CMD_LEN ]  =  {  NULL ,  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									cmd_copy  =  ast_strdupa ( cmd ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( i  =  0 ;  i  <  MAX_BLACKLIST_CMD_LEN  & &  ( cur_cmd  =  strsep ( & cmd_copy ,  "   " ) ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										cur_cmd  =  ast_strip ( cur_cmd ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( cur_cmd ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											i - - ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										cmd_words [ i ]  =  cur_cmd ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( i  =  0 ;  i  <  ARRAY_LEN ( command_blacklist ) ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										int  j ,  match  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										for  ( j  =  0 ;  command_blacklist [ i ] . words [ j ] ;  j + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( cmd_words [ j ] )  | |  strcasecmp ( cmd_words [ j ] ,  command_blacklist [ i ] . words [ j ] ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												match  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( match )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_command [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Run a CLI command. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Command: Asterisk CLI command to run \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional Action id for message matching. \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief  Manager command "command" - execute CLI command */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_command ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * cmd  =  astman_get_header ( m ,  " Command " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * id  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-10 22:25:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * buf ,  * final_buf ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 18:45:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  template [ ]  =  " /tmp/ast-ami-XXXXXX " ; 	/* template for temporary file */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-02 14:41:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  fd  =  mkstemp ( template ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 18:45:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									off_t  l ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-06-02 14:41:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( cmd ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No command provided " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( check_blacklist ( cmd ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Command blacklisted " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-24 15:30:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Response: Follows \r \n Privilege: Command \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( id ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " ActionID: %s \r \n " ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* FIXME: Wedge a ActionID response in here, waiting for later changes */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 18:45:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_cli_command ( fd ,  cmd ) ; 	/* XXX need to change this to use a FILE * */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									l  =  lseek ( fd ,  0 ,  SEEK_END ) ; 	/* how many chars available */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-29 04:56:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* This has a potential to overflow the stack.  Hence, use the heap. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									buf  =  ast_calloc ( 1 ,  l  +  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									final_buf  =  ast_calloc ( 1 ,  l  +  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( buf )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										lseek ( fd ,  0 ,  SEEK_SET ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-02 23:56:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( read ( fd ,  buf ,  l )  <  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_log ( LOG_WARNING ,  " read() failed: %s \n " ,  strerror ( errno ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-29 04:56:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										buf [ l ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( final_buf )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											term_strip ( final_buf ,  buf ,  l ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											final_buf [ l ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:13:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_append ( s ,  " %s " ,  S_OR ( final_buf ,  buf ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-29 04:56:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free ( buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 18:45:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									close ( fd ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									unlink ( template ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-25 23:50:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " --END COMMAND-- \r \n \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-29 04:56:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( final_buf ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_free ( final_buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief helper function for originate */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  fast_originate_helper  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  tech [ AST_MAX_EXTENSION ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-13 21:31:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/*! data can contain a channel name, extension number, username, password, etc. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  data [ 512 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  timeout ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  format ; 				/*!< Codecs used for a call */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  app [ AST_MAX_APP ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  appdata [ AST_MAX_EXTENSION ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  cid_name [ AST_MAX_EXTENSION ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  cid_num [ AST_MAX_EXTENSION ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  context [ AST_MAX_CONTEXT ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  exten [ AST_MAX_EXTENSION ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  idtext [ AST_MAX_EXTENSION ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  account [ AST_MAX_ACCOUNT_CODE ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  priority ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_variable  * vars ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  * fast_originate ( void  * data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  fast_originate_helper  * in  =  data ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  reason  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-02 02:54:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_channel  * chan  =  NULL ; 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 47986,47995,47997,48001,48003-48004,48008-48014,48016,48018-48019 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
r47986 | oej | 2006-11-24 07:00:19 -0700 (Fri, 24 Nov 2006) | 6 lines
Doxygen update
- Document cause codes
- Document a bit more on channel variables - global, predefined and local
- Fix some doxygen in channel.h. Adding one comment for two definitions does not
  work. They won't be copied to each.
................
r47995 | murf | 2006-11-24 10:40:49 -0700 (Fri, 24 Nov 2006) | 1 line
This fix inspired by a patch supplied in bug 8189, which points out problems with the PLC code
................
r47997 | murf | 2006-11-24 11:17:25 -0700 (Fri, 24 Nov 2006) | 1 line
removed the svnmerge-integrated property from trunk; it's confusing svnmerge in newly created branches
................
r48001 | rizzo | 2006-11-25 02:02:42 -0700 (Sat, 25 Nov 2006) | 5 lines
set pointers to NULL after freeing memory to avoid multiple free()
probably 1.4/1.2 issue as well if someone can look into that.
................
r48003 | oej | 2006-11-25 02:45:57 -0700 (Sat, 25 Nov 2006) | 9 lines
- Adding comment on suspicious memory allocation. Seems like it's never freed, but I don't
  have a clear understanding of the frame allocation/deallocation, so I just mark this
  for investigation. (Reported by Ed Guy). We're trying to see if a free() hurts...
- Doxygen comments on p2p rtp bridge stuff.  I am a bit worried about shortcutting
  rtcp this way, but will need feedback from rtcp gurus. This should work for 
  video calls too, and possibly UDPTL.
................
r48004 | oej | 2006-11-25 02:48:30 -0700 (Sat, 25 Nov 2006) | 2 lines
Changing ERROR to lesser level. Imported from 1.2/1.4
................
r48008 | rizzo | 2006-11-25 10:37:04 -0700 (Sat, 25 Nov 2006) | 7 lines
generalize a bit the functions used to create an tcp socket
and then run a service on it.
The code in manager.c does essentially the same things,
so we will be able to reuse the code in here (probably
moving it to netsock.c or another appropriate library file).
................
r48009 | mattf | 2006-11-25 13:30:04 -0700 (Sat, 25 Nov 2006) | 1 line
Updates to show linkset command
................
r48010 | mattf | 2006-11-25 13:54:38 -0700 (Sat, 25 Nov 2006) | 2 lines
Add ss7 show linkset command
................
r48011 | mattf | 2006-11-25 14:32:33 -0700 (Sat, 25 Nov 2006) | 1 line
Make sure we don't send a group reset on a group larger than 32 CICs
................
r48012 | mattf | 2006-11-25 14:35:23 -0700 (Sat, 25 Nov 2006) | 1 line
bug fix
................
r48013 | mattf | 2006-11-25 14:46:58 -0700 (Sat, 25 Nov 2006) | 1 line
Make compiler happier
................
r48014 | mattf | 2006-11-25 14:50:42 -0700 (Sat, 25 Nov 2006) | 1 line
Little fix so we use the right message
................
r48016 | murf | 2006-11-25 17:15:42 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48015 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48015 | murf | 2006-11-25 17:01:34 -0700 (Sat, 25 Nov 2006) | 1 line
A little bit of func_cdr documentation upgrade-- no bug# involved, although 8221 may have inspired it.
........
................
r48018 | murf | 2006-11-25 17:31:13 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48017 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48017 | murf | 2006-11-25 17:26:16 -0700 (Sat, 25 Nov 2006) | 1 line
might as well also document the raw values of the flag vars
........
................
r48019 | russell | 2006-11-25 23:55:33 -0700 (Sat, 25 Nov 2006) | 6 lines
- Add some comments on thread storage with a brief explanation of what it is
  as well as what the motivation is for using it.
- Add a comment by the declaration of ast_inet_ntoa() noting that this function
  is not reentrant, and the result of a previous call to the function is no
  longer valid after calling it again.
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48350 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-12-07 16:03:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  requested_channel [ AST_CHANNEL_NAME ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-02 02:54:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( in - > app ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										res  =  ast_pbx_outgoing_app ( in - > tech ,  in - > format ,  in - > data ,  in - > timeout ,  in - > app ,  in - > appdata ,  & reason ,  1 , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											S_OR ( in - > cid_num ,  NULL ) , 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-26 16:08:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											S_OR ( in - > cid_name ,  NULL ) , 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-11 18:31:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											in - > vars ,  in - > account ,  & chan ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										res  =  ast_pbx_outgoing_exten ( in - > tech ,  in - > format ,  in - > data ,  in - > timeout ,  in - > context ,  in - > exten ,  in - > priority ,  & reason ,  1 , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											S_OR ( in - > cid_num ,  NULL ) , 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-26 16:08:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											S_OR ( in - > cid_name ,  NULL ) , 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-11 18:31:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											in - > vars ,  in - > account ,  & chan ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 47986,47995,47997,48001,48003-48004,48008-48014,48016,48018-48019 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
r47986 | oej | 2006-11-24 07:00:19 -0700 (Fri, 24 Nov 2006) | 6 lines
Doxygen update
- Document cause codes
- Document a bit more on channel variables - global, predefined and local
- Fix some doxygen in channel.h. Adding one comment for two definitions does not
  work. They won't be copied to each.
................
r47995 | murf | 2006-11-24 10:40:49 -0700 (Fri, 24 Nov 2006) | 1 line
This fix inspired by a patch supplied in bug 8189, which points out problems with the PLC code
................
r47997 | murf | 2006-11-24 11:17:25 -0700 (Fri, 24 Nov 2006) | 1 line
removed the svnmerge-integrated property from trunk; it's confusing svnmerge in newly created branches
................
r48001 | rizzo | 2006-11-25 02:02:42 -0700 (Sat, 25 Nov 2006) | 5 lines
set pointers to NULL after freeing memory to avoid multiple free()
probably 1.4/1.2 issue as well if someone can look into that.
................
r48003 | oej | 2006-11-25 02:45:57 -0700 (Sat, 25 Nov 2006) | 9 lines
- Adding comment on suspicious memory allocation. Seems like it's never freed, but I don't
  have a clear understanding of the frame allocation/deallocation, so I just mark this
  for investigation. (Reported by Ed Guy). We're trying to see if a free() hurts...
- Doxygen comments on p2p rtp bridge stuff.  I am a bit worried about shortcutting
  rtcp this way, but will need feedback from rtcp gurus. This should work for 
  video calls too, and possibly UDPTL.
................
r48004 | oej | 2006-11-25 02:48:30 -0700 (Sat, 25 Nov 2006) | 2 lines
Changing ERROR to lesser level. Imported from 1.2/1.4
................
r48008 | rizzo | 2006-11-25 10:37:04 -0700 (Sat, 25 Nov 2006) | 7 lines
generalize a bit the functions used to create an tcp socket
and then run a service on it.
The code in manager.c does essentially the same things,
so we will be able to reuse the code in here (probably
moving it to netsock.c or another appropriate library file).
................
r48009 | mattf | 2006-11-25 13:30:04 -0700 (Sat, 25 Nov 2006) | 1 line
Updates to show linkset command
................
r48010 | mattf | 2006-11-25 13:54:38 -0700 (Sat, 25 Nov 2006) | 2 lines
Add ss7 show linkset command
................
r48011 | mattf | 2006-11-25 14:32:33 -0700 (Sat, 25 Nov 2006) | 1 line
Make sure we don't send a group reset on a group larger than 32 CICs
................
r48012 | mattf | 2006-11-25 14:35:23 -0700 (Sat, 25 Nov 2006) | 1 line
bug fix
................
r48013 | mattf | 2006-11-25 14:46:58 -0700 (Sat, 25 Nov 2006) | 1 line
Make compiler happier
................
r48014 | mattf | 2006-11-25 14:50:42 -0700 (Sat, 25 Nov 2006) | 1 line
Little fix so we use the right message
................
r48016 | murf | 2006-11-25 17:15:42 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48015 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48015 | murf | 2006-11-25 17:01:34 -0700 (Sat, 25 Nov 2006) | 1 line
A little bit of func_cdr documentation upgrade-- no bug# involved, although 8221 may have inspired it.
........
................
r48018 | murf | 2006-11-25 17:31:13 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48017 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48017 | murf | 2006-11-25 17:26:16 -0700 (Sat, 25 Nov 2006) | 1 line
might as well also document the raw values of the flag vars
........
................
r48019 | russell | 2006-11-25 23:55:33 -0700 (Sat, 25 Nov 2006) | 6 lines
- Add some comments on thread storage with a brief explanation of what it is
  as well as what the motivation is for using it.
- Add a comment by the declaration of ast_inet_ntoa() noting that this function
  is not reentrant, and the result of a previous call to the function is no
  longer valid after calling it again.
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48350 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-12-07 16:03:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! chan ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( requested_channel ,  AST_CHANNEL_NAME ,  " %s/%s " ,  in - > tech ,  in - > data ) ; 	
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 11:31:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* Tell the manager what happened with the channel */ 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 47986,47995,47997,48001,48003-48004,48008-48014,48016,48018-48019 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
r47986 | oej | 2006-11-24 07:00:19 -0700 (Fri, 24 Nov 2006) | 6 lines
Doxygen update
- Document cause codes
- Document a bit more on channel variables - global, predefined and local
- Fix some doxygen in channel.h. Adding one comment for two definitions does not
  work. They won't be copied to each.
................
r47995 | murf | 2006-11-24 10:40:49 -0700 (Fri, 24 Nov 2006) | 1 line
This fix inspired by a patch supplied in bug 8189, which points out problems with the PLC code
................
r47997 | murf | 2006-11-24 11:17:25 -0700 (Fri, 24 Nov 2006) | 1 line
removed the svnmerge-integrated property from trunk; it's confusing svnmerge in newly created branches
................
r48001 | rizzo | 2006-11-25 02:02:42 -0700 (Sat, 25 Nov 2006) | 5 lines
set pointers to NULL after freeing memory to avoid multiple free()
probably 1.4/1.2 issue as well if someone can look into that.
................
r48003 | oej | 2006-11-25 02:45:57 -0700 (Sat, 25 Nov 2006) | 9 lines
- Adding comment on suspicious memory allocation. Seems like it's never freed, but I don't
  have a clear understanding of the frame allocation/deallocation, so I just mark this
  for investigation. (Reported by Ed Guy). We're trying to see if a free() hurts...
- Doxygen comments on p2p rtp bridge stuff.  I am a bit worried about shortcutting
  rtcp this way, but will need feedback from rtcp gurus. This should work for 
  video calls too, and possibly UDPTL.
................
r48004 | oej | 2006-11-25 02:48:30 -0700 (Sat, 25 Nov 2006) | 2 lines
Changing ERROR to lesser level. Imported from 1.2/1.4
................
r48008 | rizzo | 2006-11-25 10:37:04 -0700 (Sat, 25 Nov 2006) | 7 lines
generalize a bit the functions used to create an tcp socket
and then run a service on it.
The code in manager.c does essentially the same things,
so we will be able to reuse the code in here (probably
moving it to netsock.c or another appropriate library file).
................
r48009 | mattf | 2006-11-25 13:30:04 -0700 (Sat, 25 Nov 2006) | 1 line
Updates to show linkset command
................
r48010 | mattf | 2006-11-25 13:54:38 -0700 (Sat, 25 Nov 2006) | 2 lines
Add ss7 show linkset command
................
r48011 | mattf | 2006-11-25 14:32:33 -0700 (Sat, 25 Nov 2006) | 1 line
Make sure we don't send a group reset on a group larger than 32 CICs
................
r48012 | mattf | 2006-11-25 14:35:23 -0700 (Sat, 25 Nov 2006) | 1 line
bug fix
................
r48013 | mattf | 2006-11-25 14:46:58 -0700 (Sat, 25 Nov 2006) | 1 line
Make compiler happier
................
r48014 | mattf | 2006-11-25 14:50:42 -0700 (Sat, 25 Nov 2006) | 1 line
Little fix so we use the right message
................
r48016 | murf | 2006-11-25 17:15:42 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48015 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48015 | murf | 2006-11-25 17:01:34 -0700 (Sat, 25 Nov 2006) | 1 line
A little bit of func_cdr documentation upgrade-- no bug# involved, although 8221 may have inspired it.
........
................
r48018 | murf | 2006-11-25 17:31:13 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48017 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48017 | murf | 2006-11-25 17:26:16 -0700 (Sat, 25 Nov 2006) | 1 line
might as well also document the raw values of the flag vars
........
................
r48019 | russell | 2006-11-25 23:55:33 -0700 (Sat, 25 Nov 2006) | 6 lines
- Add some comments on thread storage with a brief explanation of what it is
  as well as what the motivation is for using it.
- Add a comment by the declaration of ast_inet_ntoa() noting that this function
  is not reentrant, and the result of a previous call to the function is no
  longer valid after calling it again.
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48350 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-12-07 16:03:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									manager_event ( EVENT_FLAG_CALL ,  " OriginateResponse " , 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-07 20:53:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" %s%s " 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merged revisions 47986,47995,47997,48001,48003-48004,48008-48014,48016,48018-48019 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk
................
r47986 | oej | 2006-11-24 07:00:19 -0700 (Fri, 24 Nov 2006) | 6 lines
Doxygen update
- Document cause codes
- Document a bit more on channel variables - global, predefined and local
- Fix some doxygen in channel.h. Adding one comment for two definitions does not
  work. They won't be copied to each.
................
r47995 | murf | 2006-11-24 10:40:49 -0700 (Fri, 24 Nov 2006) | 1 line
This fix inspired by a patch supplied in bug 8189, which points out problems with the PLC code
................
r47997 | murf | 2006-11-24 11:17:25 -0700 (Fri, 24 Nov 2006) | 1 line
removed the svnmerge-integrated property from trunk; it's confusing svnmerge in newly created branches
................
r48001 | rizzo | 2006-11-25 02:02:42 -0700 (Sat, 25 Nov 2006) | 5 lines
set pointers to NULL after freeing memory to avoid multiple free()
probably 1.4/1.2 issue as well if someone can look into that.
................
r48003 | oej | 2006-11-25 02:45:57 -0700 (Sat, 25 Nov 2006) | 9 lines
- Adding comment on suspicious memory allocation. Seems like it's never freed, but I don't
  have a clear understanding of the frame allocation/deallocation, so I just mark this
  for investigation. (Reported by Ed Guy). We're trying to see if a free() hurts...
- Doxygen comments on p2p rtp bridge stuff.  I am a bit worried about shortcutting
  rtcp this way, but will need feedback from rtcp gurus. This should work for 
  video calls too, and possibly UDPTL.
................
r48004 | oej | 2006-11-25 02:48:30 -0700 (Sat, 25 Nov 2006) | 2 lines
Changing ERROR to lesser level. Imported from 1.2/1.4
................
r48008 | rizzo | 2006-11-25 10:37:04 -0700 (Sat, 25 Nov 2006) | 7 lines
generalize a bit the functions used to create an tcp socket
and then run a service on it.
The code in manager.c does essentially the same things,
so we will be able to reuse the code in here (probably
moving it to netsock.c or another appropriate library file).
................
r48009 | mattf | 2006-11-25 13:30:04 -0700 (Sat, 25 Nov 2006) | 1 line
Updates to show linkset command
................
r48010 | mattf | 2006-11-25 13:54:38 -0700 (Sat, 25 Nov 2006) | 2 lines
Add ss7 show linkset command
................
r48011 | mattf | 2006-11-25 14:32:33 -0700 (Sat, 25 Nov 2006) | 1 line
Make sure we don't send a group reset on a group larger than 32 CICs
................
r48012 | mattf | 2006-11-25 14:35:23 -0700 (Sat, 25 Nov 2006) | 1 line
bug fix
................
r48013 | mattf | 2006-11-25 14:46:58 -0700 (Sat, 25 Nov 2006) | 1 line
Make compiler happier
................
r48014 | mattf | 2006-11-25 14:50:42 -0700 (Sat, 25 Nov 2006) | 1 line
Little fix so we use the right message
................
r48016 | murf | 2006-11-25 17:15:42 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48015 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48015 | murf | 2006-11-25 17:01:34 -0700 (Sat, 25 Nov 2006) | 1 line
A little bit of func_cdr documentation upgrade-- no bug# involved, although 8221 may have inspired it.
........
................
r48018 | murf | 2006-11-25 17:31:13 -0700 (Sat, 25 Nov 2006) | 9 lines
Merged revisions 48017 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4
........
r48017 | murf | 2006-11-25 17:26:16 -0700 (Sat, 25 Nov 2006) | 1 line
might as well also document the raw values of the flag vars
........
................
r48019 | russell | 2006-11-25 23:55:33 -0700 (Sat, 25 Nov 2006) | 6 lines
- Add some comments on thread storage with a brief explanation of what it is
  as well as what the motivation is for using it.
- Add a comment by the declaration of ast_inet_ntoa() noting that this function
  is not reentrant, and the result of a previous call to the function is no
  longer valid after calling it again.
................
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48350 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-12-07 16:03:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" Response: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" Channel: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 11:31:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" Context: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" Exten: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" Reason: %d \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" Uniqueid: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-11 23:23:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" CallerIDNum: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 11:31:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" CallerIDName: %s \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-07 20:53:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										in - > idtext ,  ast_strlen_zero ( in - > idtext )  ?  " "  :  " \r \n " ,  res  ?  " Failure "  :  " Success " ,  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										chan  ?  chan - > name  :  requested_channel ,  in - > context ,  in - > exten ,  reason ,  
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 11:31:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										chan  ?  chan - > uniqueid  :  " <null> " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-21 10:31:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										S_OR ( in - > cid_num ,  " <unknown> " ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										S_OR ( in - > cid_name ,  " <unknown> " ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 11:31:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-09-14 22:15:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-02-02 02:54:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* Locked by ast_pbx_outgoing_exten or ast_pbx_outgoing_app */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( chan ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( chan ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_free ( in ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_originate [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Generates an outgoing call to a Extension/Context/Priority or \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   Application/Data \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Channel: Channel name to call \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Exten: Extension to use (requires 'Context' and 'Priority') \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Context: Context to use (requires 'Exten' and 'Priority') \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Priority: Priority to use (requires 'Exten' and 'Context') \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Application: Application to use \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Data: Data to use (requires 'Application') \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Timeout: How long to wait for call to be answered (in ms) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	CallerID: Caller ID to be set on the outgoing channel \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-05 21:12:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	Variable: Channel variable to set, multiple Variable: headers are allowed \n " 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	Account: Account code \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Async: Set to 'true' for fast origination \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_originate ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * exten  =  astman_get_header ( m ,  " Exten " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * context  =  astman_get_header ( m ,  " Context " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * priority  =  astman_get_header ( m ,  " Priority " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * timeout  =  astman_get_header ( m ,  " Timeout " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * callerid  =  astman_get_header ( m ,  " CallerID " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * account  =  astman_get_header ( m ,  " Account " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * app  =  astman_get_header ( m ,  " Application " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * appdata  =  astman_get_header ( m ,  " Data " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * async  =  astman_get_header ( m ,  " Async " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * id  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * codecs  =  astman_get_header ( m ,  " Codecs " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:24:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_variable  * vars  =  astman_get_variables ( m ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									char  * tech ,  * data ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * l  =  NULL ,  * n  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									int  pi  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  to  =  30000 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  reason  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  tmp [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-15 23:24:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  tmp2 [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  format  =  AST_FORMAT_SLINEAR ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									pthread_t  th ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-25 21:49:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Channel not specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( priority )  & &  ( sscanf ( priority ,  " %d " ,  & pi )  ! =  1 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ( pi  =  ast_findlabel_extension ( NULL ,  context ,  exten ,  priority ,  NULL ) )  <  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Invalid priority " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-12-27 19:13:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( timeout )  & &  ( sscanf ( timeout ,  " %d " ,  & to )  ! =  1 ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Invalid timeout " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-10 22:56:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_copy_string ( tmp ,  name ,  sizeof ( tmp ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									tech  =  tmp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									data  =  strchr ( tmp ,  ' / ' ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! data )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-15 18:25:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Invalid channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-03-28 23:52:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									* data + +  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-10 22:56:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_copy_string ( tmp2 ,  callerid ,  sizeof ( tmp2 ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-02 00:58:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_callerid_parse ( tmp2 ,  & n ,  & l ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( n )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( n ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											n  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( l )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_shrink_phone_number ( l ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( l ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											l  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( codecs ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										format  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_parse_allow_disallow ( NULL ,  & format ,  codecs ,  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-09-17 14:15:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_true ( async ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-23 02:41:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										struct  fast_originate_helper  * fast  =  ast_calloc ( 1 ,  sizeof ( * fast ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-09-17 14:15:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! fast )  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											res  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-09-17 14:15:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! ast_strlen_zero ( id ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-04-07 20:53:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												snprintf ( fast - > idtext ,  sizeof ( fast - > idtext ) ,  " ActionID: %s " ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-10 22:56:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_copy_string ( fast - > tech ,  tech ,  sizeof ( fast - > tech ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								   			ast_copy_string ( fast - > data ,  data ,  sizeof ( fast - > data ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_copy_string ( fast - > app ,  app ,  sizeof ( fast - > app ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_copy_string ( fast - > appdata ,  appdata ,  sizeof ( fast - > appdata ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-02 00:58:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( l ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-10 22:56:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_copy_string ( fast - > cid_num ,  l ,  sizeof ( fast - > cid_num ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-02 00:58:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( n ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-10 22:56:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_copy_string ( fast - > cid_name ,  n ,  sizeof ( fast - > cid_name ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											fast - > vars  =  vars ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-07-10 22:56:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_copy_string ( fast - > context ,  context ,  sizeof ( fast - > context ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_copy_string ( fast - > exten ,  exten ,  sizeof ( fast - > exten ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-02-11 18:31:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_copy_string ( fast - > account ,  account ,  sizeof ( fast - > account ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											fast - > format  =  format ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											fast - > timeout  =  to ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											fast - > priority  =  pi ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-24 18:30:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_pthread_create_detached ( & th ,  NULL ,  fast_originate ,  fast ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-13 22:50:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_free ( fast ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-09-17 14:15:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-01 23:52:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												res  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  if  ( ! ast_strlen_zero ( app ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-22 22:55:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* To run the System application (or anything else that goes to shell), you must have the additional System privilege */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ( s - > session - > writeperm  &  EVENT_FLAG_SYSTEM ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-22 22:55:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											& &  ( 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												strcasestr ( app ,  " system " )  = =  0  | |  /* System(rm -rf /)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												                                     TrySystem ( rm  - rf  / )        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												strcasestr ( app ,  " exec " )  | |         /* Exec(System(rm -rf /))
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												                                     TryExec ( System ( rm  - rf  / ) )  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												strcasestr ( app ,  " agi " )  | |          /* AGI(/bin/rm,-rf /)
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												                                     EAGI ( / bin / rm , - rf  / )        */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												strstr ( appdata ,  " SHELL " )  | |        /* NoOp(${SHELL(rm -rf /)})  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												strstr ( appdata ,  " EVAL " )            /* NoOp(${EVAL(${some_var_containing_SHELL})}) */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Originate with certain 'Application' arguments requires the additional System privilege, which you do not have. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										res  =  ast_pbx_outgoing_app ( tech ,  format ,  data ,  to ,  app ,  appdata ,  & reason ,  1 ,  l ,  n ,  vars ,  account ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-22 22:55:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-09 20:01:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( exten  & &  context  & &  pi ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-14 12:32:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											res  =  ast_pbx_outgoing_exten ( tech ,  format ,  data ,  to ,  context ,  exten ,  pi ,  & reason ,  1 ,  l ,  n ,  vars ,  account ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-03-09 20:01:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Originate with 'Exten' requires 'Context' and 'Priority' " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! res ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_ack ( s ,  m ,  " Originate successfully queued " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Originate failed " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-06-22 15:34:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Help text for manager command mailboxstatus
 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_mailboxstatus [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Checks a voicemail account for status. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Mailbox: Full mailbox ID <mailbox>@<vm-context> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional ActionID for message matching. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Returns number of messages. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Message: Mailbox Status \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Mailbox: <mailboxid> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Waiting: <count> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_mailboxstatus ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-02-24 06:00:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * mailbox  =  astman_get_header ( m ,  " Mailbox " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-09-10 15:11:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( mailbox ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Mailbox not specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-02-24 06:00:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2004-10-03 21:18:27 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ret  =  ast_app_has_voicemail ( mailbox ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Message: Mailbox Status \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											 " Mailbox: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											 " Waiting: %d \r \n \r \n " ,  mailbox ,  ret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 18:19:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_mailboxcount [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Checks a voicemail account for new messages. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Mailbox: Full mailbox ID <mailbox>@<vm-context> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionID: Optional ActionID for message matching. \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-09 21:22:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Returns number of urgent, new and old messages. \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	Message: Mailbox Message Count \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	Mailbox: <mailboxid> \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-09 21:22:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	UrgentMessages: <count> \n " 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" 	NewMessages: <count> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	OldMessages: <count> \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" \n " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_mailboxcount ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-21 20:05:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * mailbox  =  astman_get_header ( m ,  " Mailbox " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-09 21:22:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  newmsgs  =  0 ,  oldmsgs  =  0 ,  urgentmsgs  =  0 ; ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( mailbox ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Mailbox not specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-21 20:05:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-02 21:27:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_app_inboxcount2 ( mailbox ,  & urgentmsgs ,  & newmsgs ,  & oldmsgs ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,    " Message: Mailbox Message Count \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											   " Mailbox: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-09 21:22:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											   " UrgMessages: %d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											   " NewMessages: %d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											   " OldMessages: %d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											   " \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-09 21:22:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											   mailbox ,  urgentmsgs ,  newmsgs ,  oldmsgs ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-21 20:05:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_extensionstate [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Report the extension state for given extension. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   If the extension has a hint, will use devicestate to check \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   the status of the device connected to the extension. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Exten: Extension to check state on \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Context: Context for extension \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	ActionId: Optional ID for this transaction \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Will return an  \" Extension Status \"  message. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" The response will include the hint for the extension and the status. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_extensionstate ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 18:19:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * exten  =  astman_get_header ( m ,  " Exten " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * context  =  astman_get_header ( m ,  " Context " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-07 02:04:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  hint [ 256 ]  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 18:19:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  status ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( exten ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Extension not specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 18:19:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 18:54:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( context ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 18:19:51 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										context  =  " default " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									status  =  ast_extension_state ( NULL ,  context ,  exten ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-01 01:53:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_get_hint ( hint ,  sizeof ( hint )  -  1 ,  NULL ,  0 ,  NULL ,  context ,  exten ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 14:21:15 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_start_ack ( s ,  m ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,    " Message: Extension Status \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											   " Exten: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											   " Context: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											   " Hint: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											   " Status: %d \r \n \r \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											   exten ,  context ,  hint ,  status ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-02-24 06:00:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_timeout [ ]  = 
							 
						 
					
						
							
								
									
										
										
										
											2005-02-26 07:15:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								" Description: Hangup a channel after a certain time. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Channel: Channel name to hangup \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 	*Timeout: Maximum duration of the call (sec) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Acknowledges set time with 'Timeout Set' message \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_timeout ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-09 21:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * name  =  astman_get_header ( m ,  " Channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-01 23:06:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									double  timeout  =  atof ( astman_get_header ( m ,  " Timeout " ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  timeval  when  =  {  timeout ,  0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( name ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No channel specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-09 21:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-01 23:06:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! timeout  | |  timeout  <  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No timeout specified " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-09 21:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2005-06-06 02:29:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									c  =  ast_get_channel_by_name_locked ( name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-09 21:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! c )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " No such channel " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-09 21:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-01 23:06:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									when . tv_usec  =  ( timeout  -  when . tv_sec )  *  1000000.0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_channel_setwhentohangup_tv ( c ,  when ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-29 14:50:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_send_ack ( s ,  m ,  " Timeout Set " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-06-09 21:40:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-18 22:14:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 10:23:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Send  any  applicable  events  to  the  client  listening  on  this  socket . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Wait  only  for  a  finite  time  on  each  event ,  and  drop  all  events  whether 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  they  are  successfully  sent  or  not . 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-18 22:14:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  process_events ( struct  mansession  * s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  ret  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 11:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( s - > session - > f  ! =  NULL )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 11:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										struct  eventqent  * eqe ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 11:24:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										while  (  ( eqe  =  NEW_EVENT ( s ) )  )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ref_event ( eqe ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! ret  & &  s - > session - > authenticated  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											    ( s - > session - > readperm  &  eqe - > category )  = =  eqe - > category  & & 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											    ( s - > session - > send_events  &  eqe - > category )  = =  eqe - > category )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 10:23:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  ( send_string ( s ,  eqe - > eventdata )  <  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													ret  =  - 1 ; 	/* don't send more */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											s - > session - > last_ev  =  unref_event ( s - > session - > last_ev ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  ret ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-05-20 13:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_userevent [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Send an event to manager sessions. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are required) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *UserEvent: EventStringToSend \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        Header1: Content1 \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        HeaderN: ContentN \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  action_userevent ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-20 13:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * event  =  astman_get_header ( m ,  " UserEvent " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-19 20:10:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * body  =  ast_str_thread_get ( & userevent_buf ,  16 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  x ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-10 14:42:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_str_reset ( body ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-05-20 13:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  m - > hdrcount ;  x + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( strncasecmp ( " UserEvent: " ,  m - > headers [ x ] ,  strlen ( " UserEvent: " ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-01-19 20:10:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_str_append ( & body ,  0 ,  " %s \r \n " ,  m - > headers [ x ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-20 13:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-01-19 20:10:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									manager_event ( EVENT_FLAG_USER ,  " UserEvent " ,  " UserEvent: %s \r \n %s " ,  event ,  body - > str ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-20 13:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:44:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_coresettings [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Query for Core PBX settings. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are optional) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *ActionID: ActionID of this transaction \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*! \brief Show PBX core settings information */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_coresettings ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * actionid  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  idText [ 150 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:44:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 19:48:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( actionid ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( idText ,  sizeof ( idText ) ,  " ActionID: %s \r \n " ,  actionid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										idText [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:44:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Response: Success \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" AMIversion: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" AsteriskVersion: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" SystemName: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreMaxCalls: %d \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreMaxLoadAvg: %f \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreRunUser: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreRunGroup: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreMaxFilehandles: %d \r \n "  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreRealTimeEnabled: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreCDRenabled: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreHTTPenabled: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" \r \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											idText , 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:44:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											AMI_VERSION , 
							 
						 
					
						
							
								
									
										
										
											
												Now that the version.h file was getting properly regenerated every time the svn
revision changed, every module that used the version was getting rebuilt after
every svn update.  This severly annoyed me pretty quickly, so I have improved
the situation.
Now, instead of generating version.h, main/version.c is generated.  version.c
includes the version information, as well as a couple of API calls for modules
to retrieve the version.  So now, only version.c will get rebuilt, and the main
asterisk binary relinked, which is must faster than rebuilding http.c, manager.c,
asterisk.c, relinking the asterisk binary, chan_sip.c, func_version.c, res_agi ...
The only minor change in behavior here is that the version information reported by
chan_sip, for example, is the version of the Asterisk core, and not necessarily the
Asterisk version that the chan_sip module came from.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@96717 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2008-01-05 22:09:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_get_version ( ) ,  
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:44:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_config_AST_SYSTEM_NAME , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											option_maxcalls , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											option_maxload , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_config_AST_RUN_USER , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_config_AST_RUN_GROUP , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											option_maxfiles , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_realtime_enabled ( )  ?  " Yes "  :  " No " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											check_cdr_enabled ( )  ?  " Yes "  :  " No " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											check_webmanager_enabled ( )  ?  " Yes "  :  " No " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:47:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_corestatus [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Query for Core PBX status. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are optional) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *ActionID: ActionID of this transaction \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*! \brief Show PBX core status information */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_corestatus ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * actionid  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  idText [ 150 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  startuptime [ 150 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  reloadtime [ 150 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-18 19:47:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_tm  tm ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:47:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 19:48:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( actionid ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( idText ,  sizeof ( idText ) ,  " ActionID: %s \r \n " ,  actionid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										idText [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 19:48:52 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-06-14 22:09:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_localtime ( & ast_startuptime ,  & tm ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-18 19:47:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_strftime ( startuptime ,  sizeof ( startuptime ) ,  " %H:%M:%S " ,  & tm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-14 22:09:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_localtime ( & ast_lastreloadtime ,  & tm ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-18 19:47:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_strftime ( reloadtime ,  sizeof ( reloadtime ) ,  " %H:%M:%S " ,  & tm ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:47:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Response: Success \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" %s " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreStartupTime: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreReloadTime: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CoreCurrentCalls: %d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:47:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											idText , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											startuptime , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											reloadtime , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_active_channels ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-09-22 14:03:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_reload [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Send a reload event. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: (Names marked with * are optional) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *ActionID: ActionID of this transaction \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"        *Module: Name of the module to reload \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*! \brief Send a reload event */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_reload ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * module  =  astman_get_header ( m ,  " Module " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res  =  ast_module_reload ( S_OR ( module ,  NULL ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( res  = =  2 ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_ack ( s ,  m ,  " Module Reloaded " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-22 14:03:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  s  = =  0  ?  " No such module "  :  " Module does not support reload " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-04 13:44:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_coreshowchannels [ ]  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: List currently defined channels and some information \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"              about them. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables: \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"           ActionID: Optional Action id for message matching. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/*! \brief  Manager command "CoreShowChannels" - List currently defined channels 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *           and  some  information  about  them .  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  action_coreshowchannels ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * actionid  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  actionidtext [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_channel  * c  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  numchans  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  duration ,  durh ,  durm ,  durs ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( actionid ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( actionidtext ,  sizeof ( actionidtext ) ,  " ActionID: %s \r \n " ,  actionid ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										actionidtext [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_send_listack ( s ,  m ,  " Channels will follow " ,  " start " ) ; 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									while  ( ( c  =  ast_channel_walk_locked ( c ) )  ! =  NULL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										struct  ast_channel  * bc  =  ast_bridged_channel ( c ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										char  durbuf [ 10 ]  =  " " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( c - > cdr  & &  ! ast_tvzero ( c - > cdr - > start ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											duration  =  ( int ) ( ast_tvdiff_ms ( ast_tvnow ( ) ,  c - > cdr - > start )  /  1000 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											durh  =  duration  /  3600 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											durm  =  ( duration  %  3600 )  /  60 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											durs  =  duration  %  60 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											snprintf ( durbuf ,  sizeof ( durbuf ) ,  " %02d:%02d:%02d " ,  durh ,  durm ,  durs ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_append ( s , 
							 
						 
					
						
							
								
									
										
										
										
											2008-11-21 19:42:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Event: CoreShowChannel \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Channel: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" UniqueID: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Context: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Extension: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Priority: %d \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" ChannelState: %d \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" ChannelStateDesc: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Application: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" ApplicationData: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" CallerIDnum: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" Duration: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" AccountCode: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" BridgedChannel: %s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											" BridgedUniqueID: %s \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-09 03:39:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" \r \n " ,  c - > name ,  c - > uniqueid ,  c - > context ,  c - > exten ,  c - > priority ,  c - > _state ,  ast_state2str ( c - > _state ) , 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											c - > appl  ?  c - > appl  :  " " ,  c - > data  ?  S_OR ( c - > data ,  " " ) :  " " , 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-09 03:39:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											S_OR ( c - > cid . cid_num ,  " " ) ,  durbuf ,  S_OR ( c - > accountcode ,  " " ) ,  bc  ?  bc - > name  :  " " ,  bc  ?  bc - > uniqueid  :  " " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_channel_unlock ( c ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										numchans + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									astman_append ( s , 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										" Event: CoreShowChannelsComplete \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" EventList: Complete \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" ListItems: %d \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" %s " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										" \r \n " ,  numchans ,  actionidtext ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  char  mandescr_modulecheck [ ]  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Checks if Asterisk module is loaded \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables:  \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   ActionID: <id>          Action ID for this transaction. Will be returned. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   Module: <name>          Asterisk module name (not including extension) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Will return Success/Failure \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" For success returns, the module revision number is included. \n " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/* Manager function to check if module is loaded */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  manager_modulecheck ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * module  =  astman_get_header ( m ,  " Module " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * id  =  astman_get_header ( m ,  " ActionID " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:24:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  idText [ 256 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-10 22:02:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# if !defined(LOW_MEMORY) 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * version ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-10 22:02:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# endif 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:24:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  filename [ PATH_MAX ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * cut ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:24:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_copy_string ( filename ,  module ,  sizeof ( filename ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ( cut  =  strchr ( filename ,  ' . ' ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										* cut  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										cut  =  filename  +  strlen ( filename ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-13 21:47:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									snprintf ( cut ,  ( sizeof ( filename )  -  strlen ( filename ) )  -  1 ,  " .so " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_log ( LOG_DEBUG ,  " **** ModuleCheck .so file %s \n " ,  filename ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									res  =  ast_module_check ( filename ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! res )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Module not loaded " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-13 21:47:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									snprintf ( cut ,  ( sizeof ( filename )  -  strlen ( filename ) )  -  1 ,  " .c " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_log ( LOG_DEBUG ,  " **** ModuleCheck .c file %s \n " ,  filename ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-10 22:02:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# if !defined(LOW_MEMORY) 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									version  =  ast_file_version_find ( filename ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-10 22:02:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# endif 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! ast_strlen_zero ( id ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										snprintf ( idText ,  sizeof ( idText ) ,  " ActionID: %s \r \n " ,  id ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										idText [ 0 ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Response: Success \r \n %s " ,  idText ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-10 22:02:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# if !defined(LOW_MEMORY) 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( s ,  " Version: %s \r \n \r \n " ,  version  ?  version  :  " " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-10 22:02:32 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# endif 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  char  mandescr_moduleload [ ]  =  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Description: Loads, unloads or reloads an Asterisk module in a running system. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" Variables:  \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   ActionID: <id>          Action ID for this transaction. Will be returned. \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   Module: <name>          Asterisk module name (including .so extension) \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"                           or subsystem identifier: \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								" 				cdr, enum, dnsmgr, extconfig, manager, rtp, http \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"   LoadType: load | unload | reload \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"                           The operation to be done on module \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								"  If no module is specified for a reload loadtype, all modules are reloaded " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  manager_moduleload ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * module  =  astman_get_header ( m ,  " Module " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * loadtype  =  astman_get_header ( m ,  " LoadType " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! loadtype  | |  strlen ( loadtype )  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Incomplete ModuleLoad action. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ( ! module  | |  strlen ( module )  = =  0 )  & &  strcasecmp ( loadtype ,  " reload " )  ! =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Need module name " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! strcasecmp ( loadtype ,  " load " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										res  =  ast_load_resource ( module ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( res ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Could not load module. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_ack ( s ,  m ,  " Module loaded. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  if  ( ! strcasecmp ( loadtype ,  " unload " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										res  =  ast_unload_resource ( module ,  AST_FORCE_SOFT ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( res ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Could not unload module. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_ack ( s ,  m ,  " Module unloaded. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  if  ( ! strcasecmp ( loadtype ,  " reload " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( module  ! =  NULL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											res  =  ast_module_reload ( module ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( res  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												astman_send_error ( s ,  m ,  " No such module. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else  if  ( res  = =  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												astman_send_error ( s ,  m ,  " Module does not support reload action. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												astman_send_ack ( s ,  m ,  " Module reloaded. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_module_reload ( NULL ) ; 	/* Reload all modules */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											astman_send_ack ( s ,  m ,  " All modules reloaded " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Incomplete ModuleLoad action. " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 10:27:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Done  with  the  action  handlers  here ,  we  start  with  the  code  in  charge 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  of  accepting  connections  and  serving  them . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  accept_thread ( )  forks  a  new  thread  for  each  connection ,  session_do ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  which  in  turn  calls  get_input ( )  repeatedly  until  a  full  message  has 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  been  accumulated ,  and  then  invokes  process_message ( )  to  pass  it  to 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  the  appropriate  handler . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 14:00:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Process  an  AMI  message ,  performing  desired  action . 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 14:00:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Return  0  on  success ,  - 1  on  error  that  require  the  session  to  be  destroyed . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  process_message ( struct  mansession  * s ,  const  struct  message  * m ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2004-07-14 07:44:19 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  action [ 80 ]  =  " " ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  ret  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * tmp ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * user  =  astman_get_header ( m ,  " Username " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_copy_string ( action ,  __astman_get_header ( m ,  " Action " ,  GET_HEADER_SKIP_EMPTY ) ,  sizeof ( action ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_debug ( 1 ,  " Manager received command '%s' \n " ,  action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-05-26 19:30:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ast_strlen_zero ( action ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-09-08 16:44:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Missing action in request " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 12:55:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! s - > session - > authenticated  & &  strcasecmp ( action ,  " Login " )  & &  strcasecmp ( action ,  " Logoff " )  & &  strcasecmp ( action ,  " Challenge " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-22 05:49:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  " Permission denied " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-22 05:49:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! allowmultiplelogin  & &  ! s - > session - > authenticated  & &  user  & & 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										( ! strcasecmp ( action ,  " Login " )  | |  ! strcasecmp ( action ,  " Challenge " ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( check_manager_session_inuse ( user ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											sleep ( 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Login Already In Use " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & actions ,  tmp ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-23 21:38:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( strcasecmp ( action ,  tmp - > action ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( s - > session - > writeperm  &  tmp - > authority  | |  tmp - > authority  = =  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-16 00:10:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ret  =  tmp - > func ( s ,  m ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-23 21:38:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											astman_send_error ( s ,  m ,  " Permission denied " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										break ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-23 22:09:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! tmp )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:24:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										char  buf [ 512 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( buf ,  sizeof ( buf ) ,  " Invalid/unknown command: %s. Use Action: ListCommands to show available commands. " ,  action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										astman_send_error ( s ,  m ,  buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-23 22:09:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ret ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ret ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-18 22:14:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* Once done with our message, deliver any pending events */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  process_events ( s ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Read  one  full  line  ( including  crlf )  from  the  manager  socket . 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-24 19:49:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ note  \ verbatim 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ r \ n  is  the  only  valid  terminator  for  the  line . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( Note  that ,  later ,  ' \0 '  will  be  considered  as  the  end - of - line  marker , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  so  everything  between  the  ' \0 '  and  the  ' \ r \ n '  will  not  be  used ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Also  note  that  we  assume  output  to  have  at  least  " maxlen "  space . 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-24 19:49:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ endverbatim 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								static  int  get_input ( struct  mansession  * s ,  char  * output ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  res ,  x ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  maxlen  =  sizeof ( s - > session - > inbuf )  -  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * src  =  s - > session - > inbuf ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 *  Look  for  \ r \ n  within  the  buffer .  If  found ,  copy  to  the  output 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 *  buffer  and  return ,  trimming  the  \ r \ n  ( not  used  afterwards ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ;  x  <  s - > session - > inlen ;  x + + )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										int  cr ; 	/* set if we have \r */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( src [ x ]  = =  ' \r '  & &  x + 1  <  s - > session - > inlen  & &  src [ x + 1 ]  = =  ' \n ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											cr  =  2 ; 	/* Found. Update length to include \r\n */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else  if  ( src [ x ]  = =  ' \n ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											cr  =  1 ; 	/* also accept \n only */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										memmove ( output ,  src ,  x ) ; 	/*... but trim \r\n */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										output [ x ]  =  ' \0 ' ; 		/* terminate the string */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										x  + =  cr ; 			/* number of bytes used */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										s - > session - > inlen  - =  x ; 			/* remaining size */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										memmove ( src ,  src  +  x ,  s - > session - > inlen ) ;  /* remove used bytes */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( s - > session - > inlen  > =  maxlen )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* no crlf found, and buffer full - sorry, too long for us */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_log ( LOG_WARNING ,  " Dumping long line with no return from %s: %s \n " ,  ast_inet_ntoa ( s - > session - > sin . sin_addr ) ,  src ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										s - > session - > inlen  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									res  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									while  ( res  = =  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* XXX do we really need this locking ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( s - > session - > pending_event )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											s - > session - > pending_event  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 17:36:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										s - > session - > waiting_thread  =  pthread_self ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										res  =  ast_wait_for_input ( s - > session - > fd ,  - 1 ) ; 	/* return 0 on timeout ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										s - > session - > waiting_thread  =  AST_PTHREADT_NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( res  <  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-18 22:14:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* If we get a signal from some other thread (typically because
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  there  are  new  events  queued ) ,  return  0  to  notify  the  caller . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-18 21:51:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( errno  = =  EINTR  | |  errno  = =  EAGAIN ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_log ( LOG_WARNING ,  " poll() returned error: %s \n " ,  strerror ( errno ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_lock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									res  =  fread ( src  +  s - > session - > inlen ,  1 ,  maxlen  -  s - > session - > inlen ,  s - > session - > f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( res  <  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										res  =  - 1 ; 	/* error return */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										s - > session - > inlen  + =  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										src [ s - > session - > inlen ]  =  ' \0 ' ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										res  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & s - > session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-26 12:47:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  res ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  do_message ( struct  mansession  * s ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  message  m  =  {  0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  header_buf [ sizeof ( s - > session - > inbuf ) ]  =  {  ' \0 '  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( ; ; )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-15 16:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* Check if any events are pending and do them if needed */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( process_events ( s ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										res  =  get_input ( s ,  header_buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-12 16:47:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( res  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( res  >  0 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ast_strlen_zero ( header_buf ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												return  process_message ( s ,  & m )  ?  - 1  :  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else  if  ( m . hdrcount  <  ( AST_MAX_MANHEADERS  -  1 ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												m . headers [ m . hdrcount + + ]  =  ast_strdupa ( header_buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											return  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief The body of the individual manager session.
 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-18 22:14:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Call  get_input ( )  to  read  one  line  at  a  time 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( or  be  woken  up  on  new  events ) ,  collect  the  lines  in  a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  message  until  found  an  empty  line ,  and  execute  the  request . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  In  any  case ,  deliver  events  asynchronously  through  process_events ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( called  from  here  if  no  line  is  available ,  or  at  the  end  of 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  process_message ( ) .  ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								static  void  * session_do ( void  * data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-12 22:13:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_tcptls_session_instance  * ser  =  data ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session  =  ast_calloc ( 1 ,  sizeof ( * session ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  mansession  s  =  { . session  =  NULL ,  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  flags ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  res ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( session  = =  NULL ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										goto  done ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									session - > writetimeout  =  100 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									session - > waiting_thread  =  AST_PTHREADT_NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									flags  =  fcntl ( ser - > fd ,  F_GETFL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! block_sockets )  /* make sure socket is non-blocking */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										flags  | =  O_NONBLOCK ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										flags  & =  ~ O_NONBLOCK ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									fcntl ( ser - > fd ,  F_SETFL ,  flags ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_init ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									session - > send_events  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* Hook to the tail of the event queue */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									session - > last_ev  =  grab_last ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* these fields duplicate those in the 'ser' structure */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									session - > fd  =  ser - > fd ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									session - > f  =  ser - > f ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									session - > sin  =  ser - > remote_address ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									s . session  =  session ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_HEAD_INIT_NOLOCK ( & session - > datastores ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_INSERT_HEAD ( & sessions ,  session ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 20:59:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_atomic_fetchadd_int ( & num_sessions ,  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									astman_append ( & s ,  " Asterisk Call Manager/%s \r \n " ,  AMI_VERSION ) ; 	/* welcome prompt */ 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									for  ( ; ; )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ( res  =  do_message ( & s ) )  <  0 ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 16:52:13 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* session is over, explain why and terminate */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( session - > authenticated )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( manager_displayconnects ( session ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_verb ( 2 ,  " Manager '%s' logged off from %s \n " ,  session - > username ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_log ( LOG_EVENT ,  " Manager '%s' logged off from %s \n " ,  session - > username ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( displayconnects ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_verb ( 2 ,  " Connect attempt from '%s' unable to authenticate \n " ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_log ( LOG_EVENT ,  " Failed attempt from %s \n " ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-26 20:49:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-27 01:03:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* It is possible under certain circumstances for this session thread
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   to  complete  its  work  and  exit  * before *  the  thread  that  created  it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   has  finished  executing  the  ast_pthread_create_background ( )  function . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   If  this  occurs ,  some  versions  of  glibc  appear  to  act  in  a  buggy 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   fashion  and  attempt  to  write  data  into  memory  that  it  thinks  belongs 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   to  the  thread  but  is  in  fact  not  owned  by  the  thread  ( or  may  have 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   been  freed  completely ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   Causing  this  thread  to  yield  to  other  threads  at  least  one  time 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									   appears  to  work  around  this  bug . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									*/ 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-26 20:49:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									usleep ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									destroy_session ( session ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								done : 
							 
						 
					
						
							
								
									
										
										
										
											2008-06-17 21:46:57 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ao2_ref ( ser ,  - 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ser  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief remove at most n_max stale session from the list. */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  purge_sessions ( int  n_max ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									time_t  now  =  time ( NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE_SAFE_BEGIN ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( session - > sessiontimeout  & &  ( now  >  session - > sessiontimeout )  & &  ! session - > inuse )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											AST_LIST_REMOVE_CURRENT ( list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_atomic_fetchadd_int ( & num_sessions ,  - 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( session - > authenticated  & &  ( VERBOSITY_ATLEAST ( 2 ) )  & &  manager_displayconnects ( session ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-26 15:49:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_verb ( 2 ,  " HTTP Manager '%s' timed out from %s \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													session - > username ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											free_session ( session ) ; 	/* XXX outside ? */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( - - n_max  < =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE_SAFE_END ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 11:20:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  events  are  appended  to  a  queue  from  where  they 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  can  be  dispatched  to  clients . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  append_event ( const  char  * str ,  int  category ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-28 23:10:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 17:26:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  eventqent  * tmp  =  ast_malloc ( sizeof ( * tmp )  +  strlen ( str ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									static  int  seq ; 	/* sequence number */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-23 02:41:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! tmp ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 17:26:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* need to init all fields, because ast_malloc() does not */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									tmp - > usecount  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-23 02:41:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									tmp - > category  =  category ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									tmp - > seq  =  ast_atomic_fetchadd_int ( & seq ,  1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_NEXT ( tmp ,  eq_next )  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-23 02:41:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									strcpy ( tmp - > eventdata ,  str ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & all_events ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_INSERT_TAIL ( & all_events ,  tmp ,  eq_next ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & all_events ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-07-23 02:41:02 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-28 23:10:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/* XXX see if can be moved inside the function */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								AST_THREADSTORAGE ( manager_event_buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define MANAGER_EVENT_BUF_INITSIZE   256 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-10-26 13:03:17 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief  manager_event: Send AMI event to client */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  __manager_event ( int  category ,  const  char  * event , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * file ,  int  line ,  const  char  * func ,  const  char  * fmt ,  . . . ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-06 17:05:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_custom_hook  * hook ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * auth  =  ast_str_alloca ( 80 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  char  * cat_str ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									va_list  ap ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  timeval  now ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * buf ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* Abort if there aren't any manager sessions */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! num_sessions ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( buf  =  ast_str_thread_get ( & manager_event_buf ,  MANAGER_EVENT_BUF_INITSIZE ) ) ) 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
  ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
  lives in threadstorage.h, with one function being implemented in utils.c.
  This new API includes generic thread storage as well as special functions
  for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
  4096 characters as the workspace for building the manager event, use a thread
  local dynamic string.  Now there is no length limitation on the length of the
  body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
  - Instead of using a static char buffer and a lock to make sure only one
    thread can be using ast_verbose() at a time, use a thread local dynamic
    string as the workspace for preparing the verbose message. Instead of
    locking around the entire function, the only locking done now is when the
    message has been built and is being deliviered to the list of registered
    verbose message handlers.
  - This function was doing a strdup() on every message passed to it and
    keeping a queue of the last 200 messages in memory. This has been
    completely removed. The only place this was used was that if there were
    any messages in the verbose queue when a verbose handler was registered,
    all of the messages in the queue would be fed to it.  So, I just made sure
    that the console verbose handler and the network verbose handler (for
    remote asterisk consoles) were registered before any verbose messages.
    pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
    startup, but I didn't feel the performance hit of this message queue was
    worth saving the initial verbose output for these very rarely used modules.
  - I have removed the last three arguments to the verbose handlers, leaving
    only the string itself because they aren't needed anymore. For example,
    ast_verbose had some logic for telling the verbose handler to add
    a newline if the buffer was completely full. Now that the buffer can grow
    as needed, this doesn't matter anymore.
  - remove unused function, ast_verbose_dmesg() which was to dispatch the
    message queue
  - Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
  for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
  system) allocated on the stack.  The dynamic string in this case is limited
  to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-08-08 06:32:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									cat_str  =  authority_to_str ( category ,  & auth ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_str_set ( & buf ,  0 , 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
  ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
  lives in threadstorage.h, with one function being implemented in utils.c.
  This new API includes generic thread storage as well as special functions
  for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
  4096 characters as the workspace for building the manager event, use a thread
  local dynamic string.  Now there is no length limitation on the length of the
  body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
  - Instead of using a static char buffer and a lock to make sure only one
    thread can be using ast_verbose() at a time, use a thread local dynamic
    string as the workspace for preparing the verbose message. Instead of
    locking around the entire function, the only locking done now is when the
    message has been built and is being deliviered to the list of registered
    verbose message handlers.
  - This function was doing a strdup() on every message passed to it and
    keeping a queue of the last 200 messages in memory. This has been
    completely removed. The only place this was used was that if there were
    any messages in the verbose queue when a verbose handler was registered,
    all of the messages in the queue would be fed to it.  So, I just made sure
    that the console verbose handler and the network verbose handler (for
    remote asterisk consoles) were registered before any verbose messages.
    pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
    startup, but I didn't feel the performance hit of this message queue was
    worth saving the initial verbose output for these very rarely used modules.
  - I have removed the last three arguments to the verbose handlers, leaving
    only the string itself because they aren't needed anymore. For example,
    ast_verbose had some logic for telling the verbose handler to add
    a newline if the buffer was completely full. Now that the buffer can grow
    as needed, this doesn't matter anymore.
  - remove unused function, ast_verbose_dmesg() which was to dispatch the
    message queue
  - Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
  for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
  system) allocated on the stack.  The dynamic string in this case is limited
  to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-08-08 06:32:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" Event: %s \r \n Privilege: %s \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-18 11:28:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											 event ,  cat_str ) ; 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
  ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
  lives in threadstorage.h, with one function being implemented in utils.c.
  This new API includes generic thread storage as well as special functions
  for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
  4096 characters as the workspace for building the manager event, use a thread
  local dynamic string.  Now there is no length limitation on the length of the
  body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
  - Instead of using a static char buffer and a lock to make sure only one
    thread can be using ast_verbose() at a time, use a thread local dynamic
    string as the workspace for preparing the verbose message. Instead of
    locking around the entire function, the only locking done now is when the
    message has been built and is being deliviered to the list of registered
    verbose message handlers.
  - This function was doing a strdup() on every message passed to it and
    keeping a queue of the last 200 messages in memory. This has been
    completely removed. The only place this was used was that if there were
    any messages in the verbose queue when a verbose handler was registered,
    all of the messages in the queue would be fed to it.  So, I just made sure
    that the console verbose handler and the network verbose handler (for
    remote asterisk consoles) were registered before any verbose messages.
    pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
    startup, but I didn't feel the performance hit of this message queue was
    worth saving the initial verbose output for these very rarely used modules.
  - I have removed the last three arguments to the verbose handlers, leaving
    only the string itself because they aren't needed anymore. For example,
    ast_verbose had some logic for telling the verbose handler to add
    a newline if the buffer was completely full. Now that the buffer can grow
    as needed, this doesn't matter anymore.
  - remove unused function, ast_verbose_dmesg() which was to dispatch the
    message queue
  - Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
  for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
  system) allocated on the stack.  The dynamic string in this case is limited
  to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-08-08 06:32:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( timestampevents )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										now  =  ast_tvnow ( ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & buf ,  0 , 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
  ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
  lives in threadstorage.h, with one function being implemented in utils.c.
  This new API includes generic thread storage as well as special functions
  for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
  4096 characters as the workspace for building the manager event, use a thread
  local dynamic string.  Now there is no length limitation on the length of the
  body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
  - Instead of using a static char buffer and a lock to make sure only one
    thread can be using ast_verbose() at a time, use a thread local dynamic
    string as the workspace for preparing the verbose message. Instead of
    locking around the entire function, the only locking done now is when the
    message has been built and is being deliviered to the list of registered
    verbose message handlers.
  - This function was doing a strdup() on every message passed to it and
    keeping a queue of the last 200 messages in memory. This has been
    completely removed. The only place this was used was that if there were
    any messages in the verbose queue when a verbose handler was registered,
    all of the messages in the queue would be fed to it.  So, I just made sure
    that the console verbose handler and the network verbose handler (for
    remote asterisk consoles) were registered before any verbose messages.
    pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
    startup, but I didn't feel the performance hit of this message queue was
    worth saving the initial verbose output for these very rarely used modules.
  - I have removed the last three arguments to the verbose handlers, leaving
    only the string itself because they aren't needed anymore. For example,
    ast_verbose had some logic for telling the verbose handler to add
    a newline if the buffer was completely full. Now that the buffer can grow
    as needed, this doesn't matter anymore.
  - remove unused function, ast_verbose_dmesg() which was to dispatch the
    message queue
  - Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
  for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
  system) allocated on the stack.  The dynamic string in this case is limited
  to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-08-08 06:32:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												" Timestamp: %ld.%06lu \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-15 10:56:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												 ( long ) now . tv_sec ,  ( unsigned  long )  now . tv_usec ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( manager_debug )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										static  int  seq ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & buf ,  0 , 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												" SequenceNumber: %d \r \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												 ast_atomic_fetchadd_int ( & seq ,  1 ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & buf ,  0 , 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-03 18:53:26 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												" File: %s \r \n Line: %d \r \n Func: %s \r \n " ,  file ,  line ,  func ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
											 
										 
										
											
												Merge team/russell/ast_verbose_threadstorage
- instead of defining a free() wrapper in a bunch of files, define it as
  ast_free() in utils.h and remove the copies from all the files.
- centralize and abstract the code used for doing thread storage. The code
  lives in threadstorage.h, with one function being implemented in utils.c.
  This new API includes generic thread storage as well as special functions
  for handling thread local dynamic length string buffers.
- update ast_inet_ntoa() to use the new threadstorage API
- update ast_state2str() to use the new threadstorage API
- update ast_cli() to use the new threadstorage API
- Modify manager_event() to use thread storage. Instead of using a buffer of
  4096 characters as the workspace for building the manager event, use a thread
  local dynamic string.  Now there is no length limitation on the length of the
  body of a manager event.
- Significantly simplify the handling of ast_verbose() ...
  - Instead of using a static char buffer and a lock to make sure only one
    thread can be using ast_verbose() at a time, use a thread local dynamic
    string as the workspace for preparing the verbose message. Instead of
    locking around the entire function, the only locking done now is when the
    message has been built and is being deliviered to the list of registered
    verbose message handlers.
  - This function was doing a strdup() on every message passed to it and
    keeping a queue of the last 200 messages in memory. This has been
    completely removed. The only place this was used was that if there were
    any messages in the verbose queue when a verbose handler was registered,
    all of the messages in the queue would be fed to it.  So, I just made sure
    that the console verbose handler and the network verbose handler (for
    remote asterisk consoles) were registered before any verbose messages.
    pbx_gtkconsole and pbx_kdeconsole will now lose a few verbose messages at
    startup, but I didn't feel the performance hit of this message queue was
    worth saving the initial verbose output for these very rarely used modules.
  - I have removed the last three arguments to the verbose handlers, leaving
    only the string itself because they aren't needed anymore. For example,
    ast_verbose had some logic for telling the verbose handler to add
    a newline if the buffer was completely full. Now that the buffer can grow
    as needed, this doesn't matter anymore.
  - remove unused function, ast_verbose_dmesg() which was to dispatch the
    message queue
  - Convert the list of verbose handlers to use the linked list macros.
- add missing newline characters to a few ast_verbose() calls
- convert the list of log channels to use the linked list macros in logger.c
- fix close_logger() to close all of the files it opened for logging
- update ast_log() to use a thread local dynamic string for its workspace
  for preparing log messages instead of a buffer of size BUFSIZ (8kB on my
  system) allocated on the stack.  The dynamic string in this case is limited
  to only growing to a maximum size of BUFSIZ.
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@39272 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											 
										 
										
											2006-08-08 06:32:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									va_start ( ap ,  fmt ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_str_append_va ( & buf ,  0 ,  fmt ,  ap ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									va_end ( ap ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-15 23:10:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_str_append ( & buf ,  0 ,  " \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-12 13:04:03 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									append_event ( buf - > str ,  category ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-20 11:24:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* Wake up any sleeping sessions */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-24 17:14:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( session - > waiting_thread  ! =  AST_PTHREADT_NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											pthread_kill ( session - > waiting_thread ,  SIGURG ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 17:36:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											/* We have an event to process, but the mansession is
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											 *  not  waiting  for  it .  We  still  need  to  indicate  that  there 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											 *  is  an  event  waiting  so  that  get_input  processes  the  pending 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											 *  event  instead  of  polling . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											session - > pending_event  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-30 23:52:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-06 17:05:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_RDLOCK ( & manager_hooks ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-23 23:05:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & manager_hooks ,  hook ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										hook - > helper ( category ,  event ,  buf - > str ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-11-06 17:05:04 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & manager_hooks ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  support  functions  to  register / unregister  AMI  action  handlers , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  ast_manager_unregister ( char  * action ) 
							 
						 
					
						
							
								
									
										
										
										
											2005-09-28 23:10:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_WRLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE_SAFE_BEGIN ( & actions ,  cur ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( action ,  cur - > action ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											AST_RWLIST_REMOVE_CURRENT ( list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_free ( cur ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-26 15:49:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_verb ( 2 ,  " Manager unregistered action %s \n " ,  action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE_SAFE_END ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 23:32:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  manager_state_cb ( char  * context ,  char  * exten ,  int  state ,  void  * data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* Notify managers of change */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 23:24:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  hint [ 512 ] ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-09 19:05:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_get_hint ( hint ,  sizeof ( hint ) ,  NULL ,  0 ,  NULL ,  context ,  exten ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									manager_event ( EVENT_FLAG_CALL ,  " ExtensionStatus " ,  " Exten: %s \r \n Context: %s \r \n Hint: %s \r \n Status: %d \r \n " ,  exten ,  context ,  hint ,  state ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 23:32:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  ast_manager_register_struct ( struct  manager_action  * act ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * cur ,  * prev  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_WRLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE ( & actions ,  cur ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										int  ret  =  strcasecmp ( cur - > action ,  act - > action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ret  = =  0 )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_log ( LOG_WARNING ,  " Manager: Action '%s' already registered \n " ,  act - > action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-01-14 06:31:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											return  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ret  >  0 )  {  /* Insert these alphabetically */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											prev  =  cur ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( prev ) 	
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_RWLIST_INSERT_AFTER ( & actions ,  prev ,  act ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-16 09:33:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_RWLIST_INSERT_HEAD ( & actions ,  act ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-26 15:49:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_verb ( 2 ,  " Manager registered action %s \n " ,  act - > action ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & actions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief register a new command with manager, including online help. This is
 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									the  preferred  way  to  register  a  manager  command  */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  ast_manager_register2 ( const  char  * action ,  int  auth ,  int  ( * func ) ( struct  mansession  * s ,  const  struct  message  * m ) ,  const  char  * synopsis ,  const  char  * description ) 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  manager_action  * cur  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-07 22:13:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( cur  =  ast_calloc ( 1 ,  sizeof ( * cur ) ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									cur - > action  =  action ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									cur - > authority  =  auth ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									cur - > func  =  func ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									cur - > synopsis  =  synopsis ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									cur - > description  =  description ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 20:08:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_manager_register_struct ( cur ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2005-11-14 19:00:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! @}
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 END  Doxygen  group  */ 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  following  are  support  functions  for  AMI - over - http . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  common  entry  point  is  generic_http_callback ( ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  which  extracts  HTTP  header  and  URI  fields  and  reformats 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  them  into  AMI  messages ,  locates  a  proper  session 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( using  the  mansession_id  Cookie  or  GET  variable ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  and  calls  process_message ( )  as  for  regular  AMI  clients . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  When  done ,  the  output  ( which  goes  to  a  temporary  file ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  is  read  back  into  a  buffer  and  reformatted  as  desired , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  then  fed  back  to  the  client  over  the  original  socket . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:30:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								enum  output_format  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FORMAT_RAW , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FORMAT_HTML , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									FORMAT_XML , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  char  * contenttype [ ]  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									[ FORMAT_RAW ]  =  " plain " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									[ FORMAT_HTML ]  =  " html " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									[ FORMAT_XML ]  =   " xml " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-11-28 09:27:37 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*!
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  locate  an  http  session  in  the  list .  The  search  key  ( ident )  is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  the  value  of  the  mansession_id  cookie  ( 0  is  not  valid  and  means 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  a  session  on  the  AMI  socket ) . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  mansession_session  * find_session ( uint32_t  ident ,  int  incinuse ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:30:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ident  = =  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( session - > managerid  = =  ident  & &  ! session - > needdestroy )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_atomic_fetchadd_int ( & session - > inuse ,  incinuse  ?  1  :  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  session ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-05-23 21:19:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  astman_is_authed ( uint32_t  ident )  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  authed ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-23 21:19:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( session  =  find_session ( ident ,  0 ) ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-23 21:19:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									authed  =  ( session - > authenticated  ! =  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-23 21:19:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-23 21:19:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  authed ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-23 18:01:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  astman_verify_session_readpermissions ( uint32_t  ident ,  int  perm ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  result  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ( session - > managerid  = =  ident )  & &  ( session - > readperm  &  perm ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											result  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-23 18:01:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  astman_verify_session_writepermissions ( uint32_t  ident ,  int  perm ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  result  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE ( & sessions ,  session ,  list )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ( session - > managerid  = =  ident )  & &  ( session - > writeperm  &  perm ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											result  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-04-06 21:16:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  result ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  convert  to  xml  with  various  conversion : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  mode  &  1 	- >  lowercase ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  mode  &  2 	- >  replace  non - alphanumeric  chars  with  underscore 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  xml_copy_escape ( struct  ast_str  * * out ,  const  char  * src ,  int  mode ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* store in a local buffer to avoid calling ast_str_append too often */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  buf [ 256 ] ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * dst  =  buf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  space  =  sizeof ( buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* repeat until done and nothing to flush */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  (  ;  * src  | |  dst  ! =  buf  ;  src + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( * src  = =  ' \0 '  | |  space  <  10 )  { 	/* flush */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											* dst + +  =  ' \0 ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_str_append ( out ,  0 ,  " %s " ,  buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dst  =  buf ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space  =  sizeof ( buf ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( * src  = =  ' \0 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  (  ( mode  &  2 )  & &  ! isalnum ( * src ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											* dst + +  =  ' _ ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space - - ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										switch  ( * src )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  ' < ' : 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											strcpy ( dst ,  " < " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dst  + =  4 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space  - =  4 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  ' > ' : 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											strcpy ( dst ,  " > " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dst  + =  4 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space  - =  4 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  ' \" ' : 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											strcpy ( dst ,  " " " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dst  + =  6 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space  - =  6 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  ' \' ' : 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											strcpy ( dst ,  " ' " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dst  + =  6 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space  - =  6 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										case  ' & ' : 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											strcpy ( dst ,  " & " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dst  + =  5 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space  - =  5 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										default : 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											* dst + +  =  mode  ?  tolower ( * src )  :  * src ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											space - - ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  variable_count  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * varname ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  count ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  compress_char ( char  c ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									c  & =  0x7f ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( c  <  32 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else  if  ( c  > =  ' a '  & &  c  < =  ' z ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  c  -  64 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else  if  ( c  >  ' z ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  ' _ ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									else 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  c  -  32 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  variable_count_hash_fn ( const  void  * vvc ,  const  int  flags ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									const  struct  variable_count  * vc  =  vvc ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  res  =  0 ,  i ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( i  =  0 ;  i  <  5 ;  i + + )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( vc - > varname [ i ]  = =  ' \0 ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										res  + =  compress_char ( vc - > varname [ i ] )  < <  ( i  *  6 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  res ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  int  variable_count_cmp_fn ( void  * obj ,  void  * vstr ,  int  flags ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* Due to the simplicity of struct variable_count, it makes no difference
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 *  if  you  pass  in  objects  or  strings ,  the  same  operation  applies .  This  is 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 *  due  to  the  fact  that  the  hash  occurs  on  the  first  element ,  which  means 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									 *  the  address  of  both  the  struct  and  the  string  are  exactly  the  same .  */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  variable_count  * vc  =  obj ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * str  =  vstr ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-29 17:48:07 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  ! strcmp ( vc - > varname ,  str )  ?  CMP_MATCH  |  CMP_STOP  :  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief Convert the input into XML or HTML.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  input  is  supposed  to  be  a  sequence  of  lines  of  the  form 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 	Name :  value 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  optionally  followed  by  a  blob  of  unformatted  text . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  A  blank  line  is  a  section  separator .  Basically ,  this  is  a 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  mixture  of  the  format  of  Manager  Interface  and  CLI  commands . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  unformatted  text  is  considered  as  a  single  value  of  a  field 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  named  ' Opaque - data ' . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  At  the  moment  the  output  format  is  the  following  ( but  it  may 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  change  depending  on  future  requirements  so  don ' t  count  too 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  much  on  it  when  writing  applications ) : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  General :  the  unformatted  text  is  used  as  a  value  of 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  XML  output :   to  be  completed 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-07 23:07:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  \ verbatim 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *    Each  section  is  within  < response  type = " object "  id = " xxx " > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *    where  xxx  is  taken  from  ajaxdest  variable  or  defaults  to  unknown 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *    Each  row  is  reported  as  an  attribute  Name = " value "  of  an  XML 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *    entity  named  from  the  variable  ajaxobjtype ,  default  to  " generic " 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-07 23:07:25 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  \ endverbatim 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  HTML  output : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *    each  Name - value  pair  is  output  as  a  single  row  of  a  two - column  table . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *    Sections  ( blank  lines  in  the  input )  are  separated  by  a  < HR > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  void  xml_translate ( struct  ast_str  * * out ,  char  * in ,  struct  ast_variable  * vars ,  enum  output_format  format ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_variable  * v ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-14 13:18:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * dest  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  * var ,  * val ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-14 13:18:40 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * objtype  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  in_data  =  0 ; 	/* parsing data */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  inobj  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									int  xml  =  ( format  = =  FORMAT_XML ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  variable_count  * vc  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ao2_container  * vco  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									for  ( v  =  vars ;  v ;  v  =  v - > next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! dest  & &  ! strcasecmp ( v - > name ,  " ajaxdest " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											dest  =  v - > value ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else  if  ( ! objtype  & &  ! strcasecmp ( v - > name ,  " ajaxobjtype " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											objtype  =  v - > value ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! dest ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										dest  =  " unknown " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! objtype ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										objtype  =  " generic " ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* we want to stop when we find an empty line */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									while  ( in  & &  * in )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										val  =  strsep ( & in ,  " \r \n " ) ; 	/* mark start and end of line */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 17:07:08 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( in  & &  * in  = =  ' \n ' ) 		/* remove trailing \n if any */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											in + + ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_trim_blanks ( val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_debug ( 5 ,  " inobj %d in_data %d line <%s> \n " ,  inobj ,  in_data ,  val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ast_strlen_zero ( val ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( in_data )  {  /* close data */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_str_append ( out ,  0 ,  xml  ?  " ' "  :  " </td></tr> \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												in_data  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-22 15:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( inobj )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_str_append ( out ,  0 ,  xml  ?  "  /></response> \n "  : 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													" <tr><td colspan= \" 2 \" ><hr></td></tr> \r \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												inobj  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ao2_ref ( vco ,  - 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												vco  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* we expect Name: value lines */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( in_data )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											var  =  strsep ( & val ,  " : " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( val )  { 	/* found the field name */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												val  =  ast_skip_blanks ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_trim_blanks ( var ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}  else  { 		/* field name not found, move to opaque mode */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												val  =  var ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var  =  " Opaque-data " ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! inobj )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( xml ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_str_append ( out ,  0 ,  " <response type='object' id='%s'><%s " ,  dest ,  objtype ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											else 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_str_append ( out ,  0 ,  " <body> \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											vco  =  ao2_container_alloc ( 37 ,  variable_count_hash_fn ,  variable_count_cmp_fn ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											inobj  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! in_data )  { 	/* build appropriate line start */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_str_append ( out ,  0 ,  xml  ?  "   "  :  " <tr><td> " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ( vc  =  ao2_find ( vco ,  var ,  0 ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												vc - > count + + ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												/* Create a new entry for this one */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												vc  =  ao2_alloc ( sizeof ( * vc ) ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												vc - > varname  =  var ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												vc - > count  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ao2_link ( vco ,  vc ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											xml_copy_escape ( out ,  var ,  xml  ?  1  |  2  :  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( vc - > count  >  1 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_str_append ( out ,  0 ,  " -%d " ,  vc - > count ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ao2_ref ( vc ,  - 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_str_append ( out ,  0 ,  xml  ?  " =' "  :  " </td><td> " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! strcmp ( var ,  " Opaque-data " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												in_data  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										xml_copy_escape ( out ,  val ,  0 ) ; 	/* data field */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! in_data ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_str_append ( out ,  0 ,  xml  ?  " ' "  :  " </td></tr> \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_str_append ( out ,  0 ,  xml  ?  " \n "  :  " <br> \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( inobj )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( out ,  0 ,  xml  ?  "  /></response> \n "  : 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											" <tr><td colspan= \" 2 \" ><hr></td></tr> \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-23 17:56:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ao2_ref ( vco ,  - 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 17:45:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_str  * generic_http_callback ( enum  output_format  format , 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													     struct  sockaddr_in  * remote_address ,  const  char  * uri ,  enum  ast_http_method  method , 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													     struct  ast_variable  * params ,  int  * status , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													     char  * * title ,  int  * contentlength ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  mansession  s  =  { . session  =  NULL ,  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  mansession_session  * session  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-23 18:01:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									uint32_t  ident  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  blastaway  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_variable  * v ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:36:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									char  template [ ]  =  " /tmp/ast-http-XXXXXX " ; 	/* template for temporary file */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_str  * out  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  message  m  =  {  0  } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									unsigned  int  x ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									size_t  hdrlen ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( v  =  params ;  v ;  v  =  v - > next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( v - > name ,  " mansession_id " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-23 18:01:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											sscanf ( v - > value ,  " %x " ,  & ident ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:30:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( session  =  find_session ( ident ,  1 ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:30:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* Create new session.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  While  it  is  not  in  the  list  we  don ' t  need  any  locking 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ( session  =  ast_calloc ( 1 ,  sizeof ( * session ) ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-04 00:16:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											* status  =  500 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											goto  generic_callback_out ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										session - > sin  =  * remote_address ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										session - > fd  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										session - > waiting_thread  =  AST_PTHREADT_NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										session - > send_events  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_init ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_mutex_lock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										session - > inuse  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-27 18:20:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/*!\note There is approximately a 1 in 1.8E19 chance that the following
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  calculation  will  produce  0 ,  which  is  an  invalid  ID ,  but  due  to  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  properties  of  the  rand ( )  function  ( and  the  constantcy  of  s ) ,  that 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  won ' t  happen  twice  in  a  row . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-03-27 18:09:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										while  ( ( session - > managerid  =  ast_random ( )  ^  ( unsigned  long )  session )  = =  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										session - > last_ev  =  grab_last ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										AST_LIST_HEAD_INIT_NOLOCK ( & session - > datastores ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_LIST_LOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_LIST_INSERT_HEAD ( & sessions ,  session ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-08-21 19:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_atomic_fetchadd_int ( & num_sessions ,  1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-09-18 20:59:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_LIST_UNLOCK ( & sessions ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s . session  =  session ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! ( out  =  ast_str_create ( 1024 ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										* status  =  500 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										goto  generic_callback_out ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s . fd  =  mkstemp ( template ) ; 	/* create a temporary file for command output */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									unlink ( template ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									s . f  =  fdopen ( s . fd ,  " w+ " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:53:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( x  =  0 ,  v  =  params ;  v  & &  ( x  <  AST_MAX_MANHEADERS ) ;  x + + ,  v  =  v - > next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										hdrlen  =  strlen ( v - > name )  +  strlen ( v - > value )  +  3 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										m . headers [ m . hdrcount ]  =  alloca ( hdrlen ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:53:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										snprintf ( ( char  * )  m . headers [ m . hdrcount ] ,  hdrlen ,  " %s: %s " ,  v - > name ,  v - > value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_verb ( 4 ,  " HTTP Manager add header %s \n " ,  m . headers [ m . hdrcount ] ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										m . hdrcount  =  x  +  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( process_message ( & s ,  & m ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( session - > authenticated )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( manager_displayconnects ( session ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_verb ( 2 ,  " HTTP Manager '%s' logged off from %s \n " ,  session - > username ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_log ( LOG_EVENT ,  " HTTP Manager '%s' logged off from %s \n " ,  session - > username ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( displayconnects )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_verb ( 2 ,  " HTTP Connect attempt from '%s' unable to authenticate \n " ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_log ( LOG_EVENT ,  " HTTP Failed attempt from %s \n " ,  ast_inet_ntoa ( session - > sin . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										session - > needdestroy  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_str_append ( & out ,  0 , 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										       " Content-type: text/%s \r \n " 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										       " Cache-Control: no-cache; \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-23 18:01:00 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										       " Set-Cookie: mansession_id= \" %08x \" ; Version= \" 1 \" ; Max-Age=%d \r \n " 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										       " \r \n " , 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											contenttype [ format ] , 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											session - > managerid ,  httptimeout ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( format  = =  FORMAT_XML )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  " <ajax-response> \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  if  ( format  = =  FORMAT_HTML )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/*
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  When  handling  AMI - over - HTTP  in  HTML  format ,  we  provide  a  simple  form  for 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  debugging  purposes .  This  HTML  code  should  not  be  here ,  we 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 *  should  read  from  some  config  file . . . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										 */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 05:31:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# define ROW_FMT	"<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\">%s< / td>< / tr>\r\n" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# define TEST_STRING \ 
 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-20 18:07:24 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									" <form action= \" manager \" > \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									Action :  < select  name = \ " action \" > \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										< option  value = \ " \" >-----></option> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										< option  value = \ " login \" >login</option> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										< option  value = \ " command \" >Command</option> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										< option  value = \ " waitevent \" >waitevent</option> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										< option  value = \ " listcommands \" >listcommands</option> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									< / select > \ n \
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									or  < input  name = \ " action \" ><br/> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									CLI  Command  < input  name = \ " command \" ><br> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									user  < input  name = \ " username \" > pass <input type= \" password \"  name= \" secret \" ><br> \n \
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									< input  type = \ " submit \" > \n </form> \n " 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:52:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  " <title>Asterisk™ Manager Interface</title> " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  " <body bgcolor= \" #ffffff \" ><table align=center bgcolor= \" #f1f1f1 \"  width= \" 500 \" > \r \n " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  ROW_FMT ,  " <h1>Manager Tester</h1> " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  ROW_FMT ,  TEST_STRING ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:36:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( s . f  ! =  NULL )  { 	/* have temporary output */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										char  * buf ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										size_t  l  =  ftell ( s . f ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-08 20:39:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( l )  { 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ( buf  =  mmap ( NULL ,  l ,  PROT_READ  |  PROT_WRITE ,  MAP_SHARED ,  s . fd ,  0 ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-08 20:39:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												if  ( format  = =  FORMAT_XML  | |  format  = =  FORMAT_HTML ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:52:16 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													xml_translate ( & out ,  buf ,  params ,  format ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-08 20:39:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												else 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-18 15:43:34 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													ast_str_append ( & out ,  0 ,  " %s " ,  buf ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-08 20:39:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												munmap ( buf ,  l ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 17:41:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-08 20:39:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( format  = =  FORMAT_XML  | |  format  = =  FORMAT_HTML )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											xml_translate ( & out ,  " " ,  params ,  format ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 17:41:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										fclose ( s . f ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										s . f  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										s . fd  =  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-17 17:41:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( format  = =  FORMAT_XML )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  " </ajax-response> \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									}  else  if  ( format  = =  FORMAT_HTML ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_str_append ( & out ,  0 ,  " </table></body> \r \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:42:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_mutex_lock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:30:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* Reset HTTP timeout.  If we're not authenticated, keep it extremely short */ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									session - > sessiontimeout  =  time ( NULL )  +  ( ( session - > authenticated  | |  httptimeout  <  5 )  ?  httptimeout  :  5 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-01-05 22:43:18 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( session - > needdestroy )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( session - > inuse  = =  1 )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_debug ( 1 ,  " Need destroy, doing it now! \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											blastaway  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_debug ( 1 ,  " Need destroy, but can't do it yet! \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( session - > waiting_thread  ! =  AST_PTHREADT_NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												pthread_kill ( session - > waiting_thread ,  SIGURG ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											session - > inuse - - ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										session - > inuse - - ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ast_mutex_unlock ( & session - > __lock ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( blastaway ) 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										destroy_session ( session ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-04 00:16:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								generic_callback_out : 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( * status  ! =  200 ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  ast_http_error ( 500 ,  " Server Error " ,  NULL ,  " Internal Server Error (out of memory) \ n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-16 09:33:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  out ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 15:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_str  * manager_http_callback ( struct  ast_tcptls_session_instance  * ser ,  const  struct  ast_http_uri  * urih ,  const  char  * uri ,  enum  ast_http_method  method ,  struct  ast_variable  * params ,  struct  ast_variable  * headers ,  int  * status ,  char  * * title ,  int  * contentlength ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  generic_http_callback ( FORMAT_HTML ,  & ser - > remote_address ,  uri ,  method ,  params ,  status ,  title ,  contentlength ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 15:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_str  * mxml_http_callback ( struct  ast_tcptls_session_instance  * ser ,  const  struct  ast_http_uri  * urih ,  const  char  * uri ,  enum  ast_http_method  method ,  struct  ast_variable  * params ,  struct  ast_variable  * headers ,  int  * status ,  char  * * title ,  int  * contentlength ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  generic_http_callback ( FORMAT_XML ,  & ser - > remote_address ,  uri ,  method ,  params ,  status ,  title ,  contentlength ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 15:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_str  * rawman_http_callback ( struct  ast_tcptls_session_instance  * ser ,  const  struct  ast_http_uri  * urih ,  const  char  * uri ,  enum  ast_http_method  method ,  struct  ast_variable  * params ,  struct  ast_variable  * headers ,  int  * status ,  char  * * title ,  int  * contentlength ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  generic_http_callback ( FORMAT_RAW ,  & ser - > remote_address ,  uri ,  method ,  params ,  status ,  title ,  contentlength ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  ast_http_uri  rawmanuri  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. description  =  " Raw HTTP Manager Event Interface " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. uri  =  " rawman " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. callback  =  rawman_http_callback , 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 16:18:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. supports_get  =  1 , 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 15:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. data  =  NULL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. key  =  __FILE__ , 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  ast_http_uri  manageruri  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. description  =  " HTML Manager Event Interface " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. uri  =  " manager " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. callback  =  manager_http_callback , 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 16:18:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. supports_get  =  1 , 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 15:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. data  =  NULL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. key  =  __FILE__ , 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  ast_http_uri  managerxmluri  =  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. description  =  " XML Manager Event Interface " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. uri  =  " mxml " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. callback  =  mxml_http_callback , 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-19 16:18:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. supports_get  =  1 , 
							 
						 
					
						
							
								
									
										
										
										
											2008-04-02 15:25:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. data  =  NULL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. key  =  __FILE__ , 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  registered  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  webregged  =  0 ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/*! \brief cleanup code called at each iteration of server_root,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  guaranteed  to  happen  every  5  seconds  at  most 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								static  void  purge_old_stuff ( void  * data ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									purge_sessions ( 1 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									purge_events ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-01-18 22:04:33 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								struct  ast_tls_config  ami_tls_cfg ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_tcptls_session_args  ami_desc  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. accept_fd  =  - 1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. master  =  AST_PTHREADT_NULL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. tls_cfg  =  NULL ,  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. poll_timeout  =  5000 , 	/* wake up every 5 seconds */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. periodic_fn  =  purge_old_stuff , 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. name  =  " AMI server " , 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 22:23:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. accept_fn  =  ast_tcptls_server_root , 	/* thread doing the accept() */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. worker_fn  =  session_do , 	/* thread handling the session */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-06 20:46:01 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  struct  ast_tcptls_session_args  amis_desc  =  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. accept_fd  =  - 1 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. master  =  AST_PTHREADT_NULL , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. tls_cfg  =  & ami_tls_cfg ,  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. poll_timeout  =  - 1 , 	/* the other does the periodic cleanup */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									. name  =  " AMI TLS server " , 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 22:23:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. accept_fn  =  ast_tcptls_server_root , 	/* thread doing the accept() */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-03 17:40:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									. worker_fn  =  session_do , 	/* thread handling the session */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								static  int  __init_manager ( int  reload ) 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_config  * ucfg  =  NULL ,  * cfg  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-20 20:40:39 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									const  char  * val ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									char  * cat  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  newhttptimeout  =  60 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									int  have_sslbindaddr  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  hostent  * hp ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_hostent  ahp ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_manager_user  * user  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_variable  * var ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									struct  ast_flags  config_flags  =  {  reload  ?  CONFIG_FLAG_FILEUNCHANGED  :  0  } ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 00:02:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									manager_enabled  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! registered )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										/* Register default actions */ 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-04 16:18:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Ping " ,  0 ,  action_ping ,  " Keepalive command " ,  mandescr_ping ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Events " ,  0 ,  action_events ,  " Control Event Flow " ,  mandescr_events ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-29 05:04:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Logoff " ,  0 ,  action_logoff ,  " Logoff Manager " ,  mandescr_logoff ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 13:23:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Login " ,  0 ,  action_login ,  " Login Manager " ,  NULL ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Challenge " ,  0 ,  action_challenge ,  " Generate Challenge for MD5 Auth " ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 00:12:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Hangup " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_CALL ,  action_hangup ,  " Hangup Channel " ,  mandescr_hangup ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-05-05 19:33:14 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Status " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_CALL  |  EVENT_FLAG_REPORTING ,  action_status ,  " Lists channel status " ,  mandescr_status ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Setvar " ,  EVENT_FLAG_CALL ,  action_setvar ,  " Set Channel Variable " ,  mandescr_setvar ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Getvar " ,  EVENT_FLAG_CALL  |  EVENT_FLAG_REPORTING ,  action_getvar ,  " Gets a Channel Variable " ,  mandescr_getvar ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 00:12:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " GetConfig " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_CONFIG ,  action_getconfig ,  " Retrieve configuration " ,  mandescr_getconfig ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " GetConfigJSON " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_CONFIG ,  action_getconfigjson ,  " Retrieve configuration (JSON format) " ,  mandescr_getconfigjson ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-07-19 13:28:38 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " UpdateConfig " ,  EVENT_FLAG_CONFIG ,  action_updateconfig ,  " Update basic configuration " ,  mandescr_updateconfig ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-12 00:24:36 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " CreateConfig " ,  EVENT_FLAG_CONFIG ,  action_createconfig ,  " Creates an empty file in the configuration directory " ,  mandescr_createconfig ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " ListCategories " ,  EVENT_FLAG_CONFIG ,  action_listcategories ,  " List categories in configuration file " ,  mandescr_listcategories ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Redirect " ,  EVENT_FLAG_CALL ,  action_redirect ,  " Redirect (transfer) a call " ,  mandescr_redirect  ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-05 22:33:05 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Atxfer " ,  EVENT_FLAG_CALL ,  action_atxfer ,  " Attended transfer " ,  mandescr_atxfer ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-02-22 22:55:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Originate " ,  EVENT_FLAG_ORIGINATE ,  action_originate ,  " Originate Call " ,  mandescr_originate ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2005-04-13 05:45:53 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Command " ,  EVENT_FLAG_COMMAND ,  action_command ,  " Execute Asterisk CLI Command " ,  mandescr_command  ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 00:12:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " ExtensionState " ,  EVENT_FLAG_CALL  |  EVENT_FLAG_REPORTING ,  action_extensionstate ,  " Check Extension Status " ,  mandescr_extensionstate  ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " AbsoluteTimeout " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_CALL ,  action_timeout ,  " Set Absolute Timeout " ,  mandescr_timeout  ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " MailboxStatus " ,  EVENT_FLAG_CALL  |  EVENT_FLAG_REPORTING ,  action_mailboxstatus ,  " Check Mailbox " ,  mandescr_mailboxstatus  ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " MailboxCount " ,  EVENT_FLAG_CALL  |  EVENT_FLAG_REPORTING ,  action_mailboxcount ,  " Check Mailbox Message Count " ,  mandescr_mailboxcount  ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2004-06-02 22:30:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " ListCommands " ,  0 ,  action_listcommands ,  " List available manager commands " ,  mandescr_listcommands ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-31 10:42:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " SendText " ,  EVENT_FLAG_CALL ,  action_sendtext ,  " Send text message to channel " ,  mandescr_sendtext ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-05-20 13:29:22 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " UserEvent " ,  EVENT_FLAG_USER ,  action_userevent ,  " Send an arbitrary event " ,  mandescr_userevent ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " WaitEvent " ,  0 ,  action_waitevent ,  " Wait for an event to occur " ,  mandescr_waitevent ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-10 00:12:35 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " CoreSettings " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_REPORTING ,  action_coresettings ,  " Show PBX core settings (version etc) " ,  mandescr_coresettings ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " CoreStatus " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_REPORTING ,  action_corestatus ,  " Show PBX core status variables " ,  mandescr_corestatus ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " Reload " ,  EVENT_FLAG_CONFIG  |  EVENT_FLAG_SYSTEM ,  action_reload ,  " Send a reload event " ,  mandescr_reload ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " CoreShowChannels " ,  EVENT_FLAG_SYSTEM  |  EVENT_FLAG_REPORTING ,  action_coreshowchannels ,  " List currently active channels " ,  mandescr_coreshowchannels ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-01-07 15:52:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " ModuleLoad " ,  EVENT_FLAG_SYSTEM ,  manager_moduleload ,  " Module management " ,  mandescr_moduleload ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_manager_register2 ( " ModuleCheck " ,  EVENT_FLAG_SYSTEM ,  manager_modulecheck ,  " Check if module is loaded " ,  mandescr_modulecheck ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 19:58:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_cli_register_multiple ( cli_manager ,  sizeof ( cli_manager )  /  sizeof ( struct  ast_cli_entry ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-04-06 23:32:31 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_extension_state_add ( NULL ,  NULL ,  manager_state_cb ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										registered  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-02 19:59:55 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* Append placeholder event so master_eventq never runs dry */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										append_event ( " Event: Placeholder \r \n \r \n " ,  0 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2003-01-28 22:33:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 18:39:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ( cfg  =  ast_config_load2 ( " manager.conf " ,  " manager " ,  config_flags ) )  = =  CONFIG_STATUS_FILEUNCHANGED ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2005-01-05 06:24:59 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									displayconnects  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									if  ( ! cfg )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_log ( LOG_NOTICE ,  " Unable to open AMI configuration manager.conf. Asterisk management interface (AMI) disabled. \n " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
										return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* default values */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									memset ( & ami_desc . local_address ,  0 ,  sizeof ( struct  sockaddr_in ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									memset ( & amis_desc . local_address ,  0 ,  sizeof ( amis_desc . local_address ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									amis_desc . local_address . sin_port  =  htons ( 5039 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ami_desc . local_address . sin_port  =  htons ( DEFAULT_MANAGER_PORT ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									ami_tls_cfg . enabled  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ami_tls_cfg . certfile ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free ( ami_tls_cfg . certfile ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ami_tls_cfg . certfile  =  ast_strdup ( AST_CERTFILE ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ami_tls_cfg . cipher ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free ( ami_tls_cfg . cipher ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ami_tls_cfg . cipher  =  ast_strdup ( " " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									for  ( var  =  ast_variable_browse ( cfg ,  " general " ) ;  var ;  var  =  var - > next )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										val  =  var - > value ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-14 15:43:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( var - > name ,  " sslenable " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ami_tls_cfg . enabled  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-14 15:43:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else  if  ( ! strcasecmp ( var - > name ,  " sslbindport " ) ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											amis_desc . local_address . sin_port  =  htons ( atoi ( val ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-14 15:43:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										else  if  ( ! strcasecmp ( var - > name ,  " sslbindaddr " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ( hp  =  ast_gethostbyname ( val ,  & ahp ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												memcpy ( & amis_desc . local_address . sin_addr ,  hp - > h_addr ,  sizeof ( amis_desc . local_address . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												have_sslbindaddr  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												ast_log ( LOG_WARNING ,  " Invalid bind address '%s' \n " ,  val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " sslcert " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_free ( ami_tls_cfg . certfile ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ami_tls_cfg . certfile  =  ast_strdup ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " sslcipher " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_free ( ami_tls_cfg . cipher ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ami_tls_cfg . cipher  =  ast_strdup ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " enabled " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-14 20:22:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											manager_enabled  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " block-sockets " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											block_sockets  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " webenabled " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-02-14 20:22:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											webmanager_enabled  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " port " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ami_desc . local_address . sin_port  =  htons ( atoi ( val ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " bindaddr " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! inet_aton ( val ,  & ami_desc . local_address . sin_addr ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_log ( LOG_WARNING ,  " Invalid address '%s' specified, using 0.0.0.0 \n " ,  val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												memset ( & ami_desc . local_address . sin_addr ,  0 ,  sizeof ( ami_desc . local_address . sin_addr ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
									
										
										
										
											2007-05-17 17:12:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " allowmultiplelogin " ) )  {  
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											allowmultiplelogin  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " displayconnects " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											displayconnects  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " timestampevents " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											timestampevents  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " debug " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											manager_debug  =  ast_true ( val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										}  else  if  ( ! strcasecmp ( var - > name ,  " httptimeout " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											newhttptimeout  =  atoi ( val ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										}  else  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-12 10:35:10 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_log ( LOG_NOTICE ,  " Invalid keyword <%s> = <%s> in manager.conf [general] \n " , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												var - > name ,  val ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 	
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2006-01-03 22:07:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-02-14 20:22:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( manager_enabled ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ami_desc . local_address . sin_family  =  AF_INET ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ! have_sslbindaddr ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										amis_desc . local_address . sin_addr  =  ami_desc . local_address . sin_addr ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ami_tls_cfg . enabled ) 
							 
						 
					
						
							
								
									
										
										
										
											2008-10-19 19:33:42 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										amis_desc . local_address . sin_family  =  AF_INET ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-18 21:41:09 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-12-07 16:42:29 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_WRLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									/* First, get users from users.conf */ 
							 
						 
					
						
							
								
									
										
										
										
											2008-03-26 18:39:06 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ucfg  =  ast_config_load2 ( " users.conf " ,  " manager " ,  config_flags ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( ucfg  & &  ( ucfg  ! =  CONFIG_STATUS_FILEUNCHANGED ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										const  char  * hasmanager ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										int  genhasmanager  =  ast_true ( ast_variable_retrieve ( ucfg ,  " general " ,  " hasmanager " ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										while  ( ( cat  =  ast_category_browse ( ucfg ,  cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ! strcasecmp ( cat ,  " general " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											hasmanager  =  ast_variable_retrieve ( ucfg ,  cat ,  " hasmanager " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											if  ( ( ! hasmanager  & &  genhasmanager )  | |  ast_true ( hasmanager ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												const  char  * user_secret  =  ast_variable_retrieve ( ucfg ,  cat ,  " secret " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												const  char  * user_read  =  ast_variable_retrieve ( ucfg ,  cat ,  " read " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												const  char  * user_write  =  ast_variable_retrieve ( ucfg ,  cat ,  " write " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												const  char  * user_displayconnects  =  ast_variable_retrieve ( ucfg ,  cat ,  " displayconnects " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												const  char  * user_writetimeout  =  ast_variable_retrieve ( ucfg ,  cat ,  " writetimeout " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												/* Look for an existing entry,
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												 *  if  none  found  -  create  one  and  add  it  to  the  list 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! ( user  =  get_manager_by_name_locked ( cat ) ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( ! ( user  =  ast_calloc ( 1 ,  sizeof ( * user ) ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													/* Copy name over */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													ast_copy_string ( user - > username ,  cat ,  sizeof ( user - > username ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													/* Insert into list */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													AST_LIST_INSERT_TAIL ( & users ,  user ,  list ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > ha  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-07-18 22:19:56 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													user - > keep  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													user - > readperm  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > writeperm  =  - 1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													/* Default displayconnect from [general] */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > displayconnects  =  displayconnects ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > writetimeout  =  100 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! user_secret ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user_secret  =  ast_variable_retrieve ( ucfg ,  " general " ,  " secret " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! user_read ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user_read  =  ast_variable_retrieve ( ucfg ,  " general " ,  " read " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! user_write ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user_write  =  ast_variable_retrieve ( ucfg ,  " general " ,  " write " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! user_displayconnects ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user_displayconnects  =  ast_variable_retrieve ( ucfg ,  " general " ,  " displayconnects " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! user_writetimeout ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user_writetimeout  =  ast_variable_retrieve ( ucfg ,  " general " ,  " writetimeout " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( ! ast_strlen_zero ( user_secret ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( user - > secret ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
														ast_free ( user - > secret ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > secret  =  ast_strdup ( user_secret ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( user_read ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > readperm  =  get_perm ( user_read ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( user_write ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > writeperm  =  get_perm ( user_write ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( user_displayconnects ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													user - > displayconnects  =  ast_true ( user_displayconnects ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( user_writetimeout )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													int  value  =  atoi ( user_writetimeout ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													if  ( value  <  100 ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														ast_log ( LOG_WARNING ,  " Invalid writetimeout value '%s' at users.conf line %d \n " ,  var - > value ,  var - > lineno ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
													else 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
														user - > writetimeout  =  value ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_config_destroy ( ucfg ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* cat is NULL here in any case */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									while  ( ( cat  =  ast_category_browse ( cfg ,  cat ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										struct  ast_ha  * oldha ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ! strcasecmp ( cat ,  " general " ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										/* Look for an existing entry, if none found - create one and add it to the list */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 07:43:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! ( user  =  get_manager_by_name_locked ( cat ) ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! ( user  =  ast_calloc ( 1 ,  sizeof ( * user ) ) ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											/* Copy name over */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_copy_string ( user - > username ,  cat ,  sizeof ( user - > username ) ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											user - > ha  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											user - > readperm  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											user - > writeperm  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											/* Default displayconnect from [general] */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											user - > displayconnects  =  displayconnects ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											user - > writetimeout  =  100 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											/* Insert into list */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											AST_RWLIST_INSERT_TAIL ( & users ,  user ,  list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										/* Make sure we keep this user and don't destroy it during cleanup */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										user - > keep  =  1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										oldha  =  user - > ha ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										user - > ha  =  NULL ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										var  =  ast_variable_browse ( cfg ,  cat ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										for  ( ;  var ;  var  =  var - > next )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											if  ( ! strcasecmp ( var - > name ,  " secret " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( user - > secret ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													ast_free ( user - > secret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												user - > secret  =  ast_strdup ( var - > value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else  if  ( ! strcasecmp ( var - > name ,  " deny " )  | | 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												       ! strcasecmp ( var - > name ,  " permit " ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												user - > ha  =  ast_append_ha ( var - > name ,  var - > value ,  user - > ha ,  NULL ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}   else  if  ( ! strcasecmp ( var - > name ,  " read " )  )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												user - > readperm  =  get_perm ( var - > value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}   else  if  ( ! strcasecmp ( var - > name ,  " write " )  )  { 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												user - > writeperm  =  get_perm ( var - > value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											}   else  if  ( ! strcasecmp ( var - > name ,  " displayconnects " )  )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												user - > displayconnects  =  ast_true ( var - > value ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else  if  ( ! strcasecmp ( var - > name ,  " writetimeout " ) )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												int  value  =  atoi ( var - > value ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												if  ( value  <  100 ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													ast_log ( LOG_WARNING ,  " Invalid writetimeout value '%s' at line %d \n " ,  var - > value ,  var - > lineno ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
												else 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-10 19:35:50 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
													user - > writetimeout  =  value ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											}  else 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-24 18:51:41 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
												ast_debug ( 1 ,  " %s is an unknown option. \n " ,  var - > name ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free_ha ( oldha ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_config_destroy ( cfg ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									/* Perform cleanup - essentially prune out old users that no longer exist */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE_SAFE_BEGIN ( & users ,  user ,  list )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-10-19 07:43:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( user - > keep )  { 	/* valid record. clear flag for the next round */ 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											user - > keep  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										/* We do not need to keep this user so take them out of the list */ 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										AST_RWLIST_REMOVE_CURRENT ( list ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										/* Free their memory now */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( user - > secret ) 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
											ast_free ( user - > secret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-12-16 13:32:48 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free_ha ( user - > ha ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2007-06-06 21:20:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										ast_free ( user ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
									
										
										
										
											2007-11-08 05:28:47 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_TRAVERSE_SAFE_END ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-07-24 02:59:49 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_RWLIST_UNLOCK ( & users ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-09-19 22:01:23 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-02-14 20:22:20 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									if  ( webmanager_enabled  & &  manager_enabled )  { 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-01 08:49:54 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( ! webregged )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_http_uri_link ( & rawmanuri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_http_uri_link ( & manageruri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_http_uri_link ( & managerxmluri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											webregged  =  1 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									}  else  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( webregged )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_http_uri_unlink ( & rawmanuri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_http_uri_unlink ( & manageruri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											ast_http_uri_unlink ( & managerxmluri ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											webregged  =  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( newhttptimeout  >  0 ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										httptimeout  =  newhttptimeout ; 
							 
						 
					
						
							
								
									
										
										
										
											2006-04-04 19:03:12 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-12-06 15:50:43 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									manager_event ( EVENT_FLAG_SYSTEM ,  " Reload " ,  " Module: Manager \r \n Status: %s \r \n Message: Manager reload Requested \r \n " ,  manager_enabled  ?  " Enabled "  :  " Disabled " ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2008-03-04 22:23:21 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									ast_tcptls_server_start ( & ami_desc ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( ast_ssl_setup ( amis_desc . tls_cfg ) ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										ast_tcptls_server_start ( & amis_desc ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								int  init_manager ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  __init_manager ( 0 ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								int  reload_manager ( void ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2007-08-16 21:09:46 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  __init_manager ( 1 ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2002-09-12 18:32:42 +00:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								int  astman_datastore_add ( struct  mansession  * s ,  struct  ast_datastore  * datastore ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_INSERT_HEAD ( & s - > session - > datastores ,  datastore ,  entry ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  0 ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								int  astman_datastore_remove ( struct  mansession  * s ,  struct  ast_datastore  * datastore ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									return  AST_LIST_REMOVE ( & s - > session - > datastores ,  datastore ,  entry )  ?  0  :  - 1 ; 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								struct  ast_datastore  * astman_datastore_find ( struct  mansession  * s ,  const  struct  ast_datastore_info  * info ,  const  char  * uid ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								{ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									struct  ast_datastore  * datastore  =  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									if  ( info  = =  NULL ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										return  NULL ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2009-02-10 21:54:45 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE_SAFE_BEGIN ( & s - > session - > datastores ,  datastore ,  entry )  { 
							 
						 
					
						
							
								
									
										
										
										
											2008-08-05 16:56:11 +00:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
										if  ( datastore - > info  ! =  info )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											continue ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( uid  = =  NULL )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											/* matched by type only */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										if  ( ( datastore - > uid  ! =  NULL )  & &  ! strcasecmp ( uid ,  datastore - > uid ) )  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											/* Matched by type AND uid */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
											break ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
										} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									AST_LIST_TRAVERSE_SAFE_END ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
									return  datastore ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}