Only in asterisk-1.8.7.1.orig: asterisk-1.8.7.1 diff -urd asterisk-1.8.7.1.orig/channels/chan_sip.c asterisk-1.8.7.1/channels/chan_sip.c --- asterisk-1.8.7.1.orig/channels/chan_sip.c 2011-10-17 13:46:26.000000000 -0400 +++ asterisk-1.8.7.1/channels/chan_sip.c 2011-12-01 17:28:14.722251984 -0500 @@ -564,6 +564,8 @@ static int authlimit = DEFAULT_AUTHLIMIT; static int authtimeout = DEFAULT_AUTHTIMEOUT; +static int autopeer_count = 0; + /*! \brief Global jitterbuffer configuration - by default, jb is disabled * \note Values shown here match the defaults shown in sip.conf.sample */ static struct ast_jb_conf default_jbconf = @@ -13645,7 +13647,7 @@ /* We might not immediately be able to reconnect via TCP, but try caching it anyhow */ if (!peer->rt_fromcontact || !sip_cfg.peer_rtupdate) ast_db_put("SIP/Registry", peer->name, data); - manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n", peer->name, ast_sockaddr_stringify(&peer->addr)); + manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n%s", peer->name, ast_sockaddr_stringify(&peer->addr), (peer->selfdestruct) ? "Inceptor: Automatic\r\n" : ""); /* Is this a new IP address for us? */ if (VERBOSITY_ATLEAST(2) && ast_sockaddr_cmp(&peer->addr, &oldsin)) { @@ -14338,7 +14340,19 @@ } if (!peer && sip_cfg.autocreatepeer) { /* Create peer if we have autocreate mode enabled */ - peer = temp_peer(name); + + /* handle autocreatepeer=prefix */ + if (sip_cfg.autocreatepeer == 2) { + char safe_name[SIP_MAX_PEER_NAME]; + + snprintf(safe_name, SIP_MAX_PEER_NAME, "%s%d", sip_cfg.autocreateprefix, ast_atomic_fetchadd_int(&autopeer_count, +1)); + peer = temp_peer(safe_name); + + /* handle autocratepeer=yes */ + } else { + peer = temp_peer(name); + } + if (peer) { ao2_t_link(peers, peer, "link peer into peer table"); if (!ast_sockaddr_isnull(&peer->addr)) { @@ -14370,7 +14384,6 @@ ast_string_field_set(p, fullcontact, peer->fullcontact); /* Say OK and ask subsystem to retransmit msg counter */ transmit_response_with_date(p, "200 OK", req); - manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n", peer->name, ast_sockaddr_stringify(addr)); peer->lastmsgssent = -1; res = 0; break; @@ -17463,7 +17476,8 @@ ast_cli(a->fd, " Videosupport: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT))); ast_cli(a->fd, " Textsupport: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT))); ast_cli(a->fd, " Ignore SDP sess. ver.: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION))); - ast_cli(a->fd, " AutoCreate Peer: %s\n", AST_CLI_YESNO(sip_cfg.autocreatepeer)); + ast_cli(a->fd, " AutoCreate Peer: %s\n", (sip_cfg.autocreatepeer == 2) ? "Prefix" : (sip_cfg.autocreatepeer == 0) ? "No" : "Yes"); + ast_cli(a->fd, " AutoCreate Prefix: %s\n", (sip_cfg.autocreatepeer == 2) ? sip_cfg.autocreateprefix : "(unused)"); ast_cli(a->fd, " Match Auth Username: %s\n", AST_CLI_YESNO(global_match_auth_username)); ast_cli(a->fd, " Allow unknown access: %s\n", AST_CLI_YESNO(sip_cfg.allowguest)); ast_cli(a->fd, " Allow subscriptions: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); @@ -27367,6 +27381,7 @@ global_regattempts_max = 0; sip_cfg.pedanticsipchecking = DEFAULT_PEDANTIC; sip_cfg.autocreatepeer = DEFAULT_AUTOCREATEPEER; + snprintf(sip_cfg.autocreateprefix, sizeof(sip_cfg.autocreateprefix), "%s", DEFAULT_AUTOCREATEPREFIX); global_autoframing = 0; sip_cfg.allowguest = DEFAULT_ALLOWGUEST; global_callcounter = DEFAULT_CALLCOUNTER; @@ -27664,7 +27679,18 @@ proxy_update(&sip_cfg.outboundproxy); } else if (!strcasecmp(v->name, "autocreatepeer")) { - sip_cfg.autocreatepeer = ast_true(v->value); + if (!strcasecmp(v->value, "prefix")) { + sip_cfg.autocreatepeer = 2; + } else { + sip_cfg.autocreatepeer = ast_true(v->value); + } + } else if (!strcasecmp(v->name, "autocreateprefix")) { + if (ast_strlen_zero(v->value)) { + ast_log(LOG_WARNING, "no value given for autocreateprefix on line %d of sip.conf, using default of %s", v->lineno, sip_cfg.autocreateprefix); + continue; + } + + ast_copy_string(sip_cfg.autocreateprefix, v->value, sizeof(sip_cfg.autocreateprefix)); } else if (!strcasecmp(v->name, "match_auth_username")) { global_match_auth_username = ast_true(v->value); } else if (!strcasecmp(v->name, "srvlookup")) { Binary files asterisk-1.8.7.1.orig/channels/chan_sip.o and asterisk-1.8.7.1/channels/chan_sip.o differ Binary files asterisk-1.8.7.1.orig/channels/chan_sip.so and asterisk-1.8.7.1/channels/chan_sip.so differ Binary files asterisk-1.8.7.1.orig/channels/sip/config_parser.o and asterisk-1.8.7.1/channels/sip/config_parser.o differ Binary files asterisk-1.8.7.1.orig/channels/sip/dialplan_functions.o and asterisk-1.8.7.1/channels/sip/dialplan_functions.o differ diff -urd asterisk-1.8.7.1.orig/channels/sip/include/sip.h asterisk-1.8.7.1/channels/sip/include/sip.h --- asterisk-1.8.7.1.orig/channels/sip/include/sip.h 2011-08-23 14:11:50.000000000 -0400 +++ asterisk-1.8.7.1/channels/sip/include/sip.h 2011-12-01 17:38:24.433146237 -0500 @@ -94,6 +94,7 @@ #define PROVIS_KEEPALIVE_TIMEOUT 60000 /*!< How long to wait before retransmitting a provisional response (rfc 3261 13.3.1.1) */ #define MAX_AUTHTRIES 3 /*!< Try authentication three times, then fail */ +#define SIP_MAX_PEER_NAME 80 /*!< Max length of a SIP peer name */ #define SIP_MAX_HEADERS 64 /*!< Max amount of SIP headers to read */ #define SIP_MAX_LINES 256 /*!< Max amount of lines in SIP attachment (like SDP) */ #define SIP_MIN_PACKET 4096 /*!< Initialize size of memory to allocate for packets */ @@ -206,6 +207,7 @@ #define DEFAULT_NOTIFYCID DISABLED /*!< Include CID with ringing notifications */ #define DEFAULT_PEDANTIC TRUE /*!< Follow SIP standards for dialog matching */ #define DEFAULT_AUTOCREATEPEER FALSE /*!< Don't create peers automagically */ +#define DEFAULT_AUTOCREATEPREFIX "autopeer_" /*!< Default prefix for automatically created peers (when autocreatepeer=prefix) */ #define DEFAULT_MATCHEXTERNADDRLOCALLY FALSE /*!< Match extern IP locally default setting */ #define DEFAULT_QUALIFY FALSE /*!< Don't monitor devices */ #define DEFAULT_CALLEVENTS FALSE /*!< Extra manager SIP call events */ @@ -677,6 +679,7 @@ int directrtpsetup; /*!< Enable support for Direct RTP setup (no re-invites) */ int pedanticsipchecking; /*!< Extra checking ? Default off */ int autocreatepeer; /*!< Auto creation of peers at registration? Default off. */ + char autocreateprefix[SIP_MAX_PEER_NAME]; /*!< The prefix for autocreated peer names if autocreatepeer=prefix */ int srvlookup; /*!< SRV Lookup on or off. Default is on */ int allowguest; /*!< allow unauthenticated peers to connect? */ int alwaysauthreject; /*!< Send 401 Unauthorized for all failing requests */ @@ -1164,7 +1167,7 @@ */ /* XXX field 'name' must be first otherwise sip_addrcmp() will fail, as will astobj2 hashing of the structure */ struct sip_peer { - char name[80]; /*!< the unique name of this object */ + char name[SIP_MAX_PEER_NAME]; /*!< the unique name of this object */ AST_DECLARE_STRING_FIELDS( AST_STRING_FIELD(secret); /*!< Password for inbound auth */ AST_STRING_FIELD(md5secret); /*!< Password in MD5 */ Binary files asterisk-1.8.7.1.orig/channels/sip/reqresp_parser.o and asterisk-1.8.7.1/channels/sip/reqresp_parser.o differ