[svn-commits] oej: branch oej/videocaps r128559 - in /team/oej/videocaps: ./ channels/ conf...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Sun Jul 6 15:54:53 CDT 2008


Author: oej
Date: Sun Jul  6 15:54:52 2008
New Revision: 128559

URL: http://svn.digium.com/view/asterisk?view=rev&rev=128559
Log:
Reset automerge, resolve conflict.

(someone just killed the user... Weird)

Added:
    team/oej/videocaps/doc/realtimetext.txt
      - copied unchanged from r128491, trunk/doc/realtimetext.txt
Modified:
    team/oej/videocaps/   (props changed)
    team/oej/videocaps/channels/chan_sip.c
    team/oej/videocaps/configs/sip.conf.sample
    team/oej/videocaps/include/asterisk/channel.h
    team/oej/videocaps/include/asterisk/pbx.h
    team/oej/videocaps/main/cli.c
    team/oej/videocaps/main/manager.c
    team/oej/videocaps/main/pbx.c
    team/oej/videocaps/pbx/pbx_realtime.c
    team/oej/videocaps/res/res_agi.c

Propchange: team/oej/videocaps/
------------------------------------------------------------------------------
    automerge = http://www.codename-pineapple.org/

Propchange: team/oej/videocaps/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sun Jul  6 15:54:52 2008
@@ -1,1 +1,1 @@
-/trunk:1-128220
+/trunk:1-128512

Modified: team/oej/videocaps/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/videocaps/channels/chan_sip.c?view=diff&rev=128559&r1=128558&r2=128559
==============================================================================
--- team/oej/videocaps/channels/chan_sip.c (original)
+++ team/oej/videocaps/channels/chan_sip.c Sun Jul  6 15:54:52 2008
@@ -40,6 +40,8 @@
  * \todo We need to test TCP sessions with SIP proxies and in regards
  *       to the SIP outbound specs.
  * \todo Fix TCP/TLS handling in dialplan, SRV records, transfers and much more
+ * \todo Save TCP/TLS sessions in registry
+ * \todo Add TCP/TLS information to function SIPPEER and SIPCHANINFO
  *
  * \ingroup channel_drivers
  *
@@ -240,7 +242,6 @@
 static int min_expiry = DEFAULT_MIN_EXPIRY;        /*!< Minimum accepted registration time */
 static int max_expiry = DEFAULT_MAX_EXPIRY;        /*!< Maximum accepted registration time */
 static int default_expiry = DEFAULT_DEFAULT_EXPIRY;
-static int expiry = DEFAULT_EXPIRY;
 
 #ifndef MAX
 #define MAX(a,b) ((a) > (b) ? (a) : (b))
@@ -298,9 +299,10 @@
 };
 
 
+/*! \brief The result of a lot of functions */
 enum sip_result {
-	AST_SUCCESS = 0,
-	AST_FAILURE = -1,
+	AST_SUCCESS = 0,		/*! FALSE means success, funny enough */
+	AST_FAILURE = -1,		
 };
 
 /*! \brief States for the INVITE transaction, not the dialog 
@@ -322,7 +324,7 @@
        \note Should be aligned to above table as index */
 static const struct invstate2stringtable {
 	const enum invitestates state;
-	const char const *desc;
+	const char *desc;
 } invitestate2string[] = {
 	{INV_NONE,              "None"  },
 	{INV_CALLING,           "Calling (Trying)"},
@@ -334,6 +336,9 @@
 	{INV_CANCELLED,         "Cancelled"}
 };
 
+/*! \brief When sending a SIP message, we can send with a few options, depending on
+	type of SIP request. UNRELIABLE is moslty used for responses to repeated requests,
+	where the original response would be sent RELIABLE in an INVITE transaction */
 enum xmittype {
 	XMIT_CRITICAL = 2,              /*!< Transmit critical SIP message reliably, with re-transmits.
                                               If it fails, it's critical and will cause a teardown of the session */
@@ -347,6 +352,7 @@
 	PARSE_REGISTER_QUERY,
 };
 
+/*! \brief Type of subscription, based on the packages we do support */
 enum subscriptiontype { 
 	NONE = 0,
 	XPIDF_XML,
@@ -454,11 +460,13 @@
         SESSION_TIMER_REFRESHER_UAS      /*!< Session is refreshed by the UAS */
 };
 
-/*!< Define some SIP transports */
+/*! \brief Define some implemented SIP transports 
+	\note Asterisk does not support SCTP or UDP/DTLS 
+*/
 enum sip_transport {
-	SIP_TRANSPORT_UDP = 1,
-	SIP_TRANSPORT_TCP = 1 << 1,
-	SIP_TRANSPORT_TLS = 1 << 2,
+	SIP_TRANSPORT_UDP = 1,		/*!< Unreliable transport for SIP, needs retransmissions */
+	SIP_TRANSPORT_TCP = 1 << 1,	/*!< Reliable, but unsecure */
+	SIP_TRANSPORT_TLS = 1 << 2,	/*!< TCP/TLS - reliable and secure transport for signalling */
 };
 
 /*! \brief definition of a sip proxy server
@@ -645,12 +653,18 @@
 */
 #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY"
 
