[svn-commits] oej: branch oej/kill-the-user r91499 - /team/oej/kill-the-user/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Dec 6 12:20:58 CST 2007


Author: oej
Date: Thu Dec  6 12:20:58 2007
New Revision: 91499

URL: http://svn.digium.com/view/asterisk?view=rev&rev=91499
Log:
Good bye, sip user.

Modified:
    team/oej/kill-the-user/channels/chan_sip.c

Modified: team/oej/kill-the-user/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/oej/kill-the-user/channels/chan_sip.c?view=diff&rev=91499&r1=91498&r2=91499
==============================================================================
--- team/oej/kill-the-user/channels/chan_sip.c (original)
+++ team/oej/kill-the-user/channels/chan_sip.c Thu Dec  6 12:20:58 2007
@@ -597,7 +597,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 */
@@ -649,8 +648,6 @@
 /*@}*/ 
 
 /* Object counters */
-static int suserobjs = 0;                /*!< Static users */
-static int ruserobjs = 0;                /*!< Realtime users */
 static int speerobjs = 0;                /*!< Statis peers */
 static int rpeerobjs = 0;                /*!< Realtime peers */
 static int apeerobjs = 0;                /*!< Autocreated peer objects */
@@ -1229,42 +1226,6 @@
 	char data[0];
 };	
 
-/*! \brief Structure for SIP user data. User's place calls to us */
-struct sip_user {
-	/* Users who can access various contexts */
-	ASTOBJ_COMPONENTS(struct sip_user);
-	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 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 */
-
-	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;
-};
-
 /*!
  * \brief A peer's mailbox
  *
@@ -1401,11 +1362,6 @@
 
 /* --- Linked lists of various objects --------*/
 
-/*! \brief  The user list: Users and friends */
-static struct ast_user_list {
-	ASTOBJ_CONTAINER_COMPONENTS(struct sip_user);
-} userl;
-
 /*! \brief  The peer list: Peers and Friends */
 static struct ast_peer_list {
 	ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
@@ -1645,7 +1601,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_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_show_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -1659,7 +1614,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_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
 static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -1670,8 +1624,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_history(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -1700,16 +1652,13 @@
 /*--- 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, int realtime);
 static int update_call_counter(struct sip_pvt *fup, int event);
 static void sip_destroy_peer(struct sip_peer *peer);
-static void sip_destroy_user(struct sip_user *user);
 static int sip_poke_peer(struct sip_peer *peer);
 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 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);
@@ -1719,7 +1668,6 @@
 
 /* Realtime device support */
 static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, const char *fullcontact, int expirey);
-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);
@@ -1917,11 +1865,6 @@
 static void unref_peer(struct sip_peer *peer)
 {
 	ASTOBJ_UNREF(peer, sip_destroy_peer);
-}
-
-static void unref_user(struct sip_user *user)
-{
-	ASTOBJ_UNREF(user, sip_destroy_user);
 }
 
 static void *registry_unref(struct sip_registry *reg)
@@ -3243,77 +3186,6 @@
 	return p;
 }
 
-/*! \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)
-		ruserobjs--;
-	else
-		suserobjs--;
-	ast_free(user);
-}
-
-/*! \brief Load user from realtime storage
- * Loads user from "sipusers" category in realtime (extconfig.conf)
- * 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, NULL);
-
-	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, !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);
-		suserobjs++;
-		ASTOBJ_CONTAINER_LINK(&userl,user);
-	} else {
-		/* Move counter from s to r... */
-		suserobjs--;
-		ruserobjs++;
-		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) */
-static struct sip_user *find_user(const char *name, int realtime)
-{
-	struct sip_user *u = ASTOBJ_CONTAINER_FIND(&userl, name);
-	if (!u && realtime)
-		u = realtime_user(name);
-	return u;
-}
-
 /*! \brief Set nat mode on the various data sockets */
 static void do_setnat(struct sip_pvt *p, int natflags)
 {
@@ -3787,7 +3659,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");
@@ -3801,17 +3672,13 @@
 	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 */
+	if ( (p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, 1) ) ) { /* 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;
 	}
@@ -3836,7 +3703,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:
@@ -3844,11 +3711,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_ERROR, "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);
-				else
-					unref_peer(p);
+				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);
 				return -1; 
 			}
 		}
@@ -3862,7 +3726,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;
 
@@ -3879,8 +3743,7 @@
 	if (p) {
 		ast_device_state_changed("SIP/%s", p->name);
 		unref_peer(p);
-	} else /* u must be set */
-		unref_user(u);
+	} 
 	return 0;
 }
 
