2002-08-02 19:57:46 +00:00
|
|
|
/*
|
|
|
|
* synergy -- mouse and keyboard sharing utility
|
|
|
|
* Copyright (C) 2002 Chris Schoeneman
|
|
|
|
*
|
|
|
|
* This package is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* found in the file COPYING that should have accompanied this file.
|
|
|
|
*
|
|
|
|
* This package is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2002-05-30 16:13:16 +00:00
|
|
|
#include "XHTTP.h"
|
|
|
|
#include "CHTTPProtocol.h"
|
2002-06-01 19:26:11 +00:00
|
|
|
#include "stdsstream.h"
|
2002-05-30 16:13:16 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// XHTTP
|
|
|
|
//
|
|
|
|
|
2002-06-17 13:31:21 +00:00
|
|
|
XHTTP::XHTTP(SInt32 statusCode) :
|
2002-06-10 22:06:45 +00:00
|
|
|
XBase(),
|
|
|
|
m_status(statusCode),
|
|
|
|
m_reason(getReason(statusCode))
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-17 13:31:21 +00:00
|
|
|
XHTTP::XHTTP(SInt32 statusCode, const CString& reasonPhrase) :
|
2002-06-10 22:06:45 +00:00
|
|
|
XBase(),
|
|
|
|
m_status(statusCode),
|
|
|
|
m_reason(reasonPhrase)
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
XHTTP::~XHTTP()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
SInt32
|
|
|
|
XHTTP::getStatus() const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
return m_status;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
|
|
|
XHTTP::getReason() const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
return m_reason;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
XHTTP::addHeaders(CHTTPReply&) const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
CString
|
|
|
|
XHTTP::getWhat() const throw()
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
2002-07-25 17:52:40 +00:00
|
|
|
const char* reason;
|
|
|
|
if (m_reason.empty()) {
|
|
|
|
reason = getReason(m_status);
|
2002-05-30 16:13:16 +00:00
|
|
|
}
|
2002-07-25 17:52:40 +00:00
|
|
|
else {
|
|
|
|
reason = m_reason.c_str();
|
2002-05-30 16:13:16 +00:00
|
|
|
}
|
2002-07-25 17:52:40 +00:00
|
|
|
return format("XHTTP", "%{1} %{2}",
|
|
|
|
CStringUtil::print("%d", m_status).c_str(),
|
|
|
|
reason);
|
2002-05-30 16:13:16 +00:00
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
const char*
|
2002-06-17 13:31:21 +00:00
|
|
|
XHTTP::getReason(SInt32 status)
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
switch (status) {
|
|
|
|
case 300: return "Multiple Choices";
|
|
|
|
case 301: return "Moved Permanently";
|
|
|
|
case 302: return "Moved Temporarily";
|
|
|
|
case 303: return "See Other";
|
|
|
|
case 304: return "Not Modified";
|
|
|
|
case 305: return "Use Proxy";
|
|
|
|
case 400: return "Bad Request";
|
|
|
|
case 401: return "Unauthorized";
|
|
|
|
case 402: return "Payment Required";
|
|
|
|
case 403: return "Forbidden";
|
|
|
|
case 404: return "Not Found";
|
|
|
|
case 405: return "Method Not Allowed";
|
|
|
|
case 406: return "Not Acceptable";
|
|
|
|
case 407: return "Proxy Authentication Required";
|
|
|
|
case 408: return "Request Time-out";
|
|
|
|
case 409: return "Conflict";
|
|
|
|
case 410: return "Gone";
|
|
|
|
case 411: return "Length Required";
|
|
|
|
case 412: return "Precondition Failed";
|
|
|
|
case 413: return "Request Entity Too Large";
|
|
|
|
case 414: return "Request-URI Too Large";
|
|
|
|
case 415: return "Unsupported Media Type";
|
|
|
|
case 500: return "Internal Server Error";
|
|
|
|
case 501: return "Not Implemented";
|
|
|
|
case 502: return "Bad Gateway";
|
|
|
|
case 503: return "Service Unavailable";
|
|
|
|
case 504: return "Gateway Time-out";
|
|
|
|
case 505: return "HTTP Version not supported";
|
|
|
|
default: return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// XHTTPAllow
|
|
|
|
//
|
|
|
|
|
2002-07-28 17:55:59 +00:00
|
|
|
XHTTPAllow::XHTTPAllow(const CString& allowedMethods) :
|
2002-06-10 22:06:45 +00:00
|
|
|
XHTTP(405),
|
2002-07-28 17:55:59 +00:00
|
|
|
m_allowed(allowedMethods)
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
XHTTPAllow::~XHTTPAllow()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
2002-06-17 13:31:21 +00:00
|
|
|
XHTTPAllow::addHeaders(CHTTPReply& reply) const
|
2002-05-30 16:13:16 +00:00
|
|
|
{
|
|
|
|
reply.m_headers.push_back(std::make_pair(CString("Allow"), m_allowed));
|
|
|
|
}
|