StreamInterface.h
Go to the documentation of this file.
1// -*- C++ -*-
2// Copyright (c) 2005-2010, Isode Limited, London, England.
3// All rights reserved.
4//
5// Acquisition and use of this software and related materials for any
6// purpose requires a written licence agreement from Isode Limited,
7// or a written licence from an organisation licenced by Isode Limited
8// to grant such a licence.
9
10
11//
12//
14//
16//
17// @VERSION@
18
19#ifndef _STREAMINTERFACE_H_
20#define _STREAMINTERFACE_H_
21
22#include "cdecl.h"
23#include "SSLconfig.h"
24#include <isode/ll/internet.h>
25#include <isode/messages/ioevent.h>
26#include <openssl/x509.h>
27
28// Implementation notes:
29//
30// I could have defined a generic stream, and then subclassed a socket
31// addressed stream. However, most (all?) TCP streams are addressed using
32// sockaddr structures.
33//
34// A signficant question here is; "who owns the read buffers?"
35// Eventually I decided that the Stream User owns any read buffers.
36// This means that the User can, say, incrementally fill its own
37// buffer with fragments as they arrive, rather than having to copy
38// them into an internal buffer.
39
40namespace Stream {
41
42 class User;
43 class Provider;
44
45 // Provider interface
46
48 struct External {
49 endpoint_t fd;
50 bool listen;
51 };
52
54 //
57 const struct sockaddr *daddr;
58 socklen_t dalen;
59 const struct sockaddr *saddr;
60 socklen_t salen;
61 unsigned dscp;
62 };
63
66 const struct sockaddr *laddr;
67 socklen_t lalen;
68 int backlog;
69 // 0 = default
70 };
71
73 //
77 const struct sockaddr *daddr;
78 socklen_t dalen;
79 };
80
82 struct ReadRequest {
83 char *buf;
84 size_t len;
85 bool fill;
86 };
87
89 struct DataRequest {
90 const char *buf;
91 size_t len;
92 };
93
96 MSGstruct reason;
97 };
98
100 struct StartTLS {
101 SSLTLS::Context *context;
102 const char *hostname;
103 bool client;
104 };
105
112
114 enum StreamControlOption option;
115 int value;
117 };
118
120 typedef size_t LengthFnx (const char *buf);
121
125 size_t minlen;
126 };
127
129 class Provider {
130 private:
131 User *user;
132
133 public:
135 Provider () : user(0) {}
136
138 virtual ~Provider () {}
139
141 void SetUser (User *u) { user = u; }
142
144 User *GetUser () { return user; }
145
147 // by child processes and don't shutdown on close
148 virtual endpoint_t GetEndpoint (bool inheriting) = 0;
149
151 virtual unsigned Events () = 0;
152
154 virtual int GetLocalAddress (struct sockaddr *laddr,
155 socklen_t *lalenp,
156 MSGstruct *msp) = 0;
157
159 virtual int GetPeerAddress (struct sockaddr *paddr,
160 socklen_t *palenp,
161 MSGstruct *msp) = 0;
162
164 virtual TLS_CipherSuite GetCipherSuite () {
165 return 0;
166 }
167
169 virtual X509* GetPeerCertificate () {
170 return 0;
171 }
172
174 virtual void Die () = 0;
175
177 // Enables the user to set the FD from some external source
178 virtual void Deliver (External *ext) = 0;
179
181 // Request connection to a peer
182 // The result is signalled using a status indication
183 virtual void Deliver (ConnectRequest *req) = 0;
184
186 // Request listening
187 virtual void Deliver (ListenRequest *req) = 0;
188
190 // Accept a connection
191 virtual void Deliver (ConnectAccept *req) = 0;
192
194 // Disconnect, or refuse an inbound connection
195 virtual void Deliver (DisconnectRequest *req) = 0;
196
198 virtual void Deliver (DataRequest *req) = 0;
199
201 virtual void Deliver (ReadRequest *req) = 0;
202
204 virtual void Deliver (StartTLS *req) = 0;
205
207 virtual void Deliver (StreamControl *option) = 0;
208
210 virtual void Deliver (LengthFnxRequest *req) = 0;
211
213 static EVENTSVC_DLL Provider *ProviderFactory (const char *type, MSGstruct *msp);
214 };
215
216 // User interface
217
220 Provider *listener;
222 // Allocated using 'new'
223 const struct sockaddr *saddr;
224 socklen_t salen;
225 const struct sockaddr *laddr;
226 socklen_t lalen;
227 };
228
231 char *buf;
232 ssize_t len;
233 };
234
236 struct ReleaseBuf {
237 const char *buf;
238 ssize_t len;
239 };
240
243 MSGstruct msg;
245
247
249 };
250
252 class User {
253 private:
254 Provider *provider;
255
256 public:
258 User () : provider(0) {}
259
261
262 virtual ~User () {}
263
265 void SetProvider (Provider *p) { provider = p; }
266
268 Provider *GetProvider () { return provider; }
269
271 virtual void Deliver (ConnectIndication *data) = 0;
272
274 virtual void Deliver (DataIndication *data) = 0;
275
277 virtual void Deliver (ReleaseBuf *release) = 0;
278
280 virtual void Deliver (StatusIndication *error) = 0;
281 };
282
283}
284
285#endif /* __STREAMINTERFACE_H_ */
Class defining an SSL context.
Definition SSLconfig.h:123
Provider of a stream interface.
virtual void Deliver(StreamControl *option)=0
Control stream.
virtual void Deliver(External *ext)=0
Set external.
virtual void Deliver(DisconnectRequest *req)=0
disconnect
virtual void Deliver(LengthFnxRequest *req)=0
Set length function.
Provider()
The user of this provider.
virtual ~Provider()
Destructor should be virtual.
virtual void Die()=0
Go away.
virtual void Deliver(ReadRequest *req)=0
Release read buffer.
User * GetUser()
get the user
virtual void Deliver(ListenRequest *req)=0
listen
virtual int GetLocalAddress(struct sockaddr *laddr, socklen_t *lalenp, MSGstruct *msp)=0
Get the local address.
virtual void Deliver(ConnectAccept *req)=0
accept
virtual void Deliver(StartTLS *req)=0
Start SSL/TLS on stream.
virtual unsigned Events()=0
Get the poller events on the endpoint.
virtual void Deliver(DataRequest *req)=0
send data
virtual void Deliver(ConnectRequest *req)=0
connect
virtual X509 * GetPeerCertificate()
Return the current TLS client certificate, if any.
virtual int GetPeerAddress(struct sockaddr *paddr, socklen_t *palenp, MSGstruct *msp)=0
Get the local address.
static EVENTSVC_DLL Provider * ProviderFactory(const char *type, MSGstruct *msp)
Factory method for Stream provider.
Definition EventSvc.C:153
void SetUser(User *u)
set the user
virtual endpoint_t GetEndpoint(bool inheriting)=0
Get the endpoint ID, if inheriting, set to be inherited.
virtual TLS_CipherSuite GetCipherSuite()
Return the current TLS cipher, if any.
Virtual class defining interface to stream user.
Provider * GetProvider()
Get provider.
virtual ~User()
Destructor should be virtual.
void SetProvider(Provider *p)
Set provider.
User()
The provider used by this User.
virtual void Deliver(ConnectIndication *data)=0
Connection indication.
virtual void Deliver(ReleaseBuf *release)=0
Provider finished with write buffer.
virtual void Deliver(DataIndication *data)=0
Receive data read by provider.
virtual void Deliver(StatusIndication *error)=0
Provider status.
Interface between a user of a stream and the provider of a stream.
StreamControlOption
Control the stream with various options.
@ StreamControlTOS
Keep alive flag.
@ StreamControlKeepAlive
No delay flag.
size_t LengthFnx(const char *buf)
Typedef for datagram length function.
Accept a connection.
socklen_t dalen
Destination address.
Connection indication.
const struct sockaddr * saddr
Pointer to new provider.
Provider * newprovider
Pointer to listening provider.
socklen_t salen
Caller's Source address.
socklen_t lalen
Local address.
const struct sockaddr * laddr
Length of Source address.
Request a connection.
unsigned dscp
Length of Source address.
socklen_t dalen
Destination address.
const struct sockaddr * saddr
Length of destination address.
socklen_t salen
Optional Source address.
Data read from provider.
ssize_t len
Address of data.
Information for sending data.
size_t len
Pointer to data to be transferred.
Disconnect the stream.
Push an external endpoint into the provider.
bool listen
The network endpoint from some external source.
Sets length function.
LengthFnx * fnx
Function which gets length.
size_t minlen
Minimum data length to get length.
socklen_t lalen
Listen address.
int backlog
Length of listen address.
Data read from provider.
bool fill
Length of data read.
size_t len
Address of data.
Release buffer.
ssize_t len
Buffer to be released.
Initiate SSL/TLS on the stream.
const char * hostname
The context for SSL.
bool client
Hostname to check (can be NULL)
StatusIndication()
The provider sending the status.
Provider * provider
Gives details of error.
int value
Option whose value is to be set.

All rights reserved © 2002 - 2024 Isode Ltd.