![]() |
|
|||
0001 /** 0002 * @brief BFLD_UBF type support 0003 * 0004 * @file fld_ubf.c 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 /*---------------------------Includes-----------------------------------*/ 0036 #include <stdio.h> 0037 #include <stdarg.h> 0038 #include <memory.h> 0039 #include <stdlib.h> 0040 #include <regex.h> 0041 #include <ubf.h> 0042 #include <ubf_int.h> 0043 #include <ndebug.h> 0044 #include <ferror.h> 0045 #include <errno.h> 0046 #include <ubf_tls.h> 0047 #include <ubfutil.h> 0048 /*---------------------------Externs------------------------------------*/ 0049 /*---------------------------Macros-------------------------------------*/ 0050 /*---------------------------Enums--------------------------------------*/ 0051 /*---------------------------Typedefs-----------------------------------*/ 0052 /*---------------------------Globals------------------------------------*/ 0053 /*---------------------------Statics------------------------------------*/ 0054 /*---------------------------Prototypes---------------------------------*/ 0055 0056 /** 0057 * Get total data size. The payload size shall be measured with Bused() 0058 * The dlen contains cached value for 0059 * @param t type descriptor 0060 * @param ptr on UBF field start in UBF buffer 0061 * @return size in bytes, aligned 0062 */ 0063 expublic int ndrx_get_fb_ubf_size(dtype_str_t *t, char *fb, int *payload_size) 0064 { 0065 UBF_ubf_t *ubf = (UBF_ubf_t *)fb; 0066 UBF_header_t *hdr = (UBF_header_t *)ubf->ubfdata; 0067 0068 if (NULL!=payload_size) 0069 { 0070 *payload_size = hdr->bytes_used; 0071 } 0072 0073 return ALIGNED_SIZE(hdr->bytes_used); 0074 } 0075 0076 /** 0077 * Put the buffer data 0078 * @param t type descriptor 0079 * @param fb UBF buffer position for field 0080 * @param bfldid field id 0081 * @param data must be UBF type buffer 0082 * @param len not used, we take datak 0083 * @return SUCCEED 0084 */ 0085 expublic int ndrx_put_data_ubf(dtype_str_t *t, char *fb, BFLDID bfldid, 0086 char *data, int len) 0087 { 0088 UBF_ubf_t *ubf = (UBF_ubf_t *)fb; 0089 UBF_header_t *hdr = (UBF_header_t *)data; 0090 0091 /* int align; */ 0092 ubf->bfldid = bfldid; 0093 0094 memcpy(ubf->ubfdata, data, hdr->bytes_used); 0095 0096 return EXSUCCEED; 0097 } 0098 0099 0100 /** 0101 * Return estimated required data size 0102 * @param t type descr 0103 * @param data data 0104 * @param len passed len, not used 0105 * @return bytes needed 0106 */ 0107 expublic int ndrx_get_d_size_ubf (struct dtype_str *t, char *data, 0108 int len, int *payload_size) 0109 { 0110 UBF_header_t *hdr = (UBF_header_t *)data; 0111 0112 0113 /* Check that input buffer is valid? */ 0114 if (EXSUCCEED!=validate_entry((UBFH *)data, 0, 0, VALIDATE_MODE_NO_FLD)) 0115 { 0116 UBF_LOG(log_warn, "Invalid sub-UBF to add to UBF: %p", data); 0117 return EXFAIL; 0118 } 0119 0120 if (NULL!=payload_size) 0121 *payload_size=hdr->bytes_used; 0122 0123 return ALIGNED_SIZE(hdr->bytes_used); 0124 } 0125 0126 /** 0127 * Read the data from given position in fb 0128 * needs to decide what output will be? 0129 * Will it be UBF? Or it can be any byte array? 0130 * 0131 * @param t data type descr 0132 * @param fb field position in UBF buffer 0133 * @param buf output buffer 0134 * @param len output buffer len, shall we use this? 0135 * @return EXSUCCEED/EXFAIL 0136 */ 0137 expublic int ndrx_get_data_ubf (struct dtype_str *t, char *fb, char *buf, int *len) 0138 { 0139 UBF_ubf_t *ubf = (UBF_ubf_t *)fb; 0140 UBF_header_t *hdr = (UBF_header_t *)ubf->ubfdata; 0141 int ret=EXSUCCEED; 0142 BFLDLEN org_buf_len; /* keep the org buffer len */ 0143 0144 org_buf_len = hdr->buf_len; 0145 0146 if (NULL!=len && *len>0 && *len < hdr->bytes_used) 0147 { 0148 /* Set error, that string buffer too short */ 0149 ndrx_Bset_error_fmt(BNOSPACE, "output buffer too short. Data len %d in buf, " 0150 "output: %d", hdr->bytes_used, *len); 0151 EXFAIL_OUT(ret); 0152 } 0153 else 0154 { 0155 /* copy the data */ 0156 memcpy(buf, ubf->ubfdata, hdr->bytes_used); 0157 0158 if (NULL!=len) 0159 { 0160 *len=hdr->bytes_used; 0161 } 0162 } 0163 out: 0164 return ret; 0165 } 0166 0167 /** 0168 * Return empty size of UBF buffer. 0169 * Question here is -> if we add empty UBF buffer, is it normal buffer 0170 * THe buffer is normal empty buffer... 0171 * @param t data type 0172 * @return aligned bytes required for the UBF buffer 0173 */ 0174 expublic int ndrx_g_ubf_empty(struct dtype_ext1* t) 0175 { 0176 return ALIGNED_SIZE(sizeof(UBF_header_t)-FF_USED_BYTES); /* empty string eos */ 0177 } 0178 0179 /** 0180 * Put empty UBF buffer in UBF buffer 0181 * @param t type descr 0182 * @param fb UBF buffer where to install the data 0183 * @param bfldid field id to set 0184 * @return EXSUCCEED/EXFAIL 0185 */ 0186 expublic int ndrx_put_empty_ubf(struct dtype_ext1* t, char *fb, BFLDID bfldid) 0187 { 0188 int ret=EXSUCCEED; 0189 UBF_ubf_t *ubf = (UBF_ubf_t *)fb; 0190 UBF_header_t empty_buf; 0191 0192 0193 /* buffer len will be incorrect here, as we operate only with data used 0194 * and not the total len... 0195 * But any way that's how we work... 0196 */ 0197 Binit((UBFH *)&empty_buf, sizeof(empty_buf)); 0198 0199 ubf->bfldid = bfldid; 0200 /* copy off temp buffer */ 0201 memcpy(ubf->ubfdata, &empty_buf, empty_buf.bytes_used); 0202 0203 return ret; 0204 } 0205 0206 /** 0207 * Print the buffer to log 0208 * @param t type descr 0209 * @param text extra debug msg 0210 * @param data ptr to UBF field to print 0211 * @param len not used.. 0212 */ 0213 expublic void ndrx_dump_ubf(struct dtype_ext1 *t, char *text, char *data, int *len) 0214 { 0215 if (NULL!=data) 0216 { 0217 ndrx_debug_dump_UBF_ubflogger(log_debug, text, (UBFH *)data); 0218 } 0219 else 0220 { 0221 UBF_LOG(log_debug, "%s:\n[null data or len]", text); 0222 } 0223 } 0224 0225 /** 0226 * Compare two buffers 0227 * @param t data type 0228 * @param val1 UBF1 0229 * @param len1 not used 0230 * @param val2 UBF2 0231 * @param len2 not used 0232 * @param mode UBF_CMP_MODE_STD? 0233 * @return EXTRUE/EXFALSE, or -1,0,1 0234 */ 0235 expublic int ndrx_cmp_ubf (struct dtype_ext1 *t, char *val1, BFLDLEN len1, 0236 char *val2, BFLDLEN len2, long mode) 0237 { 0238 0239 if (mode & UBF_CMP_MODE_STD) 0240 { 0241 return Bcmp((UBFH *)val1, (UBFH *)val2); 0242 } 0243 else 0244 { 0245 if (0==Bcmp((UBFH *)val1, (UBFH *)val2)) 0246 { 0247 return EXTRUE; 0248 } 0249 else 0250 { 0251 return EXFALSE; 0252 } 0253 } 0254 } 0255 0256 /* vim: set ts=4 sw=4 et smartindent: */ 0257
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |