Skip to content
Snippets Groups Projects
Commit ad476d7d authored by Eugene Livis's avatar Eugene Livis
Browse files

Debug and Release versions can be built without PostgreSQL

parent 566e5cb2
Branches
Tags
No related merge requests found
...@@ -67,11 +67,15 @@ TskCaseDb::newDb(const TSK_TCHAR * const path) ...@@ -67,11 +67,15 @@ TskCaseDb::newDb(const TSK_TCHAR * const path)
TskDb *db = new TskDbSqlite(path, true); TskDb *db = new TskDbSqlite(path, true);
#ifdef WIN32 #ifdef HAVE_POSTGRESQL
#ifdef TSK_WIN32
TskDbPostgreSQL *postDb = new TskDbPostgreSQL(path, true); TskDbPostgreSQL *postDb = new TskDbPostgreSQL(path, true);
postDb->open(true); postDb->setLogInInfo();
postDb->close(); if (!postDb->open(true)) {
#endif postDb->close();
}
#endif // TSK_WIN32
#endif // HAVE_POSTGRESQL
// Open the database. // Open the database.
if (db->open(true)) { if (db->open(true)) {
......
...@@ -13,49 +13,52 @@ ...@@ -13,49 +13,52 @@
* Contains code to perform operations against PostgreSQL database. * Contains code to perform operations against PostgreSQL database.
*/ */
#ifdef HAVE_POSTGRESQL
#include "tsk_db_postgresql.h" #include "tsk_db_postgresql.h"
#ifdef TSK_WIN32 #ifdef TSK_WIN32
/**
* Set the locations and logging object. Must call
* open() before the object can be used.
*/
TskDbPostgreSQL::TskDbPostgreSQL(const char *a_dbFilePathUtf8, bool a_blkMapFlag)
{
conn = NULL;
strncpy(m_dbFilePathUtf8, a_dbFilePathUtf8, 1024);
}
#ifdef TSK_WIN32
//@@@@
TskDbPostgreSQL::TskDbPostgreSQL(const TSK_TCHAR * a_dbFilePath, bool a_blkMapFlag) TskDbPostgreSQL::TskDbPostgreSQL(const TSK_TCHAR * a_dbFilePath, bool a_blkMapFlag)
{ {
conn = NULL; conn = NULL;
wcsncpy(m_dbFilePath, a_dbFilePath, 1024); wcsncpy(m_dbFilePath, a_dbFilePath, 1024);
} }
#endif
TskDbPostgreSQL::~TskDbPostgreSQL() TskDbPostgreSQL::~TskDbPostgreSQL()
{ {
} }
int TskDbPostgreSQL::setLogInInfo(){
strncpy(userName, "postgres___s", sizeof(userName));
strncpy(password, "simple41", sizeof(password));
strncpy(dbName, "testdb", sizeof(dbName));
strncpy(hostIpAddr, "127.0.0.1", sizeof(hostIpAddr));
strncpy(hostPort, "5432", sizeof(hostPort));
return 0;
}
int TskDbPostgreSQL::open(bool flag) int TskDbPostgreSQL::open(bool flag)
{ {
conn = NULL; conn = NULL;
// Make a connection to the database // Make a connection to the database
conn = PQconnectdb("user=postgres password=simple41 dbname=testdb hostaddr=127.0.0.1 port=5432"); char connectionString[2048];
sprintf(connectionString, "user=%s password=%s dbname=%s hostaddr=%s port=%s", userName, password, dbName, hostIpAddr, hostPort);
conn = PQconnectdb(connectionString);
// Check to see that the backend connection was successfully made // Check to see that the backend connection was successfully made
if (PQstatus(conn) != CONNECTION_OK) if (PQstatus(conn) != CONNECTION_OK)
{ {
printf("Connection to database failed"); printf("Connection to database failed");
close(); close();
return -1;
} }
printf("Connection to database - OK\n"); printf("Connection to database - OK\n");
return 0; return 0;
} }
...@@ -66,10 +69,10 @@ int TskDbPostgreSQL::open(bool flag) ...@@ -66,10 +69,10 @@ int TskDbPostgreSQL::open(bool flag)
*/ */
int TskDbPostgreSQL::close() int TskDbPostgreSQL::close()
{ {
// EL: TODO need to surround this with try/catch. Otherwise if we close database second time an exception is thrown.
PQfinish(conn); PQfinish(conn);
getchar();
exit(1);
return 0; return 0;
} }
#endif // TSK_WIN32 #endif // TSK_WIN32
\ No newline at end of file #endif // HAVE_POSTGRESQL
\ No newline at end of file
...@@ -23,7 +23,11 @@ using std::string; ...@@ -23,7 +23,11 @@ using std::string;
#include "tsk_auto_i.h" #include "tsk_auto_i.h"
#include "tsk_db_sqlite.h" #include "tsk_db_sqlite.h"
#ifdef HAVE_POSTGRESQL
#include "tsk_db_postgresql.h" #include "tsk_db_postgresql.h"
#endif
#include "tsk/hashdb/tsk_hashdb.h" #include "tsk/hashdb/tsk_hashdb.h"
#define TSK_ADD_IMAGE_SAVEPOINT "ADDIMAGE" #define TSK_ADD_IMAGE_SAVEPOINT "ADDIMAGE"
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* The class is an extension of TSK abstract database handling class. * The class is an extension of TSK abstract database handling class.
*/ */
#ifdef HAVE_POSTGRESQL
#ifndef _TSK_DB_POSTGRESQL_H #ifndef _TSK_DB_POSTGRESQL_H
#define _TSK_DB_POSTGRESQL_H #define _TSK_DB_POSTGRESQL_H
...@@ -31,25 +32,29 @@ using std::map; ...@@ -31,25 +32,29 @@ using std::map;
/** \internal /** \internal
* C++ class that wraps the database internals. * C++ class that wraps PostgreSQL database internals.
*/ */
class TskDbPostgreSQL { class TskDbPostgreSQL {
public: public:
#ifdef TSK_WIN32
//@@@@
TskDbPostgreSQL(const TSK_TCHAR * a_dbFilePath, bool a_blkMapFlag); TskDbPostgreSQL(const TSK_TCHAR * a_dbFilePath, bool a_blkMapFlag);
#endif
TskDbPostgreSQL(const char *a_dbFilePathUtf8, bool a_blkMapFlag);
~TskDbPostgreSQL(); ~TskDbPostgreSQL();
int open(bool); int open(bool);
int close(); int close();
int setLogInInfo();
private: private:
PGconn *conn; PGconn *conn;
TSK_TCHAR m_dbFilePath[1024]; TSK_TCHAR m_dbFilePath[1024];
char m_dbFilePathUtf8[1024]; char m_dbFilePathUtf8[1024];
char userName[128];
char password[128];
char dbName[1024];
char hostIpAddr[64];
char hostPort[16];
}; };
#endif // TSK_WIN32
#endif // _TSK_DB_POSTGRESQL_H #endif // _TSK_DB_POSTGRESQL_H
#endif // HAVE_POSTGRESQL
#endif // TSK_WIN32 \ No newline at end of file
\ No newline at end of file
...@@ -224,7 +224,7 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)" ...@@ -224,7 +224,7 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)"
<ClCompile> <ClCompile>
<Optimization>Disabled</Optimization> <Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\;$(LIBEWF_HOME)\common;$(LIBEWF_HOME)\include;$(LIBEWF_HOME)\..\zlib;$(POSTGRESQL_HOME_64)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir)\..\..\;$(LIBEWF_HOME)\common;$(LIBEWF_HOME)\include;$(LIBEWF_HOME)\..\zlib;$(POSTGRESQL_HOME_64)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;HAVE_LIBEWF;HAVE_LIBZ;WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;HAVE_LIBEWF;HAVE_LIBZ;WIN32;_DEBUG;HAVE_POSTGRESQL;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader> <PrecompiledHeader>
...@@ -235,6 +235,8 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)" ...@@ -235,6 +235,8 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)"
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(LIBEWF_HOME)\msvscpp\x64\release\libewf.dll" "$(OutDir)" <Command>copy "$(LIBEWF_HOME)\msvscpp\x64\release\libewf.dll" "$(OutDir)"
copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)" copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)"
copy "$(POSTGRESQL_HOME_64)\bin\libpq.dll" "$(OutDir)"
copy "$(POSTGRESQL_HOME_64)\bin\libintl-8.dll" "$(OutDir)"
</Command> </Command>
</PostBuildEvent> </PostBuildEvent>
<Lib> <Lib>
...@@ -312,7 +314,7 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)" ...@@ -312,7 +314,7 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)"
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<IntrinsicFunctions>true</IntrinsicFunctions> <IntrinsicFunctions>true</IntrinsicFunctions>
<AdditionalIncludeDirectories>$(ProjectDir)\..\..\;$(LIBEWF_HOME)\common;$(LIBEWF_HOME)\include;$(LIBEWF_HOME)\..\zlib;$(POSTGRESQL_HOME_64)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ProjectDir)\..\..\;$(LIBEWF_HOME)\common;$(LIBEWF_HOME)\include;$(LIBEWF_HOME)\..\zlib;$(POSTGRESQL_HOME_64)\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;HAVE_LIBEWF;HAVE_LIBZ;WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_DEPRECATE;HAVE_LIBEWF;HAVE_LIBZ;WIN32;NDEBUG;HAVE_POSTGRESQL;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary> <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader> <PrecompiledHeader>
...@@ -323,7 +325,8 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)" ...@@ -323,7 +325,8 @@ copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)"
<PostBuildEvent> <PostBuildEvent>
<Command>copy "$(LIBEWF_HOME)\msvscpp\x64\release\libewf.dll" "$(OutDir)" <Command>copy "$(LIBEWF_HOME)\msvscpp\x64\release\libewf.dll" "$(OutDir)"
copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)" copy "$(LIBEWF_HOME)\msvscpp\x64\release\zlib.dll" "$(OutDir)"
</Command> copy "$(POSTGRESQL_HOME_64)\bin\libpq.dll" "$(OutDir)"
copy "$(POSTGRESQL_HOME_64)\bin\libintl-8.dll" "$(OutDir)"</Command>
</PostBuildEvent> </PostBuildEvent>
<Lib> <Lib>
<AdditionalDependencies>libpq.lib</AdditionalDependencies> <AdditionalDependencies>libpq.lib</AdditionalDependencies>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment