Module: sip-router
Branch: master
Commit: b1c80706eb428423d9c39796be5d4218d78ce06f
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b1c8070…
Author: Henning Westerholt <henning.westerholt(a)1und1.de>
Committer: Henning Westerholt <henning.westerholt(a)1und1.de>
Date: Tue Jul 5 23:38:13 2011 +0200
core: move redundant and identical implementation of a str_list type to core
- move redundant str_list and new_str implementations from tm and tmx to core
- rename new_str to a more descriptive append_str_list, no interface changes
- fix callers in tm and tmx
- add doxygen documentation
---
modules/tm/rpc_uac.c | 37 +++++--------------------------
modules_k/tmx/t_mi.c | 47 ++++++---------------------------------
str_list.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
str_list.h | 54 +++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 126 insertions(+), 71 deletions(-)
diff --git a/modules/tm/rpc_uac.c b/modules/tm/rpc_uac.c
index 34f7c36..f1458a1 100644
--- a/modules/tm/rpc_uac.c
+++ b/modules/tm/rpc_uac.c
@@ -29,6 +29,7 @@
#include "../../socket_info.h"
#include "../../ut.h"
#include "../../parser/parse_from.h"
+#include "../../str_list.h"
#include "ut.h"
#include "dlg.h"
#include "uac.h"
@@ -50,13 +51,6 @@
-struct str_list {
- str s;
- struct str_list *next;
-};
-
-
-
/** make sure the rpc user created the msg properly.
* Make sure that the FIFO user created the message
* correctly and fill some extra parameters in function
@@ -151,25 +145,6 @@ err:
-static inline struct str_list *new_str(char *s, int len,
- struct str_list **last, int *total)
-{
- struct str_list *new;
- new = pkg_malloc(sizeof(struct str_list));
- if (!new) {
- LOG(L_ERR, "new_str: Not enough mem\n");
- return 0;
- }
- new->s.s = s;
- new->s.len = len;
- new->next = 0;
-
- (*last)->next = new;
- *last = new;
- *total += len;
- return new;
-}
-
/** construct a "header block" from a header list.
@@ -208,7 +183,7 @@ static char *get_hfblock(str *uri, struct hdr_field *hf, int proto,
while(p) {
d = q_memchr(needle, SUBST_CHAR, p);
if (!d || d + 1 >= needle + p) { /* nothing to substitute */
- if (!new_str(begin, p, &last, &total_len)) goto error;
+ if (!append_str_list(begin, p, &last, &total_len)) goto error;
break;
} else {
frag_len = d - begin;
@@ -216,7 +191,7 @@ static char *get_hfblock(str *uri, struct hdr_field *hf, int proto,
switch(*d) {
case SUBST_CHAR: /* double SUBST_CHAR: IP */
/* string before substitute */
- if (!new_str(begin, frag_len, &last, &total_len))
+ if (!append_str_list(begin, frag_len, &last, &total_len))
goto error;
/* substitute */
if (!sock_name) {
@@ -234,12 +209,12 @@ static char *get_hfblock(str *uri, struct hdr_field *hf, int proto,
sock_name = &di.send_sock->address_str;
portname = &di.send_sock->port_no_str;
}
- if (!new_str(sock_name->s, sock_name->len, &last,
+ if (!append_str_list(sock_name->s, sock_name->len, &last,
&total_len))
goto error;
/* inefficient - FIXME --andrei*/
- if (!new_str(":", 1, &last, &total_len)) goto error;
- if (!new_str(portname->s, portname->len, &last,
+ if (!append_str_list(":", 1, &last, &total_len)) goto error;
+ if (!append_str_list(portname->s, portname->len, &last,
&total_len)) goto error;
/* keep going ... */
begin = needle = d + 1;
diff --git a/modules_k/tmx/t_mi.c b/modules_k/tmx/t_mi.c
index 973061e..e784bf6 100644
--- a/modules_k/tmx/t_mi.c
+++ b/modules_k/tmx/t_mi.c
@@ -38,13 +38,9 @@
#include "../../parser/parse_from.h"
#include "../../modules/tm/ut.h"
#include "../../lib/kmi/mi.h"
+#include "../../str_list.h"
#include "tmx_mod.h"
-/*! simple string list */
-struct str_list {
- str s;
- struct str_list *next;
-};
/*! Which header fields should be skipped */
#define skip_hf(_hf) \
@@ -160,35 +156,6 @@ static inline struct mi_root* mi_check_msg(struct sip_msg* msg, str*
method,
return 0;
}
-/*!
- * \brief Allocate a new str on a str list
- *
- * Allocate a new str in pkg_mem and attach it to a str list. Update
- * the total number of list elements.
- * \param s char array
- * \param len length of the char array
- * \param last last list element
- * \param total total number of list elements
- * \return pointer to the new list element
- */
-static inline struct str_list *new_str(char *s, int len, struct str_list **last, int
*total)
-{
- struct str_list *new;
- new=pkg_malloc(sizeof(struct str_list));
- if (!new) {
- LM_ERR("no more pkg mem\n");
- return 0;
- }
- new->s.s=s;
- new->s.len=len;
- new->next=0;
-
- (*last)->next=new;
- *last=new;
- *total+=len;
-
- return new;
-}
/*!
* \brief Convert a header field block to char array
@@ -225,7 +192,7 @@ static inline char *get_hfblock( str *uri, struct hdr_field *hf, int
*l, struct
while(hf_avail) {
d=memchr(needle, SUBST_CHAR, hf_avail);
if (!d || d+1>=needle+hf_avail) { /* nothing to substitute */
- new=new_str(begin, hf_avail, &last, &total_len);
+ new=append_str_list(begin, hf_avail, &last, &total_len);
if (!new) goto error;
break;
} else {
@@ -234,7 +201,7 @@ static inline char *get_hfblock( str *uri, struct hdr_field *hf, int
*l, struct
switch(*d) {
case SUBST_CHAR: /* double SUBST_CHAR: IP */
/* string before substitute */
- new=new_str(begin, frag_len, &last, &total_len);
+ new=append_str_list(begin, frag_len, &last, &total_len);
if (!new) goto error;
/* substitute */
if (!sock_name) {
@@ -248,13 +215,13 @@ static inline char *get_hfblock( str *uri, struct hdr_field *hf, int
*l, struct
sock_name=&(*send_sock)->address_str;
portname=&(*send_sock)->port_no_str;
}
- new=new_str(sock_name->s, sock_name->len,
+ new=append_str_list(sock_name->s, sock_name->len,
&last, &total_len );
if (!new) goto error;
/* inefficient - FIXME --andrei*/
- new=new_str(":", 1, &last, &total_len);
+ new=append_str_list(":", 1, &last, &total_len);
if (!new) goto error;
- new=new_str(portname->s, portname->len,
+ new=append_str_list(portname->s, portname->len,
&last, &total_len );
if (!new) goto error;
/* keep going ... */
@@ -268,7 +235,7 @@ static inline char *get_hfblock( str *uri, struct hdr_field *hf, int
*l, struct
} /* possible substitute */
} /* substitution loop */
/* proceed to next header */
- /* new=new_str(CRLF, CRLF_LEN, &last, &total_len );
+ /* new=append_str_list(CRLF, CRLF_LEN, &last, &total_len );
if (!new) goto error; */
LM_DBG("one more hf processed\n");
} /* header loop */
diff --git a/str_list.c b/str_list.c
new file mode 100644
index 0000000..a51bffa
--- /dev/null
+++ b/str_list.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2001-2003 FhG Fokus
+ *
+ * This file is part of sip-router, a free SIP server.
+ *
+ * sip-router is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * sip-router is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * @file
+ * @brief Simple str type list and helper functions
+ */
+
+
+#include "str.h"
+#include "mem/mem.h"
+#include "str_list.h"
+
+
+/**
+ * @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
+ * @param len length of input character
+ * @param last existing list
+ * @param total length of total characters in list
+ * @return extended list
+ */
+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) {
+ PKG_MEM_ERROR;
+ return 0;
+ }
+ new->s.s = s;
+ new->s.len = len;
+ new->next = 0;
+
+ (*last)->next = new;
+ *last = new;
+ *total += len;
+ return new;
+}
diff --git a/str_list.h b/str_list.h
new file mode 100644
index 0000000..6373d68
--- /dev/null
+++ b/str_list.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2001-2003 FhG Fokus
+ * Copyright (C) 2006 Voice Sistem SRL
+ *
+ * This file is part of sip-router, a free SIP server.
+ *
+ * sip-router is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version
+ *
+ * sip-router is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * 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
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/**
+ * @file
+ * @brief Simple str type list and helper functions
+ */
+
+
+#ifndef str_list_h
+#define str_list_h
+
+
+/**
+ * @brief Simple str type list
+ */
+struct str_list {
+ str s;
+ struct str_list *next;
+};
+
+
+/**
+ * @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
+ * @param len length of input character
+ * @param last existing list
+ * @param total length of total characters in list
+ * @return extended list
+ */
+struct str_list *append_str_list(char *s, int len, struct str_list **last, int *total);
+
+#endif