Skip to content

Commit

Permalink
Merge pull request #552 from orgads/map-params
Browse files Browse the repository at this point in the history
Use an unordered map for user params
  • Loading branch information
lemenkov authored Jan 12, 2024
2 parents c9f6f0f + 63f297f commit 7787c9c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 22 deletions.
4 changes: 3 additions & 1 deletion include/sipp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include <string>
#include <map>
#include <set>
#include <unordered_map>
#include <math.h>
#ifdef __SUNOS
#include <stdarg.h>
Expand Down Expand Up @@ -296,7 +297,8 @@ MAYBE_EXTERN int currentRepartitionToDisplay DEFVAL(1);
MAYBE_EXTERN unsigned int base_cseq DEFVAL(0);
MAYBE_EXTERN char * auth_uri DEFVAL(0);
MAYBE_EXTERN const char * call_id_string DEFVAL("%u-%p@%s");
MAYBE_EXTERN char **generic[100];
typedef std::unordered_map<std::string, std::string> ParamMap;
MAYBE_EXTERN ParamMap generic;

MAYBE_EXTERN bool rtp_echo_state DEFVAL(true);
MAYBE_EXTERN bool callidSlash DEFVAL(false);
Expand Down
19 changes: 6 additions & 13 deletions src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,19 +349,12 @@ SendingMessage::SendingMessage(scenario* msg_scenario, const char* const_src, bo
parseAuthenticationKeyword(msg_scenario, newcomp, keyword);
} else {
// scan for the generic parameters - must be last test
int i = 0;
while (generic[i]) {
char *msg1 = *generic[i];
char *msg2 = *(generic[i] + 1);
if(!strcmp(keyword, msg1)) {
newcomp->type = E_Message_Literal;
newcomp->literal = strdup(msg2);
newcomp->literalLen = strlen(newcomp->literal);
break;
}
++i;
}
if (!generic[i]) {
auto gen = generic.find(keyword);
if (gen != generic.end()) {
newcomp->type = E_Message_Literal;
newcomp->literal = strdup((*gen).second.c_str());
newcomp->literalLen = strlen(newcomp->literal);
} else {
ERROR("Unsupported keyword '%s' in xml scenario file",
keyword);
}
Expand Down
9 changes: 1 addition & 8 deletions src/sipp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1318,16 +1318,13 @@ int main(int argc, char *argv[])
{
int argi = 0;
pthread_t pthread2_id = 0, pthread3_id = 0;
unsigned int generic_count = 0;
bool slave_masterSet = false;
int rtp_errors;
int echo_errors;

rtp_errors = 0;
echo_errors = 0;

generic[0] = NULL;

/* At least one argument is needed */
if (argc < 2) {
help();
Expand Down Expand Up @@ -1641,11 +1638,7 @@ int main(int argc, char *argv[])
REQUIRE_ARG();
CHECK_PASS();

if (generic_count + 1 >= sizeof(generic)/sizeof(generic[0])) {
ERROR("Too many generic parameters %d",generic_count + 1);
}
generic[generic_count++] = &argv[argi - 1];
generic[generic_count] = NULL;
generic[argv[argi - 1]] = argv[argi];
break;
case SIPP_OPTION_VAR:
REQUIRE_ARG();
Expand Down

0 comments on commit 7787c9c

Please sign in to comment.