Revert "Revert "and added files""
[bcm963xx.git] / userapps / opensource / siproxd / src / custom_fw_module.c
1 /*
2     Copyright (C) 2004-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 /*
22  * This is just an example of how to build your custom
23  * interface between siproxd and your firewall.
24  *
25  * Take this as a starting point for your own code.
26  *
27  * To build siproxd with you own firewall control module:
28  * 1) compile your interface module (e.g. this example code) 
29  *    and make an static library out of it.
30  * 2) configure siproxd with:
31  *    ./configure --with-custom-fwmodule=<path>/<library>.a
32  *    (for example: --with-custom-fwmodule=`pwd`/src/libcustom_fw_module.a)
33  *
34  *
35  * The START_RTP action will be called BEFORE the RTP stream 
36  * actually is started. The STOP_RTP action will be called after
37  * the RTP stream has been stopped.
38  * START_RTP will only be called once for an starting RTP stream,
39  * in case of repetitions (SIP INVITE sequence) it will not
40  * be called multiple times.
41  *
42  * The code here is called synchroneously, means the time you spend
43  * in here doing things, siproxd will not do anything else, so
44  * try to do thins as fast as possible and don't wait for something
45  * to happen.
46  *
47  */
48
49 #include <stdio.h>              /* sprintf */
50 #include <string.h>             /* strcat  */
51
52
53 #include <sys/types.h>
54 #include <netinet/in.h>
55 #include "fwapi.h"
56 #include "log.h"
57
58 static char const ident[]="$Id: custom_fw_module.c,v 1.6 2005/01/08 10:05:12 hb9xar Exp $";
59
60 /*
61  * some prototypes of util.c - so I don't have to suck in the
62  * whole bunch of include files. You probably will not use this
63  * in your code anyway - or then should make it in a proper way.
64  */
65 char *utils_inet_ntoa(struct in_addr in);
66
67 /*
68  * Should return with 0 on success.
69  * If return status is != 0, siproxd will complain with an
70  * an ERROR() but continue.
71  */
72 int custom_fw_control(fw_ctl_t fwdata) {
73    static char tmp[256];
74
75    tmp[0]='\0';
76    switch (fwdata.action) {
77      case ACT_START_RTP:
78        strcat(tmp, "ACT_START_RTP: ");
79        break;
80      case ACT_STOP_RTP:
81        strcat(tmp, "ACT_STOP_RTP: ");
82        break;
83      default:
84        strcat(tmp, "ACT_unknown: ");
85        break;
86    }
87
88    switch (fwdata.direction) {
89      case DIR_IN:
90        strcat(tmp, "DIR_IN ");
91        break;
92      case DIR_OUT:
93        strcat(tmp, "DIR_OUT ");
94        break;
95      default:
96        strcat(tmp, "DIR_unknown ");
97        break;
98    }
99
100    sprintf(&tmp[strlen(tmp)],"[lcl %s:%i] ",
101            utils_inet_ntoa(fwdata.local_ipaddr),
102            fwdata.local_port);
103
104    sprintf(&tmp[strlen(tmp)],"[rem %s:%i] ",
105            utils_inet_ntoa(fwdata.remote_ipaddr),
106            fwdata.remote_port);
107
108    INFO("CUSTOM: %s", tmp);
109
110    return 0;
111 }