-/*! \brief SIP Extensions we support */
+/*! \brief SIP Extensions we support 
+	\note This should be generated based on the previous array
+		in combination with settings.
+	\todo We should not have "timer" if it's disabled in the configuration file.
+*/
 #define SUPPORTED_EXTENSIONS "replaces, timer" 
 
-/*! \brief Standard SIP and TLS port from RFC 3261. DO NOT CHANGE THIS */
+/*! \brief Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS */
 #define STANDARD_SIP_PORT	5060
+/*! \brief Standard SIP TLS port for sips: from RFC 3261. DO NOT CHANGE THIS */
 #define STANDARD_TLS_PORT	5061
+
 /*! \note in many SIP headers, absence of a port number implies port 5060,
  * and this is why we cannot change the above constant.
  * There is a limited number of places in asterisk where we could,
@@ -681,12 +695,12 @@
 #define DEFAULT_TOS_AUDIO       0               /*!< Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions. */
 #define DEFAULT_TOS_VIDEO       0               /*!< Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions. */
 #define DEFAULT_TOS_TEXT        0               /*!< Text packets should be marked as XXXX XXXX, but the default is 0 to be compatible with previous versions. */
-#define DEFAULT_COS_SIP         4
-#define DEFAULT_COS_AUDIO       5
-#define DEFAULT_COS_VIDEO       6
-#define DEFAULT_COS_TEXT        5
-#define DEFAULT_ALLOW_EXT_DOM	TRUE
-#define DEFAULT_REALM		"asterisk"
+#define DEFAULT_COS_SIP         4		/*!< Level 2 class of service for SIP signalling */
+#define DEFAULT_COS_AUDIO       5		/*!< Level 2 class of service for audio media  */
+#define DEFAULT_COS_VIDEO       6		/*!< Level 2 class of service for video media */
+#define DEFAULT_COS_TEXT        5		/*!< Level 2 class of service for text media (T.140) */
+#define DEFAULT_ALLOW_EXT_DOM	TRUE		/*!< Allow external domains */
+#define DEFAULT_REALM		"asterisk"	/*!< Realm for HTTP digest authentication */
 #define DEFAULT_NOTIFYRINGING	TRUE
 #define DEFAULT_PEDANTIC	FALSE
 #define DEFAULT_AUTOCREATEPEER	FALSE
@@ -700,7 +714,7 @@
 #ifndef DEFAULT_USERAGENT
 #define DEFAULT_USERAGENT "Asterisk PBX"	/*!< Default Useragent: header unless re-defined in sip.conf */
 #define DEFAULT_SDPSESSION "Asterisk PBX"	/*!< Default SDP session name, (s=) header unless re-defined in sip.conf */
-#define DEFAULT_SDPOWNER "root"		/*!< Default SDP username field in (o=) header unless re-defined in sip.conf */
+#define DEFAULT_SDPOWNER "root"			/*!< Default SDP username field in (o=) header unless re-defined in sip.conf */
 #endif
 /*@}*/ 
 
@@ -741,7 +755,6 @@
 */
 /*@{*/ 
 static int global_directrtpsetup;	/*!< Enable support for Direct RTP setup (no re-invites) */
-static int global_limitonpeers;		/*!< Match call limit on peers only */
 static int global_rtautoclear;		/*!< Realtime ?? */
 static int global_notifyringing;	/*!< Send notifications on ringing */
 static int global_notifyhold;		/*!< Send notifications on hold */
@@ -756,7 +769,7 @@
 static int global_rtpkeepalive;		/*!< Send RTP keepalives */
 static int global_reg_timeout;	
 static int global_regattempts_max;	/*!< Registration attempts before giving up */
-static int global_allowguest;		/*!< allow unauthenticated users/peers to connect? */
+static int global_allowguest;		/*!< allow unauthenticated peers to connect? */
 static int global_callcounter;		/*!< Enable call counters for all devices. This is currently enabled by setting the peer
 						call-limit to 999. When we remove the call-limit from the code, we can make it
 						with just a boolean flag in the device structure */
@@ -783,13 +796,13 @@
 static int global_authfailureevents;		/*!< Whether we send authentication failure manager events or not. Default no. */
 static int global_t1;			/*!< T1 time */
 static int global_t1min;		/*!< T1 roundtrip time minimum */
-static int global_timer_b;    /*!< Timer B - RFC 3261 Section 17.1.1.2 */
-static int global_regextenonqualify;  /*!< Whether to add/remove regexten when qualifying peers */
-static int global_autoframing;          /*!< Turn autoframing on or off. */
+static int global_timer_b;    			/*!< Timer B - RFC 3261 Section 17.1.1.2 */
+static int global_regextenonqualify;  		/*!< Whether to add/remove regexten when qualifying peers */
+static int global_autoframing;          	/*!< Turn autoframing on or off. */
 static enum transfermodes global_allowtransfer;	/*!< SIP Refer restriction scheme */
 static struct sip_proxy global_outboundproxy;	/*!< Outbound proxy */
-static int global_matchexterniplocally; /*!< Match externip/externhost setting against localnet setting */
-static int global_qualifyfreq; /*!< Qualify frequency */
+static int global_matchexterniplocally;		/*!< Match externip/externhost setting against localnet setting */
+static int global_qualifyfreq;			/*!< Qualify frequency */
 static int global_videoupdate = DEFAULT_VIDEO_UPDATE;
 /* We set default caps but make them invalid. 
   If a rtpmap comes in the we set valid.
@@ -800,6 +813,7 @@
 
 /*! \brief Codecs that we support by default: */
 static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