@@ -10210,112 +10073,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);
-		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) && !ast_strlen_zero(p->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_strlen_zero(p->cid_num))
-			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);
-		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);
-	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,
@@ -10330,7 +10087,12 @@
 	/* For subscribes, match on peer 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 peer on name */
+	peer = find_peer(of, NULL, 1);
+
+	/* Then find peer on IP (if it's not a SUBSCRIBE) */
+	if (sipmethod != SIP_SUBSCRIBE)
+		find_peer(NULL, &p->recv, 1);
 
 	if (!peer) {
 		if (debug)
@@ -10539,15 +10301,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)
@@ -10652,7 +10405,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:
@@ -10665,19 +10418,6 @@
 	if (a->argc == 4 && !strcmp(a->argv[3],"all")) 
 		showall = TRUE;
 	
-	ast_cli(a->fd, FORMAT, "* User name", "In use", "Limit");
-	ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
-		ASTOBJ_RDLOCK(iterator);
-		if (iterator->call_limit)
-			snprintf(ilimits, sizeof(ilimits), "%d", iterator->call_limit);
-		else 
-			ast_copy_string(ilimits, "N/A", sizeof(ilimits));
-		snprintf(iused, sizeof(iused), "%d", iterator->inUse);
-		if (showall || iterator->call_limit)
-			ast_cli(a->fd, FORMAT2, iterator->name, iused, ilimits);
-		ASTOBJ_UNLOCK(iterator);
-	} while (0) );
-
 	ast_cli(a->fd, FORMAT, "* Peer name", "In use", "Limit");
 
 	ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
@@ -10755,66 +10495,6 @@
 static const char *cli_yesno(int x)
 {
 	return x ? "Yes" : "No";
-}
-
-/*! \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;
-
-#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");
-	ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
-		ASTOBJ_RDLOCK(iterator);
-
-		if (havepattern && regexec(&regexbuf, iterator->name, 0, NULL, 0)) {
-			ASTOBJ_UNLOCK(iterator);
-			continue;
-		}
-
-		ast_cli(a->fd, FORMAT, iterator->name, 
-			iterator->secret, 
-			iterator->accountcode,
-			iterator->context,
-			cli_yesno(iterator->ha != NULL),
-			nat2str(ast_test_flag(&iterator->flags[0], SIP_NAT)));
-		ASTOBJ_UNLOCK(iterator);
-	} while (0)
-	);
-
-	if (havepattern)
-		regfree(&regexbuf);
-
-	return CLI_SUCCESS;
-#undef FORMAT
 }
 
 /*! \brief Manager Action SIPShowRegistry description */
@@ -11079,8 +10759,6 @@
 
 	if (a->argc != 3)
 		return CLI_SHOWUSAGE;
-	ast_cli(a->fd, "-= User objects: %d static, %d realtime =-\n\n", suserobjs, ruserobjs);
-	ASTOBJ_CONTAINER_DUMP(a->fd, tmp, sizeof(tmp), &userl);
 	ast_cli(a->fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs);
 	ASTOBJ_CONTAINER_DUMP(a->fd, tmp, sizeof(tmp), &peerl);
 	ast_cli(a->fd, "-= Registry objects: %d =-\n\n", regobjs);
