diff options
author | Dan Winship <danw@src.gnome.org> | 2002-03-11 08:53:49 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2002-03-11 08:53:49 +0800 |
commit | b1b809031f5a11223d97ee02d21fb6bb3693a367 (patch) | |
tree | 60bdae233e7421dde0564d0296c9767550f372c1 /camel/camel-tcp-stream.c | |
parent | 592ec9daac1b91f89036d2a3598f7f1fa6b6cbaa (diff) | |
download | gsoc2013-evolution-b1b809031f5a11223d97ee02d21fb6bb3693a367.tar.gz gsoc2013-evolution-b1b809031f5a11223d97ee02d21fb6bb3693a367.tar.zst gsoc2013-evolution-b1b809031f5a11223d97ee02d21fb6bb3693a367.zip |
Remove this: it couldn't be generically used, because different subclasses
* camel-tcp-stream.c (camel_tcp_stream_get_socket): Remove this:
it couldn't be generically used, because different subclasses
returned entirely different types of data.
(camel_tcp_stream_get_local_address,
camel_tcp_stream_get_remote_address): Add these to replace what
get_socket was being used for.
(camel_tcp_address_new, camel_tcp_address_free): Utility functions
for get_{local,remote}_address.
* providers/smtp/camel-smtp-transport.c: Change localaddr to a
CamelTcpAddress *.
(connect_to_server): Call camel_tcp_stream_get_local_address to
get the local IP address.
(smtp_disconnect): free localaddr.
(smtp_helo): Update for localaddr change.
* camel-tcp-stream-raw.c (stream_get_socket): Remove
(stream_get_local_address, stream_get_remote_address): Implement.
* camel-tcp-stream-ssl.c (stream_get_socket): Remove
(stream_get_local_address, stream_get_remote_address): Implement.
* camel-tcp-stream-openssl.c (stream_get_socket): Remove
(stream_get_local_address, stream_get_remote_address): Implement.
svn path=/trunk/; revision=16092
Diffstat (limited to 'camel/camel-tcp-stream.c')
-rw-r--r-- | camel/camel-tcp-stream.c | 93 |
1 files changed, 79 insertions, 14 deletions
diff --git a/camel/camel-tcp-stream.c b/camel/camel-tcp-stream.c index 9ab4ba2e63..2155fba6ad 100644 --- a/camel/camel-tcp-stream.c +++ b/camel/camel-tcp-stream.c @@ -36,7 +36,9 @@ static CamelStreamClass *parent_class = NULL; static int tcp_connect (CamelTcpStream *stream, struct hostent *host, int port); static int tcp_getsockopt (CamelTcpStream *stream, CamelSockOptData *data); static int tcp_setsockopt (CamelTcpStream *stream, const CamelSockOptData *data); -static gpointer tcp_get_socket (CamelTcpStream *stream); +static CamelTcpAddress *tcp_get_local_address (CamelTcpStream *stream); +static CamelTcpAddress *tcp_get_remote_address (CamelTcpStream *stream); + static void camel_tcp_stream_class_init (CamelTcpStreamClass *camel_tcp_stream_class) @@ -46,10 +48,11 @@ camel_tcp_stream_class_init (CamelTcpStreamClass *camel_tcp_stream_class) parent_class = CAMEL_STREAM_CLASS (camel_type_get_global_classfuncs (CAMEL_STREAM_TYPE)); /* tcp stream methods */ - camel_tcp_stream_class->connect = tcp_connect; - camel_tcp_stream_class->getsockopt = tcp_getsockopt; - camel_tcp_stream_class->setsockopt = tcp_setsockopt; - camel_tcp_stream_class->get_socket = tcp_get_socket; + camel_tcp_stream_class->connect = tcp_connect; + camel_tcp_stream_class->getsockopt = tcp_getsockopt; + camel_tcp_stream_class->setsockopt = tcp_setsockopt; + camel_tcp_stream_class->get_local_address = tcp_get_local_address; + camel_tcp_stream_class->get_remote_address = tcp_get_remote_address; } static void @@ -156,26 +159,88 @@ camel_tcp_stream_setsockopt (CamelTcpStream *stream, const CamelSockOptData *dat } -static gpointer -tcp_get_socket (CamelTcpStream *stream) +static CamelTcpAddress * +tcp_get_local_address (CamelTcpStream *stream) { - w(g_warning ("CamelTcpStream::get_socket called on default implementation")); + w(g_warning ("CamelTcpStream::get_local_address called on default implementation")); return NULL; } +/** + * camel_tcp_stream_get_local_address: + * @stream: tcp stream object + * + * Get the local address of @stream. + * + * Return value: the stream's local address (which must be freed with + * camel_tcp_address_free()) if the stream is connected, or %NULL if not. + **/ +CamelTcpAddress * +camel_tcp_stream_get_local_address (CamelTcpStream *stream) +{ + g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), NULL); + + return CTS_CLASS (stream)->get_local_address (stream); +} + + +static CamelTcpAddress * +tcp_get_remote_address (CamelTcpStream *stream) +{ + w(g_warning ("CamelTcpStream::get_remote_address called on default implementation")); + return NULL; +} /** - * camel_tcp_stream_get_socket: + * camel_tcp_stream_get_remote_address: * @stream: tcp stream object * - * Get the stream's socket. + * Get the remote address of @stream. * - * Return value: the stream's socket on success or NULL on failure. + * Return value: the stream's remote address (which must be freed with + * camel_tcp_address_free()) if the stream is connected, or %NULL if not. **/ -gpointer -camel_tcp_stream_get_socket (CamelTcpStream *stream) +CamelTcpAddress * +camel_tcp_stream_get_remote_address (CamelTcpStream *stream) { g_return_val_if_fail (CAMEL_IS_TCP_STREAM (stream), NULL); - return CTS_CLASS (stream)->get_socket (stream); + return CTS_CLASS (stream)->get_remote_address (stream); +} + + +/** + * camel_tcp_address_new: + * @family: the address family (currently must be CAMEL_TCP_ADDRESS_IPV4) + * @port: the port number (in network byte order) + * @length: the length of @address + * @address: the address data (family dependent, in network byte order) + * + * Return value: a new CamelTcpAddress. + **/ +CamelTcpAddress * +camel_tcp_address_new (CamelTcpAddressFamily family, gushort port, + gushort length, gpointer address) +{ + CamelTcpAddress *addr; + + addr = g_malloc (sizeof (CamelTcpAddress) + length - 1); + addr->family = family; + addr->port = port; + addr->length = length; + memcpy (&addr->address, address, length); + + return addr; +} + +/** + * camel_tcp_address_free: + * @address: the address + * + * Frees @address. + **/ +void +camel_tcp_address_free (CamelTcpAddress *address) +{ + g_free (address); } |