[asterisk-commits] oej: trunk r128242 - /trunk/channels/chan_sip.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Jul 5 15:59:50 CDT 2008


Author: oej
Date: Sat Jul  5 15:59:49 2008
New Revision: 128242

URL: http://svn.digium.com/view/asterisk?view=rev&rev=128242
Log:
KILL THE USER!

Actually, kill the in-memory structure for type=user and start using the sip_peer 
structure for every object. Have only one in-memory list and use them different
ways depending on type=user, type=peer and type=friend - like always.

The idea with this first patch is that configurations should work as before.

Some additional features for realtime peers. By adding a type= field, you
can now have multiple functions.

Let's test this for a while. Won't be integrated in 1.6.0, only in trunk,
for testing.

There's propably more to clean up and simplify here. Help is welcome
and encouraged!

Modified:
    trunk/channels/chan_sip.c

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?view=diff&rev=128242&r1=128241&r2=128242
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Jul  5 15:59:49 2008
@@ -730,7 +730,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 */
@@ -745,7 +744,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 */
@@ -793,8 +792,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 */
@@ -1437,45 +1434,6 @@
 	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 */
-	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 maxcallbitrate;		/*!< Maximum Bitrate for a video call */
-	int autoframing;
-	struct sip_st_cfg stimer;	/*!< SIP Session-Timers */
-};
-
 /*!
  * \brief A peer's mailbox
  *
@@ -1537,7 +1495,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 */
@@ -1643,9 +1602,6 @@
 /*! \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 */
 struct ao2_container *peers;
 struct ao2_container *peers_by_ip;
@@ -1710,26 +1666,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;
 }
 
 /*!
@@ -2008,7 +1944,6 @@
 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);
@@ -2025,7 +1960,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);
@@ -2038,8 +1972,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);
@@ -2073,18 +2005,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);
@@ -2094,7 +2022,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);
@@ -2454,12 +2381,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;
 }
 
@@ -4023,7 +3944,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);
@@ -4062,13 +3983,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;
@@ -4094,94 +4016,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 */
@@ -4398,7 +4232,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)
@@ -4419,7 +4253,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);
@@ -4725,7 +4559,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
@@ -4744,7 +4578,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");
@@ -4757,18 +4590,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;
 	}
@@ -4793,7 +4622,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:
@@ -4801,11 +4630,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; 
 			}
 		}
@@ -4819,7 +4645,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;
 
@@ -4836,8 +4662,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;
 }
 
@@ -10788,7 +10613,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;
@@ -10855,7 +10680,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)
 {
@@ -10937,7 +10762,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) {
@@ -11062,7 +10887,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)
@@ -11813,113 +11638,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 */
-		if (p->peercapability)				/* AND with peer's codecs */
-			p->jointcapability &= p->peercapability;
-		if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
-		    (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
-			p->noncodeccapability |= AST_RTP_DTMF;
-		else
-			p->noncodeccapability &= ~AST_RTP_DTMF;
-		p->jointnoncodeccapability = p->noncodeccapability;
-		if (p->t38.peercapability)
-			p->t38.jointcapability &= p->t38.peercapability;
-		p->maxcallbitrate = user->maxcallbitrate;
-		/* If we do not support video, remove video from call structure */
-		if ((!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) || !(p->capability & AST_FORMAT_VIDEO_MASK)) && p->vrtp) {
-			ast_rtp_destroy(p->vrtp);
-			p->vrtp = NULL;
-		}
-		/* If we do not support text, remove text from call structure */
- 		if (!ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) && p->trtp) {
- 			ast_rtp_destroy(p->trtp);
- 			p->trtp = NULL;
- 		}
-	}
-	unref_user(user, "unref_user from check_auth_result, at end");
-	return res;
-}
-
 /*! \brief Validate peer authentication */
 static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of,
 	struct sip_request *req, int sipmethod, struct sockaddr_in *sin,
@@ -11931,10 +11649,15 @@
 	int debug=sip_debug_test_addr(sin);
 	struct sip_peer *peer;
 
