• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

proxy.h

00001 /*
00002  * $Id$
00003  *
00004  *
00005  * Copyright (C) 2001-2003 FhG Fokus
00006  *
00007  * This file is part of ser, a free SIP server.
00008  *
00009  * ser is free software; you can redistribute it and/or modify
00010  * it under the terms of the GNU General Public License as published by
00011  * the Free Software Foundation; either version 2 of the License, or
00012  * (at your option) any later version
00013  *
00014  * For a license to use the ser software under conditions
00015  * other than those described here, or to purchase support for this
00016  * software, please contact iptel.org by e-mail at the following addresses:
00017  *    info@iptel.org
00018  *
00019  * ser is distributed in the hope that it will be useful,
00020  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00022  * GNU General Public License for more details.
00023  *
00024  * You should have received a copy of the GNU General Public License 
00025  * along with this program; if not, write to the Free Software 
00026  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00027  */
00028  /*
00029   * History:
00030   * -------
00031   *  2003-02-13  added proto to struct proxy_l & to *_proxy functions (andrei)
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; /* original name */
00046         struct hostent host; /* addresses */
00047         unsigned short port;
00048         unsigned short reserved; /*align*/
00049         int proto;
00050         
00051         /* socket ? */
00052 
00053         int addr_idx;   /* crt. addr. idx. */
00054         int ok; /* 0 on error */
00055         /*statistics*/
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 /* returns 0 on success, -1 on error (unknown af/bug) */
00074 inline static int proxy2su(union sockaddr_union* su, struct proxy_l* p)
00075 {
00076         /* if error try next ip address if possible */
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 /* mark as proxy either as ok (err>=0) or as bad (err<0) */
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 

Generated on Tue May 22 2012 13:10:13 for SIP Router by  doxygen 1.7.1