| 130 | |
| 131 | |
| 132 | static int pike_init(void) |
| 133 | { |
| 134 | struct script_route_ref *rt; |
| 135 | |
| 136 | LM_INFO("initializing...\n"); |
| 137 | |
| 138 | if (timeout <= time_unit) { |
| 139 | LM_WARN("remove_latency smaller than sampling_time_unit! " |
| 140 | "Having a smaller or equal value for remove_latency may " |
| 141 | "lead to missing UNBLOCK events!\n"); |
| 142 | timeout = time_unit + 1; |
| 143 | LM_NOTICE("Forcing remove_latency to %ds\n", timeout); |
| 144 | } |
| 145 | |
| 146 | /* alloc the timer lock */ |
| 147 | timer_lock=lock_alloc(); |
| 148 | if (timer_lock==0) { |
| 149 | LM_ERR(" alloc locks failed!\n"); |
| 150 | goto error1; |
| 151 | } |
| 152 | /* init the lock */ |
| 153 | if (lock_init(timer_lock)==0){ |
| 154 | LM_ERR(" init lock failed\n"); |
| 155 | goto error1; |
| 156 | } |
| 157 | |
| 158 | /* init the IP tree */ |
| 159 | if ( init_ip_tree(max_reqs)!=0 ) { |
| 160 | LM_ERR(" ip_tree creation failed!\n"); |
| 161 | goto error2; |
| 162 | } |
| 163 | |
| 164 | /* init timer list */ |
| 165 | timer = (struct list_link*)shm_malloc(sizeof(struct list_link)); |
| 166 | if (timer==0) { |
| 167 | LM_ERR(" cannot alloc shm mem for timer!\n"); |
| 168 | goto error3; |
| 169 | } |
| 170 | timer->next = timer->prev = timer; |
| 171 | |
| 172 | /* registering timing functions */ |
| 173 | register_timer( "pike-clean", clean_routine , 0, 1 , |
| 174 | TIMER_FLAG_DELAY_ON_DELAY); |
| 175 | register_timer( "pike-swap", swap_routine , 0, time_unit, |
| 176 | TIMER_FLAG_DELAY_ON_DELAY ); |
| 177 | |
| 178 | if (pike_route_s && *pike_route_s) { |
| 179 | rt = ref_script_route_by_name( pike_route_s, sroutes->request, |
| 180 | RT_NO, REQUEST_ROUTE, 0); |
| 181 | if ( !ref_script_route_is_valid(rt) ) { |
| 182 | LM_ERR("route <%s> does not exist\n",pike_route_s); |
| 183 | return -1; |
| 184 | } |
| 185 | |
| 186 | /* register the script callback to get all requests and replies */ |
| 187 | if (register_script_cb( run_pike_route , |
| 188 | PARSE_ERR_CB|REQ_TYPE_CB|RPL_TYPE_CB|PRE_SCRIPT_CB, (void*)rt )!=0 ) { |
| 189 | LM_ERR("failed to register script callbacks\n"); |
nothing calls this directly
no test coverage detected