[Asterisk-code-review] bundled_pjproject: Create generic pjsip_hdr_find functions (asterisk[16])

Friendly Automation asteriskteam at digium.com
Mon Jan 17 06:41:13 CST 2022


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17863 )

Change subject: bundled_pjproject: Create generic pjsip_hdr_find functions
......................................................................

bundled_pjproject: Create generic pjsip_hdr_find functions

pjsip_msg_find_hdr(), pjsip_msg_find_hdr_by_name(), and
pjsip_msg_find_hdr_by_names() require a pjsip_msg to be passed in
so if you need to search a header list that's not in a pjsip_msg,
you have to do it yourself.  This commit adds generic versions of
those 3 functions that take in the actual header list head instead
of a pjsip_msg so if you need to search a list of headers in
something like a pjsip_multipart_part, you can do so easily.

Change-Id: I6f2c127170eafda48e5e0d5d4d187bcd52b4df07
---
A third-party/pjproject/patches/0150-Create-generic-pjsip_hdr_find-functions.patch
1 file changed, 176 insertions(+), 0 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/third-party/pjproject/patches/0150-Create-generic-pjsip_hdr_find-functions.patch b/third-party/pjproject/patches/0150-Create-generic-pjsip_hdr_find-functions.patch
new file mode 100644
index 0000000..6ddb346
--- /dev/null
+++ b/third-party/pjproject/patches/0150-Create-generic-pjsip_hdr_find-functions.patch
@@ -0,0 +1,176 @@
+From 7e3dfd8a15fd0f98dbf0e04d2d7a5bded90ee401 Mon Sep 17 00:00:00 2001
+From: George Joseph <gjoseph at sangoma.com>
+Date: Tue, 11 Jan 2022 09:27:23 -0700
+Subject: [PATCH] Create generic pjsip_hdr_find functions
+
+pjsip_msg_find_hdr(), pjsip_msg_find_hdr_by_name(), and
+pjsip_msg_find_hdr_by_names() require a pjsip_msg to be passed in
+so if you need to search a header list that's not in a pjsip_msg,
+you have to do it yourself.  This commit adds generic versions of
+those 3 functions that take in the actual header list head instead
+of a pjsip_msg so if you need to search a list of headers in
+something like a pjsip_multipart_part, you can do so easily.
+---
+ pjsip/include/pjsip/sip_msg.h | 53 +++++++++++++++++++++++++++++++++++
+ pjsip/src/pjsip/sip_msg.c     | 51 +++++++++++++++++++++++----------
+ 2 files changed, 89 insertions(+), 15 deletions(-)
+
+diff --git a/pjsip/include/pjsip/sip_msg.h b/pjsip/include/pjsip/sip_msg.h
+index 4c9100d39..e3502e94e 100644
+--- a/pjsip/include/pjsip/sip_msg.h
++++ b/pjsip/include/pjsip/sip_msg.h
+@@ -362,6 +362,59 @@ PJ_DECL(void*) pjsip_hdr_shallow_clone( pj_pool_t *pool, const void *hdr );
+  */
+ PJ_DECL(int) pjsip_hdr_print_on( void *hdr, char *buf, pj_size_t len);
+ 
++/**
++ * Find a header in a header list by the header type.
++ *
++ * @param hdr_list  The "head" of the header list.
++ * @param type      The header type to find.
++ * @param start     The first header field where the search should begin.
++ *                  If NULL is specified, then the search will begin from the
++ *                  first header, otherwise the search will begin at the
++ *                  specified header.
++ *
++ * @return          The header field, or NULL if no header with the specified
++ *                  type is found.
++ */
++PJ_DECL(void*)  pjsip_hdr_find( const void *hdr_list,
++				pjsip_hdr_e type,
++				const void *start);
++
++/**
++ * Find a header in a header list by its name.
++ *
++ * @param hdr_list  The "head" of the header list.
++ * @param name      The header name to find.
++ * @param start     The first header field where the search should begin.
++ *                  If NULL is specified, then the search will begin from the
++ *                  first header, otherwise the search will begin at the
++ *                  specified header.
++ *
++ * @return          The header field, or NULL if no header with the specified
++ *                  type is found.
++ */
++PJ_DECL(void*)  pjsip_hdr_find_by_name( const void *hdr_list,
++					const pj_str_t *name,
++					const void *start);
++
++/**
++ * Find a header in a header list by its name and short name version.
++ *
++ * @param hdr_list  The "head" of the header list.
++ * @param name      The header name to find.
++ * @param sname     The short name version of the header name.
++ * @param start     The first header field where the search should begin.
++ *                  If NULL is specified, then the search will begin from the
++ *                  first header, otherwise the search will begin at the
++ *                  specified header.
++ *
++ * @return	    The header field, or NULL if no header with the specified
++ *		    type is found.
++ */
++PJ_DECL(void*)  pjsip_hdr_find_by_names( const void *hdr_list,
++					 const pj_str_t *name,
++					 const pj_str_t *sname,
++					 const void *start);
++
+ /**
+  * @}
+  */
+diff --git a/pjsip/src/pjsip/sip_msg.c b/pjsip/src/pjsip/sip_msg.c
+index 6ba3054da..2a6a96af0 100644
+--- a/pjsip/src/pjsip/sip_msg.c
++++ b/pjsip/src/pjsip/sip_msg.c
+@@ -356,13 +356,13 @@ PJ_DEF(pjsip_msg*) pjsip_msg_clone( pj_pool_t *pool, const pjsip_msg *src)
+     return dst;
+ }
+ 
+-PJ_DEF(void*)  pjsip_msg_find_hdr( const pjsip_msg *msg, 
+-				   pjsip_hdr_e hdr_type, const void *start)
++PJ_DEF(void*)  pjsip_hdr_find( const void *hdr_list,
++			       pjsip_hdr_e hdr_type, const void *start)
+ {
+-    const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=&msg->hdr;
++    const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=hdr_list;
+ 
+     if (hdr == NULL) {
+-	hdr = msg->hdr.next;
++	hdr = end->next;
+     }
+     for (; hdr!=end; hdr = hdr->next) {
+ 	if (hdr->type == hdr_type)
+@@ -371,14 +371,14 @@ PJ_DEF(void*)  pjsip_msg_find_hdr( const pjsip_msg *msg,
+     return NULL;
+ }
+ 
+-PJ_DEF(void*)  pjsip_msg_find_hdr_by_name( const pjsip_msg *msg, 
+-					   const pj_str_t *name, 
+-					   const void *start)
++PJ_DEF(void*)  pjsip_hdr_find_by_name( const void *hdr_list,
++				       const pj_str_t *name,
++				       const void *start)
+ {
+-    const pjsip_hdr *hdr=(const pjsip_hdr*)start, *end=&msg->hdr;
++    const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=hdr_list;
+ 
+     if (hdr == NULL) {
+-	hdr = msg->hdr.next;
++	hdr = end->next;
+     }
+     for (; hdr!=end; hdr = hdr->next) {
+ 	if (pj_stricmp(&hdr->name, name) == 0)
+@@ -387,15 +387,15 @@ PJ_DEF(void*)  pjsip_msg_find_hdr_by_name( const pjsip_msg *msg,
+     return NULL;
+ }
+ 
+-PJ_DEF(void*)  pjsip_msg_find_hdr_by_names( const pjsip_msg *msg, 
+-					    const pj_str_t *name, 
+-					    const pj_str_t *sname,
+-					    const void *start)
++PJ_DEF(void*)  pjsip_hdr_find_by_names( const void *hdr_list,
++					const pj_str_t *name,
++					const pj_str_t *sname,
++					const void *start)
+ {
+-    const pjsip_hdr *hdr=(const pjsip_hdr*)start, *end=&msg->hdr;
++    const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=hdr_list;
+ 
+     if (hdr == NULL) {
+-	hdr = msg->hdr.next;
++	hdr = end->next;
+     }
+     for (; hdr!=end; hdr = hdr->next) {
+ 	if (pj_stricmp(&hdr->name, name) == 0)
+@@ -406,6 +406,27 @@ PJ_DEF(void*)  pjsip_msg_find_hdr_by_names( const pjsip_msg *msg,
+     return NULL;
+ }
+ 
++PJ_DEF(void*)  pjsip_msg_find_hdr( const pjsip_msg *msg,
++				   pjsip_hdr_e hdr_type, const void *start)
++{
++    return pjsip_hdr_find(&msg->hdr, hdr_type, start);
++}
++
++PJ_DEF(void*)  pjsip_msg_find_hdr_by_name( const pjsip_msg *msg,
++					   const pj_str_t *name,
++					   const void *start)
++{
++    return pjsip_hdr_find_by_name(&msg->hdr, name, start);
++}
++
++PJ_DEF(void*)  pjsip_msg_find_hdr_by_names( const pjsip_msg *msg,
++					    const pj_str_t *name,
++					    const pj_str_t *sname,
++					    const void *start)
++{
++    return pjsip_hdr_find_by_names(&msg->hdr, name, sname, start);
++}
++
+ PJ_DEF(void*) pjsip_msg_find_remove_hdr( pjsip_msg *msg, 
+ 				         pjsip_hdr_e hdr_type, void *start)
+ {
+-- 
+2.34.1
+

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

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I6f2c127170eafda48e5e0d5d4d187bcd52b4df07
Gerrit-Change-Number: 17863
Gerrit-PatchSet: 2
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220117/d22f61bf/attachment-0001.html>


More information about the asterisk-code-review mailing list