OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [lib/] [current/] [src/] [default_store.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      ./lib/current/src/default_store.c
4
//
5
//
6
//==========================================================================
7
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
8
// -------------------------------------------                              
9
// This file is part of eCos, the Embedded Configurable Operating System.   
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under    
13
// the terms of the GNU General Public License as published by the Free     
14
// Software Foundation; either version 2 or (at your option) any later      
15
// version.                                                                 
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT      
18
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
20
// for more details.                                                        
21
//
22
// You should have received a copy of the GNU General Public License        
23
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
24
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
25
//
26
// As a special exception, if other files instantiate templates or use      
27
// macros or inline functions from this file, or you compile this file      
28
// and link it with other works to produce a work based on this file,       
29
// this file does not by itself cause the resulting work to be covered by   
30
// the GNU General Public License. However the source code for this file    
31
// must still be made available in accordance with section (3) of the GNU   
32
// General Public License v2.                                               
33
//
34
// This exception does not invalidate any other reasons why a work based    
35
// on this file might be covered by the GNU General Public License.         
36
// -------------------------------------------                              
37
// ####ECOSGPLCOPYRIGHTEND####                                              
38
//####UCDSNMPCOPYRIGHTBEGIN####
39
//
40
// -------------------------------------------
41
//
42
// Portions of this software may have been derived from the UCD-SNMP
43
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
44
// California at Davis, which was originally based on the Carnegie Mellon
45
// University SNMP implementation.  Portions of this software are therefore
46
// covered by the appropriate copyright disclaimers included herein.
47
//
48
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
49
// -------------------------------------------
50
//
51
//####UCDSNMPCOPYRIGHTEND####
52
//==========================================================================
53
//#####DESCRIPTIONBEGIN####
54
//
55
// Author(s):    hmt
56
// Contributors: hmt
57
// Date:         2000-05-30
58
// Purpose:      Port of UCD-SNMP distribution to eCos.
59
// Description:  
60
//              
61
//
62
//####DESCRIPTIONEND####
63
//
64
//==========================================================================
65
/********************************************************************
66
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
67
 
68
                          Derivative Work -
69
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
70
 
71
                         All Rights Reserved
72
 
73
Permission to use, copy, modify and distribute this software and its
74
documentation for any purpose and without fee is hereby granted,
75
provided that the above copyright notice appears in all copies and
76
that both that copyright notice and this permission notice appear in
77
supporting documentation, and that the name of CMU and The Regents of
78
the University of California not be used in advertising or publicity
79
pertaining to distribution of the software without specific written
80
permission.
81
 
82
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
83
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
84
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
85
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
86
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
87
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
88
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
89
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
90
*********************************************************************/
91
/* default_store.h: storage space for defaults */
92
 
93
#include <config.h>
94
#include <sys/types.h>
95
#if HAVE_STDLIB_H
96
#include <stdlib.h>
97
#endif
98
#if HAVE_NETINET_IN_H
99
#include <netinet/in.h>
100
#endif
101
#if HAVE_STDLIB_H
102
#include <stdlib.h>
103
#endif
104
#if HAVE_STRING_H
105
#include <string.h>
106
#else
107
#include <strings.h>
108
#endif
109
#if HAVE_WINSOCK_H
110
#include <winsock.h>
111
#endif
112
 
113
#if HAVE_DMALLOC_H
114
#include <dmalloc.h>
115
#endif
116
 
117
#include "asn1.h"
118
#include "snmp_api.h"
119
#include "snmp_debug.h"
120
#include "snmp_logging.h"
121
#include "tools.h"
122
#include "read_config.h"
123
#include "default_store.h"
124
#include "read_config.h"
125
#include "system.h"
126
 
127
struct ds_read_config *ds_configs = NULL;
128
 
129
int ds_integers[DS_MAX_IDS][DS_MAX_SUBIDS];
130
char ds_booleans[DS_MAX_IDS][DS_MAX_SUBIDS/8];  /* bit vector storage. */
131
char *ds_strings[DS_MAX_IDS][DS_MAX_SUBIDS];  /* bit vector storage. */
132
 
133
int
134
ds_set_boolean(int storeid, int which, int value) {
135
 
136
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
137
      storeid < 0 || which < 0)
138
    return SNMPERR_GENERR;
139
 
140
  DEBUGMSGTL(("ds_set_boolean","Setting %d:%d = %d/%s\n", storeid, which,
141
              value, ((value)?"True":"False")));
142
 
143
  if (value > 0)
144
    ds_booleans[storeid][which/8] |= (1 << (which%8));
145
  else
146
    ds_booleans[storeid][which/8] &= (0xff7f >> (7-(which%8)));
147
 
148
  return SNMPERR_SUCCESS;
149
}
150
 