-	/* For subscribes, match on peer name only; for other methods,
+	/* For subscribes, match on device name only; for other methods,
 	 * match on IP address-port of the incoming request.
 	 */
-	peer = (sipmethod == SIP_SUBSCRIBE) ? find_peer(of, NULL, 1) : find_peer(NULL, &p->recv, 1);
+	/* First find device on name */
+	peer = find_peer(of, NULL, TRUE, FALSE);
+
+	/* Then find device on IP (if it's not a SUBSCRIBE) */
+	if (sipmethod != SIP_SUBSCRIBE)
+		find_peer(NULL, &p->recv, TRUE, FALSE);
 
 	if (!peer) {
 		if (debug)
@@ -12163,15 +11886,6 @@
 		}
 	}
 
-	if (!authpeer) {
-		/* If we are looking for a peer, don't check the
-		   user objects (or realtime) */
-		res = check_user_ok(p, of, req, sipmethod, sin,
-			reliable, rpid_num, calleridname, uri2);
-		if (res != AUTH_DONT_KNOW)
-			return res;
-	}
-
 	res = check_peer_ok(p, of, req, sipmethod, sin,
 			authpeer, reliable, rpid_num, calleridname, uri2);
 	if (res != AUTH_DONT_KNOW)
@@ -12273,7 +11987,6 @@
 	char iused[40];
 	int showall = FALSE;
 	struct ao2_iterator i;
-	struct sip_user *user;
 	struct sip_peer *peer;
 	
 	switch (cmd) {
@@ -12281,7 +11994,7 @@
 		e->command = "sip show inuse";
 		e->usage =
 			"Usage: sip show inuse [all]\n"
-			"       List all SIP users and peers usage counters and limits.\n"
+			"       List all SIP devices usage counters and limits.\n"
 			"       Add option \"all\" to show all devices, not only those with a limit.\n";
 		return NULL;
 	case CLI_GENERATE:
@@ -12294,24 +12007,6 @@
 	if (a->argc == 4 && !strcmp(a->argv[3], "all")) 
 		showall = TRUE;
 	
-	ast_cli(a->fd, FORMAT, "* User name", "In use", "Limit");
-	
-	i = ao2_iterator_init(users, 0);
-	
-	while ((user = ao2_t_iterator_next(&i, "iterate thru user table"))) {
-		ao2_lock(user);
-
-		if (user->call_limit)
-			snprintf(ilimits, sizeof(ilimits), "%d", user->call_limit);
-		else 
-			ast_copy_string(ilimits, "N/A", sizeof(ilimits));
-		snprintf(iused, sizeof(iused), "%d", user->inUse);
-		if (showall || user->call_limit)
-			ast_cli(a->fd, FORMAT2, user->name, iused, ilimits);
-		ao2_unlock(user);
-		unref_user(user, "toss iterator pointer");
-	}
-
 	ast_cli(a->fd, FORMAT, "* Peer name", "In use", "Limit");
 
 	i = ao2_iterator_init(peers, 0);
@@ -12483,103 +12178,6 @@
 	return CLI_SUCCESS;
 #undef FORMAT
 #undef FORMAT2
-}
-
-int usercomparefunc(const void *a, const void *b);
-
-int usercomparefunc(const void *a, const void *b)
-{
-	struct sip_user **ap = (struct sip_user **)a;
-	struct sip_user **bp = (struct sip_user **)b;
-	return strcmp((*ap)->name, (*bp)->name);
-}
-
-
-/*! \brief  CLI Command 'SIP Show Users' */
-static char *sip_show_users(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	regex_t regexbuf;
-	int havepattern = FALSE;
-	int count = 0;
-	int totcount = 0;
-	struct sip_user *user;
-	struct ao2_iterator i;
-	int objcount = ao2_container_count(users);
-	struct sip_user **userarray;
-	int k;
-	
-	userarray = ast_calloc(sizeof(struct sip_user *), objcount);
-
-#define FORMAT  "%-25.25s  %-15.15s  %-15.15s  %-15.15s  %-5.5s%-10.10s\n"
-
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "sip show users";
-		e->usage =
-			"Usage: sip show users [like <pattern>]\n"
-			"       Lists all known SIP users.\n"
-			"       Optional regular expression pattern is used to filter the user list.\n";
-		return NULL;
-	case CLI_GENERATE:
-		return NULL;
-	}
-
-	switch (a->argc) {
-	case 5:
-		if (!strcasecmp(a->argv[3], "like")) {
-			if (regcomp(&regexbuf, a->argv[4], REG_EXTENDED | REG_NOSUB))
-				return CLI_SHOWUSAGE;
-			havepattern = TRUE;
-		} else
-			return CLI_SHOWUSAGE;
-	case 3:
-		break;
-	default:
-		return CLI_SHOWUSAGE;
-	}
-
-	ast_cli(a->fd, FORMAT, "Username", "Secret", "Accountcode", "Def.Context", "ACL", "NAT");
-
-	i = ao2_iterator_init(users, 0);
-
-	while ((user = ao2_t_iterator_next(&i, "iterate thru user table"))) {
-		ao2_lock(user);
-		totcount++;
-		if (havepattern && regexec(&regexbuf, user->name, 0, NULL, 0)) {
-			ao2_unlock(user);
-			unref_user(user, "toss iterator pointer via a continue in iterator loop");
-			continue;
-		}
-		userarray[count++] = user;
-		ao2_unlock(user);
-	}
-
-	qsort(userarray, count, sizeof(struct sip_user *), usercomparefunc);
-
-	for(k=0; k < count; k++) {
-		user = userarray[k];
-
-		ao2_lock(user);
-		ast_cli(a->fd, FORMAT, user->name, 
-			user->secret, 
-			user->accountcode,
-			user->context,
-			cli_yesno(user->ha != NULL),
-			nat2str(ast_test_flag(&user->flags[0], SIP_NAT)));
-		ao2_unlock(user);
-		unref_user(user, "toss iterator pointer");
-	}
-
-	if (havepattern)
-		regfree(&regexbuf);
-	if (havepattern)
-		ast_cli(a->fd, "Total %d of %d user entries\n", count, totcount);
-	else
-		ast_cli(a->fd, "Total of %d user entries\n", totcount);
-
-	ast_free(userarray);
-	return CLI_SUCCESS;
-#undef FORMAT
 }
 
 /*! \brief Manager Action SIPShowRegistry description */
