[sr-dev] git:master:b92b931c: core: str list - added function to insert a block string in list
Daniel-Constantin Mierla
miconda at gmail.com
Tue Jun 29 09:29:31 CEST 2021
Module: kamailio
Branch: master
Commit: b92b931c26c199b756fd08e9c80cc9305469fd2b
URL: https://github.com/kamailio/kamailio/commit/b92b931c26c199b756fd08e9c80cc9305469fd2b
Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date: 2021-06-29T08:55:32+02:00
core: str list - added function to insert a block string in list
---
Modified: src/core/str_list.c
Modified: src/core/str_list.h
---
Diff: https://github.com/kamailio/kamailio/commit/b92b931c26c199b756fd08e9c80cc9305469fd2b.diff
Patch: https://github.com/kamailio/kamailio/commit/b92b931c26c199b756fd08e9c80cc9305469fd2b.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
More information about the sr-dev
mailing list