tport  1.13.16
tport.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Sofia-SIP package
3  *
4  * Copyright (C) 2005 Nokia Corporation.
5  *
6  * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; either version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24 
25 #ifndef TPORT_H
27 #define TPORT_H
36 #ifndef SU_H
37 #include <sofia-sip/su.h>
38 #endif
39 #ifndef SU_STRLST_H
40 #include <sofia-sip/su_strlst.h>
41 #endif
42 #ifndef SU_WAIT_H
43 #include <sofia-sip/su_wait.h>
44 #endif
45 #ifndef MSG_H
46 #include <sofia-sip/msg.h>
47 #endif
48 #ifndef URL_H
49 #include <sofia-sip/url.h>
50 #endif
51 #ifndef TPORT_TAG_H
52 #include <sofia-sip/tport_tag.h>
53 #endif
54 
55 SOFIA_BEGIN_DECLS
56 
57 struct tport_s;
58 #ifndef TPORT_T
59 #define TPORT_T struct tport_s
60 typedef TPORT_T tport_t;
61 #endif
62 
63 #ifndef TP_STACK_T
64 #ifndef TP_AGENT_T
65 #define TP_STACK_T struct tp_stack_s
66 #else
67 #define TP_STACK_T TP_AGENT_T
68 #endif
69 #endif
71 typedef TP_STACK_T tp_stack_t;
72 
73 #ifndef TP_MAGIC_T
75 #define TP_MAGIC_T struct tp_magic_s
76 #endif
79 
80 #ifndef TP_CLIENT_T
81 #define TP_CLIENT_T struct tp_client_s
82 #endif
87 typedef TP_CLIENT_T tp_client_t;
88 
89 struct sigcomp_compartment;
90 struct sigcomp_udvm;
91 
93 typedef struct {
94  int tpac_size;
95 
97  void (*tpac_recv)(tp_stack_t *, tport_t *, msg_t *msg, tp_magic_t *magic,
98  su_time_t received);
99 
101  void (*tpac_error)(tp_stack_t *, tport_t *,
102  int errcode, char const *remote);
103 
105  msg_t *(*tpac_alloc)(tp_stack_t *, int flags,
106  char const [], usize_t,
107  tport_t const *, tp_client_t *);
108 
110  void (*tpac_address)(tp_stack_t *, tport_t *);
111 
113 
114 /* Compatibility */
116 
119  tport_t *, msg_t *msg, int error);
120 
121 enum {
123  TPORT_QUEUESIZE = 64
124 };
125 
126 
127 /* AI extension flags - these must not overlap with existing AI flags. */
128 
130 #define TP_AI_COMPRESSED 0x01000
132 #define TP_AI_SECURE 0x02000
133 
135 #define TP_AI_SHUTDOWN 0x04000
137 #define TP_AI_CLOSE 0x08000
138 
140 #define TP_AI_ANY 0x80000
141 
142 #define TP_AI_MASK 0xff000
143 
145 #define TPORT_HOSTPORTSIZE (55)
146 
156 typedef struct {
157  char const *tpn_proto;
158  char const *tpn_canon;
159  char const *tpn_host;
160  char const *tpn_port;
161  char const *tpn_comp;
162  char const *tpn_ident;
163 } tp_name_t;
164 
165 #define TPN_FORMAT "%s/%s:%s%s%s%s%s"
166 
167 #define TPN_ARGS(n) \
168  (n)->tpn_proto, (n)->tpn_host, (n)->tpn_port, \
169  (n)->tpn_comp ? ";comp=" : "", (n)->tpn_comp ? (n)->tpn_comp : "", \
170  (n)->tpn_ident ? "/" : "", (n)->tpn_ident ? (n)->tpn_ident : ""
171 
173 TPORT_DLL tport_t *tport_tcreate(tp_stack_t *stack,
174  tport_stack_class_t const *tpac,
175  su_root_t *root,
176  tag_type_t tag, tag_value_t value, ...);
177 
179 TPORT_DLL int tport_tbind(tport_t *self,
180  tp_name_t const *tpn,
181  char const * const transports[],
182  tag_type_t tag, tag_value_t value, ...);
183 
185 TPORT_DLL int tport_get_params(tport_t const *, tag_type_t tag, tag_value_t value, ...);
186 
188 TPORT_DLL int tport_set_params(tport_t *self, tag_type_t tag, tag_value_t value, ...);
189 
191 TPORT_DLL void tport_destroy(tport_t *tport);
192 
194 TPORT_DLL int tport_shutdown(tport_t *tport, int how);
195 
197 TPORT_DLL tport_t *tport_ref(tport_t *tp);
198 
200 TPORT_DLL void tport_unref(tport_t *tp);
201 
203 TPORT_DLL tport_t *tport_incref(tport_t *tp);
204 
206 TPORT_DLL void tport_decref(tport_t **tp);
207 
209 TPORT_DLL tport_t *tport_tsend(tport_t *, msg_t *, tp_name_t const *,
210  tag_type_t, tag_value_t, ...);
211 
213 TPORT_DLL int tport_tqueue(tport_t *, msg_t *, tag_type_t, tag_value_t, ...);
214 
216 TPORT_DLL isize_t tport_queuelen(tport_t const *self);
217 
219 TPORT_DLL int tport_tqsend(tport_t *, msg_t *, msg_t *,
220  tag_type_t, tag_value_t, ...);
221 
223 TPORT_DLL int tport_stall(tport_t *self);
224 
226 TPORT_DLL int tport_continue(tport_t *self);
227 
229 TPORT_DLL int tport_pend(tport_t *self, msg_t *msg,
230  tport_pending_error_f *callback, tp_client_t *client);
231 
233 TPORT_DLL int tport_release(tport_t *self, int pendd,
234  msg_t *msg, msg_t *reply, tp_client_t *client,
235  int still_pending);
236 
238 TPORT_DLL int tport_is_master(tport_t const *self);
239 
241 TPORT_DLL int tport_is_primary(tport_t const *self);
242 
244 TPORT_DLL int tport_is_public(tport_t const *self);
245 
247 TPORT_DLL int tport_is_secondary(tport_t const *self);
248 
250 TPORT_DLL int tport_is_reliable(tport_t const *tport);
251 
253 TPORT_DLL int tport_is_stream(tport_t const *tport);
254 
256 TPORT_DLL int tport_is_dgram(tport_t const *tport);
257 
259 TPORT_DLL int tport_has_ip4(tport_t const *tport);
260 
262 TPORT_DLL int tport_has_ip6(tport_t const *tport);
263 
265 TPORT_DLL int tport_is_udp(tport_t const *self);
266 
268 TPORT_DLL int tport_is_tcp(tport_t const *self);
269 
271 TPORT_DLL int tport_has_tls(tport_t const *tport);
272 
274 TPORT_DLL int tport_is_verified(tport_t const *tport);
275 
277 TPORT_DLL int tport_is_updating(tport_t const *self);
278 
280 TPORT_DLL int tport_is_closed(tport_t const *self);
281 
283 TPORT_DLL int tport_is_shutdown(tport_t const *self);
284 
286 TPORT_DLL int tport_is_connected(tport_t const *self);
287 
289 TPORT_DLL int tport_is_clear_to_send(tport_t const *self);
290 
292 TPORT_DLL void tport_set_magic(tport_t *self, tp_magic_t *magic);
293 
295 TPORT_DLL tp_magic_t *tport_magic(tport_t const *tport);
296 
298 TPORT_DLL tp_name_t const *tport_name(tport_t const *tport);
299 
301 TPORT_DLL su_addrinfo_t const *tport_get_address(tport_t const *tport);
302 
304 TPORT_DLL char const *tport_ident(tport_t const *self);
305 
307 TPORT_DLL tport_t *tport_parent(tport_t const *self);
308 
310 TPORT_DLL int tport_flush(tport_t *);
311 
313 TPORT_DLL tport_t *tport_primaries(tport_t const *tport);
314 
316 TPORT_DLL tport_t *tport_next(tport_t const *tport);
317 
319 TPORT_DLL tport_t *tport_secondary(tport_t const *tport);
320 
322 TPORT_DLL tport_t *tport_by_protocol(tport_t const *self, char const *proto);
323 
325 TPORT_DLL tport_t *tport_primary_by_name(tport_t const *self, tp_name_t const *tpn);
326 
328 TPORT_DLL tport_t *tport_by_name(tport_t const *self, tp_name_t const *);
329 
331 TPORT_DLL int tport_name_by_url(su_home_t *, tp_name_t *,
332  url_string_t const *us);
333 
335 TPORT_DLL tport_t *tport_delivered_by(tport_t const *tp, msg_t const *msg);
336 
338 TPORT_DLL int tport_delivered_from(tport_t *tp, msg_t const *msg,
339  tp_name_t name[1]);
340 
342 TPORT_DLL su_strlst_t const *tport_delivered_from_subjects(tport_t *tp,
343  msg_t const *msg);
344 
346 TPORT_DLL int tport_subject_search(char const *, su_strlst_t const *);
347 
349 TPORT_DLL int tport_name_is_resolved(tp_name_t const *);
350 
352 TPORT_DLL int tport_name_dup(su_home_t *,
353  tp_name_t *dst, tp_name_t const *src);
354 
356 TPORT_DLL int tport_convert_addr(su_home_t *home,
357  tp_name_t *tpn,
358  char const *protoname,
359  char const *canon,
360  su_sockaddr_t const *su);
361 
363 TPORT_DLL char *tport_hostport(char buf[], isize_t bufsize,
364  su_sockaddr_t const *su, int with_port);
365 
367 TPORT_DLL int tport_keepalive(tport_t *tp, su_addrinfo_t const *ai,
368  tag_type_t tag, tag_value_t value, ...);
369 
370 /* ---------------------------------------------------------------------- */
371 /* SigComp-related functions */
372 
373 #ifndef TPORT_COMPRESSOR
374 #define TPORT_COMPRESSOR struct tport_compressor
375 #endif
376 
377 typedef TPORT_COMPRESSOR tport_compressor_t;
378 
379 TPORT_DLL int tport_can_send_sigcomp(tport_t const *self);
380 TPORT_DLL int tport_can_recv_sigcomp(tport_t const *self);
381 
382 TPORT_DLL int tport_has_compression(tport_t const *self, char const *comp);
383 TPORT_DLL int tport_set_compression(tport_t *self, char const *comp);
384 
386 TPORT_DLL
387 int tport_sigcomp_option(tport_t const *self,
388  struct sigcomp_compartment *cc,
389  char const *option);
390 
392 TPORT_DLL struct sigcomp_compartment *
394  char const *name, isize_t namelen,
395  int create_if_needed);
396 
398 TPORT_DLL int
399 tport_sigcomp_assign(tport_t *self, struct sigcomp_compartment *);
400 
402 TPORT_DLL int tport_has_sigcomp_assigned(tport_t const *self);
403 
405 TPORT_DLL int
406 tport_sigcomp_accept(tport_t *self,
407  struct sigcomp_compartment *cc,
408  msg_t *msg);
409 
411 TPORT_DLL int
412 tport_delivered_with_comp(tport_t *tp, msg_t const *msg,
413  tport_compressor_t **return_compressor);
414 
416 TPORT_DLL int
417 tport_sigcomp_close(tport_t *self,
418  struct sigcomp_compartment *cc,
419  int how);
420 
422 TPORT_DLL int
424  struct sigcomp_compartment *,
425  unsigned lifetime_in_ms,
426  int only_expand);
427 
428 
429 SOFIA_END_DECLS
430 
431 #endif /* TPORT_H */
Transport name.
Definition: tport.h:156
char const * tpn_comp
Compression algorithm (NULL if none)
Definition: tport.h:161
char const * tpn_host
Node address in textual format.
Definition: tport.h:159
char const * tpn_ident
Transport identifier (NULL if none)
Definition: tport.h:162
char const * tpn_canon
Node DNS name (if known).
Definition: tport.h:158
char const * tpn_proto
Protocol name ("udp", "tcp", etc.)
Definition: tport.h:157
char const * tpn_port
Port number in textual format.
Definition: tport.h:160
Interface towards stack.
Definition: tport.h:93
struct addrinfo su_addrinfo_t
SU_HOME_T su_home_t
intptr_t tag_value_t
struct tag_type_s const * tag_type_t
struct su_root_t su_root_t
TPORT_DLL int tport_is_connected(tport_t const *self)
Test if transport is connected.
Definition: tport.c:319
@ TPORT_QUEUESIZE
Maximum number of messages in send queue.
Definition: tport.h:123
TPORT_DLL tport_t * tport_by_name(tport_t const *self, tp_name_t const *)
Get a transport corresponding to the name.
Definition: tport.c:4510
TPORT_DLL int tport_sigcomp_accept(tport_t *self, struct sigcomp_compartment *cc, msg_t *msg)
Accept SigComp message.
Definition: tport_sigcomp.c:765
TPORT_DLL tport_t * tport_next(tport_t const *tport)
Get next transport.
Definition: tport.c:4383
TPORT_DLL int tport_sigcomp_lifetime(tport_t *self, struct sigcomp_compartment *, unsigned lifetime_in_ms, int only_expand)
Set SigComp compartment lifetime.
TPORT_DLL int tport_tqsend(tport_t *, msg_t *, msg_t *, tag_type_t, tag_value_t,...)
Send a queued message (and queue another, if required).
Definition: tport.c:3850
TPORT_DLL int tport_stall(tport_t *self)
Stop reading from socket until tport_continue() is called.
Definition: tport.c:2844
TPORT_DLL int tport_name_by_url(su_home_t *, tp_name_t *, url_string_t const *us)
Create a transport name corresponding to the URL.
Definition: tport.c:4721
TPORT_DLL int tport_continue(tport_t *self)
Continue reading from socket.
Definition: tport.c:2850
TPORT_DLL struct sigcomp_compartment * tport_sigcomp_compartment(tport_t *self, char const *name, isize_t namelen, int create_if_needed)
Obtain a SigComp compartment with given name.
TPORT_DLL int tport_is_shutdown(tport_t const *self)
Test if transport has been shut down.
Definition: tport.c:313
TPORT_DLL tp_name_t const * tport_name(tport_t const *tport)
Get transport name.
Definition: tport.c:4420
TPORT_DLL int tport_tbind(tport_t *self, tp_name_t const *tpn, char const *const transports[], tag_type_t tag, tag_value_t value,...)
Bind transports to network.
Definition: tport.c:1493
void tport_pending_error_f(tp_stack_t *, tp_client_t *, tport_t *, msg_t *msg, int error)
Callback to report error by pending requests.
Definition: tport.h:118
TPORT_DLL int tport_is_closed(tport_t const *self)
Test if transport has been closed.
Definition: tport.c:304
TPORT_DLL tport_t * tport_tcreate(tp_stack_t *stack, tport_stack_class_t const *tpac, su_root_t *root, tag_type_t tag, tag_value_t value,...)
Create master transport.
Definition: tport.c:479
TPORT_DLL int tport_release(tport_t *self, int pendd, msg_t *msg, msg_t *reply, tp_client_t *client, int still_pending)
Do not wait for response anymore.
Definition: tport.c:4231
TPORT_DLL int tport_shutdown(tport_t *tport, int how)
Shutdown a transport connection.
Definition: tport.c:2157
TPORT_DLL tp_magic_t * tport_magic(tport_t const *tport)
Get transport magic.
Definition: tport.c:4362
TPORT_DLL int tport_has_compression(tport_t const *self, char const *comp)
Check if transport supports named compression.
Definition: tport_stub_sigcomp.c:140
TPORT_DLL int tport_keepalive(tport_t *tp, su_addrinfo_t const *ai, tag_type_t tag, tag_value_t value,...)
Initialize STUN keepalives.
Definition: tport_stub_stun.c:253
#define TP_MAGIC_T
Type of transport-protocol-specific context.
Definition: tport.h:75
TPORT_DLL int tport_is_tcp(tport_t const *self)
Test if transport is tcp.
Definition: tport.c:225
TPORT_DLL tport_t * tport_primaries(tport_t const *tport)
Get primary transports.
Definition: tport.c:4374
TPORT_DLL int tport_has_ip6(tport_t const *tport)
Return true if transport supports IPv6.
TPORT_DLL tport_t * tport_by_protocol(tport_t const *self, char const *proto)
Get a protocol corresponding to the protocol name.
Definition: tport.c:4432
TP_STACK_T tp_stack_t
Type of stack object.
Definition: tport.h:71
TPORT_DLL su_addrinfo_t const * tport_get_address(tport_t const *tport)
Get transport address list.
Definition: tport.c:4414
TPORT_DLL int tport_delivered_with_comp(tport_t *tp, msg_t const *msg, tport_compressor_t **return_compressor)
Get compressor context with which the request was delivered.
Definition: tport.c:3121
TPORT_DLL int tport_sigcomp_option(tport_t const *self, struct sigcomp_compartment *cc, char const *option)
Set SigComp option.
Definition: tport_stub_sigcomp.c:159
TPORT_DLL int tport_can_recv_sigcomp(tport_t const *self)
Check if transport can receive compressed messages.
Definition: tport_stub_sigcomp.c:118
TPORT_DLL int tport_name_dup(su_home_t *, tp_name_t *dst, tp_name_t const *src)
Duplicate a transport name.
Definition: tport.c:4786
TPORT_DLL int tport_pend(tport_t *self, msg_t *msg, tport_pending_error_f *callback, tp_client_t *client)
Mark message as waiting for a response.
Definition: tport.c:4178
TPORT_DLL tport_t * tport_secondary(tport_t const *tport)
Get secondary transports.
Definition: tport.c:4397
TPORT_DLL isize_t tport_queuelen(tport_t const *self)
Return number of queued messages.
Definition: tport.c:3794
TPORT_DLL int tport_is_clear_to_send(tport_t const *self)
Test if transport can be used to send message.
Definition: tport.c:325
TPORT_DLL int tport_convert_addr(su_home_t *home, tp_name_t *tpn, char const *protoname, char const *canon, su_sockaddr_t const *su)
Convert a socket address to a transport name.
Definition: tport.c:2360
TPORT_DLL char * tport_hostport(char buf[], isize_t bufsize, su_sockaddr_t const *su, int with_port)
Print host and port separated with ':' to a string.
Definition: tport.c:4840
TPORT_DLL void tport_decref(tport_t **tp)
Destroy a transport reference.
Definition: tport.c:1176
TPORT_DLL void tport_destroy(tport_t *tport)
Destroy transport(s).
Definition: tport.c:542
TPORT_DLL tport_t * tport_delivered_by(tport_t const *tp, msg_t const *msg)
Return source transport object for delivered message.
Definition: tport.c:3083
TP_MAGIC_T tp_magic_t
Type of transport-protocol-specific context object.
Definition: tport.h:78
TPORT_DLL int tport_can_send_sigcomp(tport_t const *self)
Check if transport can send compressed messages.
Definition: tport_stub_sigcomp.c:129
TPORT_DLL int tport_set_compression(tport_t *self, char const *comp)
Set the compression protocol as comp.
Definition: tport_stub_sigcomp.c:148
TPORT_DLL int tport_has_ip4(tport_t const *tport)
Return true if transport supports IPv4.
Definition: tport.c:253
TPORT_DLL int tport_has_sigcomp_assigned(tport_t const *self)
Test if a SigComp compartment is assigned to a tport.
Definition: tport_stub_sigcomp.c:214
TPORT_DLL void tport_unref(tport_t *tp)
Destroy reference to a transport object.
Definition: tport.c:1153
TPORT_DLL int tport_sigcomp_assign(tport_t *self, struct sigcomp_compartment *)
Assign a SigComp compartment to a connection-oriented tport.
Definition: tport_sigcomp.c:194
TP_CLIENT_T tp_client_t
Transaction object given as a reference to the transport.
Definition: tport.h:87
TPORT_DLL int tport_delivered_from(tport_t *tp, msg_t const *msg, tp_name_t name[1])
Return source transport name for delivered message.
Definition: tport.c:3093
TPORT_DLL int tport_is_stream(tport_t const *tport)
Return true if transport is a stream (no message boundaries).
Definition: tport.c:207
TPORT_DLL su_strlst_t const * tport_delivered_from_subjects(tport_t *tp, msg_t const *msg)
Return TLS Subjects provided by the source transport.
Definition: tport.c:3109
TPORT_DLL int tport_get_params(tport_t const *, tag_type_t tag, tag_value_t value,...)
Get transport parameters.
Definition: tport.c:1199
TPORT_DLL int tport_is_verified(tport_t const *tport)
Test if transport provided a verified certificate chain (TLS only)
Definition: tport.c:278
TPORT_DLL int tport_is_reliable(tport_t const *tport)
Return true if transport is reliable, false otherwise.
Definition: tport.c:234
TPORT_DLL int tport_is_primary(tport_t const *self)
Return true if transport is primary.
Definition: tport.c:184
TPORT_DLL int tport_is_master(tport_t const *self)
Return true if transport is master.
Definition: tport.c:176
TPORT_DLL int tport_set_params(tport_t *self, tag_type_t tag, tag_value_t value,...)
Set transport parameters.
Definition: tport.c:1262
TPORT_DLL int tport_has_tls(tport_t const *tport)
Test if transport has TLS.
Definition: tport.c:272
TPORT_DLL int tport_is_updating(tport_t const *self)
Return true if transport is being updated.
Definition: tport.c:284
TPORT_DLL int tport_tqueue(tport_t *, msg_t *, tag_type_t, tag_value_t,...)
Queue a message to transport.
Definition: tport.c:3785
TPORT_DLL int tport_subject_search(char const *, su_strlst_t const *)
Check if the given subject string is found in su_strlst_t.
Definition: tport.c:3135
TPORT_DLL int tport_is_secondary(tport_t const *self)
Return true if transport is secondary.
Definition: tport.c:192
TPORT_DLL int tport_flush(tport_t *)
Flush idle connections.
Definition: tport.c:2325
TPORT_DLL tport_t * tport_primary_by_name(tport_t const *self, tp_name_t const *tpn)
Get transport by interface identifier and protocol name.
Definition: tport.c:4444
TPORT_DLL tport_t * tport_ref(tport_t *tp)
Create a new reference to a transport object.
Definition: tport.c:1141
TPORT_DLL char const * tport_ident(tport_t const *self)
Get transport ident.
Definition: tport.c:4426
TPORT_DLL tport_t * tport_incref(tport_t *tp)
Create a new transport reference.
Definition: tport.c:1170
TPORT_DLL void tport_set_magic(tport_t *self, tp_magic_t *magic)
Set transport magic.
Definition: tport.c:4356
TPORT_DLL tport_t * tport_tsend(tport_t *, msg_t *, tp_name_t const *, tag_type_t, tag_value_t,...)
Send a message using transport.
Definition: tport.c:3269
TPORT_DLL int tport_is_dgram(tport_t const *tport)
Return true if transport is dgram-based.
Definition: tport.c:213
TPORT_DLL int tport_is_udp(tport_t const *self)
Test if transport is udp.
Definition: tport.c:219
TPORT_DLL int tport_sigcomp_close(tport_t *self, struct sigcomp_compartment *cc, int how)
Shutdown SigComp compartment.
TPORT_DLL int tport_is_public(tport_t const *self)
Return nonzero if transport is public.
Definition: tport.c:247
TPORT_DLL int tport_name_is_resolved(tp_name_t const *)
Check if transport named is already resolved.
Definition: tport.c:4766
TPORT_DLL tport_t * tport_parent(tport_t const *self)
Get primary transport (or self, if already parent)
Definition: tport.c:4368
Tags for tport module.

Sofia-SIP 1.13.16 - Copyright (C) 2006 Nokia Corporation. All rights reserved. Licensed under the terms of the GNU Lesser General Public License.