Webmaster  |  Imprint 
C++ Server Pages
Main  |  License  |  Documentation  |  Download 

/home/tommi/tntnet/framework/common/tnt/httperror.h

00001 /*
00002  * Copyright (C) 2003-2005 Tommi Maekitalo
00003  * 
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  * 
00009  * As a special exception, you may use this file as part of a free
00010  * software library without restriction. Specifically, if other files
00011  * instantiate templates or use macros or inline functions from this
00012  * file, or you compile this file and link it with other files to
00013  * produce an executable, this file does not by itself cause the
00014  * resulting executable to be covered by the GNU General Public
00015  * License. This exception does not however invalidate any other
00016  * reasons why the executable file might be covered by the GNU Library
00017  * General Public License.
00018  * 
00019  * This library is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00022  * Lesser General Public License for more details.
00023  * 
00024  * You should have received a copy of the GNU Lesser General Public
00025  * License along with this library; if not, write to the Free Software
00026  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00027  */
00028 
00029 
00030 #ifndef TNT_HTTPERROR_H
00031 #define TNT_HTTPERROR_H
00032 
00033 #include <stdexcept>
00034 #include <string>
00035 #include <tnt/httpmessage.h>
00036 
00037 namespace tnt
00038 {
00039   class HttpReturn
00040   {
00041       unsigned returncode;
00042       const char* msg;
00043 
00044     public:
00045       explicit HttpReturn(unsigned errcode);
00046       HttpReturn(unsigned errcode_, const char* msg_);
00047 
00048       unsigned getReturnCode() const
00049         { return returncode; }
00050 
00051       const char* getMessage() const
00052         { return msg; }
00053 
00054       static const char* httpMessage(unsigned httpstatus);
00055   };
00056 
00058   class HttpError : public std::exception, public HttpMessage
00059   {
00060       std::string msg;
00061       std::string body;
00062 
00063     public:
00064       explicit HttpError(unsigned errcode);
00065       HttpError(unsigned errcode, const std::string& msg);
00066       HttpError(unsigned errcode, const std::string& msg, const std::string& b);
00067       ~HttpError() throw() { }
00068 
00069       const char* what() const throw ()
00070       { return msg.c_str(); }
00071 
00072       std::string getErrcodeStr() const
00073       { return msg.substr(0, 3); }
00074 
00075       unsigned getErrcode() const
00076       {
00077         return (msg[0] - '0') * 100
00078              + (msg[1] - '0') * 10
00079              + (msg[2] - '0');
00080       }
00081 
00082       std::string getErrmsg() const;
00083 
00085       const std::string& getBody() const        { return body; }
00086   };
00087 
00089   class NotFoundException : public HttpError
00090   {
00091       std::string url;
00092 
00093     public:
00094       explicit NotFoundException(const std::string& url_);
00095       ~NotFoundException() throw() { }
00096 
00097       const std::string& getUrl() const  { return url; }
00098   };
00099 
00100   class NotAuthorized : public HttpError
00101   {
00102     public:
00103       explicit NotAuthorized(const std::string& realm);
00104   };
00105 
00106   class MovedTemporarily : public HttpError
00107   {
00108     public:
00109       explicit MovedTemporarily(const std::string& url);
00110   };
00111 }
00112 
00113 #endif // TNT_HTTPERROR_H
Copyright © 2008 The Tntnet Development Team
Tntnet 1.6