📄 namingscopes.c
字号:
/* namingScopes.c - register naming scopes functions *//* * Copyright 2002-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. */#include "copyright_wrs.h"/*modification history-------------------01e,19apr05,job update copyright notices01d,01dec03,job update copyright information01c,12mar03,ant changes after code review, changed component name01b,17jan02,ism code clean up01a,05dec02,ism written*/#include <wrn/wm/snmp/engine/asn1conf.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/vxagent/namingScopes.h>#if INSTALL_SNMP_VXWORKS_VIRTUAL_STACK/* defines *//* Defines used for listType */#define COMMUNITY_LIST 0x01 /* used for SNMPv1 and v2 */#define CONTEXT_LIST 0x02 /* used for SNMPv3 *//* debug define, used for testing */#ifndef NAMING_SCOPE_DEBUG#define NAMING_SCOPE_DEBUG 0#endif /* types */typedef struct VIEW_LIST_S { struct VIEW_LIST_S * next; EBUFFER_T commOrCon; /* either a community or a context */ bits8_t viewType; /* get, set or get/set */ EBUFFER_T viewName; /* RFC 2275 view name */ bits32_t vsNum; /* Virtual Stack number */ } VIEW_LIST_T;typedef struct VIEW_LIST_HEAD_S { struct VIEW_LIST_S * first; bits8_t listType; /* either COMMUNITY_LIST or CONTEXT_LIST */ } VIEW_LIST_HEAD_T;/* statics */LOCAL VIEW_LIST_HEAD_T communityStringHead;LOCAL VIEW_LIST_T * communityStringLastMatch = NULL;#if INSTALL_ENVOY_SNMP_VERSION_3LOCAL VIEW_LIST_HEAD_T contextNameHead;LOCAL VIEW_LIST_T * contextNameLastMatch = NULL;#endif /* INSTALL_ENVOY_SNMP_VERSION_3 *//* local functions that do all the work *//****************************************************************************** * * viewRegisterIntern - Internal function to register a view * * This function adds a new view, or viewType, to the list whose head is * <viewListHead>, which will be either the list for community strings or * context names. * * Note that if multi-instance is not installed then <vsNum> will be ignored. * * Parameters: * * <viewListHead> - head of view list * <commOrCon> - either community or context * <stringLen> - the length of <commOrCon> * <viewType> - type of view, get, set, get/set * <viewName> - view name for this view * <nameLen> - the length of <viewName> * <vsNum> - the vsnum for the new view * * RETURNS: OK or ERROR * */LOCAL STATUS viewRegisterIntern ( VIEW_LIST_HEAD_T * viewListHead, bits8_t * commOrCon, bits32_t stringLen, bits8_t viewType, bits8_t * viewName, bits32_t nameLen, bits32_t vsNum ) { VIEW_LIST_T * newEntry = NULL, * current; if ((commOrCon == NULL) || ((viewType & (VIEW_TYPE_GET | VIEW_TYPE_SET)) == 0)) {#if NAMING_SCOPE_DEBUG printf ("Invalid argument(s): Name: %s Name Length: %d Type: %d\n", commOrCon, stringLen, viewType);#endif /* NAMING_SCOPE_DEBUG */ return (ERROR); } /* * search for this view in our list of already registered views, starting * at <viewListHead>. If we find one then allow the viewType to be changed * if the other attributes are the same, so we don't add a contradicting * view entry, otherwise return ERROR. */ for (current = viewListHead->first; current != NULL; current = current->next) { if ((stringLen == EBufferUsed (¤t->commOrCon)) && (memcmp (commOrCon, EBufferStart (¤t->commOrCon), stringLen) == 0)) { /* * Found existing view, check attributes. */ if ((nameLen == EBufferUsed (¤t->viewName)) && (memcmp (viewName, EBufferStart (¤t->viewName), nameLen) == 0) && (current->vsNum == vsNum) ) {#if NAMING_SCOPE_DEBUG printf ("Found existing entry, adding viewType\n");#endif /* NAMING_SCOPE_DEBUG */ /* * found existing view, update viewType. This will not * remove the existing view type but will either add another * view type for this entry or have no effect if the existing * view type is the same as the new view type. */ current->viewType |= viewType; return (OK); } else { /* found existing view but with different attributes */ return (ERROR); } } } /* view doesn't already exist, add a new one */#if NAMING_SCOPE_DEBUG printf ("Adding new entry\n");#endif /* NAMING_SCOPE_DEBUG */ if ((newEntry = (VIEW_LIST_T *) SNMP_memory_alloc (sizeof (VIEW_LIST_T))) == 0) { return (ERROR); } EBufferInitialize (&newEntry->commOrCon); if ((EBufferAllocateLoad (BFL_IS_ALLOC, &newEntry->commOrCon, commOrCon, stringLen)) != 0) { SNMP_memory_free (newEntry); return (ERROR); } newEntry->viewType = viewType; EBufferInitialize (&newEntry->viewName); if ((EBufferAllocateLoad (BFL_IS_ALLOC, &newEntry->viewName, viewName, nameLen)) != 0) { EBufferClean (&newEntry->commOrCon); SNMP_memory_free (newEntry); return (ERROR); } newEntry->vsNum = vsNum; /* link newEntry into list */#if NAMING_SCOPE_DEBUG printf ("Linking into list... First: %p New entry: %p\n", viewListHead->first, newEntry);#endif /* NAMING_SCOPE_DEBUG */ newEntry->next = viewListHead->first; viewListHead->first = newEntry;#if NAMING_SCOPE_DEBUG printf ("Done! First: %p New entry->next %p\n", viewListHead->first, newEntry->next);#endif /* NAMING_SCOPE_DEBUG */ return (OK); }/****************************************************************************** * * viewDeregisterIntern - Internal funtcion to deregister a view * * This function removes a view, or viewType, from the list whose head is * <viewListHead>, which will either be the list for community strings or * context names. * * Note that if multi-instance is not installed then <vsNum> will be ignored. * * Parameters: * * <viewListHead> - head of view list * <commOrCon> - either community or context * <stringLen> - the length of <commOrCon> * <viewType> - type of view to deregister, get, set, get/set * <vsNum> - the vsnum associated with <communityString> * * RETURNS: OK or ERROR * */LOCAL STATUS viewDeregisterIntern ( VIEW_LIST_HEAD_T * viewListHead, bits8_t * commOrCon, bits32_t stringLen, bits8_t viewType, bits32_t vsNum ) { VIEW_LIST_T * current, * previous = NULL, ** lastMatch; if (viewListHead->listType == COMMUNITY_LIST) lastMatch = &communityStringLastMatch;#if INSTALL_ENVOY_SNMP_VERSION_3 else if (viewListHead->listType == CONTEXT_LIST) lastMatch = &contextNameLastMatch;#endif /* INSTALL_ENVOY_SNMP_VERSION_3 */ else { /* viewListHead not initialised! */#if NAMING_SCOPE_DEBUG printf ("\nUnknown list type!\n");#endif /* NAMING_SCOPE_DEBUG */ return (ERROR); } if (commOrCon != NULL) {#if NAMING_SCOPE_DEBUG printf ("Attempting to remove %s\n", commOrCon);#endif /* NAMING_SCOPE_DEBUG */ /* remove view that matches commOrCon */ for (current = viewListHead->first; current != NULL; current = current->next) { if ((stringLen == EBufferUsed (¤t->commOrCon)) && (memcmp (commOrCon, EBufferStart (¤t->commOrCon), stringLen) == 0)) { /* found view */ current->viewType &= ~viewType; if (current->viewType != 0) {#if NAMING_SCOPE_DEBUG printf ("Only removing view type %d from %s\n", viewType, commOrCon);#endif /* NAMING_SCOPE_DEBUG */ /* * only deregister the type specified by viewType, this * commOrCon string is also used for other view types so * don't remove the entry. */ return (OK); } if (previous == NULL) viewListHead->first = current->next; else previous->next = current->next;#if NAMING_SCOPE_DEBUG printf ("Removed %s view\n", commOrCon);#endif /* NAMING_SCOPE_DEBUG */ if (current == *lastMatch) *lastMatch = NULL; EBufferClean (¤t->viewName); EBufferClean (¤t->commOrCon); SNMP_memory_free (current); return (OK); } previous = current; } /* view not found, return ERROR */#if NAMING_SCOPE_DEBUG printf ("%s view not found!\n", commOrCon);#endif /* NAMING_SCOPE_DEBUG */ return (ERROR); } else /* commOrCon == NULL */ { /* remove all views for VS vsNum */ VIEW_LIST_T * currentNext;#if NAMING_SCOPE_DEBUG printf ("Attempting to remove all views for VS%d\n", vsNum);#endif /* NAMING_SCOPE_DEBUG */ for (current = viewListHead->first; current != NULL; current = currentNext) { if (current->vsNum == vsNum) { /* found view for VS vsNum */#if NAMING_SCOPE_DEBUG char * tmpViewString;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -