Back to home page

Enduro/X

 
 

    


0001 /**
0002  * @brief VIEW Support structures
0003  *
0004  * @file ubfview.h
0005  */
0006 /* -----------------------------------------------------------------------------
0007  * Enduro/X Middleware Platform for Distributed Transaction Processing
0008  * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved.
0009  * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved.
0010  * This software is released under one of the following licenses:
0011  * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use.
0012  * See LICENSE file for full text.
0013  * -----------------------------------------------------------------------------
0014  * AGPL license:
0015  *
0016  * This program is free software; you can redistribute it and/or modify it under
0017  * the terms of the GNU Affero General Public License, version 3 as published
0018  * by the Free Software Foundation;
0019  *
0020  * This program is distributed in the hope that it will be useful, but WITHOUT ANY
0021  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
0022  * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3
0023  * for more details.
0024  *
0025  * You should have received a copy of the GNU Affero General Public License along 
0026  * with this program; if not, write to the Free Software Foundation, Inc.,
0027  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
0028  *
0029  * -----------------------------------------------------------------------------
0030  * A commercial use license is available from Mavimax, Ltd
0031  * contact@mavimax.com
0032  * -----------------------------------------------------------------------------
0033  */
0034 
0035 #ifndef UBFVIEW_H
0036 #define UBFVIEW_H
0037 
0038 #ifdef  __cplusplus
0039 extern "C" {
0040 #endif
0041 
0042 /*---------------------------Includes-----------------------------------*/
0043 #include <ndrstandard.h>
0044 #include <utlist.h>
0045 #include <exhash.h>
0046 #include <fdatatype.h>
0047 #include <view_cmn.h>
0048 /*---------------------------Externs------------------------------------*/
0049 /*---------------------------Macros-------------------------------------*/
0050     
0051 /* field flags: */
0052 #define NDRX_VIEW_FLAG_ELEMCNT_IND_C    0x00000001 /* Include elemnt cnt ind */
0053 #define NDRX_VIEW_FLAG_1WAYMAP_C2UBF_F  0x00000002 /* One way map only C->UBF */
0054 #define NDRX_VIEW_FLAG_LEN_INDICATOR_L  0x00000004 /* Include str/carr len ind */
0055 #define NDRX_VIEW_FLAG_0WAYMAP_N        0x00000008 /* 0 way map (do not copy to ubf) */
0056 #define NDRX_VIEW_FLAG_NULLFILLER_P     0x00000010 /* last char of NULL value is filler */
0057 #define NDRX_VIEW_FLAG_1WAYMAP_UBF2C_S  0x00000020 /* One way map only UBF->C */
0058 
0059     
0060 #define NDRX_VIEW_FIELD_SEPERATORS        " \t"
0061 #define NDRX_VIEW_TOKEN_START            "VIEW"
0062 #define NDRX_VIEW_TOKEN_END              "END"
0063 #define NDRX_VIEW_EMPTY_PARAM            "-"
0064 #define NDRX_VIEW_FLD_SIZE_MAX           65535
0065 #define NDRX_VIEW_FLD_COUNT_MAX          65535
0066 /* will use the same compat base */
0067 #define NDRX_VIEW_UBF_BASE               6000
0068 #define NDRX_VIEW_SIZE_DEFAULT_SIZE      1024
0069 
0070 
0071 #define NDRX_VIEW_QUOTES_NONE           0
0072 #define NDRX_VIEW_QUOTES_SINGLE         1
0073 #define NDRX_VIEW_QUOTES_DOUBLE         2
0074     
0075 #define NDRX_VIEW_COUNT_SETUP\
0076     if (f->flags & NDRX_VIEW_FLAG_ELEMCNT_IND_C)\
0077     {\
0078         C_count = (short *)(cstruct+f->count_fld_offset);\
0079     }\
0080     else\
0081     {\
0082             C_count_stor = f->count;\
0083         C_count = &C_count_stor;\
0084     }
0085 
0086 #define NDRX_VIEW_LEN_SETUP(OCC, DIMSZ)\
0087     if (f->flags & NDRX_VIEW_FLAG_LEN_INDICATOR_L)\
0088     {\
0089         L_length = (unsigned short *)(cstruct+f->length_fld_offset+\
0090             OCC*sizeof(unsigned short));\
0091     }\
0092     else\
0093     {\
0094         L_length_stor = DIMSZ;\
0095         L_length = &L_length_stor;\
0096     }\
0097 
0098 /*---------------------------Enums--------------------------------------*/
0099 /*---------------------------Typedefs-----------------------------------*/
0100     
0101 /**
0102  * View field object. It can be part of linked list
0103  * each field may be compiled and contain the field offsets in memory.
0104  */
0105 typedef struct ndrx_typedview_field ndrx_typedview_field_t;
0106 struct ndrx_typedview_field
0107 {
0108     char type_name[NDRX_UBF_TYPE_LEN+1]; /* UBF Type name */
0109     short typecode;                     /* Resolved type code */
0110     short typecode_full;                /* this is full code (i.e. may include int) */
0111     char cname[NDRX_VIEW_CNAME_LEN+1];  /* field name in struct */
0112     char fbname[UBFFLDMAX+1];           /* fielded buffer field to project to */
0113     BFLDID ubfid;                       /* resolved field id (resolved load time) */
0114     int count;                          /* array size, 1 - no array, >1 -> array */
0115     char flagsstr[NDRX_VIEW_FLAGS_LEN+1]; /* string flags */
0116     long flags;     /* binary flags */
0117     int size;      /* size of the field, NOTE currently decimal is not supported */
0118     char nullval[NDRX_VIEW_NULL_LEN+1];       /*Null value */
0119     char nullval_bin[NDRX_VIEW_NULL_LEN+1];   /*Null value, binary version  */
0120     int  nullval_bin_len;                     /* length of NULL value... */
0121     int  nullval_none;                        /* no NULL value */
0122     int  nullval_default;                     /* defaults "-" is used for nullval */
0123     int  nullval_quotes;                      /* is quotes used? */
0124     
0125     /* type compare values, parsed numerics: */
0126     short   nullval_short;
0127     int     nullval_int;
0128     long    nullval_long;
0129     float   nullval_float;
0130     double  nullval_double;
0131     
0132     /*
0133      * char, just use nullval_bin[0]
0134      * string & carray -> Compare on the fly...
0135      */
0136     
0137     /* type compare values, parsed numerics, end */
0138     
0139     /* Compiled meta-data section: */
0140     int compdataloaded;                   /* Is compiled data loaded? */
0141     char compflags[NDRX_VIEW_COMPFLAGS_LEN];
0142     long offset; /* Compiled offset */
0143     long fldsize; /* element size in bytes */
0144     long count_fld_offset;
0145     long length_fld_offset;
0146 
0147     /* Linked list */
0148     ndrx_typedview_field_t *next, *prev;
0149     
0150     EX_hash_handle hh;         /* makes this structure hashable */  
0151 };
0152 
0153 /**
0154  *  View object will have following attributes:
0155  * - File name
0156  * - View name
0157  * List of fields and their attributes
0158  * hashed by view name
0159  */
0160 typedef struct ndrx_typedview ndrx_typedview_t;
0161 struct ndrx_typedview
0162 {
0163     char vname[NDRX_VIEW_NAME_LEN+1];
0164     char filename[PATH_MAX+1];
0165     uint32_t cksum;                 /* 32bit checksum */
0166     long ssize;                     /* structure size */
0167     
0168     ndrx_typedview_field_t *fields;
0169     ndrx_typedview_field_t *fields_h; /* hash access for fast NULL ops */
0170 
0171     EX_hash_handle hh;         /* makes this structure hashable */    
0172 };
0173 
0174 
0175 /**
0176  * Handler for data header
0177  */
0178 typedef struct
0179 { 
0180     char vname[NDRX_VIEW_NAME_LEN+1];   /**< View field name             */ 
0181     uint32_t cksum;                     /**< Checksum of view version    */
0182     long vflags;                        /**< RFU flags, ensure alignment */
0183     char data[0];                       /**< pointer to view structure   */ 
0184 } ndrx_view_header;
0185 
0186 /**
0187  * View occurrence counter
0188  */
0189 typedef struct ndrx_viewocc ndrx_viewocc_t;
0190 struct ndrx_viewocc
0191 {
0192     char fldnm[NDRX_VIEW_CNAME_LEN+1];  /**< field name */
0193     int occ;            /**< Current field occurrence */
0194     EX_hash_handle hh; /**< makes this structure hashable (for msgid)        */
0195 };
0196 
0197 /*---------------------------Globals------------------------------------*/
0198 extern ndrx_typedview_t *ndrx_G_view_hash;
0199 /*---------------------------Statics------------------------------------*/
0200 /*---------------------------Prototypes---------------------------------*/
0201 extern NDRX_API ndrx_typedview_t * ndrx_view_get_handle(void);
0202 extern NDRX_API int ndrx_view_load_directory(char *dir);
0203 extern NDRX_API int ndrx_view_init(void);
0204 extern NDRX_API int ndrx_view_chkload_directories(void);
0205 extern NDRX_API void ndrx_view_deleteall(void);
0206 extern NDRX_API ndrx_typedview_t * ndrx_view_get_view(char *vname);
0207 extern NDRX_API ndrx_typedview_field_t * ndrx_view_get_field(ndrx_typedview_t *v, char *cname);
0208 extern NDRX_API void ndrx_view_cksum_update(ndrx_typedview_t *v, char *str, int len);
0209 
0210 extern NDRX_API int ndrx_Bvnull(char *cstruct, char *cname, BFLDOCC occ, char *view);
0211 extern NDRX_API int ndrx_Bvnull_int(ndrx_typedview_t *v, ndrx_typedview_field_t *f, 
0212         BFLDOCC occ, char *cstruct);
0213 
0214 extern NDRX_API int ndrx_Bvselinit_int(ndrx_typedview_t *v, ndrx_typedview_field_t *f,  
0215         BFLDLEN single_occ, char *cstruct);
0216 extern NDRX_API int ndrx_Bvselinit(char *cstruct, char *cname, char *view);
0217 
0218 extern NDRX_API int ndrx_Bvsinit_int(ndrx_typedview_t *v, char *cstruct);
0219 extern NDRX_API int ndrx_Bvsinit(char *cstruct, char *view);
0220 
0221 
0222 extern NDRX_API int ndrx_Bvopt_int(ndrx_typedview_t *v, ndrx_typedview_field_t *f, int option);
0223 extern NDRX_API int ndrx_Bvopt(char *cname, int option, char *view) ;
0224 
0225 extern NDRX_API int ndrx_Bvftos_int(UBFH *p_ub, ndrx_typedview_t *v, char *cstruct);
0226 extern NDRX_API int ndrx_Bvftos(UBFH *p_ub, char *cstruct, char *view);
0227 
0228 extern NDRX_API int ndrx_Bvstof_int(UBFH *p_ub, ndrx_typedview_t *v, char *cstruct, int mode);
0229 extern NDRX_API int ndrx_Bvstof(UBFH *p_ub, char *cstruct, int mode, char *view);
0230 
0231 /* View dynamic data access functions: */
0232 
0233 extern NDRX_API int ndrx_Bvextread (char *cstruct, char *view, FILE *inf,
0234         long (*p_readf)(char *buffer, long bufsz, void *dataptr1), 
0235         void *dataptr1, int level, char **p_readbuf_buffered);
0236 
0237 
0238 extern NDRX_API int ndrx_Bvfprint (char *cstruct, char *view, FILE * outf,
0239           ndrx_plugin_tplogprintubf_hook_t p_writef, void *dataptr1, int level);
0240 
0241 extern NDRX_API char * ndrx_Bvfind_int(char *cstruct, ndrx_typedview_t *v,
0242     ndrx_typedview_field_t *f, BFLDOCC occ, BFLDLEN *p_len);
0243 
0244 extern NDRX_API char * ndrx_CBvget_int(char *cstruct, ndrx_typedview_t *v,
0245     ndrx_typedview_field_t *f, BFLDOCC occ, char *buf, BFLDLEN *len, 
0246                  int usrtype, long flags, int mode, int *extralen);
0247 extern NDRX_API int ndrx_CBvget(char *cstruct, char *view, char *cname, BFLDOCC occ, 
0248              char *buf, BFLDLEN *len, int usrtype, long flags);
0249 
0250 extern NDRX_API char *ndrx_CBvgetalloc(char *cstruct, char *view, char *cname, BFLDOCC occ, 
0251             int usrtype, long flags, BFLDLEN *extralen);
0252 
0253 extern NDRX_API int ndrx_CBvchg_int(char *cstruct, ndrx_typedview_t *v, 
0254         ndrx_typedview_field_t *f, BFLDOCC occ, char *buf, 
0255                  BFLDLEN len, int usrtype);
0256 extern NDRX_API int ndrx_CBvchg(char *cstruct, char *view, char *cname, BFLDOCC occ, 
0257              char *buf, BFLDLEN len, int usrtype);
0258 
0259 extern NDRX_API long ndrx_Bvsizeof(char *view);
0260 
0261 extern NDRX_API long ndrx_Bvcpy(char *cstruct_dst, char *cstruct_src, char *view);
0262 
0263 extern NDRX_API BFLDOCC ndrx_Bvoccur_int(char *cstruct, ndrx_typedview_t *v, 
0264         ndrx_typedview_field_t *f, BFLDOCC *maxocc, BFLDOCC *realocc, long *dim_size,
0265         int *fldtype);
0266 
0267 extern NDRX_API BFLDOCC ndrx_Bvoccur(char *cstruct, char *view, char *cname, 
0268         BFLDOCC *maxocc, BFLDOCC *realocc, long *dim_size, int *fldtype);
0269 
0270 extern NDRX_API int ndrx_Bvsetoccur(char *cstruct, char *view, char *cname, BFLDOCC occ);
0271 
0272 extern NDRX_API int ndrx_Bvnext (Bvnext_state_t *state, char *view, 
0273         char *cname, int *fldtype, BFLDOCC *maxocc, long *dim_size);
0274 
0275 extern NDRX_API int ndrx_Bvcmp(char *cstruct1, char *view1, char *cstruct2, char *view2);
0276 
0277 extern NDRX_API int ndrx_Bvfprint (char *cstruct, char *view, FILE * outf,
0278           ndrx_plugin_tplogprintubf_hook_t p_writef, void *dataptr1, int level);
0279 
0280 /* hash-map for getting field occurrence when reading fields in: */
0281 extern NDRX_API int ndrx_viewocc_get(ndrx_viewocc_t **hhandle, char *fld);
0282 extern NDRX_API void ndrx_viewocc_free(ndrx_viewocc_t **hhandle);
0283 
0284 
0285 #ifdef  __cplusplus
0286 }
0287 #endif
0288 
0289 #endif  /* TYPED_VIEW_H */
0290 
0291 /* vim: set ts=4 sw=4 et smartindent: */