@@ -12708,7 +12306,6 @@
 static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[])
 {
 	struct sip_peer *peer;
-	struct sip_user *user;
 	struct ao2_iterator i;
 	char fname[1024];
 	const char *id;
@@ -12742,7 +12339,7 @@
 	i = ao2_iterator_init(peers, 0);
 	while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) {	
 
-		user = find_user(peer->name, realtimepeers);	
+		peer = find_peer(peer->name, NULL, realtimepeers, TRUE); 
 
 		ao2_lock(peer);
 
@@ -12762,9 +12359,9 @@
 			fprintf(f1, ",amaflags");
 		fprintf(f1, ",`call-limit`");
 		if (peer->callgroup)
-			fprintf(f1, ",callgroup");
-		if (user && !ast_strlen_zero(user->cid_num))
-			fprintf(f1, ",callerid");
+			fprintf(f1, ", callgroup");
+		if (!ast_strlen_zero(peer->cid_num))
+			fprintf(f1, ", callerid");
 		if (ast_test_flag(&peer->flags[0], SIP_REINVITE))
 			fprintf(f1, ",canreinvite");
 		if (!ast_strlen_zero(peer->context))
@@ -12834,10 +12431,7 @@
 		if (ast_test_flag(&peer->flags[0], SIP_NAT)) {
 			fprintf(f1, ",'%s'", nat2strconfig(ast_test_flag(&peer->flags[0], SIP_NAT)));
 		}
-		if (user)
-			fprintf(f1, ",'friend'");
-		else
-			fprintf(f1, ",'peer'");
+		fprintf(f1, ",'peer'");
 		if (!ast_strlen_zero(peer->accountcode))
 			fprintf(f1, ",'%s'", peer->accountcode);
 		if (peer->amaflags)
@@ -12848,8 +12442,6 @@
 			
 			fprintf(f1, ",'%s'", ast_print_group(buf, sizeof(buf), peer->callgroup));
 		}
