ionflux.org | Impressum

TCPAuthClient.hpp

Go to the documentation of this file.
00001 #ifndef IONFLUX_TOOLS_TCPAUTHCLIENT
00002 #define IONFLUX_TOOLS_TCPAUTHCLIENT
00003 /* ==========================================================================
00004  * Ionflux Tools
00005  * Copyright (c) 2004 Joern P. Meier
00006  * mail@ionflux.org
00007  * --------------------------------------------------------------------------
00008  * TCPAuthClient.hpp                   Authenticated TCP client.
00009  * ==========================================================================
00010  * 
00011  * This file is part of Ionflux Tools.
00012  * 
00013  * Ionflux Tools is free software; you can redistribute it and/or modify it 
00014  * under the terms of the GNU General Public License as published by the Free
00015  * Software Foundation; either version 2 of the License, or (at  your option)
00016  * any later version.
00017  * 
00018  * Ionflux Tools is distributed in the hope that it will be useful, but 
00019  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
00020  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00021  * for more details.
00022  * 
00023  * You should have received a copy of the GNU General Public License
00024  * along with Ionflux Tools; if not, write to the Free Software Foundation, 
00025  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00026  * 
00027  * ========================================================================== */
00028 
00029 #include <string>
00030 #include <iostream>
00031 #include <vector>
00032 #include "ionflux/tools.hpp"
00033 #include "ionflux/TCPMessageClient.hpp"
00034 
00035 namespace Ionflux
00036 {
00037 
00038 namespace Tools
00039 {
00040 
00049 class TCPAuthClient
00050 : public TCPMessageClient
00051 {
00052     protected:
00054         std::string username;
00056         std::string password;
00058         unsigned int currentMsgID;
00059         
00069         virtual void onConnect(TCPRemotePeer &peer);
00070         
00082         virtual void onAuthMessage(TCPRemotePeer &peer);
00083         
00093         virtual void onAuthOK(TCPRemotePeer &peer);
00094         
00104         virtual void onAuthFailed(TCPRemotePeer &peer);
00105         
00106     public:
00107         using TCPClient::addConnection;
00108         
00110         static const std::string MAGIC_WORD;
00112         static const unsigned int AUTH_VERSION;
00114         static const unsigned int AUTH_VERSION_UPPER;
00116         static const unsigned int AUTH_VERSION_LOWER;
00118         static const int MSGID_HELLO;
00120         static const int MSGID_WELCOME;
00122         static const int MSGID_AUTH;
00124         static const int MSGID_AUTH_OK;
00126         static const int MSGID_AUTH_FAILED;
00128         static const int PS_WAIT_WELCOME;
00130         static const int PS_WAIT_AUTH_RESULT;
00132         static const int PS_AUTH_OK;
00133         
00138         TCPAuthClient();
00139         
00147         TCPAuthClient(bool initInteractive);
00148         
00158         TCPAuthClient(const std::string &initUsername, 
00159             const std::string &initPassword, bool initInteractive);
00160         
00165         virtual ~TCPAuthClient();
00166         
00177         virtual void onMessage(TCPRemotePeer &peer);
00178         
00187         virtual void onInvalidMessage(TCPRemotePeer &peer);
00188         
00195         virtual void broadcast(const std::string &bytes);
00196         
00209         virtual bool addConnection(const std::string &host, int port, 
00210             const std::string &connUser, const std::string &connPass);
00211         
00218         virtual void setUsername(const std::string& newUsername);
00219         
00226         virtual void setPassword(const std::string& newPassword);
00227         
00234         virtual void setCurrentMsgID(unsigned int newCurrentMsgID);
00235         
00240         virtual std::string getUsername();
00241         
00246         virtual void getPassword(std::string &target);
00247         
00252         virtual unsigned int getCurrentMsgID();
00253 };
00254 
00255 }
00256 
00257 }
00258 
00262 #endif

Generated on Tue Mar 14 20:58:30 2006 for Ionflux Tools Class Library (iftools) by  doxygen 1.4.6