From 93ffcf1ce65475bd21c0d501656d00266e850cc3 Mon Sep 17 00:00:00 2001 From: nils-ohlmeier Date: Wed, 12 Sep 2007 11:13:44 +0000 Subject: [PATCH] - fixed false retransmissions because of wrong cseq in reply - enabled -c parameter for Inivte mode git-svn-id: http://svn.berlios.de/svnroot/repos/sipsak/trunk@439 75b5f7c7-cfd4-0310-b54c-e118b2c5249a (cherry picked from commit 00ccbe03d433cb4e60dce942f74795a3e1f10638) (cherry picked from commit a63ab0e7ca4ab83958718a78a03b8f6ded0718ec) --- header_f.c | 22 +++++++++++++++++++--- header_f.h | 4 ++-- request.c | 18 ++++++++++++++---- shoot.c | 8 ++++---- transport.c | 2 +- 5 files changed, 40 insertions(+), 14 deletions(-) diff --git a/header_f.c b/header_f.c index 5fd4222..c6ec9b5 100644 --- a/header_f.c +++ b/header_f.c @@ -431,7 +431,7 @@ int cseq(char *message) } /* if it find the Cseq number in the message it will increased by one */ -void increase_cseq(char *message) +void increase_cseq(char *message, char *reply) { int cs; char *cs_s, *eol, *backup; @@ -460,6 +460,22 @@ void increase_cseq(char *message) } else if (verbose > 1) printf("'CSeq' not found in message\n"); + if (reply != NULL) { + cs_s=STRCASESTR(reply, CSEQ_STR); + if (cs_s) { + cs_s+=6; + eol=strchr(cs_s, ' '); + eol++; + backup=str_alloc(strlen(eol)+1); + strncpy(backup, eol, (size_t)(strlen(eol))); + snprintf(cs_s, 11, "%i ", cs); + cs_s+=strlen(cs_s); + strncpy(cs_s, backup, strlen(backup)); + free(backup); + } + else if (verbose > 1) + printf("'CSeq' not found in reply\n"); + } } /* separates the given URI into the parts by setting the pointer but it @@ -582,9 +598,9 @@ void new_branch(char *message) } /* increase the CSeq and insert a new branch value */ -void new_transaction(char *message) +void new_transaction(char *message, char *reply) { - increase_cseq(message); + increase_cseq(message, reply); new_branch(message); } diff --git a/header_f.h b/header_f.h index 19d22b4..86aee1d 100644 --- a/header_f.h +++ b/header_f.h @@ -49,7 +49,7 @@ void warning_extract(char *message); int cseq(char *message); -void increase_cseq(char *message); +void increase_cseq(char *message, char *reply); void parse_uri(char *uri, char **scheme, char **user, char **host, int *port); @@ -57,7 +57,7 @@ char* uri_from_contact(char *message); void new_branch(char *message); -void new_transaction(char *message); +void new_transaction(char *message, char *reply); void print_message_line(char *message); diff --git a/request.c b/request.c index 59af77c..68f3e6f 100644 --- a/request.c +++ b/request.c @@ -122,7 +122,6 @@ void create_msg(int action, char *req_buff, char *repl_buff, char *username, int case REQ_INV: sprintf(req_buff, "%s sip:%s%s%s" - "%ssip:sipsak@%s:%i;tag=%x\r\n" "%ssip:%s%s\r\n" "%s%u@%s\r\n" "%s%i %s\r\n" @@ -130,10 +129,8 @@ void create_msg(int action, char *req_buff, char *repl_buff, char *username, int "%ssip:sipsak@%s:%i\r\n" "%sDONT ANSWER this test call!\r\n" "%s70\r\n" - "%s%s\r\n" - "\r\n", + "%s%s\r\n", INV_STR, username, domainname, SIP20_STR, - FROM_STR, fqdn, lport, c, TO_STR, username, domainname, CALL_STR, c, fqdn, CSEQ_STR, cseq, INV_STR, @@ -142,6 +139,19 @@ void create_msg(int action, char *req_buff, char *repl_buff, char *username, int SUB_STR, MAX_FRW_STR, UA_STR, UA_VAL_STR); + req_buff += strlen(req_buff); + if (from_uri) { + sprintf(req_buff, + "%s%s;tag=%x\r\n" + "\r\n", + FROM_STR, from_uri, c); + } + else { + sprintf(req_buff, + "%ssip:sipsak@%s:%i;tag=%x\r\n" + "\r\n", + FROM_STR, fqdn, lport, c); + } add_via(req_buf_begin); sprintf(repl_buff, "%s" diff --git a/shoot.c b/shoot.c index 7a86d86..a99233a 100644 --- a/shoot.c +++ b/shoot.c @@ -120,7 +120,7 @@ void handle_3xx(struct sockaddr_in *tadr) } /* correct our request */ uri_replace(req, contact); - new_transaction(req); + new_transaction(req, rep); /* extract the needed information*/ rport = 0; address = 0; @@ -275,7 +275,7 @@ void handle_default() } else { counters.run++; - new_transaction(req); + new_transaction(req, rep); delays.retryAfter = timer_t1; } } @@ -1023,7 +1023,7 @@ void shoot(char *buf, int buff_size) exit_code(0, __PRETTY_FUNCTION__, NULL); } counters.run++; - new_transaction(req); + new_transaction(req, rep); delays.retryAfter = timer_t1; continue; } @@ -1037,7 +1037,7 @@ void shoot(char *buf, int buff_size) insert_auth(req, rec); if (verbose > 2) printf("\nreceived:\n%s\n", rec); - new_transaction(req); + new_transaction(req, rep); continue; } /* if auth...*/ /* lets see if received a redirect */ diff --git a/transport.c b/transport.c index c3ced07..9eb7562 100644 --- a/transport.c +++ b/transport.c @@ -820,7 +820,7 @@ int check_for_message(char *recv, int size, struct sipsak_con_data *cd, count->run++; sd->all_delay += senddiff; sd->big_delay = senddiff; - new_transaction(req); + new_transaction(req, rep); sd->retryAfter = timer_t1; if (timing == 0) { printf("%.3f/%.3f/%.3f ms\n", sd->small_delay, sd->all_delay / count->run, sd->big_delay);