Status loginServerUploadLogs(Account *account) { const auto url = ABC_SERVER_ROOT "/v1/account/debug"; ServerRequestJson json; if (account) { json.setup(account->login); // Failure is fine JsonArray jsonArray; auto ids = account->wallets.list(); for (const auto &id: ids) { std::shared_ptr<Wallet> wallet = cacheWalletSoft(id); if (wallet) { const auto name = wallet->name(); logInfo("Wallet '" + name + "' " + id); const auto addresses = wallet->addresses.list(); for (const auto &address: addresses) logInfo(address); } DataChunk watchData; if (fileLoad(watchData, WalletPaths(id).cachePath())) { jsonArray.append( json_string(base64Encode(watchData).c_str())); } } json.set("watchers", jsonArray); // Failure is fine AutoFree<tABC_AccountSettings, accountSettingsFree> settings; settings.get() = accountSettingsLoad(*account); std::string servers(settings->szOverrideBitcoinServerList); std::string strOverride = (settings->bOverrideBitcoinServers ? "true" : "false"); logInfo("bOverrideBitcoinServers:" + strOverride); logInfo("szOverrideBitcoinServerList:" + servers); } DataChunk logData = debugLogLoad(); json.set("log", base64Encode(logData)); // Failure is fine HttpReply reply; ABC_CHECK(AirbitzRequest().post(reply, url, json.encode())); return Status(); }
bool ChmDoc::HasData(const char* fileName) { if (!fileName) return nullptr; AutoFree tmpName; if (!str::StartsWith(fileName, "/")) { tmpName.Set(str::Join("/", fileName)); fileName = tmpName; } else if (str::StartsWith(fileName, "///")) fileName += 2; struct chmUnitInfo info; return chm_resolve_object(chmHandle, fileName, &info) == CHM_RESOLVE_SUCCESS; }
Status syncMakeRepo(const std::string &syncDir) { AutoSyncLock lock(gSyncMutex); git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; opts.flags |= GIT_REPOSITORY_INIT_MKDIR; opts.flags |= GIT_REPOSITORY_INIT_MKPATH; AutoFree<git_repository, git_repository_free> repo; ABC_CHECK_GIT(git_repository_init_ext(&repo.get(), syncDir.c_str(), &opts)); return Status(); }
void ChmDoc::FixPathCodepage(AutoFree& path, UINT& fileCP) { if (!path || HasData(path)) return; AutoFree utf8Path(ToUtf8((unsigned char*)path.Get())); if (HasData(utf8Path)) { path.Set(utf8Path.StealData()); fileCP = codepage; } else if (fileCP != codepage) { utf8Path.Set(ToUtf8((unsigned char*)path.Get(), fileCP)); if (HasData(utf8Path)) { path.Set(utf8Path.StealData()); codepage = fileCP; } } }
Status syncRepo(const std::string &syncDir, const std::string &syncKey, bool &dirty) { AutoSyncLock lock(gSyncMutex); AutoFree<git_repository, git_repository_free> repo; ABC_CHECK_GIT(git_repository_open(&repo.get(), syncDir.c_str())); std::string url; ABC_CHECK(syncUrl(url, syncKey)); for (int i = 0; i < syncServers.size(); i++) { ABC_CHECK(syncUrl(url, syncKey, true)); if (sync_fetch(repo, url.c_str()) >= 0) { ABC_DebugLog("Syncing to: %s", url.c_str()); break; } else { ABC_DebugLog("FAIlED Syncing to: %s", url.c_str()); } } int files_changed, need_push; ABC_CHECK_GIT(sync_master(repo, &files_changed, &need_push)); if (need_push) ABC_CHECK_GIT(sync_push(repo, url.c_str())); // If this fails, the app has been shut down, leaving us for dead. // We will crash anyhow, but this at least makes it official: assert(gContext); dirty = !!files_changed; return Status(); }
/** * Create a label based off the user settings * * @param pszLabel The label will be returned in this parameter * @param pError A pointer to the location to store the error if there is one */ static tABC_CC ABC_TxBuildFromLabel(Wallet &self, const char **pszLabel, tABC_Error *pError) { tABC_CC cc = ABC_CC_Ok; ABC_SET_ERR_CODE(pError, ABC_CC_Ok); AutoFree<tABC_AccountSettings, ABC_FreeAccountSettings> pSettings; ABC_CHECK_NULL(pszLabel); *pszLabel = NULL; ABC_CHECK_RET(ABC_AccountSettingsLoad(self.account, &pSettings.get(), pError)); if (pSettings->bNameOnPayments && pSettings->szFullName) { *pszLabel = stringCopy(pSettings->szFullName); } exit: return cc; }
unsigned char* ChmDoc::GetData(const char* fileName, size_t* lenOut) { AutoFree fileNameTmp; if (!str::StartsWith(fileName, "/")) { fileNameTmp.Set(str::Join("/", fileName)); fileName = fileNameTmp; } else if (str::StartsWith(fileName, "///")) { fileName += 2; } struct chmUnitInfo info; int res = chm_resolve_object(chmHandle, fileName, &info); if (CHM_RESOLVE_SUCCESS != res && str::FindChar(fileName, '\\')) { // Microsoft's HTML Help CHM viewer tolerates backslashes in URLs fileNameTmp.SetCopy(fileName); str::TransChars(fileNameTmp, "\\", "/"); fileName = fileNameTmp; res = chm_resolve_object(chmHandle, fileName, &info); } if (CHM_RESOLVE_SUCCESS != res) return nullptr; size_t len = (size_t)info.length; if (len > 128 * 1024 * 1024) { // don't allow anything above 128 MB return nullptr; } // +1 for 0 terminator for C string compatibility ScopedMem<unsigned char> data((unsigned char*)malloc(len + 1)); if (!data) return nullptr; if (!chm_retrieve_object(chmHandle, &info, data.Get(), 0, len)) return nullptr; data[len] = '\0'; if (lenOut) *lenOut = len; return data.StealData(); }
Status AddressJson::unpack(Address &result) { Address out; // Main json: ABC_CHECK(indexOk()); out.index = index(); ABC_CHECK(addressOk()); out.address = address(); // State json: AddressStateJson stateJson = state(); out.recyclable = stateJson.recyclable(); out.time = stateJson.time(); // Details json: AutoFree<tABC_TxDetails, ABC_TxDetailsFree> pDetails; ABC_CHECK_OLD(ABC_TxDetailsDecode(get(), &pDetails.get(), &error)); out.metadata = TxMetadata(pDetails); result = std::move(out); return Status(); }
void HtmlPrettyPrintTest() { size_t lenOut; AutoFree data; data.Set(PrettyPrintHtml("<p><b>Test</b></p>", (size_t)-1, lenOut)); utassert(str::Len(data) == lenOut && str::Eq(data, "<p><b>Test</b></p>\n")); data.Set(PrettyPrintHtml("<p><b>Test</p>", (size_t)-1, lenOut)); utassert(str::Len(data) == lenOut && str::Eq(data, "<p><b>Test</p>\n")); data.Set(PrettyPrintHtml("<html><body><p>Content</p></body></html>", (size_t)-1, lenOut)); utassert(str::Len(data) == lenOut && str::Eq(data, "<html>\n\t<body>\n\t\t<p>Content</p>\n\t</body>\n</html>\n")); data.Set(PrettyPrintHtml("<html><body><p>Content</html></body>", (size_t)-1, lenOut)); // TODO: add newline before non-matching </html> ? // TODO: insert missing closing tags (</p> and </body>)? utassert(str::Len(data) == lenOut && str::Eq(data, "<html>\n\t<body>\n\t\t<p>Content</html>\n</body>\n")); data.Set(PrettyPrintHtml("<p attr=' value '><b> bold text </b> </p>", (size_t)-1, lenOut)); // TODO: normalize whitespace? utassert(str::Len(data) == lenOut && str::Eq(data, "<p attr=' value '><b> bold text </b></p>\n")); }