class Database

Library: Net Responsibility
Package: Core
Header: Database.h

Description

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 Summary

Member Functions: getBypasses, getCount, getDistinctHostnames, getHistory, getLastRowId, getMatches, getWarnings, getWhitelist, isReportTime, logBypass, logBypassShutdown, logInitBypasses, logMatch, logReportFinish, logReportStart, logSessionStart, logSessionStop, logUrl, logWarning, processPreviousSessions, rotateLog, setStatements

Constructors

Database

Database();

Database

Database(
    Options & options
);

Destructor

~Database

~Database();

Member Functions

getBypasses

Bypasses getBypasses(
    string where = "",
    string orderBy = "date, time ASC"
) const;

Return all Bypasses found, in a Bypasses object.

getCount

int getCount(
    string from
) const;

Return the number of rows found in the table 'from'.

getDistinctHostnames

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.

getHistory

History getHistory(
    string where = "hostname <> ''",
    string orderBy = "hostname ASC"
) const;

Return all History.

getLastRowId

int getLastRowId() const;

getWarnings

Warnings getWarnings(
    string where = "",
    string orderBy = "u.hostname ASC",
    bool = false
) const;

Return all Warnings found.

getWhitelist

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.

isReportTime

bool isReportTime(
    int frequency
);

Check if it's time to send a scheduled report, depending on 'frequency'.

logBypass

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.

logInitBypasses

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?

logReportFinish

void logReportFinish(
    int id
);

Log that the report finished successfully. You'll need to enter the id given by logReportStart().

logReportStart

void logReportStart(
    int & id
);

Log that the reporting process have started. You'll need the id later to properly "close" the report.

logSessionStart

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.

logSessionStop

void logSessionStop();

Log that the current instance stopped.

rotateLog

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().

getMatches protected

void getMatches(
    vector < int > urlId,
    vector < BlacklistMatch > & bm
) const;

logBypassShutdown protected

void logBypassShutdown(
    int datetime,
    int gap = 0
);

logMatch protected

void logMatch(
    BlacklistMatch match
);

logUrl protected

void logUrl(
    HTTPRequest & request
);

Log a URL that's visited. This may only be done by the Sniffer class.

logWarning protected

void logWarning(
    BlacklistMatch match
);

Log a Warning that is flagged by the Filter. It is connected to the last URL inserted.

processPreviousSessions protected

void processPreviousSessions();

Process the previous sessions, and log any attempts to bypass NR.

setStatements protected

void setStatements();