Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (C) 2017 OpenSIPS Solutions |
3 | | * |
4 | | * This file is part of opensips, a free SIP server. |
5 | | * |
6 | | * opensips 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 | | * opensips 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 | | #ifndef __STR_LIST__ |
22 | | #define __STR_LIST__ |
23 | | |
24 | | #include <stdlib.h> |
25 | | |
26 | | #include "str.h" |
27 | | #include "lib/osips_malloc.h" |
28 | | #include "lib/list.h" |
29 | | #include "ut.h" |
30 | | |
31 | | typedef struct _str_list { |
32 | | str s; |
33 | | struct _str_list *next; |
34 | | } str_list; |
35 | | |
36 | | typedef struct _str_dlist { |
37 | | str s; |
38 | | struct list_head list; |
39 | | } str_dlist; |
40 | | |
41 | | static inline str_list *_new_str_list(str *val, osips_malloc_t alloc_item) |
42 | 0 | { |
43 | 0 | str_list *new_el; |
44 | 0 | if (!alloc_item) |
45 | 0 | return NULL; |
46 | 0 | new_el = alloc_item(sizeof *new_el + val->len + 1); |
47 | 0 | if (!new_el) |
48 | 0 | return NULL; |
49 | 0 | memset(new_el, 0, sizeof *new_el); |
50 | 0 | new_el->s.s = (char *)(new_el + 1); |
51 | 0 | str_cpy(&new_el->s, val); |
52 | 0 | new_el->s.s[new_el->s.len] = '\0'; |
53 | 0 | return new_el; |
54 | 0 | } Unexecuted instantiation: fuzz_csv_parser.c:_new_str_list Unexecuted instantiation: csv.c:_new_str_list Unexecuted instantiation: mod_fix.c:_new_str_list Unexecuted instantiation: transformations.c:_new_str_list |
55 | | |
56 | | #define new_pkg_str_list(val) \ |
57 | | _new_str_list(val, osips_pkg_malloc) |
58 | | |
59 | | #define new_shm_str_list(val) \ |
60 | | _new_str_list(val, osips_shm_malloc) |
61 | | |
62 | | static inline str_list *_insert_str_list(str_list **list, str *val, osips_malloc_t alloc_item) |
63 | 0 | { |
64 | 0 | str_list *new_el = _new_str_list(val, alloc_item); |
65 | 0 | if (!new_el) |
66 | 0 | return NULL; |
67 | 0 |
|
68 | 0 | new_el->next = *list; |
69 | 0 | *list = new_el; |
70 | 0 | return *list; |
71 | 0 | } Unexecuted instantiation: fuzz_csv_parser.c:_insert_str_list Unexecuted instantiation: csv.c:_insert_str_list Unexecuted instantiation: mod_fix.c:_insert_str_list Unexecuted instantiation: transformations.c:_insert_str_list |
72 | | |
73 | | #define insert_pkg_str_list(list, val) \ |
74 | | _insert_str_list(list, val, osips_pkg_malloc) |
75 | | |
76 | | #define insert_shm_str_list(list, val) \ |
77 | | _insert_str_list(list, val, osips_shm_malloc) |
78 | | |
79 | | static inline str_list *_add_str_list(str_list **list, str *val, osips_malloc_t alloc_item) |
80 | 0 | { |
81 | 0 | str_list *new_el = _new_str_list(val, alloc_item); |
82 | 0 | if (!new_el) |
83 | 0 | return NULL; |
84 | 0 |
|
85 | 0 | add_last(new_el, *list); |
86 | 0 | return *list; |
87 | 0 | } Unexecuted instantiation: fuzz_csv_parser.c:_add_str_list Unexecuted instantiation: csv.c:_add_str_list Unexecuted instantiation: mod_fix.c:_add_str_list Unexecuted instantiation: transformations.c:_add_str_list |
88 | | |
89 | | #define add_pkg_str_list(list, val) \ |
90 | | _add_str_list(list, val, osips_pkg_malloc) |
91 | | |
92 | | #define add_shm_str_list(list, val) \ |
93 | | _add_str_list(list, val, osips_shm_malloc) |
94 | | |
95 | | |
96 | | static inline void _free_str_list(str_list *list, |
97 | | osips_free_t free_item, osips_free_t free_str) |
98 | 0 | { |
99 | 0 | str_list *prev; |
100 | 0 |
|
101 | 0 | while (list) { |
102 | 0 | prev = list; |
103 | 0 | list = list->next; |
104 | 0 |
|
105 | 0 | if (free_str) |
106 | 0 | free_str(prev->s.s); |
107 | 0 |
|
108 | 0 | if (free_item) |
109 | 0 | free_item(prev); |
110 | 0 | } |
111 | 0 | } Unexecuted instantiation: fuzz_csv_parser.c:_free_str_list Unexecuted instantiation: csv.c:_free_str_list Unexecuted instantiation: mod_fix.c:_free_str_list Unexecuted instantiation: transformations.c:_free_str_list |
112 | | |
113 | | #define free_pkg_str_list(list) \ |
114 | | _free_str_list(list, osips_pkg_free, NULL) |
115 | | |
116 | | #define free_shm_str_list(list) \ |
117 | | _free_str_list(list, osips_shm_free, NULL) |
118 | | |
119 | | static inline str_list *dup_shm_str_list(const str_list *list) |
120 | 0 | { |
121 | 0 | str_list *item, *ret = NULL; |
122 | 0 | const str_list *it; |
123 | 0 |
|
124 | 0 | for (it = list; it; it = it->next) { |
125 | 0 | item = new_shm_str_list((str *)&it->s); |
126 | 0 | if (!item) |
127 | 0 | goto oom; |
128 | 0 |
|
129 | 0 | add_last(item, ret); |
130 | 0 | } |
131 | 0 |
|
132 | 0 | return ret; |
133 | 0 |
|
134 | 0 | oom: |
135 | 0 | LM_ERR("oom\n"); |
136 | 0 | free_shm_str_list(ret); |
137 | 0 | return NULL; |
138 | 0 | } Unexecuted instantiation: fuzz_csv_parser.c:dup_shm_str_list Unexecuted instantiation: csv.c:dup_shm_str_list Unexecuted instantiation: mod_fix.c:dup_shm_str_list Unexecuted instantiation: transformations.c:dup_shm_str_list |
139 | | |
140 | | static inline void _free_str_dlist(struct list_head *dlist, |
141 | | osips_free_t free_item, osips_free_t free_str) |
142 | 0 | { |
143 | 0 | struct list_head *_, *__; |
144 | 0 | str_dlist *item; |
145 | 0 |
|
146 | 0 | list_for_each_safe(_, __, dlist) { |
147 | 0 | item = list_entry(_, str_dlist, list); |
148 | 0 | if (free_str) |
149 | 0 | free_str(item->s.s); |
150 | 0 |
|
151 | 0 | if (free_item) |
152 | 0 | free_item(item); |
153 | 0 | } |
154 | 0 | } Unexecuted instantiation: fuzz_csv_parser.c:_free_str_dlist Unexecuted instantiation: csv.c:_free_str_dlist Unexecuted instantiation: mod_fix.c:_free_str_dlist Unexecuted instantiation: transformations.c:_free_str_dlist |
155 | | |
156 | | #define free_pkg_str_dlist(list) \ |
157 | | _free_str_dlist(list, osips_pkg_free, osips_pkg_free) |
158 | | |
159 | | #define free_shm_str_dlist(list) \ |
160 | | _free_str_dlist(list, osips_shm_free, osips_shm_free) |
161 | | |
162 | | #endif /* __STR_LIST__ */ |