Commit 24f3941d5e for asterisk.org
commit 24f3941d5e161b47ad52c46f33209fb81d3ed1ac
Author: Alexis Hadjisotiriou <ah@gilawa.com>
Date: Mon Jan 19 15:20:53 2026 +0000
res_pjsip_messaging: Remove Contact header from out-of-dialog MESSAGE as per RFC3428
According to RFC 3428 (Section 5), a Contact header is not required in a
MESSAGE request unless the sender wants to establish a session. This
patch ensures that the Contact header is removed from out-of-dialog
MESSAGE requests within res_pjsip_messaging.c.
Fixes: #1356
diff --git a/res/res_pjsip_messaging.c b/res/res_pjsip_messaging.c
index f9ab8717c6..929779a0f1 100644
--- a/res/res_pjsip_messaging.c
+++ b/res/res_pjsip_messaging.c
@@ -912,6 +912,7 @@ static int msg_send(void *data)
.body_text = ast_msg_get_body(mdata->msg)
};
+ pjsip_hdr *contact;
pjsip_tx_data *tdata;
RAII_VAR(char *, uri, NULL, ast_free);
RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
@@ -1023,7 +1024,11 @@ static int msg_send(void *data)
* tdata.
*/
vars_to_headers(mdata->msg, tdata);
-
+ /* Remove Contact header fields as per RFC 3428*/
+ contact = pjsip_msg_find_hdr(tdata->msg, PJSIP_H_CONTACT, NULL);
+ if (contact) {
+ pj_list_erase(contact);
+ }
ast_debug(1, "Sending message to '%s' (via endpoint %s) from '%s'\n",
uri, ast_sorcery_object_get_id(endpoint), mdata->from);