/
b2b_logic_ctx.c
101 lines (88 loc) · 2.7 KB
/
b2b_logic_ctx.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*
* Copyright (C) 2022 OpenSIPS Solutions
*
* This file is part of opensips, a free SIP server.
*
* opensips is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* opensips is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "records.h"
#include "b2b_logic_ctx.h"
static b2bl_tuple_t *b2bl_ctx_get_tuple(str *key)
{
b2bl_tuple_t *tuple = b2bl_get_tuple(key);
if (!tuple) {
LM_BUG("could not find logic tuple [%.*s]\n", key->len, key->s);
abort();
}
return tuple;
}
static void b2bl_ctx_release_tuple(b2bl_tuple_t *tuple)
{
lock_release(&b2bl_htable[tuple->hash_index].lock);
}
int b2bl_ctx_register_int(context_destroy_f f)
{
return context_register_int(CONTEXT_B2B_LOGIC, f);
}
int b2bl_ctx_register_str(context_destroy_f f)
{
return context_register_str(CONTEXT_B2B_LOGIC, f);
}
int b2bl_ctx_register_ptr(context_destroy_f f)
{
return context_register_ptr(CONTEXT_B2B_LOGIC, f);
}
void b2bl_ctx_put_int(str *key, int pos, int data)
{
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);
context_put_int(CONTEXT_B2B_LOGIC, context_of(tuple), pos, data);
b2bl_ctx_release_tuple(tuple);
}
void b2bl_ctx_put_str(str *key, int pos, str *data)
{
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);
context_put_str(CONTEXT_B2B_LOGIC, context_of(tuple), pos, data);
b2bl_ctx_release_tuple(tuple);
}
void b2bl_ctx_put_ptr(str *key, int pos, void *data)
{
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);
context_put_ptr(CONTEXT_B2B_LOGIC, context_of(tuple), pos, data);
b2bl_ctx_release_tuple(tuple);
}
int b2bl_ctx_get_int(str *key, int pos)
{
int ret;
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);
ret = context_get_int(CONTEXT_B2B_LOGIC, context_of(tuple), pos);
b2bl_ctx_release_tuple(tuple);
return ret;
}
str *b2bl_ctx_get_str(str *key, int pos)
{
str *ret;
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);
ret = context_get_str(CONTEXT_B2B_LOGIC, context_of(tuple), pos);
b2bl_ctx_release_tuple(tuple);
return ret;
}
void *b2bl_ctx_get_ptr(str *key, int pos)
{
void *ret;
b2bl_tuple_t *tuple = b2bl_ctx_get_tuple(key);
ret = context_get_ptr(CONTEXT_B2B_LOGIC, context_of(tuple), pos);
b2bl_ctx_release_tuple(tuple);
return ret;
}