Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

TelnetChars.h

00001 #ifndef _STR_TelnetChars_H_  // -*-c++-*-
00002 
00003 /*
00004  * Copyright 2001-2002 by Eric M. Hopper <hopper@omnifarious.org>
00005  * 
00006  *     This program is free software; you can redistribute it and/or modify it
00007  *     under the terms of the GNU Lesser General Public License as published
00008  *     by the Free Software Foundation; either version 2 of the License, or
00009  *     (at your option) any later version.
00010  * 
00011  *     This program is distributed in the hope that it will be useful, but
00012  *     WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *     Lesser General Public License for more details.
00015  * 
00016  *     You should have received a copy of the GNU Lesser General Public
00017  *     License along with this program; if not, write to the Free Software
00018  *     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #ifdef __GNUG__
00022 #  pragma interface
00023 #endif
00024 
00025 /* $Header: /home/hopper/src/cvs/C++/StrMod/StrMod/TelnetChars.h,v 1.4 2002/11/25 05:40:05 hopper Exp $ */
00026 
00027 // For a log, see ../ChangLog
00028 
00029 #include <LCore/HopClTypes.h>
00030 
00031 #define _STR_TelnetChars_H_
00032 
00033 namespace strmod {
00034 namespace strmod {
00035 
00036 /** \class TelnetChars TelnetChars.h StrMod/TelnetChars.h
00037  * A class holding a bunch of telnet character constants.
00038  *
00039  * Perhaps this class should be a namespace instead.
00040  */
00041 class TelnetChars {
00042  public:
00043    typedef lcore::U1Byte U1Byte;
00044    static const U1Byte  TEOF = 236U;  //!< End Of File
00045    static const U1Byte  SUSP = 237U;  //!< Suspend process
00046    static const U1Byte ABORT = 238U;  //!< Abort process
00047    static const U1Byte   EOR = 239U;  //!< End Of Record
00048    static const U1Byte    SE = 240U;  //!< Suboption End
00049    static const U1Byte   NOP = 241U;  //!< No Operation
00050    static const U1Byte    DM = 242U;  //!< Data mark, use with Synch option, requires out-of-band data support
00051    static const U1Byte   BRK = 243U;  //!< Break  (often a long string of 0 bits in RS232)
00052    static const U1Byte    IP = 244U;  //!< Interrupt Process
00053    static const U1Byte    AO = 245U;  //!< Abort output
00054    static const U1Byte   AYT = 246U;  //!< Are You There?  Remote side expected to reply with 'Yes'
00055    static const U1Byte    EC = 247U;  //!< Erease Character  (like backspace)
00056    static const U1Byte    EL = 248U;  //!< Erase Line
00057    static const U1Byte    GA = 249U;  //!< Go Ahead (for half duplex (the default) connections)
00058    static const U1Byte    SB = 250U;  //!< Suboption Begin
00059    static const U1Byte  WILL = 251U;  //!< Sender wants to enable option for itself
00060    static const U1Byte  WONT = 252U;  //!< Sender wants to disable option for itself
00061    static const U1Byte    DO = 253U;  //!< Sender wants receiver to enable option
00062    static const U1Byte  DONT = 254U;  //!< Sender wants receiver to disable option
00063    static const U1Byte   IAC = 255U;  //!< Interpret As Command
00064 
00065    /** An enum of all the telnet single character commands.
00066     * This is here so that functions that expect a telnet special character
00067     * representing a telnet single character command can say that's what they
00068     * want instead of generically expecting a character and being upset when
00069     * it doesn't qualify.
00070     *
00071     * These are defined in RFCs <A HREF="http://info.internet.isi.edu/in-notes/rfc/files/rfc854.txt">854</A>,
00072     * <A HREF="http://info.internet.isi.edu/in-notes/rfc/files/rfc885.txt">885</A>,
00073     * and <A HREF="http://info.internet.isi.edu/in-notes/rfc/files/rfc1184.txt">1184</A>
00074     */
00075    enum Commands {
00076       C_EOF = TEOF,     //!< See TEOF
00077       C_SUSP = SUSP,    //!< See SUSP
00078       C_ABORT = ABORT,  //!< See ABORT
00079       C_EOR = EOR,      //!< See EOR
00080       C_NOP = NOP,      //!< See NOP
00081       C_DM = DM,        //!< See DM
00082       C_BRK = BRK,      //!< See BRK
00083       C_IP = IP,        //!< See IP
00084       C_AO = AO,        //!< See AO
00085       C_AYT = AYT,      //!< See AYT
00086       C_EC = EC,        //!< See EC
00087       C_EL = EL,        //!< See EL
00088       C_GA = GA         //!< See GA
00089    };
00090 
00091    /** Convert a character to an enum value in the Commands enum, if possible.
00092     * \param ch The character to be converted.
00093     * \param cmd The character's value in the Commands enum if conversion possible, no modification if not.
00094     * \return true if conversion successful, false if not.
00095     */
00096    inline static bool convertCharToCommand(U1Byte ch, Commands &cmd);
00097 
00098    /** An enum of all the different types of option negotiation there are.
00099     * This is here so that functions that expect an option negotiation
00100     * character can say that's what they want instead of generically expecting
00101     * a character and being upset when it's the wrong one.
00102     *
00103     * The telnet protocol is designed as a peer-to-peer protocol, and so
00104     * either side can initiate an option negotiation to enable or disable an
00105     * option for either half (or direction) of the conversation.  A request to
00106     * disable must always be honored, and a refusal to enable must always be
00107     * honored.
00108     */
00109    enum OptionNegotiations {
00110       O_WILL = WILL, //!< Sender wants to enable option for itself
00111       O_WONT = WONT, //!< Sender wants to disable option for itself
00112       O_DO = DO,     //!< Sender wants receiver to enable option
00113       O_DONT = DONT  //!< Sender wants receiver to disable option
00114    };
00115 
00116    /** Convert a character to an enum value in the OptionNegotiations enum, if possible.
00117     * \param ch The character to be converted.
00118     * \param opt The character's value in the OptionNegotiations enum if conversion possible, no modification if not.
00119     * \return true if conversion successful, false if not.
00120     */
00121    inline static bool convertCharToOptionNegotiation(U1Byte ch,
00122                                                      OptionNegotiations &opt);
00123 };
00124 
00125 //-----------------------------inline functions--------------------------------
00126 
00127 inline bool TelnetChars::convertCharToCommand(U1Byte ch,
00128                                               TelnetChars::Commands &cmd)
00129 {
00130    if (((ch >= C_EOF) && (ch <= C_EOR)) ||
00131        ((ch >= C_NOP) && (ch <= C_GA)))
00132    {
00133       cmd = static_cast<Commands>(ch);
00134       return true;
00135    }
00136    return false;
00137 }
00138 
00139 inline bool
00140 TelnetChars::convertCharToOptionNegotiation(
00141    U1Byte ch, TelnetChars::OptionNegotiations &opt
00142    )
00143 {
00144    if ((ch >= WILL) && (ch <= DONT))
00145    {
00146       opt = static_cast<OptionNegotiations>(ch);
00147       return true;
00148    }
00149    return false;
00150 }
00151 
00152 };  // namespace strmod
00153 };  // namespace strmod
00154 
00155 #endif

Generated on Wed Jan 29 00:32:44 2003 for libNet by doxygen1.3-rc1