Skip to content

Commit

Permalink
enh: #4216: use std::string literals
Browse files Browse the repository at this point in the history
  • Loading branch information
obiltschnig committed Jan 30, 2024
1 parent 24b6af2 commit f83aea4
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 177 deletions.
31 changes: 17 additions & 14 deletions Foundation/src/LoggingFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "Poco/PatternFormatter.h"


using namespace std::string_literals;


namespace Poco {


Expand Down Expand Up @@ -84,37 +87,37 @@ LoggingFactory& LoggingFactory::defaultFactory()

void LoggingFactory::registerBuiltins()
{
_channelFactory.registerClass("AsyncChannel", new Instantiator<AsyncChannel, Channel>);
_channelFactory.registerClass("AsyncChannel"s, new Instantiator<AsyncChannel, Channel>);
#if defined(POCO_OS_FAMILY_WINDOWS)
_channelFactory.registerClass("ConsoleChannel", new Instantiator<WindowsConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel", new Instantiator<WindowsColorConsoleChannel, Channel>);
_channelFactory.registerClass("ConsoleChannel"s, new Instantiator<WindowsConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel"s, new Instantiator<WindowsColorConsoleChannel, Channel>);
#else
_channelFactory.registerClass("ConsoleChannel", new Instantiator<ConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel", new Instantiator<ColorConsoleChannel, Channel>);
_channelFactory.registerClass("ConsoleChannel"s, new Instantiator<ConsoleChannel, Channel>);
_channelFactory.registerClass("ColorConsoleChannel"s, new Instantiator<ColorConsoleChannel, Channel>);
#endif

#ifndef POCO_NO_FILECHANNEL
_channelFactory.registerClass("FileChannel", new Instantiator<FileChannel, Channel>);
_channelFactory.registerClass("SimpleFileChannel", new Instantiator<SimpleFileChannel, Channel>);
_channelFactory.registerClass("FileChannel"s, new Instantiator<FileChannel, Channel>);
_channelFactory.registerClass("SimpleFileChannel"s, new Instantiator<SimpleFileChannel, Channel>);
#endif
_channelFactory.registerClass("FormattingChannel", new Instantiator<FormattingChannel, Channel>);
_channelFactory.registerClass("FormattingChannel"s, new Instantiator<FormattingChannel, Channel>);
#ifndef POCO_NO_SPLITTERCHANNEL
_channelFactory.registerClass("SplitterChannel", new Instantiator<SplitterChannel, Channel>);
_channelFactory.registerClass("SplitterChannel"s, new Instantiator<SplitterChannel, Channel>);
#endif
_channelFactory.registerClass("NullChannel", new Instantiator<NullChannel, Channel>);
_channelFactory.registerClass("EventChannel", new Instantiator<EventChannel, Channel>);
_channelFactory.registerClass("NullChannel"s, new Instantiator<NullChannel, Channel>);
_channelFactory.registerClass("EventChannel"s, new Instantiator<EventChannel, Channel>);

#if defined(POCO_OS_FAMILY_UNIX)
#ifndef POCO_NO_SYSLOGCHANNEL
_channelFactory.registerClass("SyslogChannel", new Instantiator<SyslogChannel, Channel>);
_channelFactory.registerClass("SyslogChannel"s, new Instantiator<SyslogChannel, Channel>);
#endif
#endif

#if defined(POCO_OS_FAMILY_WINDOWS)
_channelFactory.registerClass("EventLogChannel", new Instantiator<EventLogChannel, Channel>);
_channelFactory.registerClass("EventLogChannel"s, new Instantiator<EventLogChannel, Channel>);
#endif

_formatterFactory.registerClass("PatternFormatter", new Instantiator<PatternFormatter, Formatter>);
_formatterFactory.registerClass("PatternFormatter"s, new Instantiator<PatternFormatter, Formatter>);
}


Expand Down
23 changes: 15 additions & 8 deletions Foundation/src/Path_UNIX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
#include <sys/types.h>
#include <climits>


#if !defined(POCO_VXWORKS)
#include <pwd.h>
#endif


#if POCO_OS == POCO_OS_MAC_OS_X
#include <mach-o/dyld.h>
#elif POCO_OS == POCO_OS_FREE_BSD
Expand All @@ -38,8 +40,13 @@
#define PATH_MAX 4096 // fallback
#endif


using namespace std::string_literals;


namespace Poco {


std::string PathImpl::selfImpl()
{
std::string path;
Expand Down Expand Up @@ -115,9 +122,9 @@ std::string PathImpl::homeImpl()
else return "/";
#else
std::string path;
if (EnvironmentImpl::hasImpl("HOME"))
if (EnvironmentImpl::hasImpl("HOME"s))
{
path = EnvironmentImpl::getImpl("HOME");
path = EnvironmentImpl::getImpl("HOME"s);
}
else
{
Expand Down Expand Up @@ -154,8 +161,8 @@ std::string PathImpl::configHomeImpl()
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME"))
path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME");
if (EnvironmentImpl::hasImpl("XDG_CONFIG_HOME"s))
path = EnvironmentImpl::getImpl("XDG_CONFIG_HOME"s);
if (!path.empty())
return path;

Expand All @@ -181,8 +188,8 @@ std::string PathImpl::dataHomeImpl()
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_DATA_HOME"))
path = EnvironmentImpl::getImpl("XDG_DATA_HOME");
if (EnvironmentImpl::hasImpl("XDG_DATA_HOME"s))
path = EnvironmentImpl::getImpl("XDG_DATA_HOME"s);
if (!path.empty())
return path;

Expand All @@ -208,8 +215,8 @@ std::string PathImpl::cacheHomeImpl()
return path;
#else
std::string path;
if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME"))
path = EnvironmentImpl::getImpl("XDG_CACHE_HOME");
if (EnvironmentImpl::hasImpl("XDG_CACHE_HOME"s))
path = EnvironmentImpl::getImpl("XDG_CACHE_HOME"s);
if (!path.empty())
return path;

Expand Down
5 changes: 4 additions & 1 deletion Net/src/HTTPServerConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#include <memory>


using namespace std::string_literals;


namespace Poco {
namespace Net {

Expand Down Expand Up @@ -73,7 +76,7 @@ void HTTPServerConnection::run()
response.setVersion(request.getVersion());
response.setKeepAlive(_pParams->getKeepAlive() && request.getKeepAlive() && session.canKeepAlive());
if (!server.empty())
response.set("Server", server);
response.set("Server"s, server);
try
{
session.requestTrailer().clear();
Expand Down
7 changes: 4 additions & 3 deletions Net/src/HTTPServerResponseImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ using Poco::StreamCopier;
using Poco::OpenFileException;
using Poco::DateTimeFormatter;
using Poco::DateTimeFormat;
using namespace std::string_literals;


namespace Poco {
Expand Down Expand Up @@ -112,7 +113,7 @@ void HTTPServerResponseImpl::sendFile(const std::string& path, const std::string
File f(path);
Timestamp dateTime = f.getLastModified();
File::FileSize length = f.getSize();
set("Last-Modified", DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
set("Last-Modified"s, DateTimeFormatter::format(dateTime, DateTimeFormat::HTTP_FORMAT));
#if defined(POCO_HAVE_INT64)
setContentLength64(length);
#else
Expand Down Expand Up @@ -159,7 +160,7 @@ void HTTPServerResponseImpl::redirect(const std::string& uri, HTTPStatus status)
setChunkedTransferEncoding(false);

setStatusAndReason(status);
set("Location", uri);
set("Location"s, uri);

_pStream = new HTTPHeaderOutputStream(_session);
write(*_pStream);
Expand All @@ -174,7 +175,7 @@ void HTTPServerResponseImpl::requireAuthentication(const std::string& realm)
std::string auth("Basic realm=\"");
auth.append(realm);
auth.append("\"");
set("WWW-Authenticate", auth);
set("WWW-Authenticate"s, auth);
}


Expand Down
13 changes: 7 additions & 6 deletions Net/src/HTTPStreamFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ using Poco::URIStreamFactory;
using Poco::URI;
using Poco::URIStreamOpener;
using Poco::UnbufferedStreamBuf;
using namespace std::string_literals;


namespace Poco {
Expand Down Expand Up @@ -115,11 +116,11 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
cred.authenticate(req, res);
}

req.set("User-Agent", Poco::format("poco/%d.%d.%d",
req.set("User-Agent"s, Poco::format("poco/%d.%d.%d"s,
(POCO_VERSION >> 24) & 0xFF,
(POCO_VERSION >> 16) & 0xFF,
(POCO_VERSION >> 8) & 0xFF));
req.set("Accept", "*/*");
req.set("Accept"s, "*/*"s);

pSession->sendRequest(req);
std::istream& rs = pSession->receiveResponse(res);
Expand All @@ -129,7 +130,7 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
if (moved)
{
resolvedURI.resolve(res.get("Location"));
resolvedURI.resolve(res.get("Location"s));
if (!username.empty())
{
resolvedURI.setUserInfo(username + ":" + password);
Expand All @@ -147,7 +148,7 @@ std::istream* HTTPStreamFactory::open(const URI& uri)
// URI of the proxy. The recipient is expected to repeat this
// single request via the proxy. 305 responses MUST only be generated by origin servers.
// only use for one single request!
proxyUri.resolve(res.get("Location"));
proxyUri.resolve(res.get("Location"s));
delete pSession;
pSession = 0;
retry = true; // only allow useproxy once
Expand All @@ -174,13 +175,13 @@ std::istream* HTTPStreamFactory::open(const URI& uri)

void HTTPStreamFactory::registerFactory()
{
URIStreamOpener::defaultOpener().registerStreamFactory("http", new HTTPStreamFactory);
URIStreamOpener::defaultOpener().registerStreamFactory("http"s, new HTTPStreamFactory);
}


void HTTPStreamFactory::unregisterFactory()
{
URIStreamOpener::defaultOpener().unregisterStreamFactory("http");
URIStreamOpener::defaultOpener().unregisterStreamFactory("http"s);
}


Expand Down
33 changes: 18 additions & 15 deletions Net/src/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
#include <sstream>


using namespace std::string_literals;


namespace Poco {
namespace Net {

Expand Down Expand Up @@ -192,19 +195,19 @@ int WebSocket::getMaxPayloadSize() const

WebSocketImpl* WebSocket::accept(HTTPServerRequest& request, HTTPServerResponse& response)
{
if (request.hasToken("Connection", "upgrade") && icompare(request.get("Upgrade", ""), "websocket") == 0)
if (request.hasToken("Connection"s, "upgrade"s) && icompare(request.get("Upgrade"s, ""s), "websocket"s) == 0)
{
std::string version = request.get("Sec-WebSocket-Version", "");
std::string version = request.get("Sec-WebSocket-Version"s, ""s);
if (version.empty()) throw WebSocketException("Missing Sec-WebSocket-Version in handshake request", WS_ERR_HANDSHAKE_NO_VERSION);
if (version != WEBSOCKET_VERSION) throw WebSocketException("Unsupported WebSocket version requested", version, WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION);
std::string key = request.get("Sec-WebSocket-Key", "");
std::string key = request.get("Sec-WebSocket-Key"s, ""s);
Poco::trimInPlace(key);
if (key.empty()) throw WebSocketException("Missing Sec-WebSocket-Key in handshake request", WS_ERR_HANDSHAKE_NO_KEY);

response.setStatusAndReason(HTTPResponse::HTTP_SWITCHING_PROTOCOLS);
response.set("Upgrade", "websocket");
response.set("Connection", "Upgrade");
response.set("Sec-WebSocket-Accept", computeAccept(key));
response.set("Upgrade"s, "websocket"s);
response.set("Connection"s, "Upgrade"s);
response.set("Sec-WebSocket-Accept"s, computeAccept(key));
response.setContentLength(HTTPResponse::UNKNOWN_CONTENT_LENGTH);
response.send().flush();

Expand All @@ -222,10 +225,10 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H
cs.proxyTunnel();
}
std::string key = createKey();
request.set("Connection", "Upgrade");
request.set("Upgrade", "websocket");
request.set("Sec-WebSocket-Version", WEBSOCKET_VERSION);
request.set("Sec-WebSocket-Key", key);
request.set("Connection"s, "Upgrade"s);
request.set("Upgrade"s, "websocket"s);
request.set("Sec-WebSocket-Version"s, WEBSOCKET_VERSION);
request.set("Sec-WebSocket-Key"s, key);
request.setChunkedTransferEncoding(false);
cs.setKeepAlive(true);
cs.sendRequest(request);
Expand Down Expand Up @@ -272,13 +275,13 @@ WebSocketImpl* WebSocket::connect(HTTPClientSession& cs, HTTPRequest& request, H

WebSocketImpl* WebSocket::completeHandshake(HTTPClientSession& cs, HTTPResponse& response, const std::string& key)
{
std::string connection = response.get("Connection", "");
if (Poco::icompare(connection, "Upgrade") != 0)
std::string connection = response.get("Connection"s, ""s);
if (Poco::icompare(connection, "Upgrade"s) != 0)
throw WebSocketException("No Connection: Upgrade header in handshake response", WS_ERR_NO_HANDSHAKE);
std::string upgrade = response.get("Upgrade", "");
if (Poco::icompare(upgrade, "websocket") != 0)
std::string upgrade = response.get("Upgrade"s, ""s);
if (Poco::icompare(upgrade, "websocket"s) != 0)
throw WebSocketException("No Upgrade: websocket header in handshake response", WS_ERR_NO_HANDSHAKE);
std::string accept = response.get("Sec-WebSocket-Accept", "");
std::string accept = response.get("Sec-WebSocket-Accept"s, ""s);
if (accept != computeAccept(key))
throw WebSocketException("Invalid or missing Sec-WebSocket-Accept header in handshake response", WS_ERR_HANDSHAKE_ACCEPT);
return new WebSocketImpl(static_cast<StreamSocketImpl*>(cs.detachSocket().impl()), cs, true);
Expand Down
Loading

0 comments on commit f83aea4

Please sign in to comment.