Module: sip-router
Branch: master
Commit: df088fb86adaf8f10bbdfebd5502ea9590341bc8
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=df088fb…
Author: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Committer: Andrei Pelinescu-Onciul <andrei(a)iptel.org>
Date: Mon Jul 20 13:00:37 2009 +0200
core: parse_phostport split for k compatibility
parse_phostport in sr and ser returned a list of pkg_malloc'ed
addresses belonging to the same multi-homed "group". For example
sctp:(1.2.3.4, 5.6.7.8):5080 is a valid address and it means
that this sctp listening socket must use multi-homing on the 2
IPs. However several kamailio modules use parse_phostport and
expect the old integer returning version. In this case it was
easier to split the function in the core into parse_phostport()
(old behaviour) and parse_phostport_mh() (returns list of MH
addresses) and make the core command line parser use the MH
supporting version.
---
main.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++-------
socket_info.h | 2 +-
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/main.c b/main.c
index 8d7bc57..23455e7 100644
--- a/main.c
+++ b/main.c
@@ -963,7 +963,21 @@ error:
* returns fills proto, port, host and returns list of addresses on success
* (pkg malloc'ed) and 0 on failure
*/
-struct name_lst* parse_phostport(char* s, char** host, int* hlen,
+/** get protocol host and port from a string representation.
+ * parses [proto:]host[:port] or
+ * [proto:](host_1, host_2, ... host_n)[:port]
+ * where proto= udp|tcp|tls|sctp
+ * @param s - string (like above)
+ * @param host - will be filled with the host part
+ * Note: for multi-homing it wil contain all the addresses
+ * (e.g.: "sctp:(1.2.3.4, 5.6.7.8)" => host="(1.2.3.4,
5.6.7.8)")
+ * @param hlen - will be filled with the length of the host part.
+ * @param port - will be filled with the port if present or 0 if it's not.
+ * @param proto - will be filled with the protocol if present or PROTO_NONE
+ * if it's not.
+ * @return fills proto, port, host and returns 0 on success and -1 on failure.
+ */
+int parse_phostport(char* s, char** host, int* hlen,
int* port, int* proto)
{
char* first; /* first ':' occurrence */
@@ -997,7 +1011,7 @@ struct name_lst* parse_phostport(char* s, char** host, int* hlen,
break;
}
}
- if (p==s) return 0;
+ if (p==s) return -1;
if (*(p-1)==':') goto error_colons;
if (first==0){ /* no ':' => only host */
@@ -1030,22 +1044,48 @@ struct name_lst* parse_phostport(char* s, char** host, int* hlen,
*hlen=(int)(first-*host);
}
end:
- return parse_name_lst(*host, *hlen);
+ return 0;
error_brackets:
LOG(L_ERR, "ERROR: parse_phostport: too many brackets in %s\n", s);
- return 0;
+ return -1;
error_colons:
LOG(L_ERR, "ERROR: parse_phostport: too many colons in %s\n", s);
- return 0;
+ return -1;
error_proto:
LOG(L_ERR, "ERROR: parse_phostport: bad protocol in %s\n", s);
- return 0;
+ return -1;
error_port:
LOG(L_ERR, "ERROR: parse_phostport: bad port number in %s\n", s);
+ return -1;
+}
+
+
+
+/** get protocol host, port and MH addresses list from a string representation.
+ * parses [proto:]host[:port] or
+ * [proto:](host_1, host_2, ... host_n)[:port]
+ * where proto= udp|tcp|tls|sctp
+ * @param s - string (like above)
+ * @param host - will be filled with the host part
+ * Note: for multi-homing it wil contain all the addresses
+ * (e.g.: "sctp:(1.2.3.4, 5.6.7.8)" => host="(1.2.3.4,
5.6.7.8)")
+ * @param hlen - will be filled with the length of the host part.
+ * @param port - will be filled with the port if present or 0 if it's not.
+ * @param proto - will be filled with the protocol if present or PROTO_NONE
+ * if it's not.
+ * @return fills proto, port, host and returns list of addresses on success
+ * (pkg malloc'ed) and 0 on failure
+ */
+static struct name_lst* parse_phostport_mh(char* s, char** host, int* hlen,
+ int* port, int* proto)
+{
+ if (parse_phostport(s, host, hlen, port, proto)==0)
+ return parse_name_lst(*host, *hlen);
return 0;
}
+
/** Update \c cfg_file variable to contain full pathname. The function updates
* the value of \c cfg_file global variable to contain full absolute pathname
* to the main configuration file of SER. The function uses CFG_FILE macro to
@@ -1712,7 +1752,7 @@ try_again:
}
break;
case 'l':
- if ((n_lst=parse_phostport(optarg, &tmp, &tmp_len,
+ if ((n_lst=parse_phostport_mh(optarg, &tmp, &tmp_len,
&port, &proto))==0){
fprintf(stderr, "bad -l address specifier: %s\n",
optarg);
diff --git a/socket_info.h b/socket_info.h
index 4179869..6da9437 100644
--- a/socket_info.h
+++ b/socket_info.h
@@ -97,7 +97,7 @@ struct socket_info* find_si(struct ip_addr* ip, unsigned short port,
struct socket_info** get_sock_info_list(unsigned short proto);
-struct name_lst* parse_phostport(char* s, char** host, int* hlen,
+int parse_phostport(char* s, char** host, int* hlen,
int* port, int* proto);
/* helper function: