00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <sys/types.h>
00035
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <memdebug.h>
00039
00040 #include <pro/snmp_config.h>
00041
00042 static VIEW_LIST *views;
00043 static COMMUNITY_LIST *communities;
00044
00051 int SnmpViewCreate(CONST char *name, CONST OID * subtree, size_t subtreelen, int type)
00052 {
00053 static int nextview = 1;
00054 VIEW_LIST *vp;
00055 VIEW_LIST *nvp;
00056 VIEW_LIST *prev = NULL;
00057 size_t i;
00058
00059
00060 if (strlen(name) > (sizeof(vp->view_name) - 1)) {
00061 return -1;
00062 }
00063
00064
00065 for (vp = views; vp; prev = vp, vp = vp->next) {
00066 if (strcmp(name, vp->view_name) == 0) {
00067 break;
00068 }
00069 }
00070
00071
00072 nvp = malloc(sizeof(VIEW_LIST));
00073 memset(nvp, 0, sizeof(VIEW_LIST));
00074 strcpy(nvp->view_name, name);
00075 nvp->view_type = type;
00076 nvp->view_subtree_len = subtreelen;
00077 for (i = 0; i < subtreelen; i++) {
00078 nvp->view_subtree[i] = subtree[i];
00079 }
00080
00081 nvp->view_index = vp ? vp->view_index : nextview++;
00082
00083
00084 if (views) {
00085 for (; vp; prev = vp, vp = vp->next);
00086 prev->next = nvp;
00087 } else {
00088 views = nvp;
00089 }
00090 return nvp->view_index;
00091 }
00092
00093 int SnmpViewFind(char *name)
00094 {
00095 VIEW_LIST *vp;
00096
00097 if (strcmp(name, "-") == 0) {
00098 return 0;
00099 }
00100 for (vp = views; vp; vp = vp->next) {
00101 if (strcmp(vp->view_name, name) == 0) {
00102 return vp->view_index;
00103 }
00104 }
00105 return -1;
00106 }
00107
00119 int SnmpCommunityFind(CONST char *name, int *readView, int *writeView)
00120 {
00121 COMMUNITY_LIST *cp;
00122
00123 for (cp = communities; cp; cp = cp->next) {
00124 if (strcmp(cp->comm_name, name) == 0) {
00125 if (readView) {
00126 *readView = cp->comm_read_view;
00127 }
00128 if (writeView) {
00129 *writeView = cp->comm_write_view;
00130 }
00131 return 0;
00132 }
00133 }
00134 return -1;
00135 }
00136
00148 int SnmpCommunityCreate(CONST char *name, int readView, int writeView)
00149 {
00150 COMMUNITY_LIST *cp;
00151 COMMUNITY_LIST *prev = 0;
00152
00153 if (strlen(name) > (sizeof(cp->comm_name) - 1)) {
00154 return -1;
00155 }
00156 for (cp = communities; cp; cp = cp->next) {
00157 if (strcmp(name, cp->comm_name) == 0) {
00158 return 0;
00159 }
00160 prev = cp;
00161 }
00162
00163 cp = malloc(sizeof(COMMUNITY_LIST));
00164 memset(cp, 0, sizeof(COMMUNITY_LIST));
00165 strcpy(cp->comm_name, name);
00166 cp->comm_read_view = readView;
00167 cp->comm_write_view = writeView;
00168 if (prev) {
00169 prev->next = cp;
00170 } else {
00171 communities = cp;
00172 }
00173 return 0;
00174 }