/* -*- C++ -*- */
/*
 * snmpkit_execpt: declaration of all the snmpkit exception classes
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later 
 * version.
 * 
 * This library 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.
 *
 * You should have received a copy of the GNU General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 *
 * See the AUTHORS file for a list of people who have hacked on 
 * this code. 
 * See the ChangeLog file for a list of changes.
 *
 */

#ifndef __SNMPKIT_EXCEPTIONS_H__
#define __SNMPKIT_EXCEPTIONS_H__

#include <string>

// All the base classes
class ProgrammerException{}; /* errors most likely caused by bad 
				programming. Programmer exceptions 
				should be caught before other types of 
				exceptions so that bad programming can 
				be caught quickly. */
class DecodeException{};
class BerException{};
class OidSeqException{};
class SNMPException{};
class SocketException{};
class FillerException{};
class UserException{};
class SessionException{};

class BerDecodeException:public DecodeException,public BerException{};

/* Although this is fundementally a decodding error is is first 
   and formost a programming error because we are calling a 
   constructor on a bad piece of data. */
class BerTagIncorrectException:public ProgrammerException,
			       public BerDecodeException{};
class BerNullTagException:public BerTagIncorrectException{};
class BerIntTagException:public BerTagIncorrectException{};
class BerCounterTagException:public BerTagIncorrectException{};
class BerTimeTickTagException:public BerTagIncorrectException{};
class BerStringTagException:public BerTagIncorrectException{};
class BerIPAddrTagException:public BerTagIncorrectException{};
class BerOidTagException:public BerTagIncorrectException{};
class BerSequenceTagException:public BerTagIncorrectException{};
class BerUnexpectedTagException:public BerTagIncorrectException{};

// The length of any ber type will not fit into a unsigned long
class BerLengthException:public BerDecodeException{};
class BerNullLengthExecption:public BerLengthException{};
class BerIntLengthExecption:public BerLengthException{};
class BerCounterLengthExecption:public BerLengthException{};
class BerTimeTickLengthExecption:public BerLengthException{};
class BerIPAddrLengthExecption:public BerLengthException{};

// Can't convert oid string
class BerBadOidException:public ProgrammerException,public BerException{};
// An OID cannot be converted to into a number
class BerOidBadSubOidException:public BerBadOidException{};
// No OIDs specified
class BerNoOidsException:public BerBadOidException{};

class OidSeqProgrammerException:
  public OidSeqException,public ProgrammerException{};
// tried to delete something that wasn't there
class OidSeqRemoveNotFoundException:public OidSeqProgrammerException{};
class OidSeqTagException:public OidSeqProgrammerException{};
// the ber sequence didn't follow the layout of an oidsequence
class OidSeqBadLayoutException:
  public DecodeException,public OidSeqException{};

class SNMPDecodeException:public SNMPException,public BerDecodeException{};
class SNMPNotResponseTagException:public SNMPDecodeException{};
class SNMPSeqnoNotIntException:public SNMPDecodeException{};
class SNMPStateNotIntException:public SNMPDecodeException{};
class SNMPFaultOidNotIntException:public SNMPDecodeException{};
class SNMPPacketNotSequenceException:public SNMPDecodeException{};
class SNMPRespNotSequenceException:public SNMPDecodeException{};
class SNMPBadOidException:public SNMPException{
  std::string oidstr;
public:
  inline SNMPBadOidException(std::string &strn):oidstr(strn){}
  inline int operator==(const std::string &otherstr){
    return otherstr==oidstr;}
  inline std::string &str(){return oidstr;}
};
class SNMPTransportException:public SNMPException{};
class SNMPNoResponseException:public SNMPTransportException{};
class SNMPSockError:public SocketException,public SNMPTransportException{};

class SyscallException{
  int errnum;
public:
  inline SyscallException(int err):errnum(err){}
  inline int error(){return errnum;}
};

class DebugFileException:public SyscallException{ 
public:
  inline DebugFileException(int err):SyscallException(err){}};

/* stat returned something weird when looking for a filename to 
   name the debug log */
class DebugFileStatException:public DebugFileException{
public: 
  inline DebugFileStatException(int err):DebugFileException(err){}};
// open returned something weird when opening the debug log
class DebugFileOpenException:public DebugFileException{
public: 
  inline DebugFileOpenException(int err):DebugFileException(err){}};

class ReceiverException:public SyscallException,public SocketException{
public:
  inline ReceiverException(int err):SyscallException(err){}};
/* select returned something weird when waiting for a packet or 
   a timeout */
class ReceiverSelectException:public ReceiverException{
public:
  inline ReceiverSelectException(int err):ReceiverException(err){}};
/* read error when reading a packet */
class ReceiverReadException:public ReceiverException{
public:
  inline ReceiverReadException(int err):ReceiverException(err){}};

class ReceiverCreateException:public ReceiverException{
public:
  inline ReceiverCreateException(int err):ReceiverException(err){}};

class SocketNoUDPException:public SocketException{};
class SocketCreateFailException:public SyscallException,
				public SocketException{
public:
  inline SocketCreateFailException(int err):SyscallException(err){}};
class SocketSendShortExecption:public SocketException{};

class FillerProgrammerException:
  public ProgrammerException,public FillerException{};
// tried to remove from an empty struct filler
class FillerRemoveEmptyException:public FillerProgrammerException{};
// tried to remove an item not in the container
class FillerRemoveNotFoundException:public FillerProgrammerException{};
// successfully removed table entry but oidseq is NULL
class FillerCorruptException:public FillerProgrammerException{};

class FillerDecodeException:
  public FillerException,public DecodeException{};
class FillerTypeMismatchException:public FillerDecodeException{};

class SessionHostspecException:public SessionException,
			       public UserException{};
class SessionCommunityException:public SessionHostspecException{};
class SessionBadRangeException:public SessionHostspecException{};
class SessionOctetOverflowException:public SessionHostspecException{};
class SessionBadSubnetException:public SessionHostspecException{};
class SessionNetbitsOverflowException:public SessionHostspecException{};
class SessionBadNetmaskException:public SessionHostspecException{};
class SessionHostNotFoundException:public SessionException{
  int errnum;
public:
  SessionHostNotFoundException(int er):errnum(er){}
  int error(){return errnum;}
};
class SessionThreadCreateException:public SyscallException,
			    public SessionException{
public:
  inline SessionThreadCreateException(int err):SyscallException(err){}
};  

class JoinerCreateException:public SessionThreadCreateException{
public:
  inline JoinerCreateException(int err):
    SessionThreadCreateException(err){}
};

class SessionWorkerCreateException:public SessionThreadCreateException{
public:
  inline SessionWorkerCreateException(int err):
    SessionThreadCreateException(err){}
};

#endif
