net-snmp 5.7
table_tdata.h
00001 /*
00002  * table_tdata.h 
00003  */
00004 #ifndef _TABLE_TDATA_HANDLER_H_
00005 #define _TABLE_TDATA_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 #define TABLE_TDATA_NAME  "table_tdata"
00020 #define TABLE_TDATA_ROW   "table_tdata"
00021 #define TABLE_TDATA_TABLE "table_tdata_table"
00022 
00023 #define TDATA_FLAG_NO_STORE_INDEXES   0x01
00024 #define TDATA_FLAG_NO_CONTAINER       0x02 /* user will provide container */
00025 
00026     /*
00027      * The (table-independent) per-row data structure
00028      * This is a wrapper round the table-specific per-row data
00029      *   structure, which is referred to as a "table entry"
00030      *
00031      * It should be regarded as an opaque, private data structure,
00032      *   and shouldn't be accessed directly.
00033      */
00034     typedef struct netsnmp_tdata_row_s {
00035         netsnmp_index   oid_index;      /* table_container index format */
00036         netsnmp_variable_list *indexes; /* stored permanently if store_indexes = 1 */
00037         void           *data;   /* the data to store */
00038     } netsnmp_tdata_row;
00039 
00040     /*
00041      * The data structure to hold a complete table.
00042      *
00043      * This should be regarded as an opaque, private data structure,
00044      *   and shouldn't be accessed directly.
00045      */
00046     typedef struct netsnmp_tdata_s {
00047         netsnmp_variable_list *indexes_template;        /* containing only types */
00048         char           *name;   /* if !NULL, it's registered globally */
00049         int             flags;  /* This field may legitimately be accessed by external code */
00050         netsnmp_container *container;
00051     } netsnmp_tdata;
00052 
00053 /* Backwards compatability with the previous (poorly named) data structures */
00054 typedef  struct netsnmp_tdata_row_s netsnmp_table_data2row;
00055 typedef  struct netsnmp_tdata_s     netsnmp_table_data2;
00056 
00057 
00058 /* ============================
00059  * TData API: Table maintenance
00060  * ============================ */
00061 
00062     netsnmp_tdata     *netsnmp_tdata_create_table(const char *name, long flags);
00063     void               netsnmp_tdata_delete_table(netsnmp_tdata *table);
00064     netsnmp_tdata_row *netsnmp_tdata_create_row(void);
00065     netsnmp_tdata_row *netsnmp_tdata_clone_row( netsnmp_tdata_row *row);
00066     int                netsnmp_tdata_copy_row(  netsnmp_tdata_row *dst_row,
00067                                                 netsnmp_tdata_row *src_row);
00068     void           *netsnmp_tdata_delete_row(   netsnmp_tdata_row *row);
00069 
00070     int             netsnmp_tdata_add_row(      netsnmp_tdata     *table,
00071                                                 netsnmp_tdata_row *row);
00072     void            netsnmp_tdata_replace_row(  netsnmp_tdata     *table,
00073                                                 netsnmp_tdata_row *origrow,
00074                                                 netsnmp_tdata_row *newrow);
00075     netsnmp_tdata_row *netsnmp_tdata_remove_row(netsnmp_tdata     *table,
00076                                                 netsnmp_tdata_row *row);
00077     void   *netsnmp_tdata_remove_and_delete_row(netsnmp_tdata     *table,
00078                                                 netsnmp_tdata_row *row);
00079 
00080 
00081 /* ============================
00082  * TData API: MIB maintenance
00083  * ============================ */
00084 
00085     netsnmp_mib_handler *netsnmp_get_tdata_handler(netsnmp_tdata *table);
00086 
00087     int netsnmp_tdata_register(  netsnmp_handler_registration    *reginfo,
00088                                  netsnmp_tdata                   *table,
00089                                  netsnmp_table_registration_info *table_info);
00090     int netsnmp_tdata_unregister(netsnmp_handler_registration    *reginfo);
00091 
00092     netsnmp_tdata      *netsnmp_tdata_extract_table(    netsnmp_request_info *);
00093     netsnmp_container  *netsnmp_tdata_extract_container(netsnmp_request_info *);
00094     netsnmp_tdata_row  *netsnmp_tdata_extract_row(      netsnmp_request_info *);
00095     void               *netsnmp_tdata_extract_entry(    netsnmp_request_info *);
00096 
00097     void netsnmp_insert_tdata_row(netsnmp_request_info *, netsnmp_tdata_row *);
00098     void netsnmp_remove_tdata_row(netsnmp_request_info *, netsnmp_tdata_row *);
00099 
00100 
00101 /* ============================
00102  * TData API: Row operations
00103  * ============================ */
00104 
00105     void * netsnmp_tdata_row_entry( netsnmp_tdata_row *row );
00106     netsnmp_tdata_row *netsnmp_tdata_row_first(netsnmp_tdata     *table);
00107     netsnmp_tdata_row *netsnmp_tdata_row_get(  netsnmp_tdata     *table,
00108                                                netsnmp_tdata_row *row);
00109     netsnmp_tdata_row *netsnmp_tdata_row_next( netsnmp_tdata     *table,
00110                                                netsnmp_tdata_row *row);
00111 
00112     netsnmp_tdata_row *netsnmp_tdata_row_get_byidx(netsnmp_tdata      *table,
00113                                                 netsnmp_variable_list *indexes);
00114     netsnmp_tdata_row *netsnmp_tdata_row_get_byoid(netsnmp_tdata      *table,
00115                                                 oid   *searchfor,
00116                                                 size_t searchfor_len);
00117     netsnmp_tdata_row *netsnmp_tdata_row_next_byidx(netsnmp_tdata     *table,
00118                                                 netsnmp_variable_list *indexes);
00119     netsnmp_tdata_row *netsnmp_tdata_row_next_byoid(netsnmp_tdata     *table,
00120                                                 oid   *searchfor,
00121                                                 size_t searchfor_len);
00122 
00123     int netsnmp_tdata_row_count(netsnmp_tdata *table);
00124 
00125 
00126 /* ============================
00127  * TData API: Index operations
00128  * ============================ */
00129 
00130 #define netsnmp_tdata_add_index(thetable, type) snmp_varlist_add_variable(&thetable->indexes_template, NULL, 0, type, NULL, 0)
00131 #define netsnmp_tdata_row_add_index(row, type, value, value_len) snmp_varlist_add_variable(&row->indexes, NULL, 0, type, (const u_char *) value, value_len)
00132 
00133     int netsnmp_tdata_compare_idx(        netsnmp_tdata_row     *row,
00134                                           netsnmp_variable_list *indexes);
00135     int netsnmp_tdata_compare_oid(        netsnmp_tdata_row     *row,
00136                                           oid *compareto, size_t compareto_len);
00137     int netsnmp_tdata_compare_subtree_idx(netsnmp_tdata_row     *row,
00138                                           netsnmp_variable_list *indexes);
00139     int netsnmp_tdata_compare_subtree_oid(netsnmp_tdata_row     *row,
00140                                           oid *compareto, size_t compareto_len);
00141 
00142 
00143 #ifdef __cplusplus
00144 }
00145 #endif
00146 
00147 #endif                          /* _TABLE_TDATA_HANDLER_H_ */