From 318fd4186b53876729c506f97787b94eeaa7c9d4 Mon Sep 17 00:00:00 2001 From: Olle Johansson Date: Sat, 5 Jul 2008 20:59:49 +0000 Subject: [PATCH] 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! git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@128242 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 1012 +++++-------------------------------------- 1 file changed, 108 insertions(+), 904 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 1c43752892..879512ee8e 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -730,7 +730,6 @@ static struct sip_settings sip_cfg; */ /*@{*/ 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_rtpholdtimeout; /*!< Time out call if no RTP during hold */ 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 @@ static int global_max_se; /*!< Highest threshold for session /*! \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 sip_pkt { 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 @@ struct sip_peer { 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 @@ static int hash_user_size = 563; /*! \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; @@ -1712,26 +1668,6 @@ static int peer_ipcmp_cb(void *obj, void *arg, int flags) 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; -} - /*! * \note The only member of the dialog used here callid string */ @@ -2008,7 +1944,6 @@ static char *sip_show_inuse(struct ast_cli_entry *e, int cmd, struct ast_cli_arg 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 const char *domain_mode_to_text(const enum domain_mode mode); 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_registered_peer(const char *word, int state, int flags 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 @@ static void sip_dump_history(struct sip_pvt *dialog); /*--- 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 @@ static int handle_common_options(struct ast_flags *flags, struct ast_flags *mask /* 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); @@ -2457,12 +2384,6 @@ static void *unref_peer(struct sip_peer *peer, char *tag) return NULL; } -static void *unref_user(struct sip_user *user, char *tag) -{ - ao2_t_ref(user, -1, tag); - return NULL; -} - static struct sip_peer *ref_peer(struct sip_peer *peer, char *tag) { ao2_t_ref(peer, 1,tag); @@ -4023,7 +3944,7 @@ static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_i /* 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 @@ static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_i 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; @@ -4096,94 +4018,6 @@ static struct sip_peer *find_peer(const char *peer, struct sockaddr_in *sin, int 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 */ static void do_setnat(struct sip_pvt *p, int natflags) { @@ -4398,7 +4232,7 @@ static int create_addr_from_peer(struct sip_pvt *dialog, struct sip_peer *peer) 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 @@ static int create_addr(struct sip_pvt *dialog, const char *opeer, struct sockadd 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 @@ static void __sip_destroy(struct sip_pvt *p, int lockowner, int lockdialoglist) } } -/*! \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 @@ static int update_call_counter(struct sip_pvt *fup, int event) 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 @@ static int update_call_counter(struct sip_pvt *fup, int event) 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 @@ static int update_call_counter(struct sip_pvt *fup, int event) 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 @@ static int update_call_counter(struct sip_pvt *fup, int event) /* 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 @@ static int update_call_counter(struct sip_pvt *fup, int event) 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 @@ static int update_call_counter(struct sip_pvt *fup, int event) 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 @@ static enum check_auth_result check_auth(struct sip_pvt *p, struct sip_request * /*! \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 @@ static int cb_extensionstate(char *context, char* exten, int state, void *data) } /*! \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 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct sockaddr 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 @@ static enum check_auth_result register_verify(struct sip_pvt *p, struct sockaddr 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 @@ static void replace_cid(struct sip_pvt *p, const char *rpid_num, const char *cal } } -/*! \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 @@ static enum check_auth_result check_peer_ok(struct sip_pvt *p, char *of, 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 @@ static enum check_auth_result check_user_full(struct sip_pvt *p, struct sip_requ } } - 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 @@ static char *sip_show_inuse(struct ast_cli_entry *e, int cmd, struct ast_cli_arg char iused[40]; int showall = FALSE; struct ao2_iterator i; - struct sip_user *user; struct sip_peer *peer; switch (cmd) { @@ -12281,7 +11994,7 @@ static char *sip_show_inuse(struct ast_cli_entry *e, int cmd, struct ast_cli_arg 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 @@ static char *sip_show_inuse(struct ast_cli_entry *e, int cmd, struct ast_cli_arg 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); @@ -12485,103 +12180,6 @@ static char *sip_show_tcp(struct ast_cli_entry *e, int cmd, struct ast_cli_args #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 ]\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(®exbuf, 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(®exbuf, 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(®exbuf); - 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 */ static char mandescr_show_registry[] = "Description: Lists all registration requests and status\n" @@ -12708,7 +12306,6 @@ static char *sip_dbdump(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[]) { struct sip_peer *peer; - struct sip_user *user; struct ao2_iterator i; char fname[1024]; const char *id; @@ -12742,7 +12339,7 @@ static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct 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 @@ static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct 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 @@ static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct 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 @@ static char *_sip_dbdump(int fd, int *total, struct mansession *s, const struct 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 @@ static char *_sip_show_peers(int fd, int *total, struct mansession *s, const str #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 @@ static char *sip_show_objects(struct ast_cli_entry *e, int cmd, struct ast_cli_a 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 @@ static int peer_is_marked(void *peerobj, void *arg, int flags) 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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli 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] [|all|like ]\n" + "Usage: sip prune realtime [peer] [|all|like ]\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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli 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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli 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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli /* 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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli 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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli } 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(®exbuf, 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 @@ static char *sip_prune_realtime(struct ast_cli_entry *e, int cmd, struct ast_cli } 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 @@ static char *_sip_qualify_peer(int type, int fd, struct mansession *s, const str 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 @@ static char *_sip_show_peer(int type, int fd, struct mansession *s, const struct 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 @@ static char *sip_show_sched(struct ast_cli_entry *e, int cmd, struct ast_cli_arg 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 [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)?"":""); - ast_cli(a->fd, " MD5Secret : %s\n", ast_strlen_zero(user->md5secret)?"":""); - 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, "")); - 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"); - } 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) { @@ -14127,7 +13580,7 @@ static char *sip_unregister(struct ast_cli_entry *e, int cmd, struct ast_cli_arg if (a->argc != 3) return CLI_SHOWUSAGE; - if ((peer = find_peer(a->argv[2], NULL, load_realtime))) { + if ((peer = find_peer(a->argv[2], NULL, load_realtime, TRUE))) { if (peer->expire > 0) { expire_register(peer); ast_cli(a->fd, "Unregistered peer \'%s\'\n\n", a->argv[2]); @@ -14233,7 +13686,6 @@ static char *sip_show_channelstats(struct ast_cli_entry *e, int cmd, struct ast_ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) { int realtimepeers; - int realtimeusers; int realtimeregs; char codec_buf[SIPBUFSIZE]; const char *msg; /* temporary msg pointer */ @@ -14251,7 +13703,6 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_ realtimepeers = ast_check_realtime("sippeers"); - realtimeusers = ast_check_realtime("sipusers"); realtimeregs = ast_check_realtime("sipregs"); if (a->argc != 3) @@ -14275,7 +13726,6 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_ 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); @@ -14293,7 +13743,7 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_ ast_cli(a->fd, " T38 fax pt RTP: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_RTP))); ast_cli(a->fd, " T38 fax pt TCP: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT_TCP))); #endif - if (!realtimepeers && !realtimeusers && !realtimeregs) + if (!realtimepeers && !realtimeregs) ast_cli(a->fd, " SIP realtime: Disabled\n" ); else ast_cli(a->fd, " SIP realtime: Enabled\n" ); @@ -14397,11 +13847,10 @@ static char *sip_show_settings(struct ast_cli_entry *e, int cmd, struct ast_cli_ ast_cli(a->fd, " Voice Mail Extension: %s\n", default_vmexten); - if (realtimepeers || realtimeusers || realtimeregs) { + if (realtimepeers || realtimeregs) { ast_cli(a->fd, "\nRealtime SIP Settings:\n"); ast_cli(a->fd, "----------------------\n"); ast_cli(a->fd, " Realtime Peers: %s\n", cli_yesno(realtimepeers)); - ast_cli(a->fd, " Realtime Users: %s\n", cli_yesno(realtimeusers)); ast_cli(a->fd, " Realtime Regs: %s\n", cli_yesno(realtimeregs)); ast_cli(a->fd, " Cache Friends: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS))); ast_cli(a->fd, " Update: %s\n", cli_yesno(sip_cfg.peer_rtupdate)); @@ -14645,46 +14094,6 @@ static char *complete_sip_unregister(const char *line, const char *word, int pos 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; - struct ao2_iterator i; - struct sip_user *user; - - i = ao2_iterator_init(users, 0); - - while ((user = ao2_t_iterator_next(&i, "iterate thru users table"))) { - /* locking of the object is not required because only the name and flags are being compared */ - if (!strncasecmp(word, user->name, wordlen)) { - if (flags2 && !ast_test_flag(&user->flags[1], flags2)) { - unref_user(user, "toss iterator user ptr before continue"); - continue; - } - if (++which > state) { - result = ast_strdup(user->name); - } - } - if (result) { - unref_user(user, "toss iterator user ptr before break"); - break; - } - unref_user(user, "toss iterator user ptr"); - } - 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 */ static char *complete_sipnotify(const char *line, const char *word, int pos, int state) { @@ -15129,7 +14538,7 @@ static char *sip_do_debug_ip(int fd, char *arg) /*! \brief Turn on SIP debugging for a given peer */ static char *sip_do_debug_peer(int fd, char *arg) { - struct sip_peer *peer = find_peer(arg, NULL, 1); + struct sip_peer *peer = find_peer(arg, NULL, TRUE, TRUE); if (!peer) ast_cli(fd, "No such peer '%s'\n", arg); else if (peer->addr.sin_addr.s_addr == 0) @@ -15440,8 +14849,8 @@ static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header /*! \brief Build reply digest \return Returns -1 if we have no auth -\note Build digest challenge for authentication of peers (for registration) - and users (for calls). Also used for authentication of CANCEL and BYE +\note Build digest challenge for authentication of registrations and calls + Also used for authentication of BYE */ static int build_reply_digest(struct sip_pvt *p, int method, char* digest, int digest_len) { @@ -15625,7 +15034,7 @@ static int function_sippeer(struct ast_channel *chan, const char *cmd, char *dat else colname = "ip"; - if (!(peer = find_peer(data, NULL, 1))) + if (!(peer = find_peer(data, NULL, TRUE, TRUE))) return -1; if (!strcasecmp(colname, "ip")) { @@ -16592,7 +16001,7 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_ gettag(req, "To", tag, sizeof(tag)); ast_string_field_set(p, theirtag, tag); } - /* This needs to be configurable on a channel/peer/user level, + /* This needs to be configurable on a channel/peer level, not mandatory for all communication. Sadly enough, NAT implementations are not so stable so we can always rely on these headers. Temporarily disabled, while waiting for fix. @@ -17364,7 +16773,7 @@ static int handle_request_options(struct sip_pvt *p, struct sip_request *req) int res; /*! XXX get_destination assumes we're already authenticated. This means that a request from - a known device (peer/user) will end up in the wrong context if this is out-of-dialog. + a known device (peer) will end up in the wrong context if this is out-of-dialog. However, we want to handle OPTIONS as light as possible, so we might want to have a configuration option whether we care or not. Some devices use this for testing capabilities, which means that we need to match device to answer with proper @@ -17790,10 +17199,10 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int } if (res < 0) { /* Something failed in authentication */ if (res == AUTH_FAKE_AUTH) { - ast_log(LOG_NOTICE, "Sending fake auth rejection for user %s\n", get_header(req, "From")); + ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); transmit_fake_auth_response(p, req, 1); } else { - ast_log(LOG_NOTICE, "Failed to authenticate user %s\n", get_header(req, "From")); + ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From")); transmit_response_reliable(p, "403 Forbidden", req); } p->invitestate = INV_COMPLETED; @@ -17832,7 +17241,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, int ast_debug(1, "Checking SIP call limits for device %s\n", p->username); if ((res = update_call_counter(p, INC_CALL_LIMIT))) { if (res < 0) { - ast_log(LOG_NOTICE, "Failed to place call for user %s, too many calls\n", p->username); + ast_log(LOG_NOTICE, "Failed to place call for device %s, too many calls\n", p->username); transmit_response_reliable(p, "480 Temporarily Unavailable (Call limit) ", req); sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); p->invitestate = INV_COMPLETED; @@ -18973,7 +18382,7 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, } /* Check if we have a global disallow setting on subscriptions. - if so, we don't have to check peer/user settings after auth, which saves a lot of processing + if so, we don't have to check peer settings after auth, which saves a lot of processing */ if (!global_allowsubscribe) { transmit_response(p, "403 Forbidden (policy)", req); @@ -19028,10 +18437,10 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, return 0; if (res < 0) { if (res == AUTH_FAKE_AUTH) { - ast_log(LOG_NOTICE, "Sending fake auth rejection for user %s\n", get_header(req, "From")); + ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); transmit_fake_auth_response(p, req, 1); } else { - ast_log(LOG_NOTICE, "Failed to authenticate user %s for SUBSCRIBE\n", get_header(req, "From")); + ast_log(LOG_NOTICE, "Failed to authenticate device %s for SUBSCRIBE\n", get_header(req, "From")); transmit_response_reliable(p, "403 Forbidden", req); } p->needdestroy = 1; @@ -19043,7 +18452,7 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, * XXX must remove all the checks for authpeer == NULL. */ - /* Check if this user/peer is allowed to subscribe at all */ + /* Check if this device is allowed to subscribe at all */ if (!ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) { transmit_response(p, "403 Forbidden (policy)", req); p->needdestroy = 1; @@ -20297,22 +19706,12 @@ int st_get_se(struct sip_pvt *p, int max) if (max == TRUE) { if (p->stimer->st_cached_max_se) { return p->stimer->st_cached_max_se; - } else { - if (p->username) { - struct sip_user *up = find_user(p->username, 1); - if (up) { - p->stimer->st_cached_max_se = up->stimer.st_max_se; - unref_user(up, "unref user pointer from find_user call in st_get_se"); - return (p->stimer->st_cached_max_se); - } - } - if (p->peername) { - struct sip_peer *pp = find_peer(p->peername, NULL, 1); - if (pp) { - p->stimer->st_cached_max_se = pp->stimer.st_max_se; - unref_peer(pp, "unref peer pointer from find_peer call in st_get_se"); - return (p->stimer->st_cached_max_se); - } + } else if (p->peername) { + struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, TRUE); + if (pp) { + p->stimer->st_cached_max_se = pp->stimer.st_max_se; + unref_peer(pp, "unref peer pointer from find_peer call in st_get_se"); + return (p->stimer->st_cached_max_se); } } p->stimer->st_cached_max_se = global_max_se; @@ -20320,22 +19719,12 @@ int st_get_se(struct sip_pvt *p, int max) } else { if (p->stimer->st_cached_min_se) { return p->stimer->st_cached_min_se; - } else { - if (p->username) { - struct sip_user *up = find_user(p->username, 1); - if (up) { - p->stimer->st_cached_min_se = up->stimer.st_min_se; - unref_user(up, "unref user pointer from find_user call in st_get_se (2)"); - return (p->stimer->st_cached_min_se); - } - } - if (p->peername) { - struct sip_peer *pp = find_peer(p->peername, NULL, 1); - if (pp) { - p->stimer->st_cached_min_se = pp->stimer.st_min_se; - unref_peer(pp, "unref peer pointer from find_peer call in st_get_se (2)"); - return (p->stimer->st_cached_min_se); - } + } else if (p->peername) { + struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, TRUE); + if (pp) { + p->stimer->st_cached_min_se = pp->stimer.st_min_se; + unref_peer(pp, "unref peer pointer from find_peer call in st_get_se (2)"); + return (p->stimer->st_cached_min_se); } } p->stimer->st_cached_min_se = global_min_se; @@ -20352,17 +19741,8 @@ enum st_refresher st_get_refresher(struct sip_pvt *p) if (p->stimer->st_cached_ref != SESSION_TIMER_REFRESHER_AUTO) return p->stimer->st_cached_ref; - if (p->username) { - struct sip_user *up = find_user(p->username, 1); - if (up) { - p->stimer->st_cached_ref = up->stimer.st_ref; - unref_user(up, "unref user pointer from find_user call in st_get_refresher"); - return up->stimer.st_ref; - } - } - if (p->peername) { - struct sip_peer *pp = find_peer(p->peername, NULL, 1); + struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, TRUE); if (pp) { p->stimer->st_cached_ref = pp->stimer.st_ref; unref_peer(pp, "unref peer pointer from find_peer call in st_get_refresher"); @@ -20386,16 +19766,8 @@ enum st_mode st_get_mode(struct sip_pvt *p) if (p->stimer->st_cached_mode != SESSION_TIMER_MODE_INVALID) return p->stimer->st_cached_mode; - if (p->username) { - struct sip_user *up = find_user(p->username, 1); - if (up) { - p->stimer->st_cached_mode = up->stimer.st_mode_oper; - unref_user(up, "unref user pointer from find_user call in st_get_mode"); - return up->stimer.st_mode_oper; - } - } if (p->peername) { - struct sip_peer *pp = find_peer(p->peername, NULL, 1); + struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, TRUE); if (pp) { p->stimer->st_cached_mode = pp->stimer.st_mode_oper; unref_peer(pp, "unref peer pointer from find_peer call in st_get_mode"); @@ -20556,7 +19928,7 @@ static int sip_devicestate(void *data) ast_debug(3, "Checking device state for peer %s\n", host); - if ((p = find_peer(host, NULL, 1))) { + if ((p = find_peer(host, NULL, TRUE, TRUE))) { if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) { /* we have an address for the peer */ @@ -20777,7 +20149,7 @@ static void set_insecure_flags (struct ast_flags *flags, const char *value, int } /*! - \brief Handle flag-type options common to configuration of devices - users and peers + \brief Handle flag-type options common to configuration of devices - peers \param flags array of two struct ast_flags \param mask array of two struct ast_flags \param v linked list of config variables to process @@ -21068,156 +20440,6 @@ static struct ast_variable *add_var(const char *buf, struct ast_variable *list) 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, struct ast_variable *alt, int realtime) -{ - struct sip_user *user; - int format; - struct ast_flags userflags[2] = {{(0)}}; - struct ast_flags mask[2] = {{(0)}}; - - if (!(user = ao2_t_alloc(sizeof(*user), sip_destroy_user_fn, "allocate a user struct"))) - return NULL; - - ast_atomic_fetchadd_int(&suserobjs, 1); - ast_copy_string(user->name, name, sizeof(user->name)); - 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; - user->stimer.st_mode_oper = global_st_mode; /* Session-Timers */ - user->stimer.st_ref = global_st_refresher; - user->stimer.st_min_se = global_min_se; - user->stimer.st_max_se = global_max_se; - - /* set default context */ - strcpy(user->context, default_context); - strcpy(user->language, default_language); - strcpy(user->mohinterpret, default_mohinterpret); - strcpy(user->mohsuggest, default_mohsuggest); - /* First we walk through the v parameters list and then the alt parameters list */ - for (; v || ((v = alt) && !(alt=NULL)); 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, "parkinglot")) { - ast_copy_string(user->parkinglot, v->value, sizeof(user->parkinglot)); - } 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; - } else if (!strcasecmp(v->name, "session-timers")) { - int i = (int) str2stmode(v->value); - if (i < 0) { - ast_log(LOG_WARNING, "Invalid session-timers '%s' at line %d of %s\n", v->value, v->lineno, config); - user->stimer.st_mode_oper = global_st_mode; - } else { - user->stimer.st_mode_oper = i; - } - } else if (!strcasecmp(v->name, "session-expires")) { - if (sscanf(v->value, "%d", &user->stimer.st_max_se) != 1) { - ast_log(LOG_WARNING, "Invalid session-expires '%s' at line %d of %s\n", v->value, v->lineno, config); - user->stimer.st_max_se = global_max_se; - } - } else if (!strcasecmp(v->name, "session-minse")) { - if (sscanf(v->value, "%d", &user->stimer.st_min_se) != 1) { - ast_log(LOG_WARNING, "Invalid session-minse '%s' at line %d of %s\n", v->value, v->lineno, config); - user->stimer.st_min_se = global_min_se; - } - if (user->stimer.st_min_se < 90) { - ast_log(LOG_WARNING, "session-minse '%s' at line %d of %s is not allowed to be < 90 secs\n", v->value, v->lineno, config); - user->stimer.st_min_se = global_min_se; - } - } else if (!strcasecmp(v->name, "session-refresher")) { - int i = (int) str2strefresher(v->value); - if (i < 0) { - ast_log(LOG_WARNING, "Invalid session-refresher '%s' at line %d of %s\n", v->value, v->lineno, config); - user->stimer.st_ref = global_st_refresher; - } else { - user->stimer.st_ref = i; - } - } - - /* 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 */ - return user; -} - /*! \brief Set peer defaults before configuring specific configurations */ static void set_peer_defaults(struct sip_peer *peer) { @@ -21318,7 +20540,7 @@ static void add_peer_mailboxes(struct sip_peer *peer, const char *value) } /*! \brief Build peer from configuration (file or realtime static/dynamic) */ -static struct sip_peer *build_peer(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) { struct sip_peer *peer = NULL; struct ast_ha *oldha = NULL; @@ -21359,6 +20581,9 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str } else ast_atomic_fetchadd_int(&speerobjs, 1); } + + peer->onlymatchonip = ispeer; /* If type=peer, don't match on caller ID for incoming calls */ + /* Note that our peer HAS had its reference count increased */ if (firstpass) { peer->lastmsgssent = -1; @@ -21417,6 +20642,9 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str } else { ast_str_set(&fullcontact, 0, "%s", v->value); } + } else if (!strcasecmp(v->name, "type")) { + if (!strcasecmp(v->value, "peer")) + peer->onlymatchonip = true; /* For realtime support, add type=peer in the table */ } else if (!strcasecmp(v->name, "secret")) ast_copy_string(peer->secret, v->value, sizeof(peer->secret)); else if (!strcasecmp(v->name, "md5secret")) @@ -21725,9 +20953,9 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str return peer; } -static int peer_markall_func(void *userobj, void *arg, int flags) +static int peer_markall_func(void *device, void *arg, int flags) { - struct sip_peer *peer = userobj; + struct sip_peer *peer = device; peer->the_mark = 1; return 0; } @@ -21743,14 +20971,13 @@ static int reload_config(enum channelreloadreason reason) 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]; struct ast_flags config_flags = { reason == CHANNEL_MODULE_LOAD ? 0 : CONFIG_FLAG_FILEUNCHANGED }; int auto_sip_domains = FALSE; struct sockaddr_in old_bindaddr = bindaddr; - int registry_count = 0, peer_count = 0, user_count = 0; + int registry_count = 0, peer_count = 0; time_t run_start, run_end; run_start = time(0); @@ -21811,13 +21038,9 @@ static int reload_config(enum channelreloadreason reason) } while(0)); /* Then, actually destroy users and registry */ - ao2_t_ref(users, -1, "destroy users table"); - ast_debug(4, "--------------- Done destroying user list\n"); ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); ast_debug(4, "--------------- Done destroying registry list\n"); ao2_t_callback(peers, OBJ_NODATA, peer_markall_func, 0, "callback to mark all peers"); - /* reinstate the user table */ - users = ao2_t_container_alloc(hash_user_size, user_hash_cb, user_cmp_cb, "allocate users"); } /* Reset certificate handling for TLS sessions */ @@ -21872,7 +21095,6 @@ static int reload_config(enum channelreloadreason reason) 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; @@ -21897,8 +21119,8 @@ static int reload_config(enum channelreloadreason reason) global_rtpkeepalive = 0; global_allowtransfer = TRANSFER_OPENFORALL; /* Merrily accept all transfers by default */ global_rtautoclear = 120; - ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE); /* Default for peers, users: TRUE */ - ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP); /* Default for peers, users: TRUE */ + ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE); /* Default for all devices: TRUE */ + ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP); /* Default for all devices: TRUE */ sip_cfg.peer_rtupdate = TRUE; /* Session-Timers */ @@ -21907,7 +21129,7 @@ static int reload_config(enum channelreloadreason reason) global_min_se = DEFAULT_MIN_SE; global_max_se = DEFAULT_MAX_SE; - /* Initialize some reasonable defaults at SIP reload (used both for channel and as default for peers and users */ + /* Initialize some reasonable defaults at SIP reload (used both for channel and as default for devices */ ast_copy_string(default_context, DEFAULT_CONTEXT, sizeof(default_context)); default_subscribecontext[0] = '\0'; default_language[0] = '\0'; @@ -22052,8 +21274,6 @@ static int reload_config(enum channelreloadreason reason) 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")) { @@ -22349,13 +21569,7 @@ static int reload_config(enum channelreloadreason reason) hassip = ast_variable_retrieve(ucfg, cat, "hassip"); registersip = ast_variable_retrieve(ucfg, cat, "registersip"); if (ast_true(hassip) || (!hassip && genhassip)) { - user = build_user(cat, gen, ast_variable_browse(ucfg, cat), 0); - if (user) { - ao2_t_link(users, user, "link user into users table"); - unref_user(user, "Unref the result of build_user. Now, the table link is the only one left."); - user_count++; - } - peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0); + peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0, FALSE); if (peer) { ao2_t_link(peers, peer, "link peer into peer table"); if (peer->addr.sin_addr.s_addr) { @@ -22407,27 +21621,21 @@ static int reload_config(enum channelreloadreason reason) 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 = 2; 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), NULL, 0); - if (user) { - ao2_t_link(users, user, "link user into users table"); - unref_user(user, "Unref the result of build_user. Now, the table link is the only one left."); - user_count++; - } - } if (is_peer) { - peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0); + peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0, is_peer == 2); if (peer) { ao2_t_link(peers, peer, "link peer into peers table"); if (peer->addr.sin_addr.s_addr) { @@ -22537,7 +21745,7 @@ static int reload_config(enum channelreloadreason reason) } /* Done, tell the manager */ - manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "ChannelType: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\nUser_Count: %d\r\n", channelreloadreason2txt(reason), registry_count, peer_count, user_count); + manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "ChannelType: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\n", channelreloadreason2txt(reason), registry_count, peer_count); run_end = time(0); ast_debug(4, "reload_config done...Runtime= %d sec\n", (int)(run_end-run_start)); @@ -23119,8 +22327,6 @@ static struct ast_cli_entry cli_sip[] = { 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_qualify_peer, "Send an OPTIONS packet to a 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_show_sched, "Present a report on the status of the sched queue"), AST_CLI_DEFINE(sip_prune_realtime, "Prune cached Realtime users/peers"), AST_CLI_DEFINE(sip_do_debug, "Enable/Disable SIP debugging"), @@ -23134,8 +22340,7 @@ static int load_module(void) { ast_verbose("SIP channel loading...\n"); /* the fact that ao2_containers can't resize automatically is a major worry! */ - /* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */ - users = ao2_t_container_alloc(hash_user_size, user_hash_cb, user_cmp_cb, "allocate users"); + /* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */ peers = ao2_t_container_alloc(hash_peer_size, peer_hash_cb, peer_cmp_cb, "allocate peers"); peers_by_ip = ao2_t_container_alloc(hash_peer_size, peer_iphash_cb, peer_ipcmp_cb, "allocate peers_by_ip"); dialogs = ao2_t_container_alloc(hash_dialog_size, dialog_hash_cb, dialog_cmp_cb, "allocate dialogs"); @@ -23325,7 +22530,6 @@ static int unload_module(void) ao2_t_ref(peers, -1, "unref the peers table"); ao2_t_ref(peers_by_ip, -1, "unref the peers_by_ip table"); - ao2_t_ref(users, -1, "unref the users table"); ao2_t_ref(dialogs, -1, "unref the dialogs table"); clear_sip_domains();