void load_filters_list (const char *file_name, char local) { int f_size; FILE *f = NULL; char *filter_list_mem; int istart, iend; char name[128]; size_t ret; f = open_file_config (file_name, "rb"); if (f == NULL) return; fseek (f, 0, SEEK_END); f_size = ftell (f); if (f_size <= 0) { fclose(f); return; } //ok, allocate memory for it filter_list_mem = (char *) calloc (f_size, 1); fseek (f, 0, SEEK_SET); ret = fread (filter_list_mem, 1, f_size, f); fclose (f); if (ret != f_size) { free (filter_list_mem); LOG_ERROR("%s read failed for file [%s]\n", __FUNCTION__, file_name); return; } istart = 0; while (istart < f_size) { // find end of the line for (iend = istart; iend < f_size; iend++) { if (filter_list_mem[iend] == '\n' || filter_list_mem[iend] == '\r') break; } // copy the line and process it if (iend > istart) { safe_strncpy2 (name, filter_list_mem+istart, sizeof (name), iend-istart); if (add_to_filter_list (name, local, 0) == -2) // -1 == already exists, -2 == list full { free (filter_list_mem); return; // filter list full } } // move to next line istart = iend+1; } free (filter_list_mem); }
void FilterDialog::on_buttonBox_accepted() { filter_list_type_t fl_type = filter_type_ == CaptureFilter ? CFILTER_LIST : DFILTER_LIST; while (GList *fl_item = get_filter_list_first(fl_type)) { remove_from_filter_list(fl_type, fl_item); } QTreeWidgetItemIterator it(ui->filterTreeWidget); while (*it) { add_to_filter_list(fl_type, (*it)->text(name_col_).toUtf8().constData(), (*it)->text(filter_col_).toUtf8().constData()); ++it; } char *pf_dir_path; char *f_path; int f_save_errno; /* Create the directory that holds personal configuration files, if necessary. */ if (create_persconffile_dir(&pf_dir_path) == -1) { QMessageBox::warning(this, tr("Unable to create profile directory."), tr("Unable to create directory\n\"%1\"\nfor filter files: %2.") .arg(pf_dir_path) .arg(g_strerror(errno)), QMessageBox::Ok); g_free(pf_dir_path); return; } save_filter_list(fl_type, &f_path, &f_save_errno); if (f_path != NULL) { /* We had an error saving the filter. */ QString warning_title; QString warning_msg; if (fl_type == CFILTER_LIST) { warning_title = tr("Unable to save capture filter settings."); warning_msg = tr("Could not save to your capture filter file\n\"%1\": %2.") .arg(f_path).arg(g_strerror(f_save_errno)); } else { warning_title = tr("Unable to save display filter settings."); warning_msg = tr("Could not save to your display filter file\n\"%1\": %2.") .arg(f_path).arg(g_strerror(f_save_errno)); } QMessageBox::warning(this, warning_title, warning_msg, QMessageBox::Ok); g_free(f_path); } if (filter_type_ == CaptureFilter) { wsApp->emitAppSignal(WiresharkApplication::CaptureFilterListChanged); } else { wsApp->emitAppSignal(WiresharkApplication::DisplayFilterListChanged); } }
int command_filter(char *text, int len) { char name[256]; char str[100]; int i; Uint8 ch = '\0'; int result; while (isspace(*text)) text++; for (i = 0; i < sizeof (name) - 1; i++) { ch = text[i]; if (ch == '\0') break; name[i] = ch; } name[i] = '\0'; if (i >= sizeof (name) - 1 && ch != '\0') { safe_snprintf (str, sizeof (str), "%s %s", word_too_long, not_added_to_filter); LOG_TO_CONSOLE (c_red1, str); return 1; } else if (i < 3) { safe_snprintf (str, sizeof (str), "%s %s", word_too_short, not_added_to_filter); LOG_TO_CONSOLE (c_red1, word_too_short); return 1; } result = add_to_filter_list (name, 1, save_ignores); if (result == -1) { safe_snprintf (str, sizeof (str), already_filtering, name); LOG_TO_CONSOLE (c_red1, str); } else if (result == -2) { LOG_TO_CONSOLE (c_red1, filter_list_full); } else { safe_snprintf (str, sizeof (str), added_to_filters, name); LOG_TO_CONSOLE (c_green1, str); } return 1; }