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