/src/net-snmp/snmplib/container_null.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * container_null.c |
3 | | * $Id$ |
4 | | * |
5 | | * see comments in header file. |
6 | | * |
7 | | */ |
8 | | |
9 | | #include <net-snmp/net-snmp-config.h> |
10 | | #include <net-snmp/net-snmp-features.h> |
11 | | |
12 | | #ifdef HAVE_IO_H |
13 | | #include <io.h> |
14 | | #endif |
15 | | #include <stdio.h> |
16 | | #ifdef HAVE_STDLIB_H |
17 | | #include <stdlib.h> |
18 | | #endif |
19 | | #ifdef HAVE_MALLOC_H |
20 | | #include <malloc.h> |
21 | | #endif |
22 | | #include <sys/types.h> |
23 | | #ifdef HAVE_STRING_H |
24 | | #include <string.h> |
25 | | #else |
26 | | #include <strings.h> |
27 | | #endif |
28 | | |
29 | | #include <net-snmp/net-snmp-includes.h> |
30 | | #include <net-snmp/types.h> |
31 | | #include <net-snmp/library/snmp_api.h> |
32 | | #include <net-snmp/library/container.h> |
33 | | #include <net-snmp/library/container_null.h> |
34 | | #include <net-snmp/library/tools.h> |
35 | | #include <net-snmp/library/snmp_assert.h> |
36 | | #include "factory.h" |
37 | | |
38 | | netsnmp_feature_child_of(container_null, container_types); |
39 | | |
40 | | /** @defgroup null_container null_container |
41 | | * Helps you implement specialized containers. |
42 | | * @ingroup container |
43 | | * |
44 | | * This is a simple container that doesn't actually contain anything. |
45 | | * All the methods simply log a debug message and return. |
46 | | * |
47 | | * The original intent for this container is as a wrapper for a specialized |
48 | | * container. Implement the functions you need, create a null_container, |
49 | | * and override the default functions with your specialized versions. |
50 | | * |
51 | | * You can use the 'container:null' debug token to see what functions are |
52 | | * being called, to help determine if you need to implement them. |
53 | | * |
54 | | * @{ |
55 | | */ |
56 | | |
57 | | #ifndef NETSNMP_FEATURE_REMOVE_CONTAINER_NULL |
58 | | /********************************************************************** |
59 | | * |
60 | | * container |
61 | | * |
62 | | */ |
63 | | static void * |
64 | | _null_find(netsnmp_container *container, const void *data) |
65 | 0 | { |
66 | 0 | DEBUGMSGTL(("container:null:find","in\n")); |
67 | 0 | return NULL; |
68 | 0 | } |
69 | | |
70 | | static void * |
71 | | _null_find_next(netsnmp_container *container, const void *data) |
72 | 0 | { |
73 | 0 | DEBUGMSGTL(("container:null:find_next","in\n")); |
74 | 0 | return NULL; |
75 | 0 | } |
76 | | |
77 | | static int |
78 | | _null_insert(netsnmp_container *container, const void *data) |
79 | 0 | { |
80 | 0 | DEBUGMSGTL(("container:null:insert","in\n")); |
81 | 0 | return 0; |
82 | 0 | } |
83 | | |
84 | | static int |
85 | | _null_remove(netsnmp_container *container, const void *data) |
86 | 0 | { |
87 | 0 | DEBUGMSGTL(("container:null:remove","in\n")); |
88 | 0 | return 0; |
89 | 0 | } |
90 | | |
91 | | static int |
92 | | _null_free(netsnmp_container *container) |
93 | 0 | { |
94 | 0 | DEBUGMSGTL(("container:null:free","in\n")); |
95 | 0 | free(container); |
96 | 0 | return 0; |
97 | 0 | } |
98 | | |
99 | | static int |
100 | | _null_init(netsnmp_container *container) |
101 | 0 | { |
102 | 0 | DEBUGMSGTL(("container:null:","in\n")); |
103 | 0 | return 0; |
104 | 0 | } |
105 | | |
106 | | static size_t |
107 | | _null_size(netsnmp_container *container) |
108 | 0 | { |
109 | 0 | DEBUGMSGTL(("container:null:size","in\n")); |
110 | 0 | return 0; |
111 | 0 | } |
112 | | |
113 | | static void |
114 | | _null_for_each(netsnmp_container *container, netsnmp_container_obj_func *f, |
115 | | void *context) |
116 | 0 | { |
117 | 0 | DEBUGMSGTL(("container:null:for_each","in\n")); |
118 | 0 | } |
119 | | |
120 | | static netsnmp_void_array * |
121 | | _null_get_subset(netsnmp_container *container, void *data) |
122 | 0 | { |
123 | 0 | DEBUGMSGTL(("container:null:get_subset","in\n")); |
124 | 0 | return NULL; |
125 | 0 | } |
126 | | |
127 | | static void |
128 | | _null_clear(netsnmp_container *container, netsnmp_container_obj_func *f, |
129 | | void *context) |
130 | 0 | { |
131 | 0 | DEBUGMSGTL(("container:null:clear","in\n")); |
132 | 0 | } |
133 | | |
134 | | /********************************************************************** |
135 | | * |
136 | | * factory |
137 | | * |
138 | | */ |
139 | | |
140 | | netsnmp_container * |
141 | | netsnmp_container_get_null(void) |
142 | 0 | { |
143 | | /* |
144 | | * allocate memory |
145 | | */ |
146 | 0 | netsnmp_container *c; |
147 | 0 | DEBUGMSGTL(("container:null:get_null","in\n")); |
148 | 0 | c = SNMP_MALLOC_TYPEDEF(netsnmp_container); |
149 | 0 | if (NULL==c) { |
150 | 0 | snmp_log(LOG_ERR, "couldn't allocate memory\n"); |
151 | 0 | return NULL; |
152 | 0 | } |
153 | | |
154 | 0 | c->container_data = NULL; |
155 | | |
156 | 0 | c->get_size = _null_size; |
157 | 0 | c->init = _null_init; |
158 | 0 | c->cfree = _null_free; |
159 | 0 | c->insert = _null_insert; |
160 | 0 | c->remove = _null_remove; |
161 | 0 | c->find = _null_find; |
162 | 0 | c->find_next = _null_find_next; |
163 | 0 | c->get_subset = _null_get_subset; |
164 | 0 | c->get_iterator = NULL; /* _null_iterator; */ |
165 | 0 | c->for_each = _null_for_each; |
166 | 0 | c->clear = _null_clear; |
167 | | |
168 | 0 | return c; |
169 | 0 | } |
170 | | |
171 | | netsnmp_factory * |
172 | | netsnmp_container_get_null_factory(void) |
173 | 0 | { |
174 | 0 | static netsnmp_factory f = { "null", |
175 | 0 | netsnmp_container_get_null}; |
176 | | |
177 | 0 | DEBUGMSGTL(("container:null:get_null_factory","in\n")); |
178 | 0 | return &f; |
179 | 0 | } |
180 | | |
181 | | void |
182 | | netsnmp_container_null_init(void) |
183 | 0 | { |
184 | 0 | netsnmp_container_register("null", |
185 | 0 | netsnmp_container_get_null_factory()); |
186 | 0 | } |
187 | | #else /* NETSNMP_FEATURE_REMOVE_CONTAINER_NULL */ |
188 | | netsnmp_feature_unused(container_null); |
189 | | #endif /* NETSNMP_FEATURE_REMOVE_CONTAINER_NULL */ |
190 | | /** @} */ |
191 | | |