seas.h

00001 /* $Id$
00002  *
00003  * Copyright (C) 2006-2007 VozTelecom Sistemas S.L
00004  *
00005  * This file is part of Kamailio, a free SIP server.
00006  *
00007  * Kamailio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 2 of the License, or
00010  * (at your option) any later version
00011  *
00012  * Kamailio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License 
00018  * along with this program; if not, write to the Free Software 
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 #ifndef _SEAS_H
00023 #define _SEAS_H
00024 #include <arpa/inet.h>
00025 
00026 #include "../../str.h"/*str*/
00027 #include "../../ip_addr.h"/*ip_addr*/
00028 #include "../../sr_module.h" /*version,etc*/
00029 #include "../../modules/tm/tm_load.h"/*tm_binds*/
00030 #include "ha.h"
00031 #include "cluster.h"
00032 #define MAX_AS_NR 5
00033 #define MAX_UNC_AS_NR 5
00034 #define MAX_AS_NAME 15
00035 /*#define AF2PF(af)   (((af)==AF_INET)?PF_INET:((af)==AF_INET6)?PF_INET6:(af))*/
00036 #define MAX_AS_PER_CLUSTER 10
00037 
00038 #define HAS_FD 1
00039 #define HAS_NAME 2
00040 
00041 #define MAX_BINDS 10
00042 #define MAX_WHOAMI_LEN 30
00043 
00044 #define AS_BUF_SIZE 4000
00045 
00046 #define ENCODED_MSG_SIZE 3200
00047 
00050 #define E2E_ACK 0x04
00051 #define CANCEL_FOUND 0x08
00052 
00053 #define AS_TYPE 1
00054 #define CLUSTER_TYPE 2
00055 
00058 #define T_REQ_IN 2
00059 #define SL_REQ_IN 3
00060 #define RES_IN 4
00061 #define PING_AC 5
00062 #define BIND_AC 6
00063 #define UNBIND_AC 7
00064 
00067 #define SPIRAL_FLAG 0x00000001
00068 
00069 #define net2hostL(dst,from,index) do{ \
00070    memcpy(&(dst),(from)+(index),4); \
00071    dst=ntohl(dst); \
00072    (index)+=4; \
00073 }while(0);
00074 
00075 
00076 
00077 extern char use_stats;
00078 extern char whoami[];
00079 extern int is_dispatcher;
00080 
00081 extern struct ip_addr *seas_listen_ip;
00082 extern unsigned short seas_listen_port;
00083 
00084 extern int write_pipe;
00085 extern int read_pipe;
00086 extern char seas_sigchld_received;
00087 
00088 extern int jain_ping;
00089 extern int jain_pings_lost;
00090 
00091 extern int servlet_ping;
00092 extern int servlet_pings_lost;
00093 
00094 extern struct as_entry *as_table;
00095 
00096 struct seas_functions{
00097    struct tm_binds tmb;
00098    cmd_function t_check_orig_trans;
00099 };
00100 
00101 /*TODO listen_points should be dynamically allocated ?*/
00102 typedef struct app_server {
00103    int event_fd;
00104    int action_fd;
00105    str name;
00106    pid_t action_pid;
00107    struct socket_info *binds[MAX_BINDS];
00108    char bound_processor[MAX_BINDS];
00109    int num_binds;
00110    str ev_buffer;
00111    str ac_buffer;
00112    struct ha jain_pings;
00113    struct ha servlet_pings;
00114    struct cluster *cluster;
00115 }as_t, *as_p;
00116 
00117 struct cluster{
00118    str name;
00119    int num;
00120    int registered;
00121    str as_names[MAX_AS_PER_CLUSTER];
00122    as_p servers[MAX_AS_PER_CLUSTER];
00123 };
00124 
00133 struct as_entry{
00134    str name;
00135    int type;
00136    int connected;
00137    union{
00138       struct app_server as;
00139       struct cluster cs;
00140    }u;
00141    struct as_entry *next;
00142 };
00143 
00144 
00145 extern struct as_entry *my_as;
00146 extern struct seas_functions seas_f; 
00147 extern struct as_entry *as_list;
00148 
00149 typedef struct as_msg {
00150    struct cell *transaction;
00151    char *msg;
00152    int len;
00153    int type;
00154    int id;
00155    struct as_entry *as;
00156 }as_msg_t,*as_msg_p;
00157 
00158 char get_processor_id(struct receive_info *rcv,as_p as);
00159 void seas_sighandler(int signo);
00160 char* create_as_event_t(struct cell *t,struct sip_msg *msg,char processor_id,int *evt_len,int flags);
00161 char* create_as_event_sl(struct sip_msg *msg,char processor_id,int *evt_len,int flags);
00162 
00163 static inline void print_ip_buf(struct ip_addr* ip, char *where,int len)
00164 {
00165    switch(ip->af){
00166       case AF_INET:
00167          snprintf(where,len,"%d.%d.%d.%d", ip->u.addr[0], ip->u.addr[1], ip->u.addr[2], ip->u.addr[3]);
00168          break;
00169       case AF_INET6:
00170          snprintf(where,len,"%x:%x:%x:%x:%x:%x:%x:%x",htons(ip->u.addr16[0]),htons(ip->u.addr16[1]),htons(ip->u.addr16[2]),
00171                htons(ip->u.addr16[3]), htons(ip->u.addr16[4]), htons(ip->u.addr16[5]), htons(ip->u.addr16[6]),
00172                htons(ip->u.addr16[7]));
00173          break;
00174       default:
00175          break;
00176    }
00177 }
00178 #endif