Merge "res_pjsip_notify: Only allow a single Event header to be added to a NOTIFY" into 16

This commit is contained in:
Friendly Automation 2020-01-15 06:42:53 -06:00 committed by Gerrit Code Review
commit ddf8e6de79
1 changed files with 22 additions and 0 deletions

View File

@ -511,6 +511,16 @@ static int not_allowed(const char *name)
return 0;
}
/*!
* \internal
* \brief Check if the given header can be added to a message more than once.
*/
static int multiple_headers_allowed(const char *name)
{
/* This can be extended to include additional headers */
return strcasecmp("Event", name);
}
/*!
* \internal
* \brief If a content type was specified add it and the content body to the
@ -564,6 +574,18 @@ static void build_notify(pjsip_tx_data *tdata, const char *name, const char *val
}
ast_str_append(content, 0, "%s", value);
} else {
/* See if there is an existing one */
if (!multiple_headers_allowed(name)) {
pj_str_t hdr_name;
pj_cstr(&hdr_name, name);
if (pjsip_msg_find_hdr_by_name(tdata->msg, &hdr_name, NULL)) {
ast_log(LOG_ERROR, "Only one '%s' header can be added to a NOTIFY, "
"ignoring \"%s: %s\"\n", name, name, value);
return;
}
}
ast_sip_add_header(tdata, name, value);
}
}