00001 #include "utility.h"
00002
00003 #include <string.h>
00004
00005 unsigned long
00006 header_MyGeneric(struct variable * vp,
00007 oid * name,
00008 size_t * length,
00009 int exact,
00010 size_t * var_len,
00011 WriteMethod * *write_method,
00012 int aEntity)
00013 {
00014 oid newname[MAX_OID_LEN];
00015 unsigned long id=0, nid;
00016 int ret;
00017
00018
00019
00020
00021
00022
00023 *write_method = 0;
00024 *var_len = sizeof(long);
00025
00026 memcpy( (char *)newname,(char *)vp->name, vp->namelen * sizeof(oid));
00027 ret = snmp_oid_compare(name, *length-1, newname, vp->namelen);
00028 if(ret > 0 || (exact && ret != 0))
00029 return 0;
00030
00031
00032
00033
00034
00035
00036
00037 if(exact) {
00038
00039 id = name[*length - 1];
00040 ret = findId(aEntity, id);
00041 if(ret)
00042 return 0;
00043
00044 } else {
00045
00046 if(ret == 0)
00047 id = name[*length - 1];
00048 else
00049 id = 0;
00050
00051 ret = getNextId(aEntity, id, &nid);
00052 if(ret)
00053 return 0;
00054
00055 id = nid;
00056 newname[vp->namelen] = id;
00057
00058 memcpy( (char *)name,(char *)newname, (vp->namelen + 1) * sizeof(oid));
00059 *length = vp->namelen + 1;
00060 }
00061
00062 return id;
00063 }
00064
00065 unsigned long
00066 header_resourceInfo(struct variable * vp,
00067 oid * name,
00068 size_t * length,
00069 int exact,
00070 size_t * var_len,
00071 WriteMethod * *write_method)
00072 {
00073 oid newname[MAX_OID_LEN];
00074 unsigned long id=0, nid, rid=0;
00075 int ret, setlowname = 0;
00076
00077 unsigned long resid, subid;
00078 oid lowname[MAX_OID_LEN];
00079
00080
00081
00082
00083
00084
00085 *write_method = 0;
00086 *var_len = sizeof(long);
00087
00088 memcpy( (char *)newname,(char *)vp->name, vp->namelen * sizeof(oid));
00089
00090 while(!getNextId(RESORUCEINFO, id, &nid)) {
00091 id = nid;
00092
00093 getUnsigned(RESORUCEINFO, RESOURCEINFO_SUBSYSTEMID, id, &subid);
00094 getUnsigned(RESORUCEINFO, RESOURCEINFO_RESOURCEID, id, &resid);
00095
00096 newname[vp->namelen] = subid;
00097 newname[vp->namelen + 1] = resid;
00098
00099 ret = snmp_oid_compare(name, *length, newname, vp->namelen + 2);
00100 if(exact && (ret == 0)) {
00101 rid = id;
00102 break;
00103 }
00104 if(!exact && (ret < 0)) {
00105 if(!setlowname) {
00106 memcpy( (char *)lowname,(char *)newname, (vp->namelen + 2) * sizeof(oid));
00107 setlowname = 1;
00108 rid = id;
00109 }
00110 else {
00111 ret = snmp_oid_compare(lowname, vp->namelen + 2, newname, vp->namelen + 3);
00112 if(ret > 0) {
00113 memcpy( (char *)lowname,(char *)newname, (vp->namelen + 2) * sizeof(oid));
00114 rid = id;
00115 }
00116 }
00117 }
00118 }
00119
00120 if(!exact) {
00121
00122 memcpy( (char *)name,(char *)lowname, (vp->namelen + 2) * sizeof(oid));
00123 *length = vp->namelen + 2;
00124 }
00125
00126 return rid;
00127 }
00128
00129
00130 unsigned long
00131 header_statisticInfo(struct variable * vp,
00132 oid * name,
00133 size_t * length,
00134 int exact,
00135 size_t * var_len,
00136 WriteMethod * *write_method)
00137 {
00138 oid newname[MAX_OID_LEN];
00139 unsigned long id=0, nid, rid=0;
00140 int ret, setlowname = 0;
00141
00142 unsigned long resid, subid, statid;
00143 oid lowname[MAX_OID_LEN];
00144
00145
00146
00147
00148
00149
00150 *write_method = 0;
00151 *var_len = sizeof(long);
00152
00153 memcpy( (char *)newname,(char *)vp->name, vp->namelen * sizeof(oid));
00154
00155 while(!getNextId(STATISTICINFO, id, &nid)) {
00156 id = nid;
00157
00158 getUnsigned(STATISTICINFO, STATISTICINFO_SUBSYSTEMID, id, &subid);
00159 getUnsigned(STATISTICINFO, STATISTICINFO_RESOURCEID, id, &resid);
00160 getUnsigned(STATISTICINFO, STATISTICINFO_ID, id, &statid);
00161
00162 newname[vp->namelen] = subid;
00163 newname[vp->namelen + 1] = resid;
00164 newname[vp->namelen + 2] = statid;
00165
00166 ret = snmp_oid_compare(name, *length, newname, vp->namelen + 3);
00167 if(exact && (ret == 0)) {
00168 rid = id;
00169 break;
00170 }
00171 if(!exact && (ret < 0)) {
00172 if(!setlowname) {
00173 memcpy( (char *)lowname,(char *)newname, (vp->namelen + 3) * sizeof(oid));
00174 setlowname = 1;
00175 rid = id;
00176 }
00177 else {
00178 ret = snmp_oid_compare(lowname, vp->namelen + 3, newname, vp->namelen + 3);
00179 if(ret > 0) {
00180 memcpy( (char *)lowname,(char *)newname, (vp->namelen + 3) * sizeof(oid));
00181 rid = id;
00182 }
00183 }
00184 }
00185 }
00186
00187 if(!exact) {
00188
00189 memcpy( (char *)name,(char *)lowname, (vp->namelen + 3) * sizeof(oid));
00190 *length = vp->namelen + 3;
00191 }
00192
00193 return rid;
00194 }
00195
00196
00197
00198 unsigned long
00199 getHigh32(const u_int64_t value)
00200 {
00201 return (value & 0xFFFFFFFF00000000) >> 32;
00202 }
00203
00204 u_int64_t
00205 setHigh32(const u_int64_t orig, const unsigned long high32)
00206 {
00207 return (orig & 0x00000000FFFFFFFF) | (( (u_int64_t) high32 & 0x00000000FFFFFFFF) << 32) ;
00208 }
00209
00210
00211 unsigned long
00212 header_writeGeneric(oid * name,
00213 size_t name_len,
00214 oid * name_prefix,
00215 size_t prefix_len,
00216 oid * name_suffix,
00217 size_t suffix_len,
00218 int aEntity,
00219 int * createNew)
00220 {
00221 unsigned long id, nextid, i;
00222 int ret;
00223 size_t newlen ;
00224
00225 oid newname[MAX_OID_LEN];
00226
00227 *createNew = 0;
00228
00229 memcpy( (char*) newname, (char*) name_prefix, prefix_len * sizeof(oid) );
00230 newlen = prefix_len;
00231
00232 for(i=0; i<suffix_len; i++) {
00233 newname[newlen++] = name_suffix[i] ;
00234 }
00235
00236 ret = snmp_oid_compare(name, name_len-1, newname, newlen);
00237 if(ret != 0)
00238 return 0;
00239
00240 id = name[name_len -1];
00241
00242 nextid = getNewId(aEntity);
00243
00244 if(id == nextid) {
00245 *createNew = 1 ;
00246 return id;
00247 }
00248
00249 ret = findId(aEntity, id);
00250
00251 if(ret)
00252 return 0;
00253 else
00254 return id;
00255 }
00256
00257
00258