Skip to content

Commit

Permalink
fmt/text2pcap: add re_text2pcap_trace helper
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Feb 8, 2024
1 parent dd87426 commit f64ff6b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
4 changes: 3 additions & 1 deletion include/re_fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ size_t utf8_byteseq(char u[4], unsigned cp);
struct re_text2pcap {
bool in;
const struct mbuf *mb;
char *id;
const char *id;
};

int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap);
void re_text2pcap_trace(const char *name, const char *id, bool in,
const struct mbuf *mb);
21 changes: 21 additions & 0 deletions src/fmt/text2pcap.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <re_types.h>
#include <re_fmt.h>
#include <re_mbuf.h>
#include <re_trace.h>
#include <re_mem.h>


int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap)
Expand All @@ -29,3 +31,22 @@ int re_text2pcap(struct re_printf *pf, struct re_text2pcap *pcap)

return 0;
}


void re_text2pcap_trace(const char *name, const char *id, bool in,
const struct mbuf *mb)
{
struct re_text2pcap pcap = {.in = in, .mb = mb, .id = id};
size_t pcap_buf_sz = (mbuf_get_left(mb) * 3) + 64;

char *pcap_buf = mem_alloc(pcap_buf_sz, NULL);
if (!pcap_buf)
return;

re_snprintf(pcap_buf, pcap_buf_sz, "%H", re_text2pcap, &pcap);

re_trace_event("pcap", name, 'I', NULL, RE_TRACE_ARG_STRING_COPY,
"pcap", pcap_buf);

mem_deref(pcap_buf);
}

0 comments on commit f64ff6b

Please sign in to comment.