libnsh  0.3
Net-SNMP helper C-library
Macros | Typedefs
nsh.h File Reference
#include "table.h"
#include "private.h"
#include "deprecated.h"

Go to the source code of this file.

Macros

#define nsh_register_scalar_ro(name)   _nsh_register_scalar(name, HANDLER_CAN_RONLY)
 
#define nsh_register_scalar_rw(name)   _nsh_register_scalar(name, HANDLER_CAN_RWRITE)
 
#define nsh_scalar_handler_const(name, type, value)   _nsh_scalar_handler(name, type, 0, NULL, sizeof(long), value, NULL)
 
#define nsh_scalar_handler_ro(name, type, callback, size)   _nsh_scalar_handler(name, type, 0, callback, size, 0, NULL)
 
#define nsh_scalar_str_handler_ro(name, callback, max_length)   _nsh_scalar_handler(name, ASN_OCTET_STR, 0, callback, max_length, 1, NULL)
 
#define nsh_scalar_group_handler_ro(name, type, id, callback, size, isstring)   _nsh_scalar_handler(name, type, id, callback, size, isstring, NULL)
 
#define nsh_scalar_handler_rw(name, type, nsh_get_cb, size, nsh_set_cb)   _nsh_scalar_handler(name, type, 0, nsh_get_cb, size, 0, nsh_set_cb)
 
#define nsh_scalar_str_handler_rw(name, nsh_get_cb, max_length, nsh_set_cb)   _nsh_scalar_handler(name, ASN_OCTET_STR, 0, nsh_get_cb, max_length, 1, nsh_set_cb)
 
#define nsh_scalar_group_handler_rw(name, type, id, nsh_get_cb, size, isstring, nsh_set_cb)   _nsh_scalar_handler(name, type, id, nsh_get_cb, size, isstring, nsh_set_cb)
 
#define nsh_table(name, get_first_cb, get_next_cb, free_cb, table_data, head, num_table, index_list, num_indexes)
 

Typedefs

typedef int(* nsh_get_cb) (void *value, int len, int id)
 
typedef int(* nsh_set_cb) (void *value, int id)
 

Macro Definition Documentation

#define nsh_register_scalar_ro (   name)    _nsh_register_scalar(name, HANDLER_CAN_RONLY)

Register a read-only scalar OID.

Parameters
nameOID define, without the oid_ prefix.

This function will register a read-only scalar handler callback for the defined OID. The name of the callback function is based on the input parameter name, which means that name shall also be the input to the scalar create function which will handle the OID.

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
Examples:
scalar_const.c, scalar_group_ro.c, scalar_ro.c, and scalar_str_ro.c.
#define nsh_register_scalar_rw (   name)    _nsh_register_scalar(name, HANDLER_CAN_RWRITE)

Register a writable scalar OID.

Parameters
nameOID define without the oid_ prefix.

This function will register a read-write scalar handler callback for the defined OID. The name of the callback function is based on the input parameter name, which means that name shall also be the input to the scalar create function which will handle the OID.

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
#define nsh_scalar_group_handler_ro (   name,
  type,
  id,
  callback,
  size,
  isstring 
)    _nsh_scalar_handler(name, type, id, callback, size, isstring, NULL)

Create a grouped read-only scalar OID handler.

Parameters
nameOID define, without the oid_ prefix.
typeOID type. ASN_COUNTER, ASN_INTEGER, ASN_TIMETICKS, ASN_UNSIGNED, ASN_IPADDRESS, ASN_OCTET_STR or ASN_OBJECT_ID.
idGroup identifier for this request.
callbackCallback function to get return value by a request.
sizeData length of handled value.
isstringSet if value is a string.

This function will create a grouped read-only scalar handler callback function. This function will behave in the same maner as nsh_scalar_handler_ro() except that a id is used to distinguish different OID requests. A common callback can therefore be shared between several created handlers. If the isstring parameter is set, the function behaves as nsh_scalar_str_handler_ro(), i.e. with repect to the string length. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_ro().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
Examples:
scalar_group_ro.c.
#define nsh_scalar_group_handler_rw (   name,
  type,
  id,
  nsh_get_cb,
  size,
  isstring,
  nsh_set_cb 
)    _nsh_scalar_handler(name, type, id, nsh_get_cb, size, isstring, nsh_set_cb)

Create a grouped read-write scalar OID handler.

Parameters
nameOID define, without the oid_ prefix.
typeOID type. ASN_COUNTER, ASN_INTEGER, ASN_TIMETICKS, ASN_UNSIGNED, ASN_IPADDRESS, ASN_OCTET_STR or ASN_OBJECT_ID.
idGroup identifier for this request.
nsh_get_cbCallback function to get return value by a request.
sizeData length of handled value.
isstringSet if value is a string.
nsh_set_cbCallback function to set value by a request.

This function will create a grouped read-write scalar handler callback function. This function will behave in the same maner as nsh_scalar_handler_rw() except that a id is used to distinguish different OID requests. A common read callback, nsh_get_cb, and a common write callback, nsh_set_cb, can therefore be shared between several created handlers. If the isstring parameter is set, the function behaves as nsh_scalar_str_handler_rw(), i.e. with repect to the string length. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_rw().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
#define nsh_scalar_handler_const (   name,
  type,
  value 
)    _nsh_scalar_handler(name, type, 0, NULL, sizeof(long), value, NULL)

Create a constant scalar OID handler.

Parameters
nameOID define, without the oid_ prefix.
typeOID type. ASN_COUNTER, ASN_INTEGER, ASN_TIMETICKS, ASN_UNSIGNED or ASN_IPADDRESS.
valueValue to be returned by a request.