@@ -11157,20 +10835,19 @@
 }
 
 /*! \brief Remove temporary realtime objects from memory (CLI) */
+/*! \todo XXXX Propably needs an overhaul after removal of the users */
 static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct sip_peer *peer;
-	struct sip_user *user;
-	int pruneuser = FALSE;
 	int prunepeer = FALSE;
 	int multi = FALSE;
 	char *name = NULL;
 	regex_t regexbuf;
 
 	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;
@@ -11178,8 +10855,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;
 	}
@@ -11187,10 +10862,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;
@@ -11198,14 +10872,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;
@@ -11219,12 +10891,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;
@@ -11262,29 +10932,6 @@
 				ast_cli(a->fd, "No peers found to prune.\n");
 			ASTOBJ_CONTAINER_UNLOCK(&peerl);
 		}
-		if (pruneuser) {
-			int pruned = 0;
-
-			ASTOBJ_CONTAINER_WRLOCK(&userl);
-			ASTOBJ_CONTAINER_TRAVERSE(&userl, 1, do {
-				ASTOBJ_RDLOCK(iterator);
-				if (name && regexec(&regexbuf, iterator->name, 0, NULL, 0)) {
-					ASTOBJ_UNLOCK(iterator);
-					continue;
-				};
-				if (ast_test_flag(&iterator->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
-					ASTOBJ_MARK(iterator);
-					pruned++;
-				}
-				ASTOBJ_UNLOCK(iterator);
-			} while (0) );
-			if (pruned) {
-				ASTOBJ_CONTAINER_PRUNE_MARKED(&userl, sip_destroy_user);
-				ast_cli(a->fd, "%d users pruned.\n", pruned);
-			} else
-				ast_cli(a->fd, "No users found to prune.\n");
-			ASTOBJ_CONTAINER_UNLOCK(&userl);
-		}
 	} else {
 		if (prunepeer) {
 			if ((peer = ASTOBJ_CONTAINER_FIND_UNLINK(&peerl, name))) {
@@ -11296,17 +10943,6 @@
 				unref_peer(peer);
 			} else
 				ast_cli(a->fd, "Peer '%s' not found.\n", name);
-		}
-		if (pruneuser) {
-			if ((user = ASTOBJ_CONTAINER_FIND_UNLINK(&userl, name))) {
-				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);
-					ASTOBJ_CONTAINER_LINK(&userl, user);
-				} else
-					ast_cli(a->fd, "User '%s' pruned.\n", name);
-				unref_user(user);
-			} else
-				ast_cli(a->fd, "User '%s' not found.\n", name);
 		}
 	}
 
@@ -11660,73 +11296,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, "  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);
-	} else {
-		ast_cli(a->fd,"User %s not found.\n", a->argv[3]);
-		ast_cli(a->fd,"\n");
-	}
-
-	return CLI_SUCCESS;
-}
-
 /*! \brief  Show SIP Registry (registrations with other SIP proxies */
 static char *sip_show_registry(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
@@ -11852,7 +11421,6 @@
 	ast_cli(a->fd, "  Our auth realm          %s\n", global_realm);
 	ast_cli(a->fd, "  Realm. auth:            %s\n", cli_yesno(authl != NULL));
  	ast_cli(a->fd, "  Always auth rejects:    %s\n", cli_yesno(global_alwaysauthreject));
-	ast_cli(a->fd, "  Call limit peers only:  %s\n", cli_yesno(global_limitonpeers));
 	ast_cli(a->fd, "  Direct RTP setup:       %s\n", cli_yesno(global_directrtpsetup));
 	ast_cli(a->fd, "  User Agent:             %s\n", global_useragent);
 	ast_cli(a->fd, "  SDP Session Name:       %s\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession);
@@ -12196,35 +11764,6 @@
                return complete_sip_registered_peer(word, state, 0);
 
        return NULL;
-}
-
-/*! \brief Do completion on user name */
-static char *complete_sip_user(const char *word, int state, int flags2)
-{
-	char *result = NULL;
-	int wordlen = strlen(word);
-	int which = 0;
-
-	ASTOBJ_CONTAINER_TRAVERSE(&userl, !result, do {
-		/* locking of the object is not required because only the name and flags are being compared */
-		if (!strncasecmp(word, iterator->name, wordlen)) {
-			if (flags2 && !ast_test_flag(&iterator->flags[1], flags2))
-				continue;
-			if (++which > state) {
-				result = ast_strdup(iterator->name);
-			}
-		}
-	} while(0) );
-	return result;
-}
-
-/*! \brief Support routine for 'sip show user' CLI */
-static char *complete_sip_show_user(const char *line, const char *word, int pos, int state)
-{
-	if (pos == 3)
-		return complete_sip_user(word, state, 0);
-
-	return NULL;
 }
 
 /*! \brief Support routine for 'sip notify' CLI */
@@ -17616,123 +17155,6 @@
 	return list;
 }
 
