Browse code

modules/tsilo: added missing ts_rpc* files

Federico Cabiddu authored on 13/11/2014 13:48:25
Showing 3 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,221 @@
1
+/**
2
+ * $Id$
3
+ *
4
+ * Copyright (C) 2014 Federico Cabiddu (federico.cabiddu@gmail.com)
5
+ *
6
+ * This file is part of SIP-Router.org, a free SIP server.
7
+ *
8
+ * SIP-Router is free software; you can redistribute it and/or modify
9
+ * it under the terms of the GNU General Public License as published by
10
+ * the Free Software Foundation; either version 2 of the License, or
11
+ * (at your option) any later version
12
+ *
13
+ * Kamailio is distributed in the hope that it will be useful,
14
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
+ * GNU General Public License for more details.
17
+ *
18
+ * You should have received a copy of the GNU General Public License
19
+ * along with this program; if not, write to the Free Software
20
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
+ */
22
+
23
+
24
+#include <string.h>
25
+#include <stdio.h>
26
+#include "ts_hash.h"
27
+#include "ts_rpc.h"
28
+
29
+
30
+static const char* rpc_tsilo_dump_doc[2] = {
31
+	"Dump tsilo transactions table",
32
+	0
33
+};
34
+
35
+
36
+static const char* rpc_tsilo_lookup_doc[2] = {
37
+	"Lookup one R-URI in the tsilo transactions table",
38
+	0
39
+};
40
+
41
+/************************ helper functions ****************************/
42
+
43
+/*!
44
+ * \brief Add a node for a transaction
45
+ */
46
+static inline int rpc_dump_transaction(rpc_t* rpc, void* ctx, void *ih, ts_transaction_t* t)
47
+{
48
+	void* vh;
49
+
50
+	if(rpc->struct_add(ih, "{", "Transaction", &vh)<0)
51
+	{
52
+		rpc->fault(ctx, 500, "Internal error creating transaction struct");
53
+		return -1;
54
+	}
55
+	if(rpc->struct_add(vh, "d", "Tindex", t->tindex)<0) {
56
+		rpc->fault(ctx, 500, "Internal error adding tindex");
57
+		return -1;
58
+	}
59
+
60
+	if(rpc->struct_add(vh, "d", "Tlabel", t->tlabel)<0) {
61
+		rpc->fault(ctx, 500, "Internal error adding tlabel");
62
+		return -1;
63
+	}
64
+	return 0;
65
+}
66
+
67
+
68
+/*************************** RPC functions *****************************/
69
+
70
+
71
+/*!
72
+ * \brief Dump the content of the tsilo table
73
+ * \param rpc RPC node that should be filled
74
+ * \param c RPC void pointer
75
+ */
76
+static void rpc_tsilo_dump(rpc_t *rpc, void *c)
77
+{
78
+	ts_transaction_t* trans;
79
+	struct ts_urecord* record;
80
+	struct ts_entry* entry;
81
+
82
+	str brief = {0, 0};
83
+
84
+	int max, res, n, ntrans, i;
85
+	int short_dump = 0;
86
+
87
+	void* th;
88
+	void* ah;
89
+	void* ih;
90
+	void* sh;
91
+
92
+	rpc->scan(c, "*S", &brief);
93
+
94
+	if(brief.len==5 && (strncmp(brief.s, "brief", 5)==0))
95
+		/* short version */
96
+		short_dump = 1;
97
+
98
+	if (rpc->add(c, "{", &th) < 0)
99
+	{
100
+		rpc->fault(c, 500, "Internal error creating top rpc");
101
+		return;
102
+	}
103
+
104
+	if (short_dump==0) {
105
+		res = rpc->struct_add(th, "d{",
106
+			"Size",		t_table->size,
107
+			"R-URIs",	&ah);
108
+	} else {
109
+		res = rpc->struct_add(th, "d",
110
+			"Size",		t_table->size);
111
+	}
112
+	if (res<0)
113
+	{
114
+		rpc->fault(c, 500, "Internal error creating inner struct");
115
+		return;
116
+	}
117
+
118
+	/* add the entries per hash */
119
+	for(i=0,n=0,max=0,ntrans=0; i<t_table->size; i++) {
120
+		entry = &t_table->entries[i];
121
+		lock_entry(entry);
122
+
123
+		n += entry->n;
124
+		if(max<entry->n)
125
+			max= entry->n;
126
+		for( record = entry->first ; record ; record=record->next ) {
127
+			/* add entry */
128
+			if(short_dump==0)
129
+			{
130
+				if(rpc->struct_add(ah, "Sd{",
131
+					"R-URI", &record->ruri,
132
+					"Hash", record->rurihash,
133
+					"Transactions", &ih)<0)
134
+				{
135
+					unlock_entry(entry);
136
+					rpc->fault(c, 500, "Internal error creating ruri struct");
137
+					return;
138
+				}
139
+			}
140
+			for( trans=record->transactions ; trans ; trans=trans->next) {
141
+				ntrans += 1;
142
+				if (short_dump==0) {
143
+					if (rpc_dump_transaction(rpc, c, ih, trans) == -1) {
144
+						unlock_entry(entry);
145
+						return;
146
+					}
147
+				}
148
+			}
149
+		}
150
+		unlock_entry(entry);
151
+	}
152
+
153
+	/* extra attributes node */
154
+	if(rpc->struct_add(th, "{", "Stats",    &sh)<0)	{
155
+		rpc->fault(c, 500, "Internal error creating stats struct");
156
+		return;
157
+	}
158
+	if(rpc->struct_add(sh, "ddd",
159
+		"RURIs", n,
160
+		"Max-Slots", max,
161
+		"Transactions", ntrans)<0)
162
+	{
163
+		rpc->fault(c, 500, "Internal error adding stats");
164
+		return;
165
+	}
166
+}
167
+/*!
168
+ * \brief Show the transactions for a given R-URI
169
+ * \param rpc RPC node that should be filled
170
+ * \param c RPC void pointer
171
+ */
172
+static void rpc_tsilo_lookup(rpc_t *rpc, void *c)
173
+{
174
+	ts_transaction_t* trans;
175
+	struct ts_urecord* record;
176
+
177
+	str ruri = {0, 0};
178
+
179
+	int res;
180
+
181
+	void* th;
182
+
183
+	if (rpc->scan(c, "S", &ruri) != 1) {
184
+		rpc->fault(c, 500, "No RURI to lookup specified");
185
+		return;
186
+	}
187
+
188
+	lock_entry_by_ruri(&ruri);
189
+
190
+	/* look for urecord */
191
+	res = get_ts_urecord(&ruri, &record);
192
+	if (res) {
193
+		unlock_entry_by_ruri(&ruri);
194
+		rpc->fault(c, 404, "RURI not found in tsilo table");
195
+		return;
196
+	}
197
+
198
+	if (rpc->add(c, "{", &th) < 0)
199
+	{
200
+		unlock_entry_by_ruri(&ruri);
201
+		rpc->fault(c, 500, "Internal error creating top rpc");
202
+		return;
203
+	}
204
+
205
+	/* add the transactions */
206
+	for( trans=record->transactions ; trans ; trans=trans->next) {
207
+		if (rpc_dump_transaction(rpc, c, th, trans) == -1) {
208
+			unlock_entry_by_ruri(&ruri);
209
+			return;
210
+		}
211
+	}
212
+	unlock_entry_by_ruri(&ruri);
213
+	return;
214
+}
215
+
216
+rpc_export_t rpc_methods[] = {
217
+	{ "ts.dump",	rpc_tsilo_dump,		rpc_tsilo_dump_doc,		0 },
218
+	{ "ts.lookup",	rpc_tsilo_lookup,	rpc_tsilo_lookup_doc,	0 },
219
+    { 0, 0, 0, 0}
220
+};
221
+
0 222
new file mode 100644
... ...
@@ -0,0 +1,35 @@
1
+/*
2
+ * Copyright (C) 2014 Federico Cabiddu, federico.cabiddu@gmail.com
3
+ *
4
+ * This file is part of Kamailio, a free SIP server.
5
+ *
6
+ * Kamailio is free software; you can redistribute it and/or modify
7
+ * it under the terms of the GNU General Public License as published by
8
+ * the Free Software Foundation; either version 2 of the License, or
9
+ * (at your option) any later version
10
+ *
11
+ * Kamailio is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License
17
+ * along with this program; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19
+ *
20
+ */
21
+
22
+/*!
23
+ * \file
24
+ * \brief Functions and definitions related to per user transaction indexing and searching
25
+ * \ingroup tsilo
26
+ * Module: \ref tsilo
27
+ */
28
+
29
+#ifndef _TS_RPC_H_
30
+#define _TS_RPC_H_
31
+
32
+#include "../../rpc.h"
33
+
34
+extern rpc_export_t rpc_methods[];
35
+#endif
... ...
@@ -32,7 +32,6 @@
32 32
 #include "../../modules/tm/tm_load.h"
33 33
 #include "../../modules/registrar/api.h"
34 34
 #include "../../dset.h"
35
-#include "../../lib/kmi/mi.h"
36 35
 #include "../../rpc_lookup.h"
37 36
 
38 37
 #include "ts_hash.h"