core/sip/transport.h
b5b216e0
 /*
00aa71fa
  * $Id: transport.h 1048 2008-07-15 18:48:07Z sayer $
b5b216e0
  *
  * Copyright (C) 2007 Raphael Coeffic
  *
7dcb7e2a
  * This file is part of SEMS, a free SIP media server.
b5b216e0
  *
7dcb7e2a
  * SEMS is free software; you can redistribute it and/or modify
b5b216e0
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 2 of the License, or
7dcb7e2a
  * (at your option) any later version. This program is released under
  * the GPL with the additional exemption that compiling, linking,
  * and/or using OpenSSL is allowed.
b5b216e0
  *
7dcb7e2a
  * For a license to use the SEMS software under conditions
b5b216e0
  * other than those described here, or to purchase support for this
  * software, please contact iptel.org by e-mail at the following addresses:
  *    info@iptel.org
  *
7dcb7e2a
  * SEMS is distributed in the hope that it will be useful,
b5b216e0
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License 
  * along with this program; if not, write to the Free Software 
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
274c6ec4
 #ifndef _transport_h_
 #define _transport_h_
 
00aa71fa
 #include "../AmThread.h"
b9cda79c
 #include "../atomic_types.h"
d31ef867
 #include <sys/socket.h>
274c6ec4
 
d31ef867
 #include <string>
274c6ec4
 using std::string;
 
c8bb6fd9
 #define DEFAULT_TCP_CONNECT_TIMEOUT 2000 /* 2 seconds */
 #define DEFAULT_TCP_IDLE_TIMEOUT 3600000 /* 1 hour */
 
d31ef867
 class trsp_socket
b9cda79c
     : public atomic_ref_cnt
274c6ec4
 {
f09bf23a
 public:
5de33efe
     enum socket_options {
04fc38ec
 	force_via_address       = (1 << 0),
 	force_outbound_if       = (1 << 1),
 	use_raw_sockets         = (1 << 2),
 	no_transport_in_contact = (1 << 3)
5de33efe
     };
 
f09bf23a
     static int log_level_raw_msgs;
     
d31ef867
 protected:
     // socket descriptor
     int sd;
274c6ec4
 
d31ef867
     // bound address
     sockaddr_storage addr;
 
     // bound IP
     string           ip;
 
     // bound port number
     unsigned short   port;
 
85c17d68
     // public IP (Via-HF)
     string      public_ip;
 
3c118eb2
     // internal interface number
47991b00
     unsigned short   if_num;
 
3c118eb2
     // network interface index
     unsigned int sys_if_idx;
 
5de33efe
     // ORed field of socket_option
     unsigned int socket_options;
 
d31ef867
 public:
3c118eb2
     trsp_socket(unsigned short if_num, unsigned int opts,
22976049
 		unsigned int sys_if_idx = 0, int sd = 0);
d31ef867
     virtual ~trsp_socket();
274c6ec4
 
     /**
d31ef867
      * Binds the transport socket to an address
274c6ec4
      * @return -1 if error(s) occured.
      */
     virtual int bind(const string& address, unsigned short port)=0;
 
eb80fbda
     /**
      * Getter for the transport name
      */
     virtual const char* get_transport() const = 0;
 
d31ef867
     /**
      * Getter for IP address
      */
680d40fb
     const char* get_ip() const;
d31ef867
     
     /**
      * Getter for the port number
      */
680d40fb
     unsigned short get_port() const;
d31ef867
 
85c17d68
     /**
      * Setter for public IP address
      */
     void set_public_ip(const string& ip);
     
     /**
      * Getter for advertised IP address
      * @return either bound IP or public IP
      */
     const char* get_advertised_ip() const;
 
d31ef867
     /**
      *  Getter for the socket descriptor
      */
680d40fb
     int get_sd() const;
d31ef867
 
47991b00
     /**
      * Getter for the interface number
      */
680d40fb
     unsigned short get_if() const;
 
     /**
      * Is the transport reliable?
      */
     virtual bool is_reliable() const { return false; }
47991b00
 
5de33efe
     /**
      * Checks for socket options
      */
680d40fb
     bool is_opt_set(unsigned int mask) const;
5de33efe
 
d31ef867
     /**
      * Copy the internal address into the given one (sa).
      */
680d40fb
     void copy_addr_to(sockaddr_storage* sa) const;
d31ef867
 
c60b508e
     /**
      * Match with the given address
      * @return true if address matches
      */
680d40fb
     bool match_addr(sockaddr_storage* other_addr) const;
c60b508e
 
274c6ec4
     /**
      * Sends a message.
      * @return -1 if error(s) occured.
      */
d3804ea5
     virtual int send(const sockaddr_storage* sa, const char* msg, 
 		     const int msg_len, unsigned int flags)=0;
d31ef867
 };
274c6ec4
 
d31ef867
 class transport: public AmThread
 {
 protected:
     trsp_socket* sock;
 
 public:
     transport(trsp_socket* sock): sock(sock) {}
     virtual ~transport();
274c6ec4
 };
 
 #endif
9c5124fd
 
 /** EMACS **
  * Local variables:
  * mode: c++
  * c-basic-offset: 4
  * End:
  */