Exemplo n.º 1
0
int main(int argc,char *argv[])
{
    if (argc < 2)
        return -1;
    std::string str;
    std::string str2;
    Base64 b;
    if (!strcmp(argv[1],"-file"))
    {
        if (argc < 3)
            return -2;
        FILE *fil;
        if ((fil = fopen(argv[2],"rt")) != NULL)
        {
            b.encode(fil, str);
            fclose(fil);
        }
        printf("File:\n%s\n--End of File\n",str.c_str());
        b.decode(str, str2);
        printf("Content:\n%s\n--End of Content\n",str2.c_str());
    }
    else
    {
        b.encode(argv[1], strlen(argv[1]), str);
        printf("'%s' ==> '%s'",argv[1], str.c_str());
        b.decode(str, str2);
        printf(" ==> '%s'\n",str2.c_str());
    }
}
Exemplo n.º 2
0
void HttpdSocket::Send64(const std::string& str64, const std::string& type)
{
	Base64 bb;

	if (!strcasecmp(m_start.c_str(), m_if_modified_since.c_str()))
	{
		SetStatus("304");
		SetStatusText("Not Modified");
		SendResponse();
	}
	else
	{
		size_t len = bb.decode_length(str64);
		unsigned char *buf = new unsigned char[len];

		SetStatus("200");
		SetStatusText("OK");

		AddResponseHeader("Content-length", Utility::l2string( (long)len) );
		AddResponseHeader("Content-type", type );
		AddResponseHeader("Last-modified", m_start);
		SendResponse();

		bb.decode(str64, buf, len);
		SendBuf( (char *)buf, len);
		delete[] buf;
	}
}