[asterisk-commits] rizzo: branch rizzo/astobj2 r72800 - /team/rizzo/astobj2/channels/chan_sip.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jun 30 16:45:29 CDT 2007
Author: rizzo
Date: Sat Jun 30 16:45:29 2007
New Revision: 72800
URL: http://svn.digium.com/view/asterisk?view=rev&rev=72800
Log:
more merge from trunk up to svn 62140
Modified:
team/rizzo/astobj2/channels/chan_sip.c
Modified: team/rizzo/astobj2/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/rizzo/astobj2/channels/chan_sip.c?view=diff&rev=72800&r1=72799&r2=72800
==============================================================================
--- team/rizzo/astobj2/channels/chan_sip.c (original)
+++ team/rizzo/astobj2/channels/chan_sip.c Sat Jun 30 16:45:29 2007
@@ -1549,6 +1549,7 @@
static int sip_show_peer(int fd, int argc, char *argv[]);
static int sip_show_user(int fd, int argc, char *argv[]);
static int sip_show_registry(int fd, int argc, char *argv[]);
+static int sip_unregister(int fd, int argc, char *argv[]);
static int sip_show_settings(int fd, int argc, char *argv[]);
static const char *subscription_type2str(enum subscriptiontype subtype) attribute_pure;
static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
@@ -2934,12 +2935,14 @@
} else if (sin) { /* Then check on IP address for dynamic peers */
ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr));
var = ast_load_realtime("sippeers", "host", ipaddr, NULL); /* First check for fixed IP hosts */
- if (var && realtimeregs) {
- for (tmp = var; tmp; tmp = tmp->next) {
+ if (var) {
+ if (realtimeregs) {
+ for (tmp = var; tmp; tmp = tmp->next) {
if (!newpeername && !strcasecmp(tmp->name, "name"))
newpeername = tmp->value;
}
varregs = ast_load_realtime("sipregs", "name", newpeername, NULL);
+ }
} else {
if (realtimeregs)
varregs = ast_load_realtime("sipregs", "ipaddr", ipaddr, NULL); /* Then check for registered hosts */
@@ -5013,6 +5016,7 @@
prof_id = ast_add_profile("find_call_cb", 0);
ast_mark(prof_id, 1);
+ if (!ast_strlen_zero(p->callid)) { /* XXX double check, do we allow match on empty p->callid ? */
if (arg->method == SIP_REGISTER)
found = (!strcmp(p->callid, arg->callid));
else
@@ -5035,6 +5039,7 @@
if (!found && option_debug > 4)
ast_log(LOG_DEBUG, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, arg->totag, sip_methods[arg->method].text);
}
+ }
ast_mark(prof_id, 0);
return found;
}
@@ -5346,6 +5351,16 @@
dst[i] = c + 1; /* record start of next line */
}
}
+ /* Check for last header without CRLF. The RFC for SDP requires CRLF,
+ but since some devices send without, we'll be generous in what we accept.
+ */
+ if (!ast_strlen_zero(dst[i])) {
+ if (sipdebug && option_debug > 3)
+ ast_log(LOG_DEBUG, "%7s %2d [%3d]: %s\n",
+ req->headers < 0 ? "Header" : "Body",
+ i, (int)strlen(dst[i]), dst[i]);
+ i++;
+ }
/* update count of header or body lines */
if (req->headers >= 0) /* we are in the body */
req->lines = i;
@@ -6390,7 +6405,8 @@
add_header(resp, "To", ot);
copy_header(resp, req, "Call-ID");
copy_header(resp, req, "CSeq");
- add_header(resp, "User-Agent", global_useragent);
+ if (!ast_strlen_zero(global_useragent))
+ add_header(resp, "User-Agent", global_useragent);
add_header(resp, "Allow", ALLOWED_METHODS);
add_header(resp, "Supported", SUPPORTED_EXTENSIONS);
if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) {
@@ -6401,7 +6417,7 @@
snprintf(tmp, sizeof(tmp), "%d", p->expiry);
add_header(resp, "Expires", tmp);
if (p->expiry) { /* Only add contact if we have an expiry time */
- char contact[256];
+ char contact[BUFSIZ];
snprintf(contact, sizeof(contact), "%s;expires=%d", p->our_contact, p->expiry);
add_header(resp, "Contact", contact); /* Not when we unregister */
}
@@ -6506,7 +6522,8 @@
copy_header(req, orig, "Call-ID");
add_header(req, "CSeq", tmp);
- add_header(req, "User-Agent", global_useragent);
+ if (!ast_strlen_zero(global_useragent))
+ add_header(req, "User-Agent", global_useragent);
if (!ast_strlen_zero(p->rpid))
add_header(req, "Remote-Party-ID", p->rpid);
@@ -7290,6 +7307,8 @@
dst->header[x] += offset;
for (x=0; x < src->lines; x++)
dst->line[x] += offset;
+ dst->rlPart1 += offset;
+ dst->rlPart2 += offset;
}
/*! \brief Used for 200 OK and 183 early media */
@@ -7393,7 +7412,7 @@
/*! \brief Check Contact: URI of SIP message */
static void extract_uri(struct sip_pvt *p, struct sip_request *req)
{
- char stripped[256];
+ char stripped[BUFSIZ];
char *c;
ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped));
@@ -7620,7 +7639,8 @@
add_header(req, "Contact", p->our_contact);
add_header(req, "Call-ID", p->callid);
add_header(req, "CSeq", tmp_n);
- add_header(req, "User-Agent", global_useragent);
+ if (!ast_strlen_zero(global_useragent))
+ add_header(req, "User-Agent", global_useragent);
if (!ast_strlen_zero(p->rpid))
add_header(req, "Remote-Party-ID", p->rpid);
}
@@ -8206,7 +8226,8 @@
add_header(&req, "To", to);
add_header(&req, "Call-ID", p->callid);
add_header(&req, "CSeq", tmp);
- add_header(&req, "User-Agent", global_useragent);
+ if (!ast_strlen_zero(global_useragent))
+ add_header(&req, "User-Agent", global_useragent);
if (auth) /* Add auth header */
@@ -8556,7 +8577,7 @@
/*! \brief Save contact header for 200 OK on INVITE */
static int parse_ok_contact(struct sip_pvt *pvt, struct sip_request *req)
{
- char contact[250];
+ char contact[BUFSIZ];
char *c;
/* Look for brackets */
@@ -10041,6 +10062,7 @@
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;
@@ -10182,6 +10204,7 @@
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;
}
@@ -11341,6 +11364,25 @@
return RESULT_SUCCESS;
#undef FORMAT
#undef FORMAT2
+}
+
+/*! \brief Unregister (force expiration) a SIP peer in the registry via CLI */
+static int sip_unregister(int fd, int argc, char *argv[])
+{
+ struct sip_peer *peer;
+ int load_realtime = 0;
+
+ if (argc != 3)
+ return RESULT_SHOWUSAGE;
+
+ if ((peer = find_peer(argv[2], NULL, load_realtime))) {
+ expire_register(peer);
+ ast_cli(fd, "Unregistered peer \'%s\'\n\n", argv[2]);
+ } else {
+ ast_cli(fd, "Attempted to unregister an unknown peer \'%s\' via CLI\n", argv[2]);
+ }
+
+ return 0;
}
/*! \brief List global settings for the SIP channel */
@@ -12379,6 +12421,10 @@
"Usage: sip show registry\n"
" Lists all registration requests and status.\n";
+static const char sip_unregister_usage[] =
+"Usage: sip unregister <peer>\n"
+" Unregister (force expiration) a SIP peer from the registry\n";
+
static const char no_history_usage[] =
"Usage: sip history off\n"
" Disables recording of SIP dialog history for debugging purposes\n";
@@ -12661,7 +12707,7 @@
/*! \brief Parse 302 Moved temporalily response */
static void parse_moved_contact(struct sip_pvt *p, struct sip_request *req)
{
- char tmp[256];
+ char tmp[BUFSIZ];
char *s, *e;
char *domain;
@@ -15575,6 +15621,9 @@
else if (ast_strlen_zero(p->context))
ast_string_field_set(p, context, default_context);
+ /* Get full contact header - this needs to be used as a request URI in NOTIFY's */
+ parse_ok_contact(p, req);
+
build_contact(p);
if (gotdest) {
transmit_response(p, "404 Not Found", req);
@@ -17361,10 +17410,9 @@
M_F("host",
if (!strcasecmp(v->value, "dynamic")) {
/* They'll register with us */
- ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
- if (!found) {
- /* Initialize stuff iff we're not found, otherwise
- we keep going with what we had */
+ if (!found || !ast_test_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC)) {
+ /* Initialize stuff if this is a new peer, or if it used to
+ * not be dynamic before the reload. */
memset(&peer->addr.sin_addr, 0, 4);
if (peer->addr.sin_port) {
/* If we've already got a port, make it the default rather than absolute */
@@ -17372,6 +17420,7 @@
peer->addr.sin_port = 0;
}
}
+ ast_set_flag(&peer->flags[1], SIP_PAGE2_DYNAMIC);
} else {
/* Non-dynamic. Make sure we become that way if we're not */
if (peer->expire > -1)
@@ -18553,6 +18602,10 @@
sip_show_registry, "List SIP registration status",
show_reg_usage },
+ { { "sip", "unregister", NULL },
+ sip_unregister, "Unregister (force expiration) a SIP peer from the registery\n",
+ sip_unregister_usage },
+
{ { "sip", "show", "settings", NULL },
sip_show_settings, "Show SIP global settings",
show_settings_usage },
More information about the asterisk-commits
mailing list