File: cookie_cache.h

package info (click to toggle)
rtpengine 13.5.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,676 kB
  • sloc: ansic: 86,764; perl: 59,422; python: 3,193; sh: 1,030; makefile: 693; asm: 211
file content (55 lines) | stat: -rw-r--r-- 1,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#ifndef _COOKIE_CACHE_H_
#define _COOKIE_CACHE_H_

#include <time.h>
#include <glib.h>

#include "helpers.h"
#include "str.h"
#include "control_ng.h"
#include "bencode.h"

struct cookie_cache_state {
	bencode_buffer_t buffer;
	GHashTable *in_use;
	GHashTable *cookies;
};

typedef struct cache_entry {
	str reply;
	str callid;
	enum ng_opmode command;
} cache_entry;

INLINE cache_entry *cache_entry_dup(const cache_entry *s) {
	if (!s)
		return NULL;
	cache_entry *r;
	r = malloc(sizeof(*r));
	r->reply = str_dup_str(&s->reply);
	r->command = s->command;
	r->callid = str_dup_str(&s->callid);
	return r;
}
INLINE void cache_entry_free(void *p) {
	cache_entry *s = p;
	if (!s)
		return;
	free(s->reply.s);
	free(s->callid.s);
	free(s);
}
struct cookie_cache {
	mutex_t lock;
	cond_t cond;
	struct cookie_cache_state current, old;
	int64_t swap_time_us;
};

void cookie_cache_init(struct cookie_cache *);
cache_entry *cookie_cache_lookup(struct cookie_cache *, const str *);
void cookie_cache_insert(struct cookie_cache *, const str *, const struct cache_entry *);
void cookie_cache_remove(struct cookie_cache *, const str *);
void cookie_cache_cleanup(struct cookie_cache *);

#endif