[Asterisk-cvs] asterisk cdr.c, 1.25, 1.26 cli.c, 1.59, 1.60 pbx.c, 1.162, 1.163

anthm at lists.digium.com anthm at lists.digium.com
Fri Oct 22 16:55:36 CDT 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv28010

Modified Files:
	cdr.c cli.c pbx.c 
Log Message:
This patch adds a new api call:
int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size);
takes a chan and a char * 'buf' assumed to be 'size' bytes.

The function fills 'buf' with a <CR>('\n') delimited list of name,value pairs in turn delimeted by '='
eg:
SIPCALLID=f30e4e72-f715193f at 1.2.3.4
SIPUSERAGENT=Sipura/SPA2000-2.0.6(c)
SIPDOMAIN=1.2.3.4

It returns the acutal number of variables encountered.
If the attempt to fill 'buf' goes beyond 'size' bytes the operation is halted and the incomplete string is returned as is.

To demonstrate a use for this, the "show channel <channame>" command has been retrofitted with the call so it also dumps all of the chan's vars 

*CLI> show channel Zap/5-1
 -- General --
           Name: Zap/5-1
           Type: Zap
       UniqueID: 1098480666.17
      Caller ID: 4999
 Caller ID Name: Tony
    DNID Digits: (N/A)
          State: Up (6)
          Rings: 0
   NativeFormat: 68
    WriteFormat: 4
     ReadFormat: 4
1st File Descriptor: 22
      Frames in: 41969
     Frames out: 83240
 Time to Hangup: 0
   Elapsed Time: 0h13m54s
 --   PBX   --
        Context: phone1
      Extension: 4994
       Priority: 2
     Call Group: 2
   Pickup Group: 2
    Application: Dial
           Data: IAX2/ulaw at cube1/00010014994 at croip
          Stack: 0
    Blocking in: ast_waitfor_nandfds
Variables:
DIALEDPEERNUMBER=ulaw at cube1/00010014994 at croip
DIALEDPEERNAME=IAX2/cube1/3
CALLTYPE=SPEECH
tempvar=tempval




Index: cdr.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cdr.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- cdr.c	3 Oct 2004 19:59:45 -0000	1.25
+++ cdr.c	22 Oct 2004 20:59:37 -0000	1.26
@@ -290,6 +290,7 @@
 			if (!ast_strlen_zero(cdr->channel)) 
 				ast_log(LOG_WARNING, "CDR already initialized on '%s'\n", chan); 
 			strncpy(cdr->channel, c->name, sizeof(cdr->channel) - 1);
+			cdr->chan = c;
 			/* Grab source from ANI or normal Caller*ID */
 			if (c->cid.cid_ani)
 				num = c->cid.cid_ani;

Index: cli.c
===================================================================
RCS file: /usr/cvsroot/asterisk/cli.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- cli.c	16 Oct 2004 21:14:05 -0000	1.59
+++ cli.c	22 Oct 2004 20:59:37 -0000	1.60
@@ -17,6 +17,7 @@
 #include <asterisk/options.h>
 #include <asterisk/cli.h>
 #include <asterisk/module.h>
+#include <asterisk/pbx.h>
 #include <asterisk/channel.h>
 #include <asterisk/channel_pvt.h>
 #include <asterisk/manager.h>
@@ -597,6 +598,7 @@
 {
 	struct ast_channel *c=NULL;
 	struct timeval now;
+	char buf[1024];
 	long elapsed_seconds=0;
 	int hour=0, min=0, sec=0;
 	if (argc != 3)
@@ -649,6 +651,9 @@
 	c->context, c->exten, c->priority, c->callgroup, c->pickupgroup, ( c->appl ? c->appl : "(N/A)" ),
 	( c-> data ? (!ast_strlen_zero(c->data) ? c->data : "(Empty)") : "(None)"),
 	c->stack, (c->blocking ? c->blockproc : "(Not Blocking)"));
+			if(pbx_builtin_serialize_variables(c,buf,sizeof(buf)))
+				ast_cli(fd,"Variables:\n%s\n",buf);
+
 		ast_mutex_unlock(&c->lock);
 		break;
 		}

Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.162
retrieving revision 1.163
diff -u -d -r1.162 -r1.163
--- pbx.c	17 Oct 2004 22:13:05 -0000	1.162
+++ pbx.c	22 Oct 2004 20:59:37 -0000	1.163
@@ -4903,6 +4903,28 @@
 	return 0;
 }
 
+int pbx_builtin_serialize_variables(struct ast_channel *chan, char *buf, size_t size) 
+{
+	struct ast_var_t *variables;
+	struct varshead *headp;
+	int total = 0;
+
+	memset(buf,0,size);
+	if (chan) {
+		headp=&chan->varshead;
+		AST_LIST_TRAVERSE(headp,variables,entries) {
+			snprintf(buf + strlen(buf), size - strlen(buf), "%s=%s\n", ast_var_name(variables), ast_var_value(variables));
+			if(strlen(buf) >= size) {
+				ast_log(LOG_ERROR,"Data Buffer Size Exceeded!\n");
+				break;
+			}
+			total++;
+		}
+	}
+	
+	return total;
+}
+
 char *pbx_builtin_getvar_helper(struct ast_channel *chan, char *name) 
 {
 	struct ast_var_t *variables;




More information about the svn-commits mailing list