/* lightuserdata pattern string format "ixrsmb" integer size */ static int _pattern_pack(lua_State *L) { struct pbc_pattern * pat = lua_touserdata(L,1); size_t format_sz = 0; const char * format = lua_tolstring(L,2,&format_sz); int size = lua_tointeger(L,3); char data[size]; memset(data, 0 ,size); char * ptr = data; int i; for (i=0;i<format_sz;i++) { if (format[i] >= 'a' && format[i] <='z') { ptr = _get_value(L, 4+i, ptr, format[i]); } else { if (!lua_istable(L,4+i)) { luaL_error(L,"need table for array type"); } int j; int n = lua_rawlen(L,4+i); for (j=0;j<n;j++) { lua_rawgeti(L,4+i,j); _get_array_value(L,(void *)ptr,format[i]); lua_pop(L,1); } ptr += sizeof(pbc_array); } } luaL_Buffer b; luaL_buffinit(L, &b); int cap = 128; do { char * temp = luaL_prepbuffsize(&b , cap); struct pbc_slice slice; slice.buffer = temp; slice.len = cap; int ret = pbc_pattern_pack(pat, data, &slice); if (ret < 0) { cap = cap * 2; _Free(temp); continue; } luaL_addsize(&b , slice.len); } while (0); luaL_pushresult(&b); pbc_pattern_close_arrays(pat, data); return 1; }
P serialize_member( const T& t, P end, const member_if<ML, MR, RU>& memb ) { typedef typename ML::type typeL; if ( !( _get_value(t, ML()) == typeL() ) ) return serialize_member( t, end, ML() ); return serialize_member( t, end, MR() ); }
// bool jackctl_parameter_set_value(jackctl_parameter_t * parameter, const union jackctl_parameter_value * value_ptr); static int _parameter_set_value(ClientData clientData, Tcl_Interp *interp, int argc, Tcl_Obj* const *objv) { if (argc != 4) return fw_error_str(interp, "usage: jack-ctl parameter-set-value parameter value"); jackctl_parameter_t * parameter; union jackctl_parameter_value value; if (_get_pointer(interp, objv[2], (void**)¶meter) != TCL_OK || _get_value(interp, parameter, objv[3], &value) != TCL_OK) return TCL_ERROR; return _return_bool(interp, jackctl_parameter_set_value(parameter, &value)); }
void *rtr_get_value(void *tbl[], uint16_t a) { uint16_t ndx; void **l0_tbl; l0_tbl = _get_value(tbl, LEVELS - 1, a, &ndx); if (l0_tbl) return l0_tbl[ndx]; return NULL; }
void *rtr_get_next_value(void *tbl, uint16_t last_value) { uint16_t ndx; /* find the last_value table */ void **last_tbl = _get_value(tbl, LEVELS - 1, last_value, &ndx); if (last_tbl) { return _rtr_get_next_value(last_tbl, 0, ndx); } return NULL; }
BWString BWDB::get_query_value(const BWString &sQuery, const std::vector<BWString> &vParams) { _clear_value(); const char *q = sQuery.c_str(); if (sqlite3_prepare_v2(_dbh, q, -1, &stmt, NULL) != SQLITE_OK) { _finalize(); _get_value(); } for (unsigned int i = 0; i < vParams.size(); ++i) { sqlite3_bind_text(stmt, i + 1, vParams[i].c_str(), -1, SQLITE_TRANSIENT); } if (sqlite3_step(stmt) == SQLITE_ROW) { char *rc = (char *) sqlite3_column_text(stmt, 0); if (rc) _set_value(rc); } _finalize(); return _get_value(); }
/* ---------------------------------------------------------------- * 功 能:将字符串解包为TLV格式数据 * 输入参数:szBuf 输入字符串 * iBufLen 输入字符串长度 * 输出参数:pTLV TLV格式数据 * 返 回 值:0 成功; -1 失败 * 作 者:fengwei * 日 期:2012-9-24 * 调用说明:UnpackTLV(pTLV, szBuf, iLen) * 修改日志:修改日期 修改者 修改内容简述 * ---------------------------------------------------------------- */ int UnpackTLV(T_TLVStru *pTLV, char* szBuf, int iBufLen) { int i, iIndex, iLen; char szTagBuf[MAX_TAG_LEN+1]; T_TLVData *pData; iIndex = 0; i = 0; while (iIndex < iBufLen) { pData = pTLV->tTLVData + i; iLen = _get_tag(szBuf+iIndex, pTLV->iTagType, pData->szTag); if (iLen == 0) { WriteLog(ERROR, "unpack tlv Tag error"); return FAIL; } iIndex += iLen; iLen = _get_len(szBuf+iIndex, pTLV->iLenType, &(pData->iLen)); if (iLen == 0) { WriteLog(ERROR, "unpack tlv len error"); return FAIL; } iIndex += iLen; iLen = _get_value(szBuf+iIndex, pData->iLen, pTLV->iValueType, pData->szValue); if (iLen < 0) { WriteLog(ERROR, "unpack tlv value error"); return FAIL; } iIndex += iLen; pData->iFlag = DATA_NOTNULL; i++; } return SUCC; }
extern int conf_load_file(std::FILE *fd, t_conf_entry *conftab) { char *buff, *directive, *value, *cp; unsigned cflag, lineno; if (!fd) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL file"); return -1; } if (!conftab) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL conftab"); return -1; } /* restore defaults */ _conf_reset_defaults(conftab); for (lineno = 1; (buff = file_get_line(fd)); lineno++) { cflag = 1; for (cp = buff; *cp; cp++) { switch (*cp) { case '\\': if (!*(++cp)) cflag = 0; break; case '"': switch (cflag) { case 1: cflag = 2; break; case 2: cflag = 1; break; } break; case '#': if (cflag == 1) cflag = 0; break; } if (!cflag) break; } if (*cp == '#') *cp = '\0'; cp = str_skip_space(buff); if (!*cp) continue; directive = cp; cp = str_skip_word(cp + 1); if (*cp) *(cp++) = '\0'; cp = str_skip_space(cp); if (*cp != '=') { eventlog(eventlog_level_error, __FUNCTION__, "missing = on line %u", lineno); continue; } cp = str_skip_space(cp + 1); if (!*cp) { eventlog(eventlog_level_error, __FUNCTION__, "missing value at line %u", lineno); continue; } value = _get_value(cp, lineno); if (!value) continue; _process_option(directive, value, conftab); } return 0; }
/* lightuserdata pattern string format "ixrsmbp" integer size */ static int _pattern_pack(lua_State *L) { struct pbc_pattern * pat = (struct pbc_pattern *)checkuserdata(L,1); if (pat == NULL) { return luaL_error(L, "pack pattern is NULL"); } size_t format_sz = 0; const char * format = lua_tolstring(L,2,&format_sz); int size = lua_tointeger(L,3); char * data = (char *)alloca(size); // A trick , we don't need default value. zero buffer for array and message field. // pbc_pattern_set_default(pat, data); memset(data, 0 , size); char * ptr = data; int i; for (i=0;i<format_sz;i++) { if (format[i] >= 'a' && format[i] <='z') { ptr = _get_value(L, 4+i, ptr, format[i]); } else { if (!lua_istable(L,4+i)) { luaL_error(L,"need table for array type"); } int j; int n = lua_rawlen(L,4+i); for (j=0;j<n;j++) { lua_rawgeti(L,4+i,j+1); _get_array_value(L,(struct _pbc_array *)ptr,format[i]); lua_pop(L,1); } ptr += sizeof(pbc_array); } } luaL_Buffer b; luaL_buffinit(L, &b); int cap = 128; for (;;) { char * temp = (char *)luaL_prepbuffsize(&b , cap); struct pbc_slice slice; slice.buffer = temp; slice.len = cap; int ret = pbc_pattern_pack(pat, data, &slice); if (ret < 0) { cap = cap * 2; continue; } luaL_addsize(&b , slice.len); break; } luaL_pushresult(&b); pbc_pattern_close_arrays(pat, data); return 1; }
const char * BWKV::value ( const char * key ) { get_query_value("SELECT value FROM kv WHERE key = ?", std::vector<BWString>({BWString(key)})); if(have_error()) return nullptr; else return _get_value(); }