[asterisk-commits] wedhorn: branch wedhorn/skinny-session r384237 - /team/wedhorn/skinny-session...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 28 02:06:33 CDT 2013


Author: wedhorn
Date: Thu Mar 28 02:06:28 2013
New Revision: 384237

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=384237
Log:
skinny: put packet data straight into req (removing inbuf) and change req int's to uint32's

Modified:
    team/wedhorn/skinny-session/channels/chan_skinny.c

Modified: team/wedhorn/skinny-session/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/wedhorn/skinny-session/channels/chan_skinny.c?view=diff&rev=384237&r1=384236&r2=384237
==============================================================================
--- team/wedhorn/skinny-session/channels/chan_skinny.c (original)
+++ team/wedhorn/skinny-session/channels/chan_skinny.c Thu Mar 28 02:06:28 2013
@@ -1196,9 +1196,9 @@
 
 /* packet composition */
 struct skinny_req {
-	int len;
-	int res;
-	int e;
+	uint32_t len;
+	uint32_t res;
+	uint32_t e;
 	union skinny_data data;
 };
 
@@ -1592,7 +1592,6 @@
 	time_t start;
 	struct sockaddr_in sin;
 	int fd;
-	char inbuf[SKINNY_MAX_PACKET];
 	char outbuf[SKINNY_MAX_PACKET];
 	struct skinny_device *device;
 	AST_LIST_ENTRY(skinnysession) list;
@@ -7429,7 +7428,6 @@
 	int dlen = 0;
 	int timeout;
 	time_t now;
-	int *bufaddr;
 	struct pollfd fds[1];
 
 	if (!s) {
@@ -7481,9 +7479,14 @@
 		}
 
 		if (fds[0].revents) {
+
+			if (!(req = ast_calloc(1, SKINNY_MAX_PACKET))) {
+				ast_verb(3, "Ending Skinny session from %s (failed parse)\n", ast_inet_ntoa(s->sin.sin_addr));
+				break;
+			}
+
 			ast_mutex_lock(&s->lock);
-			memset(s->inbuf, 0, sizeof(s->inbuf));
-			res = read(s->fd, s->inbuf, 4);
+			res = read(s->fd, req, skinny_header_size);
 			if (res < 0) {
 				ast_log(LOG_WARNING, "read() returned error: %s\n", strerror(errno));
 
@@ -7492,7 +7495,7 @@
 				ast_mutex_unlock(&s->lock);
 				ast_verb(3, "Ending Skinny session from %s (bad input)\n", ast_inet_ntoa(s->sin.sin_addr));
 				break;
-			} else if (res != 4) {
+			} else if (res != skinny_header_size) {
 				ast_log(LOG_WARNING, "Skinny Client sent less data than expected.  Expected 4 but got %d.\n", res);
 				ast_mutex_unlock(&s->lock);
 
@@ -7503,43 +7506,29 @@
 				break;
 			}
 
-			bufaddr = (int *)s->inbuf;
-			dlen = letohl(*bufaddr);
+			dlen = letohl(req->len);
 			if (dlen < 4) {
 				ast_log(LOG_WARNING, "Skinny Client sent invalid data.\n");
 				ast_mutex_unlock(&s->lock);
 				ast_verb(3, "Ending Skinny session from %s (bad input)\n", ast_inet_ntoa(s->sin.sin_addr));
 				break;
 			}
-			if (dlen+8 > sizeof(s->inbuf)) {
+			if (dlen+8 > SKINNY_MAX_PACKET) {
 				ast_log(LOG_WARNING, "Skinny packet too large (%d bytes), max length(%d bytes)\n", dlen+8, SKINNY_MAX_PACKET);
-				dlen = sizeof(s->inbuf) - 8;
-			}
-			*bufaddr = htolel(dlen);
-
-			res = read(s->fd, s->inbuf+4, dlen+4);
+				dlen = sizeof(req) - 8;
+			}
+
+			res = read(s->fd, &req->data, dlen-4);
 			ast_mutex_unlock(&s->lock);
 			if (res < 0) {
 				ast_log(LOG_WARNING, "read() returned error: %s\n", strerror(errno));
 				ast_verb(3, "Ending Skinny session from %s (bad input)\n", ast_inet_ntoa(s->sin.sin_addr));
 				break;
-			} else if (res != (dlen+4)) {
+			} else if (res != (dlen-4)) {
 				ast_log(LOG_WARNING, "Skinny Client sent less data than expected.\n");
 				ast_verb(3, "Ending Skinny session from %s (bad input)\n", ast_inet_ntoa(s->sin.sin_addr));
 				break;
 			}
-
-			if (!(req = ast_calloc(1, SKINNY_MAX_PACKET))) {
-				ast_verb(3, "Ending Skinny session from %s (failed parse)\n", ast_inet_ntoa(s->sin.sin_addr));
-				break;
-			}
-
-			ast_mutex_lock(&s->lock);
-			memcpy(req, s->inbuf, skinny_header_size);
-			bufaddr = (int *)(s->inbuf);
-			memcpy(&req->data, s->inbuf+skinny_header_size, letohl(*bufaddr)-4);
-
-			ast_mutex_unlock(&s->lock);
 
 			if (letohl(req->e) < 0) {
 				ast_log(LOG_ERROR, "Event Message is NULL from socket %d, This is bad\n", s->fd);




More information about the asterisk-commits mailing list