-		if (user && !ast_strlen_zero(user->cid_num))
-			fprintf(f1, ",\"%s<%s>\"", user->cid_name, user->cid_num);
 		if (ast_test_flag(&peer->flags[0], SIP_REINVITE)) {
 			switch (ast_test_flag(&peer->flags[0], SIP_REINVITE)) {
 			case SIP_REINVITE_NONE:
@@ -13147,16 +12739,6 @@
 #undef FORMAT2
 }
 
-static int user_dump_func(void *userobj, void *arg, int flags)
-{
-	struct sip_user *user = userobj;
-	int refc = ao2_t_ref(userobj, 0, "");
-	int *fd = arg;
-	
-	ast_cli(*fd, "name: %s\ntype: user\nobjflags: %d\nrefcount: %d\n\n", user->name, 0, refc);
-	return 0;
-}
-
 static int peer_dump_func(void *userobj, void *arg, int flags)
 {
 	struct sip_peer *peer = userobj;
@@ -13198,8 +12780,6 @@
 
 	if (a->argc != 3)
 		return CLI_SHOWUSAGE;
-	ast_cli(a->fd, "-= User objects: %d static, %d realtime =-\n\n", suserobjs, ruserobjs);
-	ao2_t_callback(users, OBJ_NODATA, user_dump_func, &a->fd, "initiate ao2_callback to dump users");
 	ast_cli(a->fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs);
 	ao2_t_callback(peers, OBJ_NODATA, peer_dump_func, &a->fd, "initiate ao2_callback to dump peers");
 	ast_cli(a->fd, "-= Registry objects: %d =-\n\n", regobjs);
@@ -13350,20 +12930,11 @@
 	return peer->the_mark ? CMP_MATCH : 0;
 }
 
-/* this func is used with ao2_callback to unlink/delete all marked
-   users */
-static int user_is_marked(void *userobj, void *arg, int flags)
-{
-	struct sip_user *user = userobj;
-	return user->the_mark ? CMP_MATCH : 0;
-}
-
 /*! \brief Remove temporary realtime objects from memory (CLI) */
+/*! \todo XXXX Propably needs an overhaul after removal of the devices */
 static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct sip_peer *peer, *pi;
-	struct sip_user *user, *ui;
-	int pruneuser = FALSE;
 	int prunepeer = FALSE;
 	int multi = FALSE;
 	char *name = NULL;
@@ -13371,9 +12942,9 @@
 	struct ao2_iterator i;
 	
 	if (cmd == CLI_INIT) {
-		e->command = "sip prune realtime [peer|user|all] [all|like]";
+		e->command = "sip prune realtime [peer|all] [all|like]";
 		e->usage =
-		"Usage: sip prune realtime [peer|user] [<name>|all|like <pattern>]\n"
+		"Usage: sip prune realtime [peer] [<name>|all|like <pattern>]\n"
 		"       Prunes object(s) from the cache.\n"
 		"       Optional regular expression pattern is used to filter the objects.\n";
 		return NULL;
@@ -13381,8 +12952,6 @@
 		if (a->pos == 4) {
 			if (strcasestr(a->line, "realtime peer"))
 				return complete_sip_peer(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS);
-			else if (strcasestr(a->line, "realtime user"))
-				return complete_sip_user(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS);
 		}
 		return NULL;
 	}
@@ -13390,10 +12959,9 @@
 	case 4:
 		name = a->argv[3];
 		/* we accept a name in position 3, but keywords are not good. */
-		if (!strcasecmp(name, "user") || !strcasecmp(name, "peer") ||
-		    !strcasecmp(name, "like"))
+		if (!strcasecmp(name, "peer") || !strcasecmp(name, "like"))
 			return CLI_SHOWUSAGE;
-		pruneuser = prunepeer = TRUE;
+		prunepeer = TRUE;
 		if (!strcasecmp(name, "all")) {
 			multi = TRUE;
 			name = NULL;
@@ -13401,14 +12969,12 @@
 		/* else a single name, already set */
 		break;
 	case 5:
-		/* sip prune realtime {user|peer|like} name */
+		/* sip prune realtime {peer|like} name */
 		name = a->argv[4];
-		if (!strcasecmp(a->argv[3], "user"))
-			pruneuser = TRUE;
-		else if (!strcasecmp(a->argv[3], "peer"))
+		if (!strcasecmp(a->argv[3], "peer"))
 			prunepeer = TRUE;
 		else if (!strcasecmp(a->argv[3], "like")) {
-			pruneuser = prunepeer = TRUE;
+			prunepeer = TRUE;
 			multi = TRUE;
 		} else
 			return CLI_SHOWUSAGE;
@@ -13422,12 +12988,10 @@
 	case 6:
 		name = a->argv[5];
 		multi = TRUE;
-		/* sip prune realtime {user|peer} like name */
+		/* sip prune realtime {peer} like name */
 		if (strcasecmp(a->argv[4], "like"))
 			return CLI_SHOWUSAGE;
-		if (!strcasecmp(a->argv[3], "user")) {
-			pruneuser = TRUE;
-		} else if (!strcasecmp(a->argv[3], "peer")) {
+		if (!strcasecmp(a->argv[3], "peer")) {
 			prunepeer = TRUE;
 		} else
 			return CLI_SHOWUSAGE;
@@ -13466,30 +13030,6 @@
 			} else
 				ast_cli(a->fd, "No peers found to prune.\n");
 		}
-		if (pruneuser) {
-			int pruned = 0;
-
-			i = ao2_iterator_init(users, 0);
-			while ((ui = ao2_t_iterator_next(&i, "iterate thru users table"))) {
-				ao2_lock(ui);
-				if (name && regexec(&regexbuf, ui->name, 0, NULL, 0)) {
-					unref_user(ui, "toss iterator user ptr before continue");
-					ao2_unlock(ui);
-					continue;
-				};
-				if (ast_test_flag(&ui->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
-					ui->the_mark = 1;
-					pruned++;
-				}
-				ao2_unlock(ui);
-				unref_user(ui, "toss iterator user ptr");
-			}
-			if (pruned) {
-				ao2_t_callback(users, OBJ_NODATA|OBJ_UNLINK, user_is_marked, 0, "callback to remove marked users");
-				ast_cli(a->fd, "%d users pruned.\n", pruned);
-			} else
-				ast_cli(a->fd, "No users found to prune.\n");
-		}
 	} else {
 		if (prunepeer) {
 			struct sip_peer tmp;
@@ -13512,20 +13052,6 @@
 			} else
 				ast_cli(a->fd, "Peer '%s' not found.\n", name);
 		}
-		if (pruneuser) {
-			struct sip_user tmp;
-			ast_copy_string(tmp.name, name, sizeof(tmp.name));
-			if ((user = ao2_t_find(users, &tmp, OBJ_POINTER|OBJ_UNLINK, "finding to unlink from users table"))) {
-				if (!ast_test_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
-					ast_cli(a->fd, "User '%s' is not a Realtime user, cannot be pruned.\n", name);
-					/* put it back! */
-					ao2_t_link(users, user, "link unlinked  user back into users table");
-				} else
-					ast_cli(a->fd, "User '%s' pruned.\n", name);
-				unref_user(user, "unref_user: Tossing temp user ptr");
-			} else
-				ast_cli(a->fd, "User '%s' not found.\n", name);
-		}
 	}
 
 	return CLI_SUCCESS;
