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 #include <string.h>
0035 #include <stdio.h>
0036 #include <stdlib.h>
0037 #include <memory.h>
0038 #include <errno.h>
0039 #include <dirent.h>
0040 #include <limits.h>
0041
0042 #include <ndrstandard.h>
0043 #include <ubfview.h>
0044 #include <ndebug.h>
0045
0046 #include <userlog.h>
0047 #include <view_cmn.h>
0048 #include <atmi_tls.h>
0049 #include <cf.h>
0050 #include "Exfields.h"
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068 expublic char * ndrx_Bvfind_int(char *cstruct, ndrx_typedview_t *v,
0069 ndrx_typedview_field_t *f, BFLDOCC occ, BFLDLEN *p_len)
0070 {
0071 int ret = EXSUCCEED;
0072 int dim_size = f->fldsize/f->count;
0073 char *fld_offs = cstruct+f->offset+occ*dim_size;
0074 char *cvn_buf;
0075 short *C_count;
0076 short C_count_stor;
0077 unsigned short *L_length;
0078 unsigned short L_length_stor;
0079
0080 UBF_LOG(log_debug, "%s enter, get %s.%s occ=%d", __func__,
0081 v->vname, f->cname, occ);
0082
0083 if (occ > f->count-1 || occ<0)
0084 {
0085 ndrx_Bset_error_fmt(BEINVAL, "Invalid occurrence requested for field "
0086 "%s.%s, count=%d occ=%d (zero base)",
0087 v->vname, f->cname, f->count, occ);
0088 fld_offs=NULL;
0089 goto out;
0090 }
0091
0092 NDRX_VIEW_COUNT_SETUP;
0093
0094
0095 NDRX_VIEW_LEN_SETUP(occ, dim_size);
0096
0097 *p_len = (BFLDLEN)*L_length;
0098 out:
0099 return fld_offs;
0100 }
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129 expublic char * ndrx_CBvget_int(char *cstruct, ndrx_typedview_t *v,
0130 ndrx_typedview_field_t *f, BFLDOCC occ, char *buf, BFLDLEN *len,
0131 int usrtype, long flags,
0132 int mode, int *extralen)
0133 {
0134 int ret = EXSUCCEED;
0135 int dim_size = f->fldsize/f->count;
0136 char *fld_offs = cstruct+f->offset+occ*dim_size;
0137 char *cvn_buf;
0138 short *C_count;
0139 short C_count_stor;
0140 unsigned short *L_length;
0141 unsigned short L_length_stor;
0142 char *allocbuf = NULL;
0143 BFLDLEN allocbuflen = 0;
0144
0145 UBF_LOG(log_debug, "%s enter, get %s.%s occ=%d", __func__,
0146 v->vname, f->cname, occ);
0147
0148 NDRX_VIEW_COUNT_SETUP;
0149
0150 if (flags & BVACCESS_NOTNULL)
0151 {
0152 if (ndrx_Bvnull_int(v, f, occ, cstruct))
0153 {
0154 UBF_LOG(log_debug, "Field is NULL");
0155 ndrx_Bset_error_fmt(BNOTPRES, "%s.%s occ=%d is NULL",
0156 v->vname, f->cname, occ);
0157 EXFAIL_OUT(ret);
0158 }
0159
0160 if (*C_count<occ+1)
0161 {
0162 UBF_LOG(log_debug, "%s.%s count field is set to %hu, "
0163 "but requesting occ=%d (zero based) - NOT PRES",
0164 v->vname, f->cname, *C_count, occ);
0165 ndrx_Bset_error_fmt(BNOTPRES, "%s.%s count field is set to %hu, "
0166 "but requesting occ=%d (zero based) - NOT PRES",
0167 v->vname, f->cname, *C_count, occ);
0168 EXFAIL_OUT(ret);
0169 }
0170 }
0171
0172
0173 NDRX_VIEW_LEN_SETUP(occ, dim_size);
0174
0175 if (CB_MODE_ALLOC==mode)
0176 {
0177
0178 if (NULL==(cvn_buf=ndrx_ubf_get_cbuf(f->typecode_full, usrtype,
0179 NULL, fld_offs, *L_length,
0180 &allocbuf,
0181 &allocbuflen,
0182 mode,
0183 (NULL!=extralen?*extralen:0))))
0184 {
0185 UBF_LOG(log_error, "%s: get_cbuf failed!", __func__);
0186
0187 ndrx_Bset_error_fmt(BMALLOC, "%s: get_cbuf failed!", __func__);
0188
0189 return NULL;
0190 }
0191
0192 buf = allocbuf;
0193 len = &allocbuflen;
0194 }
0195
0196 cvn_buf = ndrx_ubf_convert(f->typecode_full, CNV_DIR_OUT, fld_offs, *L_length,
0197 usrtype, buf, len);
0198 if (NULL==cvn_buf)
0199 {
0200 UBF_LOG(log_error, "%s: failed to convert data!", __func__);
0201
0202 EXFAIL_OUT(ret);
0203 }
0204
0205 if (NULL!=len && NULL!=extralen)
0206 {
0207 *extralen=*len;
0208 }
0209
0210 out:
0211 UBF_LOG(log_debug, "%s return %d %p", __func__, ret, buf);
0212
0213 if (EXSUCCEED!=ret)
0214 {
0215 if (NULL!=allocbuf)
0216 {
0217 NDRX_FREE(allocbuf);
0218 }
0219
0220 return NULL;
0221 }
0222
0223 return buf;
0224 }
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237 expublic int ndrx_CBvget(char *cstruct, char *view, char *cname, BFLDOCC occ,
0238 char *buf, BFLDLEN *len, int usrtype, long flags)
0239 {
0240 int ret = EXFALSE;
0241 ndrx_typedview_t *v = NULL;
0242 ndrx_typedview_field_t *f = NULL;
0243
0244
0245
0246 if (NULL==(v = ndrx_view_get_view(view)))
0247 {
0248 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0249 EXFAIL_OUT(ret);
0250 }
0251
0252 if (NULL==(f = ndrx_view_get_field(v, cname)))
0253 {
0254 ndrx_Bset_error_fmt(BNOCNAME, "Field [%s] of view [%s] not found!",
0255 cname, v->vname);
0256 EXFAIL_OUT(ret);
0257 }
0258
0259 if (occ > f->count-1 || occ<0)
0260 {
0261 ndrx_Bset_error_fmt(BEINVAL, "Invalid occurrence requested for field "
0262 "%s.%s, count=%d occ=%d (zero base)",
0263 v->vname, f->cname, f->count, occ);
0264 EXFAIL_OUT(ret);
0265 }
0266
0267 if (NULL==ndrx_CBvget_int(cstruct, v, f, occ, buf, len,
0268 usrtype, flags, CB_MODE_DEFAULT, NULL))
0269 {
0270
0271 UBF_LOG(log_error, "ndrx_CBvget_int failed");
0272 EXFAIL_OUT(ret);
0273 }
0274
0275 out:
0276
0277 return ret;
0278 }
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291 expublic char *ndrx_CBvgetalloc(char *cstruct, char *view, char *cname, BFLDOCC occ,
0292 int usrtype, long flags, BFLDLEN *extralen)
0293 {
0294 char *ret = NULL;
0295 ndrx_typedview_t *v = NULL;
0296 ndrx_typedview_field_t *f = NULL;
0297
0298
0299
0300 if (NULL==(v = ndrx_view_get_view(view)))
0301 {
0302 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0303 goto out;
0304 }
0305
0306 if (NULL==(f = ndrx_view_get_field(v, cname)))
0307 {
0308 ndrx_Bset_error_fmt(BNOCNAME, "Field [%s] of view [%s] not found!",
0309 cname, v->vname);
0310 goto out;
0311 }
0312
0313 if (occ > f->count-1 || occ<0)
0314 {
0315 ndrx_Bset_error_fmt(BEINVAL, "Invalid occurrence requested for field "
0316 "%s.%s, count=%d occ=%d (zero base)",
0317 v->vname, f->cname, f->count, occ);
0318 goto out;
0319 }
0320
0321 if (NULL==(ret=ndrx_CBvget_int(cstruct, v, f, occ, NULL, 0, usrtype,
0322 flags, CB_MODE_ALLOC, extralen)))
0323 {
0324
0325 UBF_LOG(log_error, "ndrx_CBvget_int failed");
0326 goto out;
0327 }
0328
0329 out:
0330
0331 return ret;
0332 }
0333
0334
0335
0336
0337
0338
0339
0340
0341
0342
0343
0344
0345
0346
0347
0348
0349
0350
0351
0352
0353
0354
0355
0356
0357
0358
0359
0360
0361 expublic int ndrx_CBvchg_int(char *cstruct, ndrx_typedview_t *v,
0362 ndrx_typedview_field_t *f, BFLDOCC occ, char *buf,
0363 BFLDLEN len, int usrtype)
0364 {
0365 int ret = EXSUCCEED;
0366 int dim_size = f->fldsize/f->count;
0367 char *fld_offs = cstruct+f->offset+occ*dim_size;
0368 char *cvn_buf;
0369 short *C_count;
0370 short C_count_stor;
0371 unsigned short *L_length;
0372 unsigned short L_length_stor;
0373
0374 BFLDLEN setlen;
0375 UBF_LOG(log_debug, "%s enter, get %s.%s occ=%d", __func__,
0376 v->vname, f->cname, occ);
0377
0378 NDRX_VIEW_COUNT_SETUP;
0379
0380
0381 NDRX_VIEW_LEN_SETUP(occ, dim_size);
0382
0383 setlen = dim_size;
0384
0385 cvn_buf = ndrx_ubf_convert(usrtype, CNV_DIR_OUT, buf, len,
0386 f->typecode_full, fld_offs, &setlen);
0387
0388 if (NULL==cvn_buf)
0389 {
0390 UBF_LOG(log_error, "%s: failed to convert data!", __func__);
0391
0392 EXFAIL_OUT(ret);
0393 }
0394
0395 if (occ+1 > *C_count)
0396 {
0397 *C_count = occ+1;
0398 }
0399
0400 *L_length = setlen;
0401
0402 out:
0403 UBF_LOG(log_debug, "%s return %d", __func__, ret);
0404
0405 return ret;
0406 }
0407
0408
0409
0410
0411
0412
0413
0414
0415
0416
0417
0418
0419 expublic int ndrx_CBvchg(char *cstruct, char *view, char *cname, BFLDOCC occ,
0420 char *buf, BFLDLEN len, int usrtype)
0421 {
0422 int ret = EXFALSE;
0423 ndrx_typedview_t *v = NULL;
0424 ndrx_typedview_field_t *f = NULL;
0425
0426
0427
0428 if (NULL==(v = ndrx_view_get_view(view)))
0429 {
0430 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0431 EXFAIL_OUT(ret);
0432 }
0433
0434 if (NULL==(f = ndrx_view_get_field(v, cname)))
0435 {
0436 ndrx_Bset_error_fmt(BNOCNAME, "Field [%s] of view [%s] not found!",
0437 cname, v->vname);
0438 EXFAIL_OUT(ret);
0439 }
0440
0441 if (occ > f->count-1 || occ<0)
0442 {
0443 ndrx_Bset_error_fmt(BEINVAL, "Invalid occurrence requested for field "
0444 "%s.%s, count=%d occ=%d (zero base)",
0445 v->vname, f->cname, f->count, occ);
0446 EXFAIL_OUT(ret);
0447 }
0448
0449 if (EXFAIL==(ret=ndrx_CBvchg_int(cstruct, v, f, occ, buf, len, usrtype)))
0450 {
0451
0452 UBF_LOG(log_error, "ndrx_CBvchg_int failed");
0453 EXFAIL_OUT(ret);
0454 }
0455
0456 out:
0457 return ret;
0458 }
0459
0460
0461
0462
0463
0464
0465
0466
0467
0468 expublic long ndrx_Bvsizeof(char *view)
0469 {
0470 long ret;
0471
0472 ndrx_typedview_t *v = NULL;
0473
0474 if (NULL==(v = ndrx_view_get_view(view)))
0475 {
0476 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0477 EXFAIL_OUT(ret);
0478 }
0479
0480 ret = v->ssize;
0481
0482 out:
0483 return ret;
0484 }
0485
0486
0487
0488
0489
0490
0491
0492
0493
0494 expublic long ndrx_Bvcpy(char *cstruct_dst, char *cstruct_src, char *view)
0495 {
0496 long ret;
0497
0498 ndrx_typedview_t *v = NULL;
0499
0500 if (NULL==(v = ndrx_view_get_view(view)))
0501 {
0502 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0503 EXFAIL_OUT(ret);
0504 }
0505
0506 ret = v->ssize;
0507
0508 memcpy(cstruct_dst, cstruct_src, ret);
0509
0510 out:
0511 return ret;
0512 }
0513
0514
0515
0516
0517
0518
0519
0520
0521
0522
0523
0524
0525
0526
0527
0528
0529
0530
0531
0532
0533
0534 expublic BFLDOCC ndrx_Bvoccur_int(char *cstruct, ndrx_typedview_t *v,
0535 ndrx_typedview_field_t *f, BFLDOCC *maxocc, BFLDOCC *realocc,
0536 long *dim_size, int *fldtype)
0537 {
0538 BFLDOCC ret;
0539 short *C_count;
0540 short C_count_stor;
0541 int i;
0542
0543 NDRX_VIEW_COUNT_SETUP;
0544
0545 if (NULL!=maxocc)
0546 {
0547 *maxocc=f->count;
0548 }
0549
0550 ret = *C_count;
0551
0552 if (NULL!=realocc)
0553 {
0554
0555 for (i=ret-1; i>=0; i--)
0556 {
0557 if (!ndrx_Bvnull_int(v, f, i, cstruct))
0558 {
0559 break;
0560 }
0561 }
0562 *realocc = i+1;
0563 }
0564
0565
0566 if (NULL!=dim_size)
0567 {
0568 *dim_size = f->fldsize/f->count;
0569 }
0570
0571 if (NULL!=fldtype)
0572 {
0573 *fldtype = f->typecode_full;
0574 }
0575
0576 out:
0577 UBF_LOG(log_debug, "%s returns %d maxocc=%d dim_size=%d realocc=%d", __func__,
0578 ret, maxocc?*maxocc:-1, dim_size?*dim_size:-1, realocc?*realocc:-1);
0579 return ret;
0580 }
0581
0582
0583
0584
0585
0586
0587
0588
0589
0590
0591
0592 expublic BFLDOCC ndrx_Bvoccur(char *cstruct, char *view, char *cname,
0593 BFLDOCC *maxocc, BFLDOCC *realocc, long *dim_size, int *fldtype)
0594 {
0595 BFLDOCC ret = EXSUCCEED;
0596 ndrx_typedview_t *v = NULL;
0597 ndrx_typedview_field_t *f = NULL;
0598
0599 if (NULL==(v = ndrx_view_get_view(view)))
0600 {
0601 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0602 EXFAIL_OUT(ret);
0603 }
0604
0605 if (NULL==(f = ndrx_view_get_field(v, cname)))
0606 {
0607 ndrx_Bset_error_fmt(BNOCNAME, "Field [%s] of view [%s] not found!",
0608 cname, v->vname);
0609 EXFAIL_OUT(ret);
0610 }
0611
0612 if (EXFAIL==(ret = ndrx_Bvoccur_int(cstruct, v, f, maxocc, realocc,
0613 dim_size, fldtype)))
0614 {
0615 UBF_LOG(log_error, "ndrx_Bvoccur_int failed");
0616 }
0617
0618 out:
0619 return ret;
0620 }
0621
0622
0623
0624
0625
0626
0627
0628
0629
0630
0631
0632
0633
0634
0635
0636
0637 expublic int ndrx_Bvsetoccur(char *cstruct, char *view, char *cname, BFLDOCC occ)
0638 {
0639 int ret = EXSUCCEED;
0640 ndrx_typedview_t *v = NULL;
0641 ndrx_typedview_field_t *f = NULL;
0642 short *C_count;
0643 short C_count_stor;
0644
0645 if (NULL==(v = ndrx_view_get_view(view)))
0646 {
0647 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0648 EXFAIL_OUT(ret);
0649 }
0650
0651 if (NULL==(f = ndrx_view_get_field(v, cname)))
0652 {
0653 ndrx_Bset_error_fmt(BNOCNAME, "Field [%s] of view [%s] not found!",
0654 cname, v->vname);
0655 EXFAIL_OUT(ret);
0656 }
0657
0658 if (occ>f->count || occ<0)
0659 {
0660 ndrx_Bset_error_fmt(BEINVAL, "%s: invalid occ %d max: %d, min: 0",
0661 __func__, occ, occ>f->count);
0662 EXFAIL_OUT(ret);
0663 }
0664
0665 NDRX_VIEW_COUNT_SETUP;
0666
0667 *C_count = occ;
0668
0669 out:
0670 return ret;
0671 }
0672
0673
0674
0675
0676
0677
0678
0679
0680
0681
0682
0683 expublic int ndrx_Bvnext (Bvnext_state_t *state, char *view, char *cname,
0684 int *fldtype, BFLDOCC *maxocc, long *dim_size)
0685 {
0686 int ret = EXSUCCEED;
0687 ndrx_typedview_t *v;
0688 ndrx_typedview_field_t *f;
0689
0690 v = (ndrx_typedview_t *) state->v;
0691 f = (ndrx_typedview_field_t *) state->vel;
0692
0693
0694 if (NULL!=view)
0695 {
0696 UBF_LOG(log_debug, "Starting to scan view: %s", view);
0697 memset(state, 0, sizeof(Bvnext_state_t));
0698
0699
0700 if (NULL==(v = ndrx_view_get_view(view)))
0701 {
0702 ndrx_Bset_error_fmt(BBADVIEW, "View [%s] not found!", view);
0703 EXFAIL_OUT(ret);
0704 }
0705
0706 f = v->fields;
0707
0708 if (NULL==f)
0709 {
0710 UBF_LOG(log_debug, "View scan EOF");
0711 ret = 0;
0712 goto out;
0713 }
0714
0715 }
0716 else
0717 {
0718
0719 f = f->next;
0720
0721 if (NULL==f)
0722 {
0723 UBF_LOG(log_debug, "View scan EOF");
0724 ret = 0;
0725 goto out;
0726 }
0727
0728 }
0729
0730 NDRX_STRCPY_SAFE_DST(cname, f->cname, (NDRX_VIEW_CNAME_LEN+1));
0731
0732 if (NULL!=fldtype)
0733 {
0734 *fldtype = f->typecode_full;
0735 }
0736
0737 ret = 1;
0738
0739 if (NULL!=dim_size)
0740 {
0741 *dim_size = f->fldsize/f->count;
0742 }
0743
0744 if (NULL!=maxocc)
0745 {
0746 *maxocc = f->count;
0747 }
0748
0749 out:
0750
0751
0752 state->v = v;
0753 state->vel = f;
0754
0755 if (ret > 0)
0756 {
0757 UBF_LOG(log_debug, "%s returns %d (%s.%s %d)", __func__,
0758 ret, v->vname, cname, fldtype?*fldtype:-1);
0759 }
0760 else
0761 {
0762 UBF_LOG(log_debug, "%s returns %d", __func__, ret);
0763 }
0764
0765 return ret;
0766 }
0767
0768