const char * msg_get_attribute(sip_msg_t *msg, int id, char *value) { sdp_media_t *media; char *ar; switch (id) { case SIP_ATTR_SRC: sprintf(value, "%s:%u", msg->packet->ip_src, msg->packet->sport); break; case SIP_ATTR_DST: sprintf(value, "%s:%u", msg->packet->ip_dst, msg->packet->dport); break; case SIP_ATTR_METHOD: if (sip_method_str(msg->reqresp)) { sprintf(value, "%s", sip_method_str(msg->reqresp)); } else { sip_get_response_str(msg, value); } break; case SIP_ATTR_SIPFROM: sprintf(value, "%s", msg->sip_from); break; case SIP_ATTR_SIPTO: sprintf(value, "%s", msg->sip_to); break; case SIP_ATTR_SIPFROMUSER: sprintf(value, "%s", msg->sip_from); if ((ar = strchr(value, '@'))) *ar = '\0'; break; case SIP_ATTR_SIPTOUSER: sprintf(value, "%s", msg->sip_to); if ((ar = strchr(value, '@'))) *ar = '\0'; break; case SIP_ATTR_DATE: timeval_to_date(msg_get_time(msg), value); break; case SIP_ATTR_TIME: timeval_to_time(msg_get_time(msg), value); break; case SIP_ATTR_SDP_ADDRESS: if ((media = vector_first(msg->medias))) sprintf(value, "%s", media_get_address(media)); break; case SIP_ATTR_SDP_PORT: if ((media = vector_first(msg->medias))) sprintf(value, "%d", media_get_port(media)); break; default: fprintf(stderr, "Unhandled attribute %s (%d)\n", sip_attr_get_name(id), id); abort(); break; } return strlen(value) ? value : NULL; }
const char* filter_field_method(int field_id) { int method; switch(field_id) { case FLD_FILTER_REGISTER: method = SIP_METHOD_REGISTER; break; case FLD_FILTER_INVITE: method = SIP_METHOD_INVITE; break; case FLD_FILTER_SUBSCRIBE: method = SIP_METHOD_SUBSCRIBE; break; case FLD_FILTER_NOTIFY: method = SIP_METHOD_NOTIFY; break; case FLD_FILTER_OPTIONS: method = SIP_METHOD_OPTIONS; break; case FLD_FILTER_PUBLISH: method = SIP_METHOD_PUBLISH; break; case FLD_FILTER_MESSAGE: method = SIP_METHOD_MESSAGE; break; } return sip_method_str(method); }
const char * sip_get_msg_reqresp_str(sip_msg_t *msg) { // Check if code has non-standard text if (msg->resp_str) { return msg->resp_str; } else { return sip_method_str(msg->reqresp); } }
int sip_get_msg_reqresp(sip_msg_t *msg, const u_char *payload) { regmatch_t pmatch[3]; char resp_str[256]; char reqresp[40]; char cseq[11]; const char *resp_def; // Initialize variables memset(pmatch, 0, sizeof(pmatch)); memset(resp_str, 0, sizeof(resp_str)); memset(reqresp, 0, sizeof(reqresp)); // If not already parsed if (!msg->reqresp) { // Method & CSeq if (regexec(&calls.reg_method, (const char *)payload, 2, pmatch, 0) == 0) { sprintf(reqresp, "%.*s", (int)(pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); } // CSeq if (regexec(&calls.reg_cseq, (char*)payload, 2, pmatch, 0) == 0) { sprintf(cseq, "%.*s", (int)(pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); msg->cseq = atoi(cseq); } // Response code if (regexec(&calls.reg_response, (const char *)payload, 3, pmatch, 0) == 0) { sprintf(resp_str, "%.*s", (int)(pmatch[1].rm_eo - pmatch[1].rm_so), payload + pmatch[1].rm_so); sprintf(reqresp, "%.*s", (int)(pmatch[2].rm_eo - pmatch[2].rm_so), payload + pmatch[2].rm_so); } // Get Request/Response Code msg->reqresp = sip_method_from_str(reqresp); // For response codes, check if the text matches the default if (!msg_is_request(msg)) { resp_def = sip_method_str(msg->reqresp); if (!resp_def || strcmp(resp_def, resp_str)) { msg->resp_str = strdup(resp_str); } } } return msg->reqresp; }
PANEL * filter_create() { PANEL *panel; WINDOW *win; int height, width; filter_info_t *info; const char *method; // Calculate window dimensions height = 16; width = 50; // Cerate a new indow for the panel and form win = newwin(height, width, (LINES - height) / 2, (COLS - width) / 2); // Create a new panel panel = new_panel(win); // Initialize Filter panel specific data info = sng_malloc(sizeof(filter_info_t)); // Store it into panel userptr set_panel_userptr(panel, (void*) info); // Initialize the fields info->fields[FLD_FILTER_SIPFROM] = new_field(1, 28, 3, 18, 0, 0); info->fields[FLD_FILTER_SIPTO] = new_field(1, 28, 4, 18, 0, 0); info->fields[FLD_FILTER_SRC] = new_field(1, 18, 5, 18, 0, 0); info->fields[FLD_FILTER_DST] = new_field(1, 18, 6, 18, 0, 0); info->fields[FLD_FILTER_PAYLOAD] = new_field(1, 28, 7, 18, 0, 0); info->fields[FLD_FILTER_REGISTER] = new_field(1, 1, 9, 15, 0, 0); info->fields[FLD_FILTER_INVITE] = new_field(1, 1, 10, 15, 0, 0); info->fields[FLD_FILTER_SUBSCRIBE] = new_field(1, 1, 11, 15, 0, 0); info->fields[FLD_FILTER_NOTIFY] = new_field(1, 1, 12, 15, 0, 0); info->fields[FLD_FILTER_OPTIONS] = new_field(1, 1, 9, 37, 0, 0); info->fields[FLD_FILTER_PUBLISH] = new_field(1, 1, 10, 37, 0, 0); info->fields[FLD_FILTER_MESSAGE] = new_field(1, 1, 11, 37, 0, 0); info->fields[FLD_FILTER_FILTER] = new_field(1, 10, height - 2, 11, 0, 0); info->fields[FLD_FILTER_CANCEL] = new_field(1, 10, height - 2, 30, 0, 0); info->fields[FLD_FILTER_COUNT] = NULL; // Set fields options field_opts_off(info->fields[FLD_FILTER_SIPFROM], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_SIPTO], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_SRC], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_DST], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_PAYLOAD], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_REGISTER], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_INVITE], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_SUBSCRIBE], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_NOTIFY], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_OPTIONS], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_PUBLISH], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_MESSAGE], O_AUTOSKIP); field_opts_off(info->fields[FLD_FILTER_FILTER], O_EDIT); field_opts_off(info->fields[FLD_FILTER_CANCEL], O_EDIT); // Change background of input fields set_field_back(info->fields[FLD_FILTER_SIPFROM], A_UNDERLINE); set_field_back(info->fields[FLD_FILTER_SIPTO], A_UNDERLINE); set_field_back(info->fields[FLD_FILTER_SRC], A_UNDERLINE); set_field_back(info->fields[FLD_FILTER_DST], A_UNDERLINE); set_field_back(info->fields[FLD_FILTER_PAYLOAD], A_UNDERLINE); // Create the form and post it info->form = new_form(info->fields); set_form_sub(info->form, win); post_form(info->form); // Fields labels mvwprintw(win, 3, 3, "SIP From:"); mvwprintw(win, 4, 3, "SIP To:"); mvwprintw(win, 5, 3, "Source:"); mvwprintw(win, 6, 3, "Destination:"); mvwprintw(win, 7, 3, "Payload:"); mvwprintw(win, 9, 3, "REGISTER [ ]"); mvwprintw(win, 10, 3, "INVITE [ ]"); mvwprintw(win, 11, 3, "SUBSCRIBE [ ]"); mvwprintw(win, 12, 3, "NOTIFY [ ]"); mvwprintw(win, 9, 25, "OPTIONS [ ]"); mvwprintw(win, 10, 25, "PUBLISH [ ]"); mvwprintw(win, 11, 25, "MESSAGE [ ]"); // Get Method filter if (!(method = filter_get(FILTER_METHOD))) method = setting_get_value(SETTING_FILTER_METHODS); // Set Default field values set_field_buffer(info->fields[FLD_FILTER_SIPFROM], 0, filter_get(FILTER_SIPFROM)); set_field_buffer(info->fields[FLD_FILTER_SIPTO], 0, filter_get(FILTER_SIPTO)); set_field_buffer(info->fields[FLD_FILTER_SRC], 0, filter_get(FILTER_SOURCE)); set_field_buffer(info->fields[FLD_FILTER_DST], 0, filter_get(FILTER_DESTINATION)); set_field_buffer(info->fields[FLD_FILTER_PAYLOAD], 0, filter_get(FILTER_PAYLOAD)); set_field_buffer(info->fields[FLD_FILTER_REGISTER], 0, strcasestr(method, sip_method_str(SIP_METHOD_REGISTER)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_INVITE], 0, strcasestr(method, sip_method_str(SIP_METHOD_INVITE)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_SUBSCRIBE], 0, strcasestr(method,sip_method_str(SIP_METHOD_SUBSCRIBE)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_NOTIFY], 0, strcasestr(method, sip_method_str(SIP_METHOD_NOTIFY)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_OPTIONS], 0, strcasestr(method, sip_method_str(SIP_METHOD_OPTIONS)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_PUBLISH], 0, strcasestr(method, sip_method_str(SIP_METHOD_PUBLISH)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_MESSAGE], 0, strcasestr(method, sip_method_str(SIP_METHOD_MESSAGE)) ? "*" : ""); set_field_buffer(info->fields[FLD_FILTER_FILTER], 0, "[ Filter ]"); set_field_buffer(info->fields[FLD_FILTER_CANCEL], 0, "[ Cancel ]"); // Set the window title and boxes mvwprintw(win, 1, 18, "Filter options"); wattron(win, COLOR_PAIR(CP_BLUE_ON_DEF)); title_foot_box(panel); mvwhline(win, 8, 1, ACS_HLINE, 49); mvwaddch(win, 8, 0, ACS_LTEE); mvwaddch(win, 8, 49, ACS_RTEE); wattroff(win, COLOR_PAIR(CP_BLUE_ON_DEF)); // Set default cursor position set_current_field(info->form, info->fields[FLD_FILTER_SIPFROM]); wmove(win, 3, 18); curs_set(1); return panel; }