void Serializer::serializeToXML(const std::string& type, void* data, rapidxml::xml_node<>* root) { rapidxml::xml_document<> tmpDoc; rapidxml::xml_document<>& doc = root == NULL ? tmpDoc : *root->document(); if (root == NULL) { rapidxml::xml_node<>* decl = doc.allocate_node(rapidxml::node_declaration); decl->append_attribute(doc.allocate_attribute("version", "1.0")); decl->append_attribute(doc.allocate_attribute("encoding", "utf-8")); doc.append_node(decl); root = &doc; } std::string finalType = type; bool isPointer = isTypeAPointer(finalType); if(isPointer) { data = (void*)*(void**)data; if(data == NULL) { root->append_attribute(doc.allocate_attribute(doc.allocate_string("i:isnull"), doc.allocate_string("true"))); root->append_attribute(doc.allocate_attribute(doc.allocate_string("xmlns:i"), doc.allocate_string("xmlserializer"))); return; } } ReflectionClass* reflectionClass = Reflection::getInstance().getClassByTypeId(finalType); if(reflectionClass == NULL) { SerializerDataConverter* converter = findConverter(finalType); if(converter == NULL) { throw NoSerializeConverterFoundException("Unable to serialize type " + finalType + "."); } converter->convertToXML(data, false, *root); return; } const std::vector<ReflectionMember*>& memberVars = reflectionClass->getMemberVars(); for(unsigned int i = 0; i < memberVars.size(); ++i) { ReflectionMember* member = memberVars[i]; void* currentDataSection = (void*)(((char*)data) + member->getOffset()); rapidxml::xml_node<>* thisNode = doc.allocate_node(rapidxml::node_element, doc.allocate_string(member->getName().c_str())); root->append_node(thisNode); SerializerDataConverter* converter = findConverter(member->getTypeIdName()); if(converter == NULL) { serializeToXML(member->getTypeIdName(), currentDataSection, thisNode); } else { converter->convertToXML(currentDataSection, false, *thisNode); } } }
U_CFUNC const char * ucnv_io_getConverterName(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) { const char *aliasTmp = alias; int32_t i = 0; for (i = 0; i < 2; i++) { if (i == 1) { /* * After the first unsuccess converter lookup, check to see if * the name begins with 'x-'. If it does, strip it off and try * again. This behaviour is similar to how ICU4J does it. */ if (aliasTmp[0] == 'x' || aliasTmp[1] == '-') { aliasTmp = aliasTmp+2; } else { break; } } if(haveAliasData(pErrorCode) && isAlias(aliasTmp, pErrorCode)) { uint32_t convNum = findConverter(aliasTmp, containsOption, pErrorCode); if (convNum < gMainTable.converterListSize) { return GET_STRING(gMainTable.converterList[convNum]); } /* else converter not found */ } else { break; } } return NULL; }
static const char* ucnv_io_getAlias(const char* alias, uint16_t n, UErrorCode* pErrorCode) { if (haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) { uint32_t convNum = findConverter(alias, NULL, pErrorCode); if (convNum < gMainTable.converterListSize) { /* tagListNum - 1 is the ALL tag */ int32_t listOffset = gMainTable.taggedAliasArray[ (gMainTable.tagListSize - 1) * gMainTable.converterListSize + convNum]; if (listOffset) { uint32_t listCount = gMainTable.taggedAliasLists[listOffset]; /* +1 to skip listCount */ const uint16_t* currList = gMainTable.taggedAliasLists + listOffset + 1; if (n < listCount) { return GET_STRING(currList[n]); } *pErrorCode = U_INDEX_OUTOFBOUNDS_ERROR; } /* else this shouldn't happen. internal program error */ } /* else converter not found */ } return NULL; }
static uint16_t ucnv_io_getAliases(const char* alias, uint16_t start, const char** aliases, UErrorCode* pErrorCode) { if (haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) { uint32_t currAlias; uint32_t convNum = findConverter(alias, NULL, pErrorCode); if (convNum < gMainTable.converterListSize) { /* tagListNum - 1 is the ALL tag */ int32_t listOffset = gMainTable.taggedAliasArray[ (gMainTable.tagListSize - 1) * gMainTable.converterListSize + convNum]; if (listOffset) { uint32_t listCount = gMainTable.taggedAliasLists[listOffset]; /* +1 to skip listCount */ const uint16_t* currList = gMainTable.taggedAliasLists + listOffset + 1; for (currAlias = start; currAlias < listCount; currAlias++) { aliases[currAlias] = GET_STRING(currList[currAlias]); } } /* else this shouldn't happen. internal program error */ } /* else converter not found */ } return 0; }
std::string Serializer::serializeToText(const std::string& type, void* data) { std::string finalType = type; bool isPointer = isTypeAPointer(finalType); if(isPointer) { data = (void*)*(void**)data; if(data == NULL) { return "NULL"; } } ReflectionClass* reflectionClass = Reflection::getInstance().getClassByTypeId(finalType); if(reflectionClass == NULL) { SerializerDataConverter* converter = findConverter(finalType); if(converter == NULL) { throw NoSerializeConverterFoundException("Unable to serialize type " + finalType + "."); } return converter->convertToText(data); } std::stringstream result; const std::vector<ReflectionMember*>& memberVars = reflectionClass->getMemberVars(); for(unsigned int i = 0; i < memberVars.size(); ++i) { if(i != 0) { result << "|"; } ReflectionMember* member = memberVars[i]; void* currentDataSection = (void*)(((char*)data) + member->getOffset()); SerializerDataConverter* converter = findConverter(member->getTypeIdName()); if(converter == NULL) { result << serializeToText(member->getTypeIdName(), currentDataSection); } else { result << converter->convertToText(currentDataSection); } } return result.str(); }
U_CFUNC const char * ucnv_io_getConverterName(const char *alias, UBool *containsOption, UErrorCode *pErrorCode) { if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) { uint32_t convNum = findConverter(alias, containsOption, pErrorCode); if (convNum < gMainTable.converterListSize) { return GET_STRING(gMainTable.converterList[convNum]); } /* else converter not found */ } return NULL; }
shared_ptr<PixelTransferBuffer> ImageConvert::convertBuffer(const shared_ptr<PixelTransferBuffer>& src, const ImageFormat* dstFormat) { // Early return for no conversion if (src->format() == dstFormat) { return src; } ConvertFunc converter = findConverter(src, dstFormat); if (converter) { return (*converter)(src, dstFormat); } else { return shared_ptr<PixelTransferBuffer>(); } }
/* * Search for an standard name of an alias (what is the default name * that this standard uses?) * return the listOffset for gTaggedAliasLists. If it's 0, * the it couldn't be found, but the parameters are valid. */ static uint32_t findTaggedAliasListsOffset(const char* alias, const char* standard, UErrorCode* pErrorCode) { uint32_t idx; uint32_t listOffset; uint32_t convNum; UErrorCode myErr = U_ZERO_ERROR; uint32_t tagNum = getTagNumber(standard); /* Make a quick guess. Hopefully they used a TR22 canonical alias. */ convNum = findConverter(alias, NULL, &myErr); if (myErr != U_ZERO_ERROR) { *pErrorCode = myErr; } if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) { listOffset = gMainTable.taggedAliasArray[tagNum * gMainTable.converterListSize + convNum]; if (listOffset && gMainTable.taggedAliasLists[listOffset + 1]) { return listOffset; } if (myErr == U_AMBIGUOUS_ALIAS_WARNING) { /* Uh Oh! They used an ambiguous alias. We have to search the whole swiss cheese starting at the highest standard affinity. This may take a while. */ for (idx = 0; idx < gMainTable.taggedAliasArraySize; idx++) { listOffset = gMainTable.taggedAliasArray[idx]; if (listOffset && isAliasInList(alias, listOffset)) { uint32_t currTagNum = idx / gMainTable.converterListSize; uint32_t currConvNum = (idx - currTagNum * gMainTable.converterListSize); uint32_t tempListOffset = gMainTable.taggedAliasArray[tagNum * gMainTable.converterListSize + currConvNum]; if (tempListOffset && gMainTable.taggedAliasLists[tempListOffset + 1]) { return tempListOffset; } /* else keep on looking */ /* We could speed this up by starting on the next row because an alias is unique per row, right now. This would change if alias versioning appears. */ } } /* The standard doesn't know about the alias */ } /* else no default name */ return 0; } /* else converter or tag not found */ return UINT32_MAX; }
static uint16_t ucnv_io_countAliases(const char *alias, UErrorCode *pErrorCode) { if(haveAliasData(pErrorCode) && isAlias(alias, pErrorCode)) { uint32_t convNum = findConverter(alias, NULL, pErrorCode); if (convNum < gMainTable.converterListSize) { /* tagListNum - 1 is the ALL tag */ int32_t listOffset = gMainTable.taggedAliasArray[(gMainTable.tagListSize - 1)*gMainTable.converterListSize + convNum]; if (listOffset) { return gMainTable.taggedAliasLists[listOffset]; } /* else this shouldn't happen. internal program error */ } /* else converter not found */ } return 0; }
value Marshaller::toCaml (Smoke::Index typeIndex, Smoke::StackItem const &item) const { Smoke::Type const &type = smoke->types[typeIndex]; if (type.name == nullptr) return Val_unit; Converter const *converter = findConverter (type); if (!converter) { //printf ("type %s is not known to Marshaller\n", type.name); return Val_unit; } if (!converter->toCaml) throw caml_exception ("type %s cannot be converted to Smoke", type.name); return converter->toCaml (item); }
Smoke::StackItem Marshaller::toSmoke (Smoke::Index typeIndex, value val) const { Smoke::Type const &type = smoke->types[typeIndex]; if (type.name == nullptr) return { nullptr }; Converter const *converter = findConverter (type); if (!converter) throw caml_exception ("type %s is not known to Marshaller", type.name); if (!converter->toSmoke) throw caml_exception ("type %s cannot be converted to Smoke", type.name); checkType (val, converter->type); Smoke::StackItem item; converter->toSmoke (val, item); return item; }
/* Return the canonical name */ static uint32_t findTaggedConverterNum(const char *alias, const char *standard, UErrorCode *pErrorCode) { uint32_t idx; uint32_t listOffset; uint32_t convNum; UErrorCode myErr = U_ZERO_ERROR; uint32_t tagNum = getTagNumber(standard); /* Make a quick guess. Hopefully they used a TR22 canonical alias. */ convNum = findConverter(alias, NULL, &myErr); if (myErr != U_ZERO_ERROR) { *pErrorCode = myErr; } if (tagNum < (gMainTable.tagListSize - UCNV_NUM_HIDDEN_TAGS) && convNum < gMainTable.converterListSize) { listOffset = gMainTable.taggedAliasArray[tagNum*gMainTable.converterListSize + convNum]; if (listOffset && isAliasInList(alias, listOffset)) { return convNum; } if (myErr == U_AMBIGUOUS_ALIAS_WARNING) { /* Uh Oh! They used an ambiguous alias. We have to search one slice of the swiss cheese. We search only in the requested tag, not the whole thing. This may take a while. */ uint32_t convStart = (tagNum)*gMainTable.converterListSize; uint32_t convLimit = (tagNum+1)*gMainTable.converterListSize; for (idx = convStart; idx < convLimit; idx++) { listOffset = gMainTable.taggedAliasArray[idx]; if (listOffset && isAliasInList(alias, listOffset)) { return idx-convStart; } } /* The standard doesn't know about the alias */ } /* else no canonical name */ } /* else converter or tag not found */ return UINT32_MAX; }
UT_Error IE_Imp_StarOffice::_loadFile(GsfInput * input) { try { UT_DEBUGMSG(("SDW: Starting import\n")); mOle = GSF_INFILE (gsf_infile_msole_new(input, NULL)); if (!mOle) return UT_IE_BOGUSDOCUMENT; // firstly, load metadata SDWDocInfo::load(mOle, getDoc()); mDocStream = gsf_infile_child_by_name(mOle, "StarWriterDocument"); if (!mDocStream) return UT_IE_BOGUSDOCUMENT; gsf_off_t size = gsf_input_size(mDocStream); if (!appendStrux(PTX_Section, PP_NOPROPS)) return UT_IE_NOMEMORY; UT_DEBUGMSG(("SDW: Attempting to load DocHdr...\n")); mDocHdr.load(mDocStream); UT_DEBUGMSG(("SDW: ...success\n")); // Ask for and verify the password if (mDocHdr.cryptor) { if (!mDocHdr.cryptor->SetPassword(GetPassword().c_str())) { UT_DEBUGMSG(("SDW: Wrong password\n")); return UT_IE_PROTECTED; } } // do the actual reading char type; bool done = false; UT_uint32 recSize; while (!done) { if (gsf_input_tell(mDocStream) == size) break; readChar(mDocStream, type); gsf_off_t eor; readRecSize(mDocStream, recSize, &eor); switch (type) { case SWG_CONTENTS: { gsf_off_t flagsEnd = 0; UT_uint32 nNodes; // sw/source/core/sw3io/sw3sectn.cxx#L129 if (mDocHdr.nVersion >= SWG_LAYFRAMES) { UT_uint8 flags; readFlagRec(mDocStream, flags, &flagsEnd); } if (mDocHdr.nVersion >= SWG_LONGIDX) streamRead(mDocStream, nNodes); else { if (mDocHdr.nVersion >= SWG_LAYFRAMES) { UT_uint16 sectidDummy; streamRead(mDocStream, sectidDummy); } UT_uint16 nodes16; streamRead(mDocStream, nodes16); nNodes = (UT_uint32)nodes16; } if (flagsEnd) { UT_ASSERT(flagsEnd >= gsf_input_tell(mDocStream)); if (gsf_input_tell(mDocStream) != flagsEnd) { UT_DEBUGMSG(("SDW: have not read all flags\n")); if (gsf_input_seek(mDocStream, flagsEnd, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } } bool done2 = false; UT_uint32 size2; while (!done2) { readChar(mDocStream, type); gsf_off_t eor2; readRecSize(mDocStream, size2, &eor2); switch (type) { case SWG_TEXTNODE: { // sw/source/core/sw3io/sw3nodes.cxx#L788 UT_DEBUGMSG(("SDW: Found Textnode! (start at 0x%08llX end at 0x%08llX)\n", (long long)gsf_input_tell(mDocStream), (long long)eor2)); UT_uint8 flags; gsf_off_t newPos; readFlagRec(mDocStream, flags, &newPos); // XXX check flags if (gsf_input_seek(mDocStream, newPos, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; // Read the actual text UT_UCS4Char* str; readByteString(mDocStream, str); UT_UCS4String textNode(str); free(str); UT_DEBUGMSG(("SDW: ...length=%zu contents are: |%s|\n", textNode.length(), textNode.utf8_str())); // now get the attributes UT_String attrs; UT_String pAttrs; UT_Vector charAttributes; while (gsf_input_tell(mDocStream) < eor2) { char attVal; streamRead(mDocStream, attVal); UT_uint32 attSize; gsf_off_t eoa; // end of attribute readRecSize(mDocStream, attSize, &eoa); if (attVal == SWG_ATTRIBUTE) { TextAttr* a = new TextAttr; streamRead(mDocStream, *a, eoa); UT_DEBUGMSG(("SDW: ...found text-sub-node, which=0x%x, ver=0x%x, start=%u, end=%u - data:%s len:%llu data is:", a->which, a->ver, a->start, a->end, a->data?"Yes":"No", (long long unsigned)a->dataLen)); #ifdef DEBUG hexdump(a->data, a->dataLen); putc('\n', stderr); #endif charAttributes.addItem(a); } else if (attVal == SWG_ATTRSET) { // bah, yet another loop UT_DEBUGMSG(("SDW: ...paragraph attributes found\n")); while (gsf_input_tell(mDocStream) < eoa) { // reusing attVal and attSize streamRead(mDocStream, attVal); gsf_off_t eoa2; // end of attribute readRecSize(mDocStream, attSize, &eoa2); if (attVal == SWG_ATTRIBUTE) { TextAttr a; streamRead(mDocStream, a, eoa2); if (!a.attrVal.empty()) { if (a.isPara) UT_String_setProperty(pAttrs, a.attrName, a.attrVal); else UT_String_setProperty(attrs, a.attrName, a.attrVal); } UT_DEBUGMSG(("SDW: ......found paragraph attr, which=0x%x, ver=0x%x, start=%u, end=%u (string now %s) Data:%s Len=%lld Data:", a.which, a.ver, (a.startSet?a.start:0), (a.endSet?a.end:0), attrs.c_str(), (a.data ? "Yes" : "No"), (long long)a.dataLen)); #ifdef DEBUG hexdump(a.data, a.dataLen); putc('\n', stderr); #endif } if (gsf_input_seek(mDocStream, eoa2, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } } else { UT_DEBUGMSG(("SDW: ...unknown attribute '%c' found (start=%" GSF_OFF_T_FORMAT " end=%" GSF_OFF_T_FORMAT ")\n", attVal, gsf_input_tell(mDocStream), eoa)); } if (gsf_input_seek(mDocStream, eoa, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } PP_PropertyVector attributes = { "props", pAttrs.c_str() }; // first, insert the paragraph if (!appendStrux(PTX_Block, attributes)) return UT_IE_NOMEMORY; UT_String pca(attrs); // character attributes for the whole paragraph // now insert the spans of text UT_uint32 len = textNode.length(); UT_uint32 lastInsPos = 0; for (UT_uint32 i = 1; i < len; i++) { bool doInsert = false; // whether there was an attribute change for (UT_sint32 j = 0; j < charAttributes.getItemCount(); j++) { const TextAttr* a = reinterpret_cast<const TextAttr*>(charAttributes[j]); // clear the last attribute, if set if (a->endSet && a->end == (i - 1)) { if (a->isOff) { UT_String propval = UT_String_getPropVal(pca, a->attrName); UT_String_setProperty(attrs, a->attrName, propval); } else UT_String_removeProperty(attrs, a->attrName); } // now set new attribute, if needed if (a->startSet && a->start == (i - 1)) { if (a->isPara) UT_String_setProperty(pAttrs, a->attrName, a->attrVal); else if (a->isOff) UT_String_removeProperty(attrs, a->attrName); else UT_String_setProperty(attrs, a->attrName, a->attrVal); } // insert if this is the last character, or if there was a format change if ((a->endSet && a->end == i) || (a->startSet && a->start == i)) doInsert = true; } if (doInsert || i == (len - 1)) { attributes[1] = attrs.c_str(); UT_DEBUGMSG(("SDW: Going to appendFmt with %s\n", attributes[1].c_str())); if (!appendFmt(attributes)) return UT_IE_NOMEMORY; /* leave cast alone! */ UT_DEBUGMSG(("SDW: About to insert %u-%u\n", lastInsPos, i)); size_t spanLen = i - lastInsPos; if (i == (len - 1)) spanLen++; UT_UCS4String span = textNode.substr(lastInsPos, spanLen); appendSpan(span.ucs4_str(), spanLen); lastInsPos = i; } } UT_VECTOR_PURGEALL(TextAttr*, charAttributes); break; } case SWG_JOBSETUP: { // flags are apparently unused here. no idea why they are there. gsf_off_t newpos; UT_uint8 flags; readFlagRec(mDocStream, flags, &newpos); if (gsf_input_seek(mDocStream, newpos, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; UT_uint16 len, system; streamRead(mDocStream, len); streamRead(mDocStream, system); char printerName[64]; streamRead(mDocStream, printerName, 64); char deviceName[32], portName[32], driverName[32]; streamRead(mDocStream, deviceName, 32); streamRead(mDocStream, portName, 32); streamRead(mDocStream, driverName, 32); UT_DEBUGMSG(("SDW: Jobsetup: len %u sys 0x%x printer |%.64s| device |%.32s| port |%.32s| driver |%.32s|\n", len, system, printerName, deviceName, portName, driverName)); if (system == JOBSET_FILE364_SYSTEM || system == JOBSET_FILE605_SYSTEM) { UT_uint16 len2, system2; streamRead(mDocStream, len2); streamRead(mDocStream, system2); UT_uint32 ddl; // driver data length streamRead(mDocStream, ddl); // now the interesting data UT_uint16 orient; // 0=portrait 1=landscape streamRead(mDocStream, orient); UT_uint16 paperBin; streamRead(mDocStream, paperBin); UT_uint16 paperFormat; streamRead(mDocStream, paperFormat); UT_uint32 width, height; streamRead(mDocStream, width); streamRead(mDocStream, height); UT_DEBUGMSG(("SDW: orient %u bin %u format %u width %u height %u\n", orient, paperBin, paperFormat, width, height)); // rest of the data is ignored, seems to be printer specific anyway. // Use A4, Portrait by default PP_PropertyVector attributes = { "pagetype", "a4", // A4/Letter/... "orientation", "portrait", "width", "210", "height", "297", "units", "mm" }; const char* sdwPaperToAbi[] = { "A3", "A4", "A5", "B4", "B5", "Letter", "Legal", "Tabloid/Ledger", "Custom" }; if (paperFormat < sizeof(sdwPaperToAbi)/sizeof(*sdwPaperToAbi)) { attributes[1] = sdwPaperToAbi[paperFormat]; } const char* sdwOrientToAbi[] = { "portrait", "landscape" }; if (orient < sizeof(sdwOrientToAbi)/sizeof(*sdwOrientToAbi)) { attributes[3] = sdwOrientToAbi[orient]; } attributes[5] = UT_std_string_sprintf("%f", static_cast<double>(width)/100); attributes[7] = UT_std_string_sprintf("%f", static_cast<double>(height)/100); getDoc()->setPageSizeFromFile(attributes); } break; } case SWG_EOF: done2 = true; break; default: UT_DEBUGMSG(("SDW: SWG_CONTENT: Skipping %u bytes for record type '%c' (starting at 0x%08llX)\n", size2, type, (long long)gsf_input_tell(mDocStream))); } if (gsf_input_seek(mDocStream, eor2, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } break; } case SWG_STRINGPOOL: { if (mDocHdr.nVersion <= SWG_POOLIDS) { UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); break; } UT_uint8 encoding; streamRead(mDocStream, encoding); UT_iconv_t cd = findConverter(encoding); if (!UT_iconv_isValid(cd)) throw UT_IE_IMPORTERROR; UT_uint16 count; streamRead(mDocStream, count); while (count--) { UT_uint16 id; streamRead(mDocStream, id); char* str; UT_uint16 len; ::readByteString(mDocStream, str, &len); if (id == IDX_NOCONV_FF) { UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); } // FIXME: find a way to not have to copy and free // the result of UT_convert_cd.... --hub UT_DEBUGMSG(("SDW: StringPool: found 0x%04x <-> %.*s\n", id, len, str)); UT_UCS4Char* convertedString = reinterpret_cast<UT_UCS4Char*>(UT_convert_cd(str, len + 1, cd, NULL, NULL)); mStringPool.insert(stringpool_map::value_type(id, convertedString)); FREEP(convertedString); delete [] str; } UT_iconv_close(cd); break; } case SWG_COMMENT: // skip over comments break; case SWG_EOF: done = true; break; default: UT_DEBUGMSG(("SDW: Skipping %u bytes for record type '%c' (starting at 0x%08llX)\n", recSize, type, (long long)gsf_input_tell(mDocStream))); } // Seek to the end of the record, in case it wasn't read completely if (gsf_input_seek(mDocStream, eor, G_SEEK_SET)) return UT_IE_BOGUSDOCUMENT; } UT_DEBUGMSG(("SDW: Done\n")); return UT_OK; } catch(UT_Error e) { UT_DEBUGMSG(("SDW: error %d\n", e)); return e; } catch(...) { UT_DEBUGMSG(("SDW: Unknown error\n")); return UT_IE_BOGUSDOCUMENT; } }
void DocHdr::load(GsfInput* stream) throw(UT_Error) { UT_DEBUGMSG(("SDW: entering DocHdr::load\n")); static const char sw3hdr[] = "SW3HDR"; static const char sw4hdr[] = "SW4HDR"; static const char sw5hdr[] = "SW5HDR"; char header[7]; streamRead(stream, header, 7); if (memcmp(header, sw3hdr, sizeof(sw3hdr)) != 0 && memcmp(header, sw4hdr, sizeof(sw4hdr)) != 0 && memcmp(header, sw5hdr, sizeof(sw5hdr)) != 0) throw UT_IE_BOGUSDOCUMENT; streamRead(stream, cLen); streamRead(stream, nVersion); streamRead(stream, nFileFlags); streamRead(stream, nDocFlags); streamRead(stream, nRecSzPos); streamRead(stream, nDummy); streamRead(stream, nDummy16); streamRead(stream, cRedlineMode); streamRead(stream, nCompatVer); UT_DEBUGMSG(("SDW: clen %i nversion %i fileflags %i docflags %i recszpos %i readlinemode %i compatver %i\n", cLen, nVersion, nFileFlags, nDocFlags, nRecSzPos, cRedlineMode, nCompatVer)); // (see sw/source/core/sw3io/sw3doc.cxx line 700) if (nVersion >= SWG_MAJORVERSION && nCompatVer > 0) { // File is in a too new format throw UT_IE_BOGUSDOCUMENT; } streamRead(stream, cPasswd, 16); streamRead(stream, cSet); streamRead(stream, cGui); streamRead(stream, nDate); streamRead(stream, nTime); UT_DEBUGMSG(("SDW: nDate %u nTime %u\n", nDate, nTime)); // Find the name of the used encoding converter = findConverter(cSet); if (!UT_iconv_isValid(converter)) throw UT_ERROR; if (nFileFlags & SWGF_BLOCKNAME) { char buf[64]; streamRead(stream, buf, 64); UT_DEBUGMSG(("SDW: BLOCKNAME: %.64s\n", buf)); // XXX verify that the string is really null terminated sBlockName = reinterpret_cast<UT_UCS4Char*>(UT_convert_cd(buf, strlen(buf) + 1, converter, NULL, NULL)); } if (nRecSzPos != 0 && nVersion >= SWG_RECSIZES) { // Read the Recsizes // XXX to be done see sw/source/core/sw3io/sw3imp.cxx#L1070 UT_ASSERT_HARMLESS(UT_NOT_IMPLEMENTED); } if (nFileFlags & SWGF_BAD_FILE) throw UT_IE_BOGUSDOCUMENT; if (nFileFlags & SWGF_HAS_PASSWD) cryptor = new SDWCryptor(nDate, nTime, cPasswd); else cryptor = NULL; }
void Serializer::deserializeFromText(std::stringstream& input, const std::string& type, void* output) { std::string finalType = type; bool isPointer = isTypeAPointer(finalType); if(isPointer) { std::stringstream::pos_type pos = input.tellg(); char null[4]; input.read(null, 4); input.seekg(pos); if(std::string(null, 4) == "NULL") { void** a = (void**)output; void* b = NULL; *a = b; return; } } ReflectionClass* reflectionClass = Reflection::getInstance().getClassByTypeId(finalType); if(reflectionClass == NULL) { SerializerDataConverter* converter = findConverter(finalType); if(converter == NULL) { throw NoSerializeConverterFoundException("Unable to deserialize type " + finalType + "."); } if(isPointer) { void** a = (void**)output; void* b = converter->create(); *a = b; output = (void*)*(void**)output; } converter->convertFromText(input, output); return; } if(isPointer) { void** a = (void**)output; void* b = NULL; if(reflectionClass->getCTors().size() > 0) { const std::vector<ReflectionCTor*>& cTors = reflectionClass->getCTors(); for(unsigned int i=0; i<cTors.size(); ++i) { if(cTors[i]->getParams().size()==0) { b = cTors[i]->createInstance(); break; } } } *a = b; output = (void*)*(void**)output; } const std::vector<ReflectionMember*>& memberVars = reflectionClass->getMemberVars(); for(unsigned int i = 0; i < memberVars.size(); ++i) { char delimiter; if(i != 0) { input.read(&delimiter, 1); } ReflectionMember* member = memberVars[i]; void* currentDataSection = (void*)(((char*)output) + member->getOffset()); SerializerDataConverter* converter = findConverter(member->getTypeIdName()); if(converter == NULL) { deserializeFromText(input, member->getTypeIdName(), currentDataSection); } else { converter->convertFromText(input, currentDataSection); } } }
void Serializer::deserializeFromXML(const std::string& type, rapidxml::xml_node<>* root, void* output) { std::string finalType = type; bool isPointer = isTypeAPointer(finalType); if(isPointer) { rapidxml::xml_attribute<>* isNull = root->first_attribute("i:isnull"); if(isNull) { if(std::string(isNull->value(), isNull->value_size()) == "true") { void** a = (void**)output; void* b = NULL; *a = b; return; } } } ReflectionClass* reflectionClass = Reflection::getInstance().getClassByTypeId(finalType); if(reflectionClass == NULL) { SerializerDataConverter* converter = findConverter(finalType); if(converter == NULL) { throw NoSerializeConverterFoundException("Unable to deserialize type " + finalType + "."); } if(isPointer) { void** a = (void**)output; void* b = converter->create(); *a = b; output = (void*)*(void**)output; } converter->convertFromXML(output, false, *root); return; } if(isPointer) { void** a = (void**)output; void* b = NULL; if(reflectionClass->getCTors().size() > 0) { const std::vector<ReflectionCTor*>& cTors = reflectionClass->getCTors(); for(unsigned int i=0; i<cTors.size(); ++i) { if(cTors[i]->getParams().size()==0) { b = cTors[i]->createInstance(); break; } } } *a = b; output = (void*)*(void**)output; } const std::vector<ReflectionMember*>& memberVars = reflectionClass->getMemberVars(); for(unsigned int i = 0; i < memberVars.size(); ++i) { ReflectionMember* member = memberVars[i]; void* currentDataSection = (void*)(((char*)output) + member->getOffset()); rapidxml::xml_node<>* thisNode = root->first_node(member->getName().c_str()); if(!thisNode) { throw SerializationXmlNodeNotFoundException("The node \""+member->getName()+"\" was not found"); } SerializerDataConverter* converter = findConverter(member->getTypeIdName()); if(converter == NULL) { deserializeFromXML(member->getTypeIdName(), thisNode, currentDataSection); } else { converter->convertFromXML(currentDataSection, false, *thisNode); } } }