tport 1.12.10
|
00001 /* 00002 * This file is part of the Sofia-SIP package 00003 * 00004 * Copyright (C) 2005 Nokia Corporation. 00005 * 00006 * Contact: Pekka Pessi <pekka.pessi@nokia-email.address.hidden> 00007 * 00008 * This library is free software; you can redistribute it and/or 00009 * modify it under the terms of the GNU Lesser General Public License 00010 * as published by the Free Software Foundation; either version 2.1 of 00011 * the License, or (at your option) any later version. 00012 * 00013 * This library is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA 00022 * 00023 */ 00024 00025 #ifndef TPORT_H 00026 00027 #define TPORT_H 00028 00036 #ifndef SU_H 00037 #include <sofia-sip/su.h> 00038 #endif 00039 #ifndef SU_WAIT_H 00040 #include <sofia-sip/su_wait.h> 00041 #endif 00042 #ifndef MSG_H 00043 #include <sofia-sip/msg.h> 00044 #endif 00045 #ifndef URL_H 00046 #include <sofia-sip/url.h> 00047 #endif 00048 #ifndef TPORT_TAG_H 00049 #include <sofia-sip/tport_tag.h> 00050 #endif 00051 00052 SOFIA_BEGIN_DECLS 00053 00054 struct tport_s; 00055 #ifndef TPORT_T 00056 #define TPORT_T struct tport_s 00057 typedef TPORT_T tport_t; 00058 #endif 00059 00060 #ifndef TP_STACK_T 00061 #ifndef TP_AGENT_T 00062 #define TP_STACK_T struct tp_stack_s 00063 #else 00064 #define TP_STACK_T TP_AGENT_T 00065 #endif 00066 #endif 00067 00068 typedef TP_STACK_T tp_stack_t; 00069 00070 #ifndef TP_MAGIC_T 00071 00072 #define TP_MAGIC_T struct tp_magic_s 00073 #endif 00074 00075 typedef TP_MAGIC_T tp_magic_t; 00076 00077 #ifndef TP_CLIENT_T 00078 #define TP_CLIENT_T struct tp_client_s 00079 #endif 00080 00084 typedef TP_CLIENT_T tp_client_t; 00085 00086 struct sigcomp_compartment; 00087 struct sigcomp_udvm; 00088 00090 typedef struct { 00091 int tpac_size; 00092 00094 void (*tpac_recv)(tp_stack_t *, tport_t *, msg_t *msg, tp_magic_t *magic, 00095 su_time_t received); 00096 00098 void (*tpac_error)(tp_stack_t *, tport_t *, 00099 int errcode, char const *remote); 00100 00102 msg_t *(*tpac_alloc)(tp_stack_t *, int flags, 00103 char const [], usize_t, 00104 tport_t const *, tp_client_t *); 00105 00107 void (*tpac_address)(tp_stack_t *, tport_t *); 00108 00109 } tport_stack_class_t; 00110 00111 /* Compatibility */ 00112 typedef tport_stack_class_t tp_stack_class_t; 00113 00115 typedef void tport_pending_error_f(tp_stack_t *, tp_client_t *, 00116 tport_t *, msg_t *msg, int error); 00117 00118 enum { 00120 TPORT_QUEUESIZE = 64 00121 }; 00122 00123 00124 /* AI extension flags - these must not overlap with existing AI flags. */ 00125 00127 #define TP_AI_COMPRESSED 0x01000 00128 00129 #define TP_AI_SECURE 0x02000 00130 00132 #define TP_AI_SHUTDOWN 0x04000 00133 00134 #define TP_AI_CLOSE 0x08000 00135 00137 #define TP_AI_ANY 0x80000 00138 00139 #define TP_AI_MASK 0xff000 00140 00142 #define TPORT_HOSTPORTSIZE (55) 00143 00153 typedef struct { 00154 char const *tpn_proto; 00155 char const *tpn_canon; 00156 char const *tpn_host; 00157 char const *tpn_port; 00158 char const *tpn_comp; 00159 char const *tpn_ident; 00160 } tp_name_t; 00161 00162 #define TPN_FORMAT "%s/%s:%s%s%s%s%s" 00163 00164 #define TPN_ARGS(n) \ 00165 (n)->tpn_proto, (n)->tpn_host, (n)->tpn_port, \ 00166 (n)->tpn_comp ? ";comp=" : "", (n)->tpn_comp ? (n)->tpn_comp : "", \ 00167 (n)->tpn_ident ? "/" : "", (n)->tpn_ident ? (n)->tpn_ident : "" 00168 00170 TPORT_DLL tport_t *tport_tcreate(tp_stack_t *stack, 00171 tport_stack_class_t const *tpac, 00172 su_root_t *root, 00173 tag_type_t tag, tag_value_t value, ...); 00174 00176 TPORT_DLL int tport_tbind(tport_t *self, 00177 tp_name_t const *tpn, 00178 char const * const transports[], 00179 tag_type_t tag, tag_value_t value, ...); 00180 00182 TPORT_DLL int tport_get_params(tport_t const *, tag_type_t tag, tag_value_t value, ...); 00183 00185 TPORT_DLL int tport_set_params(tport_t *self, tag_type_t tag, tag_value_t value, ...); 00186 00188 TPORT_DLL void tport_destroy(tport_t *tport); 00189 00191 TPORT_DLL int tport_shutdown(tport_t *tport, int how); 00192 00194 TPORT_DLL tport_t *tport_ref(tport_t *tp); 00195 00197 TPORT_DLL void tport_unref(tport_t *tp); 00198 00200 TPORT_DLL tport_t *tport_incref(tport_t *tp); 00201 00203 TPORT_DLL void tport_decref(tport_t **tp); 00204 00206 TPORT_DLL tport_t *tport_tsend(tport_t *, msg_t *, tp_name_t const *, 00207 tag_type_t, tag_value_t, ...); 00208 00210 TPORT_DLL int tport_tqueue(tport_t *, msg_t *, tag_type_t, tag_value_t, ...); 00211 00213 TPORT_DLL isize_t tport_queuelen(tport_t const *self); 00214 00216 TPORT_DLL int tport_tqsend(tport_t *, msg_t *, msg_t *, 00217 tag_type_t, tag_value_t, ...); 00218 00220 TPORT_DLL int tport_stall(tport_t *self); 00221 00223 TPORT_DLL int tport_continue(tport_t *self); 00224 00226 TPORT_DLL int tport_pend(tport_t *self, msg_t *msg, 00227 tport_pending_error_f *callback, tp_client_t *client); 00228 00230 TPORT_DLL int tport_release(tport_t *self, int pendd, 00231 msg_t *msg, msg_t *reply, tp_client_t *client, 00232 int still_pending); 00233 00235 TPORT_DLL int tport_is_master(tport_t const *self); 00236 00238 TPORT_DLL int tport_is_primary(tport_t const *self); 00239 00241 TPORT_DLL int tport_is_public(tport_t const *self); 00242 00244 TPORT_DLL int tport_is_secondary(tport_t const *self); 00245 00247 TPORT_DLL int tport_is_reliable(tport_t const *tport); 00248 00250 TPORT_DLL int tport_is_stream(tport_t const *tport); 00251 00253 TPORT_DLL int tport_is_dgram(tport_t const *tport); 00254 00256 TPORT_DLL int tport_has_ip4(tport_t const *tport); 00257 00259 TPORT_DLL int tport_has_ip6(tport_t const *tport); 00260 00262 TPORT_DLL int tport_is_udp(tport_t const *self); 00263 00265 TPORT_DLL int tport_is_tcp(tport_t const *self); 00266 00268 TPORT_DLL int tport_has_tls(tport_t const *tport); 00269 00271 TPORT_DLL int tport_is_updating(tport_t const *self); 00272 00274 TPORT_DLL int tport_is_closed(tport_t const *self); 00275 00277 TPORT_DLL int tport_is_shutdown(tport_t const *self); 00278 00280 TPORT_DLL int tport_is_connected(tport_t const *self); 00281 00283 TPORT_DLL int tport_is_clear_to_send(tport_t const *self); 00284 00286 TPORT_DLL void tport_set_magic(tport_t *self, tp_magic_t *magic); 00287 00289 TPORT_DLL tp_magic_t *tport_magic(tport_t const *tport); 00290 00292 TPORT_DLL tp_name_t const *tport_name(tport_t const *tport); 00293 00295 TPORT_DLL su_addrinfo_t const *tport_get_address(tport_t const *tport); 00296 00298 TPORT_DLL char const *tport_ident(tport_t const *self); 00299 00301 TPORT_DLL tport_t *tport_parent(tport_t const *self); 00302 00304 TPORT_DLL int tport_flush(tport_t *); 00305 00307 TPORT_DLL tport_t *tport_primaries(tport_t const *tport); 00308 00310 TPORT_DLL tport_t *tport_next(tport_t const *tport); 00311 00313 TPORT_DLL tport_t *tport_secondary(tport_t const *tport); 00314 00316 TPORT_DLL tport_t *tport_by_protocol(tport_t const *self, char const *proto); 00317 00319 TPORT_DLL tport_t *tport_primary_by_name(tport_t const *self, tp_name_t const *tpn); 00320 00322 TPORT_DLL tport_t *tport_by_name(tport_t const *self, tp_name_t const *); 00323 00325 TPORT_DLL int tport_name_by_url(su_home_t *, tp_name_t *, 00326 url_string_t const *us); 00327 00329 TPORT_DLL tport_t *tport_delivered_by(tport_t const *tp, msg_t const *msg); 00330 00332 TPORT_DLL int tport_delivered_from(tport_t *tp, msg_t const *msg, 00333 tp_name_t name[1]); 00334 00336 TPORT_DLL int tport_name_is_resolved(tp_name_t const *); 00337 00339 TPORT_DLL int tport_name_dup(su_home_t *, 00340 tp_name_t *dst, tp_name_t const *src); 00341 00343 TPORT_DLL int tport_convert_addr(su_home_t *home, 00344 tp_name_t *tpn, 00345 char const *protoname, 00346 char const *canon, 00347 su_sockaddr_t const *su); 00348 00350 TPORT_DLL char *tport_hostport(char buf[], isize_t bufsize, 00351 su_sockaddr_t const *su, int with_port); 00352 00354 TPORT_DLL int tport_keepalive(tport_t *tp, su_addrinfo_t const *ai, 00355 tag_type_t tag, tag_value_t value, ...); 00356 00357 /* ---------------------------------------------------------------------- */ 00358 /* SigComp-related functions */ 00359 00360 #ifndef TPORT_COMPRESSOR 00361 #define TPORT_COMPRESSOR struct tport_compressor 00362 #endif 00363 00364 typedef TPORT_COMPRESSOR tport_compressor_t; 00365 00366 TPORT_DLL int tport_can_send_sigcomp(tport_t const *self); 00367 TPORT_DLL int tport_can_recv_sigcomp(tport_t const *self); 00368 00369 TPORT_DLL int tport_has_compression(tport_t const *self, char const *comp); 00370 TPORT_DLL int tport_set_compression(tport_t *self, char const *comp); 00371 00373 TPORT_DLL 00374 int tport_sigcomp_option(tport_t const *self, 00375 struct sigcomp_compartment *cc, 00376 char const *option); 00377 00379 TPORT_DLL struct sigcomp_compartment * 00380 tport_sigcomp_compartment(tport_t *self, 00381 char const *name, isize_t namelen, 00382 int create_if_needed); 00383 00385 TPORT_DLL int 00386 tport_sigcomp_assign(tport_t *self, struct sigcomp_compartment *); 00387 00389 TPORT_DLL int tport_has_sigcomp_assigned(tport_t const *self); 00390 00392 TPORT_DLL int 00393 tport_sigcomp_accept(tport_t *self, 00394 struct sigcomp_compartment *cc, 00395 msg_t *msg); 00396 00398 TPORT_DLL int 00399 tport_delivered_with_comp(tport_t *tp, msg_t const *msg, 00400 tport_compressor_t **return_compressor); 00401 00403 TPORT_DLL int 00404 tport_sigcomp_close(tport_t *self, 00405 struct sigcomp_compartment *cc, 00406 int how); 00407 00409 TPORT_DLL int 00410 tport_sigcomp_lifetime(tport_t *self, 00411 struct sigcomp_compartment *, 00412 unsigned lifetime_in_ms, 00413 int only_expand); 00414 00415 00416 SOFIA_END_DECLS 00417 00418 #endif /* TPORT_H */