[Asterisk-code-review] res_pjsip_notify: Only allow a single Event header to be added to a N... (asterisk[13])

Joshua Colp asteriskteam at digium.com
Wed Jan 15 06:44:28 CST 2020


Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/13588 )

Change subject: res_pjsip_notify: Only allow a single Event header to be added to a NOTIFY
......................................................................

res_pjsip_notify: Only allow a single Event header to be added to a NOTIFY

ASTERISK-27775 #close
Reported by: AvayaXAsterisk

Change-Id: Iad158e908e34675ad98f74d09c5e73024e50c257
---
M res/res_pjsip_notify.c
1 file changed, 22 insertions(+), 0 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved; Approved for Submit



diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c
index a424eaa..4366e56 100644
--- a/res/res_pjsip_notify.c
+++ b/res/res_pjsip_notify.c
@@ -513,6 +513,16 @@
 
 /*!
  * \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
  *        NOTIFY request.
  */
@@ -564,6 +574,18 @@
 		}
 		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);
 	}
 }

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13588
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Iad158e908e34675ad98f74d09c5e73024e50c257
Gerrit-Change-Number: 13588
Gerrit-PatchSet: 1
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200115/a90a6918/attachment.html>


More information about the asterisk-code-review mailing list