+
 static enum st_mode global_st_mode;           /*!< Mode of operation for Session-Timers           */
 static enum st_refresher global_st_refresher; /*!< Session-Timer refresher                        */
 static int global_min_se;                     /*!< Lowest threshold for session refresh interval  */
@@ -810,8 +824,6 @@
 /*! \name Object counters @{
  * \bug These counters are not handled in a thread-safe way ast_atomic_fetchadd_int()
  * should be used to modify these values. */
-static int suserobjs = 0;                /*!< Static users */
-static int ruserobjs = 0;                /*!< Realtime users */
 static int speerobjs = 0;                /*!< Static peers */
 static int rpeerobjs = 0;                /*!< Realtime peers */
 static int apeerobjs = 0;                /*!< Autocreated peer objects */
@@ -819,14 +831,13 @@
 /* }@ */
 
 static struct ast_flags global_flags[2] = {{0}};        /*!< global SIP_ flags */
-static char used_context[AST_MAX_CONTEXT]; /*!< name of automatically created context for unloading */
+static char used_context[AST_MAX_CONTEXT];		/*!< name of automatically created context for unloading */
 
 
 AST_MUTEX_DEFINE_STATIC(netlock);
 
 /*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
    when it's doing something critical. */
-
 AST_MUTEX_DEFINE_STATIC(monlock);
 
 AST_MUTEX_DEFINE_STATIC(sip_reload_lock);
@@ -847,12 +858,12 @@
 #define DEC_CALL_RINGING 2
 #define INC_CALL_RINGING 3
 
-/*!< The SIP socket definition */
+/*! \brief The SIP socket definition */
 struct sip_socket {
-	enum sip_transport type;
-	int fd;
+	enum sip_transport type;	/*!< UDP, TCP or TLS */
+	int fd;				/*!< Filed descriptor, the actual socket */
 	uint16_t port;
-	struct ast_tcptls_session_instance *ser;
+	struct ast_tcptls_session_instance *ser;	/* If tcp or tls, a socket manager */
 };
 
 /*! \brief sip_request: The data grabbed from the UDP socket
@@ -1121,8 +1132,8 @@
 static enum sip_debug_e sipdebug;
 
 /*! \brief extra debugging for 'text' related events.
- * At thie moment this is set together with sip_debug_console.
- * It should either go away or be implemented properly.
+ * At the moment this is set together with sip_debug_console.
+ * \note It should either go away or be implemented properly.
  */
 static int sipdebug_text;
 
@@ -1234,7 +1245,7 @@
 
 
 
-/*! \brief sip_pvt: structures used for each SIP dialog, ie. a call, a registration, a subscribe.
+/*! \brief Structure used for each SIP dialog, ie. a call, a registration, a subscribe.
  * Created and initialized by sip_alloc(), the descriptor goes into the list of
  * descriptors (dialoglist).
  */
@@ -1391,7 +1402,7 @@
 /*! Max entires in the history list for a sip_pvt */
 #define MAX_HISTORY_ENTRIES 50
 
-/*!
+/*! \brief
  * Here we implement the container for dialogs (sip_pvt), defining
  * generic wrapper functions to ease the transition from the current
  * implementation (a single linked list) to a different container.
@@ -1401,7 +1412,11 @@
  */
 struct ao2_container *dialogs;
 
-/*!
+#define sip_pvt_lock(x) ao2_lock(x)
+#define sip_pvt_trylock(x) ao2_trylock(x)
+#define sip_pvt_unlock(x) ao2_unlock(x)
+
+/*! \brief
  * when we create or delete references, make sure to use these
  * functions so we keep track of the refcounts.
  * To simplify the code, we allow a NULL to be passed to dialog_unref().
@@ -1409,6 +1424,7 @@
 #ifdef REF_DEBUG
 #define dialog_ref(arg1,arg2) dialog_ref_debug((arg1),(arg2), __FILE__, __LINE__, __PRETTY_FUNCTION__)
 #define dialog_unref(arg1,arg2) dialog_unref_debug((arg1),(arg2), __FILE__, __LINE__, __PRETTY_FUNCTION__)
+
 static struct sip_pvt *dialog_ref_debug(struct sip_pvt *p, char *tag, char *file, int line, const char *func)
 {
 	if (p)
@@ -1462,46 +1478,6 @@
 	int packetlen;				/*!< Length of packet */
 	struct ast_str *data;
 };	
