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 const char** default_values; 56 guint ncols; 57 GArray* user_data; /**< An array of valid records that will be exposed to the dissector. */ 58 GArray* raw_data; /**< An array of records containing possibly invalid data. For internal use only. */ 59 GArray* valid_data; /**< An array of booleans describing whether the records in 'raw_data' are valid or not. */ 60 gboolean changed; 61 uat_rep_t* rep; 62 uat_rep_free_cb_t free_rep; 63 gboolean loaded; 64 gboolean from_global; 65 }; 66 67 WS_DLL_PUBLIC 68 gchar* uat_get_actual_filename(uat_t* uat, gboolean for_writing); 69 70 /** 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. 74 */ 75 WS_DLL_PUBLIC 76 void* uat_add_record(uat_t *uat, const void *orig_rec_ptr, gboolean valid_rec); 77 78 /** 79 * Marks the internal record in the UAT as valid or invalid. The record must 80 * exist in the UAT. 81 */ 82 WS_DLL_PUBLIC 83 void uat_update_record(uat_t *uat, const void *record, gboolean valid_rec); 84 85 /** 86 * Changes the order of two internal UAT records. 87 */ 88 WS_DLL_PUBLIC 89 void uat_swap(uat_t *uat, guint idx_a, guint idx_b); 90 91 /** 92 * Inserts the record at the given index in the internal record list. 93 */ 94 WS_DLL_PUBLIC 95 void uat_insert_record_idx(uat_t *uat, guint rec_idx, const void *src_record); 96 97 /** 98 * Removes the record with the given index from the internal record list. 99 */ 100 WS_DLL_PUBLIC 101 void uat_remove_record_idx(uat_t *uat, guint rec_idx); 102 103 /** 104 * Moves the entry from the old position to the new one 105 */ 106 WS_DLL_PUBLIC 107 void uat_move_index(uat_t *uat, guint old_idx, guint new_idx); 108 109 /** 110 * Removes and destroys all records from the UAT. 111 */ 112 WS_DLL_PUBLIC 113 void uat_clear(uat_t *uat); 114 115 /** 116 * Saves the records from an UAT to file. 117 * Returns TRUE on success and FALSE on failure, storing the reason in 'error' 118 * (which must be freed using g_free). 119 */ 120 WS_DLL_PUBLIC 121 gboolean uat_save(uat_t *uat, char **error); 122 123 /** 124 * Loads the records for all registered UATs from file. 125 */ 126 void uat_load_all(void); 127 128 /** 129 * Dump given UAT record to string in form, which can be later loaded with uat_load_str(). 130 */ 131 WS_DLL_PUBLIC 132 char *uat_fld_tostr(void *rec, uat_field_t *f); 133 134 /** 135 * Exposes the array of valid records to the UAT consumer (dissectors), updating 136 * the contents of 'data_ptr' and 'num_items_ptr' (see 'uat_new'). 137 */ 138 #define UAT_UPDATE(uat) do { *((uat)->user_ptr) = (void*)((uat)->user_data->data); *((uat)->nrows_p) = (uat)->user_data->len; } while(0) 139 /** 140 * Get a record from the array of all UAT entries, whether they are semantically 141 * valid or not. This memory must only be used internally in the UAT core and 142 * must not be exposed to dissectors. 143 */ 144 #define UAT_INDEX_PTR(uat,idx) (uat->raw_data->data + (uat->record_size * (idx))) 145 /** 146 * Get a record from the array of all valid entries. These records will be 147 * shared with UAT consumers (dissectors). 148 */ 149 #define UAT_USER_INDEX_PTR(uat,idx) (uat->user_data->data + (uat->record_size * (idx))) 150 151 #ifdef __cplusplus 152 } 153 #endif /* __cplusplus */ 154 155 #endif /* __UAT_INT_H__ */ 156 157 /* 158 * Editor modelines - https://www.wireshark.org/tools/modelines.html 159 * 160 * Local variables: 161 * c-basic-offset: 4 162 * tab-width: 8 163 * indent-tabs-mode: nil 164 * End: 165 * 166 * vi: set shiftwidth=4 tabstop=8 expandtab: 167 * :indentSize=4:tabSize=8:noTabs=true: 168 */ 169