151
int
152
ds_toggle_boolean(int storeid, int which) {
153
 
154
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
155
      storeid < 0 || which < 0)
156
    return SNMPERR_GENERR;
157
 
158
  if ((ds_booleans[storeid][which/8] & (1 << (which % 8))) == 0)
159
    ds_booleans[storeid][which/8] |= (1 << (which%8));
160
  else
161
    ds_booleans[storeid][which/8] &= (0xff7f >> (7-(which%8)));
162
 
163
  DEBUGMSGTL(("ds_toggle_boolean","Setting %d:%d = %d/%s\n", storeid, which,
164
              ds_booleans[storeid][which/8],
165
              ((ds_booleans[storeid][which/8])?"True":"False")));
166
 
167
  return SNMPERR_SUCCESS;
168
}
169
 
170
int
171
ds_get_boolean(int storeid, int which) {
172
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
173
      storeid < 0 || which < 0)
174
    return SNMPERR_GENERR;
175
 
176
  return ((ds_booleans[storeid][which/8] & (1 << (which%8))) ? 1 : 0);
177
}
178
 
179
int
180
ds_set_int(int storeid, int which, int value) {
181
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
182
      storeid < 0 || which < 0)
183
    return SNMPERR_GENERR;
184
 
185
  DEBUGMSGTL(("ds_set_int","Setting %d:%d = %d\n", storeid, which, value));
186
 
187
  ds_integers[storeid][which] = value;
188
  return SNMPERR_SUCCESS;
189
}
190
 
191
int
192
ds_get_int(int storeid, int which) {
193
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
194
      storeid < 0 || which < 0)
195
    return SNMPERR_GENERR;
196
 
197
  return (ds_integers[storeid][which]);
198
}
199
 
200
int
201
ds_set_string(int storeid, int which, const char *value) {
202
 
203
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
204
      storeid < 0 || which < 0)
205
    return SNMPERR_GENERR;
206
 
207
  DEBUGMSGTL(("ds_set_string","Setting %d:%d = %s\n", storeid, which,
208
              value));
209
 
210
  if (ds_strings[storeid][which] != NULL)
211
    free(ds_strings[storeid][which]);
212
 
213
  if (value)
214
    ds_strings[storeid][which] = strdup(value);
215
  else
216
    ds_strings[storeid][which] = NULL;
217
 
218
  return SNMPERR_SUCCESS;
219
}
220
 
221
char *
222
ds_get_string(int storeid, int which) {
223
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
224
      storeid < 0 || which < 0)
225
    return NULL;
226
 
227
  return (ds_strings[storeid][which]);
228
}
229
 