-
-/*! \brief Structure for SIP user data. User's place calls to us */
-struct sip_user {
-	/* Users who can access various contexts */
-	char name[80];
-	char secret[80];		/*!< Password */
-	char md5secret[80];		/*!< Password in md5 */
-	char context[AST_MAX_CONTEXT];	/*!< Default context for incoming calls */
-	char subscribecontext[AST_MAX_CONTEXT];	/* Default context for subscriptions */
-	char cid_num[80];		/*!< Caller ID num */
-	char cid_name[80];		/*!< Caller ID name */
-	char accountcode[AST_MAX_ACCOUNT_CODE];	/* Account code */
-	char language[MAX_LANGUAGE];	/*!< Default language for this user */
-	char mohinterpret[MAX_MUSICCLASS];/*!< Music on Hold class */
-	char mohsuggest[MAX_MUSICCLASS];/*!< Music on Hold class */
-	char parkinglot[AST_MAX_CONTEXT];/*!< Parkinglot */
-	char useragent[256];		/*!< User agent in SIP request */
-	struct ast_codec_pref prefs;	/*!< codec prefs */
-	ast_group_t callgroup;		/*!< Call group */
-	ast_group_t pickupgroup;	/*!< Pickup Group */
-	unsigned int sipoptions;	/*!< Supported SIP options */
-	struct ast_flags flags[2];	/*!< SIP_ flags */
-
-	/* things that don't belong in flags */
-	char is_realtime;		/*!< this is a 'realtime' user */
-	unsigned int the_mark:1;          /*!< moved out of the ASTOBJ fields; that which bears the_mark should be deleted! */
-
-	int amaflags;			/*!< AMA flags for billing */
-	int callingpres;		/*!< Calling id presentation */
-	struct ast_capabilities caps;	/*!< User capability */
-	int capability;			/*!< Codec capability */
-	int inUse;			/*!< Number of calls in use */
-	int call_limit;			/*!< Limit of concurrent calls */
-	enum transfermodes allowtransfer;	/*! SIP Refer restriction scheme */
-	struct ast_ha *ha;		/*!< ACL setting */
-	struct ast_variable *chanvars;	/*!< Variables to set for channel created by user */
-	int videoupdate                 /*!< Defines use of XML or RTCP for video update */;
-	int autoframing;
-	struct sip_st_cfg stimer;	/*!< SIP Session-Timers */
-};
 
 /*!
  * \brief A peer's mailbox
@@ -1564,7 +1540,8 @@
 	char rt_fromcontact;		/*!< P: copy fromcontact from realtime */
 	char host_dynamic;		/*!< P: Dynamic Peers register with Asterisk */
 	char selfdestruct;		/*!< P: Automatic peers need to destruct themselves */
-	char the_mark;           /*!< moved out of ASTOBJ into struct proper; That which bears the_mark should be deleted! */
+	char onlymatchonip;		/*!< P: Only match on IP for incoming calls (old type=peer) */
+	char the_mark;			/*!< moved out of ASTOBJ into struct proper; That which bears the_mark should be deleted! */
 
 	int expire;			/*!<  When to expire this peer registration */
 	int capability;			/*!<  Codec capability */
@@ -1630,7 +1607,7 @@
 		AST_STRING_FIELD(callback);	/*!< Contact extension */
 		AST_STRING_FIELD(random);
 	);
-	enum sip_transport transport;
+	enum sip_transport transport;	/*!< Transport for this registration UDP, TCP or TLS */
 	int portno;			/*!<  Optional port override */
 	int expire;			/*!< Sched ID of expiration */
 	int expiry;			/*!< Value to use for the Expires header */
@@ -1648,11 +1625,12 @@
 	char lastmsg[256];		/*!< Last Message sent/received */
 };
 
+/*! \brief Definition of a thread that handles a socket */
 struct sip_threadinfo {
 	int stop;
 	pthread_t threadid;
 	struct ast_tcptls_session_instance *ser;
-	enum sip_transport type;	/* We keep a copy of the type here so we can display it in the connection list */
+	enum sip_transport type;	/*!< We keep a copy of the type here so we can display it in the connection list */
 	AST_LIST_ENTRY(sip_threadinfo) list;
 };
 
@@ -1663,7 +1641,7 @@
 static int hash_dialog_size = 17;
 static int hash_user_size = 17;
 #else
-static int hash_peer_size = 563;
+static int hash_peer_size = 563;	/*!< Size of peer hash table, prime number preferred! */
 static int hash_dialog_size = 563;
 static int hash_user_size = 563;
 #endif
@@ -1671,10 +1649,7 @@
 /*! \brief  The thread list of TCP threads */
 static AST_LIST_HEAD_STATIC(threadl, sip_threadinfo);
 
-/*! \brief  The user list: Users and friends */
-static struct ao2_container *users;
-
-/*! \brief  The peer list: Peers and Friends */
+/*! \brief  The peer list: Users, Peers and Friends */
 struct ao2_container *peers;
 struct ao2_container *peers_by_ip;
 
@@ -1684,7 +1659,7 @@
 	int recheck;
 } regl;
 
-/*!
+/*! \brief
  * \note The only member of the peer used here is the name field
  */
 static int peer_hash_cb(const void *obj, const int flags)
@@ -1738,26 +1713,6 @@
 			return 0;
 	}
 	return CMP_MATCH;
-}
-
-/*!
- * \note The only member of the user used here is the name field
- */
-static int user_hash_cb(const void *obj, const int flags)
-{
-	const struct sip_user *user = obj;
-
-	return ast_str_hash(user->name);
-}
-
-/*!
- * \note The only member of the user used here is the name field
- */
-static int user_cmp_cb(void *obj, void *arg, int flags)
-{
-	struct sip_user *user = obj, *user2 = arg;
-
-	return !strcasecmp(user->name, user2->name) ? CMP_MATCH : 0;
 }
 
 /*!
@@ -1817,7 +1772,7 @@
  */
 static int sipsock  = -1;
 
