this->packet->set_dscp(this->packet, value);
}
+METHOD(packet_t, get_metadata, metadata_t*,
+ private_esp_packet_t *this, const char *key)
+{
+ return this->packet->get_metadata(this->packet, key);
+}
+
+METHOD(packet_t, set_metadata, void,
+ private_esp_packet_t *this, const char *key, metadata_t *data)
+{
+ this->packet->set_metadata(this->packet, key, data);
+}
+
METHOD(packet_t, skip_bytes, void,
private_esp_packet_t *this, size_t bytes)
{
.set_data = _set_data,
.get_dscp = _get_dscp,
.set_dscp = _set_dscp,
+ .get_metadata = _get_metadata,
+ .set_metadata = _set_metadata,
.skip_bytes = _skip_bytes,
.clone = _clone_,
.destroy = _destroy,
#include "packet.h"
+#include <metadata/metadata_set.h>
+
typedef struct private_packet_t private_packet_t;
/**
* actual chunk returned from get_data, adjusted when skip_bytes is called
*/
chunk_t adjusted_data;
+
+ /**
+ * Set of metadata objects, if any
+ */
+ metadata_set_t *metadata;
};
METHOD(packet_t, set_source, void,
this->adjusted_data = chunk_skip(this->adjusted_data, bytes);
}
+METHOD(packet_t, get_metadata, metadata_t*,
+ private_packet_t *this, const char *key)
+{
+ return metadata_set_get(this->metadata, key);
+}
+
+METHOD(packet_t, set_metadata, void,
+ private_packet_t *this, const char *key, metadata_t *data)
+{
+ if (!this->metadata && data)
+ {
+ this->metadata = metadata_set_create();
+ }
+ metadata_set_put(this->metadata, key, data);
+}
+
METHOD(packet_t, destroy, void,
private_packet_t *this)
{
DESTROY_IF(this->source);
DESTROY_IF(this->destination);
+ metadata_set_destroy(this->metadata);
free(this->data.ptr);
free(this);
}
METHOD(packet_t, clone_, packet_t*,
private_packet_t *this)
{
- packet_t *other;
+ private_packet_t *other;
- other = packet_create();
+ other = (private_packet_t*)packet_create();
if (this->destination)
{
- other->set_destination(other,
- this->destination->clone(this->destination));
+ set_destination(other, this->destination->clone(this->destination));
}
if (this->source)
{
- other->set_source(other, this->source->clone(this->source));
+ set_source(other, this->source->clone(this->source));
}
if (this->data.ptr)
{
- other->set_data(other, chunk_clone(this->adjusted_data));
+ set_data(other, chunk_clone(this->adjusted_data));
}
- other->set_dscp(other, this->dscp);
- return other;
+ other->metadata = metadata_set_clone(this->metadata);
+ set_dscp(other, this->dscp);
+ return &other->public;
}
/**
.get_destination = _get_destination,
.get_dscp = _get_dscp,
.set_dscp = _set_dscp,
+ .get_metadata = _get_metadata,
+ .set_metadata = _set_metadata,
.skip_bytes = _skip_bytes,
.clone = _clone_,
.destroy = _destroy,
*/
void (*set_dscp)(packet_t *this, uint8_t value);
+ /**
+ * Get metadata of this packet.
+ *
+ * @param key key of the metadata to retrieve
+ * @return metadata object (internal data), NULL if not found
+ */
+ metadata_t *(*get_metadata)(packet_t *packet, const char *key);
+
+ /**
+ * Set/remove metadata of this packet.
+ *
+ * @param key key of the metadata (cloned)
+ * @param data metadata object (adopted), NULL to remove and destroy
+ * existing object with the given key
+ */
+ void (*set_metadata)(packet_t *packet, const char *key, metadata_t *data);
+
/**
* Increase the offset where the actual packet data starts.
*