//----------------------------------------------------------------------------- // Analyze URL // Extract Filename, Path, FileExt // form RFC2616 / 3.2.2: // http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]] // query data is splitted and stored in ParameterList //----------------------------------------------------------------------------- void CWebserverRequest::analyzeURL(std::string url) { std::string fullurl = ""; ParameterList.clear(); // URI decode fullurl = decodeString(url); fullurl = trim(fullurl, "\r\n"); // non-HTTP-Standard: allow \r or \n in URL. Delete it. UrlData["fullurl"] = fullurl; // split Params if(ySplitString(url,"?",UrlData["url"],UrlData["paramstring"])) // split pure URL and all Params { UrlData["url"] = decodeString(UrlData["url"]); ParseParams(UrlData["paramstring"]); // split params to ParameterList } else // No Params UrlData["url"] = fullurl; if(!ySplitStringLast(UrlData["url"],"/",UrlData["path"],UrlData["filename"])) { UrlData["path"] = "/"; // Set "/" if not contained } else UrlData["path"] += "/"; if(( UrlData["url"].length() == 1) || (UrlData["url"][UrlData["url"].length()-1] == '/' )) { // if "/" at end use index.html UrlData["path"] = UrlData["url"]; UrlData["filename"] = "index.html"; } ySplitStringLast(UrlData["filename"],".",UrlData["filenamepure"],UrlData["fileext"]); }
void printAllPropertyNames(v8::Handle<v8::Object> objToPrint) { v8::Local<v8::Array> allProps = objToPrint->GetPropertyNames(); std::vector<v8::Local<v8::Object> > propertyNames; for (int s=0; s < (int)allProps->Length(); ++s) { v8::Local<v8::Object>toPrint= v8::Local<v8::Object>::Cast(allProps->Get(s)); String errorMessage = "Error: error decoding first string in debug_checkCurrentContextX. "; String strVal, strVal2; bool stringDecoded = decodeString(toPrint, strVal,errorMessage); if (!stringDecoded) { SILOG(js,error,errorMessage); return; } v8::Local<v8::Value> valueToPrint = objToPrint->Get(v8::String::New(strVal.c_str(), strVal.length())); errorMessage = "Error: error decoding second string in debug_checkCurrentContextX. "; stringDecoded = decodeString(valueToPrint,strVal2,errorMessage); if (!stringDecoded) { SILOG(js,error,errorMessage); return; } std::cout<<" property "<< s <<": "<<strVal <<": "<<strVal2<<"\n"; } }
//----------------------------------------------------------------------------- // parse parameter string // parameter = attribute "=" value // attribute = token // value = token | quoted-string // // If parameter attribute is multiple times given, the values are stored like this: // <attribute>=<value1>,<value2>,..,<value n> //----------------------------------------------------------------------------- bool CWebserverRequest::ParseParams(std::string param_string) { bool ende = false; std::string param, name="", value, number; while(!ende) { if(!ySplitStringExact(param_string,"&",param,param_string)) ende = true; if(ySplitStringExact(param,"=",name,value)) { name = decodeString(name); value = trim(decodeString(value)); if(ParameterList[name].empty()) ParameterList[name] = value; else { ParameterList[name] += ","; ParameterList[name] += value; } } else name = trim(decodeString(name)); number = string_printf("%d", ParameterList.size()+1); log_level_printf(7,"ParseParams: name: %s value: %s\n",name.c_str(), value.c_str()); ParameterList[number] = name; } return true; }
/*************************************************************************** ** expand ** ** Purpose: To uncompress the data contained in the input buffer and store ** the result in the output buffer. The fileLength parameter says how ** many bytes to uncompress. The compression itself is a form of LZW that ** adjusts the number of bits that it represents its codes in as it fills ** up the available codes. Two codes have special meaning: ** ** code 256 = start over ** code 257 = end of data ***************************************************************************/ void lzwExpand(uint8 *in, uint8 *out, int32 len) { int32 c, lzwnext, lzwnew, lzwold; uint8 *s, *end; initLZW(); setBits(START_BITS); // Starts at 9-bits lzwnext = 257; // Next available code to define end = (uint8 *)(out + (uint32)len); lzwold = inputCode(&in); // Read in the first code c = lzwold; lzwnew = inputCode(&in); while ((out < end) && (lzwnew != 0x101)) { if (lzwnew == 0x100) { // Code to "start over" lzwnext = 258; setBits(START_BITS); lzwold = inputCode(&in); c = lzwold; *out++ = (char)c; lzwnew = inputCode(&in); } else { if (lzwnew >= lzwnext) { // Handles special LZW scenario *decodeStack = c; s = decodeString(decodeStack + 1, lzwold); } else s = decodeString(decodeStack, lzwnew); // Reverse order of decoded string and // store in out buffer c = *s; while (s >= decodeStack) *out++ = *s--; if (lzwnext > MAX_CODE) setBits(BITS + 1); prefixCode[lzwnext] = lzwold; appendCharacter[lzwnext] = c; lzwnext++; lzwold = lzwnew; lzwnew = inputCode(&in); } } closeLZW(); }
void StringFile::readHeader() { if(_compressed) { std::vector<uint16_t> offsets(_strings.size()); for(uint16_t i = 0; i < _strings.size(); i++) offsets[i] = _stream.getU16LE(); for(uint16_t i = 0; i < _strings.size(); i++) _strings[i] = decodeString(offsets[i]); } else { _strings.push_back(""); while(!_stream.eof()) { uint8_t byte = _stream.get(); //TODO: Figure out what these non-alpha numeric characters are for, // some sort of formatting perhaps? Let's just treat them as // separators for now... if(byte >= 0x20 && byte <= 0x7e) _strings.back() += byte; else if(_strings.back().size() != 0) _strings.push_back(""); } } }
static err_t inner_decode(buf_t *in, void *out) { struct inner *x = (struct inner*)out; vomControl ctl = controlNone; uint64_t index; while (true) { err_t err = decodeVar128(in, &index, &ctl); ck(); if (ctl == controlEnd) { return ERR_OK; } if (ctl != controlNone) { // unexpected control message here err = ERR_DECVOM; ck(); } switch (index) { case 0: err = decodeString(in, &x->String); ck(); break; default: err = ERR_DECVOM; ck(); } } }
QPpsAttribute QPpsObjectPrivate::decodeData(pps_decoder_t *decoder) { pps_node_type_t nodeType = pps_decoder_type(decoder, 0); switch (nodeType) { case PPS_TYPE_BOOL: return decodeBool(decoder); case PPS_TYPE_NUMBER: return decodeNumber(decoder); case PPS_TYPE_STRING: return decodeString(decoder); case PPS_TYPE_ARRAY: return decodeNestedData(&QPpsObjectPrivate::decodeArray, decoder); case PPS_TYPE_OBJECT: return decodeNestedData(&QPpsObjectPrivate::decodeObject, decoder); case PPS_TYPE_DELETED: { // This should create an attribute with the flags set to PpsAttribute::Deleted. // However, we need to create a valid QPpsAttribute while doing so. To do this, // I'll create an empty map as a sentinel. Note that the readFlags() call with produce // the correct set of flags. While I suspect that there will never be any other flags // set in conjunction with this one, I'd rather not be surprised later. QPpsAttributeMap emptyMap; QPpsAttribute::Flags flags = readFlags(decoder); QPpsAttribute returnVal = QPpsAttributePrivate::createPpsAttribute(emptyMap, flags); return returnVal; } case PPS_TYPE_NULL: case PPS_TYPE_NONE: case PPS_TYPE_UNKNOWN: default: qWarning() << "QPpsObjectPrivate::decodeData: invalid pps_node_type"; return QPpsAttribute(); } }
int decodeType( const char* data, int* idx, Object::Type* output ){ int rc = 0; string type = ""; if( !(rc = decodeString(data, idx, &type)) ){ if( type == "scene" ){ *output = Ymir::Object::Scene; } else if( type == "terrain" ){ *output = Ymir::Object::Terrain; } else if( type == "camera" ){ *output = Ymir::Object::Camera; } else if( type == "light" ){ *output = Ymir::Object::Light; } else if( type == "static_entity" ){ *output = Ymir::Object::StaticEntity; } else if( type == "animate_entity" ){ *output = Ymir::Object::AnimateEntity; } else if( type == "window" ){ *output = Ymir::Object::Window; } else if( type == "button" ){ *output = Ymir::Object::Button; } else { *output = Ymir::Object::Invalid; } } return rc; }
static int bsd_uis( bsd_ctx_t *ctx, bsd_data_t *x, const uint8_t *buffer, int length) { int nread; CHECK_LENGTH( 1); uint8_t opcode = buffer[0]; CHECK_DECODE( decodeString( ctx, x, buffer, length, &BS_UIS_STRING)); x->kind = BSD_INT; if( 0x3b <= opcode && opcode <= 0xc6) { /* Tiny unsigned */ x->content.i = opcode - 0x3b; } else if( 0xc7 <= opcode && opcode <= 0xe6) { /* Small unsigned */ CHECK_LENGTH( 2); x->content.i = ((opcode - 0xc7) << 8) + buffer[1] + BS_UTI_MAX + 1; } else if( 0xe7 <= opcode && opcode <= 0xf6) { /* Medium unsigned */ CHECK_LENGTH( 3); x->content.i = ((opcode - 0xe7) << 16) + (buffer[1] << 8) + buffer[2] + BS_USI_MAX + 1; } else if( 0xf7 <= opcode && opcode <= 0xfe) { /* Large unsigned */ CHECK_LENGTH( 4); x->content.i = ((opcode - 0xf7) << 24) + (buffer[1] << 16) + (buffer[2] << 8) + buffer[3] + BS_UMI_MAX + 1; } else if( 0xff == opcode) { /* XLarge unsigned */ CHECK_LENGTH( 5); x->content.i = ((uint32_t)buffer[1] << 24) + ((uint32_t)buffer[2] << 16) + ((uint32_t)buffer[3] << 8) + (uint32_t)buffer[4]; } else if( 0x00 == opcode) { decodeNull( ctx, x); } else { return bsd_error( x, BSD_EINVALID); } return nread; }
int XDrawString(Display* display, Drawable drawable, GC gc, int x, int y, _Xconst char* string, int length) { // https://tronche.com/gui/x/xlib/graphics/drawing-text/XDrawString.html SET_X_SERVER_REQUEST(display, X_PolyText8); LOG("%s: Drawing on %lu\n", __func__, drawable); TYPE_CHECK(drawable, DRAWABLE, display, 0); if (gc == NULL) { handleError(0, display, None, 0, BadGC, 0); return 0; } if (length == 0 || string[0] == 0) { return 1; } GPU_Target* renderTarget; GET_RENDER_TARGET(drawable, renderTarget); if (renderTarget == NULL) { LOG("Failed to get the render target in %s\n", __func__); handleError(0, display, None, 0, BadDrawable, 0); return 0; } char* text = decodeString(string, length); if (text == NULL) { LOG("Out of memory: Failed to allocate decoded string in XDrawString, " "raising BadMatch error.\n"); handleError(0, display, None, 0, BadMatch, 0); return 0; } int res = 1; if (!renderText(renderTarget, gc, x, y, text)) { LOG("Rendering the text failed in %s: %s\n", __func__, SDL_GetError()); handleError(0, display, drawable, 0, BadMatch, 0); res = 0; } free(text); return res; }
/*! Adds the string \a keyseq to the key sequence. \a keyseq may contain up to four key codes, provided they are seperated by a comma, e.g. "Alt+X,Ctrl+S,Z"). Returns the number of key codes added. */ int QKeySequence::assign( QString keyseq ) { QString part; int n = 0; int p = 0, diff = 0; // Run through the whole string, but stop // if we have 4 keys before the end. while ( keyseq.length() && n < 4 ) { // We MUST use something to seperate each sequence, and space // does not cut it, since some of the key names have space // in them.. (Let's hope no one translate with a comma in it:) p = keyseq.find( ',' ); if ( -1 != p ) { if ( ',' == keyseq[p+1] ) // e.g. 'Ctrl+,, Shift+,,' p++; if ( ' ' == keyseq[p+1] ) { // Space after comma diff = 1; p++; } else if ( '\0' == keyseq[p+1] ) { // Last comma 'Ctrl+,' p = -1; } else { diff = 0; } } part = keyseq.left( -1==p?keyseq.length():p-diff ); keyseq = keyseq.right( -1==p?0:keyseq.length() - ( p + 1 ) ); d->key[n] = decodeString( part ); n++; } return n; }
string decodeString(string s) { string num = "", abc = "", ret = ""; int cnt = 0; for ( int i = 0; i < s.size(); ++i ) { if ( '0' <= s[i] && s[i] <= '9' && cnt == 0) { num += s[i]; continue; } if ( s[i] == '[' ) { cnt += 1; } if (cnt) { abc += s[i]; } else { ret += s[i]; } if ( s[i] == ']' ) { cnt -= 1; if ( cnt == 0 ) { string temp = decodeString(abc.substr(1, abc.size()-2)); for ( int i = 0; i < atoi(num.c_str()); ++i ) { ret += temp; } num = ""; abc = ""; } } } ret += abc; return ret; }
/** Returns an irrlicht wide string from the utf8 encoded string at the * given position. * \param[in] pos Buffer position where the encoded string starts. * \param[out] out The decoded string. * \return number of bytes read. If there are no special characters in the * string that will be 1+length of string, but multi-byte encoded * characters can mean that the length of the returned string is * less than the number of bytes read. */ int NetworkString::decodeStringW(int pos, irr::core::stringw *out) const { std::string s; int len = decodeString(pos, &s); *out = StringUtils::utf8ToWide(s); return len; } // decodeString
QString cLogDataSource::decodeFile( const QString &p_qsFileName ) throw( cSevException ) { cTracer obTracer( &g_obLogger, "cLogDataSource::decodeFile", p_qsFileName.toStdString() ); QString qsTempFileName = copyFile( p_qsFileName ); QString qsDecodedFileName = qsTempFileName + ".decoded"; QFile obCodedFile( qsTempFileName ); if( !obCodedFile.open( QIODevice::ReadOnly | QIODevice::Text ) ) { throw cSevException( cSeverity::ERROR, QString( "%1: %2" ).arg( qsTempFileName ).arg( obCodedFile.errorString() ).toStdString() ); } QFile obDecodedFile( qsDecodedFileName ); if( !obDecodedFile.open( QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text ) ) { obCodedFile.close(); throw cSevException( cSeverity::ERROR, QString( "%1: %2" ).arg( qsDecodedFileName ).arg( obDecodedFile.errorString() ).toStdString() ); } QTextStream srCodedStream( &obCodedFile ); QTextStream srDecodedStream( &obDecodedFile ); bool boFirstLine = true; for( QString qsCodedLine = srCodedStream.readLine(); !qsCodedLine.isNull(); qsCodedLine = srCodedStream.readLine() ) { QStringList slCodedTags = qsCodedLine.split( ',' ); bool boFirstTag = true; for( int i = 0; i < slCodedTags.size(); i++ ) { if( boFirstTag ) boFirstTag = false; else srDecodedStream << ","; //only need to decode the 5. 9. 10. and 11. tags if( boFirstLine || ( i != 5 && i != 9 && i != 10 && i != 11 ) ) { srDecodedStream << slCodedTags.at( i ); } else { srDecodedStream << decodeString( slCodedTags.at( i ) ); } } srDecodedStream << "\n"; srDecodedStream.flush(); if( boFirstLine ) boFirstLine = false; } obCodedFile.close(); QFile::remove( qsTempFileName ); obDecodedFile.close(); obTracer << qsTempFileName.toStdString(); return qsDecodedFileName; }
bool Reader::decodeString( Token &token ) { std::string decoded; if ( !decodeString( token, decoded ) ) return false; currentValue() = decoded; return true; }
bool Reader::readObject( Token &/*tokenStart*/ ) { Token tokenName; std::string name; currentValue() = Value( objectValue ); while ( readToken( tokenName ) ) { bool initialTokenOk = true; while ( tokenName.type_ == tokenComment && initialTokenOk ) initialTokenOk = readToken( tokenName ); if ( !initialTokenOk ) break; if ( tokenName.type_ == tokenObjectEnd && name.empty() ) // empty object return true; if ( tokenName.type_ != tokenString ) break; name = ""; if ( !decodeString( tokenName, name ) ) return recoverFromError( tokenObjectEnd ); Token colon; if ( !readToken( colon ) || colon.type_ != tokenMemberSeparator ) { return addErrorAndRecover( "Missing ':' after object member name", colon, tokenObjectEnd ); } Value &value = currentValue()[ name ]; nodes_.push( &value ); bool ok = readValue(); nodes_.pop(); if ( !ok ) // error already set return recoverFromError( tokenObjectEnd ); Token comma; if ( !readToken( comma ) || ( comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && comma.type_ != tokenComment ) ) { return addErrorAndRecover( "Missing ',' or '}' in object declaration", comma, tokenObjectEnd ); } bool finalizeTokenOk = true; while ( comma.type_ == tokenComment && finalizeTokenOk ) finalizeTokenOk = readToken( comma ); if ( comma.type_ == tokenObjectEnd ) return true; } return addErrorAndRecover( "Missing '}' or object member name", tokenName, tokenObjectEnd ); }
bool Reader::decodeString(Token &token) { std::string decoded; if (!decodeString(token, decoded)) return false; currentValue() = decoded; currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); return true; }
bool Reader::decodeString(Token& token) { std::string decoded_string; if (!decodeString(token, decoded_string)) return false; Value decoded(decoded_string); currentValue().swapPayload(decoded); currentValue().setOffsetStart(token.start_ - begin_); currentValue().setOffsetLimit(token.end_ - begin_); return true; }
bool decodeSpaceID(v8::Handle<v8::Value> toDecode,SpaceID& space, String& errorMessage) { String spaceStr; bool strDecode = decodeString(toDecode,spaceStr,errorMessage); if (! strDecode ) return false; space = SpaceID(spaceStr); return true; }
bool decodeObjectReference(v8::Handle<v8::Value> toDecode, ObjectReference& oref, String& errorMessage) { String orefStr; bool strDecode = decodeString(toDecode,orefStr,errorMessage); if (! strDecode ) return false; oref = ObjectReference(orefStr); return true; }
bool Reader::readObject(Token& tokenStart) { Token tokenName; std::string name; Value init(objectValue); currentValue().swapPayload(init); currentValue().setOffsetStart(tokenStart.start_ - begin_); while (readToken(tokenName)) { bool initialTokenOk = true; while (tokenName.type_ == tokenComment && initialTokenOk) initialTokenOk = readToken(tokenName); if (!initialTokenOk) break; if (tokenName.type_ == tokenObjectEnd && name.empty()) // empty object return true; name = ""; if (tokenName.type_ == tokenString) { if (!decodeString(tokenName, name)) return recoverFromError(tokenObjectEnd); } else if (tokenName.type_ == tokenNumber && features_.allowNumericKeys_) { Value numberName; if (!decodeNumber(tokenName, numberName)) return recoverFromError(tokenObjectEnd); name = numberName.asString(); } else { break; } Token colon; if (!readToken(colon) || colon.type_ != tokenMemberSeparator) { return addErrorAndRecover( "Missing ':' after object member name", colon, tokenObjectEnd); } Value& value = currentValue()[name]; nodes_.push(&value); bool ok = readValue(); nodes_.pop(); if (!ok) // error already set return recoverFromError(tokenObjectEnd); Token comma; if (!readToken(comma) || (comma.type_ != tokenObjectEnd && comma.type_ != tokenArraySeparator && comma.type_ != tokenComment)) { return addErrorAndRecover( "Missing ',' or '}' in object declaration", comma, tokenObjectEnd); } bool finalizeTokenOk = true; while (comma.type_ == tokenComment && finalizeTokenOk) finalizeTokenOk = readToken(comma); if (comma.type_ == tokenObjectEnd) return true; } return addErrorAndRecover( "Missing '}' or object member name", tokenName, tokenObjectEnd); }
int XTextWidth(XFontStruct* font_struct, _Xconst char* string, int count) { // https://tronche.com/gui/x/xlib/graphics/font-metrics/XTextWidth.html char* text = decodeString(string, count); if (text == NULL) { LOG("Out of memory: Failed to allocate memory in XTextWidth! " "Returning max width of font.\n"); return font_struct->max_bounds.rbearing * count; } int width = getTextWidth(font_struct, text); free(text); return width; }
void parseTable () { fgetc (m_fp); // B fgetc (m_fp); // M fgetc (m_fp); // L fgetc (m_fp); // 1 m_nbTags = decodeSize (); m_tags = new char * [m_nbTags]; for (int i = 0; i < m_nbTags; i++) { m_tags[i] = decodeString (); } }
IndexedTextFile::IndexedTextFile(SDL_RWops* rwop, bool bDecode) { if(rwop == NULL) { throw std::invalid_argument("IndexedTextFile:IndexedTextFile(): rwop == NULL!"); } int indexedTextFilesize = SDL_RWseek(rwop,0,SEEK_END); if(indexedTextFilesize <= 0) { throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Cannot determine size of this file!"); } if(indexedTextFilesize < 2) { throw std::runtime_error("IndexedTextFile:IndexedTextFile(): No valid indexed textfile: File too small!"); } if(SDL_RWseek(rwop,0,SEEK_SET) != 0) { throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Seeking in this indexed textfile failed!"); } unsigned char* pFiledata; if( (pFiledata = (unsigned char*) malloc(indexedTextFilesize)) == NULL) { throw std::bad_alloc(); } if(SDL_RWread(rwop, pFiledata, indexedTextFilesize, 1) != 1) { free(pFiledata); throw std::runtime_error("IndexedTextFile:IndexedTextFile(): Reading this indexed textfile failed!"); } int numIndexedStrings = (SDL_SwapLE16(((Uint16*) pFiledata)[0]))/2 - 1; Uint16* pIndex = (Uint16*) pFiledata; for(int i=0; i <= numIndexedStrings; i++) { pIndex[i] = SDL_SwapLE16(pIndex[i]); } try { for(int i=0; i < numIndexedStrings; i++) { std::string text((const char*) (pFiledata+pIndex[i])); if(bDecode) { indexedStrings.push_back(convertCP850ToISO8859_1(decodeString(text))); } else { indexedStrings.push_back( convertCP850ToISO8859_1(text) ); } } } catch(std::exception&) { delete [] pFiledata; throw; } free(pFiledata); }
string decodeString(string s) { vector<pair<int,string>> dict; int cnt = 0,start=0,bracnt = 0;; bool count = true; int fnum = 0; while(fnum < s.length() && (s[fnum]<'0'||s[fnum]>'9')) fnum++; if(fnum==s.length()) return s; if(fnum>0) dict.push_back(make_pair(1,s.substr(0,fnum))); for(int i = fnum; i < s.length(); ++i) { if(count && s[i]>='0'&&s[i]<='9') { cnt = 10*cnt+s[i]-'0'; } if(s[i]=='[') { count = false; if(bracnt==0) start = i; bracnt++; } if(s[i]==']') { bracnt--; if(bracnt==0) { dict.push_back(make_pair(cnt,s.substr(start+1,i-start-1))); cout << cnt << endl; count = true; cnt = 0; start = i+1; int t = start; while(t < s.length() && (s[t]<'0'||s[t]>'9')) t++; if(t > start) { dict.push_back(make_pair(1,s.substr(start,t-start))); start = t+1; i = t-1; } } } } string res = ""; for(int i = 0; i < dict.size(); ++i) { string body = decodeString(dict[i].second); for(int j = 0; j < dict[i].first; ++j) res += body; } return res; }
bool LogEncoderDecoder::decodeLogHeader(char *buf, int16_t size, int64_t ×tamp, int &version, std::string &recoveryId, std::string &senderIp, int64_t &config) { folly::ByteRange br((uint8_t *)buf, size); try { timestamp = decodeInt(br); version = decodeInt(br); if (!decodeString(br, buf, size, recoveryId)) { return false; } if (!decodeString(br, buf, size, senderIp)) { return false; } config = decodeInt(br); } catch (const std::exception &ex) { LOG(ERROR) << "got exception " << folly::exceptionStr(ex); return false; } return !checkForOverflow(br.start() - (uint8_t *)buf, size); }
void CoreIrcChannel::setEncrypted(bool e) { if (!Cipher::neededFeaturesAvailable()) return; if (e) { if (topic().isEmpty()) return; QByteArray decrypted = cipher()->decryptTopic(topic().toAscii()); setTopic(decodeString(decrypted)); } }
static int bsd_global( bsd_ctx_t *ctx, bsd_data_t *x, const uint8_t *buffer, int length) { int nread; CHECK_LENGTH( 1); uint8_t opcode = buffer[0]; CHECK_DECODE( decodeInteger( ctx, x, buffer, length, &BS_GLOBAL_INTEGER)); CHECK_DECODE( decodeString( ctx, x, buffer, length, &BS_GLOBAL_STRING)); CHECK_DECODE( decodeCollection( ctx, x, buffer, length, NULL, &BS_GLOBAL_LIST)); CHECK_DECODE( decodeCollection( ctx, x, buffer, length, NULL, &BS_GLOBAL_MAP)); CHECK_DECODE( decodeClass( ctx, x, buffer, length)); if( 0x60 <= opcode && opcode <= 0x6f) { /* object (short form) */ CHECK_ERROR( bsd_object( ctx, x, opcode - 0x60)); return nread; } switch( opcode) { case BS_G_NULL: /* null */ decodeNull( ctx, x); break; case 0x01: /* boolean true */ x->kind = BSD_BOOL; x->content.boolean = 1; break; case 0x02: /* boolean false */ x->kind = BSD_BOOL; x->content.boolean = 0; break; case 0x70: /* object (long form) */ CHECK_SUBDECODE( bsd_uis( ctx, x, buffer + nread, length - nread), BSD_INT); CHECK_ERROR( bsd_object( ctx, x, x->content.i + 0x10)); break; case BS_G_FLOAT32: /* float */ CHECK_LENGTH( 5); x->kind = BSD_DOUBLE; float f; memcpy( &f, buffer + 1, sizeof(float)); ntoh( &f, sizeof(float), sendian.float_); x->content.d = f; break; case BS_G_FLOAT64: /* double */ CHECK_LENGTH( 9); x->kind = BSD_DOUBLE; memcpy( &(x->content.d), buffer + 1, sizeof(double)); ntoh( &(x->content.d), sizeof(double), sendian.double_); break; default: return bsd_error( x, BSD_EINVALID); } return nread; }
char* decodeMbString(const wchar_t* string, size_t* length) { *length = wcstombs(NULL, string, 0); char* text = malloc(sizeof(char*) * (*length + 1)); if (text == NULL) { return NULL; } if (wcstombs(text, string, (*length + 1)) == (size_t) -1) { free(text); return NULL; } char* decodedText = decodeString(text, *length ); free(text); return decodedText; }
const char* decodeStringWithLength(const char* p, const char* limit, String& foundString) { ASSERT(limit >= p); int64_t len; p = decodeVarInt(p, limit, len); if (!p) return 0; if (p + len * 2 > limit) return 0; foundString = decodeString(p, p + len * 2); p += len * 2; return p; }