-static struct sockaddr_in bindaddr;	/*!< The address we bind to */
+static struct sockaddr_in bindaddr;	/*!< UDP: The address we bind to */
 
 /*! \brief our (internal) default address/port to put in SIP/SDP messages
  *  internip is initialized picking a suitable address from one of the
@@ -1860,8 +1815,8 @@
  */
 static struct ast_ha *localaddr;		/*!< List of local networks, on the same side of NAT as this Asterisk */
 
-static int ourport_tcp;
-static int ourport_tls;
+static int ourport_tcp;				/*!< The port used for TCP connections */
+static int ourport_tls;				/*!< The port used for TCP/TLS connections */
 static struct sockaddr_in debugaddr;
 
 static struct ast_config *notify_types;		/*!< The list of manual NOTIFY types we know how to send */
@@ -2043,12 +1998,9 @@
 static char *transfermode2str(enum transfermodes mode) attribute_const;
 static const char *nat2str(int nat) attribute_const;
 static int peer_status(struct sip_peer *peer, char *status, int statuslen);
-static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char * _sip_show_peers(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]);
 static char *sip_show_peers(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]);
-static char *sip_dbdump(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static void  print_group(int fd, ast_group_t group, int crlf);
 static const char *dtmfmode2str(int mode) attribute_const;
@@ -2060,7 +2012,6 @@
 static char *sip_show_domains(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]);
 static char *sip_show_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *_sip_qualify_peer(int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]);
 static char *sip_qualify_peer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -2073,8 +2024,6 @@
 static char *complete_sip_show_history(const char *line, const char *word, int pos, int state);
 static char *complete_sip_show_peer(const char *line, const char *word, int pos, int state);
 static char *complete_sip_unregister(const char *line, const char *word, int pos, int state);
-static char *complete_sip_user(const char *word, int state, int flags2);
-static char *complete_sip_show_user(const char *line, const char *word, int pos, int state);
 static char *complete_sipnotify(const char *line, const char *word, int pos, int state);
 static char *sip_show_channel(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_channelstats(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -2108,18 +2057,14 @@
 
 /*--- Device object handling */
 static struct sip_peer *temp_peer(const char *name);
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
-static struct sip_user *build_user(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime);
+static struct sip_peer *build_peer(const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime, int ispeer);
 static int update_call_counter(struct sip_pvt *fup, int event);
 static void sip_destroy_peer(struct sip_peer *peer);
 static void sip_destroy_peer_fn(void *peer);
-static void sip_destroy_user(struct sip_user *user);
-static void sip_destroy_user_fn(void *user);
 static void set_peer_defaults(struct sip_peer *peer);
 static struct sip_peer *temp_peer(const char *name);
 static void register_peer_exten(struct sip_peer *peer, int onoff);
-static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime);
-static struct sip_user *find_user(const char *name, int realtime);
+static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime, int forcenamematch);
 static int sip_poke_peer_s(const void *data);
 static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req);
 static void reg_source_db(struct sip_peer *peer);
@@ -2129,7 +2074,6 @@
 
 /* Realtime device support */
 static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, const char *useragent, int expirey, int deprecated_username);
-static struct sip_user *realtime_user(const char *username);
 static void update_peer(struct sip_peer *p, int expiry);
 static struct ast_variable *get_insecure_variable_from_config(struct ast_config *config);
 static const char *get_name_from_variable(struct ast_variable *var, const char *newpeername);
@@ -2176,6 +2120,10 @@
 static int get_destination(struct sip_pvt *p, struct sip_request *oreq);
 static int get_msg_text(char *buf, int len, struct sip_request *req, int addnewline);
 static int transmit_state_notify(struct sip_pvt *p, int state, int full, int timeout);
+
+/*-- TCP connection handling ---*/
+static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *ser);
+static void *sip_tcp_worker_fn(void *);
 
 /*--- Constructing requests and responses */
 static void initialize_initreq(struct sip_pvt *p, struct sip_request *req);
@@ -2298,11 +2246,14 @@
  */
 static struct ast_channel_tech sip_tech_info;
 
-static void *sip_tcp_worker_fn(void *);
-
+
+/*! \brief Working TLS connection configuration */
 static struct ast_tls_config sip_tls_cfg;
+
+/*! \brief Default TLS connection configuration */
 static struct ast_tls_config default_tls_cfg;
 
+/*! \brief The TCP server definition */
 static struct server_args sip_tcp_desc = {
 	.accept_fd = -1,
 	.master = AST_PTHREADT_NULL,
@@ -2313,6 +2264,7 @@
 	.worker_fn = sip_tcp_worker_fn,
 };
 
+/*! \brief The TCP/TLS server definition */
 static struct server_args sip_tls_desc = {
 	.accept_fd = -1,
 	.master = AST_PTHREADT_NULL,
@@ -2363,8 +2315,8 @@
 	.get_codec = sip_get_codec,
 };
 
-static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *ser);
-
+
+/*! \brief SIP TCP connection handler */
 static void *sip_tcp_worker_fn(void *data)
 {
 	struct ast_tcptls_session_instance *ser = data;
@@ -2372,7 +2324,7 @@
 	return _sip_tcp_helper_thread(NULL, ser);
 }
 
