CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
cmlabs::html Namespace Reference

Functions

std::string DecodeHTML (std::string str)
 Decode HTML entities in a string (e.g.
std::string EncodeHTML (std::string str)
 Encode a plain string for safe embedding in HTML (e.g.
unsigned char HTML2Char (const char *str)
 Convert a single HTML entity (e.g.
bool GetMimeType (char *dest, const char *filename, uint32 maxsize)
 Look up the MIME type for a filename based on its extension.
bool GetMimeType (char *dest, const char *filename, uint32 maxsize, bool &isBinary)
 Look up the MIME type for a filename and report whether it is binary.
bool IsMimeBinary (const char *type)
 Determine whether a MIME type denotes binary content.
std::string GetUsernameFromURL (std::string url)
 Extract the username from a URL of the form scheme://user:pass@host/...
std::string GetPasswordFromURL (std::string url)
 Extract the password from a URL of the form scheme://user:pass@host/...
std::string GetAuthenticationFromURL (std::string url)
 Extract the full "user:pass" authentication section from a URL.
std::string GetHostFromURL (std::string url)
 Extract the host name (or IP literal) from a URL.
uint16 GetPortFromURL (std::string url)
 Extract the port number from a URL.
std::string GetProtocolFromURL (std::string url)
 Extract the protocol/scheme from a URL.
std::string GetURIFromURL (std::string url)
 Extract the URI (path plus query) from a URL.
bool HTML_UnitTest ()
 Self-contained unit test of the HTML/URL helpers.

Function Documentation

◆ DecodeHTML()

std::string cmlabs::html::DecodeHTML ( std::string str)

Decode HTML entities in a string (e.g.

"&amp;lt;" to "<", "&amp;#65;" to "A").

Parameters
strInput string possibly containing HTML entities.
Returns
The decoded plain-text string.

Definition at line 12 of file HTML.cpp.

References HTML2Char().

Referenced by cmlabs::PostSpec::contentFromXML(), HTML_UnitTest(), cmlabs::RESTParser::parseRequest(), cmlabs::HTTPRequest::parseURIParameters(), and cmlabs::RESTRequest::RESTRequest().

◆ EncodeHTML()

std::string cmlabs::html::EncodeHTML ( std::string str)

Encode a plain string for safe embedding in HTML (e.g.

"<" to "&amp;lt;").

Parameters
strInput plain-text string.
Returns
The entity-encoded string.

Definition at line 51 of file HTML.cpp.

Referenced by cmlabs::RESTRequest::getStorageMessageCopy(), HTML_UnitTest(), cmlabs::utils::TextJoinXML(), cmlabs::LogEntry::toXML(), cmlabs::PostSpec::toXML(), and cmlabs::ProcessInfoStruct::toXML().

◆ GetAuthenticationFromURL()

std::string cmlabs::html::GetAuthenticationFromURL ( std::string url)

Extract the full "user:pass" authentication section from a URL.

Parameters
urlFull URL string.
Returns
The "user:pass" text before the '@', or an empty string if absent.

Definition at line 279 of file HTML.cpp.

Referenced by GetPasswordFromURL(), and GetUsernameFromURL().

◆ GetHostFromURL()

std::string cmlabs::html::GetHostFromURL ( std::string url)

Extract the host name (or IP literal) from a URL.

Parameters
urlFull URL string.
Returns
The host portion without protocol, credentials, port or path.

Definition at line 291 of file HTML.cpp.

Referenced by cmlabs::NetworkChannel::createWebsocketConnection(), cmlabs::RESTHTTPCall::generateHTTPRequest(), HTML_UnitTest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), and cmlabs::NetworkManager::makeHTTPRequest().

◆ GetMimeType() [1/2]

bool cmlabs::html::GetMimeType ( char * dest,
const char * filename,
uint32 maxsize )

Look up the MIME type for a filename based on its extension.

Parameters
destCaller-provided buffer receiving the MIME type string (e.g. "text/html").
filenameFile name or path whose extension determines the type.
maxsizeCapacity of dest in bytes (output is truncated to fit).
Returns
true if a type was written (falls back to a default for unknown extensions), false on invalid arguments.

Definition at line 137 of file HTML.cpp.

References GetMimeType().

Referenced by cmlabs::HTTPReply::createFromFile(), GetMimeType(), and HTML_UnitTest().

◆ GetMimeType() [2/2]

bool cmlabs::html::GetMimeType ( char * dest,
const char * filename,
uint32 maxsize,
bool & isBinary )

Look up the MIME type for a filename and report whether it is binary.

Parameters
destCaller-provided buffer receiving the MIME type string.
filenameFile name or path whose extension determines the type.
maxsizeCapacity of dest in bytes.
isBinarySet to true when the content should be treated as binary (no text transformations, Content-Length required), false for text types.
Returns
true if a type was written, false on invalid arguments.

Definition at line 142 of file HTML.cpp.

References cmlabs::utils::strcpyavail(), and cmlabs::utils::TextEndsWith().

◆ GetPasswordFromURL()

std::string cmlabs::html::GetPasswordFromURL ( std::string url)

Extract the password from a URL of the form scheme://user:pass@host/...

Parameters
urlFull URL string.
Returns
The password, or an empty string if none is present.

Definition at line 267 of file HTML.cpp.

References GetAuthenticationFromURL().

◆ GetPortFromURL()

uint16 cmlabs::html::GetPortFromURL ( std::string url)

Extract the port number from a URL.

Parameters
urlFull URL string.
Returns
The explicit port if given; otherwise the scheme default (80 for http, 443 for https), or 0 if it cannot be determined.

Definition at line 314 of file HTML.cpp.

References cmlabs::utils::Ascii2Uint32().

Referenced by cmlabs::NetworkChannel::createWebsocketConnection(), HTML_UnitTest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), and cmlabs::NetworkManager::makeHTTPRequest().

◆ GetProtocolFromURL()

std::string cmlabs::html::GetProtocolFromURL ( std::string url)

Extract the protocol/scheme from a URL.

Parameters
urlFull URL string.
Returns
The scheme (e.g. "http", "https", "ws"), or an empty string if absent.

Definition at line 333 of file HTML.cpp.

Referenced by cmlabs::NetworkChannel::createWebsocketConnection(), HTML_UnitTest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), and cmlabs::NetworkManager::makeHTTPRequest().

