Imported Upstream version 14.45.0
[platform/upstream/libzypp.git] / zypp / media / MediaManager.h
index 49d73e2..049da47 100644 (file)
 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
 #define ZYPP_MEDIA_MEDIAMANAGER_H
 
-#include <zypp/media/MediaAccess.h>
+#include "zypp/media/MediaAccess.h"
 
-#include <zypp/base/Deprecated.h>
-#include <zypp/base/NonCopyable.h>
-#include <zypp/base/PtrTypes.h>
-#include <zypp/Pathname.h>
-#include <zypp/Url.h>
+#include "zypp/APIConfig.h"
+#include "zypp/base/NonCopyable.h"
+#include "zypp/base/PtrTypes.h"
+#include "zypp/Pathname.h"
+#include "zypp/Url.h"
 
 #include <list>
 
@@ -216,7 +216,7 @@ namespace zypp
      *       Mandatory parameter specifying the name of the block device of
      *       the partition to mount.
      *     - <tt>filesystem</tt>:
-     *       The name of the filesystem. Defaults to "auto". 
+     *       The name of the filesystem. Defaults to "auto".
      *   - Authority:
      *     A non-empty authority URL component is not allowed.
      *   - Path name:
@@ -234,7 +234,7 @@ namespace zypp
      *       "file:/directory/name"
      *     \endcode
      *   - Query parameters:
-     *     none 
+     *     none
      *   - Authority:
      *     A non-empty authority URL component (e.g. containing
      *     a host name) is not allowed.
@@ -253,7 +253,7 @@ namespace zypp
      *
      *       "iso:/?iso=CD1.iso&url=nfs://server/path/to/media"
      *       "iso:/?iso=CD1.iso&url=hd:/?device=/dev/hda"
-     * 
+     *
      *        "iso:/subdir?iso=DVD1.iso&url=nfs://nfs-server/directory&mnt=/nfs/attach/point&filesystem=udf"
      *     \endcode
      *   - Query parameters:
@@ -265,13 +265,13 @@ namespace zypp
      *       Optional parameter specifying the URL to the directory containing
      *       the iso file.<br>
      *       The supported URL schemes are: <i><b>hd</b>, <b>dir</b>,
-     *       <b>file</b>, <b>nfs</b>, <b>smb</b>, <b>cifs</b>.</i>
+     *       <b>file</b>, <b>nfs</b>, <b>nfs4</b>, <b>smb</b>, <b>cifs</b>.</i>
      *     - <tt>mnt</tt>:
      *       Optional parameter specifying the prefered attach point for the
      *       source media url.
      *     - <tt>filesystem</tt>:
      *       Optional name of the filesystem used in the iso file. Defaults
-     *       to "auto". 
+     *       to "auto".
      *   - Authority:
      *     A non-empty authority URL component is not allowed.
      *   - Path name:
@@ -282,16 +282,21 @@ namespace zypp
      * The access handler for media on NFS exported directory tree.
      *   - Scheme:
      *     - <b>nfs</b>
+     *     - <b>nfs</b>
      *   - Examples:
      *     \code
      *        "nfs://nfs-server/exported/path"
      *        "nfs://nfs-server/exported/path?mountoptions=ro"
+     *        "nfs://nfs-server/exported/path&type=nfs4"
+     *        "nfs4://nfs-server/exported/path"
      *     \endcode
      *   - Query parameters:
      *     - <tt>mountoptions</tt>:
      *       The mount options separated by comma ','.
      *       Default is the "ro" option.
-     *   - Authority:
+     *     - <tt>type=nfs4</tt>:
+     *       Whether to mount as nfs4. This is the default for scheme nfs4.
+      *   - Authority:
      *     The authority component has to provide a hostname.
      *     Username, password and port are currently ignored.
      *   - Path name:
@@ -308,6 +313,7 @@ namespace zypp
      *     \code
      *       "cifs://servername/share/path/on/the/share"
      *       "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
+     *       "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=noguest"
      *       "smb://servername/share/path/on/the/share"
      *       "smb://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
      *     \endcode
@@ -316,17 +322,19 @@ namespace zypp
      *   - Query parameters:
      *     - <tt>mountoptions</tt>:
      *       The mount options separated by a comma ','. Default are the
