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 #ifndef proxy_h
00036 #define proxy_h
00037
00038 #include <netdb.h>
00039 #include "ip_addr.h"
00040 #include "str.h"
00041 #include "config.h"
00042
00043 struct proxy_l{
00044 struct proxy_l* next;
00045 str name;
00046 struct hostent host;
00047 unsigned short port;
00048 unsigned short reserved;
00049 int proto;
00050
00051
00052
00053 int addr_idx;
00054 int ok;
00055
00056 int tx;
00057 int tx_bytes;
00058 int errors;
00059 };
00060
00061 extern struct proxy_l* proxies;
00062
00063 struct proxy_l* add_proxy(str* name, unsigned short port, int proto);
00064 struct proxy_l* mk_proxy(str* name, unsigned short port, int proto);
00065 struct proxy_l* mk_shm_proxy(str* name, unsigned short port, int proto);
00066 struct proxy_l* mk_proxy_from_ip(struct ip_addr* ip, unsigned short port,
00067 int proto);
00068 void free_proxy(struct proxy_l* p);
00069 void free_shm_proxy(struct proxy_l* p);
00070
00071
00072
00073
00074 inline static int proxy2su(union sockaddr_union* su, struct proxy_l* p)
00075 {
00076
00077 if (p->ok==0){
00078 if (p->host.h_addr_list[p->addr_idx+1])
00079 p->addr_idx++;
00080 else p->addr_idx=0;
00081 p->ok=1;
00082 }
00083
00084 return hostent2su(su, &p->host, p->addr_idx,
00085 (p->port)?p->port:((p->proto==PROTO_TLS)?SIPS_PORT:SIP_PORT) );
00086 }
00087
00088
00089
00090
00091 inline static void proxy_mark(struct proxy_l* p, int err)
00092 {
00093 if (err<0){
00094 p->errors++;
00095 p->ok=0;
00096 }else{
00097 p->tx++;
00098 }
00099 }
00100
00101
00102
00103 #endif
00104