0
0
mirror of https://github.com/hufrea/byedpi.git synced 2025-06-29 18:21:14 +00:00
byedpi/mpool.h
2025-06-16 10:37:00 +03:00

66 lines
1.1 KiB
C

#ifndef MPOOL_H
#define MPOOL_H
#include <stdbool.h>
#include <time.h>
#include "kavl.h"
#include "params.h"
#define CMP_BYTES 0
#define CMP_BITS 1
#define CMP_HOST 2
#pragma pack(push, 1)
struct cache_key {
uint16_t family;
uint16_t port;
union {
struct in_addr v4;
struct in6_addr v6;
} ip;
};
struct cache_data {
struct cache_key key;
int host_len;
char host[];
};
#pragma pack(pop)
struct elem {
int len;
char *data;
unsigned char cmp_type;
KAVL_HEAD(struct elem) head;
};
struct elem_i {
struct elem i;
struct desync_params *dp;
time_t time;
};
struct mphdr {
bool static_data;
unsigned char cmp_type;
size_t count;
struct elem *root;
};
struct mphdr *mem_pool(bool is_static, unsigned char cmp_type);
struct elem *mem_get(const struct mphdr *hdr, const char *str, int len);
struct elem *mem_add(struct mphdr *hdr, char *str, int len, size_t ssize);
void mem_delete(struct mphdr *hdr, const char *str, int len);
void mem_destroy(struct mphdr *hdr);
void dump_cache(struct mphdr *hdr, FILE *out);
#endif