epan: Add p_set_proto_data.

Add p_set_proto_data, which either updates our entry if we have a
proto+key match or adds an entry if we don't. Use it with
p_set_proto_depth. Document it and our other proto_data routines.
This commit is contained in:
Gerald Combs 2021-12-28 18:52:30 -08:00 committed by A Wireshark GitLab Utility
parent f02d2a4793
commit d0408b8b78
3 changed files with 85 additions and 1 deletions

View File

@ -1014,6 +1014,7 @@ libwireshark.so.0 libwireshark0 #MINVER#
p_get_proto_data@Base 1.9.1
p_get_proto_depth@Base 3.3.0
p_remove_proto_data@Base 1.12.0~rc1
p_set_proto_data@Base 3.7.0
p_set_proto_depth@Base 3.3.0
parse_key_string@Base 1.9.1
plugin_if_apply_filter@Base 1.99.8

View File

@ -73,6 +73,33 @@ p_add_proto_data(wmem_allocator_t *tmp_scope, struct _packet_info* pinfo, int pr
*proto_list = g_slist_prepend(*proto_list, p1);
}
void
p_set_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key, void *proto_data)
{
proto_data_t temp;
GSList *item;
temp.proto = proto;
temp.key = key;
temp.proto_data = NULL;
if (scope == pinfo->pool) {
item = g_slist_find_custom(pinfo->proto_data, &temp, p_compare);
} else if (scope == wmem_file_scope()) {
item = g_slist_find_custom(pinfo->fd->pfd, &temp, p_compare);
} else {
DISSECTOR_ASSERT(!"invalid wmem scope");
}
if (item) {
proto_data_t *pd = (proto_data_t *)item->data;
pd->proto_data = proto_data;
return;
}
p_add_proto_data(scope, pinfo, proto, key, proto_data);
}
void *
p_get_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key)
{
@ -143,7 +170,7 @@ p_get_proto_name_and_key(wmem_allocator_t *scope, struct _packet_info* pinfo, gu
#define PROTO_DEPTH_KEY 0x3c233fb5 // printf "0x%02x%02x\n" ${RANDOM} ${RANDOM}
void p_set_proto_depth(struct _packet_info *pinfo, int proto, unsigned depth) {
p_add_proto_data(pinfo->pool, pinfo, proto, PROTO_DEPTH_KEY, GUINT_TO_POINTER(depth));
p_set_proto_data(pinfo->pool, pinfo, proto, PROTO_DEPTH_KEY, GUINT_TO_POINTER(depth));
}
unsigned p_get_proto_depth(struct _packet_info *pinfo, int proto) {

View File

@ -27,9 +27,65 @@ extern "C" {
*/
/* Allocator should be either pinfo->pool or wmem_file_scope() */
/**
* Add data associated with a protocol.
*
* This can be used to persist file-scoped data between packets or share
* packet-scoped data between dissectors without having to use global
* variables.
*
* Each call adds a new entry to the protocol data list.
*
* @param scope The memory scope, either pinfo->pool or wmem_file_scope().
* @param pinfo This dissection's packet info.
* @param proto The protocol ID.
* @param key A unique key for the data.
* @param proto_data The data to add.
*/
WS_DLL_PUBLIC void p_add_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key, void *proto_data);
/**
* Set data associated with a protocol.
*
* This can be used to persist file-scoped data between packets or share
* packet-scoped data between dissectors without having to use global
* variables.
*
* If the protocol data list contains a matching entry it will be updated,
* otherwise a new entry will be created.
*
* @param scope The memory scope, either pinfo->pool or wmem_file_scope().
* @param pinfo This dissection's packet info.
* @param proto The protocol ID.
* @param key A unique key for the data.
* @param proto_data The data to add.
*/
WS_DLL_PUBLIC void p_set_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key, void *proto_data);
/**
* Fetch data associated with a protocol.
*
* @param scope The memory scope, typically pinfo->pool or wmem_file_scope().
* @param pinfo This dissection's packet info.
* @param proto The protocol ID.
* @param key A unique key for the data.
* @return The data set using p_set_proto_data or most recently added
* using p_add_proto_data if the scope, protocol ID, and key match,
* otherwise NULL.
*/
WS_DLL_PUBLIC void *p_get_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key);
/**
* Remove data associated with a protocol.
*
* @param scope The memory scope, typically pinfo->pool or wmem_file_scope().
* @param pinfo This dissection's packet info.
* @param proto The protocol ID.
* @param key A unique key for the data.
*/
WS_DLL_PUBLIC void p_remove_proto_data(wmem_allocator_t *scope, struct _packet_info* pinfo, int proto, guint32 key);
gchar *p_get_proto_name_and_key(wmem_allocator_t *scope, struct _packet_info* pinfo, guint pfd_index);
/**