From: <cha...@us...> - 2008-09-22 15:46:32
|
Revision: 536 http://sipp.svn.sourceforge.net/sipp/?rev=536&view=rev Author: charlespwright Date: 2008-09-22 15:43:59 +0000 (Mon, 22 Sep 2008) Log Message: ----------- Enh: Allow sending of NUL characters inside of literals (Provided by Andy Aicken). Modified Paths: -------------- sipp/trunk/call.cpp sipp/trunk/call.hpp sipp/trunk/message.cpp sipp/trunk/message.hpp Modified: sipp/trunk/call.cpp =================================================================== --- sipp/trunk/call.cpp 2008-09-22 15:12:06 UTC (rev 535) +++ sipp/trunk/call.cpp 2008-09-22 15:43:59 UTC (rev 536) @@ -34,6 +34,7 @@ * Marc Van Diest from Belgacom * Michael Dwyer from Cibation * Roland Meub + * Andy Aicken */ #include <iterator> @@ -364,6 +365,7 @@ msg_index = 0; last_send_index = 0; last_send_msg = NULL; + last_send_len = 0; last_recv_hash = 0; last_recv_index = -1; @@ -818,7 +820,7 @@ return (((double)rand() / (double)RAND_MAX) < (percent / 100.0)); } -int call::send_raw(char * msg, int index) +int call::send_raw(char * msg, int index, int len) { struct sipp_socket *sock; int rc; @@ -878,9 +880,14 @@ sock=call_remote_socket ; } + // If the length hasn't been explicitly specified, treat the message as a string + if (len==0) { + len = strlen(msg); + } + assert(sock); - rc = write_socket(sock, msg, strlen(msg), WS_BUFFER, &call_peer); + rc = write_socket(sock, msg, len, WS_BUFFER, &call_peer); if(rc == -1 && errno == EWOULDBLOCK) { return -1; } @@ -896,10 +903,10 @@ /* This method is used to send messages that are not */ /* part of the XML scenario */ -void call::sendBuffer(char * msg) +void call::sendBuffer(char * msg, int len) { /* call send_raw but with a special scenario index */ - if (send_raw(msg, -1) < 0) { + if (send_raw(msg, -1, len) < 0) { if (sendbuffer_warn) { ERROR_NO("Error sending raw message"); } else { @@ -1182,10 +1189,8 @@ } -char * call::send_scene(int index, int *send_status) +char * call::send_scene(int index, int *send_status, int *len) { - static char msg_buffer[SIPP_MAX_MSG_SIZE]; - #define MAX_MSG_NAME_SIZE 30 static char msg_name[MAX_MSG_NAME_SIZE]; char *L_ptr1 ; @@ -1209,12 +1214,11 @@ assert(call_scenario->messages[index]->send_scheme); char * dest; - dest = createSendingMessage(call_scenario->messages[index] -> send_scheme, index); - strcpy(msg_buffer, dest); + dest = createSendingMessage(call_scenario->messages[index] -> send_scheme, index, len); if (dest) { L_ptr1=msg_name ; - L_ptr2=msg_buffer ; + L_ptr2=dest ; while ((*L_ptr2 != ' ') && (*L_ptr2 != '\n') && (*L_ptr2 != '\t')) { *L_ptr1 = *L_ptr2; L_ptr1 ++; @@ -1228,9 +1232,9 @@ ack_is_pending = false ; } - *send_status = send_raw(msg_buffer, index); + *send_status = send_raw(dest, index, *len); - return msg_buffer; + return dest; } void call::do_bookkeeping(message *curmsg) { @@ -1414,6 +1418,7 @@ else if(curmsg -> send_scheme) { char * msg_snd; + int msgLen; int send_status; /* Do not send a new message until the previous one which had @@ -1441,7 +1446,7 @@ incr_cseq = 1; } - msg_snd = send_scene(msg_index, &send_status); + msg_snd = send_scene(msg_index, &send_status, &msgLen); if(send_status == -1 && errno == EWOULDBLOCK) { if (incr_cseq) --cseq; /* Have we set the timeout yet? */ @@ -1476,8 +1481,10 @@ send_timeout = 0; last_send_index = curmsg->index; - last_send_msg = (char *) realloc(last_send_msg, strlen(msg_snd) + 1); - strcpy(last_send_msg, msg_snd); + last_send_len = msgLen; + last_send_msg = (char *) realloc(last_send_msg, msgLen+1); + memcpy(last_send_msg, msg_snd, msgLen); + last_send_msg[msgLen] = '\0'; if (curmsg->start_txn) { transactions[curmsg->start_txn - 1].txnID = (char *)realloc(transactions[curmsg->start_txn - 1].txnID, MAX_HEADER_LEN); @@ -1677,7 +1684,7 @@ nb_last_delay = DEFAULT_T2_TIMER_VALUE; } } - if(send_raw(last_send_msg, last_send_index) < -1) { + if(send_raw(last_send_msg, last_send_index, last_send_len) < -1) { return false; } call_scenario->messages[last_send_index] -> nb_sent_retrans++; @@ -2032,12 +2039,12 @@ } -char* call::createSendingMessage(SendingMessage *src, int P_index) { +char* call::createSendingMessage(SendingMessage *src, int P_index, int *msgLen) { static char msg_buffer[SIPP_MAX_MSG_SIZE+2]; - return createSendingMessage(src, P_index, msg_buffer, sizeof(msg_buffer)); + return createSendingMessage(src, P_index, msg_buffer, sizeof(msg_buffer), msgLen); } -char* call::createSendingMessage(SendingMessage *src, int P_index, char *msg_buffer, int buf_len) +char* call::createSendingMessage(SendingMessage *src, int P_index, char *msg_buffer, int buf_len, int *msgLen) { char * length_marker = NULL; char * auth_marker = NULL; @@ -2060,7 +2067,9 @@ dest += snprintf(dest, left, "%s", ptr); supresscrlf = false; } else { - dest += snprintf(dest, left, "%s", comp->literal); + memcpy(dest, comp->literal, comp->literalLen); + dest += comp->literalLen; + *dest = '\0'; } break; case E_Message_Remote_IP: @@ -2457,6 +2466,10 @@ SendingMessage::freeMessageComponent(auth_comp); } + if (msgLen != NULL) { + *msgLen = dest - msg_buffer; + } + return msg_buffer; } @@ -2888,7 +2901,7 @@ call_scenario->messages[recv_retrans_recv_index] -> nb_recv_retrans++; - send_scene(recv_retrans_send_index, &status); + send_scene(recv_retrans_send_index, &status, NULL); if(status >= 0) { call_scenario->messages[recv_retrans_send_index] -> nb_sent_retrans++; Modified: sipp/trunk/call.hpp =================================================================== --- sipp/trunk/call.hpp 2008-09-22 15:12:06 UTC (rev 535) +++ sipp/trunk/call.hpp 2008-09-22 15:43:59 UTC (rev 536) @@ -16,6 +16,7 @@ * Author : Richard GAYRAUD - 04 Nov 2003 * From Hewlett Packard Company. * Charles P. Wright from IBM Research + * Andy Aicken */ #ifndef __CALL__ @@ -124,6 +125,7 @@ * are kept in this index.) */ int last_send_index; char * last_send_msg; + int last_send_len; /* How long until sending this message times out. */ unsigned int send_timeout; @@ -228,9 +230,9 @@ // P_index use for message index in scenario and ctrl of CRLF // P_index = -2 No ctrl of CRLF // P_index = -1 Add crlf to end of message - char* createSendingMessage(SendingMessage *src, int P_index); + char* createSendingMessage(SendingMessage *src, int P_index, int *msgLen=NULL); char* createSendingMessage(char * src, int P_index, bool skip_sanity = false); - char* createSendingMessage(SendingMessage *src, int P_index, char *msg_buffer, int buflen); + char* createSendingMessage(SendingMessage *src, int P_index, char *msg_buffer, int buflen, int *msgLen=NULL); // method for the management of unexpected messages bool checkInternalCmd(char* cmd); // check of specific internal command @@ -241,7 +243,7 @@ int search_index); // 3pcc extended mode:check if // the twin message received // comes from the expected sender - void sendBuffer(char *buf); // send a message out of a scenario + void sendBuffer(char *buf, int len = 0); // send a message out of a scenario // execution T_AutoMode checkAutomaticResponseMode(char * P_recv); @@ -270,8 +272,8 @@ void extract_cseq_method (char* responseCseq, char* msg); void extract_transaction (char* txn, char* msg); - int send_raw(char * msg, int index); - char * send_scene(int index, int *send_status); + int send_raw(char * msg, int index, int len); + char * send_scene(int index, int *send_status, int *msgLen); bool connect_socket_if_needed(); char * compute_cseq(char * src); Modified: sipp/trunk/message.cpp =================================================================== --- sipp/trunk/message.cpp 2008-09-22 15:12:06 UTC (rev 535) +++ sipp/trunk/message.cpp 2008-09-22 15:43:59 UTC (rev 536) @@ -33,6 +33,7 @@ * Ben Evans from Open Cloud * Marc Van Diest from Belgacom * Stefan Esser + * Andy Aicken */ #include "sipp.hpp" @@ -86,6 +87,7 @@ SendingMessage::SendingMessage(scenario *msg_scenario, char *src, bool skip_sanity) { char *osrc = src; char * literal; + int literalLen; char * dest; char * key; char current_line[MAX_HEADER_LEN]; @@ -96,6 +98,7 @@ this->msg_scenario = msg_scenario; dest = literal = (char *)malloc(strlen(src) + num_cr + 1); + literalLen = 0; current_line[0] = '\0'; *dest = 0; @@ -132,7 +135,8 @@ } else { /* We have found a keyword, store the literal that we have been generating. */ *dest = '\0'; - literal = (char *)realloc(literal, strlen(literal) + 1); + literalLen = dest - literal; + literal = (char *)realloc(literal, literalLen); if (!literal) { ERROR("Out of memory!"); } MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); @@ -140,9 +144,11 @@ newcomp->type = E_Message_Literal; newcomp->literal = literal; + newcomp->literalLen = literalLen; // length without the terminator messageComponents.push_back(newcomp); dest = literal = (char *)malloc(strlen(src) + num_cr + 1); + literalLen = 0; *dest = '\0'; /* Now lets determine which keyword we have. */ @@ -275,6 +281,7 @@ getKeywordParam(keyword, "variable=", varName); newcomp->literal = strdup(filltext); + newcomp->literalLen = strlen(newcomp->literal); if (!msg_scenario) { ERROR("SendingMessage with variable usage outside of scenario!"); } @@ -282,6 +289,7 @@ } else if(!strncmp(keyword, "last_", strlen("last_"))) { newcomp->type = E_Message_Last_Header; newcomp->literal = strdup(keyword + strlen("last_")); + newcomp->literalLen = strlen(newcomp->literal); } else if(!strncmp(keyword, "authentication", strlen("authentication"))) { parseAuthenticationKeyword(msg_scenario, newcomp, keyword); } @@ -308,6 +316,7 @@ if(!strcmp(keyword, msg1)) { newcomp->type = E_Message_Literal; newcomp->literal = strdup(msg2); + newcomp->literalLen = strlen(newcomp->literal); break; } ++i; @@ -323,7 +332,8 @@ } if (literal[0]) { *dest++ = '\0'; - literal = (char *)realloc(literal, strlen(literal) + 1); + literalLen = dest - literal; + literal = (char *)realloc(literal, literalLen); if (!literal) { ERROR("Out of memory!"); } MessageComponent *newcomp = (MessageComponent *)calloc(1, sizeof(MessageComponent)); @@ -331,6 +341,7 @@ newcomp->type = E_Message_Literal; newcomp->literal = literal; + newcomp->literalLen = literalLen-1; messageComponents.push_back(newcomp); } else { free(literal); Modified: sipp/trunk/message.hpp =================================================================== --- sipp/trunk/message.hpp 2008-09-22 15:12:06 UTC (rev 535) +++ sipp/trunk/message.hpp 2008-09-22 15:43:59 UTC (rev 536) @@ -32,6 +32,7 @@ * Jan Andres from Freenet * Ben Evans from Open Cloud * Marc Van Diest from Belgacom + * Andy Aicken */ #ifndef __MESSAGE__ @@ -124,6 +125,7 @@ struct MessageComponent { MessageCompType type; char *literal; + int literalLen; int offset; int varId; union u { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |