Code Search for Developers
 
 
  

container_8c-source.html from net-snmp at Krugle


Show container_8c-source.html syntax highlighted

<!--#set var="section" value="development" -->
<!--#include virtual="/page-top.html" -->
<!-- CONTENT START -->
  <!-- Generated by Doxygen 1.3.9.1 -->

  <div class="qindex">
    <a class="qindex" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class=
    "qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class=
    "qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a> | <a class=
    "qindex" href="examples.html">Examples</a>
  </div>

  <div class="nav">
    <a class="el" href="dir_000005.html">snmplib</a>
  </div>

  <h1>container.c</h1>

  <div class="fragment">
    <pre class="fragment">
00001 <span class="preprocessor">#include &lt;net-snmp/net-snmp-config.h&gt;</span>
00002 <span class="preprocessor">#include &lt;net-snmp/net-snmp-includes.h&gt;</span>
00003 <span class="preprocessor">#include &lt;net-snmp/library/container.h&gt;</span>
00004 <span class="preprocessor">#include &lt;net-snmp/library/container_binary_array.h&gt;</span>
00005 <span class="preprocessor">#include &lt;net-snmp/library/container_list_ssll.h&gt;</span>
00006 <span class="preprocessor">#include &lt;net-snmp/library/container_null.h&gt;</span>
00007 
00008 <span class="comment">/*------------------------------------------------------------------</span>
00009 <span class="comment"> */</span>
00010 <span class="keyword">static</span> netsnmp_container *containers = NULL;
00011 
00012 <span class="keyword">typedef</span> <span class="keyword">struct </span>container_type_s {
00013    <span class="keyword">const</span> <span class="keywordtype">char</span>                 *name;
00014    netsnmp_factory            *factory;
00015    netsnmp_container_compare  *compare;
00016 } container_type;
00017 
00018 netsnmp_factory *
00019 netsnmp_container_get_factory(<span class="keyword">const</span> <span class="keywordtype">char</span> *type);
00020 
00021 <span class="comment">/*------------------------------------------------------------------</span>
00022 <span class="comment"> */</span>
00023 <span class="keyword">static</span> <span class="keywordtype">void</span> 
00024 _factory_free(<span class="keywordtype">void</span> *dat, <span class="keywordtype">void</span> *context)
00025 {
00026     container_type *data = (container_type *)dat;
00027     <span class="keywordflow">if</span> (data == NULL)
00028         <span class="keywordflow">return</span>;
00029     
00030     <span class="keywordflow">if</span> (data-&gt;name != NULL) {
00031         DEBUGMSGTL((<span class="stringliteral">"container"</span>, <span class=
"stringliteral">"  _factory_free_list() called for %s\n"</span>,
00032                     data-&gt;name));
00033         free((<span class="keywordtype">void</span> *)data-&gt;name); <span class=
"comment">/* SNMP_FREE wasted on object about to be freed */</span>
00034     }
00035     free(data); <span class="comment">/* SNMP_FREE wasted on param */</span>
00036 }
00037 
00038 <span class="comment">/*------------------------------------------------------------------</span>
00039 <span class="comment"> */</span>
00040 <span class="keywordtype">void</span>
00041 netsnmp_container_init_list(<span class="keywordtype">void</span>)
00042 {
00043     <span class="keywordflow">if</span> (NULL != containers)
00044         <span class="keywordflow">return</span>;
00045 
00046     <span class="comment">/*</span>
00047 <span class="comment">     * create a binary arry container to hold container</span>
00048 <span class="comment">     * factories</span>
00049 <span class="comment">     */</span>
00050     containers = netsnmp_container_get_binary_array();
00051     containers-&gt;compare = netsnmp_compare_cstring;
00052 
00053     <span class="comment">/*</span>
00054 <span class="comment">     * register containers</span>
00055 <span class="comment">     */</span>
00056     netsnmp_container_binary_array_init();
00057     netsnmp_container_ssll_init();
00058     netsnmp_container_null_init();
00059 
00060     <span class="comment">/*</span>
00061 <span class="comment">     * default aliases for some containers</span>
00062 <span class="comment">     */</span>
00063     netsnmp_container_register(<span class="stringliteral">"table_container"</span>,
00064                                netsnmp_container_get_factory(<span class="stringliteral">"binary_array"</span>));
00065     netsnmp_container_register(<span class="stringliteral">"linked_list"</span>,
00066                                netsnmp_container_get_factory(<span class=
"stringliteral">"sorted_singly_linked_list"</span>));
00067     netsnmp_container_register(<span class="stringliteral">"ssll_container"</span>,
00068                                netsnmp_container_get_factory(<span class=
"stringliteral">"sorted_singly_linked_list"</span>));
00069 
00070     netsnmp_container_register_with_compare
00071         (<span class="stringliteral">"string"</span>, netsnmp_container_get_factory(<span class=
"stringliteral">"binary_array"</span>),
00072          netsnmp_compare_cstring);
00073     netsnmp_container_register_with_compare
00074         (<span class="stringliteral">"string:binary_array"</span>, netsnmp_container_get_factory(<span class=
"stringliteral">"binary_array"</span>),
00075          netsnmp_compare_cstring);
00076 
00077 }
00078 
00079 <span class="keywordtype">void</span>
00080 netsnmp_container_free_list(<span class="keywordtype">void</span>)
00081 {
00082     DEBUGMSGTL((<span class="stringliteral">"container"</span>, <span class=
"stringliteral">"netsnmp_container_free_list() called\n"</span>));
00083     <span class="keywordflow">if</span> (containers == NULL)
00084         <span class="keywordflow">return</span>;
00085 
00086     <span class="comment">/*</span>
00087 <span class="comment">     * free memory used by each factory entry</span>
00088 <span class="comment">     */</span>
00089     CONTAINER_FOR_EACH(containers, ((netsnmp_container_obj_func *)_factory_free), NULL);
00090 
00091     <span class="comment">/*</span>
00092 <span class="comment">     * free factory container</span>
00093 <span class="comment">     */</span>
00094     CONTAINER_FREE(containers);
00095     containers = NULL;
00096 }
00097 
00098 <span class="keywordtype">int</span>
00099 netsnmp_container_register_with_compare(<span class="keyword">const</span> <span class=
"keywordtype">char</span>* name, netsnmp_factory *f,
00100                                         netsnmp_container_compare  *c)
00101 {
00102     container_type *ct, tmp;
00103 
00104     tmp.name = (<span class="keywordtype">char</span> *)name;
00105     ct = CONTAINER_FIND(containers, &amp;tmp);
00106     <span class="keywordflow">if</span> (NULL!=ct) {
00107         DEBUGMSGT((<span class="stringliteral">"container_registry"</span>,
00108                    <span class="stringliteral">"replacing previous container factory\n"</span>));
00109         ct-&gt;factory = f;
00110     }
00111     <span class="keywordflow">else</span> {
00112         ct = <a class="code" href="group__util.html#ga39">SNMP_MALLOC_TYPEDEF</a>(container_type);
00113         <span class="keywordflow">if</span> (NULL == ct)
00114             <span class="keywordflow">return</span> -1;
00115         ct-&gt;name = strdup(name);
00116         ct-&gt;factory = f;
00117         ct-&gt;compare = c;
00118         CONTAINER_INSERT(containers, ct);
00119     }
00120     DEBUGMSGT((<span class="stringliteral">"container_registry"</span>, <span class=
"stringliteral">"registered container factory %s (%s)\n"</span>,
00121                ct-&gt;name, f-&gt;product));
00122 
00123     <span class="keywordflow">return</span> 0;
00124 }
00125 
00126 <span class="keywordtype">int</span>
00127 netsnmp_container_register(<span class="keyword">const</span> <span class=
"keywordtype">char</span>* name, netsnmp_factory *f)
00128 {
00129     <span class="keywordflow">return</span> netsnmp_container_register_with_compare(name, f, NULL);
00130 }
00131 
00132 <span class="comment">/*------------------------------------------------------------------</span>
00133 <span class="comment"> */</span>
00134 netsnmp_factory *
00135 netsnmp_container_get_factory(<span class="keyword">const</span> <span class="keywordtype">char</span> *type)
00136 {
00137     container_type ct, *found;
00138     
00139     ct.name = type;
00140     found = CONTAINER_FIND(containers, &amp;ct);
00141 
00142     <span class="keywordflow">return</span> found ? found-&gt;factory : NULL;
00143 }
00144 
00145 netsnmp_factory *
00146 netsnmp_container_find_factory(<span class="keyword">const</span> <span class="keywordtype">char</span> *type_list)
00147 {
00148     netsnmp_factory   *f = NULL;
00149     <span class="keywordtype">char</span>              *list, *entry;
00150     <span class="keywordtype">char</span>              *st;
00151 
00152     <span class="keywordflow">if</span> (NULL==type_list)
00153         <span class="keywordflow">return</span> NULL;
00154 
00155     list = strdup(type_list);
00156     entry = strtok_r(list, <span class="stringliteral">":"</span>, &amp;st);
00157     <span class="keywordflow">while</span>(entry) {
00158         f = netsnmp_container_get_factory(entry);
00159         <span class="keywordflow">if</span> (NULL != f)
00160             <span class="keywordflow">break</span>;
00161         entry = strtok_r(NULL, <span class="stringliteral">":"</span>, &amp;st);
00162     }
00163 
00164     free(list);
00165     <span class="keywordflow">return</span> f;
00166 }
00167 
00168 <span class="comment">/*------------------------------------------------------------------</span>
00169 <span class="comment"> */</span>
00170 <span class="keyword">static</span> container_type *
00171 netsnmp_container_get_ct(<span class="keyword">const</span> <span class="keywordtype">char</span> *type)
00172 {
00173     container_type ct;
00174     
00175     ct.name = type;
00176     <span class="keywordflow">return</span> CONTAINER_FIND(containers, &amp;ct);
00177 }
00178 
00179 <span class="keyword">static</span> container_type *
00180 netsnmp_container_find_ct(<span class="keyword">const</span> <span class="keywordtype">char</span> *type_list)
00181 {
00182     container_type    *ct = NULL;
00183     <span class="keywordtype">char</span>              *list, *entry;
00184     <span class="keywordtype">char</span>              *st;
00185 
00186     <span class="keywordflow">if</span> (NULL==type_list)
00187         <span class="keywordflow">return</span> NULL;
00188 
00189     list = strdup(type_list);
00190     entry = strtok_r(list, <span class="stringliteral">":"</span>, &amp;st);
00191     <span class="keywordflow">while</span>(entry) {
00192         ct = netsnmp_container_get_ct(entry);
00193         <span class="keywordflow">if</span> (NULL != ct)
00194             <span class="keywordflow">break</span>;
00195         entry = strtok_r(NULL, <span class="stringliteral">":"</span>, &amp;st);
00196     }
00197 
00198     free(list);
00199     <span class="keywordflow">return</span> ct;
00200 }
00201 
00202 
00203 
00204 <span class="comment">/*------------------------------------------------------------------</span>
00205 <span class="comment"> */</span>
00206 netsnmp_container *
00207 netsnmp_container_get(<span class="keyword">const</span> <span class="keywordtype">char</span> *type)
00208 {
00209     netsnmp_container *c;
00210     container_type *ct = netsnmp_container_get_ct(type);
00211     <span class="keywordflow">if</span> (ct) {
00212         c = ct-&gt;factory-&gt;produce();
00213         <span class="keywordflow">if</span> (c &amp;&amp; ct-&gt;compare)
00214             c-&gt;compare = ct-&gt;compare;
00215         <span class="keywordflow">return</span> c;
00216     }
00217 
00218     <span class="keywordflow">return</span> NULL;
00219 }
00220 
00221 <span class="comment">/*------------------------------------------------------------------</span>
00222 <span class="comment"> */</span>
00223 netsnmp_container *
00224 netsnmp_container_find(<span class="keyword">const</span> <span class="keywordtype">char</span> *type)
00225 {
00226     container_type *ct = netsnmp_container_find_ct(type);
00227     netsnmp_container *c = ct ? ct-&gt;factory-&gt;produce() : NULL;
00228 
00229     <span class="comment">/*</span>
00230 <span class="comment">     * provide default compare</span>
00231 <span class="comment">     */</span>
00232     <span class="keywordflow">if</span> (c) {
00233         <span class="keywordflow">if</span> (ct-&gt;compare)
00234             c-&gt;compare = ct-&gt;compare;
00235         <span class="keywordflow">else</span> <span class="keywordflow">if</span> (NULL == c-&gt;compare)
00236             c-&gt;compare = netsnmp_compare_netsnmp_index;
00237     }
00238 
00239     <span class="keywordflow">return</span> c;
00240 }
00241 
00242 <span class="comment">/*------------------------------------------------------------------</span>
00243 <span class="comment"> */</span>
00244 <span class="keywordtype">void</span>
00245 netsnmp_container_add_index(netsnmp_container *primary,
00246                             netsnmp_container *new_index)
00247 {
00248     netsnmp_container *curr = primary;
00249 
00250     <span class="keywordflow">if</span>((NULL == new_index) || (NULL == primary)) {
00251         <a class="code" href="group__snmp__logging.html#ga41">snmp_log</a>(LOG_ERR, <span class=
"stringliteral">"add index called with null pointer\n"</span>);
00252         <span class="keywordflow">return</span>;
00253     }
00254 
00255     <span class="keywordflow">while</span>(curr-&gt;next)
00256         curr = curr-&gt;next;
00257 
00258     curr-&gt;next = new_index;
00259     new_index-&gt;prev = curr;
00260 }
00261 
00262 <span class="preprocessor">#ifndef NETSNMP_USE_INLINE </span><span class="comment">/* default is to inline */</span>
00263 
00264 <span class="comment">/*------------------------------------------------------------------</span>
00265 <span class="comment"> * These functions should EXACTLY match the inline version in</span>
00266 <span class="comment"> * container.h. If you chance one, change them both.</span>
00267 <span class="comment"> */</span>
00268 <span class="keywordtype">int</span> CONTAINER_INSERT(netsnmp_container *x, <span class="keyword">const</span> <span class=
"keywordtype">void</span> *k)
00269 { 
00270     <span class="keywordtype">int</span> rc2, rc = 0;
00271     
00273     <span class="keywordflow">while</span>(x-&gt;prev)
00274         x = x-&gt;prev;
00275     <span class="keywordflow">for</span>(; x; x = x-&gt;next) {
00276         <span class="keywordflow">if</span> ((NULL != x-&gt;insert_filter) &amp;&amp;
00277             (x-&gt;insert_filter(x,k) == 1))
00278             <span class="keywordflow">continue</span>;
00279         rc2 = x-&gt;insert(x,k);
00280         <span class="keywordflow">if</span> (rc2) {
00281             <a class="code" href="group__snmp__logging.html#ga41">snmp_log</a>(LOG_ERR,<span class=
"stringliteral">"error on subcontainer '%s' insert (%d)\n"</span>,
00282                      x-&gt;container_name ? x-&gt;container_name : <span class="stringliteral">""</span>, rc2);
00283             rc = rc2;
00284         }
00285     }
00286     <span class="keywordflow">return</span> rc;
00287 }
00288 
00289 <span class="comment">/*------------------------------------------------------------------</span>
00290 <span class="comment"> * These functions should EXACTLY match the inline version in</span>
00291 <span class="comment"> * container.h. If you chance one, change them both.</span>
00292 <span class="comment"> */</span>
00293 <span class="keywordtype">int</span> CONTAINER_REMOVE(netsnmp_container *x, <span class="keyword">const</span> <span class=
"keywordtype">void</span> *k)
00294 {
00295     <span class="keywordtype">int</span> rc2, rc = 0;
00296     
00298     <span class="keywordflow">while</span>(x-&gt;next)
00299         x = x-&gt;next;
00300     <span class="keywordflow">while</span>(x) {
00301         rc2 = x-&gt;remove(x,k);
00303         <span class="keywordflow">if</span> ((rc2) &amp;&amp; (NULL == x-&gt;insert_filter)) {
00304             <a class="code" href="group__snmp__logging.html#ga41">snmp_log</a>(LOG_ERR,<span class=
"stringliteral">"error on subcontainer remove (%d)\n"</span>, rc2);
00305             rc = rc2;
00306         }
00307         x = x-&gt;prev;
00308         
00309     }
00310     <span class="keywordflow">return</span> rc;
00311 }
00312 
00313 <span class="comment">/*------------------------------------------------------------------</span>
00314 <span class="comment"> * These functions should EXACTLY match the inline version in</span>
00315 <span class="comment"> * container.h. If you chance one, change them both.</span>
00316 <span class="comment"> */</span>
00317 <span class="keywordtype">int</span> CONTAINER_FREE(netsnmp_container *x)
00318 {
00319     <span class="keywordtype">int</span>  rc2, rc = 0;
00320         
00322     <span class="keywordflow">while</span>(x-&gt;next)
00323         x = x-&gt;next;
00324     <span class="keywordflow">while</span>(x) {
00325         netsnmp_container *tmp;
00326         tmp = x-&gt;prev;
00327         <span class="keywordflow">if</span> (NULL != x-&gt;container_name)
00328             <a class="code" href="group__util.html#ga36">SNMP_FREE</a>(x-&gt;container_name);
00329         rc2 = x-&gt;cfree(x);
00330         <span class="keywordflow">if</span> (rc2) {
00331             <a class="code" href="group__snmp__logging.html#ga41">snmp_log</a>(LOG_ERR,<span class=
"stringliteral">"error on subcontainer cfree (%d)\n"</span>, rc2);
00332             rc = rc2;
00333         }
00334         x = tmp;
00335     }
00336     <span class="keywordflow">return</span> rc;
00337 }
00338 
00339 <span class="comment">/*------------------------------------------------------------------</span>
00340 <span class="comment"> * These functions should EXACTLY match the function version in</span>
00341 <span class="comment"> * container.c. If you change one, change them both.</span>
00342 <span class="comment"> */</span>
00343 <span class="comment">/*</span>
00344 <span class="comment"> * clear all containers. When clearing the *first* container, and</span>
00345 <span class="comment"> * *only* the first container, call the function f for each item.</span>
00346 <span class="comment"> * After calling this function, all containers should be empty.</span>
00347 <span class="comment"> */</span>
00348 <span class="keywordtype">void</span> CONTAINER_CLEAR(netsnmp_container *x, netsnmp_container_obj_func *f,
00349                     <span class="keywordtype">void</span> *c)
00350 {
00352     <span class="keywordflow">while</span>(x-&gt;next)
00353         x = x-&gt;next;
00354     <span class="keywordflow">while</span>(x-&gt;prev) {
00355         x-&gt;clear(x, NULL, c);
00356         x = x-&gt;prev;
00357     }
00358     x-&gt;clear(x, f, c);
00359 }
00360 
00361 <span class="comment">/*------------------------------------------------------------------</span>
00362 <span class="comment"> * These functions should EXACTLY match the function version in</span>
00363 <span class="comment"> * container.c. If you change one, change them both.</span>
00364 <span class="comment"> */</span>
00365 <span class="comment">/*</span>
00366 <span class="comment"> * Find a sub-container with the given name</span>
00367 <span class="comment"> */</span>
00368 netsnmp_container *SUBCONTAINER_FIND(netsnmp_container *x,
00369                                      <span class="keyword">const</span> <span class="keywordtype">char</span>* name)
00370 {
00371     <span class="keywordflow">if</span> ((NULL == x) || (NULL == name))
00372         <span class="keywordflow">return</span> NULL;
00373     
00375     <span class="keywordflow">while</span>(x-&gt;prev)
00376         x = x-&gt;prev;
00377     <span class="keywordflow">while</span>(x) {
00378         <span class=
"keywordflow">if</span> ((NULL != x-&gt;container_name) &amp;&amp; (0 == strcmp(name,x-&gt;container_name)))
00379             <span class="keywordflow">break</span>;
00380         x = x-&gt;next;
00381     }
00382     <span class="keywordflow">return</span> x;
00383 }
00384 <span class="preprocessor">#endif</span>
00385 
00386 
00387 <span class="comment">/*------------------------------------------------------------------</span>
00388 <span class="comment"> */</span>
00389 <span class="keywordtype">void</span>
00390 netsnmp_init_container(netsnmp_container         *c,
00391                        netsnmp_container_rc      *init,
00392                        netsnmp_container_rc      *cfree,
00393                        netsnmp_container_size    *size,
00394                        netsnmp_container_compare *cmp,
00395                        netsnmp_container_op      *ins,
00396                        netsnmp_container_op      *rem,
00397                        netsnmp_container_rtn     *fnd)
00398 {
00399     <span class="keywordflow">if</span> (c == NULL)
00400         <span class="keywordflow">return</span>;
00401 
00402     c-&gt;init = init;
00403     c-&gt;cfree = cfree;
00404     c-&gt;get_size = size;
00405     c-&gt;compare = cmp;
00406     c-&gt;insert = ins;
00407     c-&gt;remove = rem;
00408     c-&gt;find = fnd;
00409 }
00410 
00411 <span class="comment">/*------------------------------------------------------------------</span>
00412 <span class="comment"> *</span>
00413 <span class="comment"> * simple comparison routines</span>
00414 <span class="comment"> *</span>
00415 <span class="comment"> */</span>
00416 <span class="keywordtype">int</span>
00417 netsnmp_compare_netsnmp_index(<span class="keyword">const</span> <span class="keywordtype">void</span> *lhs, <span class=
"keyword">const</span> <span class="keywordtype">void</span> *rhs)
00418 {
00419     <span class="keywordtype">int</span> rc;
00420     netsnmp_assert((NULL != lhs) &amp;&amp; (NULL != rhs));
00421     DEBUGIF(<span class="stringliteral">"compare:index"</span>) {
00422         DEBUGMSGT((<span class="stringliteral">"compare:index"</span>, <span class="stringliteral">"compare "</span>));
00423         DEBUGMSGSUBOID((<span class="stringliteral">"compare:index"</span>, ((<span class=
"keyword">const</span> netsnmp_index *) lhs)-&gt;oids,
00424                      ((<span class="keyword">const</span> netsnmp_index *) lhs)-&gt;len));
00425         DEBUGMSG((<span class="stringliteral">"compare:index"</span>, <span class="stringliteral">" to "</span>));
00426         DEBUGMSGSUBOID((<span class="stringliteral">"compare:index"</span>, ((<span class=
"keyword">const</span> netsnmp_index *) rhs)-&gt;oids,
00427                      ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;len));
00428         DEBUGMSG((<span class="stringliteral">"compare:index"</span>, <span class="stringliteral">"\n"</span>));
00429     }
00430     rc = <a class="code" href="group__library.html#ga103">snmp_oid_compare</a>(((<span class=
"keyword">const</span> netsnmp_index *) lhs)-&gt;oids,
00431                           ((<span class="keyword">const</span> netsnmp_index *) lhs)-&gt;len,
00432                           ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;oids,
00433                           ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;len);
00434     DEBUGMSGT((<span class="stringliteral">"compare:index"</span>, <span class=
"stringliteral">"result was %d\n"</span>, rc));
00435     <span class="keywordflow">return</span> rc;
00436 }
00437 
00438 <span class="keywordtype">int</span>
00439 netsnmp_ncompare_netsnmp_index(<span class="keyword">const</span> <span class="keywordtype">void</span> *lhs, <span class=
"keyword">const</span> <span class="keywordtype">void</span> *rhs)
00440 {
00441     <span class="keywordtype">int</span> rc;
00442     netsnmp_assert((NULL != lhs) &amp;&amp; (NULL != rhs));
00443     DEBUGIF(<span class="stringliteral">"compare:index"</span>) {
00444         DEBUGMSGT((<span class="stringliteral">"compare:index"</span>, <span class="stringliteral">"compare "</span>));
00445         DEBUGMSGSUBOID((<span class="stringliteral">"compare:index"</span>, ((<span class=
"keyword">const</span> netsnmp_index *) lhs)-&gt;oids,
00446                      ((<span class="keyword">const</span> netsnmp_index *) lhs)-&gt;len));
00447         DEBUGMSG((<span class="stringliteral">"compare:index"</span>, <span class="stringliteral">" to "</span>));
00448         DEBUGMSGSUBOID((<span class="stringliteral">"compare:index"</span>, ((<span class=
"keyword">const</span> netsnmp_index *) rhs)-&gt;oids,
00449                      ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;len));
00450         DEBUGMSG((<span class="stringliteral">"compare:index"</span>, <span class="stringliteral">"\n"</span>));
00451     }
00452     rc = snmp_oid_ncompare(((<span class="keyword">const</span> netsnmp_index *) lhs)-&gt;oids,
00453                            ((<span class="keyword">const</span> netsnmp_index *) lhs)-&gt;len,
00454                            ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;oids,
00455                            ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;len,
00456                            ((<span class="keyword">const</span> netsnmp_index *) rhs)-&gt;len);
00457     DEBUGMSGT((<span class="stringliteral">"compare:index"</span>, <span class=
"stringliteral">"result was %d\n"</span>, rc));
00458     <span class="keywordflow">return</span> rc;
00459 }
00460 
00461 <span class="keywordtype">int</span>
00462 netsnmp_compare_cstring(<span class="keyword">const</span> <span class="keywordtype">void</span> * lhs, <span class=
"keyword">const</span> <span class="keywordtype">void</span> * rhs)
00463 {
00464     <span class="keywordflow">return</span> strcmp(((<span class="keyword">const</span> container_type*)lhs)-&gt;name,
00465                   ((<span class="keyword">const</span> container_type*)rhs)-&gt;name);
00466 }
00467 
00468 <span class="keywordtype">int</span>
00469 netsnmp_ncompare_cstring(<span class="keyword">const</span> <span class="keywordtype">void</span> * lhs, <span class=
"keyword">const</span> <span class="keywordtype">void</span> * rhs)
00470 {
00471     <span class="keywordflow">return</span> strncmp(((<span class="keyword">const</span> container_type*)lhs)-&gt;name,
00472                    ((<span class="keyword">const</span> container_type*)rhs)-&gt;name,
00473                    strlen(((<span class="keyword">const</span> container_type*)rhs)-&gt;name));
00474 }
00475 
00476 <span class="comment">/*</span>
00477 <span class="comment"> * compare two memory buffers</span>
00478 <span class="comment"> *</span>
00479 <span class="comment"> * since snmp strings aren't NULL terminated, we can't use strcmp. So</span>
00480 <span class="comment"> * compare up to the length of the smaller, and then use length to</span>
00481 <span class="comment"> * break any ties.</span>
00482 <span class="comment"> */</span>
00483 <span class="keywordtype">int</span>
00484 netsnmp_compare_mem(<span class="keyword">const</span> <span class="keywordtype">char</span> * lhs, size_t lhs_len,
00485                     <span class="keyword">const</span> <span class="keywordtype">char</span> * rhs, size_t rhs_len)
00486 {
00487     <span class="keywordtype">int</span> rc, min = <a class="code" href=
"group__util.html#ga46">SNMP_MIN</a>(lhs_len, rhs_len);
00488 
00489     rc = memcmp(lhs, rhs, min);
00490     <span class="keywordflow">if</span>((rc==0) &amp;&amp; (lhs_len != rhs_len)) {
00491         <span class="keywordflow">if</span>(lhs_len &lt; rhs_len)
00492             rc = -1;
00493         <span class="keywordflow">else</span>
00494             rc = 1;
00495     }
00496 
00497     <span class="keywordflow">return</span> rc;
00498 }
00499 
00500 <span class="comment">/*------------------------------------------------------------------</span>
00501 <span class="comment"> * netsnmp_container_simple_free</span>
00502 <span class="comment"> *</span>
00503 <span class="comment"> * useful function to pass to CONTAINER_FOR_EACH, when a simple</span>
00504 <span class="comment"> * free is needed for every item.</span>
00505 <span class="comment"> */</span>
00506 <span class="keywordtype">void</span> 
00507 netsnmp_container_simple_free(<span class="keywordtype">void</span> *data, <span class="keywordtype">void</span> *context)
00508 {
00509     <span class="keywordflow">if</span> (data == NULL)
00510         <span class="keywordflow">return</span>;
00511     
00512     DEBUGMSGTL((<span class="stringliteral">"verbose:container"</span>,
00513                 <span class="stringliteral">"netsnmp_container_simple_free) called for %p/%p\n"</span>,
00514                 data, context));
00515     free((<span class="keywordtype">void</span>*)data); <span class="comment">/* SNMP_FREE wasted on param */</span>
00516 }
</pre>
  </div>
  <hr size="1" />

  <address style="align: right;">
    <small>Generated on Fri Dec 30 13:47:44 2005 for net-snmp by&nbsp; <a href="http://www.doxygen.org/index.html"><img src=
    "doxygen.png" alt="doxygen" align="middle" border="0" /></a> 1.3.9.1</small>
  </address>
