"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/be13_api/feature_recorder_sql.cpp" between
tcpflow-1.4.5.tar.gz and tcpflow-1.5.0.tar.gz

About: tcpflow is a TCP/IP packet demultiplexer that captures data transmitted as part of TCP connections (flows), and stores the data in a way that is convenient for protocol analysis and debugging.

feature_recorder_sql.cpp  (tcpflow-1.4.5):feature_recorder_sql.cpp  (tcpflow-1.5.0)
skipping to change at line 73 skipping to change at line 73
"CREATE TABLE h_%s (count INTEGER(12), feature_utf8 TEXT)", "CREATE TABLE h_%s (count INTEGER(12), feature_utf8 TEXT)",
"CREATE INDEX h_%s_idx1 ON h_%s(count)", "CREATE INDEX h_%s_idx1 ON h_%s(count)",
"CREATE INDEX h_%s_idx2 ON h_%s(feature_utf8)", "CREATE INDEX h_%s_idx2 ON h_%s(feature_utf8)",
0}; 0};
/* This performs the histogram operation */ /* This performs the histogram operation */
static const char *schema_hist1[] = { static const char *schema_hist1[] = {
"INSERT INTO h_%s select COUNT(*),feature_utf8 from f_%s GROUP BY feature_ut f8", "INSERT INTO h_%s select COUNT(*),feature_utf8 from f_%s GROUP BY feature_ut f8",
0}; 0};
#ifdef HAVE_SQLITE3_CREATE_FUNCTION_V2
static const char *schema_hist2[] = { static const char *schema_hist2[] = {
"INSERT INTO h_%s select sum(count),BEHIST(feature_utf8) from h_%s where BEH IST(feature_utf8)!='' GROUP BY BEHIST(feature_utf8)", "INSERT INTO h_%s select sum(count),BEHIST(feature_utf8) from h_%s where BEH IST(feature_utf8)!='' GROUP BY BEHIST(feature_utf8)",
0}; 0};
#endif
#endif #endif
const char *feature_recorder::db_insert_stmt = "INSERT INTO f_%s (offset,path,fe ature_eutf8,feature_utf8,context_eutf8) VALUES (?1, ?2, ?3, ?4, ?5)"; const char *feature_recorder::db_insert_stmt = "INSERT INTO f_%s (offset,path,fe ature_eutf8,feature_utf8,context_eutf8) VALUES (?1, ?2, ?3, ?4, ?5)";
static const char *begin_transaction[] = {"BEGIN TRANSACTION",0}; static const char *begin_transaction[] = {"BEGIN TRANSACTION",0};
static const char *commit_transaction[] = {"COMMIT TRANSACTION",0}; static const char *commit_transaction[] = {"COMMIT TRANSACTION",0};
void feature_recorder::besql_stmt::insert_feature(const pos0_t &pos, void feature_recorder::besql_stmt::insert_feature(const pos0_t &pos,
const std::string &featu re, const std::string &featu re,
const std::string &featu re8, const std::string &context) const std::string &featu re8, const std::string &context)
{ {
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
skipping to change at line 133 skipping to change at line 135
assert(db!=0); assert(db!=0);
for(int i=0;stmts[i];i++){ for(int i=0;stmts[i];i++){
char *errmsg = 0; char *errmsg = 0;
char buf[65536]; char buf[65536];
va_list ap; va_list ap;
va_start(ap,stmts); va_start(ap,stmts);
vsnprintf(buf,sizeof(buf),stmts[i],ap); vsnprintf(buf,sizeof(buf),stmts[i],ap);
va_end(ap); va_end(ap);
if(debug) std::cerr << "SQL: " << buf << "\n"; if(debug) std::cerr << "SQL: " << buf << "\n";
if(sqlite3_exec(db,buf,NULL,NULL,&errmsg) != SQLITE_OK ) { // Don't error on a PRAGMA
if((sqlite3_exec(db,buf,NULL,NULL,&errmsg) != SQLITE_OK) && (strncmp(bu
f,"PRAGMA",6)!=0)) {
fprintf(stderr,"Error executing '%s' : %s\n",buf,errmsg); fprintf(stderr,"Error executing '%s' : %s\n",buf,errmsg);
exit(1); exit(1);
} }
} }
#endif #endif
} }
void feature_recorder_set::db_create_table(const std::string &name) void feature_recorder_set::db_create_table(const std::string &name)
{ {
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
skipping to change at line 239 skipping to change at line 242
/* Hook for writing histogram /* Hook for writing histogram
*/ */
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
static int callback_counter(void *param, int argc, char **argv, char **azColName ) static int callback_counter(void *param, int argc, char **argv, char **azColName )
{ {
int *counter = reinterpret_cast<int *>(param); int *counter = reinterpret_cast<int *>(param);
(*counter)++; (*counter)++;
return 0; return 0;
} }
#ifdef HAVE_SQLITE3_CREATE_FUNCTION_V2
static void behist(sqlite3_context *ctx,int argc,sqlite3_value**argv) static void behist(sqlite3_context *ctx,int argc,sqlite3_value**argv)
{ {
const histogram_def *def = reinterpret_cast<const histogram_def *>(sqlite3_u ser_data(ctx)); const histogram_def *def = reinterpret_cast<const histogram_def *>(sqlite3_u ser_data(ctx));
if(debug) std::cerr << "behist feature=" << def->feature << " suffix=" if(debug) std::cerr << "behist feature=" << def->feature << " suffix="
<< def->suffix << " argc=" << argc << "value = " << sql ite3_value_text(argv[0]) << "\n"; << def->suffix << " argc=" << argc << "value = " << sql ite3_value_text(argv[0]) << "\n";
std::string new_feature(reinterpret_cast<const char *>(sqlite3_value_text(ar gv[0]))); std::string new_feature(reinterpret_cast<const char *>(sqlite3_value_text(ar gv[0])));
if (def->reg.search(new_feature,&new_feature,0,0)) { if (def->reg.search(new_feature,&new_feature,0,0)) {
sqlite3_result_text(ctx,new_feature.c_str(),new_feature.size(),SQLITE_TR ANSIENT); sqlite3_result_text(ctx,new_feature.c_str(),new_feature.size(),SQLITE_TR ANSIENT);
} }
} }
#endif #endif
#endif
void feature_recorder::dump_histogram_db(const histogram_def &def,void *user,fea ture_recorder::dump_callback_t cb) const void feature_recorder::dump_histogram_db(const histogram_def &def,void *user,fea ture_recorder::dump_callback_t cb) const
{ {
#ifdef USE_SQLITE3 #ifdef USE_SQLITE3
/* First check to see if there exists a feature histogram summary. If not, m ake it */ /* First check to see if there exists a feature histogram summary. If not, m ake it */
std::string query = "SELECT name FROM sqlite_master WHERE type='table' AND n ame='h_" + def.feature +"'"; std::string query = "SELECT name FROM sqlite_master WHERE type='table' AND n ame='h_" + def.feature +"'";
char *errmsg=0; char *errmsg=0;
int rowcount=0; int rowcount=0;
if (sqlite3_exec(fs.db3,query.c_str(),callback_counter,&rowcount,&errmsg)){ if (sqlite3_exec(fs.db3,query.c_str(),callback_counter,&rowcount,&errmsg)){
std::cerr << "sqlite3: " << errmsg << "\n"; std::cerr << "sqlite3: " << errmsg << "\n";
 End of changes. 5 change blocks. 
1 lines changed or deleted 7 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)