/src/kamailio/src/core/str_list.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2001-2003 FhG Fokus |
3 | | * |
4 | | * This file is part of Kamailio, a free SIP server. |
5 | | * |
6 | | * Kamailio is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 2 of the License, or |
9 | | * (at your option) any later version |
10 | | * |
11 | | * Kamailio is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with this program; if not, write to the Free Software |
18 | | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
19 | | */ |
20 | | |
21 | | /** |
22 | | * @file |
23 | | * @brief Kamailio core :: Simple str type list and helper functions |
24 | | * @ingroup core |
25 | | * Module: @ref core |
26 | | */ |
27 | | |
28 | | #include "str.h" |
29 | | #include "mem/mem.h" |
30 | | #include "str_list.h" |
31 | | |
32 | | |
33 | | /** |
34 | | * @brief Add a new allocated list element to an existing list |
35 | | * |
36 | | * Add a new allocated list element to an existing list, the allocation is done |
37 | | * from the private memory pool |
38 | | * @param s input character |
39 | | * @param len length of input character |
40 | | * @param last existing list |
41 | | * @param total length of total characters in list |
42 | | * @return extended list |
43 | | */ |
44 | | struct str_list *append_str_list( |
45 | | char *s, int len, struct str_list **last, int *total) |
46 | 0 | { |
47 | 0 | struct str_list *nv; |
48 | 0 | nv = pkg_malloc(sizeof(struct str_list)); |
49 | 0 | if(!nv) { |
50 | 0 | PKG_MEM_ERROR; |
51 | 0 | return 0; |
52 | 0 | } |
53 | 0 | nv->s.s = s; |
54 | 0 | nv->s.len = len; |
55 | 0 | nv->next = 0; |
56 | |
|
57 | 0 | (*last)->next = nv; |
58 | 0 | *last = nv; |
59 | 0 | *total += len; |
60 | 0 | return nv; |
61 | 0 | } |
62 | | |
63 | | /** |
64 | | * @brief Add a new allocated list element with cloned block value to an existing list |
65 | | * |
66 | | * Add a new allocated list element with cloned value in block to an existing list, |
67 | | * the allocation is done from the private memory pool |
68 | | * @param head existing list |
69 | | * @param s input character |
70 | | * @param len length of input character |
71 | | * @return extended list |
72 | | */ |
73 | | str_list_t *str_list_block_add(str_list_t **head, char *s, int len) |
74 | 0 | { |
75 | 0 | str_list_t *nv; |
76 | 0 | nv = pkg_mallocxz(sizeof(str_list_t) + (len + 1) * sizeof(char)); |
77 | 0 | if(!nv) { |
78 | 0 | PKG_MEM_ERROR; |
79 | 0 | return 0; |
80 | 0 | } |
81 | 0 | nv->s.s = (char *)nv + sizeof(str_list_t); |
82 | 0 | memcpy(nv->s.s, s, len); |
83 | 0 | nv->s.len = len; |
84 | 0 | nv->next = *head; |
85 | 0 | *head = nv; |
86 | |
|
87 | 0 | return nv; |
88 | 0 | } |