lib/arch: Use std::string directly instead of String typedef

This commit is contained in:
Povilas Kanapickas 2020-05-30 14:41:35 +03:00
parent dbd10820c3
commit 6868491483
12 changed files with 40 additions and 49 deletions

View File

@ -19,6 +19,7 @@
#pragma once #pragma once
#include "arch/IArchDaemon.h" #include "arch/IArchDaemon.h"
#include <string>
#define ARCH_DAEMON ArchDaemonNone #define ARCH_DAEMON ArchDaemonNone

View File

@ -19,7 +19,7 @@
#pragma once #pragma once
#include "common/IInterface.h" #include "common/IInterface.h"
#include "base/String.h" #include <string>
//! Interface for architecture dependent daemonizing //! Interface for architecture dependent daemonizing
/*! /*!

View File

@ -18,8 +18,8 @@
#pragma once #pragma once
#include "base/String.h"
#include "common/IInterface.h" #include "common/IInterface.h"
#include <string>
class IScreen; class IScreen;
class INode; class INode;
@ -90,7 +90,7 @@ public:
*/ */
virtual std::string getToolTip() const = 0; virtual std::string getToolTip() const = 0;
virtual void updateStatus(INode*, const String& errorMsg) = 0; virtual void updateStatus(INode*, const std::string& errorMsg) = 0;
virtual void cleanup() {} virtual void cleanup() {}

View File

