Changeset 666

Show
Ignore:
Timestamp:
10/15/06 00:52:57 (2 years ago)
Author:
common
Message:

@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@
@@@@@@@ @@@ @@@ @@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@

@@! @@! @@@ @@! @@! @@! @@@ @@! @@!
!@! !@! @!@ !@! !@! !@! @!@ !@! !@!
@!! @!@!@!@! @!!!:! @!!!:! @!@ !@! !!@ @!!
!!! !!!@!!!! !!!!!: !!!!!: !@! !!! !!! !!!
!!: !!: !!! !!: !!: :!: !!: !!: !!:
:!: :!: !:! :!: :!: ::!!:! :!: :!:

:: ::: :: :::: :: :::: :::: :: :: ::::
: : : : :
:: : :: :: : : : :: : :

@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@@@@ @@@ @@@@@@ @@@ @@@
@@@@@@@@ @@@@@@@@ @@@ @@@ @@@ @@@@@@@ @@@ @@@@@@@@ @@@@ @@@
@@! @@@ @@! @@! @@@ @@! !@@ @@! @@! @@@ @@!@!@@@
!@! @!@ !@! !@! @!@ !@! !@! !@! !@! @!@ !@!!@!@!
@!@!!@! @!!!:! @!@ !@! !!@ !!@@!! !!@ @!@ !@! @!@ !!@!
!!@!@! !!!!!: !@! !!! !!! !!@!!! !!! !@! !!! !@! !!!
!!: :!! !!: :!: !!: !!: !:! !!: !!: !!! !!: !!!
:!: !:! :!: ::!!:! :!: !:! :!: :!: !:! :!: !:!

::: :: :::: :::: :: :::: :: :: ::::: :: :: ::
: : : :
:: : : :: : : : : : : :: :

