1 /*
2  * Copyright (C) 2002-2003 Fhg Fokus
3  *
4  * This file is part of SEMS, a free SIP media server.
5  *
6  * SEMS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version. This program is released under
10  * the GPL with the additional exemption that compiling, linking,
11  * and/or using OpenSSL is allowed.
12  *
13  * For a license to use the SEMS software under conditions
14  * other than those described here, or to purchase support for this
15  * software, please contact iptel.org by e-mail at the following addresses:
16  *    info@iptel.org
17  *
18  * SEMS is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26  */
27 #ifndef _AmSessionEventHandler_h
28 #define _AmSessionEventHandler_h
29 
30 #include "AmArg.h"
31 #include "AmSipMsg.h"
32 #include "AmSipEvent.h"
33 #include "AmSipDialog.h"
34 #include <string>
35 using std::string;
36 
37 class AmConfigReader;
38 
39 /**
40  * \brief Interface for SIP signaling plugins that
41  *        change requests or replies using hooks (ex: session timer).
42  *
43  *        From this type of plugins, an AmSessionEventHandler
44  *        can be added to an AmSession. AmSessionEventHandler functions
45  *        are called as hooks by the Session's event handler function.
46  *
47  *  Signaling plugins must inherit from this class.
48  */
49 class AmSessionEventHandler
50   : public AmObject
51 {
52 public:
53   bool destroy;
54 
AmSessionEventHandler()55   AmSessionEventHandler()
56     : destroy(true) {}
57 
~AmSessionEventHandler()58   virtual ~AmSessionEventHandler() {}
59 
60   /** Returns -1 on error, 0 else. */
configure(AmConfigReader & conf)61   virtual int configure(AmConfigReader& conf)
62   { return 0; }
63 
64   /*
65    * All the methods return true if the event processing
66    * shall be stopped after them.
67    */
process(AmEvent *)68   virtual bool process(AmEvent*)
69   { return false; }
70 
onSipRequest(const AmSipRequest & req)71   virtual bool onSipRequest(const AmSipRequest& req)
72   { return false; }
73 
onSipReply(const AmSipRequest & req,const AmSipReply & reply,AmBasicSipDialog::Status old_dlg_status)74   virtual bool onSipReply(const AmSipRequest& req,
75   			  const AmSipReply& reply,
76   			  AmBasicSipDialog::Status old_dlg_status)
77   { return false; }
78 
onSendRequest(AmSipRequest & req,int & flags)79   virtual bool onSendRequest(AmSipRequest& req, int& flags)
80   { return false; }
81 
onSendReply(const AmSipRequest & req,AmSipReply & reply,int & flags)82   virtual bool onSendReply(const AmSipRequest& req, AmSipReply& reply, int& flags)
83   { return false; }
84 
onRequestSent(const AmSipRequest & req)85   virtual void onRequestSent(const AmSipRequest& req) {}
86 
onReplySent(const AmSipRequest & req,const AmSipReply & reply)87   virtual void onReplySent(const AmSipRequest& req, const AmSipReply& reply) {}
88 
onRemoteDisappeared(const AmSipReply & reply)89   virtual void onRemoteDisappeared(const AmSipReply& reply) {}
90 
onLocalTerminate(const AmSipReply & reply)91   virtual void onLocalTerminate(const AmSipReply& reply) {}
92 
onFailure()93   virtual void onFailure() {}
94 };
95 
96 
97 #if __GNUC__ < 3
98 #define CALL_EVENT_H(method,args...) \
99             do{\
100                 vector<AmSessionEventHandler*>::iterator evh = ev_handlers.begin(); \
101                 bool stop = false; \
102                 while((evh != ev_handlers.end()) && !stop){ \
103                     stop = (*evh)->method( ##args ); \
104                     evh++; \
105 		} \
106 		if(stop) \
107                     return; \
108             }while(0)
109 #else
110 #define CALL_EVENT_H(method,...) \
111             do{\
112                 vector<AmSessionEventHandler*>::iterator evh = ev_handlers.begin(); \
113                 bool stop = false; \
114                 while((evh != ev_handlers.end()) && !stop){ \
115                     stop = (*evh)->method( __VA_ARGS__ ); \
116                     evh++; \
117 		} \
118 		if(stop) \
119                     return; \
120             }while(0)
121 #endif
122 
123 #endif
124