1 --- lighttpd-1.4.13/src/mod_evasive.c~ 2006-10-10 03:02:12.749561697 +0300
2 +++ lighttpd-1.4.13/src/mod_evasive.c 2006-10-10 03:14:39.056335465 +0300
6 unsigned short max_conns;
7 + unsigned short http_status_code;
8 + unsigned int retry_after;
14 + buffer *evasive_rftmp;
16 plugin_config **config_storage;
21 p = calloc(1, sizeof(*p));
23 + p->evasive_rftmp = buffer_init();
25 + buffer_prepare_copy(p->evasive_rftmp, 255);
32 if (!p) return HANDLER_GO_ON;
34 + buffer_free(p->evasive_rftmp);
36 if (p->config_storage) {
38 for (i = 0; i < srv->config_context->used; i++) {
41 config_values_t cv[] = {
42 { "evasive.max-conns-per-ip", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
43 + { "evasive.http-status-code", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
44 + { "evasive.retry-after", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION },
45 { NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
51 s = calloc(1, sizeof(plugin_config));
54 + s->http_status_code = 503;
57 cv[0].destination = &(s->max_conns);
58 + cv[1].destination = &(s->http_status_code);
59 + cv[2].destination = &(s->retry_after);
61 p->config_storage[i] = s;
64 plugin_config *s = p->config_storage[0];
67 + PATCH(http_status_code);
70 /* skip the first, the global context */
71 for (i = 1; i < srv->config_context->used; i++) {
74 if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.max-conns-per-ip"))) {
76 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.http-status-code"))) {
77 + PATCH(http_status_code);
78 + } else if (buffer_is_equal_string(du->key, CONST_STR_LEN("evasive.retry-after"))) {
84 inet_ntop_cache_get_ip(srv, &(con->dst_addr)),
85 "turned away. Too many connections.");
87 - con->http_status = 403;
88 + buffer_copy_long(p->evasive_rftmp, p->conf.retry_after);
90 + con->http_status = p->conf.http_status_code;
91 + response_header_overwrite(srv, con, CONST_STR_LEN("Retry-After"), CONST_BUF_LEN(p->evasive_rftmp));
92 return HANDLER_FINISHED;