<!-- CONTENT END -->
<!--#include virtual="/page-bottom.html" -->





See more files for this project here

net-snmp

net-snmp provides tools and libraries relating to the Simple Network\r\nManagement Protocol including: An extensible agent, An SNMP library,\r\ntools to request or set information from SNMP agents, tools to\r\ngenerate and handle SNMP traps, etc.\r\n

Project homepage: http://sourceforge.net/projects/net-snmp
Programming language(s): C,Perl,Shell Script
License: other

  mfd/
  acconfig_8h-source.html
  acconfig_8h.html
  agent_2snmp__perl_8c-source.html
  agent__callbacks_8h-source.html
  agent__callbacks_8h.html
  agent__handler_8c-source.html
  agent__handler_8c.html
  agent__handler_8h-source.html
  agent__handler_8h.html
  agent__index_8c-source.html
  agent__index_8c.html
  agent__index_8h-source.html
  agent__index_8h.html
  agent__module__config_8h-source.html
  agent__read__config_8c-source.html
  agent__read__config_8c.html
  agent__read__config_8h-source.html
  agent__read__config_8h.html
  agent__registry_8c-source.html
  agent__registry_8c.html
  agent__registry_8h-source.html
  agent__registry_8h.html
  agent__trap_8c-source.html
  agent__trap_8c.html
  agent__trap_8h-source.html
  agent__trap_8h.html
  all__helpers_8c-source.html
  all__helpers_8h-source.html
  annotated.html
  asn1_8c-source.html
  asn1_8h-source.html
  auto__nlist_8c-source.html
  auto__nlist_8c.html
  auto__nlist_8h-source.html
  auto__nlist_8h.html
  autonlist_8h-source.html
  autonlist_8h.html
  baby__steps_8c-source.html
  baby__steps_8h-source.html
  blah.html
  bulk__to__next_8c-source.html
  bulk__to__next_8h-source.html
  cache__handler_8c-source.html
  cache__handler_8h-source.html
  callback_8c-source.html
  callback_8h-source.html
  check__varbind_8c-source.html
  check__varbind_8h-source.html
  cmu__compat_8c-source.html
  cmu__compat_8h-source.html
  config_8h-source.html
  config_8h.html
  config__api_8h-source.html
  container_8c-source.html
  container_8h-source.html
  container__binary__array_8c-source.html
  container__binary__array_8h-source.html
  container__iterator_8c-source.html
  container__iterator_8h-source.html
  container__list__ssll_8c-source.html
  container__list__ssll_8h-source.html
  container__null_8c-source.html
  container__null_8h-source.html
  data__list_8c-source.html
  data__list_8h-source.html
  data__set_8c-example.html
  data__set_8c-source.html
  data__set_8h-source.html
  debug__handler_8c-source.html
  debug__handler_8h-source.html
  default__store_8c-source.html
  default__store_8h-source.html
  default_store.html
  definitions_8h-source.html
  delayed__instance_8c-example.html
  delayed__instance_8c-source.html
  delayed__instance_8h-source.html
  deprecated.html
  dir_000000.html
  dir_000001.html
  dir_000002.html
  dir_000003.html
  dir_000004.html
  dir_000005.html
  dir_000006.html
  dir_000007.html
  dir_000008.html
  doxygen.css
  doxygen.gif
  doxygen.png
  ds__agent_8h-source.html
  ds__agent_8h.html
  example_8c-source.html
  example_8h-source.html
  examples.html
  factory_8h-source.html
  fd__event__manager_8c-source.html
  fd__event__manager_8h-source.html
  file__utils_8c-source.html
  file__utils_8h-source.html
  files.html