230
void
231
ds_handle_config(const char *token, char *line) {
232
  struct ds_read_config *drsp;
233
  char buf[SNMP_MAXBUF];
234
  int itmp;
235
 
236
  DEBUGMSGTL(("ds_handle_config", "handling %s\n", token));
237
  for(drsp = ds_configs; drsp != NULL && strcasecmp(token, drsp->token) != 0;
238
      drsp = drsp->next);
239
  if (drsp != NULL) {
240
    DEBUGMSGTL(("ds_handle_config",
241
                "setting: token=%s, type=%d, id=%d, which=%d\n",
242
                drsp->token, drsp->type, drsp->storeid, drsp->which));
243
    switch (drsp->type) {
244
      case ASN_BOOLEAN:
245
        if (strncasecmp(line,"yes",3) == 0 || strncasecmp(line,"true",4) == 0) {
246
          itmp = 1;
247
        } else if (strncasecmp(line,"no",3) == 0 ||
248
                strncasecmp(line,"false",5) == 0) {
249
          itmp = 0;
250
        } else if (atoi(line) > 0) {
251
          itmp = 1;
252
        } else {
253
          itmp = 0;
254
        }
255
        ds_set_boolean(drsp->storeid, drsp->which, itmp);
256
        DEBUGMSGTL(("ds_handle_config", "bool: %d\n", itmp));
257
        break;
258
 
259
      case ASN_INTEGER:
260
        ds_set_int(drsp->storeid, drsp->which, atoi(line));
261
        DEBUGMSGTL(("ds_handle_config", "int: %d\n", atoi(line)));
262
        break;
263
 
264
      case ASN_OCTET_STR:
265
        if (*line == '"') {
266
            copy_word(line, buf);
267
            ds_set_string(drsp->storeid, drsp->which, buf);
268
        } else {
269
            ds_set_string(drsp->storeid, drsp->which, line);
270
        }
271
        DEBUGMSGTL(("ds_handle_config", "string: %s\n", line));
272
        break;
273
 
274
      default:
275
        snmp_log(LOG_CRIT,"ds_handle_config *** unknown type %d\n", drsp->type);
276
        break;
277
    }
278
  } else {
279
    snmp_log(LOG_CRIT, "ds_handle_config *** no registration for %s\n", token);
280
  }
281
}
282
 
283
 
284
int
285
ds_register_config(u_char type, const char *ftype, const char *token,
286
                   int storeid, int which) {
287
  struct ds_read_config *drsp;
288
 
289
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
290
      storeid < 0 || which < 0 || token == NULL)
291
    return SNMPERR_GENERR;
292
 
293
  if (ds_configs == NULL) {
294
    ds_configs = SNMP_MALLOC_STRUCT(ds_read_config);
295
    drsp = ds_configs;
296
  } else {
297
    for(drsp = ds_configs; drsp->next != NULL; drsp = drsp->next);
298
    drsp->next = SNMP_MALLOC_STRUCT(ds_read_config);
299
    drsp = drsp->next;
300
  }
301
 
302
  drsp->type = type;
303
  drsp->token = strdup(token);
304
  drsp->storeid = storeid;
305
  drsp->which = which;
306
 
307
  switch (type) {
308
    case ASN_BOOLEAN:
309
      register_config_handler(ftype, token, ds_handle_config, NULL,"(1|yes|true|0|no|false)");
310
      break;
311
 
312
    case ASN_INTEGER:
313
      register_config_handler(ftype, token, ds_handle_config, NULL,"integerValue");
314
      break;
315
 
316
    case ASN_OCTET_STR:
317
      register_config_handler(ftype, token, ds_handle_config, NULL,"string");
318
      break;
319
 
320
  }
321
  return SNMPERR_SUCCESS;
322
}
323
 
324
int
325
ds_register_premib(u_char type, const char *ftype, const char *token,
326
                   int storeid, int which) {
327
  struct ds_read_config *drsp;
328
 
329
  if (storeid >= DS_MAX_IDS || which >= DS_MAX_SUBIDS ||
330
      storeid < 0 || which < 0 || token == NULL)
331
    return SNMPERR_GENERR;
332
 
333
  if (ds_configs == NULL) {
334
    ds_configs = SNMP_MALLOC_STRUCT(ds_read_config);
335
    drsp = ds_configs;
336
  } else {
337
    for(drsp = ds_configs; drsp->next != NULL; drsp = drsp->next);
338
    drsp->next = SNMP_MALLOC_STRUCT(ds_read_config);
339
    drsp = drsp->next;
340
  }
341
 
342
  drsp->type = type;
343
  drsp->token = strdup(token);
344
  drsp->storeid = storeid;
345
  drsp->which = which;
346
 
347
  switch (type) {
348
    case ASN_BOOLEAN:
349
      register_premib_handler(ftype, token, ds_handle_config, NULL,"(1|yes|true|0|no|false)");
350
      break;
351
 
352
    case ASN_INTEGER:
353
      register_premib_handler(ftype, token, ds_handle_config, NULL,"integerValue");
354
      break;
355
 
356
    case ASN_OCTET_STR:
357
      register_premib_handler(ftype, token, ds_handle_config, NULL,"string");
358
      break;
359
 
360
  }
361
  return SNMPERR_SUCCESS;
362
}
363
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.