⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 call.cpp

📁 sipbomber - tool for testing SIP-protocol implementation (RFC3261). Current version can check only
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    CStat::instance()->computeStat(CStat::E_FAILED_UNEXPECTED_MSG);  return (abortCall());  } else {    // Do not abort call nor send anything in reply if default behavior is disabled    return true;  }}bool call::abortCall(){  int res ;  int is_inv;  if (last_send_msg != NULL) {    is_inv = !strncmp(last_send_msg, "INVITE", 6);  } else {    is_inv = false;  }    if ((toolMode != MODE_SERVER) && (msg_index > 0)) {    if ((call_established == false) && (is_inv)) {      char * src = last_recv_msg ;      char * dest   ;      char   L_msg_buffer[SIPP_MAX_MSG_SIZE];      L_msg_buffer[0] = '\0';      char * L_param = L_msg_buffer;      // Answer unexpected errors (4XX, 5XX and beyond) with an ACK       // Contributed by F. Tarek Rogers      if((src) && (get_reply_code(src) > 400)) {       sendBuffer(createSendingMessage(         (char*)"ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n"           "Via: SIP/2.0/[transport] [local_ip]:[local_port]\n"           "From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n"           "To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]\n"           "Call-ID: [call_id]\n"           "CSeq: 1 ACK\n"           "Contact: sip:sipp@[local_ip]:[local_port]\n"           "Max-Forwards: 70\n"           "Subject: Performance Test\n"           "Content-Length: 0\n\n"         , -1));      } else if (src) {        /* Call is not established and the reply is not a 4XX, 5XX */        /* And we already received a message. */        if (ack_is_pending == true) {          /* If an ACK is expected from the other side, send it           * and send a BYE afterwards                           */          ack_is_pending = false;          /* Send an ACK */          strcpy(L_param, "ACK sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n");          sprintf(L_param, "%s%s", L_param, "Via: SIP/2.0/[transport] [local_ip]:[local_port]\n");          sprintf(L_param, "%s%s", L_param, "From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n");          sprintf(L_param, "%s%s", L_param, "To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]\n");          sprintf(L_param, "%s%s", L_param, "Call-ID: [call_id]\n");          /* The CSeq of an ACK relating to an INVITE must be the same as  */          /* the one from the INVITE.                                      */          /* Let's simplify this by putting 1 (no support for re-invite in */          /* 3PCC?)                                                        */          /* FIXME: store CSeq from last INVITE and re-use it              */          sprintf(L_param, "%sCSeq: 1 ACK\n", L_param);          sprintf(L_param, "%s%s", L_param, "Contact: <sip:[local_ip]:[local_port];transport=[transport]>\n");          sprintf(L_param, "%s%s", L_param,  "Content-Length: 0\n");          res = sendBuffer(createSendingMessage((char*)(L_param),-1));                    /* Send the BYE */          strcpy(L_param, "BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n");          sprintf(L_param, "%s%s", L_param, "Via: SIP/2.0/[transport] [local_ip]:[local_port]\n");          sprintf(L_param, "%s%s", L_param, "From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n");          sprintf(L_param, "%s%s", L_param, "To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]\n");          sprintf(L_param, "%s%s", L_param, "Call-ID: [call_id]\n");          char * cseq;          cseq = compute_cseq(src);          if (cseq != NULL) {            sprintf(L_param, "%s%s BYE\n", L_param, compute_cseq(src));          }          sprintf(L_param, "%s%s", L_param, "Contact: <sip:[local_ip]:[local_port];transport=[transport]>\n");          sprintf(L_param, "%s%s", L_param,  "Content-Length: 0\n");          res = sendBuffer(createSendingMessage((char*)(L_param),-1));        } else {          /* Send a CANCEL */          strcpy(L_param, "CANCEL sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n");          sprintf(L_param, "%s%s", L_param, "Via: SIP/2.0/[transport] [local_ip]:[local_port]\n");          sprintf(L_param, "%s%s", L_param, "From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n");          sprintf(L_param, "%s%s", L_param, "To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]\n");          sprintf(L_param, "%s%s", L_param, "Call-ID: [call_id]\n");	  sprintf(L_param, "%sCSeq: 1 CANCEL\n", L_param);          sprintf(L_param, "%s%s", L_param, "Contact: <sip:[local_ip]:[local_port];transport=[transport]>\n");          sprintf(L_param, "%s%s", L_param,  "Content-Length: 0\n");          res = sendBuffer(createSendingMessage((char*)(L_param),-1));        }      } else {        /* Call is not established and the reply is not a 4XX, 5XX */        /* and we didn't received any message. This is the case when */        /* we are aborting after having send an INVITE and not received */        /* any answer. */        /* Do nothing ! */      }    } else {      /* Call is established */      char * src = last_recv_msg ;      char   L_msg_buffer[SIPP_MAX_MSG_SIZE];      L_msg_buffer[0] = '\0';      char * L_param = L_msg_buffer;      strcpy(L_param, "BYE sip:[service]@[remote_ip]:[remote_port] SIP/2.0\n");      sprintf(L_param, "%s%s", L_param, "Via: SIP/2.0/[transport] [local_ip]:[local_port]\n");      sprintf(L_param, "%s%s", L_param, "From: sipp <sip:sipp@[local_ip]:[local_port]>;tag=[call_number]\n");      sprintf(L_param, "%s%s", L_param, "To: sut <sip:[service]@[remote_ip]:[remote_port]>[peer_tag_param]\n");      sprintf(L_param, "%s%s", L_param, "Call-ID: [call_id]\n");      char * cseq;      cseq = compute_cseq(src);      if (cseq != NULL) {        sprintf(L_param, "%s%s BYE\n", L_param, compute_cseq(src));      }      sprintf(L_param, "%s%s", L_param, "Contact: <sip:[local_ip]:[local_port];transport=[transport]>\n");      sprintf(L_param, "%s%s", L_param,  "Content-Length: 0\n");      res = sendBuffer(createSendingMessage((char*)(L_param),-1));    }  }  delete_call(id);  return false;}bool call::rejectCall(){  CStat::instance()->computeStat(CStat::E_CALL_FAILED);  CStat::instance()->computeStat(CStat::E_FAILED_CALL_REJECTED);  delete_call(id);  return false;}#ifdef __3PCC__int call::sendCmdMessage(int index){  char * dest;  char delimitor[2];  delimitor[0]=27;  delimitor[1]=0;  if(scenario[index] -> M_sendCmdData) {    // WARNING_P1("---PREPARING_TWIN_CMD---%s---", scenario[index] -> M_sendCmdData);     dest = createSendingMessage(scenario[index] -> M_sendCmdData, -2);    strcat(dest, delimitor);    //WARNING_P1("---SEND_TWIN_CMD---%s---", dest);     int rc;    rc = send(twinSippSocket,               dest,               strlen(dest),               0);    if(rc <  0) {      CStat::instance()->computeStat(CStat::E_CALL_FAILED);      CStat::instance()->computeStat(CStat::E_FAILED_CMD_NOT_SENT);      delete_call(id);      return(-1);    }    return(0);  }  else    return(-1);}int call::sendCmdBuffer(char* cmd){  char * dest;  char delimitor[2];  int  rc;  delimitor[0]=27;  delimitor[1]=0;  dest = cmd ;  strcat(dest, delimitor);  rc = send(twinSippSocket,             dest,             strlen(dest),             0);  if(rc <  0) {    CStat::instance()->computeStat(CStat::E_CALL_FAILED);    CStat::instance()->computeStat(CStat::E_FAILED_CMD_NOT_SENT);    delete_call(id);    return(-1);  }  return(0);}#endifchar* call::createSendingMessage(char * src, int P_index){  static char msg_buffer[SIPP_MAX_MSG_SIZE+2];  if(src != NULL) {    char * dest = msg_buffer;    char * key;    char * length_marker = NULL;    int    offset = 0;    int    len_offset = 0;    char   current_line[MAX_HEADER_LEN];    char * line_mark = NULL;    current_line[0] = '\0';    while(*src) {      if (current_line[0] == '\0') {        line_mark = NULL;        line_mark = strchr(src, '\n');        if (line_mark) {          memcpy(current_line, src, line_mark - src);          current_line[line_mark-src] = '\0';        }      }      if(*src == '[') {        char keyword [KEYWORD_SIZE+1];        src++;        key = strchr(src, ']');        if((!key) || ((key - src) > KEYWORD_SIZE) || (!(key - src))){          ERROR("Syntax error or invalid [keyword] in scenario");        }        memcpy(keyword, src,  key - src);         keyword[key - src] = 0;        src = key + 1;	// allow +/-n for numeric variables	if ((key = strchr(keyword,'+')) || (key = strchr(keyword,'-'))) {           offset = atoi(key);           *key = 0;	} else offset = 0;        if(!strcmp(keyword, "remote_ip")) {          dest += sprintf(dest, "%s", remote_ip_escaped);        } else if(!strcmp(keyword, "remote_port")) {          dest += sprintf(dest, "%u", remote_port + offset);        } else if(!strcmp(keyword, "transport")) {          dest += sprintf(dest, "%s", TRANSPORT_TO_STRING(transport));        } else if(!strcmp(keyword, "local_ip")) {          dest += sprintf(dest, "%s", local_ip_escaped);        } else if(!strcmp(keyword, "local_ip_type")) {          dest += sprintf(dest, "%s", (local_ip_is_ipv6 ? "6" : "4"));        } else if(!strcmp(keyword, "local_port")) {          if((transport == T_UDP) && (multisocket) && (toolMode != MODE_SERVER)) {            dest += sprintf(dest, "%u", call_port + offset);          } else {            dest += sprintf(dest, "%u", local_port + offset);          }        } else if(!strcmp(keyword, "server_ip")) {          struct sockaddr_storage server_sockaddr;          sipp_socklen_t len = SOCK_ADDR_SIZE(&server_sockaddr);          getsockname(call_socket,                (sockaddr *)(void *)&server_sockaddr,                &len);          if (server_sockaddr.ss_family == AF_INET6) {            char * temp_dest;            temp_dest = (char *) malloc(INET6_ADDRSTRLEN);            memset(temp_dest,0,INET6_ADDRSTRLEN);            inet_ntop(AF_INET6,                       &((_RCAST(struct sockaddr_in6 *,&server_sockaddr))->sin6_addr),                      temp_dest,                      INET6_ADDRSTRLEN);             dest += sprintf(dest, "%s",temp_dest);          } else {            dest += sprintf(dest, "%s",             inet_ntoa((_RCAST(struct sockaddr_in *,&server_sockaddr))->sin_addr));          }                  } else if(!strcmp(keyword, "media_ip")) {          dest += sprintf(dest, "%s", media_ip_escaped);#ifdef PCAPPLAY        } else if (!strcmp(keyword, "auto_media_port")) {          /* to make media ports begin from true media_port exported from sipp.cpp, as number begins to 1           * * 4 to allow video (audio+rtcp+video+rtcp)           * Modulo 10000 to limit the port number           * -> Max 10000 concurrent RTP sessions for pcap_play            */          int port = media_port + (4 * (number - 1)) % 10000 + offset;          if (strstr(current_line, "m=audio ")) {            if (media_ip_is_ipv6) {              (_RCAST(struct sockaddr_in6 *, &(play_args_a.from)))->sin6_port = port;            } else {              (_RCAST(struct sockaddr_in *, &(play_args_a.from)))->sin_port = port;            }          } else if (strstr(current_line, "m=video ")) {          if (media_ip_is_ipv6) {              (_RCAST(struct sockaddr_in6 *, &(play_args_v.from)))->sin6_port = port;          } else {              (_RCAST(struct sockaddr_in *, &(play_args_v.from)))->sin_port = port;            }          } else {            ERROR_P1("auto_media_port keyword with no audio or video on the current line (%s)", current_line);          }          dest += sprintf(dest, "%u", port);#endif        } else if(!strcmp(keyword, "media_port")) {          int port = media_port + offset;#ifdef PCAPPLAY          if (strstr(current_line, "audio")) {            if (media_ip_is_ipv6) {              (_RCAST(struct sockaddr_in6 *, &(play_args_a.from)))->sin6_port = port;            } else {              (_RCAST(struct sockaddr_in *, &(play_args_a.from)))->sin_port = port;            }          } else if (strstr(current_line, "video")) {          if (media_ip_is_ipv6) {              (_RCAST(struct sockaddr_in6 *, &(play_args_v.from)))->sin6_port = port;            } else {              (_RCAST(struct sockaddr_in *, &(play_args_v.from)))->sin_port = port;            }          } else {            ERROR_P1("media_port keyword with no audio or video on the current line (%s)", current_line);          }#endif          dest += sprintf(dest, "%u", port);        } else if(!strcmp(keyword, "media_ip_type")) {          dest += sprintf(dest, "%s", (media_ip_is_ipv6 ? "6" : "4"));        } else if(!strcmp(keyword, "call_number")) {          dest += sprintf(dest, "%lu", number);        } else if(!strcmp(keyword, "call_id")) {          dest += sprintf(dest, "%s", id);        } else if(!strcmp(keyword, "cseq")) {          dest += sprintf(dest, "%u", cseq +offset);        } else if(!strcmp(keyword, "pid")) {          dest += sprintf(dest, "%u", pid);        } else if(!strcmp(keyword, "service")) {          dest += sprintf(dest, "%s", service);        } else if(!strncmp(keyword, "field", 5)) {            char* local_dest = dest;            getFieldFromInputFile(keyword, m_localLineNumber, dest);            if (dest == local_dest && ('\r' == *(local_dest-1) || '\n' == *(local_dest-1))) {                /* If the line begins with a field value and there                 * is nothing to add for this field,                  * Jump to the end of line in scenario. SN                  */                while((*src) && (*src != '\n')) {                    src++;                }                if(*src == '\n') {                    src++;                }            }        } else if(!strcmp(keyword, "peer_tag_param")) {          if(peer_tag && strlen(peer_tag)) {            dest += sprintf(dest, ";tag=%s", peer_tag);          }        } else if(strstr(keyword, "$")) {          int varId = atoi(keyword+1);          if(varId < SCEN_VARIABLE_SIZE) {            if(M_callVariableTable[varId] != NULL) {              if(M_callVariableTable[varId]->isSet()) {                dest += sprintf(dest, "%s",                                M_callVariableTable[varId]->                                getMatchingValue());                // WARNING_P1("VARIABLE --%s--", M_callVariableTable[varId]->getMatchingValue());              } else {                dest += sprintf(dest, "%s", "");              }            }          }        } else if(strstr(keyword, "last_")) {          char * last_header = get_last_header(keyword+5);          if(last_header) {            dest += sprintf(dest, "%s", last_header);          } else {            /* Jump to the end of line in scenario if nothing             * to insert in place of this header. */            while((*src) && (*src != '\n')) {              src++;            }            if(*src == '\n') {              src++;            }          }        } else if(strstr(keyword, "routes")) {            if (dialog_route_set) {                dest += sprintf(dest, "Route: %s", dialog_route_set);            }#ifdef _USE_OPENSSL        } else if(strstr(keyword, "authentication")) {            /* This keyword is substituted below */            dest += sprintf(dest, "[%s]", keyword);#endif        } else if(strstr(keyword, "branch")) {          /* Branch is magic cookie + call number + message index in scenario */          dest += sprintf(dest, "z9hG4bK-%lu-%d", number, P_index);        } else if(strstr(keyword, "msg_index")) {          /* Message index in scenario */          dest += sprintf(dest, "%d", P_index);        } else if(strstr(keyword, "next_url")) {          if (next_req_url) {            dest += sprintf(dest, "%s", next_req_url);          }        } else if(strstr(keyword, "len")) {            length_marker = dest;            dest += sprintf(dest, "    ");            len_offset = offset;        } else {          ERROR_P1("Unsupported keyword '%s' in xml scenario file",                   keyword);        }      } else if (*src == '\n') {        *dest++ = '\r';        *dest++ = *src++;        current_line[0] = '\0';      } else {        *dest++ = *src++;      }    }    *dest = 0;#ifdef _USE_OPENSSL    /*      * The authentication substitution must be done outside the above     * loop because auth-int will use the body (which must have already     * been keyword substituted) to build the md5 hash     */    if((src = strstr(msg_buffer, "[authentication")) && dialog_authentication) {        char my_auth_user[KEYWORD_SIZE];        char my_auth_pass[KEYWORD_SIZE];        char * tmp;        strcpy(my_auth_user, service);        strcpy(my_auth_pass, auth_password);        /* Look for optional username and password paramaters */        if(tmp = strstr(src, "username=")) {            tmp += strlen("username=");            key = tmp;            while (*key) {                if (((key - src) > KEYWORD_SIZE) || (!(key - src))) {                    ERROR("Syntax error parsing authentication paramaters");                } else if (*key == ']' || *key < 33 || *key > 126) {                    memset(my_auth_user, 0, sizeof(my_auth_user));                    strncpy(my_auth_user, tmp, key-tmp);                    break;                }                key++;            }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -