1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
|
/*
* $Id: pike.c,v 1.3 2006/01/24 20:56:27 bogdan_iancu Exp $
*
* PIKE module
*
* Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of openser, a free SIP server.
*
* openser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* openser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* History:
* --------
* 2003-03-11 updated to the new module exports interface (andrei)
* 2003-03-11 converted to the new locking interface: locking.h --
* major changes (andrei)
* 2003-03-16 flags export parameter added (janakj)
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "../../sr_module.h"
#include "../../error.h"
#include "../../dprint.h"
#include "../../ut.h"
#include "../../mem/shm_mem.h"
#include "../../timer.h"
#include "../../locking.h"
#include "../../fifo_server.h"
#include "ip_tree.h"
#include "timer.h"
#include "pike_funcs.h"
#include "pike_fifo.h"
MODULE_VERSION
static int pike_init(void);
static int pike_exit(void);
/* parameters */
static int time_unit = 2;
static int max_reqs = 30;
int timeout = 120;
/* global variables */
gen_lock_t* timer_lock=0;
struct list_link* timer = 0;
static cmd_export_t cmds[]={
{"pike_check_req", pike_check_req, 0, 0, REQUEST_ROUTE},
{0,0,0,0,0}
};
static param_export_t params[]={
{"sampling_time_unit", INT_PARAM, &time_unit},
{"reqs_density_per_unit", INT_PARAM, &max_reqs},
{"remove_latency", INT_PARAM, &timeout},
{0,0,0}
};
struct module_exports exports= {
"pike",
cmds,
params,
0, /* exported statistics */
pike_init, /* module initialization function */
(response_function) 0,
(destroy_function) pike_exit, /* module exit function */
0 /* per-child init function */
};
static int pike_init(void)
{
LOG(L_INFO,"PIKE - initializing\n");
/* alloc the timer lock */
timer_lock=lock_alloc();
if (timer_lock==0) {
LOG(L_ERR,"ERROR:pike_init: alloc locks failed!\n");
goto error1;
}
/* init the lock */
if (lock_init(timer_lock)==0){
LOG(L_ERR, "ERROR:pike_init: init lock failed\n");
goto error1;
}
/* init the IP tree */
if ( init_ip_tree(max_reqs)!=0 ) {
LOG(L_ERR,"ERROR:pike_init: ip_tree creation failed!\n");
goto error2;
}
/* init timer list */
timer = (struct list_link*)shm_malloc(sizeof(struct list_link));
if (timer==0) {
LOG(L_ERR,"ERROR:pike_init: cannot alloc shm mem for timer!\n");
goto error3;
}
timer->next = timer->prev = timer;
/* registering timing functions */
register_timer( clean_routine , 0, 1 );
register_timer( swap_routine , 0, time_unit );
/* register fifo commands */
if (register_fifo_cmd( fifo_print_ip_tree, PIKE_PRINT_IP_TREE, 0)!=1) {
LOG(L_ERR,"ERROR:pike_init: cannot register fifo cmd %s\n",
PIKE_PRINT_IP_TREE);
goto error4;
}
/* register fifo commands */
if (register_fifo_cmd( fifo_print_timer_list, PIKE_PRINT_TIMER, 0)!=1) {
LOG(L_ERR,"ERROR:pike_init: cannot register fifo cmd %s\n",
PIKE_PRINT_IP_TREE);
goto error4;
}
return 0;
error4:
shm_free( timer );
error3:
destroy_ip_tree();
error2:
lock_destroy(timer_lock);
error1:
if (timer_lock) lock_dealloc(timer_lock);
timer_lock = 0;
return -1;
}
static int pike_exit(void)
{
LOG(L_INFO,"PIKE - destroying module\n");
/* destroy semaphore */
if (timer_lock) {
lock_destroy(timer_lock);
lock_dealloc(timer_lock);
}
/* empty the timer list head */
if (timer) {
shm_free(timer);
timer = 0;
}
/* destroy the IP tree */
destroy_ip_tree();
return 0;
}
|