From: Mark Michelson Date: Fri, 9 Jul 2010 20:58:52 +0000 (+0000) Subject: Fix error in parsing SIP registry strings from ASTdb. X-Git-Tag: 11.0.0-beta1~2695 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b1e28c6a138c68e0526ddfb86ee2b1c37354e01;p=thirdparty%2Fasterisk.git Fix error in parsing SIP registry strings from ASTdb. It was essentially an off-by-one error. The easiest way to fix this was to use the handy-dandy AST_NONSTANDARD_RAW_ARGS macro to parse the pieces of the registration string out. Tested and it works wonderfully. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@275385 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/channels/chan_sip.c b/channels/chan_sip.c index ce8a6bfe95..ac3de95f4d 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -12304,36 +12304,40 @@ static void reg_source_db(struct sip_peer *peer) char data[256]; struct ast_sockaddr sa; int expire; - char *scan, *addr, *expiry_str, *username, *contact; + char full_addr[128]; + AST_DECLARE_APP_ARGS(args, + AST_APP_ARG(addr); + AST_APP_ARG(port); + AST_APP_ARG(expiry_str); + AST_APP_ARG(username); + AST_APP_ARG(contact); + ); if (peer->rt_fromcontact) return; if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data))) return; - addr = scan = data; - if ('[' == scan[0]) { - /* It must be a bracket enclosed IPv6 address */ - scan = strchr(scan, ']') + 1; - } - scan = strchr(scan, ':') + 1; - expiry_str = strsep(&scan, ":"); - username = strsep(&scan, ":"); - contact = scan; /* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */ + AST_NONSTANDARD_RAW_ARGS(args, data, ':'); + + snprintf(full_addr, sizeof(full_addr), "%s:%s", args.addr, args.port); - if (!ast_sockaddr_parse(&sa, addr, 0)) { + if (!ast_sockaddr_parse(&sa, full_addr, 0)) { return; } - if (expiry_str) - expire = atoi(expiry_str); - else + if (args.expiry_str) { + expire = atoi(args.expiry_str); + } else { return; + } - if (username) - ast_string_field_set(peer, username, username); - if (contact) - ast_string_field_set(peer, fullcontact, contact); + if (args.username) { + ast_string_field_set(peer, username, args.username); + } + if (args.contact) { + ast_string_field_set(peer, fullcontact, args.contact); + } ast_debug(2, "SIP Seeding peer from astdb: '%s' at %s@%s for %d\n", peer->name, peer->username, ast_sockaddr_stringify_host(&sa), expire);