1 From 7e3dfd8a15fd0f98dbf0e04d2d7a5bded90ee401 Mon Sep 17 00:00:00 2001
2 From: George Joseph <gjoseph@sangoma.com>
3 Date: Tue, 11 Jan 2022 09:27:23 -0700
4 Subject: [PATCH] Create generic pjsip_hdr_find functions
6 pjsip_msg_find_hdr(), pjsip_msg_find_hdr_by_name(), and
7 pjsip_msg_find_hdr_by_names() require a pjsip_msg to be passed in
8 so if you need to search a header list that's not in a pjsip_msg,
9 you have to do it yourself. This commit adds generic versions of
10 those 3 functions that take in the actual header list head instead
11 of a pjsip_msg so if you need to search a list of headers in
12 something like a pjsip_multipart_part, you can do so easily.
14 pjsip/include/pjsip/sip_msg.h | 53 +++++++++++++++++++++++++++++++++++
15 pjsip/src/pjsip/sip_msg.c | 51 +++++++++++++++++++++++----------
16 2 files changed, 89 insertions(+), 15 deletions(-)
18 --- a/pjsip/include/pjsip/sip_msg.h
19 +++ b/pjsip/include/pjsip/sip_msg.h
20 @@ -363,6 +363,59 @@ PJ_DECL(void*) pjsip_hdr_shallow_clone(
21 PJ_DECL(int) pjsip_hdr_print_on( void *hdr, char *buf, pj_size_t len);
24 + * Find a header in a header list by the header type.
26 + * @param hdr_list The "head" of the header list.
27 + * @param type The header type to find.
28 + * @param start The first header field where the search should begin.
29 + * If NULL is specified, then the search will begin from the
30 + * first header, otherwise the search will begin at the
33 + * @return The header field, or NULL if no header with the specified
36 +PJ_DECL(void*) pjsip_hdr_find( const void *hdr_list,
41 + * Find a header in a header list by its name.
43 + * @param hdr_list The "head" of the header list.
44 + * @param name The header name to find.
45 + * @param start The first header field where the search should begin.
46 + * If NULL is specified, then the search will begin from the
47 + * first header, otherwise the search will begin at the
50 + * @return The header field, or NULL if no header with the specified
53 +PJ_DECL(void*) pjsip_hdr_find_by_name( const void *hdr_list,
54 + const pj_str_t *name,
58 + * Find a header in a header list by its name and short name version.
60 + * @param hdr_list The "head" of the header list.
61 + * @param name The header name to find.
62 + * @param sname The short name version of the header name.
63 + * @param start The first header field where the search should begin.
64 + * If NULL is specified, then the search will begin from the
65 + * first header, otherwise the search will begin at the
68 + * @return The header field, or NULL if no header with the specified
71 +PJ_DECL(void*) pjsip_hdr_find_by_names( const void *hdr_list,
72 + const pj_str_t *name,
73 + const pj_str_t *sname,
80 --- a/pjsip/src/pjsip/sip_msg.c
81 +++ b/pjsip/src/pjsip/sip_msg.c
82 @@ -334,13 +334,13 @@ PJ_DEF(pjsip_msg*) pjsip_msg_clone( pj_p
86 -PJ_DEF(void*) pjsip_msg_find_hdr( const pjsip_msg *msg,
87 - pjsip_hdr_e hdr_type, const void *start)
88 +PJ_DEF(void*) pjsip_hdr_find( const void *hdr_list,
89 + pjsip_hdr_e hdr_type, const void *start)
91 - const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=&msg->hdr;
92 + const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=hdr_list;
95 - hdr = msg->hdr.next;
98 for (; hdr!=end; hdr = hdr->next) {
99 if (hdr->type == hdr_type)
100 @@ -349,14 +349,14 @@ PJ_DEF(void*) pjsip_msg_find_hdr( const
104 -PJ_DEF(void*) pjsip_msg_find_hdr_by_name( const pjsip_msg *msg,
105 - const pj_str_t *name,
107 +PJ_DEF(void*) pjsip_hdr_find_by_name( const void *hdr_list,
108 + const pj_str_t *name,
111 - const pjsip_hdr *hdr=(const pjsip_hdr*)start, *end=&msg->hdr;
112 + const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=hdr_list;
115 - hdr = msg->hdr.next;
118 for (; hdr!=end; hdr = hdr->next) {
119 if (pj_stricmp(&hdr->name, name) == 0)
120 @@ -365,15 +365,15 @@ PJ_DEF(void*) pjsip_msg_find_hdr_by_nam
124 -PJ_DEF(void*) pjsip_msg_find_hdr_by_names( const pjsip_msg *msg,
125 - const pj_str_t *name,
126 - const pj_str_t *sname,
128 +PJ_DEF(void*) pjsip_hdr_find_by_names( const void *hdr_list,
129 + const pj_str_t *name,
130 + const pj_str_t *sname,
133 - const pjsip_hdr *hdr=(const pjsip_hdr*)start, *end=&msg->hdr;
134 + const pjsip_hdr *hdr=(const pjsip_hdr*) start, *end=hdr_list;
137 - hdr = msg->hdr.next;
140 for (; hdr!=end; hdr = hdr->next) {
141 if (pj_stricmp(&hdr->name, name) == 0)
142 @@ -384,6 +384,27 @@ PJ_DEF(void*) pjsip_msg_find_hdr_by_nam
146 +PJ_DEF(void*) pjsip_msg_find_hdr( const pjsip_msg *msg,
147 + pjsip_hdr_e hdr_type, const void *start)
149 + return pjsip_hdr_find(&msg->hdr, hdr_type, start);
152 +PJ_DEF(void*) pjsip_msg_find_hdr_by_name( const pjsip_msg *msg,
153 + const pj_str_t *name,
156 + return pjsip_hdr_find_by_name(&msg->hdr, name, start);
159 +PJ_DEF(void*) pjsip_msg_find_hdr_by_names( const pjsip_msg *msg,
160 + const pj_str_t *name,
161 + const pj_str_t *sname,
164 + return pjsip_hdr_find_by_names(&msg->hdr, name, sname, start);
167 PJ_DEF(void*) pjsip_msg_find_remove_hdr( pjsip_msg *msg,
168 pjsip_hdr_e hdr_type, void *start)