net-snmp 5.7
table_dataset.h
00001 /*
00002  * table_iterator.h 
00003  */
00004 #ifndef _TABLE_DATA_SET_HANDLER_H_
00005 #define _TABLE_DATA_SET_HANDLER_H_
00006 
00007 #ifdef __cplusplus
00008 extern          "C" {
00009 #endif
00010 
00011     /*
00012      * This helper is designed to completely automate the task of storing
00013      * tables of data within the agent that are not tied to external data
00014      * sources (like the kernel, hardware, or other processes, etc).  IE,
00015      * all rows within a table are expected to be added manually using
00016      * functions found below.
00017      */
00018 
00019     void netsnmp_init_table_dataset(void);
00020 
00021 #define TABLE_DATA_SET_NAME "netsnmp_table_data_set"
00022 
00023     /*
00024      * return SNMP_ERR_NOERROR or some SNMP specific protocol error id 
00025      */
00026     typedef int     (Netsnmp_Value_Change_Ok) (char *old_value,
00027                                                size_t old_value_len,
00028                                                char *new_value,
00029                                                size_t new_value_len,
00030                                                void *mydata);
00031 
00032     /*
00033      * stored within a given row 
00034      */
00035     typedef struct netsnmp_table_data_set_storage_s {
00036         unsigned int    column;
00037 
00038         /*
00039          * info about it? 
00040          */
00041         char            writable;
00042         Netsnmp_Value_Change_Ok *change_ok_fn;
00043         void           *my_change_data;
00044 
00045         /*
00046          * data actually stored 
00047          */
00048         u_char          type;
00049         union {                 /* value of variable */
00050             void           *voidp;
00051             long           *integer;
00052             u_char         *string;
00053             oid            *objid;
00054             u_char         *bitstring;
00055             struct counter64 *counter64;
00056 #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
00057             float          *floatVal;
00058             double         *doubleVal;
00059 #endif                          /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */
00060         } data;
00061         u_long          data_len;
00062 
00063         struct netsnmp_table_data_set_storage_s *next;
00064     } netsnmp_table_data_set_storage;
00065 
00066     typedef struct netsnmp_table_data_set_s {
00067         netsnmp_table_data *table;
00068         netsnmp_table_data_set_storage *default_row;
00069         int             allow_creation; /* set to 1 to allow creation of new rows */
00070         unsigned int    rowstatus_column;
00071     } netsnmp_table_data_set;
00072 
00073 
00074 /* ============================
00075  * DataSet API: Table maintenance
00076  * ============================ */
00077 
00078     netsnmp_table_data_set *netsnmp_create_table_data_set(const char *);
00079     netsnmp_table_row *netsnmp_table_data_set_clone_row( netsnmp_table_row *row);
00080     void netsnmp_table_dataset_delete_all_data(
00081                             netsnmp_table_data_set_storage *data);
00082     void netsnmp_table_dataset_delete_row(netsnmp_table_row *row);
00083 
00084     void netsnmp_table_dataset_add_row(netsnmp_table_data_set
00085                                                   *table,
00086                                                   netsnmp_table_row *row);
00087     void
00088         netsnmp_table_dataset_replace_row(netsnmp_table_data_set *table,
00089                                           netsnmp_table_row *origrow,
00090                                           netsnmp_table_row *newrow);
00091     void netsnmp_table_dataset_remove_row(netsnmp_table_data_set
00092                                                      *table,
00093                                                      netsnmp_table_row *row);
00094     void
00095         netsnmp_table_dataset_remove_and_delete_row(netsnmp_table_data_set
00096                                                     *table,
00097                                                     netsnmp_table_row *row);
00098     void netsnmp_delete_table_data_set(netsnmp_table_data_set *table_set);
00099 
00100 /* ============================
00101  * DataSet API: Default row operations
00102  * ============================ */
00103 
00104     /*
00105      * to set, add column, type, (writable) ? 1 : 0 
00106      */
00107     /*
00108      * default value, if not NULL, is the default value used in row
00109      * creation.  It is copied into the storage template (free your
00110      * calling argument). 
00111      */
00112     int netsnmp_table_set_add_default_row(netsnmp_table_data_set *,
00113                                           unsigned int, int, int,
00114                                           void  *default_value,
00115                                           size_t default_value_len);
00116     void netsnmp_table_set_multi_add_default_row(netsnmp_table_data_set *,
00117                                                 ...);
00118 
00119 
00120 /* ============================
00121  * DataSet API: MIB maintenance
00122  * ============================ */
00123 
00124     netsnmp_mib_handler
00125         *netsnmp_get_table_data_set_handler(netsnmp_table_data_set *);
00126     Netsnmp_Node_Handler netsnmp_table_data_set_helper_handler;
00127     int netsnmp_register_table_data_set(netsnmp_handler_registration *,
00128                                         netsnmp_table_data_set *,
00129                                         netsnmp_table_registration_info *);
00130     netsnmp_table_data_set
00131         *netsnmp_extract_table_data_set(netsnmp_request_info *request);
00132     netsnmp_table_data_set_storage
00133         *netsnmp_extract_table_data_set_column(netsnmp_request_info *,
00134                                                unsigned int);
00135     netsnmp_oid_stash_node **
00136     netsnmp_table_dataset_get_or_create_stash(netsnmp_agent_request_info *ari,
00137                                               netsnmp_table_data_set *tds,
00138                                               netsnmp_table_request_info *tri);
00139     netsnmp_table_row *
00140     netsnmp_table_dataset_get_newrow(netsnmp_request_info *request,
00141                                      netsnmp_agent_request_info *reqinfo,
00142                                      int rootoid_len,
00143                                      netsnmp_table_data_set *datatable,
00144                                      netsnmp_table_request_info *table_info);
00145 
00146 
00147 /* ============================
00148  * DataSet API: Config-based operations
00149  * ============================ */
00150 
00151     void netsnmp_register_auto_data_table(netsnmp_table_data_set *table_set,
00152                                           char *registration_name);
00153     void netsnmp_unregister_auto_data_table(netsnmp_table_data_set *table_set,
00154                                             char *registration_name);
00155     void netsnmp_config_parse_table_set(const char *token, char *line);
00156     void netsnmp_config_parse_add_row(  const char *token, char *line);
00157 
00158 
00159 /* ============================
00160  * DataSet API: Row operations
00161  * ============================ */
00162 
00163     netsnmp_table_row *netsnmp_table_data_set_get_first_row(netsnmp_table_data_set *table);
00164     netsnmp_table_row *netsnmp_table_data_set_get_next_row( netsnmp_table_data_set *table,
00165                                                             netsnmp_table_row      *row);
00166     int netsnmp_table_set_num_rows(netsnmp_table_data_set *table);
00167 
00168 
00169 /* ============================
00170  * DataSet API: Column operations
00171  * ============================ */
00172 
00173     netsnmp_table_data_set_storage
00174         *netsnmp_table_data_set_find_column(netsnmp_table_data_set_storage *,
00175                                             unsigned int);
00176     int  netsnmp_mark_row_column_writable(  netsnmp_table_row *row,
00177                                             int column, int writable);
00178     int  netsnmp_set_row_column(            netsnmp_table_row *,
00179                                             unsigned int, int, const void *,
00180                                             size_t);
00181 
00182 /* ============================
00183  * DataSet API: Index operations
00184  * ============================ */
00185 
00186     void netsnmp_table_dataset_add_index(netsnmp_table_data_set
00187                                                     *table, u_char type);
00188     void netsnmp_table_set_add_indexes(netsnmp_table_data_set *tset, ...);
00189 
00190 #ifdef __cplusplus
00191 }
00192 #endif
00193 
00194 #define netsnmp_table_row_add_column(row, type, value, value_len) snmp_varlist_add_variable(&row->indexes, NULL, 0, type, (u_char *) value, value_len)
00195 
00196 #endif                          /* _TABLE_DATA_SET_HANDLER_H_ */