From ede39aee7e00c40a43b67ca18dd8ab80ee863d85 Mon Sep 17 00:00:00 2001 From: Mason Reed Date: Tue, 26 Aug 2025 23:59:38 -0400 Subject: [WARP] Enhanced network support --- plugins/warp/ui/shared/fetcher.h | 85 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 plugins/warp/ui/shared/fetcher.h (limited to 'plugins/warp/ui/shared/fetcher.h') diff --git a/plugins/warp/ui/shared/fetcher.h b/plugins/warp/ui/shared/fetcher.h new file mode 100644 index 00000000..a7195ac4 --- /dev/null +++ b/plugins/warp/ui/shared/fetcher.h @@ -0,0 +1,85 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "warp.h" +#include "binaryninjaapi.h" +#include "uitypes.h" + +enum WarpFetchCompletionStatus +{ + KeepCallback, + RemoveCallback, +}; + +// Responsible for fetching data from the containers, to later be queried from the container interface. +class WarpFetcher +{ + LoggerRef m_logger; + + std::mutex m_requestMutex; + std::vector m_pendingRequests; + // TODO: Easy way to clear this if user wants to refetch. + std::unordered_set m_processedGuids; + + // List of callbacks to call when done fetching data, assume that others are using this as well. + std::vector > m_completionCallbacks; + +public: + explicit WarpFetcher(); + + // The global fetcher instance, this is used for the fetch dialog and the sidebar. + static std::shared_ptr Global(); + + std::atomic m_requestInProgress = false; + + // Set the allowed source tags, sources with none of these tags will not be fetched from. + void SetTags(const std::vector &tags) + { + std::lock_guard lock(m_requestMutex); + // TODO: This is kinda a hack, the fetcher instance should not sync through qt settings! + QStringList qtTags = {}; + for (const auto& t : tags) + qtTags.append(QString::fromStdString(t)); + QSettings().setValue("warp/allowedTags", qtTags); + } + + std::vector GetTags() const + { + std::lock_guard lock(const_cast(m_requestMutex)); + // TODO: This is kinda a hack, the fetcher instance should not sync through qt settings! + QSettings qtSettings; + QStringList tags = qtSettings.value("warp/allowedTags").toStringList(); + if (tags.isEmpty()) { + // The default tags to allow. + tags = QStringList{ "official", "trusted" }; + qtSettings.setValue("warp/allowedTags", tags); + qtSettings.sync(); + } + std::vector initialTags = {}; + for (const auto& t : tags) + initialTags.emplace_back(t.trimmed().toStdString()); + return initialTags; + } + + void AddCompletionCallback(std::function cb) + { + std::lock_guard lock(m_requestMutex); + m_completionCallbacks.push_back(std::move(cb)); + } + + void AddPendingFunction(const FunctionRef &func); + + void FetchPendingFunctions(); + + void ClearProcessed(); +private: + std::vector FlushPendingFunctions(); + + void ExecuteCompletionCallback(); +}; -- cgit v1.3.1