Add MediaPLUGIN: MediaHandler skeleton for 'plugin:' schema.
authorMichael Andres <ma@suse.de>
Fri, 24 Sep 2010 17:46:57 +0000 (19:46 +0200)
committerMichael Andres <ma@suse.de>
Fri, 24 Sep 2010 17:46:57 +0000 (19:46 +0200)
zypp/CMakeLists.txt
zypp/media/MediaAccess.cc
zypp/media/MediaManager.h
zypp/media/MediaPLUGIN.cc [new file with mode: 0644]
zypp/media/MediaPLUGIN.h [new file with mode: 0644]

index a898dca..9a29691 100644 (file)
@@ -264,6 +264,7 @@ SET( zypp_media_SRCS
   media/MediaMultiCurl.cc
   media/MediaAria2c.cc
   media/MediaISO.cc
+  media/MediaPLUGIN.cc
   media/MediaSource.cc
   media/MediaManager.cc
   media/MediaUserAuth.cc
@@ -289,6 +290,7 @@ SET( zypp_media_HEADERS
   media/MediaException.h
   media/MediaHandler.h
   media/MediaISO.h
+  media/MediaPLUGIN.h
   media/MediaManager.h
   media/MediaNFS.h
   media/MediaSource.h
index f0a769d..ab2e659 100644 (file)
@@ -30,6 +30,7 @@
 #include "zypp/media/MediaAria2c.h"
 #include "zypp/media/MediaMultiCurl.h"
 #include "zypp/media/MediaISO.h"
+#include "zypp/media/MediaPLUGIN.h"
 
 using namespace std;
 
@@ -169,6 +170,8 @@ MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
        else
             _handler = new MediaCurl (url,preferred_attach_point);
     }
+    else if (scheme == "plugin" )
+       _handler = new MediaPLUGIN (url,preferred_attach_point);
     else
     {
        ZYPP_THROW(MediaUnsupportedUrlSchemeException(url));
index 24ae7be..23907ec 100644 (file)
@@ -432,6 +432,34 @@ namespace zypp
      *   proxy settings to curl, but curl fallbacks to use the content of
      *   the <tt>http_proxy</tt>, <tt>ftp_proxy</tt>, etc environment
      *   variables.
+     *
+     * \subsection MediaPlugin_Url MediaPlugin - custom media handler
+     * Media access is delegated to a script located in the libzypp
+     * media plugin directory. The URLs query options are translated
+     * into commandline arguments passed to the script.
+     *   - Scheme:
+     *     - <b>plugin</b>
+     *   - Examples:
+     *     \code
+     *       "plugin:script?loptv=lvalue&v=optv&lopt=&o&=foo"
+     *                      \__________/ \____/ \___/ | \_/
+     *                __________/__    ____/_    _|_  \   \___
+     *              /              \ /       \ /    \ /\ /    \
+     *       script --loptv "lvalue" -v "optv" --lopt -o -- foo
+     *     \endcode
+     *   - Query parameters:
+     *     - The URLs query options are translated into commandline
+     *       arguments passed to the script.
+     *     - \b Note: No option may appear twice, as the <tt>(option,value)</tt>
+     *       pairs are stored in a hash.
+     *     - \b Note: The order in which the query options are passes to the
+     *       script is arbitrary, except for an option with an empty key, which
+     *       is translated into <tt>'-- value'</tt> and passed as final option.
+     *     - <tt>'c[=[value]]'</tt> ist passed as <tt>'-c [value]'</tt>
+     *     - <tt>'word[=[value]]'</tt> ist passed as <tt>'--word [value]'</tt>
+     *     - <tt>'[=value]'</tt> ist passed as last args as <tt>'-- [value]'</tt>
+     *   - \c script<->libzypp communication:
+     *     - \TODO to be documented.
      */
     class MediaManager: private zypp::base::NonCopyable
     {
diff --git a/zypp/media/MediaPLUGIN.cc b/zypp/media/MediaPLUGIN.cc
new file mode 100644 (file)
index 0000000..776a76a
--- /dev/null
@@ -0,0 +1,62 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/MediaPLUGIN.cc
+ *
+*/
+#include <iostream>
+
+#include "zypp/base/LogTools.h"
+#include "zypp/base/String.h"
+
+#include "zypp/ExternalProgram.h"
+
+#include "zypp/media/MediaPLUGIN.h"
+#include "zypp/media/MediaManager.h"
+
+using std::endl;
+
+//////////////////////////////////////////////////////////////////////
+namespace zypp
+{ ////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////
+  namespace media
+  { //////////////////////////////////////////////////////////////////
+
+    MediaPLUGIN::MediaPLUGIN( const Url & url_r, const Pathname & attach_point_hint_r )
+      : MediaHandler( url_r, attach_point_hint_r, /*path below attachpoint*/"/", /*does_download*/false )
+    {
+      MIL << "MediaPLUGIN::MediaPLUGIN(" << url_r << ", " << attach_point_hint_r << ")" << endl;
+    }
+    void MediaPLUGIN::attachTo( bool next_r )
+    {}
+
+    void MediaPLUGIN::releaseFrom( const std::string & ejectDev_r )
+    {}
+
+    void MediaPLUGIN::getFile( const Pathname & filename_r ) const
+    {}
+
+    void MediaPLUGIN::getDir( const Pathname & dirname_r, bool recurse_r ) const
+    {}
+
+    void MediaPLUGIN::getDirInfo( std::list<std::string> & retlist_r, const Pathname & dirname_r, bool dots_r ) const
+    {}
+
+    void MediaPLUGIN::getDirInfo( filesystem::DirContent & retlist_r, const Pathname & dirname_r, bool dots_r ) const
+    {}
+
+    bool MediaPLUGIN::getDoesFileExist( const Pathname & filename_r ) const
+    { return false; }
+
+    //////////////////////////////////////////////////////////////////
+  } // namespace media
+  ////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////
+} // namespace zypp
+//////////////////////////////////////////////////////////////////////
diff --git a/zypp/media/MediaPLUGIN.h b/zypp/media/MediaPLUGIN.h
new file mode 100644 (file)
index 0000000..2a10717
--- /dev/null
@@ -0,0 +1,52 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/media/MediaPLUGIN.h
+ *
+*/
+#ifndef ZYPP_MEDIA_MEDIAPLUGIN_H
+#define ZYPP_MEDIA_MEDIAPLUGIN_H
+
+#include "zypp/media/MediaHandler.h"
+
+//////////////////////////////////////////////////////////////////////
+namespace zypp
+{ ////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////
+  namespace media
+  { //////////////////////////////////////////////////////////////////
+
+    /**
+     * \brief Implementation class for PLUGIN MediaHandler
+     *
+     * @see MediaHandler
+     */
+    class MediaPLUGIN : public MediaHandler
+    {
+      public:
+       MediaPLUGIN( const Url & url_r, const Pathname & attach_point_hint_r );
+
+        virtual ~MediaPLUGIN() { try { release(); } catch(...) {} }
+
+      protected:
+       virtual void attachTo( bool next_r = false );
+       virtual void releaseFrom( const std::string & ejectDev_r );
+       virtual void getFile( const Pathname & filename_r ) const;
+       virtual void getDir( const Pathname & dirname_r, bool recurse_r ) const;
+       virtual void getDirInfo( std::list<std::string> & retlist_r, const Pathname & dirname_r, bool dots_r = true ) const;
+       virtual void getDirInfo( filesystem::DirContent & retlist_r, const Pathname & dirname_r, bool dots_r = true ) const;
+       virtual bool getDoesFileExist( const Pathname & filename_r ) const;
+    };
+
+    //////////////////////////////////////////////////////////////////
+  } // namespace media
+  ////////////////////////////////////////////////////////////////////
+  ////////////////////////////////////////////////////////////////////
+} // namespace zypp
+//////////////////////////////////////////////////////////////////////
+#endif // ZYPP_MEDIA_MEDIAPLUGIN_H