📄 call.cpp
字号:
} if(tmp = strstr(src, "password=")) { tmp += strlen("password="); 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_pass, 0, sizeof(my_auth_pass)); strncpy(my_auth_pass, tmp, key-tmp); break; } key++; } } /* Need the Method name from the CSeq of the Challenge */ char method[MAX_HEADER_LEN]; tmp = get_last_header("CSeq") + 5; if(!tmp) { ERROR("Could not extract method from cseq of challenge"); } while(isspace(*tmp) || isdigit(*tmp)) tmp++; sscanf(tmp,"%s", &method); /* Need the body for auth-int calculation */ char body[SIPP_MAX_MSG_SIZE]; memset(body, 0, sizeof(body)); tmp = msg_buffer; while(*(tmp+4)) { if (*tmp == '\r' && *(tmp + 1) == '\n' && *(tmp + 2) == '\r' && *(tmp + 3) == '\n') { sprintf(body, "%s", tmp+4); break; } tmp++; } /* Build the auth credenticals */ char result[MAX_HEADER_LEN]; char uri[MAX_HEADER_LEN]; sprintf (uri, "%s:%d", remote_ip, remote_port); if (createAuthHeader(my_auth_user, my_auth_pass, method, uri, body, dialog_authentication, result) == 0) { ERROR_P1("%s", result); } char tmp_buffer[SIPP_MAX_MSG_SIZE]; dest = strncpy(tmp_buffer, msg_buffer, src - msg_buffer); dest += src - msg_buffer; key = strchr(src, ']'); src += key - src + 1; if (dialog_challenge_type == 401) { /* Registrars use Authorization */ dest += sprintf(dest, "Authorization: %s", result); } else { /* Proxies use Proxy-Authorization */ dest += sprintf(dest, "Proxy-Authorization: %s", result); } dest += sprintf(dest, "%s", src); strcpy(msg_buffer, tmp_buffer); dest = msg_buffer + strlen(msg_buffer); }#endif // Remove all \r, \n but 1 at the end of a message to send int len = strlen(msg_buffer); while ( (msg_buffer[len-1] == '\n') && (msg_buffer[len-2] == '\r') && (msg_buffer[len-3] == '\n') && (msg_buffer[len-4] == '\r')) { msg_buffer[len-2] = 0; len -= 2; } int L_flag_crlf = 0 ; // don't need add crlf int L_content_length = 0; if(P_index == -1 ) { L_flag_crlf = 1 ; // Add crlf } else if(P_index >= 0 ) { message::ContentLengthFlag L_flag_content = scenario[P_index] -> content_length_flag ; switch (L_flag_content) { case message::ContentLengthValueZero : L_flag_crlf = 1; break ; case message::ContentLengthValueNoZero : // the msg contains content-length field and his value is greater than 0 break ; default : // the msg does not contain content-length field // control the crlf L_content_length = xp_get_content_length(msg_buffer) ; if( L_content_length == 0) { L_flag_crlf = 1; } else if (L_content_length == -1 ) { // The content_length is not present: its a [len] keyword } break; } } if(L_flag_crlf) { // Add crlf msg_buffer[len] ='\r'; msg_buffer[len+1] ='\n'; msg_buffer[len+2] =0; } if (length_marker) { key = strstr(length_marker,"\r\n\r\n"); if (key && dest - key > 4 && dest - key < 10004) { char tmp = length_marker[4]; sprintf(length_marker, "%4u", dest - key - 4 + len_offset); length_marker[4] = tmp; } else { // Other cases: Content-Length is 0 sprintf(length_marker, " 0\r\n\r\n"); } } } else { ERROR("Unsupported 'send' message in scenario"); } return(msg_buffer);}#ifdef __3PCC__bool call::process_twinSippCom(char * msg){ int search_index; bool found = false; T_ActionResult actionResult; if (checkInternalCmd(msg) == false) { for(search_index = msg_index; search_index < scenario_len; search_index++) { if(scenario[search_index] -> M_type != MSG_TYPE_RECVCMD) { if(scenario[search_index] -> optional) { continue; } /* The received message is different from the expected one */ return rejectCall(); } else { found = true; break; } } if (found) { scenario[search_index]->M_nbCmdRecv ++; // variable treatment // WARNING_P1("---RECVD_TWIN_CMD---%s---", msg); // Remove \r, \n at the end of a received command // (necessary for transport, to be removed for usage) while ( (msg[strlen(msg)-1] == '\n') && (msg[strlen(msg)-2] == '\r') ) { msg[strlen(msg)-2] = 0; } // WARNING_P1("---RECVD_TWIN_CMD AFTER---%s---", msg); actionResult = executeAction(msg, search_index); if(actionResult != call::E_AR_NO_ERROR) { // Store last action result if it is an error // and go on with the scenario call::last_action_result = actionResult; if (actionResult == E_AR_STOP_CALL) { return rejectCall(); } } } else { return rejectCall(); } return(next()); } else { return (false); }}bool call::checkInternalCmd(char * cmd){ char * L_ptr1, * L_ptr2, L_backup; L_ptr1 = strstr(cmd, "internal-cmd:"); if (!L_ptr1) {return (false);} L_ptr1 += 13 ; while((*L_ptr1 == ' ') || (*L_ptr1 == '\t')) { L_ptr1++; } if (!(*L_ptr1)) {return (false);} L_ptr2 = L_ptr1; while((*L_ptr2) && (*L_ptr2 != ' ') && (*L_ptr2 != '\t') && (*L_ptr2 != '\r') && (*L_ptr2 != '\n')) { L_ptr2 ++; } if(!*L_ptr2) { return (false); } L_backup = *L_ptr2; *L_ptr2 = 0; if (strcmp(L_ptr1, "abort_call") == 0) { *L_ptr2 = L_backup; abortCall(); CStat::instance()->computeStat(CStat::E_CALL_FAILED); return (true); } *L_ptr2 = L_backup; return (false);}#endifvoid call::extract_cseq_method (char* method, char* msg){ char* cseq ; if (cseq = strstr (msg, "CSeq")) { char * value ; if ( value = strstr (cseq, ":")) { value++; while ( isspace(*value)) value++; // ignore any white spaces after the : while ( !isspace(*value)) value++; // ignore the CSEQ numnber value++; char *end = value; int nbytes = 0; while ((*end != '\n')) { end++; nbytes++;} strncpy (method, value, (nbytes-1)); method[nbytes] = '\0'; } }}void call::formatNextReqUrl (char* next_req_url){ /* clean up the next_req_url -- Record routes may have extra gunk that needs to be removed */ char* actual_req_url = strchr(next_req_url, '<'); if (actual_req_url) { /* using a temporary buffer */ char tempBuffer[MAX_HEADER_LEN]; strcpy(tempBuffer, actual_req_url + 1); actual_req_url = strrchr(tempBuffer, '>'); *actual_req_url = '\0'; strcpy(next_req_url, tempBuffer); }}void call::computeRouteSetAndRemoteTargetUri (char* rr, char* contact, bool bRequestIncoming){ if (0 >=strlen (rr)) { // // there are no RR headers. Simply set up the contact as our target uri // if (0 < strlen(contact)) { strcpy (next_req_url, contact); } formatNextReqUrl(next_req_url); return; } char actual_rr[MAX_HEADER_LEN]; char targetURI[MAX_HEADER_LEN]; memset(actual_rr, 0, sizeof(actual_rr)); bool isFirst = true; bool bCopyContactToRR = false; while (1) { char* pointer = NULL; if (bRequestIncoming) { pointer = strchr (rr, ','); } else { pointer = strrchr(rr, ','); } if (pointer) { if (!isFirst) { if (strlen(actual_rr) ) { strcat(actual_rr, pointer + 1); } else { strcpy(actual_rr, pointer + 1); } strcat(actual_rr, ","); } else { isFirst = false; if (NULL == strstr (pointer, ";lr")) { /* bottom most RR is the next_req_url */ strcpy (targetURI, pointer + 1); bCopyContactToRR = true; } else { /* the hop is a loose router. Thus, the target URI should be the * contact */ strcpy (targetURI, contact); strcpy(actual_rr, pointer + 1); strcat(actual_rr, ","); } } } else { if (!isFirst) { strcat(actual_rr, rr); } // // this is the *only* RR header that was found // else { if (NULL == strstr (rr, ";lr")) { /* bottom most RR is the next_req_url */ strcpy (targetURI, rr); bCopyContactToRR = true; } else { /* the hop is a loose router. Thus, the target URI should be the * contact */ strcpy (actual_rr, rr); strcpy (targetURI, contact); } } break; } *pointer = '\0'; } if (bCopyContactToRR) { if (0 < strlen (actual_rr)) { strcat(actual_rr, ","); strcat(actual_rr, contact); } else { strcpy(actual_rr, contact); } } if (strlen(actual_rr)) { dialog_route_set = (char *) calloc(1, strlen(actual_rr) + 2); sprintf(dialog_route_set, "%s", actual_rr); } if (strlen (targetURI)) { strcpy (next_req_url, targetURI); formatNextReqUrl (next_req_url); }}bool call::process_incomming(char * msg){ int reply_code; static char request[65]; char responsecseqmethod[65]; unsigned long cookie; char * ptr; int search_index; bool found = false; T_ActionResult actionResult; int L_case = 0 ; struct timeval L_currentTime ; double L_stop_time ;#define MATCHES_SCENARIO(index) \ (((reply_code) && \ ((scenario[index] -> recv_response) == reply_code) && \ (scenario[index]->recv_response_for_cseq_method_list) && \ (strstr(scenario[index]->recv_response_for_cseq_method_list, responsecseqmethod))) || \ ((scenario[index] -> recv_request) && \ (!strcmp(scenario[index] -> recv_request, \ request)))) memset (responsecseqmethod, 0, sizeof(responsecseqmethod)); if((transport == T_UDP) && (retrans_enabled)) { /* Detects retransmissions from peer and retransmit the * message which was sent just after this one was received */ cookie = hash(msg); if(recv_retrans_hash == cookie) { int status; if(lost(scenario[recv_retrans_recv_index] -> lost)) { TRACE_MSG((s, "%s message (retrans) lost (recv).", TRANSPORT_TO_STRING(transport))); if(comp_state) { comp_free(&comp_state); } scenario[recv_retrans_recv_index] -> nb_lost++; return true; } send_scene(recv_retrans_send_index, &status); if(status == 0) { scenario[recv_retrans_recv_index] -> nb_recv_retrans++; scenario[recv_retrans_send_index] -> nb_sent_retrans++; } else if(status < -1) { return false; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -