int call_msg_is_retrans(sip_msg_t *msg) { sip_msg_t *prev = NULL; vector_iter_t it; // Get previous message in call with same origin and destination it = vector_iterator(msg->call->msgs); vector_iterator_set_current(&it, vector_index(msg->call->msgs, msg)); while ((prev = vector_iterator_prev(&it))) { if (!strcmp(SRC(prev), SRC(msg)) && !strcmp(DST(prev), DST(msg))) break; } return (prev && !strcasecmp(msg_get_payload(msg), msg_get_payload(prev))); }
sip_msg_t * sip_parse_msg(sip_msg_t *msg) { if (msg && !msg->cseq) { sip_parse_msg_payload(msg, (u_char*) msg_get_payload(msg)); } return msg; }
int call_msg_is_retrans(sip_msg_t *msg) { sip_msg_t *prev = NULL; vector_iter_t it; // Get previous message in call with same origin and destination it = vector_iterator(msg->call->msgs); vector_iterator_set_current(&it, vector_index(msg->call->msgs, msg)); while ((prev = vector_iterator_prev(&it))) { if (addressport_equals(prev->packet->src, msg->packet->src) && addressport_equals(prev->packet->dst, msg->packet->dst)) break; } return (prev && !strcasecmp(msg_get_payload(msg), msg_get_payload(prev))); }
int msg_diff_draw(ui_t *ui) { // Get panel information msg_diff_info_t *info = msg_diff_info(ui); char highlight[4086]; // Draw first message memset(highlight, 0, sizeof(highlight)); msg_diff_line_highlight(msg_get_payload(info->one), msg_get_payload(info->two), highlight); msg_diff_draw_message(info->one_win, info->one, highlight); // Draw second message memset(highlight, 0, sizeof(highlight)); msg_diff_line_highlight(msg_get_payload(info->two), msg_get_payload(info->one), highlight); msg_diff_draw_message(info->two_win, info->two, highlight); // Redraw footer msg_diff_draw_footer(ui); return 0; }
void save_msg_txt(FILE *f, sip_msg_t *msg) { char date[20], time[20], src[80], dst[80]; fprintf(f, "%s %s %s -> %s\n%s\n\n", msg_get_attribute(msg, SIP_ATTR_DATE, date), msg_get_attribute(msg, SIP_ATTR_TIME, time), msg_get_attribute(msg, SIP_ATTR_SRC, src), msg_get_attribute(msg, SIP_ATTR_DST, dst), msg_get_payload(msg)); }
int msg_diff_draw_message(WINDOW *win, sip_msg_t *msg, char *highlight) { int height, width, line, column, i; char header[256]; const char * payload = msg_get_payload(msg); // Clear the window werase(win); // Get window of main panel getmaxyx(win, height, width); wattron(win, A_BOLD); mvwprintw(win, 0, 0, sip_get_msg_header(msg, header)); wattroff(win, A_BOLD); // Print msg payload line = 2; column = 0; for (i = 0; i < strlen(payload); i++) { if (payload[i] == '\r') continue; if (column == width || payload[i] == '\n') { line++; column = 0; continue; } if (line == height) break; if (highlight[i] == '1') { wattron(win, COLOR_PAIR(CP_YELLOW_ON_DEF)); } else { wattroff(win, COLOR_PAIR(CP_YELLOW_ON_DEF)); } // Put next character in position mvwaddch(win, line, column++, payload[i]); } // Redraw raw win wnoutrefresh(win); return 0; }
int call_raw_print_msg(PANEL *panel, sip_msg_t *msg) { call_raw_info_t *info; int payload_lines, i, column, height, width; // Message ngrep style Header char header[256]; char payload[2048]; int color = 0; // Get panel information if (!(info = call_raw_info(panel))) return -1; // Get the pad window WINDOW *pad = info->pad; // Get current pad dimensions getmaxyx(pad, height, width); // Get message payload strcpy(payload, msg_get_payload(msg)); // Check how many lines we well need to draw this message payload_lines = 0; column = 0; for (i = 0; i < strlen(payload); i++) { if (column == width || payload[i] == '\n') { payload_lines++; column = 0; continue; } column++; } // Check if we have enough space in our huge pad to store this message if (info->padline + payload_lines > height) { // Create a new pad with more lines! pad = newpad(height + 500, COLS); // And copy all previous information overwrite(info->pad, pad); // Delete previous pad delwin(info->pad); // And store the new pad info->pad = pad; } // Color the message { if (setting_has_value(SETTING_COLORMODE, "request")) { // Determine arrow color if (msg_is_request(msg)) { color = CP_RED_ON_DEF; } else { color = CP_GREEN_ON_DEF; } } else if (info->group && setting_has_value(SETTING_COLORMODE, "callid")) { // Color by call-id color = call_group_color(info->group, msg->call); } else if (setting_has_value(SETTING_COLORMODE, "cseq")) { // Color by CSeq within the same call color = msg->cseq % 7 + 1; } // Turn on the message color wattron(pad, COLOR_PAIR(color)); // Print msg header wattron(pad, A_BOLD); mvwprintw(pad, info->padline++, 0, "%s", sip_get_msg_header(msg, header)); wattroff(pad, A_BOLD); // Print msg payload info->padline += draw_message_pos(pad, msg, info->padline); // Extra line between messages info->padline++; // Set this as the last printed message info->last = msg; return 0; }
int draw_message_pos(WINDOW *win, sip_msg_t *msg, int starting) { int height, width, line, column, i; const char *cur_line, *payload; int syntax = setting_enabled(SETTING_SYNTAX); // Default text format int attrs = A_NORMAL | COLOR_PAIR(CP_DEFAULT); if (syntax) wattrset(win, attrs); // Get window of main panel getmaxyx(win, height, width); // Get packet payload cur_line = payload = (const char *) msg_get_payload(msg); // Print msg payload line = starting; column = 0; for (i = 0; i < strlen(payload); i++) { // If syntax highlighting is enabled if (syntax) { // First line highlight if (line == starting) { // Request syntax if (i == 0 && strncmp(cur_line, "SIP/2.0", 7)) attrs = A_BOLD | COLOR_PAIR(CP_YELLOW_ON_DEF); // Response syntax if (i == 8 && !strncmp(cur_line, "SIP/2.0", 7)) attrs = A_BOLD | COLOR_PAIR(CP_RED_ON_DEF); // SIP URI syntax if (!strncasecmp(payload + i, "sip:", 4)) { attrs = A_BOLD | COLOR_PAIR(CP_CYAN_ON_DEF); } } else { // Header syntax if (strchr(cur_line, ':') && payload + i < strchr(cur_line, ':')) attrs = A_NORMAL | COLOR_PAIR(CP_GREEN_ON_DEF); // Call-ID Header syntax if (!strncasecmp(cur_line, "Call-ID:", 8) && column > 8) attrs = A_BOLD | COLOR_PAIR(CP_MAGENTA_ON_DEF); // CSeq Heaedr syntax if (!strncasecmp(cur_line, "CSeq:", 5) && column > 5 && !isdigit(payload[i])) attrs = A_NORMAL | COLOR_PAIR(CP_YELLOW_ON_DEF); // tag and branch syntax if (i > 0 && payload[i - 1] == ';') { // Highlight branch if requested if (setting_enabled(SETTING_SYNTAX_BRANCH)) { if (!strncasecmp(payload + i, "branch", 6)) { attrs = A_BOLD | COLOR_PAIR(CP_CYAN_ON_DEF); } } // Highlight tag if requested if (setting_enabled(SETTING_SYNTAX_TAG)) { if (!strncasecmp(payload + i, "tag", 3)) { if (!strncasecmp(cur_line, "From:", 5)) { attrs = A_BOLD | COLOR_PAIR(CP_DEFAULT); } else { attrs = A_BOLD | COLOR_PAIR(CP_GREEN_ON_DEF); } } } } // SDP syntax if (strcspn(cur_line, "=") == 1) attrs = A_NORMAL | COLOR_PAIR(CP_DEFAULT); } // Remove previous syntax if (strcspn(payload + i, " \n;<>") == 0) { wattroff(win, attrs); attrs = A_NORMAL | COLOR_PAIR(CP_DEFAULT); } // Syntax hightlight text! wattron(win, attrs); } // Dont print this characters if (payload[i] == '\r') continue; // Store where the line begins if (payload[i] == '\n') cur_line =payload + i + 1; // Move to the next line if line is filled or a we reach a line break if (column > width || payload[i] == '\n') { line++; column = 0; continue; } // Put next character in position mvwaddch(win, line, column++, payload[i]); // Stop if we've reached the bottom of the window if (line == height) break; } // Disable syntax when leaving if (syntax) wattroff(win, attrs); // Redraw raw win wnoutrefresh(win); return line - starting; }