0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #include <string.h>
0038 #include <stdio.h>
0039 #include <stdlib.h>
0040 #include <memory.h>
0041 #include <errno.h>
0042
0043 #include <ubf.h>
0044 #include <ubf_int.h> /* Internal headers for UBF... */
0045 #include <fdatatype.h>
0046 #include <ferror.h>
0047 #include <fieldtable.h>
0048 #include <ndrstandard.h>
0049 #include <ndebug.h>
0050 #include <cf.h>
0051
0052 #include "userlog.h"
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071 expublic int ndrx_Bcmp(UBFH *p_ubf1, UBFH *p_ubf2)
0072 {
0073 int ret = EXSUCCEED;
0074 Bnext_state_t state1;
0075 Bnext_state_t state2;
0076 BFLDID bfldid1;
0077 BFLDOCC occ1;
0078
0079 BFLDID bfldid2;
0080 BFLDOCC occ2;
0081
0082 BFLDLEN len1;
0083 BFLDLEN len2;
0084
0085 int ret1;
0086 int ret2;
0087
0088 char *buf1;
0089 char *buf2;
0090
0091 dtype_ext1_t *typ;
0092 int typcode;
0093
0094 memset(&state1, 0, sizeof(state1));
0095 memset(&state2, 0, sizeof(state2));
0096
0097 bfldid1 = BFIRSTFLDID;
0098 bfldid2 = BFIRSTFLDID;
0099 while (1)
0100 {
0101 ret1=ndrx_Bnext(&state1, p_ubf1, &bfldid1, &occ1, NULL, &len1, &buf1);
0102 ret2=ndrx_Bnext(&state2, p_ubf2, &bfldid2, &occ2, NULL, &len2, &buf2);
0103
0104 if (EXFAIL==ret1)
0105 {
0106
0107 UBF_LOG(log_debug, "buffer1 Bnext failed");
0108 ret=-2;
0109 goto out;
0110 }
0111
0112 if (EXFAIL==ret2)
0113 {
0114
0115 UBF_LOG(log_debug, "buffer2 Bnext failed");
0116 ret=-2;
0117 goto out;
0118 }
0119
0120 if (EXTRUE!=ret1 && EXTRUE!=ret2)
0121 {
0122 UBF_LOG(log_debug, "EOF reached buffers %p vs %p equal",
0123 p_ubf1, p_ubf2);
0124
0125 ret = 0;
0126 goto out;
0127 }
0128 else if (EXTRUE!=ret1 && EXTRUE==ret2)
0129 {
0130 ret=-1;
0131 goto out;
0132 }
0133 else if (EXTRUE==ret1 && EXTRUE!=ret2)
0134 {
0135 ret=1;
0136 goto out;
0137 }
0138
0139 else if (bfldid1 < bfldid2)
0140 {
0141 ret=-1;
0142 goto out;
0143 }
0144 else if (bfldid1 > bfldid2)
0145 {
0146 ret=1;
0147 goto out;
0148 }
0149
0150
0151
0152 typcode = Bfldtype(bfldid1);
0153
0154 if (typcode > BFLD_MAX || typcode < BFLD_MIN)
0155 {
0156 ret=-2;
0157 userlog("Invalid type id found in buffer %p: %d - corrupted UBF buffer?",
0158 p_ubf1, typcode);
0159 UBF_LOG(log_error, "Invalid type id found in buffer %p: %d "
0160 "- corrupted UBF buffer?", p_ubf1, typcode);
0161
0162 ndrx_Bset_error_fmt(BNOTFLD, "Invalid type id found in buffer %p: %d "
0163 "- corrupted UBF buffer?", p_ubf1, typcode);
0164
0165 goto out;
0166 }
0167
0168 typ = &G_dtype_ext1_map[typcode];
0169
0170 ret = typ->p_cmp(typ, buf1, len1, buf2, len2, UBF_CMP_MODE_STD);
0171
0172 if (ret < 0)
0173 {
0174
0175 ret = -1;
0176 goto out;
0177 }
0178 else if (ret > 0)
0179 {
0180 ret = 1;
0181 goto out;
0182 }
0183 }
0184
0185 out:
0186
0187 return ret;
0188 }
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198 expublic int ndrx_Bsubset(UBFH *p_ubf1, UBFH *p_ubf2, int level)
0199 {
0200
0201
0202
0203 int ret = EXSUCCEED;
0204 Bnext_state_t state2;
0205
0206 BFLDID bfldid2;
0207 BFLDOCC occ2;
0208
0209 BFLDLEN len1;
0210 BFLDLEN len2;
0211
0212 char *buf1 = NULL;
0213 char *buf2 = NULL;
0214
0215 int ret2;
0216
0217 dtype_ext1_t *typ;
0218 int typcode;
0219
0220 UBF_LOG(log_debug, "Matching %p vs %p at level %d", p_ubf1, p_ubf2, level);
0221
0222 memset(&state2, 0, sizeof(state2));
0223
0224 bfldid2 = BFIRSTFLDID;
0225 while (1)
0226 {
0227 ret2=ndrx_Bnext(&state2, p_ubf2, &bfldid2, &occ2, NULL, &len2, &buf2);
0228
0229 if (0==ret2)
0230 {
0231
0232 ret=EXTRUE;
0233 goto out;
0234 }
0235 else if (EXFAIL==ret2)
0236 {
0237
0238 EXFAIL_OUT(ret);
0239 }
0240
0241
0242
0243 buf1=ndrx_Bfind(p_ubf1, bfldid2, occ2, &len1, NULL);
0244
0245 if (NULL==buf1)
0246 {
0247 if (BNOTPRES!=Berror)
0248 {
0249 UBF_LOG(log_error, "Failed to get [%d] occ [%d] from haystack buffer",
0250 bfldid2, occ2);
0251 EXFAIL_OUT(ret);
0252 }
0253
0254 ndrx_Bunset_error();
0255
0256 ret = EXFALSE;
0257 goto out;
0258 }
0259
0260
0261
0262 typcode = Bfldtype(bfldid2);
0263
0264 if (typcode > BFLD_MAX || typcode < BFLD_MIN)
0265 {
0266 ret=-1;
0267 userlog("Invalid type id found in buffer %p: %d - corrupted UBF buffer?",
0268 p_ubf1, typcode);
0269 UBF_LOG(log_error, "Invalid type id found in buffer %p: %d "
0270 "- corrupted UBF buffer?", p_ubf1, typcode);
0271
0272 ndrx_Bset_error_fmt(BNOTFLD, "Invalid type id found in buffer %p: %d "
0273 "- corrupted UBF buffer?", p_ubf1, typcode);
0274
0275 goto out;
0276 }
0277
0278
0279
0280 if (typcode==BFLD_UBF)
0281 {
0282 UBF_LOG(log_debug, "Stepping into UBF for UBF fldid %d", bfldid2);
0283 ret=ndrx_Bsubset((UBFH *)buf1, (UBFH *)buf2, level+1);
0284 }
0285 else
0286 {
0287 typ = &G_dtype_ext1_map[typcode];
0288 ret=typ->p_cmp(typ, buf1, len1, buf2, len2, 0);
0289 }
0290
0291 if (EXFALSE==ret)
0292 {
0293 UBF_LOG(log_debug, "fields are different, not a subset");
0294 ret=EXFALSE;
0295 goto out;
0296 }
0297 else if (EXFAIL==ret)
0298 {
0299 UBF_LOG(log_error, "error comparing fields");
0300 ret=-1;
0301 goto out;
0302 }
0303 }
0304
0305 out:
0306 return ret;
0307 }
0308
0309