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 <stdlib.h>
0037 #include <stdio.h>
0038 #include <errno.h>
0039 #include <string.h>
0040 #include <ndrstandard.h>
0041 #include <atmi.h>
0042 #include <atmi_tls.h>
0043 #include <typed_buf.h>
0044
0045 #include "thlock.h"
0046 #include "userlog.h"
0047 #include "utlist.h"
0048 #include "exregex.h"
0049 #include <exparson.h>
0050 #include <atmi_cache.h>
0051 #include <Exfields.h>
0052 #include <ubfutil.h>
0053
0054
0055 #define OFSZ(s,e) EXOFFSET(s,e), EXELEM_SIZE(s,e)
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065 static ubf_c_map_t M_cachedata_map[] =
0066 {
0067 {EX_CACHE_TPERRNO, 0, OFSZ(ndrx_tpcache_data_t, saved_tperrno), BFLD_INT},
0068 {EX_CACHE_TPRUCODE, 0, OFSZ(ndrx_tpcache_data_t, saved_tpurcode), BFLD_LONG},
0069 {EX_CACHE_TIM, 0, OFSZ(ndrx_tpcache_data_t, t), BFLD_LONG},
0070 {EX_CACHE_TIMUSEC, 0, OFSZ(ndrx_tpcache_data_t, tusec), BFLD_LONG},
0071 {EX_CACHE_HITT, 0, OFSZ(ndrx_tpcache_data_t, hit_t), BFLD_LONG},
0072 {EX_CACHE_HITTU, 0, OFSZ(ndrx_tpcache_data_t, hit_tusec), BFLD_LONG},
0073 {EX_CACHE_HITS, 0, OFSZ(ndrx_tpcache_data_t, hits), BFLD_LONG},
0074 {EX_CACHE_NODEID, 0, OFSZ(ndrx_tpcache_data_t, nodeid), BFLD_SHORT},
0075 {EX_CACHE_BUFTYP, 0, OFSZ(ndrx_tpcache_data_t, atmi_type_id), BFLD_SHORT},
0076 {EX_CACHE_BUFLEN, 0, OFSZ(ndrx_tpcache_data_t, atmi_buf_len), BFLD_LONG},
0077 {BBADFLDID}
0078 };
0079
0080
0081
0082
0083 static long M_cachedata_req[] =
0084 {
0085 UBFUTIL_EXPORT,
0086 UBFUTIL_EXPORT,
0087 UBFUTIL_EXPORT,
0088 UBFUTIL_EXPORT,
0089 UBFUTIL_EXPORT,
0090 UBFUTIL_EXPORT,
0091 UBFUTIL_EXPORT,
0092 UBFUTIL_EXPORT,
0093 UBFUTIL_EXPORT,
0094 UBFUTIL_EXPORT
0095 };
0096
0097
0098
0099
0100
0101
0102
0103 expublic char* ndrx_cache_mgt_getsvc(void)
0104 {
0105 static char svcnm[XATMI_SERVICE_NAME_LENGTH+1];
0106
0107 snprintf(svcnm, sizeof(svcnm), NDRX_CACHE_MGSVC, tpgetnodeid());
0108
0109 return svcnm;
0110 }
0111
0112
0113
0114
0115
0116
0117
0118
0119 expublic int ndrx_cache_mgt_data2ubf(ndrx_tpcache_data_t *cdata, char *keydata,
0120 UBFH **pp_ub, int incl_blob)
0121 {
0122 int ret = EXSUCCEED;
0123 int new_size;
0124
0125
0126 Bdel(*pp_ub, EX_CACHE_TPERRNO, 0);
0127 Bdel(*pp_ub, EX_CACHE_TPRUCODE, 0);
0128 Bdel(*pp_ub, EX_CACHE_TIM, 0);
0129 Bdel(*pp_ub, EX_CACHE_TIMUSEC, 0);
0130 Bdel(*pp_ub, EX_CACHE_HITT, 0);
0131 Bdel(*pp_ub, EX_CACHE_TIMUSEC, 0);
0132 Bdel(*pp_ub, EX_CACHE_HITS, 0);
0133 Bdel(*pp_ub, EX_CACHE_NODEID, 0);
0134 Bdel(*pp_ub, EX_CACHE_BUFTYP, 0);
0135
0136
0137
0138 new_size=Bused(*pp_ub) + strlen(keydata) + 1024;
0139
0140 *pp_ub = (UBFH *)tprealloc((char *)*pp_ub, new_size);
0141
0142 if (NULL==*pp_ub)
0143 {
0144 NDRX_LOG(log_error, "Failed to reallocate new buffer size: %ld", new_size);
0145 EXFAIL_OUT(ret);
0146 }
0147
0148 NDRX_LOG(log_debug, "tusec=%ld", cdata->tusec);
0149
0150 if (EXSUCCEED!=(ret=atmi_cvt_c_to_ubf(M_cachedata_map, cdata,
0151 *pp_ub, M_cachedata_req)))
0152 {
0153 NDRX_LOG(log_error, "%s: failed to convert data to UBF", __func__);
0154 NDRX_TPCACHETPCALL_DBDATA(log_debug, cdata);
0155
0156 EXFAIL_OUT(ret);
0157 }
0158
0159
0160
0161 if (EXSUCCEED!=Bchg(*pp_ub, EX_CACHE_OPEXPR, 0, (char *)keydata, 0L))
0162 {
0163 NDRX_LOG(log_error, "Failed to set EX_CACHE_OPEXPR field: %s",
0164 Bstrerror(Berror));
0165 EXFAIL_OUT(ret);
0166 }
0167
0168
0169
0170 if (incl_blob)
0171 {
0172
0173 new_size=Bused(*pp_ub)+cdata->atmi_buf_len+256;
0174
0175 *pp_ub = (UBFH *)tprealloc((char *)*pp_ub, new_size);
0176
0177 if (NULL==*pp_ub)
0178 {
0179 NDRX_LOG(log_error, "Failed to reallocate new buffer size: %ld",
0180 new_size);
0181 EXFAIL_OUT(ret);
0182 }
0183
0184 if (EXSUCCEED!=Bchg(*pp_ub, EX_CACHE_DUMP, 0, cdata->atmi_buf,
0185 cdata->atmi_buf_len))
0186 {
0187 NDRX_LOG(log_error, "Failed to set EX_CACHE_DUMP field: %s",
0188 Bstrerror(Berror));
0189 EXFAIL_OUT(ret);
0190 }
0191 }
0192
0193 out:
0194 return ret;
0195 }
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208 expublic int ndrx_cache_mgt_ubf2data(UBFH *p_ub, ndrx_tpcache_data_t *cdata,
0209 char **blob, char **keydata, char **odata, long *olen)
0210 {
0211 int ret = EXSUCCEED;
0212 BFLDLEN len;
0213
0214 if (EXSUCCEED!=atmi_cvt_ubf_to_c(M_cachedata_map, p_ub, cdata, M_cachedata_req))
0215 {
0216 NDRX_LOG(log_error, "Failed to convert ubf to tpcache_data");
0217 EXFAIL_OUT(ret);
0218 }
0219
0220
0221
0222 if (NULL!=blob)
0223 {
0224 if (0>(len = Blen(p_ub, EX_CACHE_DUMP, 0)))
0225 {
0226 NDRX_LOG(log_error, "Failed to estimate EX_CACHE_DUMP size: %s",
0227 Bstrerror(Berror));
0228 EXFAIL_OUT(ret);
0229 }
0230
0231 NDRX_MALLOC_OUT(*blob, len, char);
0232
0233
0234 if (EXSUCCEED!=Bget(p_ub, EX_CACHE_DUMP, 0, *blob, &len))
0235 {
0236 NDRX_LOG(log_error, "Failed to get cache data: %s", Bstrerror(Berror));
0237 EXFAIL_OUT(ret);
0238 }
0239
0240 if (cdata->atmi_buf_len != len)
0241 {
0242 NDRX_LOG(log_error, "ERROR ! real data len: %d, but "
0243 "EX_CACHE_BUFLEN says: %ld",
0244 len, cdata->atmi_buf_len);
0245 EXFAIL_OUT(ret);
0246 }
0247
0248
0249
0250 if (EXSUCCEED!=ndrx_mbuf_prepare_incoming(*blob,
0251 len, odata, olen, 0, 0))
0252 {
0253
0254 NDRX_LOG(log_error, "Failed to prepare incoming buffer");
0255 EXFAIL_OUT(ret);
0256 }
0257
0258 }
0259
0260 if (NULL!=keydata)
0261 {
0262 if (0>(len = Blen(p_ub, EX_CACHE_OPEXPR, 0)))
0263 {
0264 NDRX_LOG(log_error, "Failed to estimate EX_CACHE_OPEXPR size: %s",
0265 Bstrerror(Berror));
0266 }
0267
0268 NDRX_MALLOC_OUT(*keydata, len, char);
0269
0270 if (EXSUCCEED!=Bget(p_ub, EX_CACHE_OPEXPR, 0, *keydata, &len))
0271 {
0272 NDRX_LOG(log_error, "Failed to get key data: %s", Bstrerror(Berror));
0273 EXFAIL_OUT(ret);
0274 }
0275 }
0276
0277 out:
0278
0279 if (EXSUCCEED!=ret)
0280 {
0281 if (NULL!=blob && *blob!=NULL)
0282 {
0283 NDRX_FREE(*blob);
0284 *keydata=NULL;
0285 }
0286
0287 if (NULL!=keydata && *keydata!=NULL)
0288 {
0289 NDRX_FREE(*keydata);
0290 *keydata=NULL;
0291 }
0292 }
0293 return ret;
0294 }
0295