bool DataVariantTextPlain::parse ( const Socket &sock, const std::chrono::milliseconds &timeout, std::string &str, const size_t leftBytes, const std::unordered_map<std::string, std::string> ¶ms, std::unordered_multimap<std::string, std::string> &data, std::unordered_multimap<std::string, FileIncoming> &files ) { if (str.empty() ) { return true; } for (size_t var_pos = 0, var_end = 0; std::string::npos != var_end; var_pos = var_end + 1) { // Поиск следующего параметра var_end = str.find('&', var_pos); // Поиск значения параметра size_t delimiter = str.find('=', var_pos); if (delimiter >= var_end) { // Получить имя параметра std::string var_name = str.substr(var_pos, std::string::npos != var_end ? var_end - var_pos : std::string::npos); // Сохранить параметр с пустым значением data.emplace(std::move(var_name), ""); } else { // Получить имя параметра std::string var_name = str.substr(var_pos, delimiter - var_pos); ++delimiter; // Получить значение параметра std::string var_value = str.substr(delimiter, std::string::npos != var_end ? var_end - delimiter : std::string::npos); // Сохранить параметр и значение data.emplace(std::move(var_name), std::move(var_value) ); } } str.clear(); return true; }
void rawFilesInfoToFilesIncoming(std::unordered_multimap<std::string, HttpServer::FileIncoming> &map, const Utils::raw_fileinfo raw[], const size_t count) { for (size_t i = 0; i < count; ++i) { map.emplace(raw[i].key ? raw[i].key : "", HttpServer::FileIncoming(raw[i].file_name, raw[i].file_type, raw[i].file_size) ); } }
bool parseCookies(const std::string &cookieHeader, std::unordered_multimap<std::string, std::string> &cookies) { if (cookieHeader.empty() ) { return true; } for (size_t cur_pos = 0, next_value; std::string::npos != cur_pos; cur_pos = next_value) { next_value = cookieHeader.find(';', cur_pos); size_t delimiter = cookieHeader.find('=', cur_pos); if (std::string::npos == delimiter || delimiter > next_value) { return false; } std::string key = cookieHeader.substr(cur_pos, delimiter - cur_pos); trim(key); key = urlDecode(key); ++delimiter; std::string value = cookieHeader.substr(delimiter, std::string::npos != next_value ? next_value - delimiter : next_value); trim(value); value = urlDecode(value); cookies.emplace(std::move(key), std::move(value) ); if (std::string::npos != next_value) { ++next_value; } } return true; }
void add( ID id, const POINTER& c ) { components.emplace( id, c ); }
void search_hierarchy_for_matches(DexMethod* bridge, DexMethod* bridgee) { /* * Direct reference. The only one if it's non-virtual. */ auto clstype = bridgee->get_class(); auto name = bridgee->get_name(); auto proto = bridgee->get_proto(); TRACE(BRIDGE, 5, " %s %s %s\n", SHOW(clstype), SHOW(name), SHOW(proto)); m_potential_bridgee_refs.emplace(MethodRef(clstype, name, proto), bridge); if (!bridgee->is_virtual()) return; /* * Search super classes * * A bridge method in a derived class may be referred to using the name * of a super class if a method with a matching signature is defined in * that super class. * * To build the set of potential matches, we accumulate potential refs in * maybe_refs, and when we find a matching signature in a super class, we * add everything in maybe_refs to the set. */ std::vector<std::pair<MethodRef, DexMethod*>> maybe_refs; for (auto super = type_class(type_class(clstype)->get_super_class()); super != nullptr; super = type_class(super->get_super_class())) { maybe_refs.emplace_back( MethodRef(super->get_type(), name, proto), bridge); for (auto vmethod : super->get_vmethods()) { if (signature_matches(bridgee, vmethod)) { for (auto DEBUG_ONLY refp : maybe_refs) { TRACE(BRIDGE, 5, " %s %s %s\n", SHOW(std::get<0>(refp.first)), SHOW(std::get<1>(refp.first)), SHOW(std::get<2>(refp.first))); } m_potential_bridgee_refs.insert(maybe_refs.begin(), maybe_refs.end()); maybe_refs.clear(); } } } /* * Search sub classes * * Easy. Any subclass can refer to the bridgee. */ TypeVector subclasses; get_all_children(clstype, subclasses); for (auto subclass : subclasses) { m_potential_bridgee_refs.emplace(MethodRef(subclass, name, proto), bridge); TRACE(BRIDGE, 5, " %s %s %s\n", SHOW(subclass), SHOW(name), SHOW(proto)); } }
/// Process data from bitcoind daemon (esp. RPC getrawmempool for live transactions) void daemonThreadFunc(BlockChain* blockChain) { leveldb::WriteBatch batch; while (true) { std::this_thread::sleep_for(std::chrono::seconds(1)); if (requestedQuit) break; if (!txCheck) continue; try { auto transactions = rpcClient->CallMethod("getrawmempool", Json::Value()); BlockInfo blockInfo; Hash256 latestBlock; { boost::lock_guard<boost::mutex> guard(chainMutex); latestBlock = currentChain.back(); auto blockInfoIt = blocks.find(latestBlock); if (blockInfoIt == blocks.end()) { continue; } blockInfo = blockInfoIt->second; } if (pendingPreviousBlock != latestBlock) { pendingPreviousBlock = latestBlock; // Broadcast new block for live update Json::Value blockResult; blockResult["item"] = "block"; convertBlock(blockResult, pendingPreviousBlock, blockInfo); websocket_server.broadcast_livetx(blockResult.toStyledString().c_str()); { boost::lock_guard<boost::mutex> guard(pendingTransactionsMutex); pendingTransactionIndices.clear(); pendingTransactions.clear(); pendingTransactionsByAddress.clear(); } } for (auto tx = transactions.begin(); tx != transactions.end(); ++tx) { Hash256 txHash; encodeHexString((uint8_t*) &txHash, 32, (*tx).asString(), true); batch.Clear(); { // Already exists? boost::unique_lock<boost::mutex> guard(pendingTransactionsMutex); if (pendingTransactionIndices.find(txHash) != pendingTransactionIndices.end()) continue; } { DbTransaction dbTx; Json::Value parameters(Json::arrayValue); parameters.append(*tx); auto rawTx = rpcClient->CallMethod("getrawtransaction", parameters); auto data = rawTx.asCString(); auto bufferLength = strlen(data) / 2; llvm::SmallVector<uint8_t, 65536> buffer; buffer.resize(bufferLength); encodeHexString(buffer.begin(), bufferLength, data); BlockChain::BlockTransaction tx2; if (!blockChain->processSingleTransaction(buffer.begin(), bufferLength, tx2)) assert("could not read tx" && false); assert(memcmp(tx2.transactionHash, &txHash, 32) == 0); uint64_t totalOutput = 0; bool needBroadcast = false; auto txIndex = dbHelper.txLoad(txHash, dbTx, NULL, NULL); if (txIndex == 0) { { boost::unique_lock<boost::mutex> guard(pendingTransactionsMutex); try { txIndex = processTransaction(batch, dbTx, tx2, time(NULL), false, &pendingTransactionIndices, &pendingTransactions); } catch (std::exception e) { batch.Clear(); continue; } } needBroadcast = true; dbHelper.txSave(batch, txHash, dbTx); db->Write(leveldb::WriteOptions(), &batch); } { boost::unique_lock<boost::mutex> guard(pendingTransactionsMutex); pendingTransactionIndices[txHash] = pendingTransactions.size(); pendingTransactions.emplace_back(txHash, dbTx); // lastPendingTransactions only holds last N items if (lastPendingTransactions.size() >= lastPendingTransactionsSize) lastPendingTransactions.pop_front(); lastPendingTransactions.emplace_back(txHash, dbTx); for (auto output = dbTx.outputs.begin(); output != dbTx.outputs.end(); ++output) { if (output->address.IsNull()) continue; totalOutput += output->value; pendingTransactionsByAddress.emplace(output->address, pendingTransactions.size() - 1); } for (auto input = dbTx.inputs.begin(); input != dbTx.inputs.end(); ++input) { if (input->address.IsNull()) continue; pendingTransactionsByAddress.emplace(input->address, pendingTransactions.size() - 1); } } if (needBroadcast) { Json::Value txResult; // Broadcast tx for live update txResult["item"] = "tx"; txResult["output"] = (double)totalOutput; char timeBuffer[65]; convertTime(dbTx.getBestTimeStamp(), timeBuffer, sizeof(timeBuffer)); txResult["time"] = timeBuffer; txResult["coinage_destroyed"] = dbTx.coinAgeDestroyed / 86400.0; txResult["hash"] = *tx; websocket_server.broadcast_livetx(txResult.toStyledString().c_str()); } } } } catch (std::exception e) { boost::lock_guard<boost::mutex> guard(pendingTransactionsMutex); pendingTransactionIndices.clear(); pendingTransactions.clear(); pendingTransactionsByAddress.clear(); printf("Error processing live transactions: %s!\n", e.what()); } } }
static void getIncomingVars( std::unordered_multimap<std::string, std::string> ¶ms, const std::string &uri ) { const size_t start = uri.find('?'); if (std::string::npos == start) { return; } const size_t finish = uri.find('#'); if (finish < start) { return; } for ( size_t var_pos = start + 1, var_end = 0; std::string::npos != var_end; var_pos = var_end + 1 ) { var_end = uri.find('&', var_pos); if (var_end > finish) { var_end = std::string::npos; } size_t delimiter = uri.find('=', var_pos); if (delimiter >= var_end) { std::string var_name = Utils::urlDecode( uri.substr( var_pos, std::string::npos != var_end ? var_end - var_pos : std::string::npos ) ); params.emplace( std::move(var_name), std::string() ); } else { std::string var_name = Utils::urlDecode( uri.substr( var_pos, delimiter - var_pos ) ); ++delimiter; std::string var_value = Utils::urlDecode( uri.substr( delimiter, std::string::npos != var_end ? var_end - delimiter : std::string::npos ) ); params.emplace( std::move(var_name), std::move(var_value) ); } } }