-/*! \brief Initiate a SIP user structure from configuration (configuration or realtime) */
-static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime)
-{
-	struct sip_user *user;
-	int format;
-	struct ast_ha *oldha = NULL;
-	struct ast_flags userflags[2] = {{(0)}};
-	struct ast_flags mask[2] = {{(0)}};
-
-
-	if (!(user = ast_calloc(1, sizeof(*user))))
-		return NULL;
-		
-	suserobjs++;
-	ASTOBJ_INIT(user);
-	ast_copy_string(user->name, name, sizeof(user->name));
-	oldha = user->ha;
-	user->ha = NULL;
-	ast_copy_flags(&user->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY);
-	ast_copy_flags(&user->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);
-	user->capability = global_capability;
-	user->allowtransfer = global_allowtransfer;
-	user->maxcallbitrate = default_maxcallbitrate;
-	user->autoframing = global_autoframing;
-	if (global_callcounter)
-		user->call_limit=999;
-	user->prefs = default_prefs;
-	/* set default context */
-	strcpy(user->context, default_context);
-	strcpy(user->language, default_language);
-	strcpy(user->mohinterpret, default_mohinterpret);
-	strcpy(user->mohsuggest, default_mohsuggest);
-	for (; v; v = v->next) {
-		if (handle_common_options(&userflags[0], &mask[0], v))
-			continue;
-
-		if (!strcasecmp(v->name, "context")) {
-			ast_copy_string(user->context, v->value, sizeof(user->context));
-		} else if (!strcasecmp(v->name, "subscribecontext")) {
-			ast_copy_string(user->subscribecontext, v->value, sizeof(user->subscribecontext));
-		} else if (!strcasecmp(v->name, "setvar")) {
-			user->chanvars = add_var(v->value, user->chanvars);
-		} else if (!strcasecmp(v->name, "permit") ||
-				   !strcasecmp(v->name, "deny")) {
-			int ha_error = 0;
-
-			user->ha = ast_append_ha(v->name, v->value, user->ha, &ha_error);
-			if (ha_error)
-				ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value);
-		} else if (!strcasecmp(v->name, "allowtransfer")) {
-			user->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED;
-		} else if (!strcasecmp(v->name, "secret")) {
-			ast_copy_string(user->secret, v->value, sizeof(user->secret)); 
-		} else if (!strcasecmp(v->name, "md5secret")) {
-			ast_copy_string(user->md5secret, v->value, sizeof(user->md5secret));
-		} else if (!strcasecmp(v->name, "callerid")) {
-			ast_callerid_split(v->value, user->cid_name, sizeof(user->cid_name), user->cid_num, sizeof(user->cid_num));
-		} else if (!strcasecmp(v->name, "fullname")) {
-			ast_copy_string(user->cid_name, v->value, sizeof(user->cid_name));
-		} else if (!strcasecmp(v->name, "cid_number")) {
-			ast_copy_string(user->cid_num, v->value, sizeof(user->cid_num));
-		} else if (!strcasecmp(v->name, "callgroup")) {
-			user->callgroup = ast_get_group(v->value);
-		} else if (!strcasecmp(v->name, "pickupgroup")) {
-			user->pickupgroup = ast_get_group(v->value);
-		} else if (!strcasecmp(v->name, "language")) {
-			ast_copy_string(user->language, v->value, sizeof(user->language));
-		} else if (!strcasecmp(v->name, "mohinterpret")) {
-			ast_copy_string(user->mohinterpret, v->value, sizeof(user->mohinterpret));
-		} else if (!strcasecmp(v->name, "mohsuggest")) {
-			ast_copy_string(user->mohsuggest, v->value, sizeof(user->mohsuggest));
-		} else if (!strcasecmp(v->name, "accountcode")) {
-			ast_copy_string(user->accountcode, v->value, sizeof(user->accountcode));
-		} else if (!strcasecmp(v->name, "callcounter")) {
-			user->call_limit = ast_true(v->value) ? 999 : 0;
-		} else if (!strcasecmp(v->name, "call-limit")) {
-			user->call_limit = atoi(v->value);
-			if (user->call_limit < 0)
-				user->call_limit = 0;
-		} else if (!strcasecmp(v->name, "amaflags")) {
-			format = ast_cdr_amaflags2int(v->value);
-			if (format < 0) {
-				ast_log(LOG_WARNING, "Invalid AMA Flags: %s at line %d\n", v->value, v->lineno);
-			} else {
-				user->amaflags = format;
-			}
-		} else if (!strcasecmp(v->name, "allow")) {
-			int error =  ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, TRUE);
-			if (error)
-				ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value);
-		} else if (!strcasecmp(v->name, "disallow")) {
-			int error =  ast_parse_allow_disallow(&user->prefs, &user->capability, v->value, FALSE);
-			if (error)
-				ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value);
-		} else if (!strcasecmp(v->name, "autoframing")) {
-			user->autoframing = ast_true(v->value);
-		} else if (!strcasecmp(v->name, "callingpres")) {
-			user->callingpres = ast_parse_caller_presentation(v->value);
-			if (user->callingpres == -1)
-				user->callingpres = atoi(v->value);
-		} else if (!strcasecmp(v->name, "maxcallbitrate")) {
-			user->maxcallbitrate = atoi(v->value);
-			if (user->maxcallbitrate < 0)
-				user->maxcallbitrate = default_maxcallbitrate;
-		}
-		/* We can't just report unknown options here because this may be a
-		 * type=friend entry.  All user options are valid for a peer, but not
-		 * the other way around.  */
-	}
-	ast_copy_flags(&user->flags[0], &userflags[0], mask[0].flags);
-	ast_copy_flags(&user->flags[1], &userflags[1], mask[1].flags);
-	if (ast_test_flag(&user->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))
-		global_allowsubscribe = TRUE;	/* No global ban any more */
-	ast_free_ha(oldha);
-	return user;
-}
-
 /*! \brief Set peer defaults before configuring specific configurations */
 static void set_peer_defaults(struct sip_peer *peer)
 {
@@ -18119,7 +17541,6 @@
 	struct ast_config *cfg, *ucfg;
 	struct ast_variable *v;
 	struct sip_peer *peer;
-	struct sip_user *user;
 	char *cat, *stringp, *context, *oldregcontext;
 	char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT];
 	struct ast_flags dummy[2];
