Kinda got it working ... :-/
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 17 Oct 2008 14:10:58 +0000 (14:10 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 17 Oct 2008 14:10:58 +0000 (14:10 +0000)
12 files changed:
tests/lib/CMakeLists.txt
tests/lib/WebServer.cc
tests/lib/WebServer.h
tests/zypp/CMakeLists.txt
tests/zypp/Fetcher_test.cc
tests/zypp/data/Fetcher/remote-site/complexdir-broken/directory.yast [new file with mode: 0644]
tests/zypp/data/Fetcher/remote-site/complexdir-broken/subdir1/directory.yast [new file with mode: 0644]
tests/zypp/data/Fetcher/remote-site/complexdir-broken/subdir2/directory.yast [new file with mode: 0644]
tests/zypp/data/Fetcher/remote-site/complexdir/directory.yast [new file with mode: 0644]
tests/zypp/data/Fetcher/remote-site/complexdir/subdir1/directory.yast [new file with mode: 0644]
tests/zypp/data/Fetcher/remote-site/complexdir/subdir2/directory.yast [new file with mode: 0644]
tests/zypp/data/Fetcher/remote-site/directory.yast [new file with mode: 0644]

index d08b738ad391f1f6cff994746e19e48b9eaffe1d..71ec305bbf8171d9d80c1064354667f33b2ef95c 100644 (file)
@@ -7,4 +7,4 @@ ADD_LIBRARY(zypp_test_utils
  WebServer.cc
 )
 
-TARGET_LINK_LIBRARIES(zypp_test_utils shttp zypp)
+TARGET_LINK_LIBRARIES(zypp_test_utils shttp zypp boost_thread-mt)
index b3edc664d2923c8996eaaec77b0142a388b78732..1b6d9e4636821c870492ad7e422b976050381f38 100644 (file)
 using namespace zypp;
 
 #include "shttpd.h"
-
+#include "boost/bind.hpp"
 #include "WebServer.h"
 
+#define LISTENING_PORT "8080"
+
+static shttpd_ctx * do_init_ctx()
+{
+    static char *argv[] = {"a", "-ports", LISTENING_PORT, NULL};
+    static int argc = sizeof(argv) / sizeof(argv[0]) - 1;
+    shttpd_ctx *ctx;
+    
+    ctx = shttpd_init(argc, argv);
+    return ctx;
+}
+
 WebServer::WebServer(const Pathname root, unsigned int port)
-    : _docroot(root), _port(port)
+    : _docroot(root), _port(port), _stop(false)
 {
-    _ctx = shttpd_init(0, NULL);
-    shttpd_set_option(_ctx, "root", root.c_str());
-    shttpd_set_option(_ctx, "ports", str::numstring(port).c_str());
+    // init with a user port
+    _ctx = do_init_ctx();    
+    setStrOption("root", root.asString());
+    setNumOption("ports", port);
+}
 
+void WebServer::start()
+{
+//    _thrd.reset( new boost::thread(web_thread(_ctx)) );
+    _thrd.reset( new boost::thread( boost::bind(&WebServer::worker_thread, this) ) );
 }
 
-void WebServer::operator()()
+void WebServer::worker_thread()
 {
-    for (;;)
+    while( ! _stop )
         shttpd_poll(_ctx, 1000);
 }
 
+
+void WebServer::setStrOption( std::string name, std::string value)
+{
+    if ( ! shttpd_set_option(_ctx, name.c_str(),
+                             value.c_str() ) )
+        ZYPP_THROW(Exception("bad option"));    
+}
+
+void WebServer::setNumOption( std::string name, int value)
+{
+    if ( ! shttpd_set_option(_ctx, name.c_str(),
+                             str::numstring(value).c_str()) )
+        ZYPP_THROW(Exception("bad ioption"));    
+}
+
+void WebServer::stop()
+{
+    _stop = true;
+    _thrd->join();
+    _thrd.reset();
+}
+
 WebServer::~WebServer()
 {
     shttpd_fini(_ctx);
index 45d948e9263d75333e551382dd5fadac57933886..51cfdd3f20943fc3d2366377881da1355801e9bb 100644 (file)
@@ -2,24 +2,35 @@
 #ifndef ZYPP_WEBSERVER_H
 #define ZYPP_WEBSERVER_H
 
+#include "boost/thread.hpp"
+#include "boost/smart_ptr.hpp"
+
 #include "zypp/Pathname.h"
+#include "zypp/base/PtrTypes.h"
 
 struct shttpd_ctx;
 
 class WebServer
 {
  public:
-  WebServer(const zypp::Pathname root, unsigned int port);
+  WebServer(const zypp::Pathname root, unsigned int port=9099);
   ~WebServer();
   void start();
-  
-  void operator()();
 
+  void stop();
 
  private:
+
+  void setStrOption( std::string name, std::string value);
+  void setNumOption( std::string name, int value);
+
+  void worker_thread();
    struct shttpd_ctx *_ctx;
    zypp::Pathname _docroot;
    unsigned int _port;
+   zypp::shared_ptr<boost::thread> _thrd;
+   bool _stop;
 };
 
 #endif
index 81ed86c84d8ebc5763d297dba21dfe352d1b1545..742e25c7db76b4fd6f0f3eb7f45402c01e0c964a 100644 (file)
@@ -32,4 +32,3 @@ ADD_TESTS(
   Vendor2
 )
 
-#TARGET_LINK_LIBRARIES(Fetcher_test boost_thread-mt)
\ No newline at end of file
index 95fa88f585dcdb1d51b4d4d4c606ae0093b98507..05b096ffd4956ff824692e935f5d0a351e115a74 100644 (file)
@@ -78,6 +78,33 @@ BOOST_AUTO_TEST_CASE(fetcher)
   //MIL << fetcher;
 }
 
+BOOST_AUTO_TEST_CASE(fetcher_remove)
+{
+  // at this point the key is already trusted
+  {
+      // add the key as trusted
+      //getZYpp()->keyRing()->importKey(PublicKey(DATADIR + "/complexdir/subdir1/SHA1SUMS.key"), true);
+
+      WebServer web((Pathname(TESTS_SRC_DIR) + "/zypp/data/Fetcher/remote-site").c_str() );
+      web.start();
+
+      MediaSetAccess media( Url("http://localhost:9099"), "/" );
+      Fetcher fetcher;
+      filesystem::TmpDir dest;
+
+      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir"), true);
+      fetcher.start( dest.path(), media );
+
+      fetcher.reset();
+
+      fetcher.enqueueDir(OnMediaLocation().setFilename("/complexdir-broken"), true);
+      BOOST_CHECK_THROW( fetcher.start( dest.path(), media ), Exception);  
+
+      fetcher.reset();
+
+      web.stop();
+  }
+}
 
 
 // vim: set ts=2 sts=2 sw=2 ai et:
diff --git a/tests/zypp/data/Fetcher/remote-site/complexdir-broken/directory.yast b/tests/zypp/data/Fetcher/remote-site/complexdir-broken/directory.yast
new file mode 100644 (file)
index 0000000..8c4b36d
--- /dev/null
@@ -0,0 +1,3 @@
+directory.yast
+subdir1/
+subdir2/
diff --git a/tests/zypp/data/Fetcher/remote-site/complexdir-broken/subdir1/directory.yast b/tests/zypp/data/Fetcher/remote-site/complexdir-broken/subdir1/directory.yast
new file mode 100644 (file)
index 0000000..36efc80
--- /dev/null
@@ -0,0 +1,6 @@
+directory.yast
+SHA1SUMS
+SHA1SUMS.asc
+SHA1SUMS.key
+subdir1-file1.txt
+subdir1-file2.txt
diff --git a/tests/zypp/data/Fetcher/remote-site/complexdir-broken/subdir2/directory.yast b/tests/zypp/data/Fetcher/remote-site/complexdir-broken/subdir2/directory.yast
new file mode 100644 (file)
index 0000000..6c2ce07
--- /dev/null
@@ -0,0 +1,5 @@
+directory.yast
+SHA1SUMS
+SHA1SUMS.asc
+SHA1SUMS.key
+subdir2-file1.txt
diff --git a/tests/zypp/data/Fetcher/remote-site/complexdir/directory.yast b/tests/zypp/data/Fetcher/remote-site/complexdir/directory.yast
new file mode 100644 (file)
index 0000000..9be1c91
--- /dev/null
@@ -0,0 +1,2 @@
+subdir1/
+subdir2/
diff --git a/tests/zypp/data/Fetcher/remote-site/complexdir/subdir1/directory.yast b/tests/zypp/data/Fetcher/remote-site/complexdir/subdir1/directory.yast
new file mode 100644 (file)
index 0000000..36efc80
--- /dev/null
@@ -0,0 +1,6 @@
+directory.yast
+SHA1SUMS
+SHA1SUMS.asc
+SHA1SUMS.key
+subdir1-file1.txt
+subdir1-file2.txt
diff --git a/tests/zypp/data/Fetcher/remote-site/complexdir/subdir2/directory.yast b/tests/zypp/data/Fetcher/remote-site/complexdir/subdir2/directory.yast
new file mode 100644 (file)
index 0000000..6c2ce07
--- /dev/null
@@ -0,0 +1,5 @@
+directory.yast
+SHA1SUMS
+SHA1SUMS.asc
+SHA1SUMS.key
+subdir2-file1.txt
diff --git a/tests/zypp/data/Fetcher/remote-site/directory.yast b/tests/zypp/data/Fetcher/remote-site/directory.yast
new file mode 100644 (file)
index 0000000..951afd1
--- /dev/null
@@ -0,0 +1,10 @@
+complexdir/
+complexdir-broken/
+diffs/
+file-1.txt
+file-2.txt
+file-3.txt
+file-4.txt
+file-current.txt
+file-current.txt.asc
+file-current.txt.key