bool CWizIndexBase::TagFromGUID(const CString& strTagGUID, WIZTAGDATA& data) { if (!strTagGUID || !*strTagGUID) { TOLOG(_T("TagGUID is empty")); return false; } CString strWhere; strWhere.Format(_T("TAG_GUID=%s"), STR2SQL(strTagGUID).utf16() ); CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_TAG, FIELD_LIST_WIZ_TAG, strWhere); CWizTagDataArray arrayTag; if (!SQLToTagDataArray(strSQL, arrayTag)) { TOLOG(_T("Failed to get tag by guid")); return false; } if (arrayTag.empty()) { //TOLOG(_T("Failed to get tag by guid, result is empty")); return false; } data = arrayTag[0]; return true; }
BOOL CWizKMDatabaseServer::attachment_getData2(const QString& strAttachmentGUID, UINT nParts, WIZDOCUMENTATTACHMENTDATAEX& ret) { WIZDOCUMENTATTACHMENTDATAEX wrap(ret); // CWizKMAttachmentGetDataParam param(WIZKM_WEBAPI_VERSION, m_kbInfo.strToken, m_kbInfo.strKbGUID, strAttachmentGUID, nParts); // if (!Call(_T("attachment.getData"), wrap, ¶m)) { TOLOG(_T("attachment.getData failure!")); return FALSE; } // ret = wrap; // if (nParts & WIZKM_XMKRPC_ATTACHMENT_PART_DATA) { ATLASSERT(!ret.arrayData.isEmpty()); if (!ret.arrayData.isEmpty()) { TOLOG(_T("fault error: ret.arrayData is null!")); return FALSE; } // if (!data_download(ret.strGUID, _T("attachment"), ret.arrayData, ret.strName)) { TOLOG1(_T("Failed to download attachment data: %1"), ret.strName); return FALSE; } } // // return TRUE; }
bool WizAESDecryptToFile(const unsigned char* cipher, \ QDataStream* inStream, const QString& strFileName) { Q_ASSERT(inStream->device()->isOpen()); QFile file(strFileName); if (file.exists()) { TOLOG("file already exist"); return false; } if (!file.open(QIODevice::ReadWrite)) { TOLOG("Can't open file"); return false; } QDataStream os(&file); if(!simpleAESDecrypt(cipher, inStream, &os)) { TOLOG("AES decrypt failed"); return false; } file.close(); return true; }
BOOL CWizXmlRpcArrayValue::Read(CWizXMLNode& nodeValue) { CWizXMLNode nodeData; if (!nodeValue.FindNodeByPath(_T("array/data"), nodeData)) { TOLOG(_T("Failed to get array data node!")); return FALSE; } // std::deque<CWizXMLNode> arrayValue; nodeData.GetAllChildNodes(arrayValue); // for (std::deque<CWizXMLNode>::iterator it = arrayValue.begin(); it != arrayValue.end(); it++) { CWizXMLNode& nodeElementValue = *it; // CWizXmlRpcValue* pElementValue = NULL; if (!WizXmlRpcValueFromXml(nodeElementValue, &pElementValue )) { TOLOG(_T("Failed to load array element value from node!")); return FALSE; } // ATLASSERT(pElementValue); // Add(pElementValue); } // return TRUE; }
bool CWizSearchIndexer::updateDocuments(const CWizDocumentDataArray& arrayDocuments) { Q_ASSERT(!arrayDocuments.empty()); void* pHandle = NULL; bool ret = WizFTSBeginUpdateDocument(m_strIndexPath.toStdWString().c_str(), &pHandle); if (!ret) { TOLOG("begin update failed while update FTS index"); return false; } int nErrors = 0; for (int i = 0; i < arrayDocuments.size(); i++) { WIZDOCUMENTDATAEX doc = arrayDocuments.at(i); if (!_updateDocumentImpl(pHandle, doc)) nErrors++; } ret = WizFTSEndUpdateDocument(pHandle); if (!ret) { TOLOG("end update failed while update FTS index"); return false; } if (nErrors >= 5) { return false; } return true; }
void CWizSync::on_kbSyncDone(bool bError) { if (bError) { m_bStarted = false; TOLOG(tr("Error occured while syncing, Try to syncing next time")); Q_EMIT syncDone(true); return; } if (!m_arrayGroup.size()) { m_bStarted = false; TOLOG(tr("Syncing finished")); Q_EMIT syncDone(false); return; } WIZGROUPDATA group(m_arrayGroup[0]); m_arrayGroup.erase(m_arrayGroup.begin()); // open group database for syncing if (!m_dbMgr.isOpened(group.strGroupGUID)) { m_bStarted = false; TOLOG(tr("FATAL: Can't open group database!")); Q_EMIT syncDone(false); return; } m_kbSync->setDatabase(m_dbMgr.db(group.strGroupGUID)); // reset db info and start sync group data TOLOG1(tr("Begin syncing group data: %1"), group.strGroupName); m_kbSync->startSync(group.strGroupGUID); }
bool CWizDatabaseManager::openAll() { // first, open private db if (!open()) { TOLOG("open user private database failed"); return false; } // second, get groups info CWizGroupDataArray arrayGroup; if (!m_dbPrivate->GetUserGroupInfo(arrayGroup)) { TOLOG("Failed to get user group info"); return true; } // third, open groups one by one CWizGroupDataArray::const_iterator it; for (it = arrayGroup.begin(); it != arrayGroup.end(); it++) { WIZGROUPDATA group = *it; if (!open(group.strGroupGUID)) { TOLOG1("failed to open group: %1", group.strGroupName); } } return true; }
bool CThumbIndex::AbstractIsExist(const CString& guid, const CString& type) { if(!m_dbThumb.IsOpened()) return false; CString sql = CString("select ") + "ABSTRACT_GUID" + " from " +TABLE_NAME_ABSTRACT+" where ABSTRACT_GUID='" +guid+ ("' AND ABSTRACT_TYPE=") +STR2SQL(type) +(";"); try { CppSQLite3Query query = m_dbThumb.execQuery(sql); while (!query.eof()) { return true; } return false; } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); TOLOG(sql); return false; } catch (...) { TOLOG("Unknown exception while close DB"); return false; } }
bool WizXmlRpcArrayValue::read(WizXMLNode& nodeValue) { WizXMLNode nodeData; if (!nodeValue.findNodeByPath("array/data", nodeData)) { TOLOG("Failed to get array data node!"); return false; } std::deque<WizXMLNode> arrayValue; nodeData.getAllChildNodes(arrayValue); std::deque<WizXMLNode>::iterator it; for (it = arrayValue.begin(); it != arrayValue.end(); it++) { WizXMLNode& nodeElementValue = *it; WizXmlRpcValue* pElementValue = NULL; if (!WizXmlRpcValueFromXml(nodeElementValue, &pElementValue)) { TOLOG("Failed to load array element value from node!"); return false; } Q_ASSERT(pElementValue); add(pElementValue); } return true; }
bool CWizIndexBase::AttachmentFromGUID(const CString& strAttachcmentGUID, WIZDOCUMENTATTACHMENTDATA& data) { if (strAttachcmentGUID.IsEmpty()) { TOLOG(_T("AttahcmentGUID is empty")); return false; } CString strWhere; strWhere.Format(_T("ATTACHMENT_GUID=%s"), STR2SQL(strAttachcmentGUID).utf16() ); CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_DOCUMENT_ATTACHMENT, FIELD_LIST_WIZ_DOCUMENT_ATTACHMENT, strWhere); CWizDocumentAttachmentDataArray arrayDocumentAttachment; if (!SQLToDocumentAttachmentDataArray(strSQL, arrayDocumentAttachment)) { TOLOG(_T("Failed to get attachment attachment by guid")); return false; } if (arrayDocumentAttachment.empty()) { //TOLOG(_T("Failed to get attachment by guid, result is empty")); return false; } data = arrayDocumentAttachment[0]; return true; }
bool CWizIndexBase::StyleFromGUID(const CString& strStyleGUID, WIZSTYLEDATA& data) { if (!strStyleGUID || !*strStyleGUID) { TOLOG(_T("StyleGUID is empty")); return false; } CString strWhere; strWhere.Format(_T("STYLE_GUID=%s"), STR2SQL(strStyleGUID).utf16() ); CString strSQL = FormatQuerySQL(TABLE_NAME_WIZ_STYLE, FIELD_LIST_WIZ_STYLE, strWhere); CWizStyleDataArray arrayStyle; if (!SQLToStyleDataArray(strSQL, arrayStyle)) { TOLOG(_T("Failed to get style by guid")); return false; } if (arrayStyle.empty()) { //TOLOG(_T("Failed to get style by guid, result is empty")); return false; } data = arrayStyle[0]; return true; }
bool CThumbIndex::OpenThumb(const CString& strFileName, const QString& strVersion) { if (m_dbThumb.IsOpened()) return true; try { m_dbThumb.open(strFileName); // need rebuild thumb index if (strVersion.isEmpty() || strVersion.toInt() < QString(WIZNOTE_THUMB_VERSION).toInt()) { if (m_dbThumb.tableExists("WIZ_ABSTRACT")) { m_dbThumb.execDML("drop table WIZ_ABSTRACT"); } } if (!InitThumbDB()) return false; return true; } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); return false; } catch (...) { TOLOG("Unknown exception while close DB"); return false; } }
bool CWizZiwReader::encryptDataToTempFile(const QString& sourceFileName, \ const QString& destFileName, \ const QString& strZiwCipher) { QFile sourceFile(sourceFileName); if (!sourceFile.open(QIODevice::ReadOnly)) { TOLOG("Can't open source file while encrypt to temp file"); return false; } // encrypt data QByteArray inBytes(sourceFile.readAll()); QByteArray outBytes; if (!WizAESEncryptToString((const unsigned char *)(strZiwCipher.toUtf8().constData()), inBytes, outBytes)) { return false; } // encrypt ziw cipher QByteArray encryptedZiwCipher; if (!encryptZiwCipher(strZiwCipher.toUtf8(), encryptedZiwCipher)) { return false; } // compose file // FIXME: hard coded here. WIZZIWHEADER header; memset(&header, 0, sizeof(header)); header.szSign[0] = 'Z'; header.szSign[1] = 'I'; header.szSign[2] = 'W'; header.szSign[3] = 'R'; header.nVersion = 1; header.nKeyLength = WIZZIWFILE_KEY_LENGTH; memcpy(header.szEncryptedKey, encryptedZiwCipher.constData(), sizeof(header.szEncryptedKey)); QFile destFile(destFileName); if (!destFile.open(QIODevice::WriteOnly | QIODevice::Truncate)) { TOLOG("Can't open dest file while encrypt to temp file"); return false; } QDataStream out(&destFile); if (sizeof(header) != out.writeRawData((const char *)&header, sizeof(header))) { TOLOG("Write data failed while encrypt to temp file"); destFile.remove(); return false; } if (outBytes.length() != out.writeRawData(outBytes.constData(), outBytes.length())) { TOLOG("Write data failed while encrypt to temp file"); destFile.remove(); return false; } destFile.close(); sourceFile.close(); return true; }
bool simpleRSADecrypt(const char* N, const char* e, const char* d, \ QDataStream* pStreamSrc, QDataStream* pStreamDest) { Q_ASSERT(pStreamSrc->device()->isOpen()); Q_ASSERT(pStreamDest->device()->isOpen()); pStreamSrc->device()->seek(0); pStreamDest->device()->seek(0); int nSrcLen = pStreamSrc->device()->size(); if (nSrcLen > 256) { TOLOG("nSrcLen > 256"); return false; } unsigned char src[256]; memset(src, 0, sizeof(src)); if (pStreamSrc->readRawData((char *)src, nSrcLen) != nSrcLen) { TOLOG("Input stream is not correct"); return false; } unsigned char ret[128]; memset(ret, 0, sizeof(ret)); CRSA enc; try { enc.initPrivateKey(N, e, d); } catch (std::exception& e) { TOLOG(e.what()); return false; } if (enc.getPlainLen(nSrcLen) > 117) { TOLOG("enc.getPlainLen(nSrcLen) > 117"); return false; } int nRetOlen = enc.decrypt(src, nSrcLen, ret); assert(nRetOlen < 117); if (pStreamDest->writeRawData((const char *)ret, nRetOlen) == -1) { TOLOG("WizStreamWrite(pStreamDest, ret, nRetOlen) failed"); return false; } pStreamDest->device()->seek(0); return true; }
bool WizXmlRpcResultFromXml(WizXMLDocument& doc, WizXmlRpcValue** ppRet) { WizXMLNode nodeMethodResponse; doc.findChildNode("methodResponse", nodeMethodResponse); if (nodeMethodResponse.isNull()) { TOLOG("Failed to get methodResponse node!"); return false; } WizXMLNode nodeTest; if (!nodeMethodResponse.getFirstChildNode(nodeTest)) { TOLOG("Failed to get methodResponse child node!"); return false; } QString strTestName = nodeTest.getName(); if (0 == strTestName.compare("params", Qt::CaseInsensitive)) { WizXMLNode nodeParamValue; nodeTest.findNodeByPath("param/value", nodeParamValue); if (nodeParamValue.isNull()) { TOLOG("Failed to get param value node of params!"); return false; } return WizXmlRpcValueFromXml(nodeParamValue, ppRet); } else if (0 == strTestName.compare("fault", Qt::CaseInsensitive)) { WizXMLNode nodeFaultValue; nodeTest.findChildNode("value", nodeFaultValue); if (nodeFaultValue.isNull()) { TOLOG("Failed to get fault value node!"); return false; } WizXmlRpcFaultValue* pFault = new WizXmlRpcFaultValue(); pFault->read(nodeFaultValue); *ppRet = pFault; return true; } else { TOLOG1("Unknown response node name: %1", strTestName); return false; } }
bool WizXmlRpcResultFromXml(CWizXMLDocument& doc, CWizXmlRpcValue** ppRet) { CWizXMLNode nodeMethodResponse; doc.FindChildNode("methodResponse", nodeMethodResponse); if (nodeMethodResponse.isNull()) { TOLOG("Failed to get methodResponse node!"); return false; } CWizXMLNode nodeTest; if (!nodeMethodResponse.GetFirstChildNode(nodeTest)) { TOLOG("Failed to get methodResponse child node!"); return false; } CString strTestName = nodeTest.GetName(); if (0 == strTestName.CompareNoCase("params")) { CWizXMLNode nodeParamValue; nodeTest.FindNodeByPath("param/value", nodeParamValue); if (nodeParamValue.isNull()) { TOLOG("Failed to get param value node of params!"); return false; } return WizXmlRpcValueFromXml(nodeParamValue, ppRet); } else if (0 == strTestName.CompareNoCase("fault")) { CWizXMLNode nodeFaultValue; nodeTest.FindChildNode(_T("value"), nodeFaultValue); if (nodeFaultValue.isNull()) { TOLOG("Failed to get fault value node!"); return false; } CWizXmlRpcFaultValue* pFault = new CWizXmlRpcFaultValue(); pFault->Read(nodeFaultValue); *ppRet = pFault; return true; } else { TOLOG1("Unknown response node name: %1", strTestName); return false; } }
void CWizZiwReader::debugPrintHeader() { TOLOG(m_header.szSign); TOLOG(QString::number(m_header.nVersion)); TOLOG(QString::number(m_header.nKeyLength)); //TOLOG(QString::fromStdString(base64_encode(m_header.szEncryptedKey, sizeof(m_header.szEncryptedKey)))); TOLOG("---------"); //TOLOG(QString::fromStdString(base64_encode(m_header.szReserved, sizeof(m_header.szReserved)))); }
bool CWizSearchIndexer::_updateDocumentImpl(void *pHandle, const WIZDOCUMENTDATAEX& doc) { CWizDatabase& db = m_dbMgr.db(doc.strKbGUID); db.setDocumentSearchIndexed(doc.strGUID, false); QString strFileName = db.GetDocumentFileName(doc.strGUID); // document data have not downloaded yet if (!QFile::exists(strFileName)) { return true; } // FIXME : deal with encrypted document if (doc.nProtected) { return true; } // decompress QString strDataFile; if (!db.DocumentToTempHtmlFile(doc, strDataFile)) { TOLOG("Can't decompress document while update FTS index: " + doc.strTitle); return false; } // get plain text content QString strHtmlData; if (!::WizLoadUnicodeTextFromFile(strDataFile, strHtmlData)) { TOLOG("Can't load document data while update FTS index:" + doc.strTitle); return false; } QString strPlainText; ::WizHtml2Text(strHtmlData, strPlainText); if (strPlainText.isEmpty()) { TOLOG("Html to text is failed: " + doc.strTitle); return false; } bool ret = WizFTSUpdateDocument(pHandle, \ doc.strKbGUID.toStdWString().c_str(), \ doc.strGUID.toStdWString().c_str(), \ doc.strTitle.toStdWString().c_str(), \ strPlainText.toStdWString().c_str()); if (ret) { db.setDocumentSearchIndexed(doc.strGUID, true); } return ret; }
void CWizFolder::MoveToLocation(const CString& strDestLocation) { Q_ASSERT(strDestLocation.right(1) == "/"); Q_ASSERT(strDestLocation.left(1) == "/"); if (!CanMove(Location(), strDestLocation)) return; CString strOldLocation = Location(); //CString strNewLocation; // //CString strLocationName = CWizDatabase::GetLocationName(strOldLocation); // //if (strDestLocation.IsEmpty()) { // strNewLocation = "/" + strLocationName + "/"; //} else { // strNewLocation = strDestLocation + strLocationName + "/"; //} CWizDocumentDataArray arrayDocument; if (!m_db.GetDocumentsByLocationIncludeSubFolders(strOldLocation, arrayDocument)) { TOLOG1(_T("Failed to get documents by location (include sub folders): %1"), strOldLocation); return; } CWizDocumentDataArray::const_iterator it; for (it = arrayDocument.begin(); it != arrayDocument.end(); it++) { WIZDOCUMENTDATA data = *it; Q_ASSERT(data.strLocation.startsWith(strOldLocation)); if (!data.strLocation.startsWith(strOldLocation)) { TOLOG(_T("Error location of document!")); continue; } data.strLocation.Delete(0, strOldLocation.GetLength()); data.strLocation.Insert(0, strDestLocation); if (!m_db.ModifyDocumentInfo(data)) { TOLOG(_T("Failed to move document to new folder!")); continue; } } m_db.LogDeletedFolder(strOldLocation); }
// 1 2 nfftdiv2 // re im re im re im // ((fft[1],0) (fft[2],fft[3]), (,), (,), (fft[nfft], 0)) nfft even // ((fft[1],0) (fft[2],fft[3]), (,), (,), (fft[nfft-1], fft[nfft])) nfft uneven static void complexfftoutput_to_power (double *fft, long nfft, double *dbs, bool to_db) { double valsq = fft[1] * fft[1]; dbs[1] = to_db ? TOLOG (valsq) : valsq; long nfftdiv2p1 = (nfft + 2) / 2; long nend = nfft % 2 == 0 ? nfftdiv2p1 : nfftdiv2p1 + 1; for (long i = 2; i < nend; i++) { double re = fft[i + i - 2], im = fft[i + i - 1]; valsq = re * re + im * im; dbs[i] = to_db ? TOLOG (valsq) : valsq; } if (nfft % 2 == 0) { valsq = fft[nfft] * fft[nfft]; dbs[nfftdiv2p1] = to_db ? TOLOG (valsq) : valsq; } }
bool CWizDatabaseManager::close(const QString& strKbGUID) { // should close all groups db before close user db. if (!m_dbGroups.isEmpty()) { Q_ASSERT(!strKbGUID.isEmpty()); } bool closed = false; QList<CWizDatabase*>::iterator it; for (it = m_dbGroups.begin(); it != m_dbGroups.end(); it++) { CWizDatabase* db = *it; if (db->kbGUID() == strKbGUID) { db->Close(); m_dbGroups.erase(it); closed = true; break; } } if (!closed && !strKbGUID.isEmpty()) { TOLOG("WARNING: nothing closed, guid not found"); return false; } Q_EMIT databaseClosed(strKbGUID); return true; }
void CWizSync::processObjectData(const WIZOBJECTDATA& data) { WIZOBJECTDATA conflictObjectData(data); conflictObjectData.strObjectGUID = WizGenGUIDLowerCaseLetterOnly(); conflictObjectData.strDisplayName += tr("(conflict backup)"); // set dirty flag, uploaded needed m_conflictDownloadedInfo.nVersion = -1; m_conflictDownloadedInfo.strGUID = conflictObjectData.strObjectGUID; m_conflictDownloadedInfo.strTitle += tr("(conflict backup)"); m_conflictDownloadedInfo.strInfoMD5 = m_db.CalDocumentInfoMD5(m_conflictDownloadedInfo); if (m_db.CreateDocumentEx(m_conflictDownloadedInfo)) { m_db.UpdateSyncObjectLocalData(conflictObjectData); TOLOG1(tr("Conflict backup created: %1"), m_conflictDownloadedInfo.strTitle); } else { TOLOG("unable to create conflict backup while create document"); } std::deque<WIZDOCUMENTDATABASE>::iterator it; for (it = m_arrayAllDocumentsNeedToBeDownloaded.begin(); \ it != m_arrayAllDocumentsNeedToBeDownloaded.end(); it++) { WIZDOCUMENTDATABASE data = *it; if (data.strGUID == m_conflictedDocument.strGUID) { m_arrayAllDocumentsNeedToBeDownloaded.erase(it); break; } } // chain back onQueryDocumentInfo(m_conflictedDocument); }
void CThumbIndex::CloseThumb() { if (!m_dbThumb.IsOpened()) return; // try { m_dbThumb.close(); } catch (const CppSQLite3Exception& e) { TOLOG(e.errorMessage()); } catch (...) { TOLOG("Unknown exception while close DB"); } }
bool CWizDatabase::SetUserName(const QString& strUserName) { CString strOld; GetUserName(strOld); if (!strOld.IsEmpty()) { TOLOG("Can not set user name: user name exists!"); return false; } if (!SetMeta(g_strAccountSection, _T("UserName"), strUserName)) { TOLOG("Failed to set user name while SetUserName"); return false; } return true; }
BOOL CWizKMDatabaseServer::document_postData2(const WIZDOCUMENTDATAEX& data, UINT nParts, __int64& nServerVersion) { QString strObjMd5; // if (!data.arrayData.isEmpty() && (nParts & WIZKM_XMKRPC_DOCUMENT_PART_DATA)) { strObjMd5 = WizMd5StringNoSpaceJava(data.arrayData); if (!data_upload(data.strGUID, _T("document"), data.arrayData, strObjMd5, data.strTitle)) { TOLOG1(_T("Failed to upload note data: %1"), data.strTitle); return FALSE; } } // CWizKMDocumentPostDataParam param(WIZKM_WEBAPI_VERSION, m_kbInfo.strToken, m_kbInfo.strKbGUID, data.strGUID, nParts, data, data.arrayTagGUID, data.arrayParam, strObjMd5); // CWizXmlRpcResult ret; if (!Call(_T("document.postData"), ret, ¶m)) { TOLOG(_T("document.postData failure!")); return FALSE; } // if (CWizXmlRpcStructValue* pRet = ret.GetResultValue<CWizXmlRpcStructValue>()) { pRet->GetInt64(_T("version"), nServerVersion); } // return TRUE; }
BOOL CWizKMDatabaseServer::document_getData2(const QString& strDocumentGUID, UINT nParts, WIZDOCUMENTDATAEX& ret) { WIZDOCUMENTDATAEX_XMLRPC_FULL wrap(ret); wrap.arrayData.clear(); // CWizKMDocumentGetDataParam param(WIZKM_WEBAPI_VERSION, m_kbInfo.strToken, m_kbInfo.strKbGUID, strDocumentGUID, nParts); if (!Call(_T("document.getData"), wrap, ¶m)) { TOLOG(_T("document.getData failure!")); return FALSE; } // ret = wrap; // BOOL bDownloadData = (nParts & WIZKM_XMKRPC_DOCUMENT_PART_DATA) ? TRUE : FALSE; // if (bDownloadData) { if (!data_download(ret.strGUID, _T("document"), ret.arrayData, ret.strTitle)) { TOLOG1(_T("Failed to download attachment data: %1"), ret.strTitle); return FALSE; } } // return TRUE; }
BOOL CWizKMDatabaseServer::data_download(const QString& strObjectGUID, const QString& strObjectType, QByteArray& stream, const QString& strDisplayName) { stream.clear(); // int nAllSize = 0; int startPos = 0; while (1) { int partSize = 500 * 1000; // BOOL bEOF = FALSE; if (!data_download(strObjectGUID, strObjectType, startPos, partSize, stream, nAllSize, bEOF)) { TOLOG(WizFormatString1(_T("Failed to download object part data: %1"), strDisplayName)); return FALSE; } // int nDownloadedSize = stream.size(); // if (bEOF) break; // startPos = nDownloadedSize; } // __int64 nStreamSize = stream.size(); if (nStreamSize != nAllSize) { TOLOG3(_T("Failed to download object data: %1, stream_size=%2, object_size=%3"), strDisplayName, WizInt64ToStr(nStreamSize), WizInt64ToStr(nAllSize)); return FALSE; } // return TRUE; }
BOOL CWizKMDatabaseServer::data_download(const QString& strObjectGUID, const QString& strObjectType, int pos, int size, QByteArray& stream, int& nAllSize, BOOL& bEOF) { CWizKMDataDownloadParam param(m_kbInfo.strToken, m_kbInfo.strKbGUID, strObjectGUID, strObjectType, pos, size); // WIZKMDATAPART part; if (!Call(_T("data.download"), part, ¶m)) { TOLOG(_T("data.download failure!")); return FALSE; } // __int64 nStreamSize = part.stream.size(); if (part.nPartSize != nStreamSize) { TOLOG2(_T("part size does not match: stream_size=%1, part_size=%2"), WizInt64ToStr(nStreamSize), WizInt64ToStr(part.nPartSize)); return FALSE; } // QString strStreamMD5 = WizMd5StringNoSpaceJava(part.stream); if (0 != strStreamMD5.compare(part.strPartMD5, Qt::CaseInsensitive)) { TOLOG2(_T("part md5 does not match, stream_md5=%1, part_md5=%2"), strStreamMD5, part.strPartMD5); return FALSE; } // nAllSize = (int)part.nObjectSize; bEOF = part.bEOF; // stream.append(part.stream); return TRUE; }
bool simpleRSAEncrypt(const char* N, const char* e, \ QDataStream* pStreamSrc, QDataStream* pStreamDest) { Q_ASSERT(pStreamSrc->device()->isOpen()); Q_ASSERT(pStreamDest->device()->isOpen()); pStreamSrc->device()->seek(0); pStreamDest->device()->seek(0); int nSrcLen = pStreamSrc->device()->size(); if (nSrcLen > 117) { TOLOG("nSrcLen > 117"); return false; } unsigned char src[128]; memset(src, 0, sizeof(src)); if (pStreamSrc->readRawData((char *)src, nSrcLen) != nSrcLen) { TOLOG("Input stream is not correct"); return false; } unsigned char ret[256]; memset(ret, 0, sizeof(ret)); CRSA enc; enc.initPublicKey(N, e); if (enc.getCipherLen(nSrcLen) >= 256) { TOLOG("enc.getCipherLen(nSrcLen) >= 256"); return false; } int nRetOlen = enc.encrypt(src, nSrcLen, ret); assert(nRetOlen <= 256); if (pStreamDest->writeRawData((const char *)ret, nRetOlen) == -1) { TOLOG("WizStreamWrite(pStreamDest, ret, nRetOlen) failed"); return false; } pStreamDest->device()->seek(0); return true; }
bool CWizXmlRpcStructValue::Read(CWizXMLNode& nodeValue) { CWizXMLNode nodeStruct; if (!nodeValue.FindChildNode(_T("struct"), nodeStruct)) { TOLOG(_T("Failed to get struct node!")); return FALSE; } // std::deque<CWizXMLNode> arrayMember; nodeStruct.GetAllChildNodes(arrayMember); // for (std::deque<CWizXMLNode>::iterator it = arrayMember.begin(); it != arrayMember.end(); it++) { CWizXMLNode& nodeMember = *it; // CString strName; if (!nodeMember.GetChildNodeText(_T("name"), strName)) { TOLOG(_T("Failed to get struct member name!")); return FALSE; } // CWizXMLNode nodeMemberValue; if (!nodeMember.FindChildNode(_T("value"), nodeMemberValue)) { TOLOG(_T("Failed to get struct member value!")); return FALSE; } // CWizXmlRpcValue* pMemberValue = NULL; if (!WizXmlRpcValueFromXml(nodeMemberValue, &pMemberValue)) { TOLOG(_T("Failed to load struct member value from node!")); return FALSE; } // ATLASSERT(pMemberValue); // AddValue(strName, pMemberValue); } // return TRUE; }