[sr-dev] git:5.5:557ac56a: core: str list - added function to insert a block string in list

Daniel-Constantin Mierla miconda at gmail.com
Tue Jun 29 17:24:27 CEST 2021


Hello,

see the other commits that were backported related to
modparamx/loadmodulex -- this one adds an internal helper function
needed by them.

Cheers,
Daniel

On 29.06.21 16:13, Henning Westerholt wrote:
> Hi Daniel,
>
> I probably missed the relevant discussion on the issue tracker or list. Just wondered to which fix this utility extensions were about in the stable branch.
>
> Thanks and regards,
>
> Henning
>
> -- 
> Henning Westerholt - https://skalatan.de/blog/
> Kamailio services - https://gilawa.com 
>
> -----Original Message-----
> From: sr-dev <sr-dev-bounces at lists.kamailio.org> On Behalf Of Daniel-Constantin Mierla
> Sent: Tuesday, June 29, 2021 2:53 PM
> To: sr-dev at lists.kamailio.org
> Subject: [sr-dev] git:5.5:557ac56a: core: str list - added function to insert a block string in list
>
> Module: kamailio
> Branch: 5.5
> Commit: 557ac56a6ec6b4ca3d76a57ff8b21c64027791f2
> URL: https://github.com/kamailio/kamailio/commit/557ac56a6ec6b4ca3d76a57ff8b21c64027791f2
>
> Author: Daniel-Constantin Mierla <miconda at gmail.com>
> Committer: Daniel-Constantin Mierla <miconda at gmail.com>
> Date: 2021-06-29T14:42:12+02:00
>
> core: str list - added function to insert a block string in list
>
> (cherry picked from commit b92b931c26c199b756fd08e9c80cc9305469fd2b)
>
> ---
>
> Modified: src/core/str_list.c
> Modified: src/core/str_list.h
>
> ---
>
> Diff:  https://github.com/kamailio/kamailio/commit/557ac56a6ec6b4ca3d76a57ff8b21c64027791f2.diff
> Patch: https://github.com/kamailio/kamailio/commit/557ac56a6ec6b4ca3d76a57ff8b21c64027791f2.patch
>
> ---
>
> diff --git a/src/core/str_list.c b/src/core/str_list.c index f63b4c9151..207cee5bc3 100644
> --- a/src/core/str_list.c
> +++ b/src/core/str_list.c
> @@ -13,13 +13,13 @@
>   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>   * GNU General Public License for more details.
>   *
> - * You should have received a copy of the GNU General Public License
> - * along with this program; if not, write to the Free Software 
> + * You should have received a copy of the GNU General Public License
> + * along with this program; if not, write to the Free Software
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
>   */
>  
>  /**
> - * @file 
> + * @file
>   * @brief Kamailio core :: Simple str type list and helper functions
>   * @ingroup core
>   * Module: @ref core
> @@ -32,7 +32,7 @@
>  
>  /**
>   * @brief Add a new allocated list element to an existing list
> - * 
> + *
>   * Add a new allocated list element to an existing list, the allocation is done
>   * from the private memory pool
>   * @param s input character
> @@ -43,18 +43,45 @@
>   */
>  struct str_list *append_str_list(char *s, int len, struct str_list **last, int *total)  {
> -	struct str_list *new;
> -	new = pkg_malloc(sizeof(struct str_list));
> -	if (!new) {
> +	struct str_list *nv;
> +	nv = pkg_malloc(sizeof(struct str_list));
> +	if (!nv) {
>  		PKG_MEM_ERROR;
>  		return 0;
>  	}
> -	new->s.s = s;
> -	new->s.len = len;
> -	new->next = 0;
> +	nv->s.s = s;
> +	nv->s.len = len;
> +	nv->next = 0;
>  
> -	(*last)->next = new;
> -	*last = new;
> +	(*last)->next = nv;
> +	*last = nv;
>  	*total += len;
> -	return new;
> +	return nv;
> +}
> +
> +/**
> + * @brief Add a new allocated list element with cloned block value to 
> +an existing list
> + *
> + * Add a new allocated list element with cloned value in block to an 
> +existing list,
> + * the allocation is done from the private memory pool
> + * @param head existing list
> + * @param s input character
> + * @param len length of input character
> + * @return extended list
> + */
> +str_list_t *str_list_block_add(str_list_t **head, char *s, int len) {
> +	str_list_t *nv;
> +	nv = pkg_mallocxz(sizeof(str_list_t) + (len+1)*sizeof(char));
> +	if (!nv) {
> +		PKG_MEM_ERROR;
> +		return 0;
> +	}
> +	nv->s.s = (char*)nv + sizeof(str_list_t);
> +	memcpy(nv->s.s, s, len);
> +	nv->s.len = len;
> +	nv->next = *head;
> +	*head = nv;
> +
> +	return nv;
>  }
> diff --git a/src/core/str_list.h b/src/core/str_list.h index db3fa12887..1eac2578b0 100644
> --- a/src/core/str_list.h
> +++ b/src/core/str_list.h
> @@ -51,4 +51,16 @@ typedef struct str_list {
>   */
>  struct str_list *append_str_list(char *s, int len, struct str_list **last, int *total);
>  
> +/**
> + * @brief Add a new allocated list element with cloned block value to 
> +an existing list
> + *
> + * Add a new allocated list element with cloned value in block to an 
> +existing list,
> + * the allocation is done from the private memory pool
> + * @param head existing list
> + * @param s input character
> + * @param len length of input character
> + * @return extended list
> + */
> +str_list_t *str_list_block_add(str_list_t **head, char *s, int len);
> +
>  #endif
>
>
> _______________________________________________
> Kamailio (SER) - Development Mailing List sr-dev at lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev

-- 
Daniel-Constantin Mierla -- www.asipto.com
www.twitter.com/miconda -- www.linkedin.com/in/miconda




More information about the sr-dev mailing list