This function will create a scalar handler callback function which will return a constant value. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_ro().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
Examples:
scalar_const.c.
#define nsh_scalar_handler_ro (   name,
  type,
  callback,
  size 
)    _nsh_scalar_handler(name, type, 0, callback, size, 0, NULL)

Create a read-only scalar OID handler.

Parameters
nameOID define, without the oid_ prefix.
typeOID type. ASN_COUNTER, ASN_INTEGER, ASN_TIMETICKS, ASN_UNSIGNED, ASN_IPADDRESS, ASN_OCTET_STR or ASN_OBJECT_ID.
callbackCallback function to get return value by a request.
sizeData length of handled value.

This function will create a read-only scalar handler callback function which will return the value from the callback function. If a string value is to be returned, consider using nsh_scalar_str_handler_ro() instead, else the string returned will always be size long. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_ro().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
Examples:
scalar_ro.c.
#define nsh_scalar_handler_rw (   name,
  type,
  nsh_get_cb,
  size,
  nsh_set_cb 
)    _nsh_scalar_handler(name, type, 0, nsh_get_cb, size, 0, nsh_set_cb)

Create a read-write scalar OID handler.

Parameters
nameOID define, without the oid_ prefix.
typeOID type. ASN_COUNTER, ASN_INTEGER, ASN_TIMETICKS, ASN_UNSIGNED, ASN_IPADDRESS, ASN_OCTET_STR or ASN_OBJECT_ID.
nsh_get_cbCallback function to get return value by a request.
sizeData length of handled value.
nsh_set_cbCallback function to set value by a request.

This function will create a read-write scalar handler callback function. A read request to the OID object will return the value from the nsh_get_cb callback function. A write request will pass the value to the nsh_set_cb callback function. If a string value is to be handled, consider using nsh_scalar_str_handler_rw() instead, else the string returned will always be size long. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_rw().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
#define nsh_scalar_str_handler_ro (   name,
  callback,
  max_length 
)    _nsh_scalar_handler(name, ASN_OCTET_STR, 0, callback, max_length, 1, NULL)

Create a read-only string OID handler.

Parameters
nameOID define, without the oid_ prefix.
callbackCallback function to get string value by a request.
max_lengthMaximum length of returned string.

This function will create a read-only string handler callback function which will return the string from the callback function. The function is similar to nsh_scalar_handler_ro() except it will return a string with the correct length, i.e. the actual string length instead of the maximum length of the string. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_ro().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
Examples:
scalar_str_ro.c.
#define nsh_scalar_str_handler_rw (   name,
  nsh_get_cb,
  max_length,
  nsh_set_cb 
)    _nsh_scalar_handler(name, ASN_OCTET_STR, 0, nsh_get_cb, max_length, 1, nsh_set_cb)

Create a read-write string OID handler.

Parameters
nameOID define, without the oid_ prefix.
nsh_get_cbCallback function to get string value by a request.
max_lengthMaximum length of returned string.
nsh_set_cbCallback function to set value by a request.

This function will create a read-write string handler callback function. The function is similar to nsh_scalar_handler_rw() except it will return a string with the correct length, i.e. the actual string length instead of the maximum length of the string. The callback function name will be based on the input parameter name, which should be the same parameter used when registering the OID, i.e with nsh_register_scalar_rw().

Returns
MIB_REGISTERED_OK is returned on success. Failures are MIB_REGISTRATION_FAILED and MIB_DUPLICATE_REGISTRATION.
#define nsh_table (   name,
  get_first_cb,
  get_next_cb,
  free_cb,
  table_data,
  head,
  num_table,
  index_list,
  num_indexes 
)
Value:
nsh_table_get_next(get_next_cb, table_data, index_list, num_indexes) \
nsh_table_get_first(get_first_cb, get_next_cb, head) \
nsh_table_free(free_cb, table_data, head) \
nsh_table_reg_t name = {.free = free_cb, \
.get_first = get_first_cb, \
.get_next = get_next_cb, \
.idx = index_list, \
.num_idx = num_indexes, \
.min_column = NSH_DFLT_MIN_COLUMN, \
.max_column = num_table, \
.timeout = NSH_DFLT_TIMEOUT, \
};

Create table handlers.

Parameters
nameName of table registration object.
get_first_cbName of table get first handler.
get_next_cbName of table get next handler.
free_cbName of table free handler.
table_dataTable data struct.
headHead of table data.
num_tableNumber of entries in table data struct.
index_listTable index struct.
num_indexesNumber of indexes in table index struct.

This function will create table handlers to get first table element, get next table element and to empty all table elements.

Examples:
table.c.

Typedef Documentation

typedef int(* nsh_get_cb) (void *value, int len, int id)

Callback to get (read) value for a get request.

Parameters
valuePointer to variable which should be set to the value that is to be returned by a get request.
lenData size (or maximum data size) of value.
idID for the requested OID.

This callback shall set value to the value which should be returned by a get request. len specifies the data size (or maximum data size) for the requested object. id is used to distinguish the requested OID from others OIDs if the callback is shared between several OID handlers. If the callback is only used for one OID, id can be ignored.

typedef int(* nsh_set_cb) (void *value, int id)

Callback to set (write) value for a set request.

Parameters
valuePointer to variable which holds the value from a set request.
idID for the requested OID.

This callback shall use value to update the value which should be set by a set request. id is used to distinguish the requested OID from others OIDs if the callback is shared between several OID handlers. If the callback is only used for one OID, id can be ignored.