Changeset 666
- Timestamp:
- 10/15/06 00:52:57 (2 years ago)
- Files:
-
- nepenthes/trunk/modules/submit-postgres/Makefile.am (modified) (1 diff)
- nepenthes/trunk/modules/submit-postgres/PGDownloadContext.cpp (added)
- nepenthes/trunk/modules/submit-postgres/PGDownloadContext.hpp (added)
- nepenthes/trunk/modules/submit-postgres/bencoding.c (added)
- nepenthes/trunk/modules/submit-postgres/bencoding.h (added)
- nepenthes/trunk/modules/submit-postgres/submit-postgres.cpp (modified) (5 diffs)
- nepenthes/trunk/modules/submit-postgres/submit-postgres.hpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/modules/submit-postgres/Makefile.am
r607 r666 11 11 pkglib_LTLIBRARIES = submitpostgres.la 12 12 13 submitpostgres_la_SOURCES = submit-postgres.cpp submit-postgres.hpp 13 submitpostgres_la_SOURCES = submit-postgres.cpp submit-postgres.hpp 14 submitpostgres_la_SOURCES += PGDownloadContext.cpp PGDownloadContext.hpp 15 submitpostgres_la_SOURCES += bencoding.c bencoding.h 14 16 15 17 submitpostgres_la_LDFLAGS = -module -no-undefined -avoid-version nepenthes/trunk/modules/submit-postgres/submit-postgres.cpp
r659 r666 27 27 28 28 /* $Id$ */ 29 30 #include <dirent.h> 29 31 30 32 #include "submit-postgres.hpp" … … 133 135 134 136 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); 135 187 return true; 136 188 } … … 288 340 if (resvec[0]["sensor_add_instance"] == "f") 289 341 logCrit("ERROR inserting instance\n"); 342 m_OutstandingQueries.front()->remove(); 290 343 delete m_OutstandingQueries.front(); 291 344 break; … … 294 347 if (resvec[0]["sensor_add_sample"] == "f") 295 348 logCrit("ERROR inserting sample\n"); 349 m_OutstandingQueries.front()->remove(); 296 350 delete m_OutstandingQueries.front(); 297 351 break; … … 309 363 { 310 364 logPF(); 365 m_OutstandingQueries.front()->remove(); 311 366 delete m_OutstandingQueries.front(); 312 m_OutstandingQueries.pop_front();367 m_OutstandingQueries.pop_front(); 313 368 return true; 314 369 } nepenthes/trunk/modules/submit-postgres/submit-postgres.hpp
r659 r666 28 28 /* $Id$ */ 29 29 30 #include <sys/socket.h> 31 #include <netinet/in.h> 32 #include <arpa/inet.h> 30 33 31 34 32 … … 43 41 #include "DownloadBuffer.hpp" 44 42 43 44 #include "PGDownloadContext.hpp" 45 45 46 using namespace std; 46 47 … … 49 50 50 51 class SQLHandler; 51 52 typedef enum {53 PG_NULL,54 PG_SAMPLE_EXISTS,55 PG_SAMPLE_ADD,56 PG_INSTANCE_ADD57 } pg_submit_state;58 59 60 class PGDownloadContext61 {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 };141 52 142 53
