how to get table data inside request handler
Alexander Bubnov <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Hello, all!
Can you please let me know a way getting table data to manipulate it?
below code:
1. init_tables - init tables within main function.
2. Watcher - a callback, it is called when some request is received. Inside
of this callback I would like to change the table content before I need to
get a pointer to the table.
inside Watcher() netsnmp_extract_table_data_set() function get NULL instead
returing data.
#include<string.h>
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
const int ROWID = 2;
static int Watcher(
netsnmp_mib_handler * handler
,netsnmp_handler_registration * reginfo
,netsnmp_agent_request_info * reqinfo
,netsnmp_request_info * requests
)
{
if(MODE_IS_GET(reqinfo->mode))
{
netsnmp_request_info *request;
int i = 0;
for(request=requests;request;request = request->next)
{
netsnmp_table_data_set*table_set =
netsnmp_extract_table_data_set(requests);
if(table_set)
{
fprintf(stderr,"NOT NULL\n");
}
else
{
fprintf(stderr,"NULL\n");
}
}
return SNMP_ERR_NOERROR;
}
else if(MODE_IS_SET(reqinfo->mode))
{
puts("SET request is is not allowed");
return SNMP_ERR_NOTWRITABLE;
}
return SNMP_ERR_GENERR;
}
void init_tables()
{
netsnmp_table_data_set *table_set;
oid some_oid[] = {1,3,6,1,4,1,23668,1025,2,8,1};
const char * table_name = "mytable";
const size_t size_some_oid = OID_LENGTH(some_oid);
int count = 999;
const char* pcount = (const char*)(&count);
table_set = netsnmp_create_table_data_set(table_name);
table_set->allow_creation = 0;
netsnmp_table_dataset_add_index(table_set, ASN_OCTET_STR);
netsnmp_table_set_multi_add_default_row(table_set,
/*
* column 2 = asn type,
* writable = 0,
* default value = NULL,
* default value len = 0
*/
ROWID,ASN_COUNTER,0,NULL,0,
NULL /* done */ );
netsnmp_register_table_data_set(netsnmp_create_handler_registration
(table_name, Watcher,
some_oid,
size_some_oid,
HANDLER_CAN_RONLY|HANDLER_CAN_NOT_CREATE), table_set, NULL);
netsnmp_table_row *row = netsnmp_create_table_data_row();
netsnmp_table_row_add_index(row, ASN_OCTET_STR, "some data string",
strlen("some data string"));
netsnmp_set_row_column(row, ROWID, ASN_COUNTER,
pcount, sizeof(int));
netsnmp_mark_row_column_writable(row, ROWID, 0);
netsnmp_table_dataset_add_row(table_set, row);
}
--
/BR, Alexander
------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users