-/*! \brief SIP TCP helper function */
+/*! \brief SIP TCP thread management function */
 static void *_sip_tcp_helper_thread(struct sip_pvt *pvt, struct ast_tcptls_session_instance *ser) 
 {
 	int res, cl;
@@ -2465,8 +2417,10 @@
 	fclose(ser->f);
 	ser->f = NULL;
 	ser->fd = -1;
-	if (reqcpy.data)
+	if (reqcpy.data) {
 		ast_free(reqcpy.data);
+	}
+
 	if (req.data) {
 		ast_free(req.data);
 		req.data = NULL;
@@ -2479,9 +2433,6 @@
 	return NULL;
 }
 
-#define sip_pvt_lock(x) ao2_lock(x)
-#define sip_pvt_trylock(x) ao2_trylock(x)
-#define sip_pvt_unlock(x) ao2_unlock(x)
 
 /*!
  * helper functions to unreference various types of objects.
@@ -2491,12 +2442,6 @@
 static void *unref_peer(struct sip_peer *peer, char *tag)
 {
 	ao2_t_ref(peer, -1, tag);
-	return NULL;
-}
-
-static void *unref_user(struct sip_user *user, char *tag)
-{
-	ao2_t_ref(user, -1, tag);
 	return NULL;
 }
 
@@ -4060,7 +4005,7 @@
 
 
 	/* Peer found in realtime, now build it in memory */
-	peer = build_peer(newpeername, var, varregs, 1);
+	peer = build_peer(newpeername, var, varregs, TRUE, FALSE);
 	if (!peer) {
 		if(peerlist)
 			ast_config_destroy(peerlist);
@@ -4099,13 +4044,14 @@
 	return peer;
 }
 
-/*! \brief Locate peer by name or ip address 
- *	This is used on incoming SIP message to find matching peer on ip
-	or outgoing message to find matching peer on name 
+/*! \brief Locate device by name or ip address 
+ *	This is used on find matching device on name or ip/port.
+	If the device was declared as type=peer, we don't match on peer name on incoming INVITEs.
+	
 	\note Avoid using this function in new functions if there is a way to avoid it, i
 	since it might cause a database lookup.
 */
-static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime)
+static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime, int forcenamematch)
 {
 	struct sip_peer *p = NULL;
 	struct sip_peer tmp_peer;
@@ -4131,94 +4077,6 @@
 		p = realtime_peer(peer, sin);
 
 	return p;
-}
-
-static void sip_destroy_user_fn(void *user)
-{
-	sip_destroy_user(user);
-}
-
-
-/*! \brief Remove user object from in-memory storage */
-static void sip_destroy_user(struct sip_user *user)
-{
-	ast_debug(3, "Destroying user object from memory: %s\n", user->name);
-
-	ast_free_ha(user->ha);
-	if (user->chanvars) {
-		ast_variables_destroy(user->chanvars);
-		user->chanvars = NULL;
-	}
-	if (user->is_realtime)
-		ast_atomic_fetchadd_int(&ruserobjs, -1);
-	else
-		ast_atomic_fetchadd_int(&suserobjs, -1);
-}
-
-/*! \brief Load user from realtime storage
- * Loads user from "sipusers" category in realtime (extconfig.conf)
- * returns a refcounted pointer to a sip_user structure.
- * Users are matched on From: user name (the domain in skipped) */
-static struct sip_user *realtime_user(const char *username)
-{
-	struct ast_variable *var;
-	struct ast_variable *tmp;
-	struct sip_user *user = NULL;
-
-	var = ast_load_realtime("sipusers", "name", username, SENTINEL);
-
-	if (!var)
-		return NULL;
-
-	for (tmp = var; tmp; tmp = tmp->next) {
-		if (!strcasecmp(tmp->name, "type") &&
-			!strcasecmp(tmp->value, "peer")) {
-			ast_variables_destroy(var);
-			return NULL;
-		}
-	}
-
-	user = build_user(username, var, NULL, !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS));
-	
-	if (!user) {	/* No user found */
-		ast_variables_destroy(var);
-		return NULL;
-	}
-
-	if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
-		ast_set_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS);
-		ast_atomic_fetchadd_int(&suserobjs, 1);
-		ao2_t_link(users, user, "link user into users table");
-	} else {
-		/* Move counter from s to r... */
-		ast_atomic_fetchadd_int(&suserobjs, -1);
-		ast_atomic_fetchadd_int(&ruserobjs, 1);
-		user->is_realtime = 1;
-	}
-	ast_variables_destroy(var);
-	return user;
-}
-
-/*! \brief Locate user by name 
- * Locates user by name (From: sip uri user name part) first
- * from in-memory list (static configuration) then from 
- * realtime storage (defined in extconfig.conf) 
- * \return a refcounted pointer to a user. Make sure the
- * the ref count is decremented when this pointer is nulled, changed,
- * or goes out of scope!
- */
-
-static struct sip_user *find_user(const char *name, int realtime)
-{
-	struct sip_user tmp;
-	struct sip_user *u;
-
-	ast_copy_string(tmp.name, name, sizeof(tmp.name));
-	u = ao2_t_find(users, &tmp, OBJ_POINTER, "ao2_find in users table");
-
-	if (!u && realtime)
-		u = realtime_user(name);
-	return u;
 }
 
 /*! \brief Set nat mode on the various data sockets */
