Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 134124) +++ channels/chan_sip.c (working copy) @@ -1435,7 +1435,7 @@ 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_peer *find_peer(const char *peer, struct sockaddr_in *sin, int realtime, int devstate_only); static struct sip_user *find_user(const char *name, int realtime); static enum parse_register_result parse_register_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req); static int expire_register(const void *data); @@ -1447,7 +1447,7 @@ 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 sip_peer *realtime_peer(const char *peername, struct sockaddr_in *sin); +static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *sin, int devstate_only); static int sip_prune_realtime(int fd, int argc, char *argv[]); /*--- Internal UA client handling (outbound registrations) */ @@ -2509,7 +2509,7 @@ * \todo Consider adding check of port address when matching here to follow the same * algorithm as for static peers. Will we break anything by adding that? */ -static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_in *sin) +static struct sip_peer *realtime_peer(const char *newpeername, struct sockaddr_in *sin, int devstate_only) { struct sip_peer *peer=NULL; struct ast_variable *var = NULL; @@ -2628,7 +2628,7 @@ return NULL; } - if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { + if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && !devstate_only) { /* Cache peer */ ast_copy_flags(&peer->flags[1],&global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS); if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) { @@ -2665,7 +2665,7 @@ /*! \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 */ -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 devstate_only) { struct sip_peer *p = NULL; @@ -2674,8 +2674,8 @@ else p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); - if (!p && realtime) - p = realtime_peer(peer, sin); + if (!p && (realtime || devstate_only)) + p = realtime_peer(peer, sin, devstate_only); return p; } @@ -2902,7 +2902,7 @@ *port++ = '\0'; dialog->sa.sin_family = AF_INET; dialog->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */ - p = find_peer(peer, NULL, 1); + p = find_peer(peer, NULL, 1, 0); if (p) { int res = create_addr_from_peer(dialog, p); @@ -3230,7 +3230,7 @@ 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 */ + } else if ( (p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, 1, 0) ) ) { /* Try to find peer */ inuse = &p->inUse; call_limit = &p->call_limit; inringing = &p->inRinging; @@ -8610,7 +8610,7 @@ /*! \brief Change onhold state of a peer using a pvt structure */ static void sip_peer_hold(struct sip_pvt *p, int hold) { - struct sip_peer *peer = find_peer(p->peername, NULL, 1); + struct sip_peer *peer = find_peer(p->peername, NULL, 1, 0); if (!peer) return; @@ -8730,7 +8730,7 @@ ast_string_field_set(p, exten, name); build_contact(p); - peer = find_peer(name, NULL, 1); + peer = find_peer(name, NULL, 1, 0); if (!(peer && ast_apply_ha(peer->ha, sin))) { /* Peer fails ACL check */ if (peer) { @@ -9591,13 +9591,13 @@ /* If we didn't find a user match, check for peers */ if (sipmethod == SIP_SUBSCRIBE) /* For subscribes, match on peer name only */ - peer = find_peer(of, NULL, 1); + peer = find_peer(of, NULL, 1, 0); else /* Look for peer based on the IP address we received data from */ /* If peer is registered from this IP address or have this as a default IP address, this call is from the peer */ - peer = find_peer(NULL, &p->recv, 1); + peer = find_peer(NULL, &p->recv, 1, 0); if (peer) { /* Set Frame packetization */ @@ -10457,7 +10457,7 @@ return RESULT_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, 0); if (s) { /* Manager */ if (peer) { const char *id = astman_get_header(m,"ActionID"); @@ -11353,7 +11353,7 @@ struct sip_peer *peer; if (argc != 5) return RESULT_SHOWUSAGE; - peer = find_peer(argv[4], NULL, 1); + peer = find_peer(argv[4], NULL, 1, 0); if (peer) { if (peer->addr.sin_addr.s_addr) { debugaddr.sin_family = AF_INET; @@ -11904,7 +11904,7 @@ else colname = "ip"; - if (!(peer = find_peer(data, NULL, 1))) + if (!(peer = find_peer(data, NULL, 1, 0))) return -1; if (!strcasecmp(colname, "ip")) { @@ -16342,7 +16342,7 @@ * load it BACK into memory, thus defeating the point of trying to trying to * clear dead hosts out of memory. */ - if ((p = find_peer(host, NULL, 0))) { + if ((p = find_peer(host, NULL, 0, 1))) { if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) { /* we have an address for the peer */