agent__index_8c.html from net-snmp at Krugle
Show agent__index_8c.html syntax highlighted
<!--#set var="section" value="development" -->
<!--#include virtual="/page-top.html" -->
<!-- CONTENT START -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>agent_index.c File Reference</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body bgcolor="#ffffff">
<!-- Generated by Doxygen 1.2.11 -->
<center>
<a class="qindex" href="index.html">Main Page</a> <a class="qindex" href="annotated.html">Data Structures</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Data Fields</a> <a class="qindex" href="globals.html">Globals</a> </center>
<hr><h1>agent_index.c File Reference</h1><code>#include <<a class="el" href="config_8h-source.html">config.h</a>></code><br>
<code>#include <signal.h></code><br>
<code>#include <string.h></code><br>
<code>#include <stdlib.h></code><br>
<code>#include <sys/types.h></code><br>
<code>#include <stdio.h></code><br>
<code>#include <fcntl.h></code><br>
<code>#include <sys/time.h></code><br>
<code>#include <time.h></code><br>
<code>#include <dmalloc.h></code><br>
<code>#include "mibincl.h"</code><br>
<code>#include "snmp_client.h"</code><br>
<code>#include "default_store.h"</code><br>
<code>#include "<a class="el" href="ds__agent_8h-source.html">ds_agent.h</a>"</code><br>
<code>#include "callback.h"</code><br>
<code>#include "<a class="el" href="agent__callbacks_8h-source.html">agent_callbacks.h</a>"</code><br>
<code>#include "<a class="el" href="agent__index_8h-source.html">agent_index.h</a>"</code><br>
<code>#include "snmp_alarm.h"</code><br>
<code>#include "snmp_secmod.h"</code><br>
<code>#include "<a class="el" href="snmpd_8h-source.html">snmpd.h</a>"</code><br>
<code>#include "mibgroup/struct.h"</code><br>
<code>#include "<a class="el" href="table_8h-source.html">helpers/table.h</a>"</code><br>
<code>#include "<a class="el" href="table__iterator_8h-source.html">helpers/table_iterator.h</a>"</code><br>
<code>#include "mib_module_includes.h"</code><br>
<p>
<a href="agent__index_8c-source.html">Go to the source code of this file.</a><table border=0 cellpadding=0 cellspacing=0>
<tr><td colspan=2><br><h2>Data Structures</h2></td></tr>
<tr><td nowrap align=right valign=top>struct </td><td valign=bottom><a class="el" href="structsnmp__index.html">snmp_index</a></td></tr>
<tr><td colspan=2><br><h2>Functions</h2></td></tr>
<tr><td nowrap align=right valign=top>char * </td><td valign=bottom><a class="el" href="agent__index_8c.html#a2">register_string_index</a> (oid *name, size_t name_len, char *cp)</td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="agent__index_8c.html#a3">register_int_index</a> (oid *name, size_t name_len, int val)</td></tr>
<tr><td nowrap align=right valign=top>variable_list * </td><td valign=bottom><a class="el" href="agent__index_8c.html#a4">register_oid_index</a> (oid *name, size_t name_len, oid *value, size_t value_len)</td></tr>
<tr><td nowrap align=right valign=top>variable_list * </td><td valign=bottom><a class="el" href="agent__index_8c.html#a5">register_index</a> (struct variable_list *varbind, int flags, struct snmp_session *ss)</td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="agent__index_8c.html#a6">release_index</a> (struct variable_list *varbind)</td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="agent__index_8c.html#a7">remove_index</a> (struct variable_list *varbind, struct snmp_session *ss)</td></tr>
<tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="agent__index_8c.html#a8">unregister_index_by_session</a> (struct snmp_session *ss)</td></tr>
<tr><td nowrap align=right valign=top>int </td><td valign=bottom><a class="el" href="agent__index_8c.html#a9">unregister_index</a> (struct variable_list *varbind, int remember, struct snmp_session *ss)</td></tr>
<tr><td nowrap align=right valign=top>void </td><td valign=bottom><a class="el" href="agent__index_8c.html#a10">dump_idx_registry</a> (void)</td></tr>
<tr><td colspan=2><br><h2>Variables</h2></td></tr>
<tr><td nowrap align=right valign=top><a class="el" href="structsnmp__index.html">snmp_index</a> * </td><td valign=bottom><a class="el" href="agent__index_8c.html#a0">snmp_index_head</a></td></tr>
<tr><td nowrap align=right valign=top>snmp_session * </td><td valign=bottom><a class="el" href="agent__index_8c.html#a1">main_session</a></td></tr>
</table>
<hr><h2>Function Documentation</h2>
<a name="a10" doxytag="agent_index.c::dump_idx_registry"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void dump_idx_registry </td>
<td class="md">( </td>
<td class="md" nowrap>void </td>
<td class="mdname1"> </td>
<td class="md">) </td>
<td class="md"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00495">495</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.
<p>
Referenced by <a class="el" href="agent__registry_8c-source.html#l01031">dump_registry</a>().
<p>
<div class="fragment"><pre>00496 {
00497 <font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *idxptr, *idxptr2;
00498 <font class="keywordtype">char</font> start_oid[SPRINT_MAX_LEN];
00499 <font class="keywordtype">char</font> end_oid[SPRINT_MAX_LEN];
00500
00501 <font class="keywordflow">if</font> ( snmp_index_head )
00502 printf(<font class="stringliteral">"\nIndex Allocations:\n"</font>);
00503 <font class="keywordflow">for</font>( idxptr = <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> ; idxptr != NULL; idxptr = idxptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a>) {
00504 sprint_objid(start_oid, idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->name, idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->name_length);
00505 printf(<font class="stringliteral">"%s indexes:\n"</font>, start_oid);
00506 <font class="keywordflow">for</font>( idxptr2 = idxptr ; idxptr2 != NULL; idxptr2 = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>) {
00507 <font class="keywordflow">switch</font>( idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->type ) {
00508 <font class="keywordflow">case</font> ASN_INTEGER:
00509 printf(<font class="stringliteral">" %c %ld %c\n"</font>,
00510 ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> ? <font class="charliteral">' '</font> : <font class="charliteral">'('</font> ),
00511 *idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.integer,
00512 ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> ? <font class="charliteral">' '</font> : <font class="charliteral">')'</font> ));
00513 <font class="keywordflow">break</font>;
00514 <font class="keywordflow">case</font> ASN_OCTET_STR:
00515 printf(<font class="stringliteral">" %c %s %c\n"</font>,
00516 ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> ? <font class="charliteral">' '</font> : <font class="charliteral">'('</font> ),
00517 idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.string,
00518 ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> ? <font class="charliteral">' '</font> : <font class="charliteral">')'</font> ));
00519 <font class="keywordflow">break</font>;
00520 <font class="keywordflow">case</font> ASN_OBJECT_ID:
00521 sprint_objid(end_oid, idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid,
00522 idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len/<font class="keyword">sizeof</font>(oid));
00523 printf(<font class="stringliteral">" %c %s %c\n"</font>,
00524 ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> ? <font class="charliteral">' '</font> : <font class="charliteral">'('</font> ),
00525 end_oid,
00526 ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> ? <font class="charliteral">' '</font> : <font class="charliteral">')'</font> ));
00527 <font class="keywordflow">break</font>;
00528 <font class="keywordflow">default</font>:
00529 printf(<font class="stringliteral">"unsupported type (%d)\n"</font>,
00530 idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->type);
00531 }
00532 }
00533 }
00534 }
</pre></div> </td>
</tr>
</table>
<a name="a5" doxytag="agent_index.c::register_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> struct variable_list* register_index </td>
<td class="md">( </td>
<td class="md" nowrap>struct variable_list * </td>
<td class="mdname"> <em>varbind</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int </td>
<td class="mdname"> <em>flags</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>struct snmp_session * </td>
<td class="mdname"> <em>ss</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00140">140</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00141 {
00142 <font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *new_index, *idxptr, *idxptr2;
00143 <font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *prev_oid_ptr, *prev_idx_ptr;
00144 <font class="keywordtype">int</font> res, res2, i;
00145
00146 <font class="preprocessor">#if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(TESTING)</font>
00147 <font class="keywordflow">if</font> (ds_get_boolean(DS_APPLICATION_ID, <a class="code" href="ds__agent_8h.html#a1">DS_AGENT_ROLE</a>) == <a class="code" href="snmpd_8h.html#a1">SUB_AGENT</a> )
00148 <font class="keywordflow">return</font>( agentx_register_index( ss, varbind, flags ));
00149 <font class="preprocessor">#endif</font>
00150 <font class="comment">/* Look for the requested OID entry */</font>
00151 prev_oid_ptr = NULL;
00152 prev_idx_ptr = NULL;
00153 res = 1;
00154 res2 = 1;
00155 <font class="keywordflow">for</font>( idxptr = <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> ; idxptr != NULL;
00156 prev_oid_ptr = idxptr, idxptr = idxptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a>) {
00157 <font class="keywordflow">if</font> ((res = snmp_oid_compare(varbind->name, varbind->name_length,
00158 idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->name,
00159 idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->name_length)) <= 0 )
00160 <font class="keywordflow">break</font>;
00161 }
00162
00163 <font class="comment">/* Found the OID - now look at the registered indices */</font>
00164 <font class="keywordflow">if</font> ( res == 0 && idxptr ) {
00165 <font class="keywordflow">if</font> ( varbind->type != idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->type )
00166 <font class="keywordflow">return</font> NULL; <font class="comment">/* wrong type */</font>
00167
00168 <font class="comment">/*</font>
00169 * If we've been asked for an arbitrary new value,
00170 * then find the end of the list.
00171 * If we've been asked for any arbitrary value,
00172 * then look for an unused entry, and use that.
00173 * If there aren't any, continue as for new.
00174 * Otherwise, locate the given value in the (sorted)
00175 * list of already allocated values
00176 */
00177 <font class="keywordflow">if</font> ( flags & <a class="code" href="agent__index_8h.html#a1">ALLOCATE_ANY_INDEX</a> ) {
00178 <font class="keywordflow">for</font>(idxptr2 = idxptr ; idxptr2 != NULL;
00179 prev_idx_ptr = idxptr2, idxptr2 = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>) {
00180 <font class="keywordflow">if</font> ( flags == <a class="code" href="agent__index_8h.html#a1">ALLOCATE_ANY_INDEX</a> && idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> == NULL ) {
00181 idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> = ss ;
00182 <font class="keywordflow">return</font> idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>;
00183 }
00184 }
00185 }
00186 <font class="keywordflow">else</font> {
00187 <font class="keywordflow">for</font>(idxptr2 = idxptr ; idxptr2 != NULL;
00188 prev_idx_ptr = idxptr2, idxptr2 = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>) {
00189 <font class="keywordflow">switch</font> ( varbind->type ) {
00190 <font class="keywordflow">case</font> ASN_INTEGER:
00191 res2 = (*varbind->val.integer - *idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.integer);
00192 <font class="keywordflow">break</font>;
00193 <font class="keywordflow">case</font> ASN_OCTET_STR:
00194 i = SNMP_MIN(varbind->val_len, idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len);
00195 res2 = memcmp(varbind->val.string, idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.string, i);
00196 <font class="keywordflow">break</font>;
00197 <font class="keywordflow">case</font> ASN_OBJECT_ID:
00198 res2 = snmp_oid_compare(varbind->val.objid, varbind->val_len/<font class="keyword">sizeof</font>(oid),
00199 idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid,
00200 idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len/<font class="keyword">sizeof</font>(oid));
00201 <font class="keywordflow">break</font>;
00202 <font class="keywordflow">default</font>:
00203 <font class="keywordflow">return</font> NULL; <font class="comment">/* wrong type */</font>
00204 }
00205 <font class="keywordflow">if</font> ( res2 <= 0 )
00206 <font class="keywordflow">break</font>;
00207 }
00208 <font class="keywordflow">if</font> ( res2 == 0 )
00209 <font class="keywordflow">return</font> NULL; <font class="comment">/* duplicate value */</font>
00210 }
00211 }
00212
00213 <font class="comment">/*</font>
00214 * OK - we've now located where the new entry needs to
00215 * be fitted into the index registry tree
00216 * To recap:
00217 * 'prev_oid_ptr' points to the head of the OID index
00218 * list prior to this one. If this is null, then
00219 * it means that this is the first OID in the list.
00220 * 'idxptr' points either to the head of this OID list,
00221 * or the next OID (if this is a new OID request)
00222 * These can be distinguished by the value of 'res'.
00223 *
00224 * 'prev_idx_ptr' points to the index entry that sorts
00225 * immediately prior to the requested value (if any).
00226 * If an arbitrary value is required, then this will
00227 * point to the last allocated index.
00228 * If this pointer is null, then either this is a new
00229 * OID request, or the requested value is the first
00230 * in the list.
00231 * 'idxptr2' points to the next sorted index (if any)
00232 * but is not actually needed any more.
00233 *
00234 * Clear? Good!
00235 * I hope you've been paying attention.
00236 * There'll be a test later :-)
00237 */
00238
00239 <font class="comment">/*</font>
00240 * We proceed by creating the new entry
00241 * (by copying the entry provided)
00242 */
00243 new_index = (<font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *)calloc( 1, sizeof( struct snmp_index ));
00244 <font class="keywordflow">if</font> (new_index == NULL)
00245 <font class="keywordflow">return</font> NULL;
00246
00247 <font class="keywordflow">if</font> (0 == snmp_varlist_add_variable(&new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>,
00248 varbind->name,
00249 varbind->name_length,
00250 varbind->type,
00251 varbind->val.string,
00252 varbind->val_len))<font class="keyword"> </font>{
00253 <font class="comment">/* if (snmp_clone_var( varbind, new_index->varbind ) != 0 ) */</font>
00254 free( new_index );
00255 <font class="keywordflow">return</font> NULL;
00256 }
00257 new_index-><a class="code" href="structsnmp__index.html#m1">session</a> = ss;
00258
00259 <font class="keywordflow">if</font> ( varbind->type == ASN_OCTET_STR && flags == <a class="code" href="agent__index_8h.html#a0">ALLOCATE_THIS_INDEX</a> )
00260 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.string[new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len] = 0;
00261
00262 <font class="comment">/*</font>
00263 * If we've been given a value, then we can use that, but
00264 * otherwise, we need to create a new value for this entry.
00265 * Note that ANY_INDEX and NEW_INDEX are both covered by this
00266 * test (since NEW_INDEX & ANY_INDEX = ANY_INDEX, remember?)
00267 */
00268 <font class="keywordflow">if</font> ( flags & <a class="code" href="agent__index_8h.html#a1">ALLOCATE_ANY_INDEX</a> ) {
00269 <font class="keywordflow">if</font> ( prev_idx_ptr ) {
00270 <font class="keywordflow">if</font> ( snmp_clone_var( prev_idx_ptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>, new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a> ) != 0 )<font class="keyword"> </font>{
00271 free( new_index );
00272 <font class="keywordflow">return</font> NULL;
00273 }
00274 }
00275 <font class="keywordflow">else</font>
00276 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.string = new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf;
00277
00278 <font class="keywordflow">switch</font> ( varbind->type ) {
00279 <font class="keywordflow">case</font> ASN_INTEGER:
00280 <font class="keywordflow">if</font> ( prev_idx_ptr ) {
00281 (*new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.integer)++;
00282 }
00283 <font class="keywordflow">else</font>
00284 *(new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.integer) = 1;
00285 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len = <font class="keyword">sizeof</font>(long);
00286 <font class="keywordflow">break</font>;
00287 <font class="keywordflow">case</font> ASN_OCTET_STR:
00288 <font class="keywordflow">if</font> ( prev_idx_ptr ) {
00289 i = new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len-1;
00290 <font class="keywordflow">while</font> ( new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf[ i ] == <font class="charliteral">'z'</font> ) {
00291 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf[ i ] = <font class="charliteral">'a'</font>;
00292 i--;
00293 <font class="keywordflow">if</font> ( i < 0 ) {
00294 i = new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len;
00295 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf[ i ] = <font class="charliteral">'a'</font>;
00296 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf[ i+1 ] = 0;
00297 }
00298 }
00299 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf[ i ]++;
00300 }
00301 <font class="keywordflow">else</font>
00302 strcpy((<font class="keywordtype">char</font> *)new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf, <font class="stringliteral">"aaaa"</font>);
00303 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len = strlen((<font class="keywordtype">char</font> *)new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->buf);
00304 <font class="keywordflow">break</font>;
00305 <font class="keywordflow">case</font> ASN_OBJECT_ID:
00306 <font class="keywordflow">if</font> ( prev_idx_ptr ) {
00307 i = prev_idx_ptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len/<font class="keyword">sizeof</font>(oid) -1;
00308 <font class="keywordflow">while</font> ( new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[ i ] == 255 ) {
00309 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[ i ] = 1;
00310 i--;
00311 <font class="keywordflow">if</font> ( i == 0 && new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[0] == 2 ) {
00312 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[ 0 ] = 1;
00313 i = new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len/<font class="keyword">sizeof</font>(oid);
00314 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[ i ] = 0;
00315 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len += <font class="keyword">sizeof</font>(oid);
00316 }
00317 }
00318 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[ i ]++;
00319 }
00320 <font class="keywordflow">else</font> {
00321 <font class="comment">/* If the requested OID name is small enough,</font>
00322 * append another OID (1) and use this as the
00323 * default starting value for new indexes.
00324 */
00325 <font class="keywordflow">if</font> ( (varbind->name_length+1) * <font class="keyword">sizeof</font>(oid) <= 40 ) {
00326 <font class="keywordflow">for</font> ( i = 0 ; i < (int)varbind->name_length ; i++ )
00327 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[i] = varbind->name[i];
00328 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[varbind->name_length] = 1;
00329 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len =
00330 (varbind->name_length+1) * <font class="keyword">sizeof</font>(oid);
00331 }
00332 <font class="keywordflow">else</font> {
00333 <font class="comment">/* Otherwise use '.1.1.1.1...' */</font>
00334 i = 40/<font class="keyword">sizeof</font>(oid);
00335 <font class="keywordflow">if</font> ( i > 4 )
00336 i = 4;
00337 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len = i * (<font class="keyword">sizeof</font>(oid));
00338 <font class="keywordflow">for</font> (i-- ; i>=0 ; i-- )
00339 new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.objid[i] = 1;
00340 }
00341 }
00342 <font class="keywordflow">break</font>;
00343 <font class="keywordflow">default</font>:
00344 snmp_free_var(new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>);
00345 free( new_index );
00346 <font class="keywordflow">return</font> NULL; <font class="comment">/* Index type not supported */</font>
00347 }
00348 }
00349
00350 <font class="comment">/*</font>
00351 * Right - we've set up the new entry.
00352 * All that remains is to link it into the tree.
00353 * There are a number of possible cases here,
00354 * so watch carefully.
00355 */
00356 <font class="keywordflow">if</font> ( prev_idx_ptr ) {
00357 new_index-><a class="code" href="structsnmp__index.html#m4">next_idx</a> = prev_idx_ptr-><a class="code" href="structsnmp__index.html#m4">next_idx</a>;
00358 new_index-><a class="code" href="structsnmp__index.html#m2">next_oid</a> = prev_idx_ptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a>;
00359 prev_idx_ptr-><a class="code" href="structsnmp__index.html#m4">next_idx</a> = new_index;
00360 }
00361 <font class="keywordflow">else</font> {
00362 <font class="keywordflow">if</font> ( res == 0 && idxptr ) {
00363 new_index-><a class="code" href="structsnmp__index.html#m4">next_idx</a> = idxptr;
00364 new_index-><a class="code" href="structsnmp__index.html#m2">next_oid</a> = idxptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a>;
00365 }
00366 <font class="keywordflow">else</font> {
00367 new_index-><a class="code" href="structsnmp__index.html#m4">next_idx</a> = NULL;
00368 new_index-><a class="code" href="structsnmp__index.html#m2">next_oid</a> = idxptr;
00369 }
00370
00371 <font class="keywordflow">if</font> ( prev_oid_ptr ) {
00372 <font class="keywordflow">while</font> ( prev_oid_ptr ) {
00373 prev_oid_ptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a> = new_index;
00374 prev_oid_ptr = prev_oid_ptr-><a class="code" href="structsnmp__index.html#m4">next_idx</a>;
00375 }
00376 }
00377 <font class="keywordflow">else</font>
00378 <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> = new_index;
00379 }
00380 <font class="keywordflow">return</font> new_index-><a class="code" href="structsnmp__index.html#m0">varbind</a>;
00381 }
</pre></div> </td>
</tr>
</table>
<a name="a3" doxytag="agent_index.c::register_int_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int register_int_index </td>
<td class="md">( </td>
<td class="md" nowrap>oid * </td>
<td class="mdname"> <em>name</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>size_t </td>
<td class="mdname"> <em>name_len</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int </td>
<td class="mdname"> <em>val</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00100">100</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00101 {
00102 <font class="keyword">struct </font>variable_list varbind, *res;
00103
00104 memset( &varbind, 0, <font class="keyword">sizeof</font>(<font class="keyword">struct</font> variable_list));
00105 varbind.type = ASN_INTEGER;
00106 snmp_set_var_objid( &varbind, name, name_len );
00107 varbind.val.string = varbind.buf;
00108 <font class="keywordflow">if</font> ( val != <a class="code" href="agent__index_8h.html#a3">ANY_INTEGER_INDEX</a> ) {
00109 varbind.val_len = <font class="keyword">sizeof</font>(long);
00110 *varbind.val.integer = val;
00111 res = <a class="code" href="agent__index_8h.html#a13">register_index</a>( &varbind, <a class="code" href="agent__index_8h.html#a0">ALLOCATE_THIS_INDEX</a>, main_session );
00112 }
00113 <font class="keywordflow">else</font>
00114 res = <a class="code" href="agent__index_8h.html#a13">register_index</a>( &varbind, <a class="code" href="agent__index_8h.html#a1">ALLOCATE_ANY_INDEX</a>, main_session );
00115
00116 <font class="keywordflow">if</font> ( res == NULL )
00117 <font class="keywordflow">return</font> -1;
00118 <font class="keywordflow">else</font>
00119 <font class="keywordflow">return</font> *res->val.integer;
00120 }
</pre></div> </td>
</tr>
</table>
<a name="a4" doxytag="agent_index.c::register_oid_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> struct variable_list* register_oid_index </td>
<td class="md">( </td>
<td class="md" nowrap>oid * </td>
<td class="mdname"> <em>name</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>size_t </td>
<td class="mdname"> <em>name_len</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>oid * </td>
<td class="mdname"> <em>value</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>size_t </td>
<td class="mdname"> <em>value_len</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00123">123</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00125 {
00126 <font class="keyword">struct </font>variable_list varbind;
00127
00128 memset( &varbind, 0, <font class="keyword">sizeof</font>(<font class="keyword">struct</font> variable_list));
00129 varbind.type = ASN_OBJECT_ID;
00130 snmp_set_var_objid( &varbind, name, name_len );
00131 <font class="keywordflow">if</font> ( value != <a class="code" href="agent__index_8h.html#a5">ANY_OID_INDEX</a> ) {
00132 snmp_set_var_value( &varbind, (u_char*)value, value_len*<font class="keyword">sizeof</font>(oid) );
00133 <font class="keywordflow">return</font>( <a class="code" href="agent__index_8h.html#a13">register_index</a>( &varbind, <a class="code" href="agent__index_8h.html#a0">ALLOCATE_THIS_INDEX</a>, main_session ));
00134 }
00135 <font class="keywordflow">else</font>
00136 <font class="keywordflow">return</font>( <a class="code" href="agent__index_8h.html#a13">register_index</a>( &varbind, <a class="code" href="agent__index_8h.html#a1">ALLOCATE_ANY_INDEX</a>, main_session ));
00137 }
</pre></div> </td>
</tr>
</table>
<a name="a2" doxytag="agent_index.c::register_string_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> char* register_string_index </td>
<td class="md">( </td>
<td class="md" nowrap>oid * </td>
<td class="mdname"> <em>name</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>size_t </td>
<td class="mdname"> <em>name_len</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>char * </td>
<td class="mdname"> <em>cp</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00079">79</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00080 {
00081 <font class="keyword">struct </font>variable_list varbind, *res;
00082
00083 memset( &varbind, 0, <font class="keyword">sizeof</font>(<font class="keyword">struct</font> variable_list));
00084 varbind.type = ASN_OCTET_STR;
00085 snmp_set_var_objid( &varbind, name, name_len );
00086 <font class="keywordflow">if</font> ( cp != <a class="code" href="agent__index_8h.html#a4">ANY_STRING_INDEX</a> ) {
00087 snmp_set_var_value( &varbind, (u_char *)cp, strlen(cp) );
00088 res = <a class="code" href="agent__index_8h.html#a13">register_index</a>( &varbind, <a class="code" href="agent__index_8h.html#a0">ALLOCATE_THIS_INDEX</a>, main_session );
00089 }
00090 <font class="keywordflow">else</font>
00091 res = <a class="code" href="agent__index_8h.html#a13">register_index</a>( &varbind, <a class="code" href="agent__index_8h.html#a1">ALLOCATE_ANY_INDEX</a>, main_session );
00092
00093 <font class="keywordflow">if</font> ( res == NULL )
00094 <font class="keywordflow">return</font> NULL;
00095 <font class="keywordflow">else</font>
00096 <font class="keywordflow">return</font> (<font class="keywordtype">char</font> *)res->val.string;
00097 }
</pre></div> </td>
</tr>
</table>
<a name="a6" doxytag="agent_index.c::release_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int release_index </td>
<td class="md">( </td>
<td class="md" nowrap>struct variable_list * </td>
<td class="mdname1"> <em>varbind</em> </td>
<td class="md">) </td>
<td class="md"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00388">388</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00389 {
00390 <font class="keywordflow">return</font>( <a class="code" href="agent__index_8h.html#a17">unregister_index</a>( varbind, TRUE, NULL ));
00391 }
</pre></div> </td>
</tr>
</table>
<a name="a7" doxytag="agent_index.c::remove_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int remove_index </td>
<td class="md">( </td>
<td class="md" nowrap>struct variable_list * </td>
<td class="mdname"> <em>varbind</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>struct snmp_session * </td>
<td class="mdname"> <em>ss</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00398">398</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00399 {
00400 <font class="keywordflow">return</font>( <a class="code" href="agent__index_8h.html#a17">unregister_index</a>( varbind, FALSE, ss ));
00401 }
</pre></div> </td>
</tr>
</table>
<a name="a9" doxytag="agent_index.c::unregister_index"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> int unregister_index </td>
<td class="md">( </td>
<td class="md" nowrap>struct variable_list * </td>
<td class="mdname"> <em>varbind</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>int </td>
<td class="mdname"> <em>remember</em>, </td>
</tr>
<tr>
<td></td>
<td></td>
<td class="md" nowrap>struct snmp_session * </td>
<td class="mdname"> <em>ss</em></td>
</tr>
<tr>
<td></td>
<td class="md">) </td>
<td class="md" colspan="2"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00415">415</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00416 {
00417 <font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *idxptr, *idxptr2;
00418 <font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *prev_oid_ptr, *prev_idx_ptr;
00419 <font class="keywordtype">int</font> res, res2, i;
00420
00421 <font class="preprocessor">#if defined(USING_AGENTX_SUBAGENT_MODULE) && !defined(TESTING)</font>
00422 <font class="keywordflow">if</font> (ds_get_boolean(DS_APPLICATION_ID, <a class="code" href="ds__agent_8h.html#a1">DS_AGENT_ROLE</a>) == <a class="code" href="snmpd_8h.html#a1">SUB_AGENT</a> )
00423 <font class="keywordflow">return</font>( agentx_unregister_index( ss, varbind ));
00424 <font class="preprocessor">#endif</font>
00425 <font class="comment">/* Look for the requested OID entry */</font>
00426 prev_oid_ptr = NULL;
00427 prev_idx_ptr = NULL;
00428 res = 1;
00429 res2 = 1;
00430 <font class="keywordflow">for</font>( idxptr = <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> ; idxptr != NULL;
00431 prev_oid_ptr = idxptr, idxptr = idxptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a>) {
00432 <font class="keywordflow">if</font> ((res = snmp_oid_compare(varbind->name, varbind->name_length,
00433 idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->name,
00434 idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->name_length)) <= 0 )
00435 <font class="keywordflow">break</font>;
00436 }
00437
00438 <font class="keywordflow">if</font> ( res != 0 )
00439 <font class="keywordflow">return</font> <a class="code" href="agent__index_8h.html#a8">INDEX_ERR_NOT_ALLOCATED</a>;
00440 <font class="keywordflow">if</font> ( varbind->type != idxptr-><a class="code" href="structsnmp__index.html#m0">varbind</a>->type )
00441 <font class="keywordflow">return</font> <a class="code" href="agent__index_8h.html#a7">INDEX_ERR_WRONG_TYPE</a>;
00442
00443 <font class="keywordflow">for</font>(idxptr2 = idxptr ; idxptr2 != NULL;
00444 prev_idx_ptr = idxptr2, idxptr2 = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>) {
00445 i = SNMP_MIN(varbind->val_len, idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val_len);
00446 res2 = memcmp(varbind->val.string, idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a>->val.string, i);
00447 <font class="keywordflow">if</font> ( res2 <= 0 )
00448 <font class="keywordflow">break</font>;
00449 }
00450 <font class="keywordflow">if</font> ( res2 != 0 )
00451 <font class="keywordflow">return</font> <a class="code" href="agent__index_8h.html#a8">INDEX_ERR_NOT_ALLOCATED</a>;
00452 <font class="keywordflow">if</font> ( ss != idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> )
00453 <font class="keywordflow">return</font> <a class="code" href="agent__index_8h.html#a9">INDEX_ERR_WRONG_SESSION</a>;
00454
00455 <font class="comment">/*</font>
00456 * If this is a "normal" index unregistration,
00457 * mark the index entry as unused, but leave
00458 * it in situ. This allows differentiation
00459 * between ANY_INDEX and NEW_INDEX
00460 */
00461 <font class="keywordflow">if</font> ( remember ) {
00462 idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> = NULL; <font class="comment">/* Unused index */</font>
00463 <font class="keywordflow">return</font> SNMP_ERR_NOERROR;
00464 }
00465 <font class="comment">/*</font>
00466 * If this is a failed attempt to register a
00467 * number of indexes, the successful ones
00468 * must be removed completely.
00469 */
00470 <font class="keywordflow">if</font> ( prev_idx_ptr ) {
00471 prev_idx_ptr-><a class="code" href="structsnmp__index.html#m4">next_idx</a> = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>;
00472 }
00473 <font class="keywordflow">else</font> <font class="keywordflow">if</font> ( prev_oid_ptr ) {
00474 <font class="keywordflow">if</font> ( idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a> ) <font class="comment">/* Use p_idx_ptr as a temp variable */</font>
00475 prev_idx_ptr = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>;
00476 <font class="keywordflow">else</font>
00477 prev_idx_ptr = idxptr2-><a class="code" href="structsnmp__index.html#m2">next_oid</a>;
00478 <font class="keywordflow">while</font> ( prev_oid_ptr ) {
00479 prev_oid_ptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a> = prev_idx_ptr;
00480 prev_oid_ptr = prev_oid_ptr-><a class="code" href="structsnmp__index.html#m4">next_idx</a>;
00481 }
00482 }
00483 <font class="keywordflow">else</font> {
00484 <font class="keywordflow">if</font> ( idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a> )
00485 <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>;
00486 <font class="keywordflow">else</font>
00487 <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> = idxptr2-><a class="code" href="structsnmp__index.html#m2">next_oid</a>;
00488 }
00489 snmp_free_var( idxptr2-><a class="code" href="structsnmp__index.html#m0">varbind</a> );
00490 free( idxptr2 );
00491 <font class="keywordflow">return</font> SNMP_ERR_NOERROR;
00492 }
</pre></div> </td>
</tr>
</table>
<a name="a8" doxytag="agent_index.c::unregister_index_by_session"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> void unregister_index_by_session </td>
<td class="md">( </td>
<td class="md" nowrap>struct snmp_session * </td>
<td class="mdname1"> <em>ss</em> </td>
<td class="md">) </td>
<td class="md"></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00404">404</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>.<div class="fragment"><pre>00405 {
00406 <font class="keyword">struct </font><a class="code" href="structsnmp__index.html">snmp_index</a> *idxptr, *idxptr2;
00407 <font class="keywordflow">for</font>(idxptr = <a class="code" href="agent__index_8c.html#a0">snmp_index_head</a> ; idxptr != NULL; idxptr = idxptr-><a class="code" href="structsnmp__index.html#m2">next_oid</a>)
00408 <font class="keywordflow">for</font>(idxptr2 = idxptr ; idxptr2 != NULL; idxptr2 = idxptr2-><a class="code" href="structsnmp__index.html#m4">next_idx</a>)
00409 <font class="keywordflow">if</font> ( idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> == ss )
00410 idxptr2-><a class="code" href="structsnmp__index.html#m1">session</a> = NULL;
00411 }
</pre></div> </td>
</tr>
</table>
<hr><h2>Variable Documentation</h2>
<a name="a1" doxytag="agent_index.c::main_session"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> struct snmp_session* main_session
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
<p>
Definition at line <a class="el" href="agent__index_8c-source.html#l00076">76</a> of file <a class="el" href="agent__index_8c-source.html">agent_index.c</a>. </td>
</tr>
</table>
<a name="a0" doxytag="agent_index.c::snmp_index_head"></a><p>
<table width="100%" cellpadding="2" cellspacing="0" border="0">
<tr>
<td class="md">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td class="md" nowrap valign="top"> struct <a class="el" href="structsnmp__index.html">snmp_index</a> * snmp_index_head
</table>
</td>
</tr>
</table>
<table cellspacing=5 cellpadding=0 border=0>
<tr>
<td>
</td>
<td>
<p>
</td>
</tr>
</table>
<hr><address><small>Generated on Sat Nov 10 14:09:53 2001 for net-snmp by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.gif" alt="doxygen" align="middle" border=0
width=110 height=53></a>1.2.11 written by <a href="mailto:dimitri@stack.nl">Dimitri van Heesch</a>,
© 1997-2001</small></address>
</body>
</html>
<!--#include virtual="/sfbutton.html" -->
<!--#include virtual="/sfbutton.html" -->
<!-- CONTENT END -->
<!--#include virtual="/page-bottom.html" -->
See more files for this project here