From David Aggeler:
[obnox/wireshark/wip.git] / gtk / export_object_dicom.c
1 /* export_object_dicom.c
2  * $Id$
3  * Routines for tracking & saving objects found in DICOM streams
4  * See also: export_object.c / export_object.h for common code
5  * Copyright 2008, David Aggeler <david_aggeler@hispeed.ch>
6  * 
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
26  * USA.
27  */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <glib.h>
34 #include <gtk/gtk.h>
35
36 #include <epan/dissectors/packet-dcm.h>
37
38 #include <epan/packet.h>
39 #include <epan/emem.h>
40 #include <epan/tap.h>
41
42 #include "gtk/export_object.h"
43
44 static int
45 eo_dicom_packet(void *tapdata, packet_info *pinfo, epan_dissect_t *edt _U_,
46                const void *data)
47 {
48         export_object_list_t *object_list = tapdata;
49         const dicom_eo_t *eo_info = data;
50         export_object_entry_t *entry;
51
52         if (eo_info) { /* We have data waiting for us */
53                 /* These values will be freed when the Export Object window is closed.
54                    Therefore, sings and buffers must be copied
55                 */
56                 entry = g_malloc(sizeof(export_object_entry_t));
57
58                 entry->pkt_num = pinfo->fd->num;
59                 entry->hostname = g_strdup(eo_info->hostname);
60                 entry->content_type = g_strdup(eo_info->content_type);
61                 entry->filename = g_strdup(g_path_get_basename(eo_info->filename));
62                 entry->payload_len  = eo_info->payload_len;
63                 entry->payload_data = g_memdup(eo_info->payload_data, eo_info->payload_len);
64
65                 object_list->entries =
66                         g_slist_append(object_list->entries, entry);
67
68                 return 1; /* State changed - window should be redrawn */
69         } else {
70                 return 0; /* State unchanged - no window updates needed */
71         }
72 }
73
74 void
75 eo_dicom_cb(GtkWidget *widget _U_, gpointer data _U_)
76 {
77         export_object_window("dicom_eo", "DICOM", eo_dicom_packet);
78 }