#include "fastcgi.h"
/* maybe it's better to use weak name instead */
-static fcgi_logger logger;
+#ifndef HAVE_ATTRIBUTE_WEAK
+static fcgi_logger fcgi_log;
+#endif
typedef union _sa_t {
struct sockaddr sa;
in_shutdown = 1;
}
+#ifndef HAVE_ATTRIBUTE_WEAK
void fcgi_set_logger(fcgi_logger lg) {
- logger = lg;
+ fcgi_log = lg;
}
+#else
+void __attribute__((weak)) fcgi_log(int type, const char *format, ...) {
+ va_list ap;
+
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+}
+#endif
int fcgi_init(void)
{
hep = gethostbyname(host);
}
if (!hep || hep->h_addrtype != AF_INET || !hep->h_addr_list[0]) {
- logger(FCGI_ERROR, "Cannot resolve host name '%s'!\n", host);
+ fcgi_log(FCGI_ERROR, "Cannot resolve host name '%s'!\n", host);
return -1;
} else if (hep->h_addr_list[1]) {
- logger(FCGI_ERROR, "Host '%s' has multiple addresses. You must choose one explicitly!\n", host);
+ fcgi_log(FCGI_ERROR, "Host '%s' has multiple addresses. You must choose one explicitly!\n", host);
return -1;
}
sa.sa_inet.sin_addr.s_addr = ((struct in_addr*)hep->h_addr_list[0])->s_addr;
int path_len = strlen(path);
if (path_len >= sizeof(sa.sa_unix.sun_path)) {
- logger(FCGI_ERROR, "Listening socket's path name is too long.\n");
+ fcgi_log(FCGI_ERROR, "Listening socket's path name is too long.\n");
return -1;
}
bind(listen_socket, (struct sockaddr *) &sa, sock_len) < 0 ||
listen(listen_socket, backlog) < 0) {
- logger(FCGI_ERROR, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno));
+ fcgi_log(FCGI_ERROR, "Cannot bind/listen socket - [%d] %s.\n",errno, strerror(errno));
return -1;
}
n++;
#endif
} else {
- logger(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
+ fcgi_log(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
}
cur = end;
}
allowed_clients[n].sa.sa_family = 0;
free(ip);
if (!n) {
- logger(FCGI_ERROR, "There are no allowed addresses");
+ fcgi_log(FCGI_ERROR, "There are no allowed addresses");
/* don't clear allowed_clients as it will create an "open for all" security issue */
}
}
n++;
#endif
} else {
- logger(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
+ fcgi_log(FCGI_ERROR, "Wrong IP address '%s' in listen.allowed_clients", cur);
}
cur = end;
}
allowed_clients[n].sa.sa_family = 0;
free(ip);
if (!n) {
- logger(FCGI_ERROR, "There are no allowed addresses");
+ fcgi_log(FCGI_ERROR, "There are no allowed addresses");
/* don't clear allowed_clients as it will create an "open for all" security issue */
}
}
}
#endif
- logger(FCGI_ERROR, "Connection disallowed: IP address '%s' has been dropped.", fcgi_get_last_client_ip());
+ fcgi_log(FCGI_ERROR, "Connection disallowed: IP address '%s' has been dropped.", fcgi_get_last_client_ip());
return 0;
}
}
fcgi_close(req, 1, 0);
} else {
- logger(FCGI_ERROR, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
+ fcgi_log(FCGI_ERROR, "Too many open file descriptors. FD_SETSIZE limit exceeded.");
fcgi_close(req, 1, 0);
}
#endif
typedef void (*fcgi_apply_func)(char *var, unsigned int var_len, char *val, unsigned int val_len, void *arg);
-typedef void (*fcgi_logger)(int type, const char *fmt, ...);
-
#define FCGI_HASH_TABLE_SIZE 128
#define FCGI_HASH_TABLE_MASK (FCGI_HASH_TABLE_SIZE - 1)
#define FCGI_HASH_SEG_SIZE 4096
void fcgi_set_allowed_clients(char *ip);
int fcgi_accept_request(fcgi_request *req);
int fcgi_finish_request(fcgi_request *req, int force_close);
-void fcgi_set_logger(fcgi_logger lg);
const char *fcgi_get_last_client_ip();
void fcgi_set_in_shutdown(int new_value);
+#ifndef HAVE_ATTRIBUTE_WEAK
+typedef void (*fcgi_logger)(int type, const char *fmt, ...);
+void fcgi_set_logger(fcgi_logger lg);
+#endif
+
char* fcgi_getenv(fcgi_request *req, const char* var, int var_len);
char* fcgi_putenv(fcgi_request *req, char* var, int var_len, char* val);
char* fcgi_quick_getenv(fcgi_request *req, const char* var, int var_len, unsigned int hash_value);