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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [lib/] [current/] [src/] [snmp_debug.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/snmp_debug.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
#include <config.h>
92
 
93
#include <stdio.h>
94
#if HAVE_STDLIB_H
95
#include <stdlib.h>
96
#endif
97
#if HAVE_STRING_H
98
#include <string.h>
99
#else
100
#include <strings.h>
101
#endif
102
#include <sys/types.h>
103
#if HAVE_NETINET_IN_H
104
#include <netinet/in.h>
105
#endif
106
#if HAVE_STDARG_H
107
#include <stdarg.h>
108
#else
109
#include <varargs.h>
110
#endif
111
#if HAVE_WINSOCK_H
112
#include <winsock.h>
113
#endif
114
 
115
#if HAVE_DMALLOC_H
116
#include <dmalloc.h>
117
#endif
118
 
119
#include "asn1.h"
120
#include "mib.h"
121
#include "snmp_api.h"
122
#include "read_config.h"
123
#include "snmp_debug.h"
124
#include "snmp_impl.h"
125
#include "snmp_logging.h"
126
 
127
static int   dodebug = SNMP_ALWAYS_DEBUG;
128
static int   debug_num_tokens=0;
129
static char *debug_tokens[MAX_DEBUG_TOKENS];
130
static int   debug_print_everything=0;
131
 
132
/* indent debugging:  provide a space padded section to return an indent for */
133
static int debugindent=0;
134
#define INDENTMAX 80
135
static char debugindentchars[] = "                                                                                ";
136
 
137
char *
138
debug_indent(void) {
139
  return debugindentchars;
140
}
141
 
142
void
143
debug_indent_add(int amount) {
144
  if (debugindent+amount >= 0 && debugindent+amount < 80) {
145
    debugindentchars[debugindent] = ' ';
146
    debugindent += amount;
147
    debugindentchars[debugindent] = '\0';
148
  }
149
}
150
 
151
void
152
#if HAVE_STDARG_H
153
DEBUGP(const char *first, ...)
154
#else
155
DEBUGP(va_alist)
156
  va_dcl
157
#endif
158
{
159
  va_list args;
160
#if HAVE_STDARG_H
161
  va_start(args, first);
162
#else
163
  const char *first;
164
  va_start(args);
165
  first = va_arg(args, const char *);
166
#endif
167
 
168
  if (dodebug && (debug_print_everything || debug_num_tokens == 0)) {
169
    fprintf(stderr, "%s: ", DEBUG_ALWAYS_TOKEN);
170
    vfprintf(stderr, first, args);
171
  }
172
  va_end(args);
173
}
174
 
175
void
176
DEBUGPOID(oid *theoid,
177
          size_t len)
178
{
179
  char c_oid[SPRINT_MAX_LEN];
180
  sprint_objid(c_oid,theoid,len);
181
  DEBUGP(c_oid);
182
}
183
 
184
void debug_config_register_tokens(const char *configtoken, char *tokens) {
185
  debug_register_tokens(tokens);
186
}
187
 
188
void debug_config_turn_on_debugging(const char *configtoken, char *line) {
189
  snmp_set_do_debugging(atoi(line));
190
}
191
 
192
void
193
snmp_debug_init(void) {
194
  debugindentchars[0] = '\0'; /* zero out the debugging indent array. */
195
  register_premib_handler("snmp","doDebugging",
196
                          debug_config_turn_on_debugging, NULL,
197
                          "(1|0)");
198
  register_premib_handler("snmp","debugTokens",
199
                          debug_config_register_tokens, NULL,
200
                          "token[,token...]");
201
}
202
 
203
void debug_register_tokens(char *tokens) {
204
  char *newp, *cp;
205
 
206
  if (tokens == 0 || *tokens == 0)
207
    return;
208
 
209
  newp = strdup(tokens); /* strtok messes it up */
210
  cp = strtok(newp, DEBUG_TOKEN_DELIMITER);
211
  while(cp) {
212
    if (strlen(cp) < MAX_DEBUG_TOKEN_LEN) {
213
      if (strcasecmp(cp, DEBUG_ALWAYS_TOKEN) == 0)
214
        debug_print_everything = 1;
215
      else if (debug_num_tokens < MAX_DEBUG_TOKENS)
216
        debug_tokens[debug_num_tokens++] = strdup(cp);
217
    }
218
    cp = strtok(NULL, DEBUG_TOKEN_DELIMITER);
219
  }
220
  free(newp);
221
}
222
 
223
 
224
/*
225
  debug_is_token_registered(char *TOKEN):
226
 
227
  returns SNMPERR_SUCCESS
228
       or SNMPERR_GENERR
229
 
230
  if TOKEN has been registered and debugging support is turned on.
231
*/
232
int
233
debug_is_token_registered(const char *token) {
234
  int i;
235
 
236
  /* debugging flag is on or off */
237
  if (!dodebug)
238
    return SNMPERR_GENERR;
239
 
240
  if (debug_num_tokens == 0 || debug_print_everything) {
241
    /* no tokens specified, print everything */
242
    return SNMPERR_SUCCESS;
243
  } else {
244
    for(i=0; i < debug_num_tokens; i++) {
245
      if (strncmp(debug_tokens[i], token, strlen(debug_tokens[i])) == 0) {
246
        return SNMPERR_SUCCESS;
247
      }
248
    }
249
  }
250
  return SNMPERR_GENERR;
251
}
252
 
253
void
254
#if HAVE_STDARG_H
255
debugmsg(const char *token, const char *format, ...)
256
#else
257
debugmsg(va_alist)
258
  va_dcl
259
#endif
260
{
261
  va_list debugargs;
262
 
263
#if HAVE_STDARG_H
264
  va_start(debugargs,format);
265
#else
266
  const char *format;
267
  const char *token;
268
 
269
  va_start(debugargs);
270
  token = va_arg(debugargs, const char *);
271
  format = va_arg(debugargs, const char *); /* ??? */
272
#endif
273
 
274
  if (debug_is_token_registered(token) == SNMPERR_SUCCESS) {
275
    snmp_vlog(LOG_DEBUG, format, debugargs);
276
  }
277
  va_end(debugargs);
278
}
279
 
280
void
281
debugmsg_oid(const char *token, oid *theoid, size_t len) {
282
  char c_oid[SPRINT_MAX_LEN];
283
 
284
  sprint_objid(c_oid, theoid, len);
285
  debugmsg(token, c_oid);
286
}
287
 
288
void
289
debugmsg_hex(const char *token, u_char *thedata, size_t len) {
290
  char buf[SPRINT_MAX_LEN];
291
 
292
  sprint_hexstring(buf, thedata, len);
293
  debugmsg(token, buf);
294
}
295
 
296
void
297
debugmsg_hextli(const char *token, u_char *thedata, size_t len) {
298
  char buf[SPRINT_MAX_LEN];
299
  int incr;
300
 
301
  /*XX tracing lines removed from this function DEBUGTRACE; */
302
  DEBUGIF(token) {
303
    for(incr = 16; len > 0; len -= incr, thedata += incr) {
304
      if ((int)len < incr) incr = len;
305
      /*XXnext two lines were DEBUGPRINTINDENT(token);*/
306
      debugmsgtoken(token, "%s", debug_indent());
307
      debugmsg(token, "%s", debug_indent());
308
      sprint_hexstring(buf, thedata, incr);
309
      debugmsg(token, buf);
310
    }
311
  }
312
}
313
 
314
void
315
#if HAVE_STDARG_H
316
debugmsgtoken(const char *token, const char *format, ...)
317
#else
318
debugmsgtoken(va_alist)
319
  va_dcl
320
#endif
321
{
322
  va_list debugargs;
323
 
324
#if HAVE_STDARG_H
325
  va_start(debugargs,format);
326
#else
327
  const char *token;
328
 
329
  va_start(debugargs);
330
  token = va_arg(debugargs, const char *);
331
#endif
332
 
333
  debugmsg(token, "%s: ", token);
334
 
335
  va_end(debugargs);
336
}
337
 
338
/* for speed, these shouldn't be in default_storage space */
339
void
340
snmp_set_do_debugging(int val)
341
{
342
  dodebug = val;
343
}
344
 
345
int
346
snmp_get_do_debugging (void)
347
{
348
  return dodebug;
349
}

powered by: WebSVN 2.1.0

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