◆ GetURIFromURL()

std::string cmlabs::html::GetURIFromURL ( std::string url)

Extract the URI (path plus query) from a URL.

Parameters
urlFull URL string.
Returns
The path starting at '/', including any query string; "/" if the URL has no explicit path.

Definition at line 348 of file HTML.cpp.

Referenced by cmlabs::NetworkChannel::createWebsocketConnection(), cmlabs::RESTHTTPCall::generateHTTPRequest(), HTML_UnitTest(), cmlabs::NetworkManager::makeHTTPRequest(), cmlabs::NetworkManager::makeHTTPRequest(), and cmlabs::NetworkManager::makeHTTPRequest().

◆ GetUsernameFromURL()

std::string cmlabs::html::GetUsernameFromURL ( std::string url)

Extract the username from a URL of the form scheme://user:pass@host/...

Parameters
urlFull URL string.
Returns
The username, or an empty string if none is present.

Definition at line 255 of file HTML.cpp.

References GetAuthenticationFromURL().

◆ HTML2Char()

unsigned char cmlabs::html::HTML2Char ( const char * str)

Convert a single HTML entity (e.g.

"&amp;amp;" or "&amp;#38;") to its character.

Parameters
strPointer to the entity text (starting at or after '&').
Returns
The decoded character, or 0 if the entity is not recognised.

Definition at line 90 of file HTML.cpp.

Referenced by DecodeHTML(), and HTML_UnitTest().

◆ HTML_UnitTest()

bool cmlabs::html::HTML_UnitTest ( )

◆ IsMimeBinary()

bool cmlabs::html::IsMimeBinary ( const char * type)

Determine whether a MIME type denotes binary content.

Parameters
typeMIME type string, e.g. "image/png".
Returns
true for binary types, false for textual types (text&#47;∗, JSON, XML, etc.).

Definition at line 130 of file HTML.cpp.

References cmlabs::utils::stristr().

Referenced by cmlabs::HTTPRequest::createMultipartRequest(), cmlabs::RESTHTTPCall::generateHTTPRequest(), and HTML_UnitTest().