[asterisk-commits] bbryant: branch bbryant/ssl-tcp-tls r70654 - /team/bbryant/ssl-tcp-tls/channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 21 03:11:24 CDT 2007
Author: bbryant
Date: Thu Jun 21 03:11:24 2007
New Revision: 70654
URL: http://svn.digium.com/view/asterisk?view=rev&rev=70654
Log:
Sip tcp/tls support appears to function correctly.
Modified:
team/bbryant/ssl-tcp-tls/channels/chan_sip.c
Modified: team/bbryant/ssl-tcp-tls/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/bbryant/ssl-tcp-tls/channels/chan_sip.c?view=diff&rev=70654&r1=70653&r2=70654
==============================================================================
--- team/bbryant/ssl-tcp-tls/channels/chan_sip.c (original)
+++ team/bbryant/ssl-tcp-tls/channels/chan_sip.c Thu Jun 21 03:11:24 2007
@@ -1715,36 +1715,67 @@
static void *sip_tcp_helper_thread(void *data) {
struct sip_pvt *p;
struct server_instance *ser = data;
- int req_len, lockretry, nounlock;
+ int lockretry, i, j, nounlock;
char buf[1024];
struct sip_request req = { 0, };
for (;;) {
bzero(req.data, sizeof(req.data));
fgets(req.data, sizeof(req.data), ser->f);
- req_len = strlen(req.data);
-
- while (req_len < 4 || strncmp((char *)&req.data + req_len - 4, "\r\n\r\n", 4)) {
+ req.len = strlen(req.data);
+
+ while (req.len < 4 || strncmp((char *)&req.data + req.len - 4, "\r\n\r\n", 4)) {
if(!fgets(buf, sizeof(buf), ser->f))
return NULL;
- strncat(req.data, buf, sizeof(req.data) - req_len - 1);
- req_len = strlen(req.data);
- }
+ strncat(req.data, buf, sizeof(req.data) - req.len - 1);
+ req.len = strlen(req.data);
+ }
+
+ if(sip_debug_test_addr(&ser->requestor)) /* Set the debug flag early on packet level */
+ ast_set_flag(&req, SIP_PKT_DEBUG);
+ if (pedanticsipchecking)
+ req.len = lws2sws(req.data, req.len); /* Fix multiline headers */
+ if (ast_test_flag(&req, SIP_PKT_DEBUG))
+ ast_verbose("\n<--- SIP read from %s://%s:%d --->\n%s\n<------------->\n",
+ (ser->parent->tls_cfg ? "TLS" : "TCP"), ast_inet_ntoa(ser->requestor.sin_addr), ntohs(ser->requestor.sin_port), req.data);
+
+ parse_request(&req);
+ req.method = find_sip_method(req.rlPart1);
+
+ if (ast_test_flag(&req, SIP_PKT_DEBUG))
+ ast_verbose("--- (%d headers %d lines)%s ---\n", req.headers, req.lines, (req.headers + req.lines == 0) ? " Nat keepalive" : "");
+
+ if (req.headers < 2) /* Must have at least two headers */
+ return NULL;
for (lockretry = 100; lockretry > 0; lockretry--) {
ast_mutex_lock(&netlock);
/* Find the active SIP dialog or create a new one */
- p = find_call(&req, &ser->parent->sin, req.method); /* returns p locked */
+ p = find_call(&req, &ser->requestor, req.method); /* returns p locked */
if (p == NULL) {
ast_debug(1, "Invalid SIP message - rejected , no callid, len %d\n", req.len);
+
+ for(i=0;i<req.len;i+=16) {
+ char tmp[17];
+ bzero(tmp, sizeof(tmp));
+
+ for(j=i;j<i+16 && j < req.len;j++) {
+ printf("0x%02x ", req.data[j]);
+ tmp[j-i] = req.data[j];
+ }
+
+ printf("%s\n", tmp);
+ }
+
ast_mutex_unlock(&netlock);
return NULL;
}
p->transport = (ser->parent->tls_cfg) ? SIP_TRANSPORT_TLS : SIP_TRANSPORT_TCP;
+ p->ser = data;
/* Go ahead and lock the owner if it has one -- we may need it */
/* becaues this is deadlock-prone, we need to try and unlock if failed */
if (!p->owner || !ast_channel_trylock(p->owner))
@@ -1756,7 +1787,7 @@
usleep(1);
}
- p->recv = ser->parent->sin;
+ p->recv = ser->requestor;
if (!lockretry) {
if (p->owner)
@@ -1769,7 +1800,7 @@
return NULL;
}
- handle_request_do(p, &req, &ser->parent->sin, &nounlock);
+ handle_request_do(p, &req, &ser->requestor, &nounlock);
if (p->owner && !nounlock)
ast_channel_unlock(p->owner);
@@ -2035,7 +2066,7 @@
int fd;
const struct sockaddr_in *dst = sip_real_dst(p);
- fd = (p->transport & SIP_TRANSPORT_UDP) ? sipsock : p->ser->parent->accept_fd;
+ fd = (p->transport & SIP_TRANSPORT_UDP) ? sipsock : p->ser->fd;
res = sendto(fd, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in));
@@ -2061,8 +2092,7 @@
const char *rport = ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_RFC3581 ? ";rport" : "";
/* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */
- ast_string_field_build(p, via, "%s/2.0/%s %s:%d;branch=z9hG4bK%08x%s",
- ((p->transport & SIP_TRANSPORT_TLS) ? "SIPS" : "SIP"),
+ ast_string_field_build(p, via, "SIP/2.0/%s %s:%d;branch=z9hG4bK%08x%s",
get_transport(p), ast_inet_ntoa(p->ourip), ourport, p->branch, rport);
}
@@ -15836,9 +15866,7 @@
if (pedanticsipchecking)
req.len = lws2sws(req.data, req.len); /* Fix multiline headers */
if (ast_test_flag(&req, SIP_PKT_DEBUG))
- ast_verbose("\n<--- SIP read from %s://%s:%d %s--->\n%s\n<------------->\n",
- get_transport(p), ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port),
- ((p->transport & SIP_TRANSPORT_TLS) ? "(Secure) " : ""), req.data);
+ ast_verbose("\n<--- SIP read from udp://%s:%d --->\n%s\n<------------->\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), req.data);
parse_request(&req);
req.method = find_sip_method(req.rlPart1);
@@ -15894,7 +15922,7 @@
}
static char *get_transport(struct sip_pvt *p) {
- char *str = (p->transport & SIP_TRANSPORT_UDP) ? "UDP" : "TCP";
+ char *str = (p->transport & SIP_TRANSPORT_UDP) ? "UDP" : (p->transport & SIP_TRANSPORT_TCP) ? "TCP" : "TLS";
return ast_strdup(str);
}
More information about the asterisk-commits
mailing list