2012-05-21 19:08:04 +01:00
C{
remote_ip = VRT_IP_string(sp, VRT_r_client_ip(sp));
forwarded_ip = VRT_GetHdr(sp, HDR_REQ, "\020X-Forwarded-For:");
useragent = VRT_GetHdr(sp, HDR_REQ, "\013User-Agent:");
cookie = VRT_GetHdr(sp, HDR_REQ, "\007Cookie:");
char statement[BUFSIZ];
char *sqlite3_error;
char *safecookie = str_replace(cookie, "'", "''");
2012-11-08 13:57:29 +00:00
snprintf(statement, BUFSIZ, "SELECT COUNT(*), remote_ip FROM blocklist WHERE remote_ip = '%s' AND (forwarded_ip = 'ANY' OR forwarded_ip = '%s') AND (useragent = 'ANY' OR useragent = '%s')", remote_ip, forwarded_ip, useragent);
2012-05-21 19:08:04 +01:00
sqlite3_init();
if (sqlite3_exec(db, statement, resultHandler, sp, &sqlite3_error) != SQLITE_OK) {
/* SQLite error. Allow. */
syslog(LOG_WARNING, "SQLite error (%s). Allow traffic from %s by default.", sqlite3_error, remote_ip);
syslog(LOG_INFO, "SQLite statment: %s", statement);
sqlite3_free(sqlite3_error);
}
free(safecookie);
}C