1 /********************************************************************************
2  *                              Nepenthes
3  *                        - finest collection -
4  *
5  *
6  *
7  * Copyright (C) 2005  Paul Baecher & Markus Koetter
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22  *
23  *
24  *             contact nepenthesdev@users.sourceforge.net
25  *
26  *******************************************************************************/
27 
28 /* $Id: Dialogue.hpp 2043 2005-10-04 15:59:52Z common $ */
29 
30 #ifndef HAVE_DIALOGUE_HPP
31 #define HAVE_DIALOGUE_HPP
32 
33 #include <string>
34 using namespace std;
35 
36 namespace nepenthes
37 {
38 
39 
40     class Module;
41     class Socket;
42     class Nepenthes;
43     class Message;
44 
45 	/**
46 	 */
47 	typedef enum
48 	{
49 		CL_DROP,
50 		CL_UNSURE,
51 		CL_READONLY,
52 		CL_ASSIGN,
53 		CL_ASSIGN_AND_DONE
54 	} ConsumeLevel;
55 
56 
57 
58 	/**
59 	 * whenever we want to interact with a Socket, we assign a Dialogue.
60 	 * the Dialogue implements the protocol the socket speaks
61 	 * multiple Dialogues can be assigned to a Socket
62 	 */
63     class Dialogue
64     {
65     public:
~Dialogue()66         virtual ~Dialogue(){};
67         virtual ConsumeLevel incomingData(Message * msg) = 0;
68         virtual ConsumeLevel outgoingData(Message * msg) = 0;
69         virtual ConsumeLevel handleTimeout(Message * msg) = 0;
70 
connectionEstablished()71 		virtual ConsumeLevel connectionEstablished()
72 		{
73 			return m_ConsumeLevel;
74 		};      // getsockopt()  == EISCONN || == 0 && m_Socket->getState() == SS_CONNECTING
75 
76         virtual ConsumeLevel connectionLost(Message * msg) = 0;      // recv < 0
77         virtual ConsumeLevel connectionShutdown(Message * msg) = 0;  // recv() == 0
getConsumeLevel()78         virtual ConsumeLevel getConsumeLevel()
79 		{
80 			return m_ConsumeLevel;
81 		}
setConsumeLevel(ConsumeLevel cl)82         virtual void setConsumeLevel(ConsumeLevel cl)
83 		{
84 			m_ConsumeLevel = cl;
85 		}
getDialogueName()86         virtual string getDialogueName()
87 		{
88 			return m_DialogueName;
89 		};
getDialogueDescription()90         virtual string getDialogueDescription()
91 		{
92 			return m_DialogueDescription;
93 		};
94 
getSocket()95 		virtual Socket *getSocket()
96 		{
97 			return m_Socket;
98 		}
99 
100 
101 		/**
102 		 */
dump()103 		virtual void dump()
104 		{// as some dialogues wont need this fn
105 			return;
106 		}
107 
108     protected:
109         Module      *m_Module;
110         Socket      *m_Socket;
111         Nepenthes   *m_Nepenthes;
112 
113         ConsumeLevel m_ConsumeLevel;
114         string      m_DialogueName;
115         string      m_DialogueDescription;
116 
117     };
118 
119 }
120 #endif
121