Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / siproxd / src / siproxd.h
1 /*
2     Copyright (C) 2002-2005  Thomas Ries <tries@gmx.net>
3
4     This file is part of Siproxd.
5     
6     Siproxd is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10     
11     Siproxd is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15     
16     You should have received a copy of the GNU General Public License
17     along with Siproxd; if not, write to the Free Software
18     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
19 */
20
21 /* $Id: siproxd.h,v 1.48 2005/01/08 10:05:13 hb9xar Exp $ */
22
23 #ifdef DMALLOC
24  #include <dmalloc.h>
25 #endif
26
27
28 /*
29  * table to hold the client registrations
30  */
31 struct urlmap_s {
32    int  active;
33    int  expires;
34    osip_uri_t *true_url;        // true URL of UA  (inbound URL)
35    osip_uri_t *masq_url;        // masqueraded URL (outbound URL)
36    osip_uri_t *reg_url;         // registered URL  (masq URL as wished by UA)
37 };
38 /*
39  * the difference between masq_url and reg_url is, 
40  * the reg URL *always* holds the url registered by the UA.
41  * the masq_url may contain a different URL due to an additional
42  * masquerading feature (mask_host, masked_host config options)
43  */
44
45
46 /*
47  * Array of strings - used within configuration store
48  */
49 #define CFG_STRARR_SIZE         128     /* max 128 entries in array */
50 typedef struct {
51    int  used;
52    char *string[CFG_STRARR_SIZE];
53 } stringa_t;
54
55 /*
56  * configuration option table
57  */
58 struct siproxd_config {
59    int debuglevel;
60    int debugport;
61    char *inbound_if;
62    char *outbound_if;
63    int sip_listen_port;
64    int daemonize;
65    int silence_log;
66    int rtp_port_low;
67    int rtp_port_high;
68    int rtp_timeout;
69    int rtp_proxy_enable;
70    char *user;
71    char *chrootjail;
72    char *hosts_allow_reg;
73    char *hosts_allow_sip;
74    char *hosts_deny_sip;
75    char *proxy_auth_realm;
76    char *proxy_auth_passwd;
77    char *proxy_auth_pwfile;
78    stringa_t mask_host;
79    stringa_t masked_host;
80    char *outbound_proxy_host;
81    int  outbound_proxy_port;
82    stringa_t outbound_proxy_domain_name;
83    stringa_t outbound_proxy_domain_host;
84    stringa_t outbound_proxy_domain_port;
85    char *registrationfile;
86    int  log_calls;
87    char *pid_file;
88    int  default_expires;
89 };
90
91 /*
92  * SIP ticket
93  */
94 typedef struct {
95    osip_message_t *sipmsg;      /* SIP */
96    struct sockaddr_in from;     /* received from */
97 #define PROTO_UNKN -1
98 #define PROTO_UDP  1
99 #define PROTO_TCP  2
100    int protocol;                /* received by protocol */
101 #define REQTYP_INCOMING         1
102 #define REQTYP_OUTGOING         2
103 #define RESTYP_INCOMING         3
104 #define RESTYP_OUTGOING         4
105    int direction;               /* direction as determined by proxy */
106 } sip_ticket_t;
107
108
109
110 /*
111  * Function prototypes
112  */
113
114 /*                              function returns STS_* status values     vvv */
115
116 /* sock.c */
117 int sipsock_listen(void);                                               /*X*/
118 int sipsock_wait(void);
119 int sipsock_read(void *buf, size_t bufsize,
120                  struct sockaddr_in *from, int *protocol);
121 int sipsock_send(struct in_addr addr, int port, int protocol,                   /*X*/
122                  char *buffer, int size);
123 int sockbind(struct in_addr ipaddr, int localport, int errflg);
124
125 /* register.c */
126 void register_init(void);
127 void register_shut(void);
128 int  register_client(sip_ticket_t *ticket, int force_lcl_masq);         /*X*/
129 void register_agemap(void);
130 int  register_response(sip_ticket_t *ticket, int flag);                 /*X*/
131
132 /* proxy.c */
133 int proxy_request (sip_ticket_t *ticket);                               /*X*/
134 int proxy_response (sip_ticket_t *ticket);                              /*X*/
135 int proxy_rewrite_invitation_body(osip_message_t *m, int direction,
136                                   struct in_addr *local_ip);            /*X*/
137 int proxy_rewrite_request_uri(osip_message_t *mymsg, int idx);          /*X*/
138
139 /* route_preprocessing.c */
140 int route_preprocess(sip_ticket_t *ticket);                             /*X*/
141 int route_add_recordroute(sip_ticket_t *ticket);                        /*X*/
142 int route_purge_recordroute(sip_ticket_t *ticket);                      /*X*/
143 int route_postprocess(sip_ticket_t *ticket);                            /*X*/
144 int route_determine_nexthop(sip_ticket_t *ticket,
145                             struct in_addr *dest, int *port);           /*X*/
146
147 /* utils.c */
148 int  get_ip_by_host(char *hostname, struct in_addr *addr);              /*X*/
149 void secure_enviroment (void);
150 int  get_ip_by_ifname(char *ifname, struct in_addr *retaddr);           /*X*/
151 char *utils_inet_ntoa(struct in_addr in);
152 int  utils_inet_aton(const char *cp, struct in_addr *inp);
153 void get_local_ip(char *ip, struct in_addr *local_ip);
154
155 /* sip_utils.c */
156 osip_message_t * msg_make_template_reply (sip_ticket_t *ticket, int code);
157 int  check_vialoop (sip_ticket_t *ticket);                              /*X*/
158 int  is_via_local (osip_via_t *via, struct in_addr *local_ip);          /*X*/
159 int  compare_url(osip_uri_t *url1, osip_uri_t *url2);                   /*X*/
160 int  compare_callid(osip_call_id_t *cid1, osip_call_id_t *cid2);        /*X*/
161 int  is_sipuri_local (sip_ticket_t *ticket);                            /*X*/
162 int  check_rewrite_rq_uri (osip_message_t *sip);                        /*X*/
163 int  sip_gen_response(sip_ticket_t *ticket, int code);                  /*X*/
164 #define IF_OUTBOUND 0
165 #define IF_INBOUND  1
166 int  sip_add_myvia (sip_ticket_t *ticket, int interface,
167                     struct in_addr *local_ip);                          /*X*/
168 int  sip_del_myvia (sip_ticket_t *ticket, struct in_addr *local_ip);/*X*/
169 int  sip_rewrite_contact (sip_ticket_t *ticket, int direction,
170                           struct in_addr *local_ip);                    /*X*/
171 int  sip_calculate_branch_id (sip_ticket_t *ticket, char *id);          /*X*/
172 int  sip_find_outbound_proxy(sip_ticket_t *ticket, struct in_addr *addr,
173                              int *port);                                /*X*/
174
175 /* readconf.c */
176 int read_config(char *name, int search);                                /*X*/
177 int make_default_config(void);                                          /*X*/
178
179 /* rtpproxy.c */
180 int  rtpproxy_init( void );                                             /*X*/
181 int  rtp_start_fwd (osip_call_id_t *callid, char *client_id,            /*X*/
182                     int direction, int media_stream_no,
183                     struct in_addr outbound_ipaddr, int *outboundport,
184                     struct in_addr lcl_client_ipaddr, int lcl_clientport);
185 int  rtp_stop_fwd (osip_call_id_t *callid, int direction);              /*X*/
186 void rtpproxy_kill( void );                                             /*X*/
187
188 /* accessctl.c */
189 int  accesslist_check(struct sockaddr_in from);
190
191 /* security.c */
192 int  security_check_raw(char *sip_buffer, int size);                    /*X*/
193 int  security_check_sip(sip_ticket_t *ticket);                          /*X*/
194
195 /* auth.c */
196 int  authenticate_proxy(sip_ticket_t *ticket);                          /*X*/
197 int  auth_include_authrq(sip_ticket_t *ticket);                         /*X*/
198 void CvtHex(char *hash, char *hashstring);
199
200 /* fwapi.c */
201 int fwapi_start_rtp(int rtp_direction,
202                     struct in_addr local_ipaddr, int local_port,
203                     struct in_addr remote_ipaddr, int remote_port);
204 int fwapi_stop_rtp(int rtp_direction,
205                    struct in_addr local_ipaddr, int local_port,
206                    struct in_addr remote_ipaddr, int remote_port);
207
208
209 /*
210  * some constant definitions
211  */
212 #define SIP_PORT        5060    /* default port to listen */
213 #define DEFAULT_MAXFWD  70      /* default Max-Forward count */
214 #define DEFAULT_EXPIRES 3600    /* default Expires timeout */
215
216 #define URLMAP_SIZE     32      /* number of URL mapping table entries  */
217 #define RTPPROXY_SIZE   64      /* number of rtp proxy entries          */
218
219 #define BUFFER_SIZE     8196    /* input buffer for read from socket    */
220 #define RTP_BUFFER_SIZE 512     /* max size of an RTP frame             */
221 #define URL_STRING_SIZE 128     /* max size of an URL/URI string        */
222 #define STATUSCODE_SIZE 5       /* size of string representation of status */
223 #define DNS_CACHE_SIZE  32      /* number of entries in internal DNS cache */
224 #define DNS_MAX_AGE     60      /* maximum age of an cache entry (sec)  */
225 #define IFADR_CACHE_SIZE 32     /* number of entries in internal IFADR cache */
226 #define IFADR_MAX_AGE   5       /* max. age of the IF address cache (sec) */
227 #define IFNAME_SIZE     16      /* max string length of a interface name */
228 #define HOSTNAME_SIZE   64      /* max string length of a hostname      */
229 #define USERNAME_SIZE   64      /* max string length of a username (auth) */
230 #define PASSWORD_SIZE   64      /* max string length of a password (auth) */
231 #define VIA_BRANCH_SIZE 64      /* max string length for via branch param */
232                                 /* scratch buffer for gethostbyname_r() */
233 #if defined(PR_NETDB_BUF_SIZE)
234    #define GETHOSTBYNAME_BUFLEN PR_NETDB_BUF_SIZE 
235 #else
236    #define GETHOSTBYNAME_BUFLEN 1024
237 #endif
238
239 /* constants for security testing */
240 #define SEC_MINLEN      16      /* minimum received length */
241 #define SEC_MAXLINELEN  1024    /* maximum acceptable length of one line
242                                    in the SIP telegram (security check)
243                                    Careful: Proxy-Authorization lines may
244                                    get quite long */
245
246 /* symbols for access control */
247 #define ACCESSCTL_SIP   1       /* for access control - SIP allowed     */
248 #define ACCESSCTL_REG   2       /* --"--              - registr. allowed */
249
250 /* symbolic return stati */
251 #define STS_SUCCESS     0       /* SUCCESS                              */
252 #define STS_TRUE        0       /* TRUE                                 */
253 #define STS_FAILURE     1       /* FAILURE                              */
254 #define STS_FALSE       1       /* FALSE                                */
255 #define STS_NEED_AUTH   1001    /* need authentication                  */
256
257 /* symbolic direction of data */
258 #define DIR_INCOMING    1
259 #define DIR_OUTGOING    2
260
261 /* various */
262 #ifndef satoi
263 #define satoi atoi  /* used in libosips MSG_TEST_CODE macro ... */
264 #endif