sharkd: export uat records.
[metze/wireshark/wip.git] / epan / uat-int.h
1 /*
2  *  uat-int.h
3  *
4  *  User Accessible Tables
5  *  Maintain an array of user accessible data structures
6  *  Internal interface
7  *
8  * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
9  *
10  * Wireshark - Network traffic analyzer
11  * By Gerald Combs <gerald@wireshark.org>
12  * Copyright 2001 Gerald Combs
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License
16  * as published by the Free Software Foundation; either version 2
17  * of the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27  *
28  */
29 #ifndef __UAT_INT_H__
30 #define __UAT_INT_H__
31
32 #include "uat.h"
33 #include "ws_symbol_export.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 typedef struct _uat_fld_rep_t uat_fld_rep_t;
40 typedef struct _uat_rep_t uat_rep_t;
41
42 typedef void (*uat_rep_fld_free_cb_t)(uat_fld_rep_t*);
43 typedef void (*uat_rep_free_cb_t)(uat_rep_t*);
44
45 typedef struct _fld_data_t {
46     guint colnum;
47     uat_fld_rep_t* rep;
48     uat_rep_fld_free_cb_t free_rep;
49 } fld_data_t;
50
51 struct epan_uat {
52     char* name;
53     size_t record_size;
54     char* filename;
55     gboolean from_profile;
56     char* help;
57     guint flags;
58     void** user_ptr;    /**< Pointer to a dissector variable where an array of valid records are stored. */
59     guint* nrows_p;     /**< Pointer to a dissector variable where the number of valid records in user_ptr are written. */
60     uat_copy_cb_t copy_cb;
61     uat_update_cb_t update_cb;
62     uat_free_cb_t free_cb;
63     uat_post_update_cb_t post_update_cb;
64     uat_reset_cb_t reset_cb;
65
66     uat_field_t* fields;
67     guint ncols;
68     GArray* user_data;  /**< An array of valid records that will be exposed to the dissector. */
69     GArray* raw_data;   /**< An array of records containing possibly invalid data. For internal use only. */
70     GArray* valid_data; /**< An array of booleans describing whether the records in 'raw_data' are valid or not. */
71     gboolean changed;
72     uat_rep_t* rep;
73     uat_rep_free_cb_t free_rep;
74     gboolean loaded;
75     gboolean from_global;
76 };
77
78 WS_DLL_PUBLIC
79 gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing);
80
81 /**
82  * Clones the given record and stores it internally in the UAT. If it is
83  * considered a valid record, then it will also be cloned and stored in the
84  * externally visible list.
85  */
86 WS_DLL_PUBLIC
87 void* uat_add_record(uat_t *uat, const void *orig_rec_ptr, gboolean valid_rec);
88
89 /**
90  * Marks the internal record in the UAT as valid or invalid. The record must
91  * exist in the UAT.
92  */
93 WS_DLL_PUBLIC
94 void uat_update_record(uat_t *uat, const void *record, gboolean valid_rec);
95
96 /**
97  * Changes the order of two internal UAT records.
98  */
99 WS_DLL_PUBLIC
100 void uat_swap(uat_t *uat, guint idx_a, guint idx_b);
101
102 /**
103  * Inserts the record at the given index in the internal record list.
104  */
105 WS_DLL_PUBLIC
106 void uat_insert_record_idx(uat_t *uat, guint rec_idx, const void *src_record);
107
108 /**
109  * Removes the record with the given index from the internal record list.
110  */
111 WS_DLL_PUBLIC
112 void uat_remove_record_idx(uat_t *uat, guint rec_idx);
113
114 /**
115  * Removes and destroys all records from the UAT.
116  */
117 WS_DLL_PUBLIC
118 void uat_clear(uat_t *uat);
119
120 /**
121  * Saves the records from an UAT to file.
122  * Returns TRUE on success and FALSE on failure, storing the reason in 'error'
123  * (which must be freed using g_free).
124  */
125 WS_DLL_PUBLIC
126 gboolean uat_save(uat_t *uat, char **error);
127
128 /**
129  * Loads the records for all registered UATs from file.
130  */
131 void uat_load_all(void);
132
133 /**
134  * Dump given UAT record to string in form, which can be later loaded with uat_load_str().
135  */
136 WS_DLL_PUBLIC
137 char *uat_fld_tostr(void *rec, uat_field_t *f);
138
139 /**
140  * Exposes the array of valid records to the UAT consumer (dissectors), updating
141  * the contents of 'data_ptr' and 'num_items_ptr' (see 'uat_new').
142  */
143 #define UAT_UPDATE(uat) do { *((uat)->user_ptr) = (void*)((uat)->user_data->data); *((uat)->nrows_p) = (uat)->user_data->len; } while(0)
144 /**
145  * Get a record from the array of all UAT entries, whether they are semantically
146  * valid or not. This memory must only be used internally in the UAT core and
147  * must not be exposed to dissectors.
148  */
149 #define UAT_INDEX_PTR(uat,idx) (uat->raw_data->data + (uat->record_size * (idx)))
150 /**
151  * Get a record from the array of all valid entries. These records will be
152  * shared with UAT consumers (dissectors).
153  */
154 #define UAT_USER_INDEX_PTR(uat,idx) (uat->user_data->data + (uat->record_size * (idx)))
155
156 #ifdef __cplusplus
157 }
158 #endif /* __cplusplus */
159
160 #endif /* __UAT_INT_H__ */
161
162 /*
163  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
164  *
165  * Local variables:
166  * c-basic-offset: 4
167  * tab-width: 8
168  * indent-tabs-mode: nil
169  * End:
170  *
171  * vi: set shiftwidth=4 tabstop=8 expandtab:
172  * :indentSize=4:tabSize=8:noTabs=true:
173  */