-     *       "ro" and "guest" options.
-     *     - <tt>workgroup</tt>:
+     *       "ro" and "guest" options. Specify "noguest" to turn off
+     *       "guest". This is necessary if Samba is configured to reject
+     *       guest connections.
+     *     - <tt>workgroup</tt> or <tt>domain</tt>:
      *       The name of the workgroup.
      *     - <tt>username</tt>:
      *       Alternative username to username in URL authority.
      *     - <tt>password</tt>:
      *       Alternative password to password in URL authority.
      *     - <tt>user</tt>:
-     *       Alternative username (cifs specific variant?)
+     *       Alternative username (cifs specific variant)
      *     - <tt>pass</tt>:
-     *       Alternative password (cifs specific variant?)
+     *       Alternative password (cifs specific variant)
      *   - Authority:
      *     The authority component has to provide a hostname. Optionally
      *     also a username and password.
@@ -334,10 +342,11 @@ namespace zypp
      *     Mandatory URL component, that specifies the share name with
      *     optional subdirectory, where the desired files are located.
      *
-     * \subsection MediaCurl_Url MediaCurl - FTP/HTTP directory tree (ftp, http, https) 
+     * \subsection MediaCurl_Url MediaCurl - FTP/HTTP directory tree (ftp, tftp, http, https)
      * The access handler to media directory tree on a ftp/http server.
      *   - Scheme:
      *     - <b>ftp</b>
+     *     - <b>tftp</b>
      *     - <b>http</b>
      *     - <b>https</b>
      *   - Examples:
@@ -371,8 +380,12 @@ namespace zypp
      *     "ftp://user:pass@server/%2fhome/user/path/to/media" -- both
      *     URLs points to the same directory on the server.
      *   - Query parameters:
+     *     - <tt>cookies</tt>:
+     *       Turn off using cookies by setting it to "0" (or false, no, off).
      *     - <tt>proxy</tt>:
      *       A proxy hostname or hostname and port separated by ':'.
+     *       Setting the hostname to '_none_' explicitly disables the use of a
+     *       proxy even if configured in /etc/sysconfig/proxy or the environment.
      *     - <tt>proxyport</tt>:
      *       Alternative way to provide the proxy port.
      *     - <tt>proxyuser</tt>:
@@ -390,11 +403,15 @@ namespace zypp
      *         enables ssl verify, this is the default
      *         and is equivalent to 'host,peer'.
      *       - 'host': The server is considered the intended one, when the
-     *         'Common Name' field or a 'Subject Alternate Name' field in 
+     *         'Common Name' field or a 'Subject Alternate Name' field in
      *         the certificate matches the host name in the URL.
      *       - 'peer': Verifies whether the certificate provided by the
      *         server is authentic against the chain of digital signatures
-     *         found in <tt>ssl_capath</tt>. 
+     *         found in <tt>ssl_capath</tt>.
+     *     - <tt>ssl_clientcert</tt>
+     *       Path to the ssl client certificate for authentication to a repo (CURLOPT_SSLCERT).
+     *     - <tt>ssl_clientkey</tt>
+     *       Path to the ssl client key for authentication to a repo (CURLOPT_SSLKEY).
      *     - <tt>timeout</tt>:
      *       Transfer timeout in seconds between 0 and 3600, 0 disables
      *       the timeout, default timeout is 180 seconds.
@@ -402,7 +419,9 @@ namespace zypp
      *       method names to use: 'basic', 'digest', 'ntlm', 'negotiate',
      *       'spnego', 'gssnego'.
      *       Note, that this list depends on the list of methods supported
-     *       by the curl library. 
+     *       by the curl library.
+     *     - <tt>mediahandler</tt>: Set the mediahandler for this url
+     *     Valid values are: 'curl', 'multicurl'
      *   - Authority:
      *     The authority component has to provide a hostname. Optionally
      *     also a username and password. In case of the 'ftp' scheme,
