#include <tr.h>
#include <trust_router/trp.h>
#include <tr_util.h>
+#include <tr_inet_util.h>
#if JANSSON_VERSION_HEX < 0x020500
#include "jansson_iterators.h"
TR_GSS_NAMES *names=NULL;
TR_FILTER_SET *filt_set=NULL;
TR_CFG_RC rc=TR_CFG_ERROR;
- TR_NAME *hostname=NULL;
- char *s_hostname=NULL;
+ char *hostname=NULL;
int port;
jhost=json_object_get(jporg, "hostname");
goto cleanup;
}
- if (0 != tr_parse_hostname_and_port(json_string_value(jhost), &hostname, &port)) {
+ /* parse / validate the hostname and port */
+ hostname = tr_parse_host(tmp_ctx, json_string_value(jhost), &port);
+ if (NULL == hostname) {
tr_err("tr_cfg_parse_one_peer_org: error parsing hostname (%s)", json_string_value(jhost));
rc=TR_CFG_NOPARSE;
goto cleanup;
}
- if ((port < 0) || (port > 65535)) {
+ if (port < 0) {
tr_err("tr_cfg_parse_one_peer_org: invalid port (%s)", json_string_value(jhost));
rc=TR_CFG_NOPARSE;
goto cleanup;
port = TRP_PORT;
trp_peer_set_port(new_peer, port);
-
- if (hostname->len == 0) {
- tr_err("tr_cfg_parse_one_peer_org: no hostname specified (%s)", json_string_value(jhost));
- rc=TR_CFG_NOPARSE;
- goto cleanup;
- }
-
- s_hostname = tr_name_strdup(hostname);
- if (s_hostname == NULL) {
- tr_err("tr_cfg_parse_one_peer_org: could not allocate hostname string.");
- rc = TR_CFG_NOMEM;
- goto cleanup;
- }
-
- trp_peer_set_server(new_peer, s_hostname); /* string is strdup'ed in _set_server() */
+ trp_peer_set_server(new_peer, hostname); /* string is strdup'ed in _set_server() */
if (trp_peer_get_server(new_peer) == NULL) {
tr_err("tr_cfg_parse_one_peer: could not set server hostname for new peer");
rc = TR_CFG_NOMEM;
rc=TR_CFG_SUCCESS;
cleanup:
- if (hostname)
- tr_free_name(hostname);
-
- if (s_hostname)
- free(s_hostname);
-
talloc_free(tmp_ctx);
return rc;
}