Status & Roadmap
Authors & License
Funding U++
Search on this site

SourceForge.net Logo

SourceForge.net Logo

GitHub Logo

Discord Logo

Internet format utility functions


String WwwFormat(Time tm)

Returns Time in format defined by RFC2822, commonly used in HTTP and other internet protocol, like "Sun, 15 Apr 2012 16:00:25 GMT".



bool ScanWwwTime(const char *s, Time& tm)

Scans Time format as defined by RFC2822, returns true on success..



Time ScanWwwTime(const char *s)

Scans Time format as defined by RFC2822, returns Null on failure.



String MIMECharsetName(byte charset)

Returns U++ charset formatted as required by MIME.



String UrlEncode(const char *s, const char *end)

String UrlEncode(const char *s, int len)

String UrlEncode(const String& s)

Encodes data as required by MIME type application/x-www-form-urlencoded. ASCII alphanumeric characters and characters '.', '-', '_' are passed directly, space is represented by '+' and anything else as %HH, where HH is two digit hexadecimal number.



String UrlDecode(const char *s, const char *end)

String UrlDecode(const char *s, int len)

String UrlDecode(const String& s)

Decodes data as required by MIME type application/x-www-form-urlencoded (see UrlEncode).



String QPEncode(const char* s)

Encodes string to quoted-printable format.



String QPDecode(const char *s, bool underscore_to_space = false)

Decodes string from quoted-printable format. If s underscore_to_space is true, function replaces '_' with space ' ' (as required by encoded-word).



String Base64Encode(const char *b, const char *e)

String Base64Encode(const char *s, int len)

String Base64Encode(const String& data)

Encodes binary data into Base64 format.



String Base64Decode(const char *b, const char *e)

String Base64Decode(const char *s, int len)

String Base64Decode(const String& data)

Decodes binary data from Base64 format..



String DeHtml(const char *s)

Escapes characters '<', '>', '&', '\"' and characters < 31 as html entities and escapes character 31 as "&nbsp;".



const Index<String>& GetMIMETypes()

Returns a list of MIME types (known to U++).



String FileExtToMIME(const String& ext)

Converts the file extension to MIME type. ext can, but does not need to start with '.' (it is removed before searching).



String MIMEToFileExt(const String& mime)

Converts the MIME type to the most likely file extension (without '.' at begin).



bool HttpResponse(TcpSocket& socket, bool scgi, int code, const char *phrase, const char *content_type = NULL, const String& data = Null, const char *server = NULL, bool gzip = false)

This function sends simple HTTP response over socket. If scgi is true, first line of response is formatted for SCGI (rest is the same for normal HTTP and SCGI). code and phrase set the first line of response, content_type sets the respective http header (if NULL, it is not send). If data is not empty, "content-length" header is sent and data is sent after the header. server sets the "server" field of http header, if not present, it is set to "U++ based server". If gzip is true, function adds "content-encoding: gzip" header, but does NOT actually zip the content (that is up to caller).



Do you want to contribute?