Mark the file as having unsaved data if you change address resolution.
authorGuy Harris <guy@alum.mit.edu>
Mon, 18 Jul 2016 23:04:22 +0000 (16:04 -0700)
committerGuy Harris <guy@alum.mit.edu>
Mon, 18 Jul 2016 23:04:59 +0000 (23:04 +0000)
That information can, and will, get saved in some file formats, so mark
the file as changed so it can and will get saved by "Save".

XXX - we need to treat it as a type of data that can be discarded when
saving in some file formats, just like comments.

Bug: 12629
Change-Id: I1fd69b95f4f7345c339961b4c53c28b98b364e4e
Reviewed-on: https://code.wireshark.org/review/16538
Reviewed-by: Guy Harris <guy@alum.mit.edu>
file.c
file.h
ui/gtk/manual_addr_resolv.c
ui/qt/address_editor_frame.cpp
ui/qt/address_editor_frame.h

diff --git a/file.c b/file.c
index 9ab28544363294a98649f1e7d7de9e2594d2086e..73eef29fe815977745084a225134a7c8932450c1 100644 (file)
--- a/file.c
+++ b/file.c
@@ -3977,6 +3977,24 @@ cf_comment_types(capture_file *cf)
   return comment_types;
 }
 
+/*
+ * Add a resolved address to this file's list of resolved addresses.
+ */
+gboolean
+cf_add_ip_name_from_string(capture_file *cf, const char *addr, const char *name)
+{
+  /*
+   * XXX - support multiple resolved address lists, and add to the one
+   * attached to this file?
+   */
+  if (!add_ip_name_from_string(addr, name))
+    return FALSE;
+
+  /* OK, we have unsaved changes. */
+  cf->unsaved_changes = TRUE;
+  return TRUE;
+}
+
 #ifdef WANT_PACKET_EDITOR
 static gint
 g_direct_compare_func(gconstpointer a, gconstpointer b, gpointer user_data _U_)