@@ -4438,7 +4296,7 @@
 	
 	return 0;
 }
-/*! \brief create address structure from peer name
+/*! \brief create address structure from device name
  *      Or, if peer not found, find it in the global DNS 
  *      returns TRUE (-1) on failure, FALSE on success */
 static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin)
@@ -4459,7 +4317,7 @@
 	dialog->sa.sin_family = AF_INET;
 	dialog->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */
 	dialog->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
-	peer = find_peer(peername, NULL, 1);
+	peer = find_peer(peername, NULL, TRUE, TRUE);
 
 	if (peer) {
 		int res = create_addr_from_peer(dialog, peer);
@@ -4492,6 +4350,9 @@
 
 		/* Let's see if we can find the host in DNS. First try DNS SRV records,
 		   then hostname lookup */
+		/*! \todo Fix this function. When we ask SRC, we should check all transports 
+			  In the future, we should first check NAPTR to find out transport preference
+		 */
 		hostn = peername;
 		portno = port ? atoi(port) : (dialog->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT;
 		if (global_srvlookup) {
@@ -4776,7 +4637,7 @@
 	}
 }
 
-/*! \brief  update_call_counter: Handle call_limit for SIP users 
+/*! \brief  update_call_counter: Handle call_limit for SIP devices
  * Setting a call-limit will cause calls above the limit not to be accepted.
  *
  * Remember that for a type=friend, there's one limit for the user and
@@ -4795,7 +4656,6 @@
 	char name[256];
 	int *inuse = NULL, *call_limit = NULL, *inringing = NULL;
 	int outgoing = fup->outgoing_call;
-	struct sip_user *u = NULL;
 	struct sip_peer *p = NULL;
 
 	ast_debug(3, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming");
@@ -4808,18 +4668,14 @@
 
 	ast_copy_string(name, fup->username, sizeof(name));
 
-	/* Check the list of users only for incoming calls */
-	if (global_limitonpeers == FALSE && !outgoing && (u = find_user(name, 1)))  {
-		inuse = &u->inUse;
-		call_limit = &u->call_limit;
-		inringing = NULL;
-	} else if ( (p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, 1) ) ) { /* Try to find peer */
+	/* Check the list of devices */
+	if ( (p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, TRUE, FALSE) ) ) { /* Try to find peer */
 		inuse = &p->inUse;
 		call_limit = &p->call_limit;
 		inringing = &p->inRinging;
 		ast_copy_string(name, fup->peername, sizeof(name));
 	} 
-	if (!p && !u) {
+	if (!p) {
 		ast_debug(2, "%s is not a local device, no call limit\n", name);
 		return 0;
 	}
@@ -4844,7 +4700,7 @@
 			sip_peer_hold(fup, FALSE);
 		}
 		if (sipdebug)
-			ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
+			ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", "peer", name, *call_limit);
 		break;
 
 	case INC_CALL_RINGING:
@@ -4852,11 +4708,8 @@
 		/* If call limit is active and we have reached the limit, reject the call */
 		if (*call_limit > 0 ) {
 			if (*inuse >= *call_limit) {
-				ast_log(LOG_WARNING, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *call_limit);
-				if (u)
-					unref_user(u, "update_call_counter: unref user u call limit exceeded");
-				else
-					unref_peer(p, "update_call_counter: unref peer p, call limit exceeded");
+				ast_log(LOG_ERROR, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", "peer", name, *call_limit);
+				unref_peer(p, "update_call_counter: unref peer p, call limit exceeded");
 				return -1; 
 			}
 		}
@@ -4870,7 +4723,7 @@
 		ast_atomic_fetchadd_int(inuse, +1);
 		ast_set_flag(&fup->flags[0], SIP_INC_COUNT);
 		if (sipdebug) {
-			ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", u ? "user":"peer", name, *inuse, *call_limit);
+			ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", "peer", name, *inuse, *call_limit);
 		}
 		break;
 
@@ -4887,8 +4740,7 @@
 	if (p) {
 		ast_device_state_changed("SIP/%s", p->name);
 		unref_peer(p, "update_call_counter: unref_peer from call counter");
-	} else /* u must be set */
-		unref_user(u, "update_call_counter: unref_user from call counter");
+	} 
 	return 0;
 }
 
@@ -11119,7 +10971,10 @@
 		ast_sched_add(sched, (expiry + 10) * 1000, expire_register, peer);
 	pvt->expiry = expiry;
 	snprintf(data, sizeof(data), "%s:%d:%d:%s:%s", ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expiry, peer->username, peer->fullcontact);
-	/* Saving TCP connections is useless, we won't be able to reconnect */
+	/* Saving TCP connections is useless, we won't be able to reconnect 
+		XXX WHY???? XXX
+		\todo check this
+	*/
 	if (!peer->rt_fromcontact && (peer->socket.type & SIP_TRANSPORT_UDP)) 
 		ast_db_put("SIP/Registry", peer->name, data);
 	manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\nPort: %d\r\n", peer->name,  ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port));
