PANEL * call_list_create() { PANEL *panel; WINDOW *win; int height, width, i, attrid, collen; call_list_info_t *info; char option[80]; const char *field, *title; // Create a new panel that fill all the screen panel = new_panel(newwin(LINES, COLS, 0, 0)); // Initialize Call List specific data info = sng_malloc(sizeof(call_list_info_t)); // Store it into panel userptr set_panel_userptr(panel, (void*) info); // Add configured columns for (i = 0; i < SIP_ATTR_COUNT; i++) { // Get column attribute name from options sprintf(option, "cl.column%d", i); if ((field = get_option_value(option))) { if ((attrid = sip_attr_from_name(field)) == -1) continue; // Get column width from options sprintf(option, "cl.column%d.width", i); if ((collen = get_option_int_value(option)) == -1) collen = sip_attr_get_width(attrid); // Get column title title = sip_attr_get_title(attrid); // Add column to the list call_list_add_column(panel, attrid, field, title, collen); } } // Let's draw the fixed elements of the screen win = panel_window(panel); getmaxyx(win, height, width); // Initialize the fields info->fields[FLD_LIST_FILTER] = new_field(1, width - 19, 2, 18, 0, 0); info->fields[FLD_LIST_COUNT] = NULL; // Create the form and post it info->form = new_form(info->fields); set_form_sub(info->form, win); // Form starts inactive call_list_form_activate(panel, 0); // Calculate available printable area info->list_win = subwin(win, height - 5, width, 4, 0); info->group = call_group_create(); // Get current call list info->calls = sip_calls_iterator(); vector_iterator_set_filter(&info->calls, filter_check_call); info->cur_call = info->first_call = -1; // Set autoscroll default status info->autoscroll = setting_enabled(SETTING_CL_AUTOSCROLL); // Apply initial configured method filters filter_method_from_setting(setting_get_value(SETTING_FILTER_METHODS)); // Return the created panel return panel; }
int save_to_file(ui_t *ui) { char savepath[256]; char savefile[256]; char fullfile[512]; sip_call_t *call = NULL; sip_msg_t *msg = NULL; pcap_dumper_t *pd = NULL; FILE *f = NULL; int cur = 0, total = 0; WINDOW *progress; vector_iter_t calls, msgs, rtps, packets; packet_t *packet; vector_t *sorted; // Get panel information save_info_t *info = save_info(ui); // Get current path field value. memset(savepath, 0, sizeof(savepath)); strcpy(savepath, field_buffer(info->fields[FLD_SAVE_PATH], 0)); strtrim(savepath); if (strlen(savepath)) strcat(savepath, "/"); // Get current file field value. memset(savefile, 0, sizeof(savefile)); strcpy(savefile, field_buffer(info->fields[FLD_SAVE_FILE], 0)); strtrim(savefile); if (!strlen(savefile)) { dialog_run("Please enter a valid filename"); return 1; } if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { if (!strstr(savefile, ".pcap")) strcat(savefile, ".pcap"); } else { if (!strstr(savefile, ".txt")) strcat(savefile, ".txt"); } // Absolute filename sprintf(fullfile, "%s%s", savepath, savefile); if (access(fullfile, R_OK) == 0) { if (dialog_confirm("Overwrite confirmation", "Selected file already exits.\n Do you want to overwrite it?", "Yes,No") != 0) return 1; } // Don't allow to save no packets! if (info->savemode == SAVE_SELECTED && call_group_msg_count(info->group) == 0) { dialog_run("Unable to save: No selected dialogs."); return 1; } if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { // Open dump file pd = dump_open(fullfile); if (access(fullfile, W_OK) != 0) { dialog_run(capture_last_error()); return 1; } } else { // Open a text file if (!(f = fopen(fullfile, "w"))) { dialog_run("Error: %s", strerror(errno)); return 0; } } // Get calls iterator switch (info->savemode) { case SAVE_ALL: // Get calls iterator calls = sip_calls_iterator(); break; case SAVE_SELECTED: // Save selected packets to file calls = vector_iterator(info->group->calls); break; case SAVE_DISPLAYED: // Set filtering for this iterator calls = sip_calls_iterator(); vector_iterator_set_filter(&calls, filter_check_call); break; default: break; } if (info->savemode == SAVE_MESSAGE) { if (info->saveformat == SAVE_TXT) { // Save selected message to file save_msg_txt(f, info->msg); } else { // Save selected message packet to pcap dump_packet(pd, info->msg->packet); } } else if (info->saveformat == SAVE_TXT) { // Save selected packets to file while ((call = vector_iterator_next(&calls))) { msgs = vector_iterator(call->msgs); // Save SIP message content while ((msg = vector_iterator_next(&msgs))) { save_msg_txt(f, msg); } } } else { // Store all messages in a time sorted vector sorted = vector_create(100, 50); vector_set_sorter(sorted, capture_packet_time_sorter); // Count packages for progress bar while ((call = vector_iterator_next(&calls))) { total += vector_count(call->msgs); if (info->saveformat == SAVE_PCAP_RTP) total += vector_count(call->rtp_packets); } vector_iterator_reset(&calls); progress = dialog_progress_run("Saving packets..."); dialog_progress_set_value(progress, 0); // Save selected packets to file while ((call = vector_iterator_next(&calls))) { msgs = vector_iterator(call->msgs); // Save SIP message content while ((msg = vector_iterator_next(&msgs))) { // Update progress bar dialog dialog_progress_set_value(progress, (++cur * 100) / total); vector_append(sorted, msg->packet); } // Save RTP packets if (info->saveformat == SAVE_PCAP_RTP) { rtps = vector_iterator(call->rtp_packets); while ((packet = vector_iterator_next(&rtps))) { // Update progress bar dialog dialog_progress_set_value(progress, (++cur * 100) / total); vector_append(sorted, packet); } } } // Save sorted packets packets = vector_iterator(sorted); while ((packet = vector_iterator_next(&packets))) { dump_packet(pd, packet); } dialog_progress_destroy(progress); } // Close saved file if (info->saveformat == SAVE_PCAP || info->saveformat == SAVE_PCAP_RTP) { dump_close(pd); } else { fclose(f); } // Show success popup if (info->savemode == SAVE_MESSAGE) { dialog_run("Successfully saved selected SIP message to %s", savefile); } else { dialog_run("Successfully saved %d dialogs to %s", vector_iterator_count(&calls), savefile); } return 0; }