@@ -422,6 +441,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
     {
@@ -505,19 +552,6 @@ namespace zypp
       downloads(MediaAccessId accessId) const;
 
       /**
-       * Hint if files will be downloaded when using the
-       * specified media \p url.
-       *
-       * @note This hint is based on the \p url scheme
-       * only and does not imply, that the URL is valid.
-       *
-       * @param url The media URL to check.
-       * @return True, if the files are downloaded.
-       */
-      static bool
-      downloads(const Url &url);
-
-      /**
        * Returns the \ref MediaAccessUrl of the media access id.
        *
        * \param accessId The media access id to query.
@@ -567,35 +601,36 @@ namespace zypp
       setAttachPrefix(const Pathname &attach_prefix);
 
       /**
-       * Attach the media using the concrete handler.
+       * Attach the media using the concrete handler (checks all devices).
        *
        * Remember to release() or close() each id you've attached
        * and not need any more. Attach is like an open of a file!
        *
        * \param accessId A media access id.
-       * \param next     Whether to try the next drive if avaliable.
        * \throws MediaNotOpenException for invalid access id.
        */
       void
-      attach(MediaAccessId accessId, bool next = false);
+      attach(MediaAccessId accessId);
 
       /**
        * Release the attached media and optionally eject.
        *
-       * If the \p eject parameter is set to true and there
-       * is currently an attached drive, all other access
-       * id's are released and the drive (CD/DVD drive) is
+       * If the \p ejectDev parameter is not empty all other access
+       * id's are released and the specified drive (CD/DVD drive) is
        * ejected.
-       * In case that there is currently no attached drive,
-       * a \p eject set to true causes to eject all drives
-       * that are _not_ used by another access id's.
        *
        * \param accessId A media access id.
-       * \param eject    Whether to eject the drive.
+       * \param ejectDev Device to eject. None if empty.
        * \throws MediaNotOpenException for invalid access id.
        */
       void
-      release(MediaAccessId accessId, bool eject = false);
+      release(MediaAccessId accessId, const std::string & ejectDev = "");
+
+      /**
+       * Release all attached media.
+       */
+      void
+      releaseAll();
 
       /**
        * Disconnect a remote media.
@@ -662,6 +697,20 @@ namespace zypp
                      const MediaVerifierRef &verifier) const;
 
       /**
+       * Simple check, based on media's URL scheme, telling whether the
+       * it is possible to physically change the media inside its drive, like
+       * CDs or DVDs. Useful to decide whether to request media change from
+       * user or not.
+       *
+       * \param accessId The media access id.
+       * \return <tt>false</tt> if the media is not changeable,
+       *         <tt>true</tt> otherwise.
+       * \throws MediaNotOpenException for invalid access id.
+       */
+      bool
+      isChangeable(MediaAccessId accessId);
+
+      /**
        * Return the local directory that corresponds to medias url,
        * no matter if media isAttached or not. Files requested will
        * be available at 'localRoot() + filename' or even better
@@ -699,14 +748,6 @@ namespace zypp
        *
        * \param accessId  The media access id to use.
        * \param filename  The filename to provide, relative to localRoot().
-       * \param cached    If cached is set to true, the function checks, if
-       *                  the file already exists and doesn't download it again
-       *                  if it does. Currently only the existence is checked,
-       *                  no other file attributes.
-       * \param checkonly If this and 'cached' are set to true only the
-       *                  existence of the file is checked but it's not
-       *                  downloaded. If 'cached' is unset an errer is
-       *                  returned always.
        *
        * \throws MediaNotOpenException in case of invalid access id.
        * \throws MediaNotAttachedException in case, that the media is not attached.
@@ -717,11 +758,10 @@ namespace zypp
        * \throws MediaSystemException in case a system operation fails.
        * \throws MediaException derived exception, depending on the url (handler).
        */
+
       void
       provideFile(MediaAccessId   accessId,
-                  const Pathname &filename,
-                  bool            cached    = false,
-                  bool            checkonly = false) const;
+                  const Pathname &filename ) const;
 
       /**
        * FIXME: see MediaAccess class.
@@ -781,6 +821,25 @@ namespace zypp
        */
       bool doesFileExist(MediaAccessId  accessId,
                          const Pathname & filename ) const;
+
+      /**
+       * Fill in a vector of detected ejectable devices and the index of the
+       * currently attached device within the vector. The contents of the vector
+       * are the device names (/dev/cdrom and such).
+       *
+       * \param accessId Medium id.
+       * \param devices  vector to load with the device names
+       * \param index    index of the currently used device in the devices vector
+       */
+      void
+      getDetectedDevices(MediaAccessId accessId,
+                         std::vector<std::string> & devices,
+                         unsigned int & index) const;
+
+      void
+      setDeltafile(MediaAccessId   accessId,
+                  const Pathname &filename ) const;
+
     public:
       /**
        * Get the modification time of the /etc/mtab file.