~ubuntu-branches/ubuntu/utopic/evolution-data-server/utopic-proposed

« back to all changes in this revision

Viewing changes to camel/camel-tcp-stream.h

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-06-13 12:02:14 UTC
  • mfrom: (1.1.116) (1.2.35 sid)
  • Revision ID: package-import@ubuntu.com-20140613120214-1zx93d8jxwt093aw
Tags: 3.12.2-1ubuntu1
* Merge with Debian, remaining changes:
  - debian/control: build depend on hardening-wrapper
  - Add build-depends and pass configure flag to enable Ubuntu Online
    Accounts support.
  - Filter out -Bsymbolic-functions from LDFLAGS (for future people
    wondering about this change, see e.g. BGO #594473 and duplicates).
  - Enable Ubuntu Online Accounts and split it and GOA into a separate
    package

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2
 
/*
3
 
 *  Authors: Jeffrey Stedfast <fejj@ximian.com>
4
 
 *
5
 
 *  Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
6
 
 *
7
 
 * This program is free software; you can redistribute it and/or
8
 
 * modify it under the terms of version 2 of the GNU Lesser General Public
9
 
 * License as published by the Free Software Foundation.
10
 
 *
11
 
 * This program is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Lesser General Public
17
 
 * License along with this program; if not, write to the
18
 
 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19
 
 * Boston, MA 02110-1301, USA.
20
 
 *
21
 
 */
22
 
 
23
 
#if !defined (__CAMEL_H_INSIDE__) && !defined (CAMEL_COMPILATION)
24
 
#error "Only <camel/camel.h> can be included directly."
25
 
#endif
26
 
 
27
 
#ifndef CAMEL_TCP_STREAM_H
28
 
#define CAMEL_TCP_STREAM_H
29
 
 
30
 
#ifndef _WIN32
31
 
#include <sys/types.h>
32
 
#include <sys/socket.h>
33
 
#include <netinet/in.h>
34
 
#include <netinet/tcp.h>
35
 
#include <netdb.h>
36
 
typedef struct linger CamelLinger;
37
 
#else
38
 
typedef struct {
39
 
        gushort l_onoff;
40
 
        gushort l_linger;
41
 
} CamelLinger;
42
 
#define socklen_t int
43
 
struct addrinfo;
44
 
#endif
45
 
#include <unistd.h>
46
 
 
47
 
#include <prio.h>
48
 
 
49
 
#include <camel/camel-stream.h>
50
 
 
51
 
/* Standard GObject macros */
52
 
#define CAMEL_TYPE_TCP_STREAM \
53
 
        (camel_tcp_stream_get_type ())
54
 
#define CAMEL_TCP_STREAM(obj) \
55
 
        (G_TYPE_CHECK_INSTANCE_CAST \
56
 
        ((obj), CAMEL_TYPE_TCP_STREAM, CamelTcpStream))
57
 
#define CAMEL_TCP_STREAM_CLASS(cls) \
58
 
        (G_TYPE_CHECK_CLASS_CAST \
59
 
        ((cls), CAMEL_TYPE_TCP_STREAM, CamelTcpStreamClass))
60
 
#define CAMEL_IS_TCP_STREAM(obj) \
61
 
        (G_TYPE_CHECK_INSTANCE_TYPE \
62
 
        ((obj), CAMEL_TYPE_TCP_STREAM))
63
 
#define CAMEL_IS_TCP_STREAM_CLASS(cls) \
64
 
        (G_TYPE_CHECK_CLASS_TYPE \
65
 
        ((cls), CAMEL_TYPE_TCP_STREAM))
66
 
#define CAMEL_TCP_STREAM_GET_CLASS(obj) \
67
 
        (G_TYPE_INSTANCE_GET_CLASS \
68
 
        ((obj), CAMEL_TYPE_TCP_STREAM, CamelTcpStreamClass))
69
 
 
70
 
G_BEGIN_DECLS
71
 
 
72
 
typedef struct _CamelTcpStream CamelTcpStream;
73
 
typedef struct _CamelTcpStreamClass CamelTcpStreamClass;
74
 
typedef struct _CamelTcpStreamPrivate CamelTcpStreamPrivate;
75
 
 
76
 
typedef enum {
77
 
        CAMEL_SOCKOPT_NONBLOCKING,     /* nonblocking io */
78
 
        CAMEL_SOCKOPT_LINGER,          /* linger on close if data present */
79
 
        CAMEL_SOCKOPT_REUSEADDR,       /* allow local address reuse */
80
 
        CAMEL_SOCKOPT_KEEPALIVE,       /* keep connections alive */
81
 
        CAMEL_SOCKOPT_RECVBUFFERSIZE,  /* receive buffer size */
82
 
        CAMEL_SOCKOPT_SENDBUFFERSIZE,  /* send buffer size */
83
 
 
84
 
        CAMEL_SOCKOPT_IPTIMETOLIVE,    /* time to live */
85
 
        CAMEL_SOCKOPT_IPTYPEOFSERVICE, /* type of service and precedence */
86
 
 
87
 
        CAMEL_SOCKOPT_ADDMEMBER,       /* add an IP group membership */
88
 
        CAMEL_SOCKOPT_DROPMEMBER,      /* drop an IP group membership */
89
 
        CAMEL_SOCKOPT_MCASTINTERFACE,  /* multicast interface address */
90
 
        CAMEL_SOCKOPT_MCASTTIMETOLIVE, /* multicast timetolive */
91
 
        CAMEL_SOCKOPT_MCASTLOOPBACK,   /* multicast loopback */
92
 
 
93
 
        CAMEL_SOCKOPT_NODELAY,         /* don't delay send to coalesce packets */
94
 
        CAMEL_SOCKOPT_MAXSEGMENT,      /* maximum segment size */
95
 
        CAMEL_SOCKOPT_BROADCAST,       /* enable broadcast */
96
 
        CAMEL_SOCKOPT_LAST
97
 
} CamelSockOpt;
98
 
 
99
 
typedef struct _CamelSockOptData {
100
 
        CamelSockOpt option;
101
 
        union {
102
 
                guint       ip_ttl;              /* IP time to live */
103
 
                guint       mcast_ttl;           /* IP multicast time to live */
104
 
                guint       tos;                 /* IP type of service and precedence */
105
 
                gboolean    non_blocking;        /* Non-blocking (network) I/O */
106
 
                gboolean    reuse_addr;          /* Allow local address reuse */
107
 
                gboolean    keep_alive;          /* Keep connections alive */
108
 
                gboolean    mcast_loopback;      /* IP multicast loopback */
109
 
                gboolean    no_delay;            /* Don't delay send to coalesce packets */
110
 
                gboolean    broadcast;           /* Enable broadcast */
111
 
                gsize      max_segment;         /* Maximum segment size */
112
 
                gsize      recv_buffer_size;    /* Receive buffer size */
113
 
                gsize      send_buffer_size;    /* Send buffer size */
114
 
                CamelLinger linger;              /* Time to linger on close if data present */
115
 
        } value;
116
 
} CamelSockOptData;
117
 
 
118
 
struct _CamelTcpStream {
119
 
        CamelStream parent;
120
 
 
121
 
        CamelTcpStreamPrivate *priv;
122
 
};
123
 
 
124
 
struct _CamelTcpStreamClass {
125
 
        CamelStreamClass parent_class;
126
 
 
127
 
        gint            (*connect)              (CamelTcpStream *stream,
128
 
                                                 const gchar *host,
129
 
                                                 const gchar *service,
130
 
                                                 gint fallback_port,
131
 
                                                 GCancellable *cancellable,
132
 
                                                 GError **error);
133
 
        gint            (*getsockopt)           (CamelTcpStream *stream,
134
 
                                                 CamelSockOptData *data);
135
 
        gint            (*setsockopt)           (CamelTcpStream *stream,
136
 
                                                 const CamelSockOptData *data);
137
 
        struct sockaddr *
138
 
                        (*get_local_address)    (CamelTcpStream *stream,
139
 
                                                 socklen_t *len);
140
 
        struct sockaddr *
141
 
                        (*get_remote_address)   (CamelTcpStream *stream,
142
 
                                                 socklen_t *len);
143
 
 
144
 
        PRFileDesc *    (*get_file_desc)        (CamelTcpStream *stream);
145
 
};
146
 
 
147
 
GType           camel_tcp_stream_get_type       (void);
148
 
gint            camel_tcp_stream_connect        (CamelTcpStream *stream,
149
 
                                                 const gchar *host,
150
 
                                                 const gchar *service,
151
 
                                                 gint fallback_port,
152
 
                                                 GCancellable *cancellable,
153
 
                                                 GError **error);
154
 
gint            camel_tcp_stream_getsockopt     (CamelTcpStream *stream,
155
 
                                                 CamelSockOptData *data);
156
 
gint            camel_tcp_stream_setsockopt     (CamelTcpStream *stream,
157
 
                                                 const CamelSockOptData *data);
158
 
PRFileDesc  *   camel_tcp_stream_get_file_desc  (CamelTcpStream *stream);
159
 
 
160
 
/* Note about SOCKS proxies:
161
 
 *
162
 
 * As of 2010/Jun/02, Camel supports SOCKS4 proxies, but not SOCKS4a nor SOCKS5.
163
 
 * This comment leaves the implementation of those proxy types as an exercise
164
 
 * for the reader, with some hints:
165
 
 *
166
 
 * The way SOCKS proxies work right now is that clients of Camel call
167
 
 * camel_session_set_socks_proxy().  Later, users of TCP streams like
168
 
 * the POP/IMAP providers will look at the CamelSession's proxy, and
169
 
 * set it on the CamelTcpStream subclasses that they instantiate.
170
 
 *
171
 
 * Both SOCKS4a and SOCKS5 let you resolve hostnames on the proxy; while
172
 
 * SOCKS5 also has extra features like passing a username/password to the
173
 
 * proxy.  However, Camel's current API does not let us implement those
174
 
 * features.
175
 
 *
176
 
 * You use a CamelTCPStream by essentially doing this:
177
 
 *
178
 
 *   struct addrinfo *ai;
179
 
 *   CamelTcpStream *stream;
180
 
 *   gint result;
181
 
 *
182
 
 *   stream = camel_tcp_stream_{raw/ssl}_new (session, ...);
183
 
 *   camel_tcp_stream_set_socks_proxy (stream, ...);
184
 
 *
185
 
 *   ai = camel_getaddrinfo (host, port, ...);
186
 
 *   result = camel_tcp_stream_connect (stream, ai);
187
 
 *
188
 
 * Since you pass a struct addrinfo directly to camel_tcp_stream_connect(), this means
189
 
 * that the stream expects your hostname to be resolved already.  However, SOCKS4a/SOCKS5
190
 
 * proxies would rather resolve the hostname themselves.
191
 
 *
192
 
 * The solution would be to make camel_tcp_stream_connect() a higher-level API, more or
193
 
 * less like this:
194
 
 *
195
 
 *   gint camel_tcp_stream_connect (stream, host, port);
196
 
 *
197
 
 * Internally it would do camel_getaddrinfo() for the case without SOCKS proxies,
198
 
 * and otherwise have the proxy itself resolve the host.
199
 
 *
200
 
 * Fortunately, it seems that the only callers of CamelTcpStream are *inside* Camel;
201
 
 * Evolution doesn't use this API directly.  So all the changes required to
202
 
 * support SOCKS4a/SOCKS5 proxies should be well-contained within Camel,
203
 
 * with no extra changes required in Evolution.
204
 
 */
205
 
void            camel_tcp_stream_set_socks_proxy (CamelTcpStream *stream,
206
 
                                                 const gchar *socks_host,
207
 
                                                 gint socks_port);
208
 
void            camel_tcp_stream_peek_socks_proxy
209
 
                                                (CamelTcpStream *stream,
210
 
                                                 const gchar **socks_host_ret,
211
 
                                                 gint *socks_port_ret);
212
 
 
213
 
struct sockaddr *
214
 
                camel_tcp_stream_get_local_address
215
 
                                                (CamelTcpStream *stream,
216
 
                                                 socklen_t *len);
217
 
struct sockaddr *
218
 
                camel_tcp_stream_get_remote_address
219
 
                                                (CamelTcpStream *stream,
220
 
                                                 socklen_t *len);
221
 
 
222
 
G_END_DECLS
223
 
 
224
 
#ifdef G_OS_WIN32
225
 
#undef socklen_t
226
 
#endif
227
 
 
228
 
#endif /* CAMEL_TCP_STREAM_H */