Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ infinoted_parameter_convert_security_policy
infinoted_parameter_convert_string
infinoted_parameter_convert_string_list
infinoted_parameter_convert_flags
infinoted_parameter_convert_ip_address
<SUBSECTION Standard>
INFINOTED_PARAMETER_TYPED_VALUE_TYPE
infinoted_parameter_typed_value_get_type
Expand Down
3 changes: 3 additions & 0 deletions infinoted/infinoted-0.7.man
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Creates a new self\-signed certificate using the given key
\fB\-p\fR, \fB\-\-port\-number\fR=\fIPORT\fR
The port number to listen on
.TP
\fB\-\-listen\-address\fR=\fIADDRESS\fR
The IP address to listen on
.TP
\fB\-\-security\-policy\fR=\fIno\-tls\fR|allow\-tls|require\-tls
How to decide whether to use TLS
.TP
Expand Down
11 changes: 11 additions & 0 deletions infinoted/infinoted-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ const InfinotedParameterInfo INFINOTED_OPTIONS[] = {
'p',
N_("The TCP port number to listen on."),
N_("PORT")
}, {
"listen-address",
INFINOTED_PARAMETER_STRING,
0,
offsetof(InfinotedOptions, listen_address),
infinoted_parameter_convert_ip_address,
0,
N_("The IP address to listen on."),
N_("ADDRESS"),
}, {
"security-policy",
INFINOTED_PARAMETER_STRING,
Expand Down Expand Up @@ -962,6 +971,7 @@ infinoted_options_new(const gchar* const* config_files,
options->create_key = FALSE;
options->create_certificate = FALSE;
options->port = inf_protocol_get_default_port();
options->listen_address = NULL;
options->security_policy = INF_XMPP_CONNECTION_SECURITY_ONLY_TLS;
options->root_directory =
g_build_filename(g_get_home_dir(), ".infinote", NULL);
Expand Down Expand Up @@ -1003,6 +1013,7 @@ infinoted_options_free(InfinotedOptions* options)
g_free(options->certificate_file);
g_free(options->certificate_chain_file);
g_free(options->root_directory);
inf_ip_address_free(options->listen_address);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would need a NULL check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to malloc(3) free(NULL) does nothing, therefore the check is not strictly required as far as I understand.

Copy link
Copy Markdown
Contributor

@aburgm aburgm May 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is not free, it is inf_ip_address_free, which does not like a NULL argument. Or at least it's not documented to. It uses g_slice_free under the hood, which apparently handles NULL fine, but in general the *_free functions in libinfinity don't.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was told that it is usual for functions that free memory to handle NULL themselves, therefore it might be a good idea to just do the same for the libinfinity free functions if they need it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, but it's more important to stay consistent within this PR. If I'm not mistaken some glib free functions such as g_object_unref don't handle NULL arguments either.

g_strfreev(options->plugins);
g_free(options->password);
#ifdef LIBINFINITY_HAVE_PAM
Expand Down
1 change: 1 addition & 0 deletions infinoted/infinoted-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct _InfinotedOptions {
gboolean create_key;
gboolean create_certificate;
guint port;
InfIpAddress *listen_address;
InfXmppConnectionSecurityPolicy security_policy;
gchar* root_directory;

Expand Down
46 changes: 46 additions & 0 deletions infinoted/infinoted-parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,52 @@ infinoted_parameter_convert_port(gpointer out,
return TRUE;
}

/**
* infinoted_parameter_convert_ip_address:
* @out: (type InfIpAddress**) (out): The pointer to the output #InfIpAddress
* location.
* @in: (type gchar**) (in): The pointer to the input string location.
* @error: Location to store error information, if any, or %NULL.
*
* Converts the string that @in points to to an #InfIpAddress* value. If the
* string can not be converted to an IP address, the functions fails and @error
* is set.
*
* This is a #InfinotedParameterConvertFunc function that can be used for
* fields of type #InfIpAddress*.
*
* Returns: %TRUE on success, or %FALSE otherwise.
*/
gboolean
infinoted_parameter_convert_ip_address(gpointer out,
gpointer in,
GError** error)
{
gchar** in_str;
InfIpAddress** out_val;

in_str = (gchar**) in;
out_val = (InfIpAddress**) out;

InfIpAddress *address = inf_ip_address_new_from_string(*in_str);

if(address == NULL)
{
g_set_error_literal(
error,
infinoted_parameter_error_quark(),
INFINOTED_PARAMETER_ERROR_INVALID_IP_ADDRESS,
_("Invalid IP address")
);

return FALSE;
}

*out_val = address;

return TRUE;
}

/**
* infinoted_parameter_convert_nonnegative:
* @out: (type guint*) (out): The pointer to the output #guint.
Expand Down
15 changes: 12 additions & 3 deletions infinoted/infinoted-parameter.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ struct _InfinotedParameterTypedValue {
* infinoted_parameter_convert_boolean(),
* infinoted_parameter_convert_port(),
* infinoted_parameter_convert_nonnegative(),
* infinoted_parameter_convert_positive(), and
* infinoted_parameter_convert_security_policy().
* infinoted_parameter_convert_positive(),
* infinoted_parameter_convert_security_policy() and
* infinoted_parameter_convert_ip_address().
*
* Returns: %TRUE on success or %FALSE if an error occurred.
*/
Expand Down Expand Up @@ -160,6 +161,8 @@ struct _InfinotedParameterInfo {
* @INFINOTED_PARAMETER_ERROR_INVALID_SECURITY_POLICY: A security policy given
* as a parameter is not valid. The only allowed values are
* &quot;no-tls&quot;, &quot;allow-tls&quot;, and &quot;require-tls&quot;.
* @INFINOTED_PARAMETER_ERROR_INVALID_IP_ADDRESS: The value given as a
* parameter is not a valid IP address.
*
* Specifies the possible error conditions for errors in the
* <literal>INFINOTED_PARAMETER_ERROR</literal> domain. These typically
Expand All @@ -169,7 +172,8 @@ typedef enum _InfinotedParameterError {
INFINOTED_PARAMETER_ERROR_REQUIRED,
INFINOTED_PARAMETER_ERROR_INVALID_NUMBER,
INFINOTED_PARAMETER_ERROR_INVALID_FLAG,
INFINOTED_PARAMETER_ERROR_INVALID_SECURITY_POLICY
INFINOTED_PARAMETER_ERROR_INVALID_SECURITY_POLICY,
INFINOTED_PARAMETER_ERROR_INVALID_IP_ADDRESS
} InfinotedParameterError;

GQuark
Expand Down Expand Up @@ -240,6 +244,11 @@ infinoted_parameter_convert_flags(gpointer out,
const GFlagsValue* values,
GError** error);

gboolean
infinoted_parameter_convert_ip_address(gpointer out,
gpointer in,
GError** error);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this function to show up in the documentation, it would need to be added to docs/reference/libinfinoted-plugin-manager/libinfinoted-plugin-manager-0.7-sections.txt.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, I must have overlooked that. My fault!

G_END_DECLS

#endif /* __INFINOTED_PARAMETER_H__ */
Expand Down
34 changes: 28 additions & 6 deletions infinoted/infinoted-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,18 +249,40 @@ infinoted_run_new(InfinotedStartup* startup,
g_object_unref(xmpp_manager);
#endif

address = inf_ip_address_new_raw6(INFINOTED_RUN_IPV6_ANY_ADDR);
run->xmpp6 = infinoted_run_create_server(run, startup, address, NULL);

local_error = NULL;
run->xmpp4 = infinoted_run_create_server(run, startup, NULL, &local_error);

if(startup->options->listen_address != NULL)
{
/* Use manually specified listen address */
address = inf_ip_address_copy(startup->options->listen_address);

switch(inf_ip_address_get_family(address))
{
case INF_IP_ADDRESS_IPV4:
run->xmpp4 = infinoted_run_create_server(run, startup, address, &local_error);
run->xmpp6 = NULL;
break;
case INF_IP_ADDRESS_IPV6:
run->xmpp4 = NULL;
run->xmpp6 = infinoted_run_create_server(run, startup, address, &local_error);
break;
}
}
else
{
address = inf_ip_address_new_raw6(INFINOTED_RUN_IPV6_ANY_ADDR);

run->xmpp6 = infinoted_run_create_server(run, startup, address, NULL);
run->xmpp4 = infinoted_run_create_server(run, startup, NULL, &local_error);
}

if(run->xmpp4 == NULL)
{
/* Ignore if we have an IPv6 server running */
if(run->xmpp6 != NULL)
{
g_error_free(local_error);
if(local_error != NULL)
g_error_free(local_error);
}
else
{
Expand All @@ -272,7 +294,7 @@ infinoted_run_new(InfinotedStartup* startup,
g_object_unref(run->directory);
g_object_unref(run->io);
g_slice_free(InfinotedRun, run);
return NULL;
run = NULL;
}
}

Expand Down