Library: Net Responsibility
Package: Core
Header: Database.h
Database handles all connections to the SQLite database. The Database object is instanciated in by MainApplication, and may be accessed by the static method &MainApplication::getDatabase().
The only class allowed to actually store any entries in the database is Sniffer. Other classes may only load data from it.
There is no method to write any custom SQLite query. Instead the queries are a little more limited. Most methods that returns data from the database also takes the arguments where and orderBy. With these you may customize the return values.
Queries that are done repeatedly are stored inside Statements. This will enchance their speed.
Member Functions: getBypasses, getCount, getDistinctHostnames, getHistory, getLastRowId, getMatches, getWarnings, getWhitelist, isReportTime, logBypass, logBypassShutdown, logInitBypasses, logMatch, logReportFinish, logReportStart, logSessionStart, logSessionStop, logUrl, logWarning, processPreviousSessions, rotateLog, setStatements
Database();
~Database();
Bypasses getBypasses(
string where = "",
string orderBy = "date, time ASC"
) const;
int getCount(
string from
) const;
Return the number of rows found in the table 'from'.
vector < string > getDistinctHostnames(
string where = "hostname <> ''",
string orderBy = "hostname ASC"
) const;
Return all unique hostnames in a simple vector. By default it will not return hostnames that are empty entries (if found), and the hostnames will be ordered by name.
History getHistory(
string where = "hostname <> ''",
string orderBy = "hostname ASC"
) const;
Return all History.
int getLastRowId() const;
Warnings getWarnings(
string where = "",
string orderBy = "u.hostname ASC",
bool = false
) const;
Return all Warnings found.
Warnings getWhitelist(
string where = "",
string orderBy = "u.hostname ASC"
) const;
Return all matches that are whitelisted for some reason. This is wrapped up in a Warnings object, since it's actually the same thing, but the matches are also considered clean.
bool isReportTime(
int frequency
);
Check if it's time to send a scheduled report, depending on 'frequency'.
void logBypass(
int type,
string details = "",
int datetime = 0
);
Log attempts to bypass the software. You'll need to enter the type (BYPASS_TYPE), and optionally more verbose details. The int datetime is a unix timestamp of when the bypass happened. If 0 the current timestamp will be used.
void logInitBypasses(
Bypasses & bypasses
);
During startup the software makes several sanity checks, to make sure it hasn't been bypassed. Even attempts that fails will be reported. This may be discussed however, if they are redundant and confusing for the accountability partners?
void logReportFinish(
int id
);
Log that the report finished successfully. You'll need to enter the id given by logReportStart().
void logReportStart(
int & id
);
Log that the reporting process have started. You'll need the id later to properly "close" the report.
void logSessionStart();
Log that this current instance started. This info is used to process if Net Responsibility has been bypassed by shutting it down or omitting it at boot time. The boot time of this specific session is also stored.
void logSessionStop();
Log that the current instance stopped.
void rotateLog(
int reportId
);
This method rotated the database, to clean up everything that have been included. Only entries older than the time for the report with reportId will be deleted. The reportId was given by logReportStart().
void getMatches(
vector < int > urlId,
vector < BlacklistMatch > & bm
) const;
void logBypassShutdown(
int datetime,
int gap = 0
);
void logMatch(
BlacklistMatch match
);
void logUrl(
HTTPRequest & request
);
Log a URL that's visited. This may only be done by the Sniffer class.
void logWarning(
BlacklistMatch match
);
Log a Warning that is flagged by the Filter. It is connected to the last URL inserted.
void processPreviousSessions();
Process the previous sessions, and log any attempts to bypass NR.
void setStatements();