AmSipDialog.h

Go to the documentation of this file.
00001 /*
00002  * $Id: AmSipDialog.h 923 2008-04-30 15:02:22Z sayer $
00003  *
00004  * Copyright (C) 2002-2003 Fhg Fokus
00005  *
00006  * This file is part of sems, a free SIP media server.
00007  *
00008  * sems is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License as published by
00010  * the Free Software Foundation; either version 2 of the License, or
00011  * (at your option) any later version
00012  *
00013  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * sems is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00028 #ifndef AmSipDialog_h
00029 #define AmSipDialog_h
00030 
00031 #include "AmSipMsg.h"
00032 
00033 #include <string>
00034 #include <vector>
00035 #include <map>
00036 using std::string;
00037 
00038 #define MAX_SER_KEY_LEN 30
00039 #define CONTACT_USER_PREFIX "sems"
00040 
00041 // flags which may be used when sending request/reply
00042 #define SIP_FLAGS_VERBATIM     1 // send request verbatim, 
00043                                  // i.e. modify as little as possible
00044 
00046 struct AmSipTransaction
00047 {
00048   string       method;
00049   unsigned int cseq;
00050 
00051   // last reply code
00052   // (sent or received)
00053   //int reply_code;
00054 
00055   AmSipTransaction(const string& method, unsigned int cseq)
00056     : method(method),
00057        cseq(cseq)
00058   {}
00059 
00060   AmSipTransaction()
00061   {}
00062 };
00063 
00064 typedef std::map<int,AmSipTransaction> TransMap;
00065 
00069 class AmSipDialogEventHandler 
00070 {
00071  public:
00072   virtual void onSendRequest(const string& method,
00073                              const string& content_type,
00074                              const string& body,
00075                              string& hdrs,
00076                              int flags,
00077                              unsigned int cseq)=0;
00078 
00079   virtual void onSendReply(const AmSipRequest& req,
00080                            unsigned int  code,
00081                            const string& reason,
00082                            const string& content_type,
00083                            const string& body,
00084                            string& hdrs,
00085                            int flags)=0;
00086 
00087   virtual ~AmSipDialogEventHandler() {};
00088 };
00089 
00093 class AmSipDialog
00094 {
00095   int status;
00096 
00097   TransMap uas_trans;
00098   TransMap uac_trans;
00099 
00100   AmSipDialogEventHandler* hdl;
00101   std::vector<string> route;        // record routing
00102 
00103   int updateStatusReply(const AmSipRequest& req, 
00104                         unsigned int code);
00105 
00106  public:
00107   enum Status {
00108         
00109     Disconnected=0,
00110     Pending,
00111     Connected,
00112     Disconnecting
00113   };
00114 
00115   static const char* status2str[4];
00116 
00117   string user;         // local user
00118   string domain;       // local domain
00119   string sip_ip;       // destination IP of first received message
00120   string sip_port;     // optional: SIP port
00121 
00122   string local_uri;    // local uri
00123   string remote_uri;   // remote uri
00124 
00125   string contact_uri;  // pre-calculated contact uri
00126 
00127   string callid;
00128   string remote_tag;
00129   string local_tag;
00130 
00131   string remote_party; // To/From
00132   string local_party;  // To/From
00133 
00134   string getRoute(); // record routing
00135   void   setRoute(const string& n_route);
00136 
00137   string next_hop;     // next_hop for t_uac_dlg
00138 
00139   int cseq;            // CSeq for next request
00140 
00141   char serKey[MAX_SER_KEY_LEN];      // opaque string returned by SER, when staring a T
00142   unsigned int serKeyLen;
00143 
00144   AmSipDialog(AmSipDialogEventHandler* h=0);
00145   ~AmSipDialog();
00146 
00147   bool   getUACTransPending() { return !uac_trans.empty(); }
00148   int    getStatus() { return status; }
00149   string getContactHdr();
00150 
00151   void updateStatus(const AmSipRequest& req);
00152   void updateStatus(const AmSipReply& reply);
00154   void updateStatusFromLocalRequest(const AmSipRequest& req);
00155 
00156   int reply(const AmSipRequest& req, // Ser's transaction key
00157             unsigned int  code, 
00158             const string& reason,
00159             const string& content_type = "",
00160             const string& body = "",
00161             const string& hdrs = "",
00162             int flags = 0);
00163 
00164   int sendRequest(const string& method, 
00165                   const string& content_type = "",
00166                   const string& body = "",
00167                   const string& hdrs = "",
00168                   int flags = 0);
00169     
00170   int bye();
00171   int cancel();
00172   int update(const string& hdrs);
00173   int reinvite(const string& hdrs,  
00174                const string& content_type,
00175                const string& body);
00176   int invite(const string& hdrs,  
00177              const string& content_type,
00178              const string& body);
00179   int refer(const string& refer_to);
00180   int transfer(const string& target);
00181   int drop();
00182 
00187   bool match_cancel(const AmSipRequest& cancel_req);
00188 
00192   string get_uac_trans_method(unsigned int cseq);
00193 
00194   static int reply_error(const AmSipRequest& req,
00195                          unsigned int  code, 
00196                          const string& reason,
00197                          const string& hdrs = "");
00198 };
00199 
00200 
00201 #endif

Generated on Fri May 16 12:02:05 2008 for SEMS by  doxygen 1.5.1
Home |  Recent changes |  Search |  Glossary |  Sitemap |  Login