struct metadata * zht_lookup_meta(ZHTClient_c zhtClient, const char * key){ //1. Lookup in ZHT ZHTClient * zhtcppClient = (ZHTClient *) zhtClient; string keyStr(key); string resSerializedPackage; Package keyPackage; keyPackage.set_virtualpath(keyStr); //as key keyPackage.set_isdir(false); keyPackage.set_replicano(1); keyPackage.set_operation(1); //1 for look up, 2 for remove, 3 for insert int res = zhtcppClient->lookup(keyPackage.SerializeAsString(),resSerializedPackage); dbgprintf("Package Length:%i\n",resSerializedPackage.size()); //2. Parse Package and fill meta Package package; package.ParseFromString(resSerializedPackage); struct metadata* meta = (struct metadata*)malloc(sizeof(struct metadata)); //2.1 General file infos meta->key = package.virtualpath().c_str(); meta->k = package.k(); meta->m = package.m(); meta->bufsize = package.bufsize(); meta->fileSize = package.filesize(); meta->encodingLib = package.encodinglib(); //2.2 Locations meta->loc = (struct comLocations *) malloc(sizeof(struct comLocations)); struct comTransfer * current; struct comTransfer * prev = NULL; for (int j = package.location_size() -1 ; j >= 0; j--) { current = (struct comTransfer *) malloc(sizeof(struct comTransfer)); const Package_Location& location = package.location(j); //const std::string host = location.hostname(); current->hostName = (char *) malloc((location.hostname()).size()+1); strcpy(current->hostName,location.hostname().c_str()); current->port = location.port(); current->distantChunkName = (char *) malloc((location.distantchunkname()).size()+1); strcpy(current->distantChunkName,location.distantchunkname().c_str()); dbgprintf("Host (%i):%s - port: %i - chunkname: %s\n",j,location.hostname().c_str(),location.port(), location.distantchunkname().c_str()); current->next = prev; prev = current; } meta->loc->transfers = current; return meta; }
am_status_t LogService::addLogDetails(const std::string& logName, const LogRecord& record, const std::string& loggedByTokenID) { ScopeLock scopeLock(mLock); char logLevel[32]; am_status_t status = AM_SUCCESS; char *msg = NULL; std::string message = record.getLogMessage(); //The encoded log message needs to be in multiple of 4 bytes. msg = (char *)malloc(((message.size() * 4/3 + 1)/4+1)*4 + 4); if(msg != NULL) { encode_base64(message.c_str(), message.size(), msg); } else { status = AM_NO_MEMORY; } if (status == AM_SUCCESS) { if(!remoteBodyChunkListInitialized) { const std::size_t NUM_EXTRA_CHUNKS = 50; remoteRequest = new Request(*this, requestPrefixChunk, logRequestPrefixChunk, NUM_EXTRA_CHUNKS); if (remoteRequest != NULL) { remoteBodyChunkList = remoteRequest->getBodyChunkList(); remoteBodyChunkListInitialized = true; } } if(bufferCount >= 1) { remoteBodyChunkList.push_back(additionalRequestPrefixChunk); BodyChunk temp; char serviceIdBuf[1024]; if (remoteRequest != NULL) { remoteRequest->getNextServiceRequestIdAsString( serviceIdBuf, sizeof(serviceIdBuf)); } temp.data = serviceIdBuf; remoteBodyChunkList.push_back(temp); } sprintf(logLevel, "%d", record.getLogLevel()); remoteBodyChunkList.push_back(logLogPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(logName)); remoteBodyChunkList.push_back(logSidPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(loggedByTokenID)); remoteBodyChunkList.push_back(logLogSuffixChunk); remoteBodyChunkList.push_back(logRecordPrefixChunk); remoteBodyChunkList.push_back(logLevelPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(std::string(logLevel))); remoteBodyChunkList.push_back(logLevelSuffixChunk); remoteBodyChunkList.push_back(logRecMsgPrefixChunk); std::string t_mesg(msg); free(msg); Utils::expandEntityRefs(t_mesg); remoteBodyChunkList.push_back(BodyChunk(t_mesg)); remoteBodyChunkList.push_back(logRecMsgSuffixChunk); remoteBodyChunkList.push_back(logInfoMapPrefixChunk); const Properties &properties = record.getLogInfo(); Properties::const_iterator iter = properties.begin(); for(; iter != properties.end(); iter++) { const Properties::key_type &k_iter = iter->first; const Properties::mapped_type &v_iter = iter->second; std::string keyStr(""); keyStr = k_iter.c_str(); std::string valueStr(""); valueStr = v_iter.c_str(); remoteBodyChunkList.push_back(logInfoKeyPrefixChunk); remoteBodyChunkList.push_back(BodyChunk(keyStr)); remoteBodyChunkList.push_back(logInfoKeySuffixChunk); remoteBodyChunkList.push_back(logInfoValuePrefixChunk); remoteBodyChunkList.push_back(BodyChunk(valueStr)); remoteBodyChunkList.push_back(logInfoValueSuffixChunk); } remoteBodyChunkList.push_back(logInfoMapSuffixChunk); remoteBodyChunkList.push_back(logRecordSuffixChunk); remoteBodyChunkList.push_back(requestSuffixChunk); bufferCount++; } else { status = AM_NO_MEMORY; } return status; }
// 解密按钮 void CAesGroupDecryptDlg::OnBnClickedDecryptTest() { m_listBox1.ResetContent(); // 重置 m_listBox2.ResetContent(); CString CCipher,CKey; m_cipherEdit.GetWindowTextW(CCipher); m_keyEdit.GetWindowTextW(CKey); if(CCipher == "") MessageBox(_T("请输入128-bits的十六进制密文(32个字符)!"), _T("提示"), MB_ICONINFORMATION); else if(CKey == "") MessageBox(_T("请输入128-bits的十六进制密钥(32个字符)!"), _T("提示"), MB_ICONINFORMATION); else if(CCipher.GetLength() != 32) MessageBox(_T("密文长度不对,请输入32个十六进制字符!"), _T("提示"), MB_ICONINFORMATION); else if(CKey.GetLength() != 32) MessageBox(_T("密钥长度不对,请输入32个十六进制字符!"), _T("提示"), MB_ICONINFORMATION); else { // CString转化为string CT2CA pszCAS_key(CKey); string keyStr(pszCAS_key); CT2CA pszCAS_cipher(CCipher); string cipherStr(pszCAS_cipher); Aes aes; Byte cipher[16]; // 密文 Byte key[16]; // 密钥 Word w[4*(Nr+1)]; for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) { string s1 = keyStr.substr(i*8+j*2, 2); key[i*4+j] = strtol(s1.c_str(), NULL, 16); string s2 = cipherStr.substr(i*8+j*2, 2); cipher[i+j*4] = strtol(s2.c_str(), NULL, 16); } // 密钥扩展 aes.KeyExpansion(key, w); for(int i=0; i<4*(Nr+1); ++i) { CString temp; temp.Format(_T("w[%2d] = %08x"), i, w[i]); m_listBox2.AddString(temp); } // 16轮解密 Word k[4]; CString ik_sch(""); for(int i=0; i<4; ++i) { k[i] = w[4*Nr+i]; CString t; t.Format(_T("%08x"), k[i]); ik_sch += t; } m_listBox1.AddString(_T("round[ 0].iinput ")+CCipher); m_listBox1.AddString(_T("round[ 0].ik_sch ")+ik_sch); aes.AddRoundKey(cipher, k); CString tmp; for(int round=Nr-1; round>0; --round) { tmp.Format(_T("round[%3d].istart "), 10-round); m_listBox1.AddString(tmp + plainToCString(cipher)); aes.InvShiftRows(cipher); tmp.Format(_T("round[%3d].is_row "), 10-round); m_listBox1.AddString(tmp + plainToCString(cipher)); aes.InvSubBytes(cipher); tmp.Format(_T("round[%3d].is_box "), 10-round); m_listBox1.AddString(tmp + plainToCString(cipher)); ik_sch = ""; for(int i=0; i<4; ++i) { k[i] = w[4*round+i]; CString t; t.Format(_T("%08x"), k[i]); ik_sch += t; } tmp.Format(_T("round[%3d].ik_sch "), 10-round); m_listBox1.AddString(tmp + ik_sch); aes.AddRoundKey(cipher, k); tmp.Format(_T("round[%3d].ik_add "), 10-round); m_listBox1.AddString(tmp + plainToCString(cipher)); aes.InvMixColumns(cipher); } m_listBox1.AddString(_T("round[10].istart ") + plainToCString(cipher)); aes.InvSubBytes(cipher); m_listBox1.AddString(_T("round[10].is_box ") + plainToCString(cipher)); aes.InvShiftRows(cipher); m_listBox1.AddString(_T("round[10].is_row ") + plainToCString(cipher)); ik_sch = ""; for(int i=0; i<4; ++i) { k[i] = w[i]; CString t; t.Format(_T("%08x"), k[i]); ik_sch += t; } m_listBox1.AddString(_T("round[10].ik_sch ") + ik_sch); aes.AddRoundKey(cipher, k); CString ioutput = plainToCString(cipher); m_listBox1.AddString(_T("round[10].ioutput ") + ioutput); m_plainText.SetWindowText(ioutput); m_plainText.ShowWindow(SW_HIDE); m_plainText.ShowWindow(SW_SHOW); } }
//static MPtiKeyMappings* CBCTestKeymap::CreateKeyMapL() { TBuf<sizeof(Keys)/sizeof(TUint16)> keyStr(Keys); return CPtiKeyMappings::NewL(keyStr); }
//------------------------------------------------------------------------------ void SetEncryptionKey(const char * const key) { std::string keyStr (key); SettingsHolder::Instance().SetKey(keyStr); }
// // Writes the info dictionary into the OutputData File. The OutputData file is // then read in to compute the info_hash // void TorrentCreator::WriteTorrentInfoFile(vector<DataFile *> vDatafiles) { m_tempOutputFile.SetLength(0); m_tempOutputFile.SeekToBegin(); BDictionary infoDict; string key; BDictionaryItem *filesItem = NULL; BList *b_files = NULL; vector<BDictionary *> v_b_file_dict; vector<BDictionaryItem *> v_lengthItem; vector<BDictionaryItem *> v_pathItem; vector<BList *> v_b_pathlist; // IF there is only one file in the torrent if( vDatafiles.size() == 1 ) { DataFile *datafile = vDatafiles.front(); //Add lengthItem BInteger *fileLen = datafile->getBFileLen(); BDictionaryItem *lengthItem = new BDictionaryItem(); string key = "length"; lengthItem->addIntegerItem( fileLen, key ); infoDict.addItem( lengthItem ); v_lengthItem.push_back( lengthItem ); } // ELSE there are multiple files in the torrent else { filesItem = new BDictionaryItem; b_files = new BList; //b_files is a Blist of the BDictionaries b_file_dict. // FOR each file in the torrent for( vector<DataFile *>::iterator v_iter = vDatafiles.begin(); v_iter != vDatafiles.end(); v_iter++ ) { DataFile* datafile = *v_iter; BDictionary* b_file_dict = new BDictionary(); BInteger * fileLen = datafile->getBFileLen(); BDictionaryItem * lengthItem = new BDictionaryItem(); string key = "length"; lengthItem->addIntegerItem(fileLen, key); b_file_dict->addItem(lengthItem); v_lengthItem.push_back(lengthItem); BDictionaryItem * pathItem = new BDictionaryItem(); // path is a Blist of BStrings of //the directory hierarchy and the filename key = "path"; BList * b_pathlist = new BList(); vector <DataPath *> v_datapath = datafile->get_v_datapath(); vector<DataPath *>::iterator v_iter2; for(v_iter2 = v_datapath.begin(); v_iter2 != v_datapath.end( ) ; v_iter2++) { BString *dir = (*v_iter2)->GetBDir(); b_pathlist->addItem(dir); } //add filename to end of the pathlist BString *filename = datafile->getBFilename(); b_pathlist->addItem(filename); pathItem->addListItem(b_pathlist, key); v_b_pathlist.push_back(b_pathlist); b_file_dict->addItem(pathItem); v_pathItem.push_back(pathItem); b_files->addItem(b_file_dict); v_b_file_dict.push_back(b_file_dict); } key = "files"; filesItem->addListItem( b_files, key ); infoDict.addItem(filesItem); } BDictionaryItem *root_item = new BDictionaryItem(); key = "name"; BString *root = m_pIPData->GetBParentDataname(); root_item->addStringItem(root, key); infoDict.addItem(root_item); BDictionaryItem pieceLen; BInteger *plen = m_pIPData->GetBPieceLength(); key = "piece length"; pieceLen.addIntegerItem(plen, key); infoDict.addItem(&pieceLen); // Am not adding the hashes to the infoDict for it is UCHAR data that I do not want to // convert to a signed char or string data. infoDict.WritePartialEncodedData( &m_tempOutputFile ); key = "pieces"; BString keyStr(key); keyStr.WriteEncodedData( &m_tempOutputFile ); int pieces_size = (int)(m_vPieceHashes.size()) * 20; char aBuf[ sizeof(int)*8 + 1 ]; int nLen = sprintf( aBuf, "%d%c", pieces_size, ':' ); m_tempOutputFile.Write( aBuf, nLen ); UCHAR *pAllPieces = new UCHAR[ pieces_size ]; int pos =0; for( vector<UCHAR *>::iterator v_iter = m_vPieceHashes.begin(); v_iter != m_vPieceHashes.end(); v_iter++ ) { memcpy( &pAllPieces[pos], *v_iter, 20 ); pos += 20; } m_tempOutputFile.Write( pAllPieces, pieces_size ); delete pAllPieces; //end the info dictionary char end = 'e'; m_tempOutputFile.Write( &end, 1 ); delete root_item; for( vector <BList *>::iterator v_iter = v_b_pathlist.begin(); v_iter != v_b_pathlist.end(); v_iter++ ) { delete (*v_iter); } v_b_pathlist.clear(); vector <BDictionaryItem *>::iterator v_iter2; for( v_iter2 = v_pathItem.begin(); v_iter2 != v_pathItem.end(); v_iter2++) { delete (*v_iter2); } v_pathItem.clear(); for( v_iter2 = v_lengthItem.begin(); v_iter2 != v_lengthItem.end(); v_iter2++) { delete (*v_iter2); } v_lengthItem.clear(); vector <BDictionary *>::iterator v_iter4; for( v_iter4 = v_b_file_dict.begin(); v_iter4 != v_b_file_dict.end(); v_iter4++) { delete (*v_iter4); } v_b_file_dict.clear(); if (b_files != NULL) delete b_files; if (filesItem != NULL) delete filesItem; }
JBoolean JXTextMenuData::ParseNMShortcut ( JString* str, int* key, JXKeyModifiers* modifiers ) { JIndex i; JString keyStr(*str); modifiers->Clear(); // decode modifiers while (1) { JBoolean found = kJFalse; for (i=0; i<kNMModConvCount; i++) { if (keyStr.BeginsWith(kNMModConv[i].str) && keyStr.GetLength() > kNMModConv[i].strLength) { const JXModifierKey key = JXMenu::AdjustNMShortcutModifier(kNMModConv[i].key); if (!modifiers->Available(key)) { return kJFalse; } if (key != kNMModConv[i].key) { AdjustNMShortcutString(str, i, key); } keyStr.RemoveSubstring(1, kNMModConv[i].strLength); modifiers->SetState(key, kJTrue); found = kJTrue; break; } } if (!found) { break; } } // translate known name to single character for (i=0; i<kNMKeyConvCount; i++) { if (JStringCompare(keyStr, kNMKeyConv[i].str, kJFalse) == 0) { const int k = kNMKeyConv[i].key; if (0 < k && k <= (int) UCHAR_MAX) { const JCharacter s[2] = { k, '\0' }; keyStr = s; break; // extra processing below } else { *key = k; return kJTrue; } } } // check for single character const int c1 = (unsigned char) keyStr.GetFirstCharacter(); if (keyStr.GetLength() == 1) { if (!isalpha(c1) && !iscntrl(c1)) { // can't complain because of menu_strings file modifiers->SetState(kJXShiftKeyIndex, kJFalse); } *key = tolower(c1); return kJTrue; } // check for function key JSize fnIndex; if (c1 == 'F' && JString::ConvertToUInt(keyStr.GetCString()+1, &fnIndex) && 1 <= fnIndex && fnIndex <= 35) { *key = XK_F1 + fnIndex-1; return kJTrue; } // give up return kJFalse; }
bool APICALL DOMImplementationRegistryImpl::RegisterSerializer( const char * key, const spcIDOMSerializer & serializer ) { spcIUTF8String keyStr( IUTF8String_I::CreateUTF8String( key, AdobeXMPCommon::npos ) ); auto it = mSerializerMap.insert( std::pair< spcIUTF8String, spcIDOMSerializer >( keyStr, serializer ) ); return it.second; }