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 #include <string.h>
0037 #include <stdio.h>
0038 #include <stdlib.h>
0039 #include <memory.h>
0040
0041 #include <ubf.h>
0042 #include <ubf_int.h> /* Internal headers for UBF... */
0043 #include <fdatatype.h>
0044 #include <ferror.h>
0045 #include <fieldtable.h>
0046 #include <ndrstandard.h>
0047 #include <ndebug.h>
0048 #include "cf.h"
0049
0050
0051
0052 #define CARR_TEMP_BUF \
0053 char tmp[CF_TEMP_BUF_MAX]; \
0054 int cpy_len = in_len > CF_TEMP_BUF_MAX?CF_TEMP_BUF_MAX: in_len;\
0055 UBF_LOG(log_debug, "[%10.10s]", input_buf);\
0056 memcpy(tmp, input_buf, cpy_len); \
0057 tmp[cpy_len] = EXEOS
0058
0059
0060
0061
0062
0063 #define CHECK_OUTPUT_BUF_SIZE \
0064 if (CNV_DIR_OUT==cnv_dir && NULL!=out_len)\
0065 {\
0066 if (to->size > *out_len)\
0067 {\
0068 ndrx_Bset_error_fmt(BNOSPACE, "data size: %d specified :%d", to->size, *out_len);\
0069 return NULL; \
0070 }\
0071 }
0072
0073
0074
0075
0076 #define CONV_TO_STRING(X, C) \
0077 if (CNV_DIR_OUT==cnv_dir && NULL!=out_len)\
0078 {\
0079 char tmp[CF_TEMP_BUF_MAX];\
0080 snprintf(tmp, sizeof(tmp), X, (C)*ptr);\
0081 len = strlen(tmp)+1; \
0082 if (*out_len<len)\
0083 {\
0084 ndrx_Bset_error_fmt(BNOSPACE, "data size: %d specified: %d", len, *out_len);\
0085 return NULL;\
0086 }\
0087 else\
0088 {\
0089 strcpy(output_buf, tmp);\
0090 }\
0091 }\
0092 else\
0093 {\
0094 \
0095 if (NULL!=out_len) \
0096 {\
0097 snprintf(output_buf, *out_len, X, (C)*ptr);\
0098 len = strlen(output_buf)+1;\
0099 }\
0100 else\
0101 sprintf(output_buf, X, (C)*ptr);\
0102 }\
0103 if (NULL!=out_len)\
0104 *out_len = len;\
0105
0106
0107
0108
0109
0110 #define CONV_TO_CARRAY(X, C)\
0111 if (CNV_DIR_OUT==cnv_dir)\
0112 {\
0113 char tmp[CF_TEMP_BUF_MAX];\
0114 snprintf(tmp, sizeof(tmp), X, (C)*ptr);\
0115 len = strlen(tmp); \
0116 if (NULL!=out_len && *out_len < len)\
0117 {\
0118 ndrx_Bset_error_fmt(BNOSPACE, "data size: %d specified: %d", len, *out_len);\
0119 return NULL;\
0120 }\
0121 else\
0122 {\
0123 NDRX_STRNCPY(output_buf, tmp, len);\
0124 }\
0125 }\
0126 else\
0127 {\
0128 \
0129 if (NULL!=out_len) \
0130 {\
0131 snprintf(output_buf, *out_len, X, (C)*ptr);\
0132 len = strlen(output_buf);\
0133 }\
0134 else\
0135 {\
0136 sprintf(output_buf, X, (C)*ptr);\
0137 }\
0138 }\
0139 if (NULL!=out_len)\
0140 *out_len = len;
0141
0142
0143
0144
0145
0146
0147
0148
0149 exprivate char * conv_short_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0150 exprivate char * conv_short_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0151 exprivate char * conv_short_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0152 exprivate char * conv_short_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0153 exprivate char * conv_short_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0154 exprivate char * conv_short_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0155 exprivate char * conv_short_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0156 exprivate char * conv_short_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0157
0158
0159 exprivate char * conv_long_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0160 exprivate char * conv_long_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0161 exprivate char * conv_long_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0162 exprivate char * conv_long_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0163 exprivate char * conv_long_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0164 exprivate char * conv_long_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0165 exprivate char * conv_long_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0166 exprivate char * conv_long_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0167
0168
0169 exprivate char * conv_char_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0170 exprivate char * conv_char_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0171 exprivate char * conv_char_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0172 exprivate char * conv_char_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0173 exprivate char * conv_char_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0174 exprivate char * conv_char_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0175 exprivate char * conv_char_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0176 exprivate char * conv_char_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0177
0178
0179 exprivate char * conv_float_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0180 exprivate char * conv_float_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0181 exprivate char * conv_float_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0182 exprivate char * conv_float_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0183 exprivate char * conv_float_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0184 exprivate char * conv_float_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0185 exprivate char * conv_float_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0186 exprivate char * conv_float_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0187
0188
0189 exprivate char * conv_double_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0190 exprivate char * conv_double_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0191 exprivate char * conv_double_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0192 exprivate char * conv_double_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0193 exprivate char * conv_double_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0194 exprivate char * conv_double_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0195 exprivate char * conv_double_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0196 exprivate char * conv_double_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0197
0198
0199 exprivate char * conv_string_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0200 exprivate char * conv_string_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0201 exprivate char * conv_string_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0202 exprivate char * conv_string_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0203 exprivate char * conv_string_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0204 exprivate char * conv_string_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0205 exprivate char * conv_string_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0206 exprivate char * conv_string_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0207
0208 exprivate char * conv_carr_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0209 exprivate char * conv_carr_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0210 exprivate char * conv_carr_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0211 exprivate char * conv_carr_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0212 exprivate char * conv_carr_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0213 exprivate char * conv_carr_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0214 exprivate char * conv_carr_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0215 exprivate char * conv_carr_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0216
0217
0218 exprivate char * conv_int_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0219 exprivate char * conv_int_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0220 exprivate char * conv_int_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0221 exprivate char * conv_int_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0222 exprivate char * conv_int_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0223 exprivate char * conv_int_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0224 exprivate char * conv_int_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0225 exprivate char * conv_int_ptr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0226
0227
0228 exprivate char * conv_ptr_short(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0229 exprivate char * conv_ptr_long(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0230 exprivate char * conv_ptr_char(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0231 exprivate char * conv_ptr_float(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0232 exprivate char * conv_ptr_double(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0233 exprivate char * conv_ptr_string(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0234 exprivate char * conv_ptr_carr(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0235 exprivate char * conv_ptr_int(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0236
0237
0238 exprivate char * conv_same(struct conv_type *t, int cnv_dir, char *input_buf, int in_len, char *output_buf , int *out_len);
0239
0240
0241 expublic conv_type_t G_conv_fn_short[] =
0242 {
0243 {BFLD_SHORT, BFLD_SHORT, conv_same},
0244 {BFLD_SHORT, BFLD_LONG, conv_short_long},
0245 {BFLD_SHORT, BFLD_CHAR, conv_short_char},
0246 {BFLD_SHORT, BFLD_FLOAT, conv_short_float},
0247 {BFLD_SHORT, BFLD_DOUBLE, conv_short_double},
0248 {BFLD_SHORT, BFLD_STRING, conv_short_string},
0249 {BFLD_SHORT, BFLD_CARRAY, conv_short_carr},
0250 {BFLD_SHORT, BFLD_INT, conv_short_int},
0251 {BFLD_SHORT, BFLD_RFU0, NULL},
0252 {BFLD_SHORT, BFLD_PTR, conv_short_ptr}
0253 };
0254 expublic conv_type_t G_conv_fn_long[] =
0255 {
0256 {BFLD_LONG, BFLD_SHORT, conv_long_short},
0257 {BFLD_LONG, BFLD_LONG, conv_same},
0258 {BFLD_LONG, BFLD_CHAR, conv_long_char},
0259 {BFLD_LONG, BFLD_FLOAT, conv_long_float},
0260 {BFLD_LONG, BFLD_DOUBLE, conv_long_double},
0261 {BFLD_LONG, BFLD_STRING, conv_long_string},
0262 {BFLD_LONG, BFLD_CARRAY, conv_long_carr},
0263 {BFLD_LONG, BFLD_INT, conv_long_int},
0264 {BFLD_LONG, BFLD_RFU0, NULL},
0265 {BFLD_LONG, BFLD_PTR, conv_long_ptr}
0266 };
0267
0268 expublic conv_type_t G_conv_fn_char[] =
0269 {
0270
0271 {BFLD_CHAR, BFLD_SHORT, conv_char_short},
0272 {BFLD_CHAR, BFLD_LONG, conv_char_long},
0273 {BFLD_CHAR, BFLD_CHAR, conv_same},
0274 {BFLD_CHAR, BFLD_FLOAT, conv_char_float},
0275 {BFLD_CHAR, BFLD_DOUBLE, conv_char_double},
0276 {BFLD_CHAR, BFLD_STRING, conv_char_string},
0277 {BFLD_CHAR, BFLD_CARRAY, conv_char_carr},
0278 {BFLD_CHAR, BFLD_INT, conv_char_int},
0279 {BFLD_CHAR, BFLD_RFU0, NULL},
0280 {BFLD_CHAR, BFLD_PTR, conv_char_ptr}
0281 };
0282
0283 expublic conv_type_t G_conv_fn_float[] =
0284 {
0285 {BFLD_FLOAT, BFLD_SHORT, conv_float_short},
0286 {BFLD_FLOAT, BFLD_LONG, conv_float_long},
0287 {BFLD_FLOAT, BFLD_CHAR, conv_float_char},
0288 {BFLD_FLOAT, BFLD_FLOAT, conv_same},
0289 {BFLD_FLOAT, BFLD_DOUBLE, conv_float_double},
0290 {BFLD_FLOAT, BFLD_STRING, conv_float_string},
0291 {BFLD_FLOAT, BFLD_CARRAY, conv_float_carr},
0292 {BFLD_FLOAT, BFLD_INT, conv_float_int},
0293 {BFLD_FLOAT, BFLD_RFU0, NULL},
0294 {BFLD_FLOAT, BFLD_PTR, conv_float_ptr}
0295 };
0296
0297 expublic conv_type_t G_conv_fn_double[] =
0298 {
0299 {BFLD_DOUBLE, BFLD_SHORT, conv_double_short},
0300 {BFLD_DOUBLE, BFLD_LONG, conv_double_long},
0301 {BFLD_DOUBLE, BFLD_CHAR, conv_double_char},
0302 {BFLD_DOUBLE, BFLD_FLOAT, conv_double_float},
0303 {BFLD_DOUBLE, BFLD_DOUBLE, conv_same},
0304 {BFLD_DOUBLE, BFLD_STRING, conv_double_string},
0305 {BFLD_DOUBLE, BFLD_CARRAY, conv_double_carr},
0306 {BFLD_DOUBLE, BFLD_INT, conv_double_int},
0307 {BFLD_DOUBLE, BFLD_RFU0, NULL},
0308 {BFLD_DOUBLE, BFLD_PTR, conv_double_ptr}
0309 };
0310
0311 expublic conv_type_t G_conv_fn_string[] =
0312 {
0313 {BFLD_STRING, BFLD_SHORT, conv_string_short},
0314 {BFLD_STRING, BFLD_LONG, conv_string_long},
0315 {BFLD_STRING, BFLD_CHAR, conv_string_char},
0316 {BFLD_STRING, BFLD_FLOAT, conv_string_float},
0317 {BFLD_STRING, BFLD_DOUBLE, conv_string_double},
0318 {BFLD_STRING, BFLD_STRING, conv_same},
0319 {BFLD_STRING, BFLD_CARRAY, conv_string_carr},
0320 {BFLD_STRING, BFLD_INT, conv_string_int},
0321 {BFLD_STRING, BFLD_RFU0, NULL},
0322 {BFLD_STRING, BFLD_PTR, conv_string_ptr}
0323 };
0324
0325 expublic conv_type_t G_conv_fn_carr[] =
0326 {
0327 {BFLD_CARRAY, BFLD_SHORT, conv_carr_short},
0328 {BFLD_CARRAY, BFLD_LONG, conv_carr_long},
0329 {BFLD_CARRAY, BFLD_CHAR, conv_carr_char},
0330 {BFLD_CARRAY, BFLD_FLOAT, conv_carr_float},
0331 {BFLD_CARRAY, BFLD_DOUBLE, conv_carr_double},
0332 {BFLD_CARRAY, BFLD_STRING, conv_carr_string},
0333 {BFLD_CARRAY, BFLD_CARRAY, conv_same},
0334 {BFLD_CARRAY, BFLD_INT, conv_carr_int},
0335 {BFLD_CARRAY, BFLD_RFU0, NULL},
0336 {BFLD_CARRAY, BFLD_PTR, conv_carr_ptr}
0337 };
0338
0339 expublic conv_type_t G_conv_fn_int[] =
0340 {
0341 {BFLD_INT, BFLD_SHORT, conv_int_short},
0342 {BFLD_INT, BFLD_LONG, conv_int_long},
0343 {BFLD_INT, BFLD_CHAR, conv_int_char},
0344 {BFLD_INT, BFLD_FLOAT, conv_int_float},
0345 {BFLD_INT, BFLD_DOUBLE, conv_int_double},
0346 {BFLD_INT, BFLD_STRING, conv_int_string},
0347 {BFLD_INT, BFLD_CARRAY, conv_int_carr},
0348 {BFLD_INT, BFLD_INT, conv_same},
0349 {BFLD_INT, BFLD_RFU0, NULL},
0350 {BFLD_INT, BFLD_PTR, conv_int_ptr}
0351 };
0352
0353 expublic conv_type_t G_conv_fn_ptr[] =
0354 {
0355 {BFLD_PTR, BFLD_SHORT, conv_ptr_short},
0356 {BFLD_PTR, BFLD_LONG, conv_ptr_long},
0357 {BFLD_PTR, BFLD_CHAR, conv_ptr_char},
0358 {BFLD_PTR, BFLD_FLOAT, conv_ptr_float},
0359 {BFLD_PTR, BFLD_DOUBLE, conv_ptr_double},
0360 {BFLD_PTR, BFLD_STRING, conv_ptr_string},
0361 {BFLD_PTR, BFLD_CARRAY, conv_ptr_carr},
0362 {BFLD_PTR, BFLD_INT, conv_ptr_carr},
0363 {BFLD_PTR, BFLD_RFU0, NULL},
0364 {BFLD_PTR, BFLD_PTR, conv_same},
0365 };
0366
0367
0368
0369
0370
0371
0372
0373
0374
0375
0376
0377
0378
0379 expublic char * ndrx_ubf_get_cbuf(int in_from_type, int in_to_type,
0380 char *in_temp_buf, char *in_data, int in_len,
0381 char **out_alloc_buf,
0382 int *alloc_size,
0383 int mode,
0384 int extra_len)
0385 {
0386 char *ret=NULL;
0387 dtype_ext1_t *dtype_ext1 = &G_dtype_ext1_map[in_to_type];
0388 dtype_str_t *dtype = &G_dtype_str_map[in_to_type];
0389
0390
0391
0392
0393
0394
0395 if ((BFLD_CARRAY==in_from_type || BFLD_STRING==in_from_type) &&
0396 (BFLD_CARRAY==in_to_type || BFLD_STRING==in_to_type))
0397 {
0398 UBF_LOG(log_debug, "Conv: carray/string->carray/string - allocating buf, "
0399 "size: %d", in_len+1);
0400
0401 if (CB_MODE_DEFAULT==mode)
0402 {
0403
0404
0405
0406 if (BFLD_STRING==in_from_type)
0407 {
0408 in_len = strlen(in_data);
0409 }
0410
0411 if (NULL==(*out_alloc_buf = NDRX_MALLOC(in_len+1)))
0412 {
0413 ndrx_Bset_error(BMALLOC);
0414 return NULL;
0415 }
0416 ret=*out_alloc_buf;
0417
0418 *alloc_size=in_len+1;
0419 }
0420 else if (CB_MODE_TEMPSPACE==mode)
0421 {
0422
0423 if (NULL==(ret = dtype_ext1->p_tbuf(dtype_ext1, in_len+1)))
0424 {
0425 return NULL;
0426 }
0427
0428 *alloc_size=in_len+1;
0429 }
0430 else if (CB_MODE_ALLOC==mode)
0431 {
0432 int tmp_len = in_len+1+extra_len;
0433
0434 if (NULL==(ret = dtype_ext1->p_talloc(dtype_ext1, &tmp_len)))
0435 {
0436 return NULL;
0437 }
0438
0439 *alloc_size=tmp_len;
0440 *out_alloc_buf=ret;
0441 }
0442 }
0443 else
0444 {
0445 UBF_LOG(log_debug, "Conv: using temp buf mode: %d", mode);
0446 if (CB_MODE_DEFAULT==mode)
0447 {
0448
0449 ret=in_temp_buf;
0450 *alloc_size=CF_TEMP_BUF_MAX;
0451 }
0452 else if (CB_MODE_TEMPSPACE==mode)
0453 {
0454
0455 if (NULL==(ret = dtype_ext1->p_tbuf(dtype_ext1, CF_TEMP_BUF_MAX)))
0456 {
0457 return NULL;
0458 }
0459
0460
0461 *alloc_size=CF_TEMP_BUF_MAX;
0462 }
0463 else if (CB_MODE_ALLOC==mode)
0464 {
0465 int tmp_len;
0466
0467
0468
0469
0470
0471 if (BFLD_UBF==in_from_type || BFLD_VIEW==in_from_type)
0472 {
0473 tmp_len = in_len+extra_len;
0474 }
0475 else
0476 {
0477 tmp_len = CF_TEMP_BUF_MAX+extra_len;
0478 }
0479
0480 if (NULL==(ret = dtype_ext1->p_talloc(dtype_ext1, &tmp_len)))
0481 {
0482 return NULL;
0483 }
0484
0485 *alloc_size=tmp_len;
0486 *out_alloc_buf=ret;
0487 }
0488 }
0489
0490 return ret;
0491 }
0492
0493
0494
0495
0496
0497
0498
0499
0500
0501 expublic char * ndrx_ubf_convert(int from_type, int cnv_dir, char *input_buf, int in_len,
0502 int to_type, char *output_buf , int *out_len)
0503 {
0504 conv_type_t* conv_tab = NULL;
0505 conv_type_t *conv_entry = NULL;
0506 char *ret=NULL;
0507
0508 switch (from_type)
0509 {
0510 case BFLD_SHORT:
0511 conv_tab = (conv_type_t*)&G_conv_fn_short;
0512 break;
0513 case BFLD_LONG:
0514 conv_tab = (conv_type_t*)&G_conv_fn_long;
0515 break;
0516 case BFLD_CHAR:
0517 conv_tab = (conv_type_t*)&G_conv_fn_char;
0518 break;
0519 case BFLD_FLOAT:
0520 conv_tab = (conv_type_t*)&G_conv_fn_float;
0521 break;
0522 case BFLD_DOUBLE:
0523 conv_tab = (conv_type_t*)&G_conv_fn_double;
0524 break;
0525 case BFLD_STRING:
0526 conv_tab = (conv_type_t*)&G_conv_fn_string;
0527 break;
0528 case BFLD_CARRAY:
0529 conv_tab = (conv_type_t*)&G_conv_fn_carr;
0530 break;
0531 case BFLD_INT:
0532 conv_tab = (conv_type_t*)&G_conv_fn_int;
0533 break;
0534 case BFLD_PTR:
0535 conv_tab = (conv_type_t*)&G_conv_fn_ptr;
0536 break;
0537 default:
0538
0539 ret=NULL;
0540 ndrx_Bset_error_fmt(BTYPERR, "Bad from type %d", from_type);
0541 break;
0542 }
0543
0544 if (NULL!=conv_tab)
0545 {
0546 UBF_LOG(log_debug, "Converting from %d to %d",
0547 from_type, to_type);
0548 conv_entry = &conv_tab[to_type];
0549 ret=conv_entry->conv_fn(conv_entry, cnv_dir, input_buf, in_len, output_buf, out_len);
0550 }
0551
0552 return ret;
0553 }
0554
0555
0556
0557
0558
0559 exprivate char * conv_same(struct conv_type *t, int cnv_dir, char *input_buf,
0560 int in_len, char *output_buf , int *out_len)
0561 {
0562 dtype_str_t *dtype = &G_dtype_str_map[t->to_type];
0563 int real_data;
0564 int size = dtype->p_get_data_size(dtype, input_buf, in_len, &real_data);
0565
0566
0567
0568 if (NULL!=out_len && real_data > *out_len)
0569 {
0570 ndrx_Bset_error_fmt(BNOSPACE, "data size: %d specified :%d",
0571 real_data, *out_len);
0572 return NULL;
0573 }
0574
0575 if (NULL!=out_len)
0576 *out_len = real_data;
0577
0578
0579 memcpy(output_buf, input_buf, real_data);
0580
0581 return output_buf;
0582 }
0583
0584
0585 exprivate char * conv_short_long(struct conv_type *t, int cnv_dir, char *input_buf,
0586 int in_len, char *output_buf , int *out_len)
0587 {
0588 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0589 short *ptr = (short *)input_buf;
0590 long *l = (long *)output_buf;
0591
0592
0593 CHECK_OUTPUT_BUF_SIZE;
0594
0595 if (NULL!=out_len)
0596 *out_len = to->size;
0597
0598 *l = (long)*ptr;
0599
0600 return output_buf;
0601 }
0602
0603 exprivate char * conv_short_char(struct conv_type *t, int cnv_dir, char *input_buf,
0604 int in_len, char *output_buf , int *out_len)
0605 {
0606 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0607 short *ptr = (short *)input_buf;
0608 unsigned char *c = (unsigned char *)output_buf;
0609
0610
0611 CHECK_OUTPUT_BUF_SIZE;
0612
0613 if (NULL!=out_len)
0614 *out_len = to->size;
0615
0616 *c = (char) *ptr;
0617
0618 return output_buf;
0619 }
0620
0621 exprivate char * conv_short_float(struct conv_type *t, int cnv_dir, char *input_buf,
0622 int in_len, char *output_buf , int *out_len)
0623 {
0624 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0625 short *ptr = (short *)input_buf;
0626 float *f = (float *)output_buf;
0627
0628
0629 CHECK_OUTPUT_BUF_SIZE;
0630
0631 if (NULL!=out_len)
0632 *out_len = to->size;
0633
0634 *f = (float) *ptr;
0635
0636 return output_buf;
0637 }
0638
0639 exprivate char * conv_short_double(struct conv_type *t, int cnv_dir, char *input_buf,
0640 int in_len, char *output_buf , int *out_len)
0641 {
0642 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0643 short *ptr = (short *)input_buf;
0644 double *d = (double *)output_buf;
0645
0646
0647 CHECK_OUTPUT_BUF_SIZE;
0648
0649 if (NULL!=out_len)
0650 *out_len = to->size;
0651
0652 *d = (double) *ptr;
0653
0654 return output_buf;
0655 }
0656
0657 exprivate char * conv_short_string(struct conv_type *t, int cnv_dir, char *input_buf,
0658 int in_len, char *output_buf , int *out_len)
0659 {
0660 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0661 short *ptr = (short *)input_buf;
0662 int len;
0663
0664 CONV_TO_STRING("%hd", short);
0665
0666 return output_buf;
0667 }
0668
0669 exprivate char * conv_short_carr(struct conv_type *t, int cnv_dir, char *input_buf,
0670 int in_len, char *output_buf , int *out_len)
0671 {
0672 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0673 short *ptr = (short *)input_buf;
0674 int len;
0675
0676 CONV_TO_CARRAY("%hd", short);
0677
0678 return output_buf;
0679 }
0680
0681 exprivate char * conv_short_int(struct conv_type *t, int cnv_dir, char *input_buf,
0682 int in_len, char *output_buf , int *out_len)
0683 {
0684 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0685 short *ptr = (short *)input_buf;
0686 int *l = (int *)output_buf;
0687
0688
0689 CHECK_OUTPUT_BUF_SIZE;
0690
0691 if (NULL!=out_len)
0692 *out_len = to->size;
0693
0694 *l = (int)*ptr;
0695
0696 return output_buf;
0697 }
0698
0699 exprivate char * conv_short_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
0700 int in_len, char *output_buf , int *out_len)
0701 {
0702 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0703 short *ptr = (short *)input_buf;
0704 void** p = (void **)output_buf;
0705
0706
0707 CHECK_OUTPUT_BUF_SIZE;
0708
0709 if (NULL!=out_len)
0710 *out_len = to->size;
0711
0712 *p = (void*)(ndrx_longptr_t)*ptr;
0713
0714 return output_buf;
0715 }
0716
0717
0718 exprivate char * conv_long_short(struct conv_type *t, int cnv_dir, char *input_buf,
0719 int in_len, char *output_buf , int *out_len)
0720 {
0721 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0722 long *ptr = (long *)input_buf;
0723 short *l = (short *)output_buf;
0724
0725
0726 CHECK_OUTPUT_BUF_SIZE;
0727
0728 if (NULL!=out_len)
0729 *out_len = to->size;
0730
0731 *l = (short)*ptr;
0732
0733 return output_buf;
0734 }
0735
0736 exprivate char * conv_long_char(struct conv_type *t, int cnv_dir, char *input_buf,
0737 int in_len, char *output_buf , int *out_len)
0738 {
0739 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0740 long *ptr = (long *)input_buf;
0741 unsigned char *c = (unsigned char *)output_buf;
0742
0743
0744 CHECK_OUTPUT_BUF_SIZE;
0745
0746 if (NULL!=out_len)
0747 *out_len = to->size;
0748
0749 *c = (char) *ptr;
0750
0751 return output_buf;
0752 }
0753
0754 exprivate char * conv_long_float(struct conv_type *t, int cnv_dir, char *input_buf,
0755 int in_len, char *output_buf , int *out_len)
0756 {
0757 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0758 long *ptr = (long *)input_buf;
0759 float *f = (float *)output_buf;
0760
0761
0762 CHECK_OUTPUT_BUF_SIZE;
0763
0764 if (NULL!=out_len)
0765 *out_len = to->size;
0766
0767 *f = (float) *ptr;
0768
0769 return output_buf;
0770 }
0771
0772 exprivate char * conv_long_double(struct conv_type *t, int cnv_dir, char *input_buf,
0773 int in_len, char *output_buf , int *out_len)
0774 {
0775 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0776 long *ptr = (long *)input_buf;
0777 double *d = (double *)output_buf;
0778
0779
0780 CHECK_OUTPUT_BUF_SIZE;
0781
0782 if (NULL!=out_len)
0783 *out_len = to->size;
0784
0785 *d = (double) *ptr;
0786
0787 return output_buf;
0788 }
0789
0790 exprivate char * conv_long_string(struct conv_type *t, int cnv_dir, char *input_buf,
0791 int in_len, char *output_buf , int *out_len)
0792 {
0793 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0794 long *ptr = (long *)input_buf;
0795 int len;
0796
0797 CONV_TO_STRING("%ld", long);
0798
0799 return output_buf;
0800 }
0801
0802 exprivate char * conv_long_carr(struct conv_type *t, int cnv_dir, char *input_buf,
0803 int in_len, char *output_buf , int *out_len)
0804 {
0805 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0806 long *ptr = (long *)input_buf;
0807 long len;
0808
0809 CONV_TO_CARRAY("%ld", long);
0810
0811 return output_buf;
0812 }
0813
0814 exprivate char * conv_long_int(struct conv_type *t, int cnv_dir, char *input_buf,
0815 int in_len, char *output_buf , int *out_len)
0816 {
0817 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0818 long *ptr = (long *)input_buf;
0819 int *i = (int *)output_buf;
0820
0821
0822 CHECK_OUTPUT_BUF_SIZE;
0823
0824 if (NULL!=out_len)
0825 *out_len = to->size;
0826
0827 *i = (int)*ptr;
0828
0829 return output_buf;
0830 }
0831
0832 exprivate char * conv_long_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
0833 int in_len, char *output_buf , int *out_len)
0834 {
0835 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0836 long *ptr = (long *)input_buf;
0837 void **p = (void **)output_buf;
0838
0839
0840 CHECK_OUTPUT_BUF_SIZE;
0841
0842 if (NULL!=out_len)
0843 *out_len = to->size;
0844
0845 *p = (void *)(ndrx_longptr_t)*ptr;
0846
0847 return output_buf;
0848 }
0849
0850
0851
0852 exprivate char * conv_char_short(struct conv_type *t, int cnv_dir, char *input_buf,
0853 int in_len, char *output_buf , int *out_len)
0854 {
0855 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0856 unsigned char *ptr = (unsigned char *)input_buf;
0857 short *l = (short *)output_buf;
0858
0859 CHECK_OUTPUT_BUF_SIZE;
0860
0861 if (NULL!=out_len)
0862 *out_len = to->size;
0863
0864 *l = (short)*ptr;
0865
0866 return output_buf;
0867 }
0868
0869 exprivate char * conv_char_long(struct conv_type *t, int cnv_dir, char *input_buf,
0870 int in_len, char *output_buf , int *out_len)
0871 {
0872 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0873 unsigned char *ptr = (unsigned char *)input_buf;
0874 long *l = (long *)output_buf;
0875
0876 CHECK_OUTPUT_BUF_SIZE;
0877
0878 if (NULL!=out_len)
0879 *out_len = to->size;
0880
0881 *l = (long) *ptr;
0882
0883 return output_buf;
0884 }
0885
0886 exprivate char * conv_char_float(struct conv_type *t, int cnv_dir, char *input_buf,
0887 int in_len, char *output_buf , int *out_len)
0888 {
0889 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0890 unsigned char *ptr = (unsigned char *)input_buf;
0891 float *f = (float *)output_buf;
0892
0893 CHECK_OUTPUT_BUF_SIZE;
0894
0895 if (NULL!=out_len)
0896 *out_len = to->size;
0897
0898 *f = (float) *ptr;
0899
0900 return output_buf;
0901 }
0902
0903 exprivate char * conv_char_double(struct conv_type *t, int cnv_dir, char *input_buf,
0904 int in_len, char *output_buf , int *out_len)
0905 {
0906 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0907 unsigned char *ptr = (unsigned char *)input_buf;
0908 double *d = (double *)output_buf;
0909
0910 CHECK_OUTPUT_BUF_SIZE;
0911
0912 if (NULL!=out_len)
0913 *out_len = to->size;
0914
0915 *d = (double) *ptr;
0916
0917 return output_buf;
0918 }
0919
0920 exprivate char * conv_char_string(struct conv_type *t, int cnv_dir, char *input_buf,
0921 int in_len, char *output_buf , int *out_len)
0922 {
0923 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0924 unsigned char *ptr = (unsigned char *)input_buf;
0925 int len;
0926
0927 if (CNV_DIR_OUT==cnv_dir && NULL!=out_len && *out_len<2)
0928 {
0929 ndrx_Bset_error_fmt(BNOSPACE, "data size: 2 specified :%d", len, *out_len);
0930 return NULL;
0931 }
0932 else
0933 {
0934 output_buf[0] = ptr[0];
0935 output_buf[1] = EXEOS;
0936
0937 if (NULL!=out_len)
0938 *out_len = 2;
0939
0940 }
0941
0942 return output_buf;
0943 }
0944
0945 exprivate char * conv_char_carr(struct conv_type *t, int cnv_dir, char *input_buf,
0946 int in_len, char *output_buf , int *out_len)
0947 {
0948 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0949 unsigned char *ptr = (unsigned char *)input_buf;
0950 int len;
0951
0952 if (CNV_DIR_OUT==cnv_dir && NULL!=out_len && *out_len<1)
0953 {
0954 ndrx_Bset_error_fmt(BNOSPACE, "data size: 1 specified :%d", len, *out_len);
0955 return NULL;
0956 }
0957 else
0958 {
0959 if (NULL!=out_len)
0960 *out_len = 1;
0961 output_buf[0] = ptr[0];
0962 }
0963
0964 return output_buf;
0965 }
0966
0967 exprivate char * conv_char_int(struct conv_type *t, int cnv_dir, char *input_buf,
0968 int in_len, char *output_buf , int *out_len)
0969 {
0970 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0971 unsigned char *ptr = (unsigned char *)input_buf;
0972 int *i = (int *)output_buf;
0973
0974 CHECK_OUTPUT_BUF_SIZE;
0975
0976 if (NULL!=out_len)
0977 *out_len = to->size;
0978
0979 *i = (int) *ptr;
0980
0981 return output_buf;
0982 }
0983
0984 exprivate char * conv_char_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
0985 int in_len, char *output_buf , int *out_len)
0986 {
0987 dtype_str_t *to = &G_dtype_str_map[t->to_type];
0988 unsigned char *ptr = (unsigned char *)input_buf;
0989 void **p = (void **)output_buf;
0990
0991 CHECK_OUTPUT_BUF_SIZE;
0992
0993 if (NULL!=out_len)
0994 *out_len = to->size;
0995
0996 *p = (void *)(ndrx_longptr_t) *ptr;
0997
0998 return output_buf;
0999 }
1000
1001
1002 exprivate char * conv_float_short(struct conv_type *t, int cnv_dir, char *input_buf,
1003 int in_len, char *output_buf , int *out_len)
1004 {
1005 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1006 float *ptr = (float *)input_buf;
1007 short *l = (short *)output_buf;
1008
1009 CHECK_OUTPUT_BUF_SIZE;
1010
1011 if (NULL!=out_len)
1012 *out_len = to->size;
1013
1014 *l = (short)*ptr;
1015
1016 return output_buf;
1017 }
1018
1019 exprivate char * conv_float_char(struct conv_type *t, int cnv_dir, char *input_buf,
1020 int in_len, char *output_buf , int *out_len)
1021 {
1022 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1023 float *ptr = (float *)input_buf;
1024 unsigned char *c = (unsigned char *)output_buf;
1025
1026 CHECK_OUTPUT_BUF_SIZE;
1027
1028 if (NULL!=out_len)
1029 *out_len = to->size;
1030
1031
1032 *c = (short) *ptr;
1033
1034 return output_buf;
1035 }
1036
1037 exprivate char * conv_float_double(struct conv_type *t, int cnv_dir, char *input_buf,
1038 int in_len, char *output_buf , int *out_len)
1039 {
1040 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1041 float *ptr = (float *)input_buf;
1042 double *d = (double *)output_buf;
1043
1044 CHECK_OUTPUT_BUF_SIZE;
1045
1046 if (NULL!=out_len)
1047 *out_len = to->size;
1048
1049 *d = (double) *ptr;
1050
1051 return output_buf;
1052 }
1053
1054 exprivate char * conv_float_long(struct conv_type *t, int cnv_dir, char *input_buf,
1055 int in_len, char *output_buf , int *out_len)
1056 {
1057 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1058 float *ptr = (float *)input_buf;
1059 long *d = (long *)output_buf;
1060
1061 CHECK_OUTPUT_BUF_SIZE;
1062
1063 if (NULL!=out_len)
1064 *out_len = to->size;
1065
1066 *d = (long) *ptr;
1067
1068 return output_buf;
1069 }
1070
1071 exprivate char * conv_float_string(struct conv_type *t, int cnv_dir, char *input_buf,
1072 int in_len, char *output_buf , int *out_len)
1073 {
1074 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1075 float *ptr = (float *)input_buf;
1076 int len;
1077 char fmt[]="%.0lf";
1078 fmt[2]+=FLOAT_RESOLUTION;
1079
1080 CONV_TO_STRING(fmt, float);
1081
1082 return output_buf;
1083 }
1084
1085 exprivate char * conv_float_carr(struct conv_type *t, int cnv_dir, char *input_buf,
1086 int in_len, char *output_buf , int *out_len)
1087 {
1088 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1089 float *ptr = (float *)input_buf;
1090 int len;
1091 char fmt[]="%.0lf";
1092 fmt[2]+=FLOAT_RESOLUTION;
1093
1094 CONV_TO_CARRAY(fmt, float);
1095
1096 return output_buf;
1097 }
1098
1099 exprivate char * conv_float_int(struct conv_type *t, int cnv_dir, char *input_buf,
1100 int in_len, char *output_buf , int *out_len)
1101 {
1102 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1103 float *ptr = (float *)input_buf;
1104 int *i = (int *)output_buf;
1105
1106 CHECK_OUTPUT_BUF_SIZE;
1107
1108 if (NULL!=out_len)
1109 *out_len = to->size;
1110
1111 *i = (int)*ptr;
1112
1113 return output_buf;
1114 }
1115
1116 exprivate char * conv_float_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
1117 int in_len, char *output_buf , int *out_len)
1118 {
1119 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1120 float *ptr = (float *)input_buf;
1121 void **p = (void **)output_buf;
1122
1123 CHECK_OUTPUT_BUF_SIZE;
1124
1125 if (NULL!=out_len)
1126 *out_len = to->size;
1127
1128 *p = (void*)(ndrx_longptr_t)*ptr;
1129
1130 return output_buf;
1131 }
1132
1133
1134 exprivate char * conv_double_short(struct conv_type *t, int cnv_dir, char *input_buf,
1135 int in_len, char *output_buf , int *out_len)
1136 {
1137 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1138 double *ptr = (double *)input_buf;
1139 short *l = (short *)output_buf;
1140
1141
1142 CHECK_OUTPUT_BUF_SIZE;
1143
1144 if (NULL!=out_len)
1145 *out_len = to->size;
1146
1147 *l = (short)*ptr;
1148
1149 return output_buf;
1150 }
1151
1152 exprivate char * conv_double_char(struct conv_type *t, int cnv_dir, char *input_buf,
1153 int in_len, char *output_buf , int *out_len)
1154 {
1155 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1156 double *ptr = (double *)input_buf;
1157 unsigned char *c = (unsigned char *)output_buf;
1158
1159 CHECK_OUTPUT_BUF_SIZE;
1160
1161 if (NULL!=out_len)
1162 *out_len = to->size;
1163
1164 *c = (char) *ptr;
1165
1166 return output_buf;
1167 }
1168
1169 exprivate char * conv_double_float(struct conv_type *t, int cnv_dir, char *input_buf,
1170 int in_len, char *output_buf , int *out_len)
1171 {
1172 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1173 double *ptr = (double *)input_buf;
1174 float *f = (float *)output_buf;
1175
1176 CHECK_OUTPUT_BUF_SIZE;
1177
1178 if (NULL!=out_len)
1179 *out_len = to->size;
1180
1181 *f = (float) *ptr;
1182
1183 return output_buf;
1184 }
1185
1186 exprivate char * conv_double_long(struct conv_type *t, int cnv_dir, char *input_buf,
1187 int in_len, char *output_buf , int *out_len)
1188 {
1189 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1190 double *ptr = (double *)input_buf;
1191 long *d = (long *)output_buf;
1192
1193 CHECK_OUTPUT_BUF_SIZE;
1194
1195 if (NULL!=out_len)
1196 *out_len = to->size;
1197
1198 *d = (long) *ptr;
1199
1200 return output_buf;
1201 }
1202
1203 exprivate char * conv_double_string(struct conv_type *t, int cnv_dir, char *input_buf,
1204 int in_len, char *output_buf , int *out_len)
1205 {
1206 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1207 double *ptr = (double *)input_buf;
1208 int len;
1209 char fmt[]="%.0lf";
1210 fmt[2]+=DOUBLE_RESOLUTION;
1211
1212 CONV_TO_STRING(fmt, double);
1213
1214 return output_buf;
1215 }
1216
1217 exprivate char * conv_double_carr(struct conv_type *t, int cnv_dir, char *input_buf,
1218 int in_len, char *output_buf , int *out_len)
1219 {
1220 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1221 double *ptr = (double *)input_buf;
1222 int len;
1223 char fmt[]="%.0lf";
1224 fmt[2]+=DOUBLE_RESOLUTION;
1225
1226 CONV_TO_CARRAY(fmt, double);
1227
1228 return output_buf;
1229 }
1230
1231 exprivate char * conv_double_int(struct conv_type *t, int cnv_dir, char *input_buf,
1232 int in_len, char *output_buf , int *out_len)
1233 {
1234 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1235 double *ptr = (double *)input_buf;
1236 int *i = (int *)output_buf;
1237
1238
1239 CHECK_OUTPUT_BUF_SIZE;
1240
1241 if (NULL!=out_len)
1242 *out_len = to->size;
1243
1244 *i = (int)*ptr;
1245
1246 return output_buf;
1247 }
1248
1249 exprivate char * conv_double_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
1250 int in_len, char *output_buf , int *out_len)
1251 {
1252 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1253 double *ptr = (double *)input_buf;
1254 void **p = (void **)output_buf;
1255
1256
1257 CHECK_OUTPUT_BUF_SIZE;
1258
1259 if (NULL!=out_len)
1260 *out_len = to->size;
1261
1262 *p = (void *)(ndrx_longptr_t)*ptr;
1263
1264 return output_buf;
1265 }
1266
1267
1268
1269 exprivate char * conv_string_short(struct conv_type *t, int cnv_dir, char *input_buf,
1270 int in_len, char *output_buf , int *out_len)
1271 {
1272 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1273 char *ptr = (char *)input_buf;
1274 short *s = (short *)output_buf;
1275
1276 CHECK_OUTPUT_BUF_SIZE;
1277
1278 if (NULL!=out_len)
1279 *out_len = to->size;
1280
1281 *s = atoi(ptr);
1282
1283 return output_buf;
1284 }
1285
1286 exprivate char * conv_string_char(struct conv_type *t, int cnv_dir, char *input_buf,
1287 int in_len, char *output_buf , int *out_len)
1288 {
1289 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1290 char *ptr = (char *)input_buf;
1291 unsigned char *c = (unsigned char *)output_buf;
1292
1293 CHECK_OUTPUT_BUF_SIZE;
1294
1295 if (NULL!=out_len)
1296 *out_len = to->size;
1297
1298 *c = ptr[0];
1299
1300 return output_buf;
1301 }
1302
1303 exprivate char * conv_string_float(struct conv_type *t, int cnv_dir, char *input_buf,
1304 int in_len, char *output_buf , int *out_len)
1305 {
1306 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1307 char *ptr = (char *)input_buf;
1308 float *f = (float *)output_buf;
1309
1310 CHECK_OUTPUT_BUF_SIZE;
1311
1312 if (NULL!=out_len)
1313 *out_len = to->size;
1314
1315 *f = atof(ptr);
1316
1317 return output_buf;
1318 }
1319
1320 exprivate char * conv_string_long(struct conv_type *t, int cnv_dir, char *input_buf,
1321 int in_len, char *output_buf , int *out_len)
1322 {
1323 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1324 char *ptr = (char *)input_buf;
1325 long *d = (long *)output_buf;
1326
1327 CHECK_OUTPUT_BUF_SIZE;
1328
1329 if (NULL!=out_len)
1330 *out_len = to->size;
1331
1332 *d = atol(ptr);
1333
1334 return output_buf;
1335 }
1336
1337 exprivate char * conv_string_double(struct conv_type *t, int cnv_dir, char *input_buf,
1338 int in_len, char *output_buf , int *out_len)
1339 {
1340 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1341 char *ptr = (char *)input_buf;
1342 double *d = (double *)output_buf;
1343
1344 CHECK_OUTPUT_BUF_SIZE;
1345
1346 if (NULL!=out_len)
1347 *out_len = to->size;
1348
1349 *d = atof(ptr);
1350
1351 return output_buf;
1352 }
1353
1354 exprivate char * conv_string_carr(struct conv_type *t, int cnv_dir, char *input_buf,
1355 int in_len, char *output_buf , int *out_len)
1356 {
1357 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1358 int input_strlen = strlen(input_buf);
1359
1360
1361
1362 if (CNV_DIR_OUT==cnv_dir && NULL!=out_len && *out_len > 0 && *out_len < input_strlen)
1363 {
1364 ndrx_Bset_error_fmt(BNOSPACE, "data size: %d specified :%d", input_strlen, *out_len);
1365 return NULL;
1366 }
1367
1368 NDRX_STRNCPY(output_buf, input_buf, input_strlen);
1369
1370 if (NULL!=out_len)
1371 *out_len = input_strlen;
1372
1373 return output_buf;
1374 }
1375
1376 exprivate char * conv_string_int(struct conv_type *t, int cnv_dir, char *input_buf,
1377 int in_len, char *output_buf , int *out_len)
1378 {
1379 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1380 char *ptr = (char *)input_buf;
1381 int *i = (int *)output_buf;
1382
1383 CHECK_OUTPUT_BUF_SIZE;
1384
1385 if (NULL!=out_len)
1386 *out_len = to->size;
1387
1388 *i = atoi(ptr);
1389
1390 return output_buf;
1391 }
1392
1393 exprivate char * conv_string_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
1394 int in_len, char *output_buf , int *out_len)
1395 {
1396 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1397 char *ptr = (char *)input_buf;
1398 void **p = (void **)output_buf;
1399
1400 CHECK_OUTPUT_BUF_SIZE;
1401
1402 if (NULL!=out_len)
1403 *out_len = to->size;
1404
1405 if (0!=strncmp(ptr, "0x", 2))
1406 {
1407
1408 *((ndrx_longptr_t *)p) = 0;
1409 }
1410 else
1411 {
1412
1413 sscanf (ptr, "0x" NDRX_LONGPTR_HEX, (ndrx_longptr_t *)p);
1414 }
1415
1416 return output_buf;
1417 }
1418
1419
1420 exprivate char * conv_carr_short(struct conv_type *t, int cnv_dir, char *input_buf,
1421 int in_len, char *output_buf , int *out_len)
1422 {
1423 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1424 char *ptr = (char *)input_buf;
1425 short *s = (short *)output_buf;
1426 CARR_TEMP_BUF;
1427
1428 CHECK_OUTPUT_BUF_SIZE;
1429
1430 if (NULL!=out_len)
1431 *out_len = to->size;
1432
1433 *s = atoi(tmp);
1434
1435 return output_buf;
1436 }
1437
1438 exprivate char * conv_carr_char(struct conv_type *t, int cnv_dir, char *input_buf,
1439 int in_len, char *output_buf , int *out_len)
1440 {
1441 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1442 char *ptr = (char *)input_buf;
1443 unsigned char *c = (unsigned char *)output_buf;
1444 CHECK_OUTPUT_BUF_SIZE;
1445
1446 if (NULL!=out_len)
1447 *out_len = to->size;
1448
1449 *c = ptr[0];
1450
1451 return output_buf;
1452 }
1453
1454 exprivate char * conv_carr_float(struct conv_type *t, int cnv_dir, char *input_buf,
1455 int in_len, char *output_buf , int *out_len)
1456 {
1457 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1458 float *f = (float *)output_buf;
1459 CARR_TEMP_BUF;
1460 CHECK_OUTPUT_BUF_SIZE;
1461
1462 if (NULL!=out_len)
1463 *out_len = to->size;
1464
1465 *f = atof(tmp);
1466
1467 return output_buf;
1468 }
1469
1470 exprivate char * conv_carr_long(struct conv_type *t, int cnv_dir, char *input_buf,
1471 int in_len, char *output_buf , int *out_len)
1472 {
1473 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1474 char *ptr = (char *)input_buf;
1475 long *d = (long *)output_buf;
1476 CARR_TEMP_BUF;
1477 CHECK_OUTPUT_BUF_SIZE;
1478
1479 if (NULL!=out_len)
1480 *out_len = to->size;
1481
1482 *d = atol(tmp);
1483
1484 return output_buf;
1485 }
1486
1487 exprivate char * conv_carr_double(struct conv_type *t, int cnv_dir, char *input_buf,
1488 int in_len, char *output_buf , int *out_len)
1489 {
1490 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1491 char *ptr = (char *)input_buf;
1492 double *d = (double *)output_buf;
1493 CARR_TEMP_BUF;
1494 CHECK_OUTPUT_BUF_SIZE;
1495
1496 if (NULL!=out_len)
1497 *out_len = to->size;
1498
1499 *d = atof(tmp);
1500
1501 return output_buf;
1502 }
1503
1504 exprivate char * conv_carr_string(struct conv_type *t, int cnv_dir, char *input_buf,
1505 int in_len, char *output_buf , int *out_len)
1506 {
1507 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1508 int input_carrlen = in_len;
1509
1510
1511
1512 if (CNV_DIR_OUT==cnv_dir && NULL!=out_len && *out_len > 0 && *out_len < input_carrlen+1)
1513 {
1514 ndrx_Bset_error_fmt(BNOSPACE, "data size: %d specified :%d", input_carrlen+1, *out_len);
1515 return NULL;
1516 }
1517
1518 NDRX_STRNCPY_SRC(output_buf, input_buf, input_carrlen);
1519 output_buf[input_carrlen] = EXEOS;
1520
1521 if (NULL!=out_len)
1522 *out_len = strlen(output_buf)+1;
1523
1524 return output_buf;
1525 }
1526
1527 exprivate char * conv_carr_int(struct conv_type *t, int cnv_dir, char *input_buf,
1528 int in_len, char *output_buf , int *out_len)
1529 {
1530 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1531 char *ptr = (char *)input_buf;
1532 int *s = (int *)output_buf;
1533 CARR_TEMP_BUF;
1534
1535 CHECK_OUTPUT_BUF_SIZE;
1536
1537 if (NULL!=out_len)
1538 *out_len = to->size;
1539
1540 *s = atoi(tmp);
1541
1542 return output_buf;
1543 }
1544
1545 exprivate char * conv_carr_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
1546 int in_len, char *output_buf , int *out_len)
1547 {
1548 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1549 char *ptr = (char *)input_buf;
1550 void **p = (void **)output_buf;
1551 CARR_TEMP_BUF;
1552
1553 CHECK_OUTPUT_BUF_SIZE;
1554
1555 if (NULL!=out_len)
1556 *out_len = to->size;
1557
1558 if (0!=strncmp(tmp, "0x", 2))
1559 {
1560
1561 *((ndrx_longptr_t *)p) = 0;
1562 }
1563 else
1564 {
1565
1566 sscanf(tmp, "0x" NDRX_LONGPTR_HEX, (ndrx_longptr_t*)p);
1567 }
1568
1569
1570 return output_buf;
1571 }
1572
1573
1574
1575
1576 exprivate char * conv_int_short(struct conv_type *t, int cnv_dir, char *input_buf,
1577 int in_len, char *output_buf , int *out_len)
1578 {
1579 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1580 int *ptr = (int *)input_buf;
1581 short *l = (short *)output_buf;
1582
1583
1584 CHECK_OUTPUT_BUF_SIZE;
1585
1586 if (NULL!=out_len)
1587 *out_len = to->size;
1588
1589 *l = (short)*ptr;
1590
1591 return output_buf;
1592 }
1593
1594 exprivate char * conv_int_long(struct conv_type *t, int cnv_dir, char *input_buf,
1595 int in_len, char *output_buf , int *out_len)
1596 {
1597 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1598 int *ptr = (int *)input_buf;
1599 long *l = (long *)output_buf;
1600
1601
1602 CHECK_OUTPUT_BUF_SIZE;
1603
1604 if (NULL!=out_len)
1605 *out_len = to->size;
1606
1607 *l = (long)*ptr;
1608
1609 return output_buf;
1610 }
1611
1612 exprivate char * conv_int_char(struct conv_type *t, int cnv_dir, char *input_buf,
1613 int in_len, char *output_buf , int *out_len)
1614 {
1615 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1616 int *ptr = (int *)input_buf;
1617 unsigned char *c = (unsigned char *)output_buf;
1618
1619
1620 CHECK_OUTPUT_BUF_SIZE;
1621
1622 if (NULL!=out_len)
1623 *out_len = to->size;
1624
1625 *c = (char) *ptr;
1626
1627 return output_buf;
1628 }
1629
1630 exprivate char * conv_int_float(struct conv_type *t, int cnv_dir, char *input_buf,
1631 int in_len, char *output_buf , int *out_len)
1632 {
1633 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1634 int *ptr = (int *)input_buf;
1635 float *f = (float *)output_buf;
1636
1637
1638 CHECK_OUTPUT_BUF_SIZE;
1639
1640 if (NULL!=out_len)
1641 *out_len = to->size;
1642
1643 *f = (float) *ptr;
1644
1645 return output_buf;
1646 }
1647
1648 exprivate char * conv_int_double(struct conv_type *t, int cnv_dir, char *input_buf,
1649 int in_len, char *output_buf , int *out_len)
1650 {
1651 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1652 int *ptr = (int *)input_buf;
1653 double *d = (double *)output_buf;
1654
1655
1656 CHECK_OUTPUT_BUF_SIZE;
1657
1658 if (NULL!=out_len)
1659 *out_len = to->size;
1660
1661 *d = (double) *ptr;
1662
1663 return output_buf;
1664 }
1665
1666 exprivate char * conv_int_string(struct conv_type *t, int cnv_dir, char *input_buf,
1667 int in_len, char *output_buf , int *out_len)
1668 {
1669 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1670 int *ptr = (int *)input_buf;
1671 int len;
1672
1673 CONV_TO_STRING("%d", int);
1674
1675 return output_buf;
1676 }
1677
1678 exprivate char * conv_int_carr(struct conv_type *t, int cnv_dir, char *input_buf,
1679 int in_len, char *output_buf , int *out_len)
1680 {
1681 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1682 int *ptr = (int *)input_buf;
1683 int len;
1684
1685 CONV_TO_CARRAY("%d", int);
1686
1687 return output_buf;
1688 }
1689
1690 exprivate char * conv_int_ptr(struct conv_type *t, int cnv_dir, char *input_buf,
1691 int in_len, char *output_buf , int *out_len)
1692 {
1693 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1694 int *ptr = (int *)input_buf;
1695 void **p = (void *)output_buf;
1696
1697
1698 CHECK_OUTPUT_BUF_SIZE;
1699
1700 if (NULL!=out_len)
1701 *out_len = to->size;
1702
1703 *p = (void *)(ndrx_longptr_t)*ptr;
1704
1705 return output_buf;
1706 }
1707
1708
1709
1710
1711 exprivate char * conv_ptr_short(struct conv_type *t, int cnv_dir, char *input_buf,
1712 int in_len, char *output_buf , int *out_len)
1713 {
1714 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1715 void **ptr = (void *)input_buf;
1716 short *s = (short *)output_buf;
1717
1718
1719 CHECK_OUTPUT_BUF_SIZE;
1720
1721 if (NULL!=out_len)
1722 *out_len = to->size;
1723
1724 *s = (short)(ndrx_longptr_t)*ptr;
1725
1726 return output_buf;
1727 }
1728
1729 exprivate char * conv_ptr_long(struct conv_type *t, int cnv_dir, char *input_buf,
1730 int in_len, char *output_buf , int *out_len)
1731 {
1732 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1733 ndrx_longptr_t **ptr = (ndrx_longptr_t **)input_buf;
1734 long *l = (long *)output_buf;
1735
1736
1737 CHECK_OUTPUT_BUF_SIZE;
1738
1739 if (NULL!=out_len)
1740 *out_len = to->size;
1741
1742 *l = (long)*ptr;
1743
1744 return output_buf;
1745 }
1746
1747 exprivate char * conv_ptr_char(struct conv_type *t, int cnv_dir, char *input_buf,
1748 int in_len, char *output_buf , int *out_len)
1749 {
1750 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1751 void **ptr = (void **)input_buf;
1752 unsigned char *c = (unsigned char *)output_buf;
1753
1754
1755 CHECK_OUTPUT_BUF_SIZE;
1756
1757 if (NULL!=out_len)
1758 *out_len = to->size;
1759
1760 *c = (char)(ndrx_longptr_t)*ptr;
1761
1762 return output_buf;
1763 }
1764
1765 exprivate char * conv_ptr_float(struct conv_type *t, int cnv_dir, char *input_buf,
1766 int in_len, char *output_buf , int *out_len)
1767 {
1768 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1769 void **ptr = (void **)input_buf;
1770 float *f = (float *)output_buf;
1771
1772
1773 CHECK_OUTPUT_BUF_SIZE;
1774
1775 if (NULL!=out_len)
1776 *out_len = to->size;
1777
1778 *f = (float)(ndrx_longptr_t) *ptr;
1779
1780 return output_buf;
1781 }
1782
1783 exprivate char * conv_ptr_double(struct conv_type *t, int cnv_dir, char *input_buf,
1784 int in_len, char *output_buf , int *out_len)
1785 {
1786 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1787 void **ptr = (void **)input_buf;
1788 double *d = (double *)output_buf;
1789
1790
1791 CHECK_OUTPUT_BUF_SIZE;
1792
1793 if (NULL!=out_len)
1794 *out_len = to->size;
1795
1796 *d = (double)(ndrx_longptr_t)*ptr;
1797
1798 return output_buf;
1799 }
1800
1801 exprivate char * conv_ptr_string(struct conv_type *t, int cnv_dir, char *input_buf,
1802 int in_len, char *output_buf , int *out_len)
1803 {
1804 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1805 void **ptr = (void **)input_buf;
1806 int len;
1807
1808
1809 CONV_TO_STRING("0x" NDRX_LONGPTR_HEX, ndrx_longptr_t);
1810
1811 return output_buf;
1812 }
1813
1814 exprivate char * conv_ptr_carr(struct conv_type *t, int cnv_dir, char *input_buf,
1815 int in_len, char *output_buf , int *out_len)
1816 {
1817 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1818 void **ptr = (void **)input_buf;
1819 int len;
1820
1821
1822 CONV_TO_CARRAY("0x" NDRX_LONGPTR_HEX, ndrx_longptr_t);
1823
1824 return output_buf;
1825 }
1826
1827 exprivate char * conv_ptr_int(struct conv_type *t, int cnv_dir, char *input_buf,
1828 int in_len, char *output_buf , int *out_len)
1829 {
1830 dtype_str_t *to = &G_dtype_str_map[t->to_type];
1831 void **ptr = (void **)input_buf;
1832 int *i = (int *)output_buf;
1833
1834
1835 CHECK_OUTPUT_BUF_SIZE;
1836
1837 if (NULL!=out_len)
1838 *out_len = to->size;
1839
1840 *i = (int)(ndrx_longptr_t)*ptr;
1841
1842 return output_buf;
1843 }
1844
1845