@@ -11451,7 +11306,7 @@
 /*! \brief Change onhold state of a peer using a pvt structure */
 static void sip_peer_hold(struct sip_pvt *p, int hold)
 {
-	struct sip_peer *peer = find_peer(p->peername, NULL, 1);
+	struct sip_peer *peer = find_peer(p->peername, NULL, 1, TRUE);
 
 	if (!peer)
 		return;
@@ -11518,7 +11373,7 @@
 }
 
 /*! \brief Send a fake 401 Unauthorized response when the administrator
-  wants to hide the names of local users/peers from fishers
+  wants to hide the names of local devices  from fishers
  */
 static void transmit_fake_auth_response(struct sip_pvt *p, struct sip_request *req, int reliable)
 {
@@ -11600,7 +11455,7 @@
 
 	ast_string_field_set(p, exten, name);
 	build_contact(p);
-	peer = find_peer(name, NULL, 1);
+	peer = find_peer(name, NULL, TRUE, TRUE);
 	if (!(peer && ast_apply_ha(peer->ha, sin))) {
 		/* Peer fails ACL check */
 		if (peer) {
@@ -11725,7 +11580,7 @@
 		case AUTH_USERNAME_MISMATCH:
 			/* Username and digest username does not match. 
 			   Asterisk uses the From: username for authentication. We need the
-			   users to use the same authentication user name until we support
+			   devices to use the same authentication user name until we support
 			   proper authentication by digest auth name */
 			transmit_response(p, "403 Authentication user name does not match account name", &p->initreq);
 			if (global_authfailureevents)
@@ -12476,118 +12331,6 @@
 	}
 }
 
-/*! \brief Validate user authentication */
-static enum check_auth_result check_user_ok(struct sip_pvt *p, char *of,
-	struct sip_request *req, int sipmethod, struct sockaddr_in *sin,
-	enum xmittype reliable,
-	char *rpid_num, char *calleridname, char *uri2)
-{
-	enum check_auth_result res;
-	struct sip_user *user = find_user(of, 1);
-	int debug=sip_debug_test_addr(sin);
-
-	/* Find user based on user name in the from header */
-	if (!user) {
-		if (debug)
-			ast_verbose("No user '%s' in SIP users list\n", of);
-		return AUTH_DONT_KNOW;
-	}
-	if (!ast_apply_ha(user->ha, sin)) {
-		if (debug)
-			ast_verbose("Found user '%s' for '%s', but fails host access\n",
-				user->name, of);
-		unref_user(user, "unref_user: from check_user_ok from find_user call, early return of AUTH_DONT_KNOW.");
-		return AUTH_DONT_KNOW;
-	}
-	if (debug)
-		ast_verbose("Found user '%s' for '%s'\n", user->name, of);
-
-	ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY);
-	ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
-	/* copy channel vars */
-	p->chanvars = copy_vars(user->chanvars);
-	p->prefs = user->prefs;
-	/* Set Frame packetization */
-	if (p->rtp) {
-		ast_rtp_codec_setpref(p->rtp, &p->prefs);
-		p->autoframing = user->autoframing;
-	}
-
-	replace_cid(p, rpid_num, calleridname);
-	do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE) );
-
-	if (!(res = check_auth(p, req, user->name, user->secret, user->md5secret, sipmethod, uri2, reliable, req->ignore))) {
-		sip_cancel_destroy(p);
-		ast_copy_flags(&p->flags[0], &user->flags[0], SIP_FLAGS_TO_COPY);
-		ast_copy_flags(&p->flags[1], &user->flags[1], SIP_PAGE2_FLAGS_TO_COPY);
-		/* Copy SIP extensions profile from INVITE */
-		if (p->sipoptions)
-			user->sipoptions = p->sipoptions;
-
-		/* If we have a call limit, set flag */
-		if (user->call_limit)
-			ast_set_flag(&p->flags[0], SIP_CALL_LIMIT);
-		if (!ast_strlen_zero(user->context))
-			ast_string_field_set(p, context, user->context);
-		if (!ast_strlen_zero(user->cid_num)) {
-			char *tmp = ast_strdupa(user->cid_num);
-			if (ast_is_shrinkable_phonenumber(tmp))
-				ast_shrink_phone_number(tmp);
-			ast_string_field_set(p, cid_num, tmp);
-		}
-		if (!ast_strlen_zero(user->cid_name))
-			ast_string_field_set(p, cid_name, user->cid_name);
-		ast_string_field_set(p, username, user->name);
-		ast_string_field_set(p, peername, user->name);
-		ast_string_field_set(p, peersecret, user->secret);
-		ast_string_field_set(p, peermd5secret, user->md5secret);
-		ast_string_field_set(p, subscribecontext, user->subscribecontext);
-		ast_string_field_set(p, accountcode, user->accountcode);
-		ast_string_field_set(p, language, user->language);
-		ast_string_field_set(p, mohsuggest, user->mohsuggest);
-		ast_string_field_set(p, mohinterpret, user->mohinterpret);
-		ast_string_field_set(p, parkinglot, user->parkinglot);
-		p->allowtransfer = user->allowtransfer;
-		p->amaflags = user->amaflags;
-		p->callgroup = user->callgroup;
-		p->pickupgroup = user->pickupgroup;
-		if (user->callingpres)	/* User callingpres setting will override RPID header */
-			p->callingpres = user->callingpres;
-		
-		/* Set default codec settings for this call */
-		p->capability = user->capability;		/* User codec choice */
-		p->jointcapability = user->capability;		/* Our codecs */

[... 1931 lines stripped ...]



More information about the svn-commits mailing list