diff --git a/file.h b/file.h
index 8a54cdefefa4129c0afe829aa166832d21b4c95b..65354e7d473ab9953395d45c0b345082d0cf1871 100644 (file)
--- a/file.h
+++ b/file.h
@@ -696,6 +696,16 @@ gboolean cf_set_user_packet_comment(capture_file *cf, frame_data *fd, const gcha
  */
 guint32 cf_comment_types(capture_file *cf);
 
+/**
+ * Add a resolved address to this file's list of resolved addresses.
+ *
+ * @param cf the capture file
+ * @param addr a string representing an IPv4 or IPv6 address
+ * @param name a string containing a name corresponding to that address
+ * @return TRUE if it succeeds, FALSE if not
+ */
+gboolean cf_add_ip_name_from_string(capture_file *cf, const char *addr, const char *name);
+
 #ifdef WANT_PACKET_EDITOR
 /**
  * Give a frame new, edited data.
index 0fae93da27406e724364d6b882811e9a7e50f848..085dc0637c1623f541c249796d55f7581f8f172c 100644 (file)
@@ -62,7 +62,7 @@ man_addr_resolv_ok(GtkWidget *w _U_, gpointer data _U_)
   name = gtk_entry_get_text(GTK_ENTRY(name_te));
 
   if (strlen(addr) && strlen(name)) {
-    if (!add_ip_name_from_string(addr, name)) {
+    if (!cf_add_ip_name_from_string(&cfile, addr, name)) {
       GtkWidget *dialog = (GtkWidget *)simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
                                         "Illegal IP address: \"%s\".", addr);
       simple_dialog_set_cb(dialog, man_addr_ill_addr_cb, NULL);
@@ -70,6 +70,7 @@ man_addr_resolv_ok(GtkWidget *w _U_, gpointer data _U_)
       return;
     } else {
       redissect = TRUE;
+      main_update_for_unsaved_changes(&cfile);
     }
   }
   g_free(addr);
index cb271446151c5acb0b55d7009b2d8c676378367e..49e3fa121760ec142cde5d9e8a27f38086f8d8b9 100644 (file)
@@ -42,7 +42,8 @@
 
 AddressEditorFrame::AddressEditorFrame(QWidget *parent) :
     AccordionFrame(parent),
-    ui(new Ui::AddressEditorFrame)
+    ui(new Ui::AddressEditorFrame),
+    cap_file_(NULL)
 {
     ui->setupUi(this);
 
@@ -60,12 +61,14 @@ AddressEditorFrame::~AddressEditorFrame()
 
 void AddressEditorFrame::editAddresses(CaptureFile &cf, int column)
 {
-    if (!cf.capFile()->current_frame) {
+    cap_file_ = cf.capFile();
+
+    if (!cap_file_->current_frame) {
         on_buttonBox_rejected();
         return;
     }
 
-    if (!cf_read_record(cf.capFile(), cf.capFile()->current_frame)) {
+    if (!cf_read_record(cap_file_, cap_file_->current_frame)) {
         on_buttonBox_rejected();
         return; // error reading the frame
     }
@@ -75,22 +78,22 @@ void AddressEditorFrame::editAddresses(CaptureFile &cf, int column)
 
     ui->addressComboBox->clear();
 
-    epan_dissect_init(&edt, cf.capFile()->epan, FALSE, FALSE);
-    col_custom_prime_edt(&edt, &cf.capFile()->cinfo);
+    epan_dissect_init(&edt, cap_file_->epan, FALSE, FALSE);
+    col_custom_prime_edt(&edt, &cap_file_->cinfo);
 
-    epan_dissect_run(&edt, cf.capFile()->cd_t, &cf.capFile()->phdr,
-        frame_tvbuff_new_buffer(cf.capFile()->current_frame, &cf.capFile()->buf), cf.capFile()->current_frame, &cf.capFile()->cinfo);
+    epan_dissect_run(&edt, cap_file_->cd_t, &cap_file_->phdr,
+        frame_tvbuff_new_buffer(cap_file_->current_frame, &cap_file_->buf), cap_file_->current_frame, &cap_file_->cinfo);
     epan_dissect_fill_in_columns(&edt, TRUE, TRUE);
 
     /* First check selected column */
-    if (isAddressColumn(&cf.capFile()->cinfo, column)) {
-        addresses << cf.capFile()->cinfo.col_expr.col_expr_val[column];
+    if (isAddressColumn(&cap_file_->cinfo, column)) {
+        addresses << cap_file_->cinfo.col_expr.col_expr_val[column];
     }
 
-    for (int col = 0; col < cf.capFile()->cinfo.num_cols; col++) {
+    for (int col = 0; col < cap_file_->cinfo.num_cols; col++) {
         /* Then check all columns except the selected */
-        if ((col != column) && (isAddressColumn(&cf.capFile()->cinfo, col))) {
-            addresses << cf.capFile()->cinfo.col_expr.col_expr_val[col];
+        if ((col != column) && (isAddressColumn(&cap_file_->cinfo, col))) {
+            addresses << cap_file_->cinfo.col_expr.col_expr_val[col];
         }
     }
 
@@ -142,7 +145,7 @@ void AddressEditorFrame::on_buttonBox_accepted()
     }
     QString addr = ui->addressComboBox->currentText();
     QString name = ui->nameLineEdit->text();
-    if (!add_ip_name_from_string(addr.toUtf8().constData(), name.toUtf8().constData())) {
+    if (!cf_add_ip_name_from_string(cap_file_, addr.toUtf8().constData(), name.toUtf8().constData())) {
         QString error_msg = tr("Can't assign %1 to %2").arg(name).arg(addr);
         emit editAddressStatus(error_msg);
         ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
index 0bec30b4b96e97c111f398092960f6679618740f..eb57263c79737a4b61c321b282c600d051311de0 100644 (file)
@@ -59,6 +59,7 @@ private slots:
 
 private:
     Ui::AddressEditorFrame *ui;
+    capture_file *cap_file_;
 
     bool isAddressColumn(struct epan_column_info *cinfo, int column);
 };