/
snmpSIPMethodSupportedTable.c
258 lines (208 loc) · 7.44 KB
/
snmpSIPMethodSupportedTable.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/*
* SNMPStats Module
* Copyright (C) 2006 SOMA Networks, INC.
* Written by: Jeffrey Magder (jmagder@somanetworks.com)
*
* This file is part of Kamailio, a free SIP server.
*
* Kamailio 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
*
* Kamailio 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
*
* The file implements the kamailioSIPMethodSupportedTable. The table is
* populated by looking to see which modules are loaded, and guessing what SIP
* Methods they provide. It is quite possible that this initial implementation
* is not very good at guessing. This should be fixed in future releases as
* more information becomes available.
*
* For full details, please see the KAMAILIO-SIP-COMMON-MIB.
*
*/
#include "../../core/sr_module.h"
#include "../../core/mem/mem.h"
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <net-snmp/library/snmp_assert.h>
#include "snmpstats_globals.h"
#include "snmpSIPMethodSupportedTable.h"
static netsnmp_handler_registration *my_handler = NULL;
static netsnmp_table_array_callbacks cb;
oid kamailioSIPMethodSupportedTable_oid[] = {
kamailioSIPMethodSupportedTable_TABLE_OID};
size_t kamailioSIPMethodSupportedTable_oid_len =
OID_LENGTH(kamailioSIPMethodSupportedTable_oid);
/* Create a row at the given index, containing stringToRegister, and insert it
* into the table. Note that stringToRegister will be copied, so it is not
* necessary to pre-allocate this string anywhere. */
void createRow(int index, char *stringToRegister)
{
kamailioSIPMethodSupportedTable_context *theRow;
oid *OIDIndex;
char *copiedString;
int stringLength;
theRow = SNMP_MALLOC_TYPEDEF(kamailioSIPMethodSupportedTable_context);
if(theRow == NULL) {
LM_ERR("failed to create a row for kamailioSIPMethodSupportedTable\n");
return;
}
OIDIndex = pkg_malloc(sizeof(oid));
if(OIDIndex == NULL) {
free(theRow);
LM_ERR("failed to create a row for kamailioSIPMethodSupportedTable\n");
return;
}
stringLength = strlen(stringToRegister);
copiedString = pkg_malloc((stringLength + 1) * sizeof(char));
if(copiedString == NULL) {
free(theRow);
free(OIDIndex);
LM_ERR("failed to create a row for kamailioSIPMethodSupportedTable\n");
return;
}
strcpy(copiedString, stringToRegister);
OIDIndex[0] = index;
theRow->index.len = 1;
theRow->index.oids = OIDIndex;
theRow->kamailioSIPMethodSupportedIndex = index;
theRow->kamailioSIPMethodName = (unsigned char *)copiedString;
theRow->kamailioSIPMethodName_len = stringLength;
CONTAINER_INSERT(cb.container, theRow);
}
/* Initializes the kamailioSIPMethodSupportedTable, and populates the tables
* contents */
void init_kamailioSIPMethodSupportedTable(void)
{
initialize_table_kamailioSIPMethodSupportedTable();
/* Tables is defined as follows:
*
* 1) METHOD_INVITE
* 2) METHOD_CANCEL
* 3) METHOD_ACK
* 4) METHOD_BYE
* 5) METHOD_INFO
* 6) METHOD_OPTIONS
* 7) METHOD_UPDATE
* 8) METHOD_REGISTER
* 9) METHOD_MESSAGE
* 10) METHOD_SUBSCRIBE
* 11) METHOD_NOTIFY
* 12) METHOD_PRACK
* 13) METHOD_REFER
* 14) METHOD_PUBLISH
*
* We should keep these indices fixed. For example if we don't support
* METHOD_REGISTER but we do support METHOD_MESSAGE, then METHOD_MESSAGE
* should still be at index 9.
*
* NOTE: My way of checking what METHODS we support is probably wrong.
* Please feel free to correct it! */
createRow(1, "METHOD_INVITE");
createRow(2, "METHOD_CANCEL");
createRow(3, "METHOD_ACK");
createRow(4, "METHOD_BYE");
if(module_loaded("options") || module_loaded("siputils")) {
createRow(6, "METHOD_OPTIONS");
}
createRow(7, "METHOD_UPDATE");
if(module_loaded("registrar")) {
createRow(8, "METHOD_REGISTER");
createRow(10, "METHOD_SUBSCRIBE");
createRow(11, "METHOD_NOTIFY");
}
createRow(5, "METHOD_INFO");
createRow(9, "METHOD_MESSAGE");
createRow(12, "METHOD_PRACK");
createRow(13, "METHOD_REFER");
createRow(14, "METHOD_PUBLISH");
}
/* Initialize the kamailioSIPMethodSupportedTable by defining its structure and
* callback mechanisms */
void initialize_table_kamailioSIPMethodSupportedTable(void)
{
netsnmp_table_registration_info *table_info;
if(my_handler) {
snmp_log(LOG_ERR, "initialize_table_kamailioSIPMethodSupported"
"Table_handler called again\n");
return;
}
memset(&cb, 0x00, sizeof(cb));
/** create the table structure itself */
table_info = SNMP_MALLOC_TYPEDEF(netsnmp_table_registration_info);
if(table_info==NULL) {
snmp_log(LOG_ERR, "failed to allocate table_info\n");
return;
}
my_handler = netsnmp_create_handler_registration(
"kamailioSIPMethodSupportedTable",
netsnmp_table_array_helper_handler,
kamailioSIPMethodSupportedTable_oid,
kamailioSIPMethodSupportedTable_oid_len, HANDLER_CAN_RONLY);
if(!my_handler) {
SNMP_FREE(table_info);
snmp_log(LOG_ERR, "malloc failed in initialize_table_kamailio"
"SIPMethodSupportedTable_handler\n");
return;
}
netsnmp_table_helper_add_index(table_info, ASN_UNSIGNED);
table_info->min_column = kamailioSIPMethodSupportedTable_COL_MIN;
table_info->max_column = kamailioSIPMethodSupportedTable_COL_MAX;
/***************************************************
* registering the table with the master agent
*/
cb.get_value = kamailioSIPMethodSupportedTable_get_value;
cb.container =
netsnmp_container_find("kamailioSIPMethodSupportedTable_primary:"
"kamailioSIPMethodSupportedTable:"
"table_container");
DEBUGMSGTL(("initialize_table_kamailioSIPMethodSupportedTable",
"Registering table kamailioSIPMethodSupportedTable"
"as a table array\n"));
netsnmp_table_container_register(
my_handler, table_info, &cb, cb.container, 1);
}
/*
* This routine is called to process get requests for elements of the table.
*
* The function is pretty much left as is from the auto-generated code.
*/
int kamailioSIPMethodSupportedTable_get_value(netsnmp_request_info *request,
netsnmp_index *item, netsnmp_table_request_info *table_info)
{
netsnmp_variable_list *var = request->requestvb;
kamailioSIPMethodSupportedTable_context *context =
(kamailioSIPMethodSupportedTable_context *)item;
switch(table_info->colnum) {
case COLUMN_KAMAILIOSIPMETHODNAME:
/** SnmpAdminString = ASN_OCTET_STR */
snmp_set_var_typed_value(var, ASN_OCTET_STR,
(unsigned char *)context->kamailioSIPMethodName,
context->kamailioSIPMethodName_len);
break;
default: /** We shouldn't get here */
snmp_log(LOG_ERR, "unknown column in kamailioSIPMethod"
"SupportedTable_get_value\n");
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
/*
* kamailioSIPMethodSupportedTable_get_by_idx is an auto-generated function.
*/
const kamailioSIPMethodSupportedTable_context *
kamailioSIPMethodSupportedTable_get_by_idx(netsnmp_index *hdr)
{
return (const kamailioSIPMethodSupportedTable_context *)CONTAINER_FIND(
cb.container, hdr);
}