Example #1
0
    void testEncode(const CString& in, const CString& expectedOut,
                    const CString& sformat) {
        CString::EEscape format = CString::ToEscape(sformat);
        CString out;

        SCOPED_TRACE("Format: " + sformat);

        // Encode, then decode again and check we still got the same string
        out = in.Escape_n(CString::EASCII, format);
        EXPECT_EQ(out, expectedOut);
        out = out.Escape_n(format, CString::EASCII);
        EXPECT_EQ(out, in);
    }
Example #2
0
bool CHTTPSock::PrintErrorPage(unsigned int uStatusId,
                               const CString& sStatusMsg,
                               const CString& sMessage) {
    if (SentHeader()) {
        DEBUG("PrintErrorPage(): Header was already sent");
        return false;
    }

    CString sPage =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n"
        "<!DOCTYPE html>\r\n"
        "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" "
        "xml:lang=\"en\">\r\n"
        "<head>\r\n"
        "<meta charset=\"UTF-8\"/>\r\n"
        "<title>" +
        CString(uStatusId) + " " + sStatusMsg.Escape_n(CString::EHTML) +
        "</title>\r\n"
        "</head>\r\n"
        "<body>\r\n"
        "<h1>" +
        sStatusMsg.Escape_n(CString::EHTML) +
        "</h1>\r\n"
        "<p>" +
        sMessage.Escape_n(CString::EHTML) +
        "</p>\r\n"
        "<hr/>\r\n"
        "<p>" +
        CZNC::GetTag(false, /* bHTML = */ true) +
        "</p>\r\n"
        "</body>\r\n"
        "</html>\r\n";

    PrintHeader(sPage.length(), "text/html; charset=utf-8", uStatusId,
                sStatusMsg);
    Write(sPage);
    Close(Csock::CLT_AFTERWRITE);

    return true;
}
Example #3
0
bool CHTTPSock::Redirect(const CString& sURL) {
    if (SentHeader()) {
        DEBUG("Redirect() - Header was already sent");
        return false;
    } else if (!sURL.StartsWith("/")) {
        // HTTP/1.1 only admits absolute URIs for the Location header.
        DEBUG("Redirect to relative URI [" + sURL + "] is not allowed.");
        return false;
    } else {
        CString location = m_sURIPrefix + sURL;

        DEBUG("- Redirect to [" << location
                                << "] with prefix [" + m_sURIPrefix + "]");
        AddHeader("Location", location);
        PrintErrorPage(302, "Found", "The document has moved <a href=\"" +
                                         location.Escape_n(CString::EHTML) +
                                         "\">here</a>.");

        return true;
    }
}
Example #4
0
/**
 * Shorthand for encoding a string for a URL.
 *
 * @param str String to be encoded
 * @return Encoded string
 */
CString urlencode(const CString& str)
{
	return str.Escape_n(CString::EASCII, CString::EURL);
}
Example #5
0
// GTest uses this function to output objects
static void PrintTo(const CString& s, std::ostream* o) {
    *o << '"' << s.Escape_n(CString::EASCII, CString::EDEBUG) << '"';
}