nepenthes

  • submit-postgres
    • basic spooling with bencoded files"
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/modules/submit-postgres/Makefile.am

    r607 r666  
    1111pkglib_LTLIBRARIES = submitpostgres.la 
    1212 
    13 submitpostgres_la_SOURCES = submit-postgres.cpp submit-postgres.hpp 
     13submitpostgres_la_SOURCES = submit-postgres.cpp submit-postgres.hpp  
     14submitpostgres_la_SOURCES += PGDownloadContext.cpp PGDownloadContext.hpp  
     15submitpostgres_la_SOURCES += bencoding.c bencoding.h 
    1416 
    1517submitpostgres_la_LDFLAGS = -module -no-undefined -avoid-version 
  • nepenthes/trunk/modules/submit-postgres/submit-postgres.cpp

    r659 r666  
    2727 
    2828 /* $Id$ */ 
     29 
     30#include <dirent.h> 
    2931 
    3032#include "submit-postgres.hpp" 
     
    133135 
    134136        REG_SUBMIT_HANDLER(this); 
     137 
     138 
     139 
     140        string m_SpoolDir = "var/spool/submitpostgres"; 
     141        DIR *dir; 
     142        struct dirent *dent; 
     143         
     144        if((dir = opendir(m_SpoolDir.c_str())) == NULL) 
     145        { 
     146                logWarn("could not open spool dir\n"); 
     147                return true; // for now this is not critical FIXME 
     148        } 
     149         
     150        while((dent = readdir(dir)) != NULL) 
     151        { 
     152                string filepath = m_SpoolDir + "/" + string(dent->d_name); 
     153                struct stat s; 
     154 
     155                logInfo("Checking %s\n",filepath.c_str()); 
     156                 
     157                if(stat(filepath.c_str(), &s) != 0) 
     158                { 
     159                        continue; 
     160                } 
     161                 
     162                if(S_ISREG(s.st_mode) == 0) 
     163                { 
     164                        continue; 
     165                } 
     166                 
     167                PGDownloadContext *ctx = PGDownloadContext::unserialize(filepath.c_str()); 
     168                if (ctx == NULL) 
     169                        continue; 
     170 
     171                string query; 
     172                query = "SELECT mwcollect.sensor_exists_sample('"; 
     173                query += ctx->getHashMD5(); 
     174                query += "','"; 
     175                query += ctx->getHashSHA512(); 
     176                query += "')"; 
     177 
     178                logSpam("Query is %s\n",query.c_str()); 
     179 
     180                m_SQLHandler->addQuery(&query,this,ctx); 
     181 
     182                ctx->setState(PG_SAMPLE_EXISTS); 
     183                m_OutstandingQueries.push_back(ctx); 
     184 
     185        } 
     186        closedir(dir); 
    135187        return true; 
    136188} 
     
    288340                if (resvec[0]["sensor_add_instance"] == "f") 
    289341                        logCrit("ERROR inserting instance\n"); 
     342                m_OutstandingQueries.front()->remove(); 
    290343                delete m_OutstandingQueries.front(); 
    291344                break; 
     
    294347                if (resvec[0]["sensor_add_sample"] == "f") 
    295348                        logCrit("ERROR inserting sample\n"); 
     349                m_OutstandingQueries.front()->remove(); 
    296350                delete m_OutstandingQueries.front(); 
    297351                break; 
     
    309363{ 
    310364        logPF(); 
     365        m_OutstandingQueries.front()->remove(); 
    311366        delete m_OutstandingQueries.front(); 
    312        m_OutstandingQueries.pop_front(); 
     367    m_OutstandingQueries.pop_front(); 
    313368        return true; 
    314369} 
  • nepenthes/trunk/modules/submit-postgres/submit-postgres.hpp

    r659 r666  
    2828 /* $Id$ */ 
    2929 
    30 #include <sys/socket.h> 
    31 #include <netinet/in.h> 
    32 #include <arpa/inet.h> 
     30 
    3331 
    3432 
     
    4341#include "DownloadBuffer.hpp" 
    4442 
     43 
     44#include "PGDownloadContext.hpp" 
     45 
    4546using namespace std; 
    4647 
     
    4950 
    5051        class SQLHandler; 
    51  
    52         typedef enum { 
    53                 PG_NULL, 
    54                 PG_SAMPLE_EXISTS, 
    55                 PG_SAMPLE_ADD, 
    56                 PG_INSTANCE_ADD 
    57         } pg_submit_state; 
    58  
    59  
    60         class PGDownloadContext 
    61         { 
    62         public: 
    63                 PGDownloadContext(Download *down) 
    64                 { 
    65                         m_hash_md5              = down->getMD5Sum(); 
    66                         m_hash_sha512   = down->getSHA512Sum(); 
    67                         m_Url                   = down->getUrl();        
    68  
    69                         uint32_t host   = down->getRemoteHost(); 
    70                         m_RemoteHost    = inet_ntoa(*(struct in_addr *)&host); 
    71  
    72                         host = down->getLocalHost(); 
    73                         m_LocalHost             = inet_ntoa(*(struct in_addr *)&host);   
    74  
    75                         m_FileContent   = string(down->getDownloadBuffer()->getData(),down->getDownloadBuffer()->getSize()); 
    76  
    77                         m_State = PG_NULL; 
    78                 } 
    79  
    80                 ~PGDownloadContext() 
    81                 { 
    82  
    83                 } 
    84  
    85                 string getHashMD5() 
    86                 { 
    87                         return m_hash_md5; 
    88                 } 
    89  
    90                 string getHashSHA512() 
    91                 { 
    92                         return m_hash_sha512; 
    93                 } 
    94  
    95                 string *getUrl() 
    96                 { 
    97                         return &m_Url; 
    98                 } 
    99  
    100                 string getRemoteHost() 
    101                 { 
    102                         return m_RemoteHost; 
    103                 } 
    104  
    105                 string getLocalHost() 
    106                 { 
    107                         return m_LocalHost; 
    108                 } 
    109  
    110                 string  *getFileContent() 
    111                 { 
    112                         return &m_FileContent; 
    113                 } 
    114  
    115                 uint32_t getFileSize() 
    116                 { 
    117                         return m_FileContent.size(); 
    118                 } 
    119  
    120                 pg_submit_state getState() 
    121                 { 
    122                         return m_State; 
    123                 } 
    124  
    125                 void setState(pg_submit_state s) 
    126                 { 
    127                         m_State = s; 
    128                 } 
    129  
    130         private: 
    131                 string                  m_hash_md5; 
    132                 string                  m_hash_sha512; 
    133                 string                  m_Url; 
    134  
    135                 string                  m_RemoteHost; 
    136                 string                  m_LocalHost; 
    137  
    138                 string                  m_FileContent; 
    139         pg_submit_state m_State; 
    140         }; 
    14152 
    14253