Skip to content

Commit

Permalink
Change session_token to integer timestamp
Browse files Browse the repository at this point in the history
fixes #10529
  • Loading branch information
Michael Friedrich committed Nov 5, 2015
1 parent 4c0b245 commit 3b902b5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/db_ido_mysql/idomysqlconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void IdoMysqlConnection::Reconnect(void)

CONTEXT("Reconnecting to MySQL IDO database '" + GetName() + "'");

m_SessionToken = Utility::NewUniqueID();
m_SessionToken = static_cast<int>(Utility::GetTime());

SetShouldConnect(true);

Expand Down Expand Up @@ -382,7 +382,7 @@ void IdoMysqlConnection::Reconnect(void)

void IdoMysqlConnection::ClearCustomVarTable(const String& table)
{
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE session_token <> '" + Escape(m_SessionToken) + "'");
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE session_token <> " + Convert::ToString(m_SessionToken));
}

void IdoMysqlConnection::ClearConfigTable(const String& table)
Expand Down Expand Up @@ -683,7 +683,7 @@ bool IdoMysqlConnection::FieldToEscapedString(const String& key, const Value& va
return true;
}
if (key == "session_token") {
*result = "'" + Escape(m_SessionToken) + "'";
*result = m_SessionToken;
return true;
}
if (key == "notification_id") {
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido_mysql/idomysqlconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class IdoMysqlConnection : public ObjectImpl<IdoMysqlConnection>

private:
DbReference m_InstanceID;
String m_SessionToken;
int m_SessionToken;

WorkQueue m_QueryQueue;

Expand Down
4 changes: 2 additions & 2 deletions lib/db_ido_mysql/schema/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ CREATE TABLE IF NOT EXISTS icinga_customvariables (
varname varchar(255) character set latin1 collate latin1_general_cs default NULL,
varvalue TEXT character set latin1 default '',
is_json smallint default 0,
session_token varchar(512) character set latin1 default NULL,
session_token int default NULL,
PRIMARY KEY (customvariable_id),
UNIQUE KEY object_id_2 (object_id,config_type,varname),
KEY varname (varname)
Expand All @@ -363,7 +363,7 @@ CREATE TABLE IF NOT EXISTS icinga_customvariablestatus (
varname varchar(255) character set latin1 collate latin1_general_cs default NULL,
varvalue TEXT character set latin1 default '',
is_json smallint default 0,
session_token varchar(512) character set latin1 default NULL,
session_token int default NULL,
PRIMARY KEY (customvariablestatus_id),
UNIQUE KEY object_id_2 (object_id,varname),
KEY varname (varname)
Expand Down
4 changes: 2 additions & 2 deletions lib/db_ido_mysql/schema/upgrade/2.4.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ ALTER TABLE icinga_hoststatus ADD COLUMN original_attributes TEXT character set
-- #10436 deleted custom vars
-- -----------------------------------------

ALTER TABLE icinga_customvariables ADD COLUMN session_token varchar(512) character set latin1 default NULL;
ALTER TABLE icinga_customvariablestatus ADD COLUMN session_token varchar(512) character set latin1 default NULL;
ALTER TABLE icinga_customvariables ADD COLUMN session_token int default NULL;
ALTER TABLE icinga_customvariablestatus ADD COLUMN session_token int default NULL;

CREATE INDEX cv_session_del_idx ON icinga_customvariables (session_token);
CREATE INDEX cvs_session_del_idx ON icinga_customvariablestatus (session_token);
Expand Down
6 changes: 3 additions & 3 deletions lib/db_ido_pgsql/idopgsqlconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void IdoPgsqlConnection::Reconnect(void)

CONTEXT("Reconnecting to PostgreSQL IDO database '" + GetName() + "'");

m_SessionToken = Utility::NewUniqueID();
m_SessionToken = static_cast<int>(Utility::GetTime());

SetShouldConnect(true);

Expand Down Expand Up @@ -377,7 +377,7 @@ void IdoPgsqlConnection::Reconnect(void)

void IdoPgsqlConnection::ClearCustomVarTable(const String& table)
{
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE session_token <> '" + Escape(m_SessionToken) + "'");
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE session_token <> " + Convert::ToString(m_SessionToken));
}

void IdoPgsqlConnection::ClearConfigTable(const String& table)
Expand Down Expand Up @@ -561,7 +561,7 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va
return true;
}
if (key == "session_token") {
*result = "'" + Escape(m_SessionToken) + "'";
*result = m_SessionToken;
return true;
}
if (key == "notification_id") {
Expand Down
2 changes: 1 addition & 1 deletion lib/db_ido_pgsql/idopgsqlconnection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class IdoPgsqlConnection : public ObjectImpl<IdoPgsqlConnection>

private:
DbReference m_InstanceID;
String m_SessionToken;
int m_SessionToken;

WorkQueue m_QueryQueue;

Expand Down
4 changes: 2 additions & 2 deletions lib/db_ido_pgsql/schema/pgsql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ CREATE TABLE icinga_customvariables (
varname TEXT default '',
varvalue TEXT default '',
is_json INTEGER default 0,
session_token TEXT default NULL,
session_token INTEGER default NULL,
CONSTRAINT PK_customvariable_id PRIMARY KEY (customvariable_id) ,
CONSTRAINT UQ_customvariables UNIQUE (object_id,config_type,varname)
) ;
Expand All @@ -389,7 +389,7 @@ CREATE TABLE icinga_customvariablestatus (
varname TEXT default '',
varvalue TEXT default '',
is_json INTEGER default 0,
session_token TEXT default NULL,
session_token INTEGER default NULL,
CONSTRAINT PK_customvariablestatus_id PRIMARY KEY (customvariablestatus_id) ,
CONSTRAINT UQ_customvariablestatus UNIQUE (object_id,varname)
) ;
Expand Down
4 changes: 2 additions & 2 deletions lib/db_ido_pgsql/schema/upgrade/2.4.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ ALTER TABLE icinga_hoststatus ADD COLUMN original_attributes TEXT default NULL;
-- #10436 deleted custom vars
-- -----------------------------------------

ALTER TABLE icinga_customvariables ADD COLUMN session_token TEXT default NULL;
ALTER TABLE icinga_customvariablestatus ADD COLUMN session_token TEXT default NULL;
ALTER TABLE icinga_customvariables ADD COLUMN session_token INTEGER default NULL;
ALTER TABLE icinga_customvariablestatus ADD COLUMN session_token INTEGER default NULL;

CREATE INDEX cv_session_del_idx ON icinga_customvariables (session_token);
CREATE INDEX cvs_session_del_idx ON icinga_customvariablestatus (session_token);
Expand Down

0 comments on commit 3b902b5

Please sign in to comment.