@ -28,8 +28,8 @@ class CurlFacade {
public: public:
CurlFacade(); CurlFacade();
~CurlFacade(); ~CurlFacade();
String get(const String& url); std::string get(const std::string& url);
String urlEncode(const String& url); std::string urlEncode(const std::string& url);
private: private:
CURL* m_curl; CURL* m_curl;
@ -39,15 +39,13 @@ private:
// ArchInternetUnix // ArchInternetUnix
// //
String std::string ArchInternetUnix::get(const std::string& url)
ArchInternetUnix::get(const String& url)
{ {
CurlFacade curl; CurlFacade curl;
return curl.get(url); return curl.get(url);
} }
String std::string ArchInternetUnix::urlEncode(const std::string& url)
ArchInternetUnix::urlEncode(const String& url)
{ {
CurlFacade curl; CurlFacade curl;
return curl.urlEncode(url); return curl.urlEncode(url);
@ -87,8 +85,7 @@ CurlFacade::~CurlFacade()
curl_global_cleanup(); curl_global_cleanup();
} }
String std::string CurlFacade::get(const std::string& url)
CurlFacade::get(const String& url)
{ {
curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(m_curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlWriteCallback); curl_easy_setopt(m_curl, CURLOPT_WRITEFUNCTION, curlWriteCallback);
@ -110,8 +107,7 @@ CurlFacade::get(const String& url)
return result; return result;
} }
String std::string CurlFacade::urlEncode(const std::string& url)
CurlFacade::urlEncode(const String& url)
{ {
char* resultCStr = curl_easy_escape(m_curl, url.c_str(), 0); char* resultCStr = curl_easy_escape(m_curl, url.c_str(), 0);

View File

@ -19,10 +19,10 @@
#define ARCH_INTERNET ArchInternetUnix #define ARCH_INTERNET ArchInternetUnix
#include "base/String.h" #include <string>
class ArchInternetUnix { class ArchInternetUnix {
public: public:
String get(const String& url); std::string get(const std::string& url);
String urlEncode(const String& url); std::string urlEncode(const std::string& url);
}; };

View File

@ -25,19 +25,19 @@
#include <Shlwapi.h> #include <Shlwapi.h>
struct WinINetUrl { struct WinINetUrl {
String m_scheme; std::string m_scheme;
String m_host; std::string m_host;
String m_path; std::string m_path;
INTERNET_PORT m_port; INTERNET_PORT m_port;
DWORD m_flags; DWORD m_flags;
}; };
class WinINetRequest { class WinINetRequest {
public: public:
WinINetRequest(const String& url); WinINetRequest(const std::string& url);
~WinINetRequest(); ~WinINetRequest();
String send(); std::string send();
void openSession(); void openSession();
void connect(); void connect();
void openRequest(); void openRequest();
@ -54,15 +54,13 @@ private:
// ArchInternetWindows // ArchInternetWindows
// //
String std::string ArchInternetWindows::get(const std::string& url)
ArchInternetWindows::get(const String& url)
{ {
WinINetRequest request(url); WinINetRequest request(url);
return request.send(); return request.send();
} }
String std::string ArchInternetWindows::urlEncode(const std::string& url)
ArchInternetWindows::urlEncode(const String& url)
{ {
TCHAR buffer[1024]; TCHAR buffer[1024];
DWORD bufferSize = sizeof(buffer); DWORD bufferSize = sizeof(buffer);
@ -71,7 +69,7 @@ ArchInternetWindows::urlEncode(const String& url)
throw XArch(new XArchEvalWindows()); throw XArch(new XArchEvalWindows());
} }
String result(buffer); std::string result(buffer);
// the win32 url encoding funcitons are pretty useless (to us) and only // the win32 url encoding funcitons are pretty useless (to us) and only
// escape "unsafe" chars, but not + or =, so we need to replace these // escape "unsafe" chars, but not + or =, so we need to replace these
@ -86,9 +84,9 @@ ArchInternetWindows::urlEncode(const String& url)
// WinINetRequest // WinINetRequest
// //
static WinINetUrl parseUrl(const String& url); static WinINetUrl parseUrl(const std::string& url);
WinINetRequest::WinINetRequest(const String& url) : WinINetRequest::WinINetRequest(const std::string& url) :
m_session(NULL), m_session(NULL),
m_connect(NULL), m_connect(NULL),
m_request(NULL), m_request(NULL),
@ -112,8 +110,7 @@ WinINetRequest::~WinINetRequest()
} }
} }
String std::string WinINetRequest::send()
WinINetRequest::send()
{ {
if (m_used) { if (m_used) {
throw XArch("class is one time use."); throw XArch("class is one time use.");
@ -124,7 +121,7 @@ WinINetRequest::send()
connect(); connect();
openRequest(); openRequest();
String headers("Content-Type: text/html"); std::string headers("Content-Type: text/html");
if (!HttpSendRequest(m_request, headers.c_str(), (DWORD)headers.length(), NULL, NULL)) { if (!HttpSendRequest(m_request, headers.c_str(), (DWORD)headers.length(), NULL, NULL)) {
throw XArch(new XArchEvalWindows()); throw XArch(new XArchEvalWindows());
} }
@ -142,8 +139,7 @@ WinINetRequest::send()
return result.str(); return result.str();
} }
void void WinINetRequest::openSession()
WinINetRequest::openSession()
{ {
std::stringstream userAgent; std::stringstream userAgent;
userAgent << "Barrier "; userAgent << "Barrier ";
@ -200,8 +196,7 @@ WinINetRequest::openRequest()
// nb: i tried to use InternetCrackUrl here, but couldn't quite get that to // nb: i tried to use InternetCrackUrl here, but couldn't quite get that to
// work. here's some (less robust) code to split the url into components. // work. here's some (less robust) code to split the url into components.
// this works fine with simple urls, but doesn't consider the full url spec. // this works fine with simple urls, but doesn't consider the full url spec.
static WinINetUrl static WinINetUrl parseUrl(const std::string& url)
parseUrl(const String& url)
{ {
WinINetUrl parsed; WinINetUrl parsed;
@ -215,7 +210,7 @@ parseUrl(const String& url)
parsed.m_port = INTERNET_DEFAULT_HTTP_PORT; parsed.m_port = INTERNET_DEFAULT_HTTP_PORT;
parsed.m_flags = 0; parsed.m_flags = 0;
if (parsed.m_scheme.find("https") != String::npos) { if (parsed.m_scheme.find("https") != std::string::npos) {
parsed.m_port = INTERNET_DEFAULT_HTTPS_PORT; parsed.m_port = INTERNET_DEFAULT_HTTPS_PORT;
parsed.m_flags = INTERNET_FLAG_SECURE; parsed.m_flags = INTERNET_FLAG_SECURE;
} }

View File

@ -19,10 +19,10 @@
#define ARCH_INTERNET ArchInternetWindows #define ARCH_INTERNET ArchInternetWindows
#include "base/String.h" #include <string>
class ArchInternetWindows { class ArchInternetWindows {
public: public:
String get(const String& url); std::string get(const std::string& url);
String urlEncode(const String& url); std::string urlEncode(const std::string& url);
}; };

View File

@ -431,7 +431,7 @@ ArchMiscWindows::wakeupDisplay()
bool bool
ArchMiscWindows::wasLaunchedAsService() ArchMiscWindows::wasLaunchedAsService()
{ {
String name; std::string name;
if (!getParentProcessName(name)) { if (!getParentProcessName(name)) {
LOG((CLOG_ERR "cannot determine if process was launched as service")); LOG((CLOG_ERR "cannot determine if process was launched as service"));
return false; return false;
@ -440,8 +440,7 @@ ArchMiscWindows::wasLaunchedAsService()
return (name == SERVICE_LAUNCHER); return (name == SERVICE_LAUNCHER);
} }
bool bool ArchMiscWindows::getParentProcessName(std::string &name)
ArchMiscWindows::getParentProcessName(String &name)
{ {
PROCESSENTRY32 parentEntry; PROCESSENTRY32 parentEntry;
if (!getParentProcessEntry(parentEntry)){ if (!getParentProcessEntry(parentEntry)){

View File

@ -21,7 +21,6 @@
#include "common/common.h" #include "common/common.h"
#include "common/stdstring.h" #include "common/stdstring.h"
#include "common/stdset.h" #include "common/stdset.h"
#include "base/String.h"
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#include <Windows.h> #include <Windows.h>
@ -163,7 +162,7 @@ public:
static bool wasLaunchedAsService(); static bool wasLaunchedAsService();
//! Returns true if we got the parent process name. //! Returns true if we got the parent process name.
static bool getParentProcessName(String &name); static bool getParentProcessName(std::string &name);
static HINSTANCE instanceWin32(); static HINSTANCE instanceWin32();

View File

@ -18,7 +18,6 @@
#include "arch/win32/XArchWindows.h" #include "arch/win32/XArchWindows.h"
#include "arch/win32/ArchNetworkWinsock.h" #include "arch/win32/ArchNetworkWinsock.h"
#include "base/String.h"
// //
// XArchEvalWindows // XArchEvalWindows

View File

@ -20,6 +20,7 @@
#include "io/IStream.h" #include "io/IStream.h"
#include "base/Log.h" #include "base/Log.h"
#include "common/stdvector.h" #include "common/stdvector.h"
#include "base/String.h"
#include <cctype> #include <cctype>
#include <cstring> #include <cstring>

View File

@ -21,6 +21,7 @@
#include "arch/Arch.h" #include "arch/Arch.h"
#include "arch/IArchMultithread.h" #include "arch/IArchMultithread.h"
#include "base/ILogOutputter.h" #include "base/ILogOutputter.h"
#include "base/String.h"
#include "ipc/Ipc.h" #include "ipc/Ipc.h"
#include <deque> #include <deque>