diff options
| -rw-r--r-- | server/configure.in | 9 | ||||
| -rw-r--r-- | server/src/database.cc | 23 | ||||
| -rw-r--r-- | server/src/database.h | 2 | ||||
| -rw-r--r-- | server/src/journal_commit.cc | 17 | ||||
| -rw-r--r-- | server/src/queryhandler.cc | 26 | 
5 files changed, 56 insertions, 21 deletions
| diff --git a/server/configure.in b/server/configure.in index 9d6b803..a5af2c1 100644 --- a/server/configure.in +++ b/server/configure.in @@ -8,10 +8,11 @@ dnl Compile with debug options  dnl ======================  AC_ARG_WITH(debug,  	[  --with-debug            build with debug support (default=no)], -	[with_debug=yes], +	[],  	[with_debug=no])  if test x$with_debug == xyes; then      AC_MSG_WARN([*** Building with debug support!]) +    AC_DEFINE_UNQUOTED(WITH_DEBUG, , [The project is configured to use debug output])      CXXFLAGS="$CXXFLAGS -D_FORTIFY_SOURCE=2 -fstack-protector -Wall -Werror -g -O0"  fi  @@ -24,7 +25,7 @@ AC_ARG_WITH(pentominos,  	[with_pentominos=yes])  if test x$with_pentominos == xno; then      AC_MSG_WARN([*** Building without pentominos support!]) -    CXXFLAGS="$CXXFLAGS -DWITHOUT_PENTOMINOS" +    AC_DEFINE_UNQUOTED(WITHOUT_PENTOMINOS, , [The project is configured not to use pentomimos])  fi   dnl ====================== @@ -36,7 +37,7 @@ AC_ARG_WITH(uploadserver,  	[with_uploadserver=yes])  if test x$with_uploadserver == xno; then      AC_MSG_WARN([*** Building without uploadserver support!]) -    CXXFLAGS="$CXXFLAGS -DWITHOUT_UPLOADSERVER" +    AC_DEFINE_UNQUOTED(WITHOUT_UPLOADSERVER, , [The project is configured not to use the upload server])  fi   dnl ====================== @@ -48,7 +49,7 @@ AC_ARG_WITH(db,  	[with_db=yes])  if test x$with_db == xno; then      AC_MSG_WARN([*** Building without db support!]) -    CXXFLAGS="$CXXFLAGS -DWITHOUT_DB" +    AC_DEFINE_UNQUOTED(WITHOUT_DB, , [The project is configured not to use the db])  fi   AC_PROG_CXX diff --git a/server/src/database.cc b/server/src/database.cc index 2b8b83c..96aa697 100644 --- a/server/src/database.cc +++ b/server/src/database.cc @@ -26,6 +26,8 @@   */  #include "database.h" +#include <config.h> +  Database::Database(std::string hostname, std::string user, std::string password)  #ifndef WITHOUT_DB    : c("host=" + hostname + " user=" + user + " password=" + password + " dbname=pracro") @@ -74,9 +76,12 @@ void Database::commit(std::string user,    oid << R.inserted_oid();  #else    oid << "###GENERATED_OID###"; -  printf("%s\n", ts.c_str());  #endif/*WITHOUT_DB*/ +#ifdef WITH_DEBUG +  printf("%s\n", ts.c_str()); +#endif/*WITH_DEBUG*/ +    std::map< std::string, std::string >::iterator i = fields.begin();    while(i != fields.end()) { @@ -86,9 +91,11 @@ void Database::commit(std::string user,  #ifndef WITHOUT_DB      W.exec(fs); -#else -    printf("%s\n", fs.c_str());  #endif/*WITHOUT_DB*/ + +#ifdef WITH_DEBUG +    printf("%s\n", fs.c_str()); +#endif/*WITH_DEBUG*/      i++;    } @@ -158,9 +165,11 @@ Values Database::getValues(std::string cpr,      ri++;    } -#else -  printf("%s\n", query.str().c_str());  #endif/*WITHOUT_DB*/ + +#ifdef WITH_DEBUG +  printf("%s\n", query.str().c_str()); +#endif/*WITH_DEBUG*/    return values;  } @@ -181,6 +190,10 @@ bool Database::checkMacro(std::string cpr,    query << " AND timestamp >= " << oldest;    query << " ORDER BY timestamp";  +#ifdef WITH_DEBUG +  printf("%s\n", query.str().c_str()); +#endif/*WITH_DEBUG*/ +  #ifndef WITHOUT_DB    try {      pqxx::result R = W.exec(query.str()); diff --git a/server/src/database.h b/server/src/database.h index bd3139e..c15aca5 100644 --- a/server/src/database.h +++ b/server/src/database.h @@ -27,6 +27,8 @@  #ifndef __PRACRO_DATABASE_H__  #define __PRACRO_DATABASE_H__ +#include <config.h> +  #include <pqxx/pqxx>  #include <string> diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index b1ae866..c10e8c7 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -26,6 +26,8 @@   */  #include "journal_commit.h" +#include <config.h> +  // for gethostbyname  #include <netdb.h> @@ -48,18 +50,22 @@ static int mwrite(int sock, const char *fmt, ...)    va_list args;    char *buffer; -  buffer = (char*)malloc(64*1024); +  buffer = (char*)calloc(64*1024, 1);    va_start(args, fmt);    l = vsnprintf(buffer, 64*1024, fmt, args);    va_end(args); -  if(write(sock, buffer, l) != l) { +  if(sock != -1 && write(sock, buffer, l) != l) {      fprintf(stderr, "write did not write all the bytes in the buffer.\n");    }    free(buffer); +#ifdef WITH_DEBUG +  printf(buffer); +#endif/*WITH_DEBUG*/ +    return l;  } @@ -67,7 +73,7 @@ int journal_commit(const char *cpr, const char *user,                     const char *addr, unsigned short int port,                     const char *buf, size_t size)  { -  int sock = 1; +  int sock = -1;  #ifndef WITHOUT_UPLOADSERVER    struct sockaddr_in sin; @@ -116,9 +122,12 @@ int journal_commit(const char *cpr, const char *user,    mwrite(sock, "\r\n");    // send body -  if(write(sock, buf, size) != (ssize_t)size) { +  if(sock != -1 && write(sock, buf, size) != (ssize_t)size) {      fprintf(stderr, "write did not write all the bytes in the buffer.\n");    } +#ifdef WITH_DEBUG +  printf(buf); +#endif/*WITH_DEBUG*/  #ifndef WITHOUT_UPLOADSERVER    // close socket diff --git a/server/src/queryhandler.cc b/server/src/queryhandler.cc index 573ce3a..29e8fda 100644 --- a/server/src/queryhandler.cc +++ b/server/src/queryhandler.cc @@ -26,6 +26,8 @@   */  #include "queryhandler.h" +#include <config.h> +  // For time  #include <time.h> @@ -155,10 +157,12 @@ std::string QueryHandler::exec()      "          xsi:schemaLocation=\"http://www.aasimon.org/pentominos schema.xsd\">\n";  #ifndef WITHOUT_PENTOMINOS    socket->write(header, strlen(header)); -#else -  printf(header);  #endif/*WITHOUT_PENTOMINOS*/ +#ifdef WITH_DEBUG +  printf(header); +#endif/*WITH_DEBUG*/ +    sprintf(buf, "  <pentominos:entry cpr=\"%s\"\n"            "                    src_addr=\"%s\"\n"            "                    dst_addr=\"%s\"\n" @@ -176,10 +180,12 @@ std::string QueryHandler::exec()            uid.c_str());  #ifndef WITHOUT_PENTOMINOS    socket->write(buf, strlen(buf)); -#else -  printf(buf);  #endif/*WITHOUT_PENTOMINOS*/ +#ifdef WITH_DEBUG +  printf(buf); +#endif/*WITH_DEBUG*/ +    std::vector< Query >::iterator j = queries.begin();    while(j != queries.end()) {      Query query = *j; @@ -194,10 +200,12 @@ std::string QueryHandler::exec()  #ifndef WITHOUT_PENTOMINOS      socket->write(buf, strlen(buf)); -#else -    printf(buf);  #endif/*WITHOUT_PENTOMINOS*/ +#ifdef WITH_DEBUG +    printf(buf); +#endif/*WITH_DEBUG*/ +      j++;    } @@ -208,10 +216,12 @@ std::string QueryHandler::exec()    // Terminate    char term[] = "\0";    socket->write(term, 1); -#else -  printf(buf);  #endif/*WITHOUT_PENTOMINOS*/ +#ifdef WITH_DEBUG +  printf(buf); +#endif/*WITH_DEBUG*/ +    std::string answer;  #ifndef WITHOUT_PENTOMINOS | 
