modules/tm/ut.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #ifndef _TM_UT_H
00042 #define _TM_UT_H
00043
00044
00045 #include "../../proxy.h"
00046 #include "../../str.h"
00047 #include "../../parser/parse_uri.h"
00048 #include "../../dprint.h"
00049 #include "../../ut.h"
00050 #include "../../ip_addr.h"
00051 #include "../../error.h"
00052 #include "../../forward.h"
00053 #include "../../mem/mem.h"
00054 #include "../../parser/msg_parser.h"
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065 inline static enum sip_protos get_proto(enum sip_protos force_proto,
00066 enum sip_protos proto)
00067 {
00068
00069 switch(force_proto) {
00070 case PROTO_NONE:
00071 switch(proto) {
00072 case PROTO_NONE:
00073 return PROTO_NONE;
00074 case PROTO_UDP:
00075 #ifdef USE_TCP
00076 case PROTO_TCP:
00077 #endif
00078 #ifdef USE_TLS
00079 case PROTO_TLS:
00080 #endif
00081 #ifdef USE_SCTP
00082 case PROTO_SCTP:
00083 #endif
00084 return proto;
00085 default:
00086 LM_ERR("unsupported transport: %d\n", proto );
00087 return PROTO_NONE;
00088 }
00089 case PROTO_UDP:
00090 #ifdef USE_TCP
00091 case PROTO_TCP:
00092 #endif
00093 #ifdef USE_TLS
00094 case PROTO_TLS:
00095 #endif
00096 #ifdef USE_SCTP
00097 case PROTO_SCTP:
00098 #endif
00099 return force_proto;
00100 default:
00101 LM_ERR("unsupported forced protocol: %d\n", force_proto);
00102 return PROTO_NONE;
00103 }
00104 }
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 inline static struct proxy_l *uri2proxy( str *uri, int forced_proto )
00118 {
00119 struct sip_uri parsed_uri;
00120 struct proxy_l *p;
00121
00122 if (parse_uri(uri->s, uri->len, &parsed_uri) < 0) {
00123 LM_ERR("bad_uri: %.*s\n", uri->len, uri->s );
00124 return 0;
00125 }
00126
00127 if (parsed_uri.type==SIPS_URI_T &&
00128 ((parsed_uri.proto!=PROTO_TLS) && (parsed_uri.proto!=PROTO_NONE)) ) {
00129 LM_ERR("bad transport for sips uri: %d\n", parsed_uri.proto);
00130 return 0;
00131 }
00132 p = mk_proxy( &parsed_uri.host, parsed_uri.port_no,
00133 get_proto(forced_proto, parsed_uri.proto),
00134 (parsed_uri.type==SIPS_URI_T)?1:0 );
00135 if (p == 0) {
00136 LM_ERR("bad host name in URI <%.*s>\n", uri->len, ZSW(uri->s));
00137 return 0;
00138 }
00139
00140 return p;
00141 }
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 static inline int uri2su(str *uri, union sockaddr_union *to_su, int proto)
00153 {
00154 struct proxy_l *proxy;
00155
00156 proxy = uri2proxy(uri, proto);
00157 if (!proxy) {
00158 ser_error = E_BAD_ADDRESS;
00159 LM_ERR("failed create a dst proxy\n");
00160 return -1;
00161 }
00162
00163 hostent2su(to_su, &proxy->host, proxy->addr_idx,
00164 (proxy->port) ? proxy->port : SIP_PORT);
00165 proto = proxy->proto;
00166
00167 free_proxy(proxy);
00168 pkg_free(proxy);
00169 return proto;
00170 }
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184 static inline struct socket_info *uri2sock(struct sip_msg* msg, str *uri,
00185 union sockaddr_union *to_su, int proto)
00186 {
00187 struct socket_info* send_sock;
00188
00189 if ( (proto=uri2su(uri, to_su, proto))==-1 )
00190 return 0;
00191
00192 send_sock = get_send_socket(msg, to_su, proto);
00193 if (!send_sock) {
00194 LM_ERR("no corresponding socket for af %d\n", to_su->s.sa_family);
00195 ser_error = E_NO_SOCKET;
00196 }
00197
00198 return send_sock;
00199 }
00200
00201
00202 #endif