[Asterisk-cvs] asterisk/channels chan_iax2.c, 1.287, 1.288 iax2-parser.c, 1.42, 1.43

russell at lists.digium.com russell at lists.digium.com
Tue May 17 15:35:59 CDT 2005


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

Modified Files:
	chan_iax2.c iax2-parser.c 
Log Message:
print out the IAX DATETIME IE in 'iax2 debug' in human readable form


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.287
retrieving revision 1.288
diff -u -d -r1.287 -r1.288
--- chan_iax2.c	15 May 2005 23:26:45 -0000	1.287
+++ chan_iax2.c	17 May 2005 19:41:09 -0000	1.288
@@ -2764,12 +2764,12 @@
 	localtime_r(&t, &tm);
 	if (!ast_strlen_zero(tz))
 		ast_localtime(&t, &tm, tz);
-	tmp  = (tm.tm_sec >> 1) & 0x1f;	  /* 5 bits of seconds */
-	tmp |= (tm.tm_min & 0x3f) << 5;   /* 6 bits of minutes */
-	tmp |= (tm.tm_hour & 0x1f) << 11;   /* 5 bits of hours */
-	tmp |= (tm.tm_mday & 0x1f) << 16; /* 5 bits of day of month */
-	tmp |= ((tm.tm_mon + 1) & 0xf) << 21; /* 4 bits of month */
-	tmp |= ((tm.tm_year - 100) & 0x7f) << 25; /* 7 bits of year */
+	tmp  = (tm.tm_sec >> 1) & 0x1f;			/* 5 bits of seconds */
+	tmp |= (tm.tm_min & 0x3f) << 5;			/* 6 bits of minutes */
+	tmp |= (tm.tm_hour & 0x1f) << 11;		/* 5 bits of hours */
+	tmp |= (tm.tm_mday & 0x1f) << 16;		/* 5 bits of day of month */
+	tmp |= ((tm.tm_mon + 1) & 0xf) << 21;		/* 4 bits of month */
+	tmp |= ((tm.tm_year - 100) & 0x7f) << 25;	/* 7 bits of year */
 	return tmp;
 }
 

Index: iax2-parser.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/iax2-parser.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -u -d -r1.42 -r1.43
--- iax2-parser.c	21 Apr 2005 06:02:44 -0000	1.42
+++ iax2-parser.c	17 May 2005 19:41:09 -0000	1.43
@@ -89,7 +89,7 @@
 	if (len == (int)sizeof(unsigned int))
 		snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_unaligned_uint32(value)));
 	else
-		snprintf(output, maxlen, "Invalid INT");
+		ast_copy_string(output, "Invalid INT", maxlen);	
 }
 
 static void dump_short(char *output, int maxlen, void *value, int len)
@@ -97,7 +97,7 @@
 	if (len == (int)sizeof(unsigned short))
 		snprintf(output, maxlen, "%d", ntohs(get_unaligned_uint16(value)));
 	else
-		snprintf(output, maxlen, "Invalid SHORT");
+		ast_copy_string(output, "Invalid SHORT", maxlen);
 }
 
 static void dump_byte(char *output, int maxlen, void *value, int len)
@@ -105,7 +105,23 @@
 	if (len == (int)sizeof(unsigned char))
 		snprintf(output, maxlen, "%d", *((unsigned char *)value));
 	else
-		snprintf(output, maxlen, "Invalid BYTE");
+		ast_copy_string(output, "Invalid BYTE", maxlen);
+}
+
+static void dump_datetime(char *output, int maxlen, void *value, int len)
+{
+	struct tm tm;
+	unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value));
+	if (len == (int)sizeof(unsigned int)) {
+		tm.tm_sec  = (val & 0x1f) << 1;
+		tm.tm_min  = (val >> 5) & 0x3f;
+		tm.tm_hour = (val >> 11) & 0x1f;
+		tm.tm_mday = (val >> 16) & 0x1f;
+		tm.tm_mon  = ((val >> 21) & 0x0f) - 1;
+		tm.tm_year = ((val >> 25) & 0x7f) + 100;
+		strftime(output, maxlen, "%F  %T", &tm); 
+	} else
+		ast_copy_string(output, "Invalid DATETIME format!", maxlen);
 }
 
 static void dump_ipaddr(char *output, int maxlen, void *value, int len)
@@ -117,7 +133,7 @@
 		ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr);
 		snprintf(output, maxlen, "%s", iabuf);
 	} else
-		snprintf(output, maxlen, "Invalid IPADDR");
+		ast_copy_string(output, "Invalid IPADDR", maxlen);
 }
 
 
@@ -128,7 +144,7 @@
 		snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_unaligned_uint32(value)),
 			iax_provflags2str(buf, sizeof(buf), ntohl(get_unaligned_uint32(value))));
 	else
-		snprintf(output, maxlen, "Invalid INT");
+		ast_copy_string(output, "Invalid INT", maxlen);
 }
 
 static void dump_samprate(char *output, int maxlen, void *value, int len)
@@ -150,11 +166,11 @@
 		if (sr & IAX_RATE_48KHZ)
 			strcat(tmp, ",48khz");
 		if (strlen(tmp))
-			strncpy(output, &tmp[1], maxlen - 1);
+			ast_copy_string(output, &tmp[1], maxlen);
 		else
-			strncpy(output, "None specified!\n", maxlen - 1);
+			ast_copy_string(output, "None Specified!\n", maxlen);
 	} else
-		snprintf(output, maxlen, "Invalid SHORT");
+		ast_copy_string(output, "Invalid SHORT", maxlen);
 
 }
 
@@ -198,7 +214,7 @@
 	{ IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
 	{ IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
 	{ IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
-	{ IAX_IE_DATETIME, "DATE TIME", dump_int },
+	{ IAX_IE_DATETIME, "DATE TIME", dump_datetime },
 	{ IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
 	{ IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
 	{ IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
@@ -269,8 +285,9 @@
 		ielen = iedata[1];
 		if (ielen + 2> len) {
 			snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
-			strncpy(output, tmp, maxlen - 1);
-			maxlen -= strlen(output); output += strlen(output);
+			ast_copy_string(output, tmp, maxlen);
+			maxlen -= strlen(output);
+			output += strlen(output);
 			return;
 		}
 		found = 0;




More information about the svn-commits mailing list