[libsoup/wip/remove-deprecations: 42/49] Delete SoupAddress
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/wip/remove-deprecations: 42/49] Delete SoupAddress
- Date: Tue, 30 Jun 2020 21:57:49 +0000 (UTC)
commit cc29223ec4691cf3723b6ec9ffc5fea3f47bf822
Author: Patrick Griffis <pgriffis igalia com>
Date: Tue Mar 24 23:05:19 2020 -0700
Delete SoupAddress
docs/reference/libsoup-2.4-sections.txt | 44 --
libsoup/include/soup-installed.h | 1 -
libsoup/meson.build | 2 -
libsoup/soup-address.c | 1297 -------------------------------
libsoup/soup-address.h | 110 ---
libsoup/soup-autocleanups.h | 1 -
libsoup/soup-connection.c | 24 +-
libsoup/soup-message-private.h | 1 -
libsoup/soup-message-server-io.c | 9 +-
libsoup/soup-message.c | 32 -
libsoup/soup-message.h | 3 -
libsoup/soup-misc.h | 2 -
libsoup/soup-server.c | 57 +-
libsoup/soup-session-host.c | 14 +-
libsoup/soup-session-host.h | 2 +-
libsoup/soup-session.c | 56 +-
libsoup/soup-session.h | 5 +-
libsoup/soup-socket-private.h | 4 +-
libsoup/soup-socket-properties.c | 14 +-
libsoup/soup-socket.c | 198 ++---
libsoup/soup-socket.h | 5 +-
libsoup/soup-types.h | 1 -
libsoup/soup.h | 1 -
tests/socket-test.c | 69 +-
24 files changed, 221 insertions(+), 1731 deletions(-)
---
diff --git a/docs/reference/libsoup-2.4-sections.txt b/docs/reference/libsoup-2.4-sections.txt
index d6fbe4a6..2bb28b1d 100644
--- a/docs/reference/libsoup-2.4-sections.txt
+++ b/docs/reference/libsoup-2.4-sections.txt
@@ -14,7 +14,6 @@ soup_message_set_http_version
soup_message_get_http_version
soup_message_get_uri
soup_message_set_uri
-soup_message_get_address
<SUBSECTION>
soup_message_set_status
soup_message_set_status_full
@@ -366,49 +365,6 @@ SOUP_AUTH_DOMAIN_DIGEST_GET_CLASS
SoupAuthDomainDigestClass
</SECTION>
-<SECTION>
-<FILE>soup-address</FILE>
-<TITLE>SoupAddress</TITLE>
-SoupAddress
-SoupAddressFamily
-SOUP_ADDRESS_ANY_PORT
-soup_address_new
-soup_address_new_from_sockaddr
-soup_address_new_any
-<SUBSECTION>
-SoupAddressCallback
-soup_address_resolve_async
-soup_address_resolve_sync
-soup_address_is_resolved
-<SUBSECTION>
-soup_address_get_name
-soup_address_get_sockaddr
-soup_address_get_gsockaddr
-soup_address_get_physical
-soup_address_get_port
-<SUBSECTION>
-soup_address_equal_by_name
-soup_address_hash_by_name
-soup_address_equal_by_ip
-soup_address_hash_by_ip
-<SUBSECTION>
-SOUP_ADDRESS_FAMILY
-SOUP_ADDRESS_NAME
-SOUP_ADDRESS_PHYSICAL
-SOUP_ADDRESS_PORT
-SOUP_ADDRESS_SOCKADDR
-SOUP_ADDRESS_PROTOCOL
-<SUBSECTION Standard>
-SOUP_ADDRESS
-SOUP_IS_ADDRESS
-SOUP_TYPE_ADDRESS
-soup_address_get_type
-SOUP_ADDRESS_CLASS
-SOUP_IS_ADDRESS_CLASS
-SOUP_ADDRESS_GET_CLASS
-SoupAddressClass
-</SECTION>
-
<SECTION>
<FILE>soup-session</FILE>
<TITLE>SoupSession</TITLE>
diff --git a/libsoup/include/soup-installed.h b/libsoup/include/soup-installed.h
index 24bec683..320e056d 100644
--- a/libsoup/include/soup-installed.h
+++ b/libsoup/include/soup-installed.h
@@ -12,7 +12,6 @@ extern "C" {
#define __SOUP_H_INSIDE__
-#include <libsoup/soup-address.h>
#include <libsoup/soup-auth.h>
#include <libsoup/soup-auth-domain.h>
#include <libsoup/soup-auth-domain-basic.h>
diff --git a/libsoup/meson.build b/libsoup/meson.build
index 9b1c6d2f..45926d82 100644
--- a/libsoup/meson.build
+++ b/libsoup/meson.build
@@ -48,7 +48,6 @@ soup_sources = [
'xmlrpc/soup-xmlrpc.c',
- 'soup-address.c',
'soup-body-input-stream.c',
'soup-body-output-stream.c',
'soup-client-input-stream.c',
@@ -158,7 +157,6 @@ soup_introspection_headers = [
'xmlrpc/soup-xmlrpc.h',
- 'soup-address.h',
'soup-autocleanups.h',
'soup-date.h',
diff --git a/libsoup/soup-autocleanups.h b/libsoup/soup-autocleanups.h
index 836a2b3f..14095612 100644
--- a/libsoup/soup-autocleanups.h
+++ b/libsoup/soup-autocleanups.h
@@ -26,7 +26,6 @@
#ifndef __GI_SCANNER__
#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(SoupAddress, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(SoupAuth, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(SoupAuthDomain, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(SoupAuthDomainBasic, g_object_unref)
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 927c545a..82bfae6c 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -390,7 +390,7 @@ soup_connection_connect_async (SoupConnection *conn,
gpointer user_data)
{
SoupConnectionPrivate *priv;
- SoupAddress *remote_addr;
+ GInetSocketAddress *remote_addr;
GTask *task;
g_return_if_fail (SOUP_IS_CONNECTION (conn));
@@ -401,14 +401,14 @@ soup_connection_connect_async (SoupConnection *conn,
/* Set the protocol to ensure correct proxy resolution. */
remote_addr =
- g_object_new (SOUP_TYPE_ADDRESS,
- SOUP_ADDRESS_NAME, priv->remote_uri->host,
- SOUP_ADDRESS_PORT, priv->remote_uri->port,
- SOUP_ADDRESS_PROTOCOL, priv->remote_uri->scheme,
+ g_object_new (G_TYPE_NETWORK_ADDRESS,
+ "hostname", priv->remote_uri->host,
+ "port", priv->remote_uri->port,
+ "scheme", priv->remote_uri->scheme,
NULL);
priv->socket =
- soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS, remote_addr,
+ soup_socket_new (SOUP_SOCKET_REMOTE_CONNECTABLE, remote_addr,
SOUP_SOCKET_SOCKET_PROPERTIES, priv->socket_props,
NULL);
g_object_unref (remote_addr);
@@ -436,7 +436,7 @@ soup_connection_connect_sync (SoupConnection *conn,
GError **error)
{
SoupConnectionPrivate *priv;
- SoupAddress *remote_addr;
+ GNetworkAddress *remote_addr;
g_return_val_if_fail (SOUP_IS_CONNECTION (conn), FALSE);
priv = soup_connection_get_instance_private (conn);
@@ -446,14 +446,14 @@ soup_connection_connect_sync (SoupConnection *conn,
/* Set the protocol to ensure correct proxy resolution. */
remote_addr =
- g_object_new (SOUP_TYPE_ADDRESS,
- SOUP_ADDRESS_NAME, priv->remote_uri->host,
- SOUP_ADDRESS_PORT, priv->remote_uri->port,
- SOUP_ADDRESS_PROTOCOL, priv->remote_uri->scheme,
+ g_object_new (G_TYPE_NETWORK_ADDRESS,
+ "hostname", priv->remote_uri->host,
+ "port", priv->remote_uri->port,
+ "scheme", priv->remote_uri->scheme,
NULL);
priv->socket =
- soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS, remote_addr,
+ soup_socket_new (SOUP_SOCKET_REMOTE_CONNECTABLE, remote_addr,
SOUP_SOCKET_SOCKET_PROPERTIES, priv->socket_props,
SOUP_SOCKET_FLAG_NONBLOCKING, FALSE,
NULL);
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index b8955e52..d5306d29 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -24,7 +24,6 @@ typedef struct {
SoupHTTPVersion http_version, orig_http_version;
SoupURI *uri;
- SoupAddress *addr;
SoupAuth *auth, *proxy_auth;
SoupConnection *connection;
diff --git a/libsoup/soup-message-server-io.c b/libsoup/soup-message-server-io.c
index 196690a7..750843c8 100644
--- a/libsoup/soup-message-server-io.c
+++ b/libsoup/soup-message-server-io.c
@@ -110,15 +110,18 @@ parse_request_headers (SoupMessage *msg, char *headers, guint headers_len,
g_free (url);
} else if (soup_message_get_http_version (msg) == SOUP_HTTP_1_0) {
/* No Host header, no AbsoluteUri */
- SoupAddress *addr = soup_socket_get_local_address (sock);
+ GInetSocketAddress *addr = soup_socket_get_local_address (sock);
+ GInetAddress *inet_addr = g_inet_socket_address_get_address (addr);
+ char *local_hostname = g_inet_address_to_string (inet_addr);
uri = soup_uri_new (NULL);
soup_uri_set_scheme (uri, soup_socket_is_ssl (sock) ?
SOUP_URI_SCHEME_HTTPS :
SOUP_URI_SCHEME_HTTP);
- soup_uri_set_host (uri, soup_address_get_physical (addr));
- soup_uri_set_port (uri, soup_address_get_port (addr));
+ soup_uri_set_host (uri, local_hostname);
+ soup_uri_set_port (uri, g_inet_socket_address_get_port (addr));
soup_uri_set_path (uri, req_path);
+ g_free (local_hostname);
} else
uri = NULL;
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index a36193b2..b85126ea 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -175,7 +175,6 @@ soup_message_finalize (GObject *object)
g_clear_pointer (&priv->uri, soup_uri_free);
g_clear_pointer (&priv->first_party, soup_uri_free);
g_clear_pointer (&priv->site_for_cookies, soup_uri_free);
- g_clear_object (&priv->addr);
g_clear_object (&priv->auth);
g_clear_object (&priv->proxy_auth);
@@ -1668,10 +1667,6 @@ soup_message_set_uri (SoupMessage *msg, SoupURI *uri)
if (priv->uri)
soup_uri_free (priv->uri);
- if (priv->addr) {
- g_object_unref (priv->addr);
- priv->addr = NULL;
- }
priv->uri = soup_uri_copy (uri);
g_object_notify (G_OBJECT (msg), SOUP_MESSAGE_URI);
@@ -1697,33 +1692,6 @@ soup_message_get_uri (SoupMessage *msg)
return priv->uri;
}
-/**
- * soup_message_get_address:
- * @msg: a #SoupMessage
- *
- * Gets the address @msg's URI points to. After first setting the
- * URI on a message, this will be unresolved, although the message's
- * session will resolve it before sending the message.
- *
- * Return value: (transfer none): the address @msg's URI points to
- *
- * Since: 2.26
- **/
-SoupAddress *
-soup_message_get_address (SoupMessage *msg)
-{
- SoupMessagePrivate *priv;
-
- g_return_val_if_fail (SOUP_IS_MESSAGE (msg), NULL);
-
- priv = soup_message_get_instance_private (msg);
- if (!priv->addr) {
- priv->addr = soup_address_new (priv->uri->host,
- priv->uri->port);
- }
- return priv->addr;
-}
-
/**
* soup_message_set_status:
* @msg: a #SoupMessage
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index d0f4acff..e1d4368f 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -120,9 +120,6 @@ SoupURI *soup_message_get_uri (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_4
void soup_message_set_uri (SoupMessage *msg,
SoupURI *uri);
-SOUP_AVAILABLE_IN_2_26
-SoupAddress *soup_message_get_address (SoupMessage *msg);
-
SOUP_AVAILABLE_IN_2_30
SoupURI *soup_message_get_first_party (SoupMessage *msg);
SOUP_AVAILABLE_IN_2_30
diff --git a/libsoup/soup-misc.h b/libsoup/soup-misc.h
index 8aad3bdf..9d25d8c2 100644
--- a/libsoup/soup-misc.h
+++ b/libsoup/soup-misc.h
@@ -89,8 +89,6 @@ guint soup_message_headers_get_ranges_internal (SoupMessageHeaders *hdrs,
SoupRange **ranges,
int *length);
-SoupAddress *soup_address_new_from_gsockaddr (GSocketAddress *addr);
-
gboolean soup_host_matches_host (const gchar *host,
const gchar *compare_with);
diff --git a/libsoup/soup-server.c b/libsoup/soup-server.c
index 34f9cb8d..315e695b 100644
--- a/libsoup/soup-server.c
+++ b/libsoup/soup-server.c
@@ -181,9 +181,6 @@ typedef struct {
char **http_aliases, **https_aliases;
- SoupAddress *legacy_iface;
- int legacy_port;
-
GPtrArray *websocket_extension_types;
gboolean disposed;
@@ -1217,22 +1214,13 @@ soup_server_accept_iostream (SoupServer *server,
GError **error)
{
SoupSocket *sock;
- SoupAddress *local = NULL, *remote = NULL;
-
- if (local_addr)
- local = soup_address_new_from_gsockaddr (local_addr);
- if (remote_addr)
- remote = soup_address_new_from_gsockaddr (remote_addr);
sock = g_initable_new (SOUP_TYPE_SOCKET, NULL, error,
"iostream", stream,
- "local-address", local,
- "remote-address", remote,
+ SOUP_SOCKET_LOCAL_ADDRESS, local_addr,
+ SOUP_SOCKET_REMOTE_CONNECTABLE, remote_addr,
NULL);
- g_clear_object (&local);
- g_clear_object (&remote);
-
if (!sock)
return FALSE;
@@ -1340,12 +1328,15 @@ soup_server_listen_internal (SoupServer *server, SoupSocket *listener,
NULL);
if (!is_listening) {
if (!soup_socket_listen_full (listener, error)) {
- SoupAddress *saddr = soup_socket_get_local_address (listener);
+ GInetSocketAddress *addr = soup_socket_get_local_address (listener);
+ GInetAddress *inet_addr = g_inet_socket_address_get_address (addr);
+ char *local_hostname = g_inet_address_to_string (inet_addr);
g_prefix_error (error,
_("Could not listen on address %s, port %d: "),
- soup_address_get_physical (saddr),
- soup_address_get_port (saddr));
+ local_hostname,
+ g_inet_socket_address_get_port (addr));
+ g_free (local_hostname);
return FALSE;
}
}
@@ -1399,7 +1390,6 @@ soup_server_listen (SoupServer *server, GSocketAddress *address,
{
SoupServerPrivate *priv;
SoupSocket *listener;
- SoupAddress *saddr;
gboolean success;
g_return_val_if_fail (SOUP_IS_SERVER (server), FALSE);
@@ -1409,14 +1399,12 @@ soup_server_listen (SoupServer *server, GSocketAddress *address,
priv = soup_server_get_instance_private (server);
g_return_val_if_fail (priv->disposed == FALSE, FALSE);
- saddr = soup_address_new_from_gsockaddr (address);
- listener = soup_socket_new (SOUP_SOCKET_LOCAL_ADDRESS, saddr,
+ listener = soup_socket_new (SOUP_SOCKET_LOCAL_ADDRESS, address,
SOUP_SOCKET_IPV6_ONLY, TRUE,
NULL);
success = soup_server_listen_internal (server, listener, options, error);
g_object_unref (listener);
- g_object_unref (saddr);
return success;
}
@@ -1449,7 +1437,7 @@ soup_server_listen_ipv4_ipv6 (SoupServer *server,
g_object_unref (addr4);
v4sock = priv->listeners->data;
- v4port = soup_address_get_port (soup_socket_get_local_address (v4sock));
+ v4port = g_inet_socket_address_get_port (soup_socket_get_local_address (v4sock));
} else {
v4sock = NULL;
v4port = port;
@@ -1723,7 +1711,9 @@ soup_server_get_uris (SoupServer *server)
SoupServerPrivate *priv;
GSList *uris, *l;
SoupSocket *listener;
- SoupAddress *addr;
+ GInetSocketAddress *addr;
+ GInetAddress *inet_addr;
+ char *hostname;
SoupURI *uri;
gpointer creds;
@@ -1733,15 +1723,19 @@ soup_server_get_uris (SoupServer *server)
for (l = priv->listeners, uris = NULL; l; l = l->next) {
listener = l->data;
addr = soup_socket_get_local_address (listener);
+ inet_addr = g_inet_socket_address_get_address (addr);
+ hostname = g_inet_address_to_string (inet_addr);
g_object_get (G_OBJECT (listener), SOUP_SOCKET_SSL_CREDENTIALS, &creds, NULL);
uri = soup_uri_new (NULL);
soup_uri_set_scheme (uri, creds ? "https" : "http");
- soup_uri_set_host (uri, soup_address_get_physical (addr));
- soup_uri_set_port (uri, soup_address_get_port (addr));
+ soup_uri_set_host (uri, hostname);
+ soup_uri_set_port (uri, g_inet_socket_address_get_port (addr));
soup_uri_set_path (uri, "/");
uris = g_slist_prepend (uris, uri);
+
+ g_free (hostname);
}
return uris;
@@ -1841,7 +1835,7 @@ soup_client_context_get_remote_address (SoupClientContext *client)
client->remote_addr = client->gsock ?
g_socket_get_remote_address (client->gsock, NULL) :
- soup_address_get_gsockaddr (soup_socket_get_remote_address (client->sock));
+ G_SOCKET_ADDRESS (g_object_ref (soup_socket_get_remote_address (client->sock)));
return client->remote_addr;
}
@@ -1869,7 +1863,7 @@ soup_client_context_get_local_address (SoupClientContext *client)
client->local_addr = client->gsock ?
g_socket_get_local_address (client->gsock, NULL) :
- soup_address_get_gsockaddr (soup_socket_get_local_address (client->sock));
+ G_SOCKET_ADDRESS (g_object_ref (soup_socket_get_local_address (client->sock)));
return client->local_addr;
}
@@ -1902,12 +1896,9 @@ soup_client_context_get_host (SoupClientContext *client)
iaddr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS (addr));
client->remote_ip = g_inet_address_to_string (iaddr);
} else {
- SoupAddress *addr;
-
- G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
- addr = soup_socket_get_remote_address (client->sock);
- G_GNUC_END_IGNORE_DEPRECATIONS;
- client->remote_ip = g_strdup (soup_address_get_physical (addr));
+ GInetSocketAddress *addr = G_INET_SOCKET_ADDRESS (soup_socket_get_remote_address
(client->sock));
+ GInetAddress *inet_addr = g_inet_socket_address_get_address (addr);
+ client->remote_ip = g_inet_address_to_string (inet_addr);
}
return client->remote_ip;
diff --git a/libsoup/soup-session-host.c b/libsoup/soup-session-host.c
index 40c47727..819122e2 100644
--- a/libsoup/soup-session-host.c
+++ b/libsoup/soup-session-host.c
@@ -24,8 +24,8 @@ struct _SoupSessionHost
typedef struct {
GMutex mutex;
- SoupURI *uri;
- SoupAddress *addr;
+ SoupURI *uri;
+ GNetworkAddress *addr;
GSList *connections; /* CONTAINS: SoupConnection */
guint num_conns;
@@ -105,10 +105,10 @@ soup_session_host_new (SoupSession *session,
priv = soup_session_host_get_instance_private (host);
priv->uri = soup_uri_copy_host (uri);
- priv->addr = g_object_new (SOUP_TYPE_ADDRESS,
- SOUP_ADDRESS_NAME, priv->uri->host,
- SOUP_ADDRESS_PORT, priv->uri->port,
- SOUP_ADDRESS_PROTOCOL, priv->uri->scheme,
+ priv->addr = g_object_new (G_TYPE_NETWORK_ADDRESS,
+ "hostname", priv->uri->host,
+ "port", priv->uri->port,
+ "scheme", priv->uri->scheme,
NULL);
priv->keep_alive_src = NULL;
priv->session = session;
@@ -127,7 +127,7 @@ soup_session_host_get_uri (SoupSessionHost *host)
return priv->uri;
}
-SoupAddress *
+GNetworkAddress *
soup_session_host_get_address (SoupSessionHost *host)
{
SoupSessionHostPrivate *priv = soup_session_host_get_instance_private (host);
diff --git a/libsoup/soup-session-host.h b/libsoup/soup-session-host.h
index 10aa43ae..90279ba8 100644
--- a/libsoup/soup-session-host.h
+++ b/libsoup/soup-session-host.h
@@ -18,7 +18,7 @@ SoupSessionHost *soup_session_host_new (SoupSession *se
SoupURI *uri);
SoupURI *soup_session_host_get_uri (SoupSessionHost *host);
-SoupAddress *soup_session_host_get_address (SoupSessionHost *host);
+GNetworkAddress *soup_session_host_get_address (SoupSessionHost *host);
void soup_session_host_add_message (SoupSessionHost *host,
SoupMessage *msg);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index ff9ae87c..53c106dd 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -82,7 +82,7 @@ typedef struct {
gboolean tlsdb_use_default;
guint io_timeout, idle_timeout;
- SoupAddress *local_addr;
+ GInetSocketAddress *local_addr;
GResolver *resolver;
GProxyResolver *proxy_resolver;
@@ -2029,25 +2029,10 @@ soup_session_abort (SoupSession *session)
}
static void
-prefetch_uri (SoupSession *session, SoupURI *uri,
- GCancellable *cancellable,
- SoupAddressCallback callback, gpointer user_data)
+on_prefetch_finish (GObject *source, GAsyncResult *result, gpointer user_data)
{
- SoupSessionPrivate *priv;
- SoupSessionHost *host;
- SoupAddress *addr;
-
- priv = soup_session_get_instance_private (session);
-
- g_mutex_lock (&priv->conn_lock);
- host = get_host_for_uri (session, uri);
- addr = g_object_ref (soup_session_host_get_address (host));
- g_mutex_unlock (&priv->conn_lock);
-
- soup_address_resolve_async (addr,
- priv->async_context,
- cancellable, callback, user_data);
- g_object_unref (addr);
+ GList *addresses = g_resolver_lookup_by_name_finish (G_RESOLVER (source), result, NULL);
+ g_clear_pointer (&addresses, g_resolver_free_addresses);
}
/**
@@ -2055,9 +2040,6 @@ prefetch_uri (SoupSession *session, SoupURI *uri,
* @session: a #SoupSession
* @hostname: a hostname to be resolved
* @cancellable: (allow-none): a #GCancellable object, or %NULL
-* @callback: (scope async) (allow-none): callback to call with the
-* result, or %NULL
-* @user_data: data for @callback
*
* Tells @session that an URI from the given @hostname may be requested
* shortly, and so the session can try to prepare by resolving the
@@ -2065,29 +2047,21 @@ prefetch_uri (SoupSession *session, SoupURI *uri,
* is actually requested.
*
* If @cancellable is non-%NULL, it can be used to cancel the
-* resolution. @callback will still be invoked in this case, with a
-* status of %SOUP_STATUS_CANCELLED.
+* resolution.
*
* Since: 2.38
**/
void
-soup_session_prefetch_dns (SoupSession *session, const char *hostname,
- GCancellable *cancellable,
- SoupAddressCallback callback, gpointer user_data)
+soup_session_prefetch_dns (SoupSession *session,
+ const char *hostname,
+ GCancellable *cancellable)
{
- SoupURI *uri;
-
- g_return_if_fail (SOUP_IS_SESSION (session));
- g_return_if_fail (hostname != NULL);
-
- /* FIXME: Prefetching should work for both HTTP and HTTPS */
- uri = soup_uri_new (NULL);
- soup_uri_set_scheme (uri, SOUP_URI_SCHEME_HTTP);
- soup_uri_set_host (uri, hostname);
- soup_uri_set_path (uri, "");
+ g_return_if_fail (SOUP_IS_SESSION (session));
+ g_return_if_fail (hostname);
- prefetch_uri (session, uri, cancellable, callback, user_data);
- soup_uri_free (uri);
+ GResolver *resolver = g_resolver_get_default ();
+ g_resolver_lookup_by_name_async (resolver, hostname, cancellable, on_prefetch_finish, NULL);
+ g_object_unref (resolver);
}
/**
@@ -3054,7 +3028,7 @@ soup_session_class_init (SoupSessionClass *session_class)
/**
* SoupSession:local-address:
*
- * Sets the #SoupAddress to use for the client side of
+ * Sets the #GInetSocketAddress to use for the client side of
* the connection.
*
* Use this property if you want for instance to bind the
@@ -3067,7 +3041,7 @@ soup_session_class_init (SoupSessionClass *session_class)
g_param_spec_object (SOUP_SESSION_LOCAL_ADDRESS,
"Local address",
"Address of local end of socket",
- SOUP_TYPE_ADDRESS,
+ G_TYPE_INET_SOCKET_ADDRESS,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h
index 4f965e93..1879b36d 100644
--- a/libsoup/soup-session.h
+++ b/libsoup/soup-session.h
@@ -6,7 +6,6 @@
#pragma once
#include "soup-types.h"
-#include "soup-address.h"
#include "soup-message.h"
#include "websocket/soup-websocket-connection.h"
@@ -92,9 +91,7 @@ GInputStream *soup_session_send (SoupSession *session,
SOUP_AVAILABLE_IN_2_38
void soup_session_prefetch_dns (SoupSession *session,
const char *hostname,
- GCancellable *cancellable,
- SoupAddressCallback callback,
- gpointer user_data);
+ GCancellable *cancellable);
SOUP_AVAILABLE_IN_2_38
gboolean soup_session_would_redirect (SoupSession *session,
diff --git a/libsoup/soup-socket-private.h b/libsoup/soup-socket-private.h
index 1d4d6f45..efe9affe 100644
--- a/libsoup/soup-socket-private.h
+++ b/libsoup/soup-socket-private.h
@@ -52,7 +52,7 @@ gboolean soup_socket_listen_full (SoupSocket *sock,
typedef struct {
GProxyResolver *proxy_resolver;
- SoupAddress *local_addr;
+ GInetSocketAddress *local_addr;
GTlsDatabase *tlsdb;
GTlsInteraction *tls_interaction;
@@ -69,7 +69,7 @@ GType soup_socket_properties_get_type (void);
#define SOUP_TYPE_SOCKET_PROPERTIES (soup_socket_properties_get_type ())
SoupSocketProperties *soup_socket_properties_new (GProxyResolver *proxy_resolver,
- SoupAddress *local_addr,
+ GInetSocketAddress *local_addr,
GTlsDatabase *tlsdb,
GTlsInteraction *tls_interaction,
gboolean ssl_strict,
diff --git a/libsoup/soup-socket-properties.c b/libsoup/soup-socket-properties.c
index 38bfea3c..8e132435 100644
--- a/libsoup/soup-socket-properties.c
+++ b/libsoup/soup-socket-properties.c
@@ -11,13 +11,13 @@
#include "soup.h"
SoupSocketProperties *
-soup_socket_properties_new (GProxyResolver *proxy_resolver,
- SoupAddress *local_addr,
- GTlsDatabase *tlsdb,
- GTlsInteraction *tls_interaction,
- gboolean ssl_strict,
- guint io_timeout,
- guint idle_timeout)
+soup_socket_properties_new (GProxyResolver *proxy_resolver,
+ GInetSocketAddress *local_addr,
+ GTlsDatabase *tlsdb,
+ GTlsInteraction *tls_interaction,
+ gboolean ssl_strict,
+ guint io_timeout,
+ guint idle_timeout)
{
SoupSocketProperties *props;
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index 686d8eec..21964efc 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -48,7 +48,8 @@ enum {
PROP_GSOCKET,
PROP_IOSTREAM,
PROP_LOCAL_ADDRESS,
- PROP_REMOTE_ADDRESS,
+ PROP_REMOTE_ADDRESS,
+ PROP_REMOTE_CONNECTABLE,
PROP_NON_BLOCKING,
PROP_IPV6_ONLY,
PROP_IS_SERVER,
@@ -65,7 +66,8 @@ enum {
};
typedef struct {
- SoupAddress *local_addr, *remote_addr;
+ GInetSocketAddress *local_addr, *remote_addr;
+ GSocketConnectable *remote_connectable;
GIOStream *conn, *iostream;
GSocket *gsock;
GInputStream *istream;
@@ -87,7 +89,7 @@ typedef struct {
GSource *watch_src;
GSource *read_src, *write_src;
- GMutex iolock, addrlock;
+ GMutex iolock;
guint timeout;
GCancellable *connect_cancel;
@@ -114,7 +116,6 @@ soup_socket_init (SoupSocket *sock)
priv->non_blocking = TRUE;
priv->fd = -1;
- g_mutex_init (&priv->addrlock);
g_mutex_init (&priv->iolock);
priv->async_context = g_main_context_ref_thread_default ();
@@ -225,6 +226,7 @@ soup_socket_finalize (GObject *object)
g_clear_object (&priv->local_addr);
g_clear_object (&priv->remote_addr);
+ g_clear_object (&priv->remote_connectable);
g_clear_object (&priv->tls_interaction);
g_clear_object (&priv->proxy_resolver);
@@ -237,7 +239,6 @@ soup_socket_finalize (GObject *object)
}
g_clear_pointer (&priv->async_context, g_main_context_unref);
- g_mutex_clear (&priv->addrlock);
g_mutex_clear (&priv->iolock);
G_OBJECT_CLASS (soup_socket_parent_class)->finalize (object);
@@ -288,8 +289,11 @@ soup_socket_set_property (GObject *object, guint prop_id,
case PROP_LOCAL_ADDRESS:
priv->local_addr = g_value_dup_object (value);
break;
- case PROP_REMOTE_ADDRESS:
- priv->remote_addr = g_value_dup_object (value);
+ case PROP_REMOTE_ADDRESS:
+ priv->remote_addr = g_value_dup_object (value);
+ break;
+ case PROP_REMOTE_CONNECTABLE:
+ priv->remote_connectable = g_value_dup_object (value);
break;
case PROP_NON_BLOCKING:
priv->non_blocking = g_value_get_boolean (value);
@@ -358,10 +362,13 @@ soup_socket_get_property (GObject *object, guint prop_id,
g_value_set_int (value, priv->fd);
break;
case PROP_LOCAL_ADDRESS:
- g_value_set_object (value, soup_socket_get_local_address (SOUP_SOCKET (object)));
+ g_value_set_object (value, soup_socket_get_local_address (sock));
break;
- case PROP_REMOTE_ADDRESS:
- g_value_set_object (value, soup_socket_get_remote_address (SOUP_SOCKET (object)));
+ case PROP_REMOTE_ADDRESS:
+ g_value_set_object (value, soup_socket_get_remote_address (sock));
+ break;
+ case PROP_REMOTE_CONNECTABLE:
+ g_value_set_object (value, priv->remote_connectable);
break;
case PROP_NON_BLOCKING:
g_value_set_boolean (value, priv->non_blocking);
@@ -543,7 +550,7 @@ soup_socket_class_init (SoupSocketClass *socket_class)
g_param_spec_object (SOUP_SOCKET_LOCAL_ADDRESS,
"Local address",
"Address of local end of socket",
- SOUP_TYPE_ADDRESS,
+ G_TYPE_INET_SOCKET_ADDRESS,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
@@ -557,7 +564,22 @@ soup_socket_class_init (SoupSocketClass *socket_class)
g_param_spec_object (SOUP_SOCKET_REMOTE_ADDRESS,
"Remote address",
"Address of remote end of socket",
- SOUP_TYPE_ADDRESS,
+ G_TYPE_SOCKET_ADDRESS,
+ G_PARAM_READABLE |
+ G_PARAM_STATIC_STRINGS));
+
+ /**
+ * SOUP_SOCKET_REMOTE_CONNECTABLE:
+ *
+ * Alias for the #SoupSocket:remote-connectable property. (Address
+ * to connect to.)
+ **/
+ g_object_class_install_property (
+ object_class, PROP_REMOTE_CONNECTABLE,
+ g_param_spec_object (SOUP_SOCKET_REMOTE_CONNECTABLE,
+ "Remote address",
+ "Address to connect to",
+ G_TYPE_SOCKET_CONNECTABLE,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS));
/**
@@ -797,6 +819,22 @@ re_emit_socket_client_event (GSocketClient *client,
gpointer user_data)
{
SoupSocket *sock = user_data;
+ SoupSocketPrivate *priv = soup_socket_get_instance_private (sock);
+
+ switch (event) {
+ case G_SOCKET_CLIENT_CONNECTING: {
+ GError *error = NULL;
+ g_clear_object (&priv->remote_addr);
+ priv->remote_addr = G_INET_SOCKET_ADDRESS (g_socket_connection_get_remote_address
(G_SOCKET_CONNECTION (connection), &error));
+ if (error) {
+ g_warning ("Failed to set remote address: %s", error->message);
+ g_error_free (error);
+ }
+ break;
+ }
+ default:
+ break;
+ }
soup_socket_event (sock, event, connection);
}
@@ -848,14 +886,8 @@ new_socket_client (SoupSocket *sock)
g_socket_client_set_enable_proxy (client, FALSE);
if (priv->timeout)
g_socket_client_set_timeout (client, priv->timeout);
-
- if (priv->local_addr) {
- GSocketAddress *addr;
-
- addr = soup_address_get_gsockaddr (priv->local_addr);
- g_socket_client_set_local_address (client, addr);
- g_object_unref (addr);
- }
+ if (priv->local_addr)
+ g_socket_client_set_local_address (client, G_SOCKET_ADDRESS (priv->local_addr));
return client;
}
@@ -899,14 +931,14 @@ soup_socket_connect_async_internal (SoupSocket *sock,
priv = soup_socket_get_instance_private (sock);
g_return_if_fail (!priv->is_server);
g_return_if_fail (priv->gsock == NULL);
- g_return_if_fail (priv->remote_addr != NULL);
+ g_return_if_fail (priv->remote_connectable != NULL);
priv->connect_cancel = cancellable ? g_object_ref (cancellable) : g_cancellable_new ();
task = g_task_new (sock, priv->connect_cancel, callback, user_data);
client = new_socket_client (sock);
g_socket_client_connect_async (client,
- G_SOCKET_CONNECTABLE (priv->remote_addr),
+ G_SOCKET_CONNECTABLE (priv->remote_connectable),
priv->connect_cancel,
async_connected, task);
g_object_unref (client);
@@ -973,7 +1005,7 @@ soup_socket_connect_async (SoupSocket *sock, GCancellable *cancellable,
priv = soup_socket_get_instance_private (sock);
g_return_if_fail (!priv->is_server);
g_return_if_fail (priv->gsock == NULL);
- g_return_if_fail (priv->remote_addr != NULL);
+ g_return_if_fail (priv->remote_connectable != NULL);
sacd = g_slice_new0 (SoupSocketAsyncConnectData);
sacd->sock = g_object_ref (sock);
@@ -998,13 +1030,13 @@ soup_socket_connect_sync_internal (SoupSocket *sock,
priv = soup_socket_get_instance_private (sock);
g_return_val_if_fail (!priv->is_server, SOUP_STATUS_MALFORMED);
g_return_val_if_fail (priv->gsock == NULL, SOUP_STATUS_MALFORMED);
- g_return_val_if_fail (priv->remote_addr != NULL, SOUP_STATUS_MALFORMED);
+ g_return_val_if_fail (priv->remote_connectable != NULL, SOUP_STATUS_MALFORMED);
priv->connect_cancel = cancellable ? g_object_ref (cancellable) : g_cancellable_new ();
client = new_socket_client (sock);
conn = g_socket_client_connect (client,
- G_SOCKET_CONNECTABLE (priv->remote_addr),
+ G_SOCKET_CONNECTABLE (priv->remote_connectable),
priv->connect_cancel, error);
g_object_unref (client);
@@ -1034,7 +1066,7 @@ soup_socket_connect_sync (SoupSocket *sock, GCancellable *cancellable)
priv = soup_socket_get_instance_private (sock);
g_return_val_if_fail (!priv->is_server, SOUP_STATUS_MALFORMED);
g_return_val_if_fail (priv->gsock == NULL, SOUP_STATUS_MALFORMED);
- g_return_val_if_fail (priv->remote_addr != NULL, SOUP_STATUS_MALFORMED);
+ g_return_val_if_fail (priv->remote_connectable != NULL, SOUP_STATUS_MALFORMED);
if (soup_socket_connect_sync_internal (sock, cancellable, &error))
return SOUP_STATUS_OK;
@@ -1086,8 +1118,7 @@ soup_socket_steal_gsocket (SoupSocket *sock)
g_return_val_if_fail (SOUP_IS_SOCKET (sock), NULL);
priv = soup_socket_get_instance_private (sock);
- gsock = priv->gsock;
- priv->gsock = NULL;
+ gsock = g_steal_pointer (&priv->gsock);
g_clear_object (&priv->conn);
g_clear_object (&priv->iostream);
@@ -1216,7 +1247,6 @@ soup_socket_listen_full (SoupSocket *sock,
{
SoupSocketPrivate *priv;
- GSocketAddress *addr;
g_return_val_if_fail (SOUP_IS_SOCKET (sock), FALSE);
priv = soup_socket_get_instance_private (sock);
@@ -1229,10 +1259,9 @@ soup_socket_listen_full (SoupSocket *sock,
* have to make a new addr by calling getsockname(), which
* will have the right port number.
*/
- addr = soup_address_get_gsockaddr (priv->local_addr);
- g_return_val_if_fail (addr != NULL, FALSE);
+ g_return_val_if_fail (priv->local_addr != NULL, FALSE);
- priv->gsock = g_socket_new (g_socket_address_get_family (addr),
+ priv->gsock = g_socket_new (g_socket_address_get_family (G_SOCKET_ADDRESS (priv->local_addr)),
G_SOCKET_TYPE_STREAM,
G_SOCKET_PROTOCOL_DEFAULT,
error);
@@ -1252,24 +1281,20 @@ soup_socket_listen_full (SoupSocket *sock,
#endif
/* Bind */
- if (!g_socket_bind (priv->gsock, addr, TRUE, error))
+ if (!g_socket_bind (priv->gsock, G_SOCKET_ADDRESS (priv->local_addr), TRUE, error))
goto cant_listen;
/* Force local_addr to be re-resolved now */
- g_object_unref (priv->local_addr);
- priv->local_addr = NULL;
+ g_clear_object (&priv->local_addr);
/* Listen */
if (!g_socket_listen (priv->gsock, error))
goto cant_listen;
finish_listener_setup (sock);
-
- g_object_unref (addr);
return TRUE;
cant_listen:
if (priv->conn)
disconnect_internal (sock, TRUE);
- g_object_unref (addr);
return FALSE;
}
@@ -1387,9 +1412,20 @@ gboolean
soup_socket_start_ssl (SoupSocket *sock, GCancellable *cancellable)
{
SoupSocketPrivate *priv = soup_socket_get_instance_private (sock);
-
- return soup_socket_setup_ssl (sock, soup_address_get_name (priv->remote_addr),
- cancellable, NULL);
+ char *hostname = NULL;
+ gboolean ret;
+
+ if (G_IS_NETWORK_ADDRESS (priv->remote_connectable))
+ hostname = g_strdup (g_network_address_get_hostname (G_NETWORK_ADDRESS
(priv->remote_connectable)));
+ else if (G_IS_INET_SOCKET_ADDRESS (priv->remote_connectable)) {
+ GInetAddress *addr = g_inet_socket_address_get_address (G_INET_SOCKET_ADDRESS
(priv->remote_connectable));
+ hostname = g_inet_address_to_string (addr);
+ } else
+ g_assert_not_reached ();
+
+ ret = soup_socket_setup_ssl (sock, hostname, cancellable, NULL);
+ g_free (hostname);
+ return ret;
}
/**
@@ -1580,14 +1616,14 @@ soup_socket_is_connected (SoupSocket *sock)
* soup_socket_get_local_address:
* @sock: a #SoupSocket
*
- * Returns the #SoupAddress corresponding to the local end of @sock.
+ * Returns the #GInetSocketAddress corresponding to the local end of @sock.
*
* Calling this method on an unconnected socket is considered to be
* an error, and produces undefined results.
*
- * Return value: (transfer none): the #SoupAddress
+ * Return value: (transfer none): the #GInetSocketAddress
**/
-SoupAddress *
+GInetSocketAddress *
soup_socket_get_local_address (SoupSocket *sock)
{
SoupSocketPrivate *priv;
@@ -1595,31 +1631,21 @@ soup_socket_get_local_address (SoupSocket *sock)
g_return_val_if_fail (SOUP_IS_SOCKET (sock), NULL);
priv = soup_socket_get_instance_private (sock);
- g_mutex_lock (&priv->addrlock);
if (!priv->local_addr) {
- GSocketAddress *addr;
- struct sockaddr_storage sa;
- gssize sa_len;
GError *error = NULL;
if (priv->gsock == NULL) {
g_warning ("%s: socket not connected", G_STRLOC);
- goto unlock;
+ return NULL;
}
- addr = g_socket_get_local_address (priv->gsock, &error);
- if (addr == NULL) {
+ priv->local_addr = G_INET_SOCKET_ADDRESS (g_socket_get_local_address (priv->gsock, &error));
+ if (priv->local_addr == NULL) {
g_warning ("%s: %s", G_STRLOC, error->message);
g_error_free (error);
- goto unlock;
+ return NULL;
}
- sa_len = g_socket_address_get_native_size (addr);
- g_socket_address_to_native (addr, &sa, sa_len, NULL);
- priv->local_addr = soup_address_new_from_sockaddr ((struct sockaddr *)&sa, sa_len);
- g_object_unref (addr);
}
-unlock:
- g_mutex_unlock (&priv->addrlock);
return priv->local_addr;
}
@@ -1628,14 +1654,14 @@ unlock:
* soup_socket_get_remote_address:
* @sock: a #SoupSocket
*
- * Returns the #SoupAddress corresponding to the remote end of @sock.
+ * Returns the #GInetSocketAddress corresponding to the remote end of @sock.
*
* Calling this method on an unconnected socket is considered to be
* an error, and produces undefined results.
*
- * Return value: (transfer none): the #SoupAddress
+ * Return value: (transfer none): the #GInetSocketAddress
**/
-SoupAddress *
+GInetSocketAddress *
soup_socket_get_remote_address (SoupSocket *sock)
{
SoupSocketPrivate *priv;
@@ -1643,33 +1669,29 @@ soup_socket_get_remote_address (SoupSocket *sock)
g_return_val_if_fail (SOUP_IS_SOCKET (sock), NULL);
priv = soup_socket_get_instance_private (sock);
- g_mutex_lock (&priv->addrlock);
- if (!priv->remote_addr) {
- GSocketAddress *addr;
- struct sockaddr_storage sa;
- gssize sa_len;
- GError *error = NULL;
-
- if (priv->gsock == NULL) {
- g_warning ("%s: socket not connected", G_STRLOC);
- goto unlock;
- }
-
- addr = g_socket_get_remote_address (priv->gsock, &error);
- if (addr == NULL) {
- g_warning ("%s: %s", G_STRLOC, error->message);
- g_error_free (error);
- goto unlock;
- }
- sa_len = g_socket_address_get_native_size (addr);
- g_socket_address_to_native (addr, &sa, sa_len, NULL);
- priv->remote_addr = soup_address_new_from_sockaddr ((struct sockaddr *)&sa, sa_len);
- g_object_unref (addr);
- }
-unlock:
- g_mutex_unlock (&priv->addrlock);
-
- return priv->remote_addr;
+ if (!priv->remote_addr) {
+ GError *error = NULL;
+
+ // We may be conencting to a socket address rather than a network address
+ if (G_IS_INET_SOCKET_ADDRESS (priv->remote_connectable)) {
+ priv->remote_addr = g_object_ref (G_INET_SOCKET_ADDRESS (priv->remote_connectable));
+ return priv->remote_addr;
+ }
+
+ if (priv->gsock == NULL) {
+ g_warning ("%s: socket not connected", G_STRLOC);
+ return NULL;
+ }
+
+ priv->remote_addr = G_INET_SOCKET_ADDRESS (g_socket_get_remote_address (priv->gsock,
&error));
+ if (priv->remote_addr == NULL) {
+ g_warning ("%s: %s", G_STRLOC, error->message);
+ g_error_free (error);
+ return NULL;
+ }
+ }
+
+ return priv->remote_addr;
}
SoupURI *
diff --git a/libsoup/soup-socket.h b/libsoup/soup-socket.h
index 1e70d906..808719de 100644
--- a/libsoup/soup-socket.h
+++ b/libsoup/soup-socket.h
@@ -41,6 +41,7 @@ typedef struct {
#define SOUP_SOCKET_LOCAL_ADDRESS "local-address"
#define SOUP_SOCKET_REMOTE_ADDRESS "remote-address"
+#define SOUP_SOCKET_REMOTE_CONNECTABLE "remote-connectable"
#define SOUP_SOCKET_FLAG_NONBLOCKING "non-blocking"
#define SOUP_SOCKET_IS_SERVER "is-server"
#define SOUP_SOCKET_SSL_CREDENTIALS "ssl-creds"
@@ -92,9 +93,9 @@ SOUP_AVAILABLE_IN_2_4
gboolean soup_socket_is_connected (SoupSocket *sock);
SOUP_AVAILABLE_IN_2_4
-SoupAddress *soup_socket_get_local_address (SoupSocket *sock);
+GInetSocketAddress *soup_socket_get_local_address (SoupSocket *sock);
SOUP_AVAILABLE_IN_2_4
-SoupAddress *soup_socket_get_remote_address (SoupSocket *sock);
+GInetSocketAddress *soup_socket_get_remote_address (SoupSocket *sock);
typedef enum {
SOUP_SOCKET_OK,
diff --git a/libsoup/soup-types.h b/libsoup/soup-types.h
index 754350c6..b489cb5c 100644
--- a/libsoup/soup-types.h
+++ b/libsoup/soup-types.h
@@ -16,7 +16,6 @@ G_BEGIN_DECLS
#define _SOUP_ATOMIC_INTERN_STRING(variable, value) ((const char *)(g_atomic_pointer_get (&(variable)) ?
(variable) : (g_atomic_pointer_set (&(variable), (gpointer)g_intern_static_string (value)), (variable))))
-typedef struct _SoupAddress SoupAddress;
typedef struct _SoupAuth SoupAuth;
typedef struct _SoupAuthDomain SoupAuthDomain;
typedef struct _SoupCookie SoupCookie;
diff --git a/libsoup/soup.h b/libsoup/soup.h
index a41c9c1c..f023565c 100644
--- a/libsoup/soup.h
+++ b/libsoup/soup.h
@@ -12,7 +12,6 @@ extern "C" {
#define __SOUP_H_INSIDE__
-#include "soup-address.h"
#include "auth/soup-auth.h"
#include "auth/soup-auth-domain.h"
#include "auth/soup-auth-domain-basic.h"
diff --git a/tests/socket-test.c b/tests/socket-test.c
index 10229ffc..f4e51d6c 100644
--- a/tests/socket-test.c
+++ b/tests/socket-test.c
@@ -14,27 +14,26 @@
#include <io.h>
#endif
+static void
+assert_host_equals (GInetSocketAddress *addr, const char *host)
+{
+ char *addr_host = g_inet_address_to_string (g_inet_socket_address_get_address (addr));
+ g_assert_cmpstr (addr_host, ==, host);
+ g_free (addr_host);
+}
+
static void
do_unconnected_socket_test (void)
{
- SoupAddress *localhost;
+ GInetSocketAddress *addr;
+ GSocketAddress *localhost;
SoupSocket *sock;
SoupSocket *client;
- SoupAddress *addr;
guint res;
- struct sockaddr_in in_localhost;
g_test_bug ("673083");
- in_localhost.sin_family = AF_INET;
- in_localhost.sin_port = 0;
- in_localhost.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-
- localhost = soup_address_new_from_sockaddr (
- (struct sockaddr *) &in_localhost, sizeof (in_localhost));
- g_assert_true (localhost != NULL);
- res = soup_address_resolve_sync (localhost, NULL);
- g_assert_cmpuint (res, ==, SOUP_STATUS_OK);
+ localhost = g_inet_socket_address_new_from_string ("127.0.0.1", 0);
sock = soup_socket_new (SOUP_SOCKET_LOCAL_ADDRESS, localhost,
NULL);
@@ -42,8 +41,8 @@ do_unconnected_socket_test (void)
addr = soup_socket_get_local_address (sock);
g_assert_true (addr != NULL);
- g_assert_cmpstr (soup_address_get_physical (addr), ==, "127.0.0.1");
- g_assert_cmpuint (soup_address_get_port (addr), ==, 0);
+ assert_host_equals (addr, "127.0.0.1");
+ g_assert_cmpuint (g_inet_socket_address_get_port (addr), ==, 0);
/* fails with ENOTCONN */
g_test_expect_message ("libsoup", G_LOG_LEVEL_WARNING,
@@ -57,11 +56,10 @@ do_unconnected_socket_test (void)
addr = soup_socket_get_local_address (sock);
g_assert_true (addr != NULL);
- g_assert_cmpstr (soup_address_get_physical (addr), ==, "127.0.0.1");
- g_assert_cmpuint (soup_address_get_port (addr), >, 0);
+ assert_host_equals (addr, "127.0.0.1");
+ g_assert_cmpuint (g_inet_socket_address_get_port (addr), >, 0);
- client = soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS,
- soup_socket_get_local_address (sock),
+ client = soup_socket_new (SOUP_SOCKET_REMOTE_CONNECTABLE, soup_socket_get_local_address (sock),
NULL);
res = soup_socket_connect_sync (client, NULL);
g_assert_cmpuint (res, ==, SOUP_STATUS_OK);
@@ -69,12 +67,11 @@ do_unconnected_socket_test (void)
g_assert_true (addr != NULL);
addr = soup_socket_get_remote_address (client);
g_assert_true (addr != NULL);
- g_assert_cmpstr (soup_address_get_physical (addr), ==, "127.0.0.1");
- g_assert_cmpuint (soup_address_get_port (addr), >, 0);
+ assert_host_equals (addr, "127.0.0.1");
+ g_assert_cmpuint (g_inet_socket_address_get_port (addr), >, 0);
g_object_unref (client);
- client = soup_socket_new (SOUP_SOCKET_REMOTE_ADDRESS,
- soup_socket_get_local_address (sock),
+ client = soup_socket_new (SOUP_SOCKET_REMOTE_CONNECTABLE, soup_socket_get_local_address (sock),
NULL);
/* save it for later */
@@ -125,7 +122,7 @@ do_socket_from_fd_client_test (void)
SoupURI *uri;
GSocket *gsock;
SoupSocket *sock;
- SoupAddress *local, *remote;
+ GInetSocketAddress *local, *remote;
GSocketAddress *gaddr;
gboolean is_server;
GError *error = NULL;
@@ -149,7 +146,7 @@ do_socket_from_fd_client_test (void)
g_assert_no_error (error);
sock = g_initable_new (SOUP_TYPE_SOCKET, NULL, &error,
- SOUP_SOCKET_FD, g_socket_get_fd (gsock),
+ SOUP_SOCKET_GSOCKET, gsock,
NULL);
g_assert_no_error (error);
g_assert_nonnull (sock);
@@ -163,10 +160,10 @@ do_socket_from_fd_client_test (void)
g_assert_false (is_server);
g_assert_true (soup_socket_is_connected (sock));
- g_assert_cmpstr (soup_address_get_physical (local), ==, "127.0.0.1");
- g_assert_cmpint (soup_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
- g_assert_cmpstr (soup_address_get_physical (remote), ==, "127.0.0.1");
- g_assert_cmpint (soup_address_get_port (remote), ==, uri->port);
+ assert_host_equals (local, "127.0.0.1");
+ g_assert_cmpint (g_inet_socket_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
+ assert_host_equals (remote, "127.0.0.1");
+ g_assert_cmpint (g_inet_socket_address_get_port (remote), ==, uri->port);
g_object_unref (local);
g_object_unref (remote);
@@ -184,7 +181,7 @@ do_socket_from_fd_server_test (void)
{
GSocket *gsock;
SoupSocket *sock;
- SoupAddress *local;
+ GInetSocketAddress *local;
GSocketAddress *gaddr;
gboolean is_server;
GError *error = NULL;
@@ -220,8 +217,8 @@ do_socket_from_fd_server_test (void)
g_assert_true (is_server);
g_assert_true (soup_socket_is_connected (sock));
- g_assert_cmpstr (soup_address_get_physical (local), ==, "127.0.0.1");
- g_assert_cmpint (soup_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
+ assert_host_equals (local, "127.0.0.1");
+ g_assert_cmpint (g_inet_socket_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
g_object_unref (local);
g_object_unref (gaddr);
@@ -238,7 +235,7 @@ do_socket_from_fd_bad_test (void)
{
GSocket *gsock, *gsock2, *gsockcli;
SoupSocket *sock, *sock2;
- SoupAddress *local, *remote;
+ GInetSocketAddress *local, *remote;
GSocketAddress *gaddr;
gboolean is_server;
int fd;
@@ -322,14 +319,14 @@ do_socket_from_fd_bad_test (void)
/* This is wrong, but can't be helped. */
g_assert_false (is_server);
- g_assert_cmpstr (soup_address_get_physical (local), ==, "127.0.0.1");
- g_assert_cmpint (soup_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
+ assert_host_equals (local, "127.0.0.1");
+ g_assert_cmpint (g_inet_socket_address_get_port (local), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
g_object_unref (gaddr);
gaddr = g_socket_get_local_address (gsockcli, &error);
g_assert_no_error (error);
- g_assert_cmpstr (soup_address_get_physical (remote), ==, "127.0.0.1");
- g_assert_cmpint (soup_address_get_port (remote), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
+ assert_host_equals (remote, "127.0.0.1");
+ g_assert_cmpint (g_inet_socket_address_get_port (remote), ==, g_inet_socket_address_get_port
(G_INET_SOCKET_ADDRESS (gaddr)));
g_object_unref (gaddr);
g_object_unref (local);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]