@@ -13650,7 +13176,7 @@
 		return CLI_SHOWUSAGE;
 
 	load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE;
-	if ((peer = find_peer(argv[3], NULL, load_realtime))) {
+	if ((peer = find_peer(argv[3], NULL, load_realtime, FALSE))) {
 		sip_poke_peer(peer, 1);
 		unref_peer(peer, "qualify: done with peer");
 	} else if (type == 0) {
@@ -13732,7 +13258,7 @@
 		return CLI_SHOWUSAGE;
 
 	load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE;
-	peer = find_peer(argv[3], NULL, load_realtime);
+	peer = find_peer(argv[3], NULL, load_realtime, TRUE);
 	if (s) { 	/* Manager */
 		if (peer) {
 			const char *id = astman_get_header(m, "ActionID");
@@ -13988,79 +13514,6 @@
 	return CLI_SUCCESS;
 }
 
-/*! \brief Show one user in detail */
-static char *sip_show_user(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
-{
-	char cbuf[256];
-	struct sip_user *user;
-	struct ast_variable *v;
-	int load_realtime;
-
-	switch (cmd) {
-	case CLI_INIT:
-		e->command = "sip show user";
-		e->usage =
-			"Usage: sip show user <name> [load]\n"
-			"       Shows all details on one SIP user and the current status.\n"
-			"       Option \"load\" forces lookup of peer in realtime storage.\n";
-		return NULL;
-	case CLI_GENERATE:
-		return complete_sip_show_user(a->line, a->word, a->pos, a->n);
-	}
-
-	if (a->argc < 4)
-		return CLI_SHOWUSAGE;
-
-	/* Load from realtime storage? */
-	load_realtime = (a->argc == 5 && !strcmp(a->argv[4], "load")) ? TRUE : FALSE;
-
-	user = find_user(a->argv[3], load_realtime);
-	if (user) {
-		ast_cli(a->fd, "\n\n");
-		ast_cli(a->fd, "  * Name       : %s\n", user->name);
-		ast_cli(a->fd, "  Secret       : %s\n", ast_strlen_zero(user->secret)?"<Not set>":"<Set>");
-		ast_cli(a->fd, "  MD5Secret    : %s\n", ast_strlen_zero(user->md5secret)?"<Not set>":"<Set>");
-		ast_cli(a->fd, "  Context      : %s\n", user->context);
-		ast_cli(a->fd, "  Language     : %s\n", user->language);
-		if (!ast_strlen_zero(user->accountcode))
-			ast_cli(a->fd, "  Accountcode  : %s\n", user->accountcode);
-		ast_cli(a->fd, "  AMA flags    : %s\n", ast_cdr_flags2str(user->amaflags));
-		ast_cli(a->fd, "  Transfer mode: %s\n", transfermode2str(user->allowtransfer));
-		ast_cli(a->fd, "  MaxCallBR    : %d kbps\n", user->maxcallbitrate);
-		ast_cli(a->fd, "  CallingPres  : %s\n", ast_describe_caller_presentation(user->callingpres));
-		ast_cli(a->fd, "  Call limit   : %d\n", user->call_limit);
-		ast_cli(a->fd, "  Callgroup    : ");
-		print_group(a->fd, user->callgroup, 0);
-		ast_cli(a->fd, "  Pickupgroup  : ");
-		print_group(a->fd, user->pickupgroup, 0);
-		ast_cli(a->fd, "  Callerid     : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>"));
-		ast_cli(a->fd, "  ACL          : %s\n", cli_yesno(user->ha != NULL));
- 		ast_cli(a->fd, "  Sess-Timers  : %s\n", stmode2str(user->stimer.st_mode_oper));
- 		ast_cli(a->fd, "  Sess-Refresh : %s\n", strefresher2str(user->stimer.st_ref));
- 		ast_cli(a->fd, "  Sess-Expires : %d secs\n", user->stimer.st_max_se);
- 		ast_cli(a->fd, "  Sess-Min-SE  : %d secs\n", user->stimer.st_min_se);
-
-		ast_cli(a->fd, "  Codec Order  : (");
-		print_codec_to_cli(a->fd, &user->prefs);
-		ast_cli(a->fd, ")\n");
-
-		ast_cli(a->fd, "  Auto-Framing:  %s \n", cli_yesno(user->autoframing));
-		if (user->chanvars) {
- 			ast_cli(a->fd, "  Variables    :\n");
-			for (v = user->chanvars ; v ; v = v->next)
- 				ast_cli(a->fd, "                 %s = %s\n", v->name, v->value);
-		}
-
-		ast_cli(a->fd, "\n");
-		unref_user(user, "unref_user from sip_show_user, near end");

[... 681 lines stripped ...]



More information about the asterisk-commits mailing list