Changeset 594

Show
Ignore:
Timestamp:
07/29/06 20:51:55 (2 years ago)
Author:
common
Message:

nepenthes

  • draft for a generic sql interface
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/nepenthes-core/include/Makefile.am

    r535 r594  
    2121EXTRA_DIST += Packet.hpp 
    2222EXTRA_DIST += SubmitManager.hpp SubmitHandler.hpp  
     23EXTRA_DIST += SQLCallback.hpp SQLHandlerFactory.hpp SQLHandler.hpp SQLManager.hpp SQLQuery.hpp SQLResult.hpp 
    2324EXTRA_DIST += Utilities.hpp 
  • nepenthes/trunk/nepenthes-core/include/Nepenthes.hpp

    r551 r594  
    109109        class DNSManager; 
    110110        class Message; 
     111        class SQLManager; 
    111112 
    112113 
     
    136137                virtual DialogueFactoryManager *getFactoryMgr(); 
    137138                virtual DNSManager                      *getDNSMgr(); 
     139                virtual SQLManager                      *getSQLMgr(); 
    138140 
    139141                virtual bool                            doLoop(); 
     
    155157                SocketManager       *m_SocketManager; 
    156158                Utilities           *m_Utilities; 
    157                  
     159                SQLManager                     *m_SQLManager; 
    158160                 
    159161                 
  • nepenthes/trunk/nepenthes-core/include/SQLCallback.hpp

    r474 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
    27  
     27  
    2828/* $Id$ */ 
    2929 
     
    3535using namespace std; 
    3636 
    37 namespace library 
     37namespace nepenthes 
    3838{ 
    3939        class SQLResult; 
  • nepenthes/trunk/nepenthes-core/include/SQLHandler.hpp

    r514 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
     
    3333#include <string> 
    3434 
     35#include "SQLQuery.hpp" 
     36 
    3537using namespace std; 
    3638 
    37 namespace library 
     39namespace nepenthes 
    3840{ 
    3941        class SQLQuery; 
     
    4648 
    4749                virtual bool runQuery(SQLQuery *query)=0; 
    48  
    4950                virtual string escapeString(string *str)=0; 
    5051                virtual string escapeBinary(string *str)=0; 
    5152                virtual string unescapeBinary(string *str)=0; 
    52                  
     53 
     54                virtual SQLQuery *addQuery(string *query, SQLCallback *callback, void *obj) 
     55                { 
     56//                      logPF(); 
     57//                      logSpam("Query %s\nCallback %x\n",query->c_str(),callback); 
     58                        SQLQuery *sqlquery = new SQLQuery(query,callback, obj); 
     59                        runQuery(sqlquery); 
     60                        return sqlquery; 
     61                } 
    5362 
    5463                virtual string getSQLHandlerName() 
     
    5665                        return m_SQLHandlerName; 
    5766                } 
     67 
    5868 
    5969        protected: 
  • nepenthes/trunk/nepenthes-core/include/SQLManager.hpp

    r514 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
     
    3232 
    3333#include <list> 
     34#include <string> 
    3435#include <stdint.h> 
    3536 
    3637#include "Manager.hpp" 
    3738 
    38 #define SQL_ESCAPE_BINARY(x)    g_Library->getSQLMgr()->escapeBinary((x)) 
    39 #define SQL_UNESCAPE_BINARY(x)  g_Library->getSQLMgr()->unescapeBinary((x)) 
    40 #define SQL_ESCAPE_STRING(x)    g_Library->getSQLMgr()->escapeString((x)) 
    41  
    4239using namespace std; 
    4340 
    44 namespace library 
     41namespace nepenthes 
    4542{ 
    4643        class SQLHandler; 
     44        class SQLHandlerFactory; 
    4745        class SQLQuery; 
    4846        class SQLCallback; 
     
    5149        { 
    5250        public: 
    53                 SQLManager(Library *library); 
     51                SQLManager(Nepenthes *nepenthes); 
    5452                virtual ~SQLManager(); 
    5553 
    56                 virtual SQLQuery *addQuery(string *query, SQLCallback *callback, void *obj); 
    57                 virtual string escapeString(string *str); 
    58                 virtual string escapeBinary(string *str); 
    59                 virtual string unescapeBinary(string *str); 
    60  
    61                 virtual bool setSQLHandler(SQLHandler *handler); 
    6254                bool Init(); 
    6355                bool Exit(); 
    6456                void doList(); 
    6557 
     58                virtual bool registerSQLHandlerFactory(SQLHandlerFactory * handlerfactory); 
     59                virtual void unregisterSQLHandlerFactory(const char *dbtype); 
     60                virtual SQLHandler *createSQLHandler(const char *dbtype, string user, string passwd, string table, string options); 
     61 
    6662        private: 
    67                 SQLHandler *m_SQLHandler
     63                list<SQLHandlerFactory *>  m_SQLHandlerFactories
    6864        }; 
    6965 
  • nepenthes/trunk/nepenthes-core/include/SQLQuery.hpp

    r474 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
     
    3636 
    3737 
    38 namespace library 
     38namespace nepenthes 
    3939{ 
    4040        class SQLCallback; 
  • nepenthes/trunk/nepenthes-core/include/SQLResult.hpp

    r474 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
     
    3131#define HAVE_SQLRESULT_HPP 
    3232 
    33 #include <libpq-fe.h> 
    34  
    35  
    3633#include <list> 
    3734#include <string> 
     
    4138using namespace std; 
    4239 
    43 namespace library 
     40namespace nepenthes 
    4441{ 
    4542 
     
    4946                SQLResult(string query, void *obj); 
    5047                virtual ~SQLResult(); 
    51                 virtual string         getQuery(); 
    52                 virtual void   *getObject(); 
    53                  
     48                virtual string getQuery(); 
     49                virtual void    *getObject(); 
     50 
    5451                virtual vector< map<string,string> > *getResult(); 
    5552        protected: 
    5653                string m_Query; 
    57                 void   *m_Object; 
    58                 vector< map<string,string> >           m_Result; 
     54                void    *m_Object; 
     55                vector< map<string,string> >        m_Result; 
    5956 
    6057        }; 
  • nepenthes/trunk/nepenthes-core/src/Makefile.am

    r559 r594  
    2727nepenthes_SOURCES += ShellcodeManager.cpp ShellcodeHandler.cpp  
    2828nepenthes_SOURCES += SubmitManager.cpp SubmitHandler.cpp  
     29nepenthes_SOURCES += SQLCallback.cpp SQLHandler.cpp SQLManager.cpp SQLQuery.cpp SQLResult.cpp 
    2930nepenthes_SOURCES += Utilities.cpp 
    3031 
  • nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp

    r570 r594  
    6666#include "DNSManager.hpp" 
    6767 
     68#include "SQLManager.hpp" 
     69 
    6870#include "Message.hpp" 
    6971 
     
    101103        m_SubmitManager = NULL; 
    102104        m_Utilities = NULL; 
     105 
     106        m_SQLManager = NULL; 
    103107 
    104108        m_UID = 0; 
     
    413417                        m_Utilities         = new Utilities(); 
    414418                        m_DNSManager        = new DNSManager(this); 
     419                        m_SQLManager            = new SQLManager(this); 
    415420                } 
    416421        } 
     
    562567                { 
    563568                        m_DialogueFactoryManager->doList(); 
     569                } 
     570 
     571                if (run == true) 
     572                { 
     573                        m_SQLManager->doList(); 
    564574                } 
    565575 
     
    731741                fileCheckMain(filecheckarg,argc,optind,argv); 
    732742        } 
    733         if( run == true ) 
     743        if( true )//run == true ) 
    734744        { 
    735745        doLoop(); 
     
    10921102 
    10931103 
     1104/** 
     1105 * get the SQLManager 
     1106 *  
     1107 * @return returns the SQLManager 
     1108 */ 
     1109SQLManager *Nepenthes::getSQLMgr() 
     1110{ 
     1111        return m_SQLManager; 
     1112} 
    10941113 
    10951114/** 
  • nepenthes/trunk/nepenthes-core/src/SQLManager.cpp

    r514 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
    27  
     27  
    2828/* $Id$ */ 
    2929 
     
    3434#include "SQLQuery.hpp" 
    3535#include "SQLHandler.hpp" 
    36  
    37 #include "Library.hpp" 
     36#include "SQLHandlerFactory.hpp" 
     37#include "Nepenthes.hpp" 
    3838#include "LogManager.hpp" 
    3939 
    40 using namespace library
     40using namespace nepenthes
    4141 
    4242 
    4343 
    44 SQLManager::SQLManager(Library *library
     44SQLManager::SQLManager(Nepenthes *nepenthes
    4545{ 
    46  
     46        m_Nepenthes = nepenthes; 
    4747} 
    4848 
     
    5050{ 
    5151 
    52 } 
    53  
    54 SQLQuery *SQLManager::addQuery(string *query, SQLCallback *callback, void *obj) 
    55 { 
    56         logPF(); 
    57         logSpam("Query %s\nCallback %x\n",query->c_str(),callback); 
    58         SQLQuery *sqlquery = new SQLQuery(query,callback, obj); 
    59         m_SQLHandler->runQuery(sqlquery); 
    60         return sqlquery; 
    6152} 
    6253 
     
    7465void SQLManager::doList() 
    7566{ 
    76         logInfo("=--- %-69s ---=\n","SQLManager"); 
    77         if (m_SQLHandler != NULL) 
     67 
     68        list <SQLHandlerFactory *>::iterator it; 
     69        logSpam("=--- %-69s ---=\n","SQLManager"); 
     70        int32_t i=0; 
     71        for(it = m_SQLHandlerFactories.begin();it != m_SQLHandlerFactories.end();it++,i++) 
    7872        { 
    79                 logInfo("  # %s\n",m_SQLHandler->getSQLHandlerName().c_str()); 
    80         }else 
    81         { 
    82                 logCrit("%s"," no sql handler loaded\n"); 
     73                logSpam("  %i) %-8s \n",i,(*it)->getDBType().c_str()); 
    8374        } 
    84         logInfo("=--- %2s %-66s ---=\n","", "SQLHandler registerd"); 
     75        logSpam("=--- %2i %-66s ---=\n\n",i, "SQLHandlerFactories registerd"); 
    8576} 
    8677 
    87 bool SQLManager::setSQLHandler(SQLHandler *handler) 
     78 
     79bool SQLManager::registerSQLHandlerFactory(SQLHandlerFactory * handlerfactory) 
    8880{ 
    89         if (m_SQLHandler == NULL) 
    90         { 
    91                 m_SQLHandler = handler; 
    92                 return true; 
    93         }else 
    94         { 
    95                 return false; 
    96         } 
     81        m_SQLHandlerFactories.push_back(handlerfactory); 
     82        return true; 
    9783} 
    9884 
    99 string SQLManager::escapeString(string *str
    100 { 
    101         return m_SQLHandler->escapeString(str)
     85void SQLManager::unregisterSQLHandlerFactory(const char *dbtype
     86{ // FIXME 
     87        return
    10288} 
    10389 
    104 string SQLManager::escapeBinary(string *str
     90SQLHandler *SQLManager::createSQLHandler(const char *dbtype, string user, string passwd, string table, string options
    10591{ 
    106         return m_SQLHandler->escapeBinary(str); 
     92        list <SQLHandlerFactory *>::iterator it; 
     93        int i=0; 
     94        for (it = m_SQLHandlerFactories.begin(); it != m_SQLHandlerFactories.end(); i++) 
     95        { 
     96                if (dbtype == (*it)->getDBType()) 
     97                { 
     98                        SQLHandler *sqlh =  (*it)->createSQLHandler(user,passwd,table,options); 
     99                        return sqlh; 
     100                } 
     101        } 
     102        return NULL; 
    107103} 
    108  
    109 string SQLManager::unescapeBinary(string *str) 
    110 { 
    111         return m_SQLHandler->unescapeBinary(str); 
    112 } 
    113  
  • nepenthes/trunk/nepenthes-core/src/SQLQuery.cpp

    r474 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
    27  
     27  
    2828/* $Id$ */ 
    2929 
     
    3535#include "SQLHandler.hpp" 
    3636 
    37 #include "Library.hpp" 
     37#include "Nepenthes.hpp" 
    3838#include "LogManager.hpp" 
    3939 
    40 using namespace library
     40using namespace nepenthes
    4141 
    4242 
  • nepenthes/trunk/nepenthes-core/src/SQLResult.cpp

    r474 r594  
    11/******************************************************************************** 
    2  *                              Library 
     2 *                              Nepenthes 
    33 *                        - finest collection - 
    44 * 
     
    2222 *  
    2323 *  
    24  *             contact librarydev@users.sourceforge.net   
     24 *             contact nepenthesdev@users.sourceforge.net   
    2525 * 
    2626 *******************************************************************************/ 
    27  
     27  
    2828/* $Id$ */ 
    2929 
     
    3535#include "SQLHandler.hpp" 
    3636 
    37 #include "Library.hpp" 
     37#include "Nepenthes.hpp" 
    3838#include "LogManager.hpp" 
    3939 
    40 using namespace library
     40using namespace nepenthes
    4141 
    4242