📄 v3_con.c
字号:
/* v3_con.c - v3_con.c routines *//* * Copyright 2000-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//* * Copyright 1998 Integrated Systems, Inc. * All rights reserved. *//* * $Log: v3_con.c,v $ * Revision 1.2 2001/11/06 21:20:30 josh * revised new path hacking * * Revision 1.1.1.1 2001/11/05 17:47:44 tneale * Tornado shuffle * * Revision 9.2 2001/01/19 22:22:29 paul * Update copyright. * * Revision 9.1 2000/03/17 00:19:29 meister * Update copyright message * * Revision 9.0 1998/10/16 22:12:33 sar * Update version stamp to match release * * Revision 8.6 1998/08/12 04:44:04 sar * Move the initialization routines around some in order to minimize * the amount of code that gets pulled in for init purposes. * * Revision 8.5 1998/08/04 02:00:13 sar * Modified some of the routines that allocate longer term * storage (table structures and indexing information) to * user SNMP_memory_{alloc free}_lt in preparation for * possibly allocating them from a different pool then the * short term structures. * * Revision 8.4 1998/07/02 00:47:55 sar * Correct search function * * Revision 8.3 1998/06/19 20:13:58 sar * make sure all files include asn1conf.h and snmp.h to pick up all of * the common code * * Revision 8.2 1998/06/09 21:46:29 sar * Cleaned up some code that might have called alloc or memcmp with * 0 lenght strings * * Revision 8.1 1998/06/09 16:43:53 sar * Moved some context routines to snmp so that they are in the core code * and can be used by the rest of the core. Also renamed the routines * to keep them separate from usec. * *//* [clearcase]modification history-------------------01d,12may05,job fix apigen comments01c,18apr05,job update copyright notices01b,23feb05,job apigen for documented APIs01a,24nov03,job update copyright information*//*DESCRIPTIONThis library contains v3_con.c routines.INCLUDE FILES: snmp.h, v3_con.h*/#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/vbdefs.h>#include <wrn/wm/snmp/engine/snmpdefs.h>#include <wrn/wm/snmp/engine/v3_con.h>#include <wrn/wm/snmp/engine/auxfuncs.h>/* this file manages the context information we must maintain *//************************************************************************NAME: context_searchPURPOSE: Find the pointer that would point to the named context if that context were to exist. We use this scheme to allow the find, add and remove routines to use this routine. PARAMETERS: bits8_t * context name ALENGTH_T length of context nameRETURNS: SNMP_CONTEXT_T ** ************************************************************************/static SNMP_CONTEXT_T ** context_search (bits8_t *con_name, ALENGTH_T con_len){SNMP_CONTEXT_T **context;for(context = &v3_context_root; *context; context = &(*context)->next) if ((*context)->length >= con_len) break;for(; *context; context = &(*context)->next) if (((*context)->length != con_len) || (MEMCMP_NULLOK((*context)->name, con_name, con_len) >= 0)) break;return(context);}/********************************************************************************* SNMP_V3_Context_Add - create a context with the given name* SYNOPSIS** \cs* int SNMP_V3_Context_Add * ( * bits8_t * name, * ALENGTH_T length * )* \ce** DESCRIPTION** This routine creates a context with the given name and adds it to list.** PARAMETERS* \is* \i <*name>* Specify the name to use for the created context.* \i <length>* Specify the length in bytes of the name.* \ie** RETURNS * If successful, this routine returns 0. If a context using name already * exists, or if the value specified for length is greater than the maximum * length allowed for context names, it returns 1.** ERRNO: N/A** SEE ALSO: SNMP_V3_Context_Find(), SNMP_V3_Context_Remove()*/int SNMP_V3_Context_Add (bits8_t *con_name, ALENGTH_T con_len){SNMP_CONTEXT_T **con_list, *con_add;if (con_len > ETC_CONTEXT_MAX) return(1);con_list = context_search(con_name, con_len);if (*con_list && ((*con_list)->length == con_len) && (MEMCMP_NULLOK((*con_list)->name, con_name, con_len) == 0)) return(1);con_add = (SNMP_CONTEXT_T *)SNMP_memory_alloc_lt(sizeof(SNMP_CONTEXT_T) + con_len);if (con_add == 0) return(1);if (con_len) { con_add->name = ((bits8_t *)con_add) + sizeof(SNMP_CONTEXT_T); MEMCPY(con_add->name, con_name, con_len); con_add->length = con_len; }else { con_add->name = 0; con_add->length = 0; }con_add->next = *con_list;*con_list = con_add;return(0);}/********************************************************************************* SNMP_V3_Context_Remove - remove a specified context from the list* SYNOPSIS** \cs* int SNMP_V3_Context_Remove * (* bits8_t * name,* ALENGTH_T length* )* \ce** DESCRIPTION** This routine removes a specified context from the list and frees the space.** PARAMETERS* \is* \i <*name>* Specify the context name to remove.* \i <length>* Specify the length in bytes of the context name.* \ie** RETURNS: If the context was successfully removed, this routine returns 0. * Otherwise, it returns 1.** ERRNO: N/A** SEE ALSO: SNMP_V3_Context_Add(), SNMP_V3_Context_Find()*/int SNMP_V3_Context_Remove (bits8_t *con_name, ALENGTH_T con_len){SNMP_CONTEXT_T **con_list, *con_remove;if (con_len > ETC_CONTEXT_MAX) return(1);con_list = context_search(con_name, con_len);if ((*con_list == 0) || ((*con_list)->length != con_len) || (MEMCMP_NULLOK((*con_list)->name, con_name, con_len) != 0)) return(1);con_remove = *con_list;*con_list = con_remove->next;SNMP_memory_free_lt(con_remove);return(0);}/********************************************************************************* SNMP_V3_Context_Find - find the context with the given name* SYNOPSIS** \cs* SNMP_CONTEXT_T * SNMP_V3_Context_Find * ( * bits8_t * name, * LENGTH_T length * )* \ce** DESCRIPTION** This routine finds the context with the given name.** PARAMETERS* \is* \i <*name>* Specify the context name for which to search.* \i <length>* Specify the length in bytes of the context name.* \ie** RETURNS: If the context exists, this routine returns a pointer to it. * Otherwise, it returns 0.** ERRNO: N/A** SEE ALSO: SNMP_V3_Context_Add(), SNMP_V3_Context_Remove()*/SNMP_CONTEXT_T * SNMP_V3_Context_Find (bits8_t *con_name, ALENGTH_T con_len){SNMP_CONTEXT_T **con_list;if (con_len > ETC_CONTEXT_MAX) return(0);con_list = context_search(con_name, con_len);if ((*con_list == 0) || ((*con_list)->length != con_len) || (MEMCMP_NULLOK((*con_list)->name, con_name, con_len) != 0)) return(0);return(*con_list);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -