diff options
author | mmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-09 20:58:52 +0000 |
---|---|---|
committer | mmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b> | 2010-07-09 20:58:52 +0000 |
commit | e8220c1f878156712741bd6427aad7b92c759dd5 (patch) | |
tree | 57f9455e9d52b56120ff44044184edbec67cedd7 /channels/chan_sip.c | |
parent | af4ffb86d02789de4dcda6ed9bf2543792517105 (diff) |
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: http://svn.digium.com/svn/asterisk/trunk@275385 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels/chan_sip.c')
-rw-r--r-- | channels/chan_sip.c | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c index ce8a6bfe9..ac3de95f4 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); |