From a973ccf8f29f9f2ff49ed82cdb856ef527f6df17 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 11 May 2013 13:07:14 -0400 Subject: [PATCH] Sync - When taskwarrior is built without GnuTLS, there will be a message to that effect. - Stubbed the TLSClient calling code. The current Socket code will become obsolete soon. --- CMakeLists.txt | 1 - src/commands/CmdSync.cpp | 33 ++++++++++++++++++++++++++++++--- src/en-US.h | 1 + src/es-ES.h | 1 + src/fr-FR.h | 1 + src/it-IT.h | 1 + test/CMakeLists.txt | 8 +++----- 7 files changed, 37 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb6724bea..61ecb0e03 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,7 +90,6 @@ check_function_exists (srandom HAVE_SRANDOM) check_function_exists (timegm HAVE_TIMEGM) check_function_exists (get_current_dir_name HAVE_GET_CURRENT_DIR_NAME) - check_struct_has_member ("struct tm" tm_gmtoff time.h HAVE_TM_GMTOFF) check_struct_has_member ("struct stat" st_birthtime "sys/types.h;sys/stat.h" HAVE_ST_BIRTHTIME) diff --git a/src/commands/CmdSync.cpp b/src/commands/CmdSync.cpp index becbab95e..c8b5ac875 100644 --- a/src/commands/CmdSync.cpp +++ b/src/commands/CmdSync.cpp @@ -29,7 +29,11 @@ #include #include #include -#include +#include +#include // TODO Socket is obsolete. +/* +#include +*/ #include #include #include @@ -51,6 +55,7 @@ CmdSync::CmdSync () int CmdSync::execute (std::string& output) { int status = 0; +#ifdef HAVE_LIBGNUTLS Timer timer_sync; timer_sync.start (); @@ -110,8 +115,8 @@ int CmdSync::execute (std::string& output) std::string code = response.get ("code"); if (code == "200") { - Color colorAdded (context.config.get ("color.sync.added")); - Color colorChanged (context.config.get ("color.sync.changed")); + Color colorAdded (context.config.get ("color.sync.added")); + Color colorChanged (context.config.get ("color.sync.changed")); int download_count = 0; payload = response.getPayload (); @@ -244,6 +249,10 @@ int CmdSync::execute (std::string& output) debug (s.str ()); */ +#else + // Without GnuTLS found at compile time, there is no working sync command. + throw std::string (STRING_CMD_SYNC_NO_TLS); +#endif return status; } @@ -253,6 +262,7 @@ bool CmdSync::send ( const Msg& request, Msg& response) { +#ifdef HAVE_LIBGNUTLS std::string::size_type colon = to.rfind (':'); if (colon == std::string::npos) throw format (STRING_CMD_SYNC_BAD_SERVER, to); @@ -262,6 +272,7 @@ bool CmdSync::send ( try { + // TODO Socket is obsolete. Socket s; s.connect (server, port); s.write (request.serialize () + "\n"); @@ -270,6 +281,21 @@ bool CmdSync::send ( s.read (incoming); s.close (); +/* + // A very basic TLS client, with X.509 authentication. + TLSClient client; + client.debug (); // TODO if (context.config.get ("debug")) + client.limit (1024); // TODO ??? + client.init ("pki/client.cert.pem"); // TODO ??? + client.connect (server, port); + + client.send (request.serialize () + "\n"); + + std::string incoming; + client.recv (incoming); + client.bye (); +*/ + response.parse (incoming); return true; } @@ -280,6 +306,7 @@ bool CmdSync::send ( } // Indicate message failed. +#endif return false; } diff --git a/src/en-US.h b/src/en-US.h index 0e1bad8ce..91bdb75fd 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -416,6 +416,7 @@ #define STRING_CMD_SYNC_FAIL_ERROR "Sync failed. The Task Server returned error: {1} {2}" #define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server." #define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'" +#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_UNKNOWN "" diff --git a/src/es-ES.h b/src/es-ES.h index d1a276b99..049bd1af0 100644 --- a/src/es-ES.h +++ b/src/es-ES.h @@ -427,6 +427,7 @@ #define STRING_CMD_SYNC_FAIL_ERROR "Sincronización fallida. El Servidor Task devolvió error: {1} {2}" #define STRING_CMD_SYNC_FAIL_CONNECT "Sincronización fallida. No se pudo conectar con el Servidor Task." #define STRING_CMD_SYNC_BAD_SERVER "Sincronización fallida. Ajuste de configuración '{1}' incorrecto" +#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_DIAG_USAGE "Detalles de plataforma, construcción y entorno" #define STRING_CMD_DIAG_PLATFORM "Plataforma" diff --git a/src/fr-FR.h b/src/fr-FR.h index b892d7c6c..0bf8a7978 100644 --- a/src/fr-FR.h +++ b/src/fr-FR.h @@ -416,6 +416,7 @@ #define STRING_CMD_SYNC_FAIL_ERROR "Sync failed. The Task Server returned error: {1} {2}" #define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server." #define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'" +#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_UNKNOWN "" diff --git a/src/it-IT.h b/src/it-IT.h index 36af326ff..a3f96886b 100644 --- a/src/it-IT.h +++ b/src/it-IT.h @@ -417,6 +417,7 @@ #define STRING_CMD_SYNC_FAIL_ERROR "Sincronizzazione fallita. Il Task Server ha ritornato l'errore: {1} {2}" #define STRING_CMD_SYNC_FAIL_CONNECT "Sincronizzazione fallita. Impossibile connettersi al Task Server." #define STRING_CMD_SYNC_BAD_SERVER "Sincronizzazione fallita. Impostazione di configurazione '{1}' malformata" +#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_DIAG_USAGE "Dettagli su piattaforma, build e ambiente" #define STRING_CMD_DIAG_PLATFORM "Piattaforma" #define STRING_CMD_DIAG_UNKNOWN "" diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6da3406de..3950a31d9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -16,21 +16,19 @@ if (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) set (TESTBLOB "./*.t") if (CYGWIN) -set (TESTBLOB "./*.t ./*.t.exe") + set (TESTBLOB "./*.t ./*.t.exe") endif (CYGWIN) else (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) set (TESTBLOB "${CMAKE_SOURCE_DIR}/test/*.t ${CMAKE_BINARY_DIR}/test/*.t") if (CYGWIN) -set (TESTBLOB "${CMAKE_SOURCE_DIR}/test/*.t ${CMAKE_BINARY_DIR}/test/*.t.exe") + set (TESTBLOB "${CMAKE_SOURCE_DIR}/test/*.t ${CMAKE_BINARY_DIR}/test/*.t.exe") endif (CYGWIN) endif (${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_BINARY_DIR}) -configure_file ( - run_all.in - run_all) +configure_file (run_all.in run_all) add_custom_target (test ./run_all --verbose DEPENDS ${test_SRCS} task_executable