3 * User Accessible Tables
4 * Maintain an array of user accessible data structures
7 * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
9 * Wireshark - Network traffic analyzer
10 * By Gerald Combs <gerald@wireshark.org>
11 * Copyright 2001 Gerald Combs
13 * SPDX-License-Identifier: GPL-2.0-or-later
22 #include "ws_symbol_export.h"
26 #endif /* __cplusplus */
28 typedef struct _uat_fld_rep_t uat_fld_rep_t
;
29 typedef struct _uat_rep_t uat_rep_t
;
31 typedef void (*uat_rep_fld_free_cb_t
)(uat_fld_rep_t
*);
32 typedef void (*uat_rep_free_cb_t
)(uat_rep_t
*);
34 typedef struct _fld_data_t
{
37 uat_rep_fld_free_cb_t free_rep
;
47 void** user_ptr
; /**< Pointer to a dissector variable where an array of valid records are stored. */
48 unsigned* nrows_p
; /**< Pointer to a dissector variable where the number of valid records in user_ptr are written. */
49 uat_copy_cb_t copy_cb
;
50 uat_update_cb_t update_cb
;
51 uat_free_cb_t free_cb
;
52 uat_post_update_cb_t post_update_cb
;
53 uat_reset_cb_t reset_cb
;
56 const char** default_values
;
58 GArray
* user_data
; /**< An array of valid records that will be exposed to the dissector. */
59 GArray
* raw_data
; /**< An array of records containing possibly invalid data. For internal use only. */
60 GArray
* valid_data
; /**< An array of booleans describing whether the records in 'raw_data' are valid or not. */
63 uat_rep_free_cb_t free_rep
;
68 char* uat_get_actual_filename(uat_t
* uat
, bool for_writing
);
71 * Clones the given record and stores it internally in the UAT. If it is
72 * considered a valid record, then it will also be cloned and stored in the
73 * externally visible list.
76 void* uat_add_record(uat_t
*uat
, const void *orig_rec_ptr
, bool valid_rec
);
79 * Marks the internal record in the UAT as valid or invalid. The record must
83 void uat_update_record(uat_t
*uat
, const void *record
, bool valid_rec
);
86 * Changes the order of two internal UAT records.
89 void uat_swap(uat_t
*uat
, unsigned idx_a
, unsigned idx_b
);
92 * Inserts the record at the given index in the internal record list.
95 void uat_insert_record_idx(uat_t
*uat
, unsigned rec_idx
, const void *src_record
);
98 * Removes the record with the given index from the internal record list.
99 * If the UAT has a free_cb it is called for the removed record.
102 void uat_remove_record_idx(uat_t
*uat
, unsigned rec_idx
);
105 * Removes the given number of records starting with the given index from
106 * the internal record list. If the UAT has a free_cb it is called for
107 * the removed records.
110 void uat_remove_record_range(uat_t
*uat
, unsigned rec_idx
, unsigned count
);
113 * Moves the entry from the old position to the new one
116 void uat_move_index(uat_t
*uat
, unsigned old_idx
, unsigned new_idx
);
119 * Removes and destroys all records from the UAT.
122 void uat_clear(uat_t
*uat
);
125 * Saves the records from an UAT to file.
126 * Returns true on success and false on failure, storing the reason in 'error'
127 * (which must be freed using g_free).
130 bool uat_save(uat_t
*uat
, char **error
);
133 * Loads the records for all registered UATs from file.
135 void uat_load_all(void);
138 * Dump given UAT record to string in form which can be later loaded with uat_load_str().
139 * XXX - In fact this only dumps a single field. To produce the format for
140 * uat_load_str(), join all the fields as CSV records, escaping and double-
141 * quoting field types other than PT_TXTMOD_HEXBYTES. Perhaps we should have
142 * a function that dumps the entire record.
145 char *uat_fld_tostr(void *rec
, uat_field_t
*f
);
148 * Exposes the array of valid records to the UAT consumer (dissectors), updating
149 * the contents of 'data_ptr' and 'num_items_ptr' (see 'uat_new').
151 #define UAT_UPDATE(uat) do { *((uat)->user_ptr) = (void*)((uat)->user_data->data); *((uat)->nrows_p) = (uat)->user_data->len; } while(0)
153 * Get a record from the array of all UAT entries, whether they are semantically
154 * valid or not. This memory must only be used internally in the UAT core and
155 * must not be exposed to dissectors.
157 #define UAT_INDEX_PTR(uat,idx) (uat->raw_data->data + (uat->record_size * (idx)))
159 * Get a record from the array of all valid entries. These records will be
160 * shared with UAT consumers (dissectors).
162 #define UAT_USER_INDEX_PTR(uat,idx) (uat->user_data->data + (uat->record_size * (idx)))
166 #endif /* __cplusplus */
168 #endif /* __UAT_INT_H__ */
171 * Editor modelines - https://www.wireshark.org/tools/modelines.html
176 * indent-tabs-mode: nil
179 * vi: set shiftwidth=4 tabstop=8 expandtab:
180 * :indentSize=4:tabSize=8:noTabs=true: