From c011914f7050ef8d84ffb1b266672a44699a4906 Mon Sep 17 00:00:00 2001 From: Naveen Albert Date: Wed, 9 Aug 2023 23:17:26 +0000 Subject: [PATCH] res_pjsip_header_funcs: Make prefix argument optional. The documentation for PJSIP_HEADERS claims that prefix is optional, but in the code it is actually not. However, there is no inherent reason for this, as users may want to retrieve all header names, not just those beginning with a certain prefix. This makes the prefix optional for this function, simply fetching all header names if not specified. As a result, the documentation is now correct. Resolves: #230 UserNote: The prefix argument to PJSIP_HEADERS is now optional. If not specified, all header names will be returned. (cherry picked from commit 2179082eafdb328277fcfeed0d6f471e60186d2c) --- res/res_pjsip_header_funcs.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/res/res_pjsip_header_funcs.c b/res/res_pjsip_header_funcs.c index 8a60e36aad..00640a0d22 100644 --- a/res/res_pjsip_header_funcs.c +++ b/res/res_pjsip_header_funcs.c @@ -453,7 +453,7 @@ static pjsip_hdr *find_header(struct hdr_list *list, const char *header_name, static int read_headers(void *obj) { struct header_data *data = obj; - size_t len = strlen(data->header_name); + size_t len = !ast_strlen_zero(data->header_name) ? strlen(data->header_name) : 0; pjsip_hdr *hdr = NULL; char *pj_hdr_string; int pj_hdr_string_len; @@ -475,7 +475,7 @@ static int read_headers(void *obj) list = datastore->data; pj_hdr_string = ast_alloca(data->len); AST_LIST_TRAVERSE(list, le, nextptr) { - if (pj_strnicmp2(&le->hdr->name, data->header_name, len) == 0) { + if (!len || pj_strnicmp2(&le->hdr->name, data->header_name, len) == 0) { /* Found matched header, append to buf */ hdr = le->hdr; @@ -518,8 +518,13 @@ static int read_headers(void *obj) } if (wlen == 0) { - ast_debug(1, "There was no header named %s.\n", data->header_name); - return -1; + if (!len) { + /* No headers at all on this channel */ + return 0; + } else { + ast_debug(1, "There was no header beginning with %s.\n", data->header_name); + return -1; + } } else { data->buf[wlen-1] = '\0'; } @@ -758,11 +763,6 @@ static int func_read_headers(struct ast_channel *chan, const char *function, cha return -1; } - if (ast_strlen_zero(args.header_pattern)) { - ast_log(AST_LOG_ERROR, "This function requires a pattern.\n"); - return -1; - } - header_data.channel = channel; header_data.header_name = args.header_pattern; header_data.header_value = NULL;