summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/app_queue.c2
-rw-r--r--channels/chan_sip.c5
-rw-r--r--contrib/scripts/safe_asterisk13
-rw-r--r--res/res_pjsip_messaging.c122
4 files changed, 86 insertions, 56 deletions
diff --git a/apps/app_queue.c b/apps/app_queue.c
index 9b283d467..45b5683ed 100644
--- a/apps/app_queue.c
+++ b/apps/app_queue.c
@@ -9197,7 +9197,7 @@ static void do_print(struct mansession *s, int fd, const char *str)
static char *__queues_show(struct mansession *s, int fd, int argc, const char * const *argv)
{
struct call_queue *q;
- struct ast_str *out = ast_str_alloca(240);
+ struct ast_str *out = ast_str_alloca(512);
int found = 0;
time_t now = time(NULL);
struct ao2_iterator queue_iter;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index b03a3e34d..9c9a407ad 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -26057,12 +26057,15 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, str
copy_request(&p->initreq, req); /* Save this INVITE as the transaction basis */
if (sipdebug)
ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid);
+
+ /* Parse new contact both for existing (re-invite) and new calls. */
+ parse_ok_contact(p, req);
+
if (!p->owner) { /* Not a re-invite */
if (req->debug)
ast_verbose("Using INVITE request as basis request - %s\n", p->callid);
if (newcall)
append_history(p, "Invite", "New call: %s", p->callid);
- parse_ok_contact(p, req);
} else { /* Re-invite on existing call */
ast_clear_flag(&p->flags[0], SIP_OUTGOING); /* This is now an inbound dialog */
if (get_rpid(p, req)) {
diff --git a/contrib/scripts/safe_asterisk b/contrib/scripts/safe_asterisk
index 62f3dadc2..66213a530 100644
--- a/contrib/scripts/safe_asterisk
+++ b/contrib/scripts/safe_asterisk
@@ -120,13 +120,20 @@ if test -n "$TTY" && test "$TTY" != "no"; then
TTY=tty${TTY}
elif test -c /dev/vc/${TTY}; then
TTY=vc/${TTY}
+ elif test "$TTY" = "9"; then # ignore default if it was untouched
+ # If there is no /dev/tty9 and not /dev/vc/9 we don't
+ # necessarily want to die at this point. Pretend that
+ # TTY wasn't set.
+ TTY=
else
message "Cannot find specified TTY (${TTY})"
exit 1
fi
- ASTARGS="${ASTARGS} -vvvg"
- if test "$CONSOLE" != "no"; then
- ASTARGS="${ASTARGS} -c"
+ if test -n "$TTY"; then
+ ASTARGS="${ASTARGS} -vvvg"
+ if test "$CONSOLE" != "no"; then
+ ASTARGS="${ASTARGS} -c"
+ fi
fi
fi
diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index 07869052d..835a38393 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -106,8 +106,9 @@ static const char *skip_sip(const char *fromto)
*
* Expects the given 'to' to be in one of the following formats:
* sip[s]:endpoint[/aor]
- * sip[s]:endpoint[/uri]
- * sip[s]:uri <-- will use default outbound endpoint
+ * sip[s]:endpoint[/uri] - Where uri is: sip[s]:user@domain
+ * sip[s]:endpoint[@domain]
+ * sip[s]:unknown_user@domain <-- will use default outbound endpoint
*
* If an optional aor is given it will try to find an associated uri
* to return. If an optional uri is given then that will be returned,
@@ -116,22 +117,20 @@ static const char *skip_sip(const char *fromto)
* \param to 'From' or 'To' field with possible endpoint
* \param uri Optional uri to return
*/
-static struct ast_sip_endpoint* get_outbound_endpoint(
- const char *to, char **uri)
+static struct ast_sip_endpoint *get_outbound_endpoint(const char *to, char **uri)
{
- char *name, *aor_uri;
- struct ast_sip_endpoint* endpoint;
- RAII_VAR(struct ast_sip_aor *, aor, NULL, ao2_cleanup);
- RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+ char *name;
+ char *aor_uri;
+ struct ast_sip_endpoint *endpoint;
name = ast_strdupa(skip_sip(to));
/* attempt to extract the endpoint name */
if ((aor_uri = strchr(name, '/'))) {
- /* format was 'endpoint/' */
+ /* format was 'endpoint/(aor_name | uri)' */
*aor_uri++ = '\0';
} else if ((aor_uri = strchr(name, '@'))) {
- /* format was 'endpoint@' - don't use the rest */
+ /* format was 'endpoint@domain' - discard the domain */
*aor_uri = '\0';
/*
@@ -143,29 +142,41 @@ static struct ast_sip_endpoint* get_outbound_endpoint(
/* at this point, if name is not empty then it
might be an endpoint, so try to retrieve it */
- if (ast_strlen_zero(name) || !(endpoint = ast_sorcery_retrieve_by_id(
- ast_sip_get_sorcery(), "endpoint", name))) {
+ if (ast_strlen_zero(name)
+ || !(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+ name))) {
/* an endpoint was not found, so assume sending directly
to a uri and use the default outbound endpoint */
*uri = ast_strdup(to);
return ast_sip_default_outbound_endpoint();
}
- *uri = aor_uri;
- if (*uri) {
- char *end = strchr(*uri, '>');
+ if (ast_strlen_zero(aor_uri)) {
+ *uri = NULL;
+ } else {
+ struct ast_sip_aor *aor;
+ struct ast_sip_contact *contact = NULL;
+ char *end;
+
+ /* Trim off any stray angle bracket that shouldn't be here */
+ end = strchr(aor_uri, '>');
if (end) {
- *end++ = '\0';
+ *end = '\0';
}
- /* if what's in 'uri' is a retrievable aor use the uri on it
- instead, otherwise assume what's there is already a uri*/
- if ((aor = ast_sip_location_retrieve_aor(*uri)) &&
- (contact = ast_sip_location_retrieve_first_aor_contact(aor))) {
- *uri = (char*)contact->uri;
+ /*
+ * if what's in 'uri' is a retrievable aor use the uri on it
+ * instead, otherwise assume what's there is already a uri
+ */
+ aor = ast_sip_location_retrieve_aor(aor_uri);
+ if (aor && (contact = ast_sip_location_retrieve_first_aor_contact(aor))) {
+ aor_uri = (char *) contact->uri;
}
/* need to copy because underlying uri goes away */
- *uri = ast_strdup(*uri);
+ *uri = ast_strdup(aor_uri);
+
+ ao2_cleanup(contact);
+ ao2_cleanup(aor);
}
return endpoint;
@@ -182,16 +193,16 @@ static struct ast_sip_endpoint* get_outbound_endpoint(
*/
static void update_to(pjsip_tx_data *tdata, char *to)
{
- pjsip_name_addr *name_addr = (pjsip_name_addr *)
- PJSIP_MSG_TO_HDR(tdata->msg)->uri;
- pjsip_uri *parsed;
+ pjsip_name_addr *parsed_name_addr;
- if ((parsed = pjsip_parse_uri(tdata->pool, to, strlen(to),
- PJSIP_PARSE_URI_AS_NAMEADDR))) {
- pjsip_name_addr *parsed_name_addr = (pjsip_name_addr *)parsed;
+ parsed_name_addr = (pjsip_name_addr *) pjsip_parse_uri(tdata->pool, to, strlen(to),
+ PJSIP_PARSE_URI_AS_NAMEADDR);
+ if (parsed_name_addr) {
if (pj_strlen(&parsed_name_addr->display)) {
- pj_strdup(tdata->pool, &name_addr->display,
- &parsed_name_addr->display);
+ pjsip_name_addr *name_addr =
+ (pjsip_name_addr *) PJSIP_MSG_TO_HDR(tdata->msg)->uri;
+
+ pj_strdup(tdata->pool, &name_addr->display, &parsed_name_addr->display);
}
}
}
@@ -210,22 +221,24 @@ static void update_to(pjsip_tx_data *tdata, char *to)
*/
static void update_from(pjsip_tx_data *tdata, char *from)
{
- pjsip_name_addr *name_addr = (pjsip_name_addr *)
- PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
- pjsip_sip_uri *uri = pjsip_uri_get_uri(name_addr);
- pjsip_uri *parsed;
+ pjsip_name_addr *name_addr;
+ pjsip_sip_uri *uri;
+ pjsip_name_addr *parsed_name_addr;
if (ast_strlen_zero(from)) {
return;
}
- if ((parsed = pjsip_parse_uri(tdata->pool, from, strlen(from),
- PJSIP_PARSE_URI_AS_NAMEADDR))) {
- pjsip_name_addr *parsed_name_addr = (pjsip_name_addr *)parsed;
+ name_addr = (pjsip_name_addr *) PJSIP_MSG_FROM_HDR(tdata->msg)->uri;
+ uri = pjsip_uri_get_uri(name_addr);
+
+ parsed_name_addr = (pjsip_name_addr *) pjsip_parse_uri(tdata->pool, from,
+ strlen(from), PJSIP_PARSE_URI_AS_NAMEADDR);
+ if (parsed_name_addr) {
pjsip_sip_uri *parsed_uri = pjsip_uri_get_uri(parsed_name_addr->uri);
+
if (pj_strlen(&parsed_name_addr->display)) {
- pj_strdup(tdata->pool, &name_addr->display,
- &parsed_name_addr->display);
+ pj_strdup(tdata->pool, &name_addr->display, &parsed_name_addr->display);
}
pj_strdup(tdata->pool, &uri->user, &parsed_uri->user);
@@ -234,11 +247,17 @@ static void update_from(pjsip_tx_data *tdata, char *from)
} else {
/* assume it is 'user[@domain]' format */
char *domain = strchr(from, '@');
+
if (domain) {
- *domain++ = '\0';
- pj_strdup2(tdata->pool, &uri->host, domain);
+ pj_str_t pj_from;
+
+ pj_strset3(&pj_from, from, domain);
+ pj_strdup(tdata->pool, &uri->user, &pj_from);
+
+ pj_strdup2(tdata->pool, &uri->host, domain + 1);
+ } else {
+ pj_strdup2(tdata->pool, &uri->user, from);
}
- pj_strdup2(tdata->pool, &uri->user, from);
}
}
@@ -538,7 +557,7 @@ static void msg_data_destroy(void *obj)
ast_msg_destroy(mdata->msg);
}
-static struct msg_data* msg_data_create(const struct ast_msg *msg, const char *to, const char *from)
+static struct msg_data *msg_data_create(const struct ast_msg *msg, const char *to, const char *from)
{
char *uri_params;
struct msg_data *mdata = ao2_alloc(sizeof(*mdata), msg_data_destroy);
@@ -548,17 +567,17 @@ static struct msg_data* msg_data_create(const struct ast_msg *msg, const char *t
}
/* typecast to suppress const warning */
- mdata->msg = ast_msg_ref((struct ast_msg*)msg);
+ mdata->msg = ast_msg_ref((struct ast_msg *) msg);
- /* starts with 'pjsip:' the 'pj' needs to be removed and maybe even
- the entire string. */
+ /* To starts with 'pjsip:' which needs to be removed. */
if (!(to = strchr(to, ':'))) {
ao2_ref(mdata, -1);
return NULL;
}
+ ++to;/* Now skip the ':' */
/* Make sure we start with sip: */
- mdata->to = ast_begins_with(to, "sip:") ? ast_strdup(++to) : ast_strdup(to - 3);
+ mdata->to = ast_begins_with(to, "sip:") ? ast_strdup(to) : ast_strdup(to - 4);
mdata->from = ast_strdup(from);
if (!mdata->to || !mdata->from) {
ao2_ref(mdata, -1);
@@ -589,12 +608,13 @@ static int msg_send(void *data)
pjsip_tx_data *tdata;
RAII_VAR(char *, uri, NULL, ast_free);
- RAII_VAR(struct ast_sip_endpoint *, endpoint, get_outbound_endpoint(
- mdata->to, &uri), ao2_cleanup);
+ RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+ endpoint = get_outbound_endpoint(mdata->to, &uri);
if (!endpoint) {
- ast_log(LOG_ERROR, "PJSIP MESSAGE - Could not find endpoint '%s' and "
- "no default outbound endpoint configured\n", mdata->to);
+ ast_log(LOG_ERROR,
+ "PJSIP MESSAGE - Could not find endpoint '%s' and no default outbound endpoint configured\n",
+ mdata->to);
return -1;
}