Go to the documentation of this file.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
00046
00047 static VIEW_LIST *views;
00048 static COMMUNITY_LIST *communities;
00049
00056 int SnmpViewCreate(CONST char *name, CONST OID * subtree, size_t subtreelen, int type)
00057 {
00058 static int nextview = 1;
00059 VIEW_LIST *vp;
00060 VIEW_LIST *nvp;
00061 VIEW_LIST *prev = NULL;
00062 size_t i;
00063
00064
00065 if (strlen(name) > (sizeof(vp->view_name) - 1)) {
00066 return -1;
00067 }
00068
00069
00070 for (vp = views; vp; prev = vp, vp = vp->next) {
00071 if (strcmp(name, vp->view_name) == 0) {
00072 break;
00073 }
00074 }
00075
00076
00077 nvp = malloc(sizeof(VIEW_LIST));
00078 memset(nvp, 0, sizeof(VIEW_LIST));
00079 strcpy(nvp->view_name, name);
00080 nvp->view_type = type;
00081 nvp->view_subtree_len = subtreelen;
00082 for (i = 0; i < subtreelen; i++) {
00083 nvp->view_subtree[i] = subtree[i];
00084 }
00085
00086 nvp->view_index = vp ? vp->view_index : nextview++;
00087
00088
00089 if (views) {
00090 for (; vp; prev = vp, vp = vp->next);
00091 prev->next = nvp;
00092 } else {
00093 views = nvp;
00094 }
00095 return nvp->view_index;
00096 }
00097
00098 int SnmpViewFind(char *name)
00099 {
00100 VIEW_LIST *vp;
00101
00102 if (strcmp(name, "-") == 0) {
00103 return 0;
00104 }
00105 for (vp = views; vp; vp = vp->next) {
00106 if (strcmp(vp->view_name, name) == 0) {
00107 return vp->view_index;
00108 }
00109 }
00110 return -1;
00111 }
00112
00124 int SnmpCommunityFind(CONST char *name, int *readView, int *writeView)
00125 {
00126 COMMUNITY_LIST *cp;
00127
00128 for (cp = communities; cp; cp = cp->next) {
00129 if (strcmp(cp->comm_name, name) == 0) {
00130 if (readView) {
00131 *readView = cp->comm_read_view;
00132 }
00133 if (writeView) {
00134 *writeView = cp->comm_write_view;
00135 }
00136 return 0;
00137 }
00138 }
00139 return -1;
00140 }
00141
00153 int SnmpCommunityCreate(CONST char *name, int readView, int writeView)
00154 {
00155 COMMUNITY_LIST *cp;
00156 COMMUNITY_LIST *prev = 0;
00157
00158 if (strlen(name) > (sizeof(cp->comm_name) - 1)) {
00159 return -1;
00160 }
00161 for (cp = communities; cp; cp = cp->next) {
00162 if (strcmp(name, cp->comm_name) == 0) {
00163 return 0;
00164 }
00165 prev = cp;
00166 }
00167
00168 cp = malloc(sizeof(COMMUNITY_LIST));
00169 memset(cp, 0, sizeof(COMMUNITY_LIST));
00170 strcpy(cp->comm_name, name);
00171 cp->comm_read_view = readView;
00172 cp->comm_write_view = writeView;
00173 if (prev) {
00174 prev->next = cp;
00175 } else {
00176 communities = cp;
00177 }
00178 return 0;
00179 }
00180