@@ -18167,8 +17588,6 @@
 		} while(0));
 
 		/* Then, actually destroy users and registry */
-		ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user);
-		ast_debug(4, "--------------- Done destroying user list\n");
 		ASTOBJ_CONTAINER_DESTROYALL(&regl, sip_registry_destroy);
 		ast_debug(4, "--------------- Done destroying registry list\n");
 		ASTOBJ_CONTAINER_MARKALL(&peerl);
@@ -18218,7 +17637,6 @@
 	global_regextenonqualify = DEFAULT_REGEXTENONQUALIFY;
 	expiry = DEFAULT_EXPIRY;
 	global_notifyringing = DEFAULT_NOTIFYRINGING;
-	global_limitonpeers = FALSE;		/*!< Match call limit on peers only */
 	global_notifyhold = FALSE;		/*!< Keep track of hold status for a peer */
 	global_directrtpsetup = FALSE;		/* Experimental feature, disabled by default */
 	global_alwaysauthreject = 0;
@@ -18353,8 +17771,6 @@
 			compactheaders = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "notifymimetype")) {
 			ast_copy_string(default_notifymime, v->value, sizeof(default_notifymime));
-		} else if (!strncasecmp(v->name, "limitonpeer", 11) || !strcasecmp(v->name, "counteronpeer")) {
-			global_limitonpeers = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "directrtpsetup")) {
 			global_directrtpsetup = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "notifyringing")) {
@@ -18620,24 +18036,18 @@
 			ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat);
 			continue;
 		} else {
-			int is_user = 0, is_peer = 0;
-			if (!strcasecmp(utype, "user"))
-				is_user = 1;
-			else if (!strcasecmp(utype, "friend"))
-				is_user = is_peer = 1;
-			else if (!strcasecmp(utype, "peer"))
+			int is_peer = 0;
+			if (!strcasecmp(utype, "user")) {
+				ast_log(LOG_WARNING, "type=user is deprecated. Please use type=peer only.");
+				is_peer = 1;
+			} else if (!strcasecmp(utype, "friend")) {
+				ast_log(LOG_WARNING, "type=friend is deprecated. Please use type=peer only.");
+				is_peer = 1;
+			} else if (!strcasecmp(utype, "peer"))
 				is_peer = 1;
 			else {
 				ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf");
 				continue;
-			}
-			if (is_user) {
-				user = build_user(cat, ast_variable_browse(cfg, cat), 0);
-				if (user) {
-					ASTOBJ_CONTAINER_LINK(&userl,user);
-					unref_user(user);
-					user_count++;
-				}
 			}
 			if (is_peer) {
 				peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0);
@@ -19305,8 +18715,6 @@
 	AST_CLI_DEFINE(sip_show_channel, "Show detailed SIP channel info"),
 	AST_CLI_DEFINE(sip_show_history, "Show SIP dialog history"),
 	AST_CLI_DEFINE(sip_show_peer, "Show details on specific SIP peer"),
-	AST_CLI_DEFINE(sip_show_users, "List defined SIP users"),
-	AST_CLI_DEFINE(sip_show_user, "Show details on specific SIP user"),
 	AST_CLI_DEFINE(sip_prune_realtime, "Prune cached Realtime users/peers"),
 	AST_CLI_DEFINE(sip_do_debug, "Enable/Disable SIP debugging"),
 	AST_CLI_DEFINE(sip_do_history, "Enable SIP history"),
@@ -19318,7 +18726,6 @@
 static int load_module(void)
 {
 	ast_verbose("SIP channel loading...\n");
-	ASTOBJ_CONTAINER_INIT(&userl);	/* User object list */
 	ASTOBJ_CONTAINER_INIT(&peerl);	/* Peer object list */
 	ASTOBJ_CONTAINER_INIT(&regl);	/* Registry object list */
 
@@ -19452,8 +18859,6 @@
 	/* Free memory for local network address mask */
 	ast_free_ha(localaddr);
 
-	ASTOBJ_CONTAINER_DESTROYALL(&userl, sip_destroy_user);
-	ASTOBJ_CONTAINER_DESTROY(&userl);
 	ASTOBJ_CONTAINER_DESTROYALL(&peerl, sip_destroy_peer);
 	ASTOBJ_CONTAINER_DESTROY(&peerl);
 	ASTOBJ_CONTAINER_DESTROYALL(&regl, sip_registry_destroy);




More information about the svn-commits mailing list