debug keys
[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  * SPDX-License-Identifier: GPL-2.0-or-later
15  *
16  */
17 #ifndef __UAT_INT_H__
18 #define __UAT_INT_H__
19
20 #include "uat.h"
21 #include "ws_symbol_export.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif /* __cplusplus */
26
27 typedef struct _uat_fld_rep_t uat_fld_rep_t;
28 typedef struct _uat_rep_t uat_rep_t;
29
30 typedef void (*uat_rep_fld_free_cb_t)(uat_fld_rep_t*);
31 typedef void (*uat_rep_free_cb_t)(uat_rep_t*);
32
33 typedef struct _fld_data_t {
34     guint colnum;
35     uat_fld_rep_t* rep;
36     uat_rep_fld_free_cb_t free_rep;
37 } fld_data_t;
38
39 struct epan_uat {
40     char* name;
41     size_t record_size;
42     char* filename;
43     gboolean from_profile;
44     char* help;
45     guint flags;
46     void** user_ptr;    /**< Pointer to a dissector variable where an array of valid records are stored. */
47     guint* nrows_p;     /**< Pointer to a dissector variable where the number of valid records in user_ptr are written. */
48     uat_copy_cb_t copy_cb;
49     uat_update_cb_t update_cb;
50     uat_free_cb_t free_cb;
51     uat_post_update_cb_t post_update_cb;
52     uat_reset_cb_t reset_cb;
53
54     uat_field_t* fields;
55     guint ncols;
56     GArray* user_data;  /**< An array of valid records that will be exposed to the dissector. */
57     GArray* raw_data;   /**< An array of records containing possibly invalid data. For internal use only. */
58     GArray* valid_data; /**< An array of booleans describing whether the records in 'raw_data' are valid or not. */
59     gboolean changed;
60     uat_rep_t* rep;
61     uat_rep_free_cb_t free_rep;
62     gboolean loaded;
63     gboolean from_global;
64 };
65
66 WS_DLL_PUBLIC
67 gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing);
68
69 /**
70  * Clones the given record and stores it internally in the UAT. If it is
71  * considered a valid record, then it will also be cloned and stored in the
72  * externally visible list.
73  */
74 WS_DLL_PUBLIC
75 void* uat_add_record(uat_t *uat, const void *orig_rec_ptr, gboolean valid_rec);
76
77 /**
78  * Marks the internal record in the UAT as valid or invalid. The record must
79  * exist in the UAT.
80  */
81 WS_DLL_PUBLIC
82 void uat_update_record(uat_t *uat, const void *record, gboolean valid_rec);
83
84 /**
85  * Changes the order of two internal UAT records.
86  */
87 WS_DLL_PUBLIC
88 void uat_swap(uat_t *uat, guint idx_a, guint idx_b);
89
90 /**
91  * Inserts the record at the given index in the internal record list.
92  */
93 WS_DLL_PUBLIC
94 void uat_insert_record_idx(uat_t *uat, guint rec_idx, const void *src_record);
95
96 /**
97  * Removes the record with the given index from the internal record list.
98  */
99 WS_DLL_PUBLIC
100 void uat_remove_record_idx(uat_t *uat, guint rec_idx);
101
102 /**
103  * Moves the entry from the old position to the new one
104  */
105 WS_DLL_PUBLIC
106 void uat_move_index(uat_t *uat, guint old_idx, guint new_idx);
107
108 /**
109  * Removes and destroys all records from the UAT.
110  */
111 WS_DLL_PUBLIC
112 void uat_clear(uat_t *uat);
113
114 /**
115  * Saves the records from an UAT to file.
116  * Returns TRUE on success and FALSE on failure, storing the reason in 'error'
117  * (which must be freed using g_free).
118  */
119 WS_DLL_PUBLIC
120 gboolean uat_save(uat_t *uat, char **error);
121
122 /**
123  * Loads the records for all registered UATs from file.
124  */
125 void uat_load_all(void);
126
127 /**
128  * Dump given UAT record to string in form, which can be later loaded with uat_load_str().
129  */
130 WS_DLL_PUBLIC
131 char *uat_fld_tostr(void *rec, uat_field_t *f);
132
133 /**
134  * Exposes the array of valid records to the UAT consumer (dissectors), updating
135  * the contents of 'data_ptr' and 'num_items_ptr' (see 'uat_new').
136  */
137 #define UAT_UPDATE(uat) do { *((uat)->user_ptr) = (void*)((uat)->user_data->data); *((uat)->nrows_p) = (uat)->user_data->len; } while(0)
138 /**
139  * Get a record from the array of all UAT entries, whether they are semantically
140  * valid or not. This memory must only be used internally in the UAT core and
141  * must not be exposed to dissectors.
142  */
143 #define UAT_INDEX_PTR(uat,idx) (uat->raw_data->data + (uat->record_size * (idx)))
144 /**
145  * Get a record from the array of all valid entries. These records will be
146  * shared with UAT consumers (dissectors).
147  */
148 #define UAT_USER_INDEX_PTR(uat,idx) (uat->user_data->data + (uat->record_size * (idx)))
149
150 #ifdef __cplusplus
151 }
152 #endif /* __cplusplus */
153
154 #endif /* __UAT_INT_H__ */
155
156 /*
157  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
158  *
159  * Local variables:
160  * c-basic-offset: 4
161  * tab-width: 8
162  * indent-tabs-mode: nil
163  * End:
164  *
165  * vi: set shiftwidth=4 tabstop=8 expandtab:
166  * :indentSize=4:tabSize=8:noTabs=true:
167  */