00001
00002
00003
00004 #include <netinet/in.h>
00005
00006 #ifdef IN_UCD_SNMP_SOURCE
00007
00008
00009
00010
00011 #include <config.h>
00012
00013
00014
00015 #include "mibincl.h"
00016 #include "util_funcs.h"
00017
00018
00019 #else
00020
00021
00022 #include <ucd-snmp/ucd-snmp-config.h>
00023 #include <ucd-snmp/ucd-snmp-includes.h>
00024 #include <ucd-snmp/ucd-snmp-agent-includes.h>
00025
00026
00027 #endif
00028
00029
00030 #include "RMWatermarkConfig.h"
00031
00032 #include "rmClient.h"
00033 #include "utility.h"
00034
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <ucd-snmp/util_funcs.h>
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 oid RMWatermarkConfig_variables_oid[] = { 1,3,6,1,4,1,343,2,15,1,2,2,3 };
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 struct variable4 RMWatermarkConfig_variables[] = {
00059
00060 #define WATERMARKCONFIGNEXTINDEX 1
00061 { WATERMARKCONFIGNEXTINDEX, ASN_UNSIGNED , RONLY , var_RMWatermarkConfig, 1, { 1 } },
00062 #define WATERMARKTYPE 5
00063 { WATERMARKTYPE , ASN_INTEGER , RWRITE, var_WatermarkConfigTable, 3, { 2,1,2 } },
00064 #define WATERMARKCONFIGREFCOUNT 7
00065 { WATERMARKCONFIGREFCOUNT, ASN_INTEGER , RONLY , var_WatermarkConfigTable, 3, { 2,1,3 } },
00066 #define WATERMARKCONFIGSTATUS 8
00067 { WATERMARKCONFIGSTATUS, ASN_INTEGER , RWRITE, var_WatermarkConfigTable, 3, { 2,1,4 } },
00068
00069 };
00070
00071
00072
00073
00074
00075
00076
00077
00078 void init_RMWatermarkConfig(void) {
00079
00080
00081
00082 REGISTER_MIB("RMWatermarkConfig", RMWatermarkConfig_variables, variable4,
00083 RMWatermarkConfig_variables_oid);
00084
00085
00086
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 unsigned char *
00103 var_RMWatermarkConfig(struct variable *vp,
00104 oid *name,
00105 size_t *length,
00106 int exact,
00107 size_t *var_len,
00108 WriteMethod **write_method)
00109 {
00110
00111
00112
00113 static u_long ulong_ret;
00114
00115 if (header_generic(vp,name,length,exact,var_len,write_method)
00116 == MATCH_FAILED )
00117 return NULL;
00118
00119
00120
00121
00122
00123 switch(vp->magic) {
00124
00125
00126 case WATERMARKCONFIGNEXTINDEX:
00127
00128 ulong_ret = getNewId(WATERMARKCONFIG);
00129 return (unsigned char *) &ulong_ret;
00130
00131
00132 default:
00133 ERROR_MSG("");
00134 }
00135 return NULL;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144 unsigned char *
00145 var_WatermarkConfigTable(struct variable *vp,
00146 oid *name,
00147 size_t *length,
00148 int exact,
00149 size_t *var_len,
00150 WriteMethod **write_method)
00151 {
00152
00153
00154
00155 static long long_ret;
00156
00157 unsigned long id;
00158
00159 id = header_MyGeneric(vp,name,length,exact,var_len,write_method, WATERMARKCONFIG);
00160 if(id == 0) {
00161 switch(vp->magic) {
00162
00163
00164 case WATERMARKTYPE:
00165 *write_method = write_watermarkType;
00166 break;
00167
00168 case WATERMARKCONFIGSTATUS:
00169 *write_method = write_watermarkConfigStatus;
00170 break;
00171
00172
00173 default:
00174 ERROR_MSG("");
00175 }
00176
00177 return NULL;
00178 }
00179
00180
00181
00182
00183
00184
00185 switch(vp->magic) {
00186
00187
00188 case WATERMARKTYPE:
00189 *write_method = write_watermarkType;
00190 long_ret = 0;
00191 getInteger32(WATERMARKCONFIG, WATERMARKCONFIG_TYPE, id, &long_ret);
00192 return (unsigned char *) &long_ret;
00193
00194 case WATERMARKCONFIGREFCOUNT:
00195
00196 long_ret = 0;
00197 getInteger32(WATERMARKCONFIG, WATERMARKCONFIG_REFCOUNT, id, &long_ret);
00198 return (unsigned char *) &long_ret;
00199
00200 case WATERMARKCONFIGSTATUS:
00201 *write_method = write_watermarkConfigStatus;
00202 long_ret = 0;
00203 getInteger32(WATERMARKCONFIG, WATERMARKCONFIG_STATUS, id, &long_ret);
00204 return (unsigned char *) &long_ret;
00205
00206
00207 default:
00208 ERROR_MSG("");
00209 }
00210 return NULL;
00211 }
00212
00213
00214
00215
00216 int
00217 write_watermarkType(int action,
00218 u_char *var_val,
00219 u_char var_val_type,
00220 size_t var_val_len,
00221 u_char *statP,
00222 oid *name,
00223 size_t name_len)
00224 {
00225 static long *long_ret;
00226 int size;
00227
00228 int createNew, ret;
00229 unsigned long id;
00230 size_t prefix_len;
00231
00232 static long oldVal;
00233
00234 oid suffix[] = { 2, 1, 2 };
00235 createNew = 0;
00236 prefix_len = sizeof(RMWatermarkConfig_variables_oid)/sizeof(oid);
00237
00238 id = header_writeGeneric(name, name_len, RMWatermarkConfig_variables_oid, prefix_len, suffix, 3, WATERMARKCONFIG, &createNew);
00239
00240 if(id == 0 || (createNew && action == ACTION))
00241 return SNMP_ERR_NOSUCHNAME;
00242
00243
00244 switch ( action ) {
00245 case RESERVE1:
00246 if (var_val_type != ASN_INTEGER){
00247 fprintf(stderr, "write to watermarkType not ASN_INTEGER\n");
00248 return SNMP_ERR_WRONGTYPE;
00249 }
00250 if (var_val_len > sizeof(long_ret)){
00251 fprintf(stderr,"write to watermarkType: bad length\n");
00252 return SNMP_ERR_WRONGLENGTH;
00253 }
00254 break;
00255
00256
00257 case RESERVE2:
00258 size = var_val_len;
00259 long_ret = (long *) var_val;
00260
00261 if(!createNew) {
00262 ret = getInteger32(WATERMARKCONFIG, WATERMARKCONFIG_TYPE, id, &oldVal);
00263 if(ret)
00264 return SNMP_ERR_INCONSISTENTVALUE;
00265 }
00266
00267
00268 break;
00269
00270
00271 case FREE:
00272
00273 break;
00274
00275
00276 case ACTION:
00277
00278
00279
00280 ret = setInteger32(WATERMARKCONFIG, WATERMARKCONFIG_TYPE, id, *long_ret);
00281 if(ret)
00282 return SNMP_ERR_INCONSISTENTVALUE;
00283
00284 case UNDO:
00285
00286 setInteger32(WATERMARKCONFIG, WATERMARKCONFIG_TYPE, id, oldVal);
00287 break;
00288
00289
00290 case COMMIT:
00291
00292
00293 break;
00294 }
00295 return SNMP_ERR_NOERROR;
00296 }
00297
00298
00299
00300
00301 int
00302 write_watermarkConfigStatus(int action,
00303 u_char *var_val,
00304 u_char var_val_type,
00305 size_t var_val_len,
00306 u_char *statP,
00307 oid *name,
00308 size_t name_len)
00309 {
00310 static long *long_ret;
00311 int size;
00312
00313
00314 int createNew, ret;
00315 unsigned long id;
00316 size_t prefix_len;
00317
00318 static long oldStatus;
00319 static int rowCreated;
00320
00321 oid suffix[] = { 2, 1, 4 };
00322 createNew = 0;
00323 prefix_len = sizeof(RMWatermarkConfig_variables_oid)/sizeof(oid);
00324
00325 id = header_writeGeneric(name, name_len, RMWatermarkConfig_variables_oid, prefix_len, suffix, 3, WATERMARKCONFIG, &createNew);
00326
00327 if(action == COMMIT && *long_ret == DESTROY && id == 0)
00328 return SNMP_ERR_NOERROR;
00329
00330 if(id == 0)
00331 return SNMP_ERR_NOSUCHNAME;
00332
00333
00334 switch ( action ) {
00335 case RESERVE1:
00336 if (var_val_type != ASN_INTEGER){
00337 fprintf(stderr, "write to watermarkConfigStatus not ASN_INTEGER\n");
00338 return SNMP_ERR_WRONGTYPE;
00339 }
00340 if (var_val_len > sizeof(long_ret)){
00341 fprintf(stderr,"write to watermarkConfigStatus: bad length\n");
00342 return SNMP_ERR_WRONGLENGTH;
00343 }
00344 break;
00345
00346
00347 case RESERVE2:
00348 size = var_val_len;
00349 long_ret = (long *) var_val;
00350
00351 rowCreated = 0;
00352 oldStatus = 0;
00353 if (*long_ret < ACTIVE || *long_ret > DESTROY ||
00354 *long_ret == NOTREADY)
00355 return SNMP_ERR_INCONSISTENTVALUE;
00356
00357 if(createNew &&
00358 (*long_ret != CREATEANDWAIT && *long_ret != CREATEANDGO))
00359 return SNMP_ERR_INCONSISTENTVALUE;
00360
00361 if (*long_ret == NOTINSERVICE || *long_ret == ACTIVE) {
00362 ret = getInteger32(WATERMARKCONFIG, WATERMARKCONFIG_STATUS, id, &oldStatus);
00363 if(ret)
00364 return SNMP_ERR_INCONSISTENTVALUE;
00365 }
00366
00367
00368 break;
00369
00370 case FREE:
00371
00372 break;
00373
00374
00375 case ACTION:
00376
00377
00378
00379 if(*long_ret == CREATEANDWAIT || *long_ret == CREATEANDGO) {
00380 ret = newEntry(WATERMARKCONFIG, id);
00381 if(ret)
00382 return SNMP_ERR_INCONSISTENTVALUE;
00383
00384 rowCreated = 1;
00385 }
00386 else if (*long_ret == NOTINSERVICE || *long_ret == ACTIVE) {
00387 ret = setInteger32(WATERMARKCONFIG, WATERMARKCONFIG_STATUS, id, *long_ret);
00388 if(ret)
00389 return SNMP_ERR_INCONSISTENTVALUE;
00390 }
00391 else if(*long_ret == DESTROY) {
00392 ret = deleteEntry(WATERMARKCONFIG, id);
00393 if(ret)
00394 return SNMP_ERR_INCONSISTENTVALUE;
00395 }
00396
00397 break;
00398
00399
00400 case UNDO:
00401
00402 if(rowCreated) {
00403 deleteEntry(WATERMARKCONFIG, id);
00404 }
00405 else if(*long_ret == NOTINSERVICE || *long_ret == ACTIVE) {
00406 if(oldStatus != 0)
00407 setInteger32(WATERMARKCONFIG, WATERMARKCONFIG_STATUS, id, oldStatus);
00408 }
00409 else if((*long_ret == DESTROY)) {
00410
00411
00412
00413 }
00414
00415 break;
00416
00417
00418 case COMMIT:
00419
00420
00421 if(*long_ret == CREATEANDGO) {
00422 ret = setInteger32(WATERMARKCONFIG, WATERMARKCONFIG_STATUS, id, ACTIVE);
00423 if(ret) {
00424 deleteEntry(WATERMARKCONFIG, id);
00425 return SNMP_ERR_COMMITFAILED;
00426 }
00427 }
00428
00429 break;
00430 }
00431 return SNMP_ERR_NOERROR;
00432 }
00433
00434
00435
00436
00437
00438