[libss7-commits] mattf: branch mattf/bug13495 r246 - /team/mattf/bug13495/
SVN commits to the libss7 project
libss7-commits at lists.digium.com
Tue Dec 23 11:52:13 CST 2008
Author: mattf
Date: Tue Dec 23 11:52:12 2008
New Revision: 246
URL: http://svn.digium.com/view/libss7?view=rev&rev=246
Log:
Add support for working client side TCP! Note: the message format will change, this is only for testing the socket code to make sure we have good read/write socket servicing code.
Modified:
team/mattf/bug13495/isup_masq.c
team/mattf/bug13495/mtp2.h
team/mattf/bug13495/ss7.c
Modified: team/mattf/bug13495/isup_masq.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/isup_masq.c?view=diff&rev=246&r1=245&r2=246
==============================================================================
--- team/mattf/bug13495/isup_masq.c (original)
+++ team/mattf/bug13495/isup_masq.c Tue Dec 23 11:52:12 2008
@@ -38,6 +38,24 @@
return;
}
+
+static int isup_ip_dump(struct mtp2 *link, char prefix, unsigned char * msg, int len)
+{
+
+ if (!(link->master->debug & SS7_DEBUG_MTP2))
+ return 0;
+
+ ss7_dump_msg(link->master, msg, len);
+
+ ss7_message(link->master, "%c\n", prefix);
+
+ if (prefix == '<')
+ mtp3_dump(link->master, NULL, &msg[1], len - 1);
+ else
+ mtp3_dump(link->master, NULL, &msg[0], len);
+
+ return 0;
+}
static int isup_ip_receive_buffer(struct mtp2 *mtp2, unsigned char *msg, int len)
{
@@ -63,10 +81,7 @@
return 0;
case 5: /*This is the case for all ISUP messages such as IAM's, RLC,ANMs,ACMs..etc */
newmsg = &buf[1]; /*Get the buf minus the event byte */
- if (mtp2->master->debug > 0) { /* Send data to be decode for debug */
- ss7_message(mtp2->master, "<\n");
- mtp3_dump(mtp2->master,NULL, (void *)newmsg, len-1);
- }
+ isup_ip_dump(mtp2, '<', msg, len);
mtp3_receive(mtp2->master, mtp2, (void *)newmsg, len-1);
return 1;
default:
@@ -76,9 +91,10 @@
static int get_msg_length(struct mtp2 *mtp2)
{
- char lenbuf[10] = {0,};
- int i = 0;
-
+ char lenbuf[1];
+ int res;
+
+#if 0
do {
if (read(mtp2->fd, &lenbuf[i++], 1) < 0) {
ss7_message(mtp2->master, "Read returned -1in get_msg_length\n");
@@ -92,8 +108,21 @@
}
sscanf(lenbuf, "%d", &i);
-
- return i;
+#endif
+ res = read(mtp2->fd, lenbuf, sizeof(lenbuf));
+
+ if (res != 1) {
+ ss7_message(mtp2->master, "Read len of %d:%s\n", res, strerror(errno));
+ return -1;
+ }
+
+ if ((res < 0) && (errno == 104)) {
+ ss7_message(mtp2->master, "Link dropped\n");
+ return -1;
+ }
+
+
+ return lenbuf[0];
}
#if 0
@@ -117,29 +146,44 @@
int len;
int res = -1;
- len = get_msg_length(mtp2);
-
- if (len < 0)
- return -1;
-
- res = read(mtp2->fd, msg, len);
+ if (mtp2->tcpreadstate == TCPSTATE_NEED_LEN) {
+ len = get_msg_length(mtp2);
+
+ if (len < 0)
+ return -1;
+ mtp2->tcplen = len;
+ mtp2->tcpreadstate = TCPSTATE_NEED_MSG;
+ } else {
+ len = mtp2->tcplen;
+
+ res = read(mtp2->fd, msg, len);
+
+ if ((res < 0) && (errno == 104)) {
+ ss7_message(mtp2->master, "Link dropped\n");
+ }
+
#if 0
if (res == 0) {
isup_ip_link_down(mtp2);
}
#endif
- if (res < 0) {
- ss7_message(mtp2->master, "Read problem from socket: %s\n", strerror(errno));
- return -1;
- }
-
- if (res != len) {
- ss7_message(mtp2->master, "Short read from socket (%d): %s\n", res, strerror(errno));
- return -1;
- }
-
- res = isup_ip_receive_buffer(mtp2, msg, len);
+ if (res < 0) {
+ ss7_message(mtp2->master, "Read problem from socket: %s\n", strerror(errno));
+ return -1;
+ }
+
+ if (res != len) {
+ ss7_message(mtp2->master, "Short read from socket (%d): %s\n", res, strerror(errno));
+ return -1;
+ }
+
+ msg[res] = 0;
+
+ res = isup_ip_receive_buffer(mtp2, msg, len);
+
+ mtp2->tcpreadstate = TCPSTATE_NEED_LEN;
+ }
return res;
}
@@ -187,11 +231,8 @@
static int isup_ip_send(struct mtp2 *mtp2, unsigned char *data, int len)
{
int i;
-
- if (mtp2->master->debug > 0) { /* Send data to be decode for debug */
- ss7_message(mtp2->master, ">\n");
- mtp3_dump(mtp2->master, mtp2, data, len);
- }
+
+ isup_ip_dump(mtp2, '>', data, len);
/* Send the length of entire ISUP message first */
i = isup_carefulwrite(mtp2->fd, itoa(len,10), 4, 50);
Modified: team/mattf/bug13495/mtp2.h
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/mtp2.h?view=diff&rev=246&r1=245&r2=246
==============================================================================
--- team/mattf/bug13495/mtp2.h (original)
+++ team/mattf/bug13495/mtp2.h Tue Dec 23 11:52:12 2008
@@ -106,6 +106,9 @@
int t7;
};
+#define TCPSTATE_NEED_LEN 0
+#define TCPSTATE_NEED_MSG 1
+
struct mtp2 {
int state;
int std_test_passed;
@@ -157,6 +160,10 @@
struct adjacent_sp *adj_sp;
unsigned char cb_seq;
struct ss7 *master;
+
+ /* Some TCP specific variables */
+ int tcplen;
+ int tcpreadstate;
};
/* Flags for the struct mtp2 flags parameter */
Modified: team/mattf/bug13495/ss7.c
URL: http://svn.digium.com/view/libss7/team/mattf/bug13495/ss7.c?view=diff&rev=246&r1=245&r2=246
==============================================================================
--- team/mattf/bug13495/ss7.c (original)
+++ team/mattf/bug13495/ss7.c Tue Dec 23 11:52:12 2008
@@ -285,6 +285,7 @@
if ((transport == SS7_TRANSPORT_DAHDIDCHAN) || (transport == SS7_TRANSPORT_DAHDIMTP2) ||
(transport == SS7_TRANSPORT_TCP)) {
+
if (slc > -1)
m->slc = slc;
else
@@ -305,6 +306,7 @@
if (transport == SS7_TRANSPORT_TCP) {
ss7->links[ss7->numlinks - 1]->adj_sp->state = MTP3_UP;
ss7->mtp2_linkstate[ss7->numlinks - 1] = MTP2_LINKSTATE_UP;
+ ss7->links[ss7->numlinks - 1]->tcpreadstate = TCPSTATE_NEED_LEN;
}
} else {
More information about the libss7-commits
mailing list