add url-option to select specific mediahandler
[platform/upstream/libzypp.git] / zypp / media / MediaManager.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/media/MediaManager.h
10  *
11 */
12 #ifndef ZYPP_MEDIA_MEDIAMANAGER_H
13 #define ZYPP_MEDIA_MEDIAMANAGER_H
14
15 #include <zypp/media/MediaAccess.h>
16
17 #include <zypp/base/Deprecated.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/Pathname.h>
21 #include <zypp/Url.h>
22
23 #include <list>
24
25
26 //////////////////////////////////////////////////////////////////////
27 namespace zypp
28 { ////////////////////////////////////////////////////////////////////
29
30   ////////////////////////////////////////////////////////////////////
31   namespace media
32   { //////////////////////////////////////////////////////////////////
33
34
35     ///////////////////////////////////////////////////////////////////
36     typedef zypp::RW_pointer<MediaAccess> MediaAccessRef;
37
38     // OBSOLETE HERE:
39     typedef MediaAccessId                 MediaId;
40     typedef unsigned int                  MediaNr;
41
42
43     ///////////////////////////////////////////////////////////////////
44     // forward declaration
45     class MountEntry;
46     class MediaManager_Impl;
47
48     ///////////////////////////////////////////////////////////////////
49     //
50     // CLASS NAME : MediaVerifierBase
51     //
52     /**
53      * Interface to implement a media verifier.
54      */
55     class MediaVerifierBase //: private zypp::NonCopyable
56     {
57     public:
58       MediaVerifierBase()
59       {}
60
61       virtual
62       ~MediaVerifierBase()
63       {}
64
65       /**
66        * Returns a string with some info about the verifier.
67        * By default, the type info name is returned.
68        */
69       virtual std::string
70       info() const;
71
72       /*
73       ** Check if the specified attached media contains
74       ** the desired media (e.g. SLES10 CD1).
75       */
76       virtual bool
77       isDesiredMedia(const MediaAccessRef &ref) = 0;
78     };
79
80
81     ///////////////////////////////////////////////////////////////////
82     //
83     // CLASS NAME : NoVerifier
84     //
85     /**
86      * Dummy default media verifier, which is always happy.
87      */
88     class NoVerifier : public MediaVerifierBase
89     {
90     public:
91       NoVerifier(): MediaVerifierBase()
92       {}
93
94       virtual
95       ~NoVerifier()
96       {}
97
98       /**
99        * Returns the "zypp::media::NoVerifier" string.
100        */
101       virtual std::string
102       info() const;
103
104       /*
105       ** Don't check if the specified attached media contains
106       ** the desired media number. Always return true.
107       */
108       virtual bool
109       isDesiredMedia(const MediaAccessRef &ref)
110       {
111         (void)ref;
112         return true;
113       }
114     };
115
116
117     ///////////////////////////////////////////////////////////////////
118     //
119     // CLASS NAME : MediaVerifierRef
120     //
121     /**
122      * A shared reference to the MediaVerifier implementation.
123      */
124     typedef zypp::RW_pointer<MediaVerifierBase> MediaVerifierRef;
125
126
127     ///////////////////////////////////////////////////////////////////
128     //
129     // CLASS NAME : MediaManager
130     //
131     /**
132      * Manages access to the 'physical' media, e.g CDROM drives,
133      * Disk volumes, directory trees, etc, using \ref MediaAccessUrl's.
134      *
135      * \note The MediaManager class is just an envelope around an
136      *       inner singleton like implementation.<br>
137      *       That is, you can create as many managers as you want,
138      *       also temporary in a function call.<br>
139      *       But <b>don't</b> declare static MediaManager instances,
140      *       unless you want to force (mutex) initialization order
141      *       problems!
142      *
143      * \section MediaAccessUrl Media Access Url
144      * The MediaManager uses several media access handlers (backends),
145      * that can be specified by a Media Access URL in its open() method.
146      *
147      * All URL's may contain following query parameters, that are
148      * reserved by the Source classes and unused/ignored by the media
149      * manager:
150      * - <tt>alias</tt>: A source specific media alias string.
151      *
152      * Currently, following access handlers (backends) are implemented:
153      *   - \ref MediaCD_Url
154      *   - \ref MediaDISK_Url
155      * .
156      *   - \ref MediaISO_Url
157      *   - \ref MediaDIR_Url
158      * .
159      *   - \ref MediaNFS_Url
160      *   - \ref MediaCIFS_Url
161      *   - \ref MediaCurl_Url
162      *
163      * \subsection MediaCD_Url MediaCD - CD/DVD drives (cd, dvd)
164      * The access handler for media on CD / DVD drives.
165      *   - Scheme:
166      *     - <b>cd</b>: Requires a drive supporting CD media.
167      *     - <b>dvd</b>: Prefers a drive supporting DVD media.
168      *   - Examples:
169      *     \code
170      *       "cd:/"
171      *       "cd:/?devices=/dev/hda,/dev/hdb"
172      *       "cd:/subdir?devices=/dev/hda,/dev/hdb"
173      *
174      *       "dvd:/"
175      *       "dvd:/?devices=/dev/hda,/dev/hdb"
176      *       "dvd:/subdir?devices=/dev/hda,/dev/hdb"
177      *     \endcode
178      *     Note: You can use either "dvd:/" (just path, no authority)
179      *           or "dvd:///" (path and empty authority).
180      *   - Query parameters:
181      *     - <tt>devices</tt>:
182      *       Optional parameter, containing a comma separated list of
183      *       block device names to use, e.g.: "/dev/sr0,/dev/sr1".
184      *       <br>
185      *       The device names will be verified using a HAL query. If one
186      *       of the provided devices is not usable (not a block device,
187      *       or does not support required media type), an exception is
188      *       thrown.
189      *       <br>
190      *       If the devices parameter is not provided (or empty), all
191      *       avaliable CD/DVD drives 'detected' using a HAL query. The
192      *       preferred drive (used as first drive) is the drive pointed
193      *       to by the symlink "/dev/dvd" ("dvd" scheme only) or
194      *       "/dev/cdrom".
195      *   - Authority:
196      *     A non-empty authority URL component (e.g. containing a host
197      *     name) is not allowed.
198      *   - Path name:
199      *     Mandatory URL component, that specifies a subdirectory on the
200      *     CD/DVD, where the desired files are located.
201      *
202      * \subsection MediaDISK_Url MediaDISK - HD disk volumes (hd)
203      * The access handler for media on a disk volume (partition).
204      *   - Scheme:
205      *     - <b>hd</b>
206      *   - Examples:
207      *     \code
208      *       "hd:/?device=/dev/hda1"
209      *       "hd:/subdir?device=/dev/sda1"
210      *       "hd:/subdir?device=/dev/sda1&filesystem=reiserfs"
211      *     \endcode
212      *     Note: You can use either "hd:/" (just path, no authority)
213      *     or "hd:///" (path and empty authority).
214      *   - Query parameters:
215      *     - <tt>device</tt>:
216      *       Mandatory parameter specifying the name of the block device of
217      *       the partition to mount.
218      *     - <tt>filesystem</tt>:
219      *       The name of the filesystem. Defaults to "auto".
220      *   - Authority:
221      *     A non-empty authority URL component is not allowed.
222      *   - Path name:
223      *     Mandatory URL component, that specifies a subdirectory on the disk
224      *     partition, where the desired files are located.
225      *
226      * \subsection MediaDIR_Url MediaDIR - Local directory tree (dir, file)
227      * The access handler to media stored in a local directory tree.
228      *   - Scheme:
229      *     - <b>dir</b>
230      *     - <b>file</b>
231      *   - Examples:
232      *     \code
233      *       "dir:/directory/name"
234      *       "file:/directory/name"
235      *     \endcode
236      *   - Query parameters:
237      *     none
238      *   - Authority:
239      *     A non-empty authority URL component (e.g. containing
240      *     a host name) is not allowed.
241      *   - Path name:
242      *     Mandatory URL component, that specifies a directory, where
243      *     the desired files are located.
244      *
245      * \subsection MediaISO_Url MediaISO - Loopback ISO images (iso)
246      * The access handler for media in a ISO image (loopback mount).
247      *   - Scheme:
248      *     - <b>iso</b>
249      *   - Examples:
250      *     \code
251      *       "iso:/?iso=/path/to/CD1.iso"
252      *       "iso:/?iso=CD1.iso&url=dir:/path/to"
253      *
254      *       "iso:/?iso=CD1.iso&url=nfs://server/path/to/media"
255      *       "iso:/?iso=CD1.iso&url=hd:/?device=/dev/hda"
256      *
257      *        "iso:/subdir?iso=DVD1.iso&url=nfs://nfs-server/directory&mnt=/nfs/attach/point&filesystem=udf"
258      *     \endcode
259      *   - Query parameters:
260      *     - <tt>iso</tt>:
261      *       Mandatory parameter specifying the name of the iso file.<br>
262      *       If the url parameter is missed, the iso parameter has to contain
263      *       an absolute iso file name.
264      *     - <tt>url</tt>:
265      *       Optional parameter specifying the URL to the directory containing
266      *       the iso file.<br>
267      *       The supported URL schemes are: <i><b>hd</b>, <b>dir</b>,
268      *       <b>file</b>, <b>nfs</b>, <b>nfs4</b>, <b>smb</b>, <b>cifs</b>.</i>
269      *     - <tt>mnt</tt>:
270      *       Optional parameter specifying the prefered attach point for the
271      *       source media url.
272      *     - <tt>filesystem</tt>:
273      *       Optional name of the filesystem used in the iso file. Defaults
274      *       to "auto".
275      *   - Authority:
276      *     A non-empty authority URL component is not allowed.
277      *   - Path name:
278      *     Mandatory URL component, that specifies a subdirectory inside of
279      *     the iso file, where the desired files are located.
280      *
281      * \subsection MediaNFS_Url MediaNFS  - NFS directory tree (nfs)
282      * The access handler for media on NFS exported directory tree.
283      *   - Scheme:
284      *     - <b>nfs</b>
285      *     - <b>nfs</b>
286      *   - Examples:
287      *     \code
288      *        "nfs://nfs-server/exported/path"
289      *        "nfs://nfs-server/exported/path?mountoptions=ro"
290      *        "nfs://nfs-server/exported/path&type=nfs4"
291      *        "nfs4://nfs-server/exported/path"
292      *     \endcode
293      *   - Query parameters:
294      *     - <tt>mountoptions</tt>:
295      *       The mount options separated by comma ','.
296      *       Default is the "ro" option.
297      *     - <tt>type=nfs4</tt>:
298      *       Whether to mount as nfs4. This is the default for scheme nfs4.
299       *   - Authority:
300      *     The authority component has to provide a hostname.
301      *     Username, password and port are currently ignored.
302      *   - Path name:
303      *     Mandatory URL component, that specifies the exported
304      *     (sub-)directory on the NFS server, where the desired
305      *     files are located.
306      *
307      * \subsection MediaCIFS_Url MediaCIFS - CIFS/SMB directory tree (cifs, smb)
308      * The access handler for media in a CIFS/SMB shared directory tree.
309      *   - Scheme:
310      *     - <b>cifs</b>
311      *     - <b>smb</b>
312      *   - Examples:
313      *     \code
314      *       "cifs://servername/share/path/on/the/share"
315      *       "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
316      *       "cifs://username:passwd@servername/share/path/on/the/share?mountoptions=noguest"
317      *       "smb://servername/share/path/on/the/share"
318      *       "smb://username:passwd@servername/share/path/on/the/share?mountoptions=ro"
319      *     \endcode
320      *     Note: There is no difference between cifs and smb scheme
321      *     (any more). In both cases the 'cifs' filesystem is used.
322      *   - Query parameters:
323      *     - <tt>mountoptions</tt>:
324      *       The mount options separated by a comma ','. Default are the
325      *       "ro" and "guest" options. Specify "noguest" to turn off
326      *       "guest". This is necessary if Samba is configured to reject
327      *       guest connections.
328      *     - <tt>workgroup</tt> or <tt>domain</tt>:
329      *       The name of the workgroup.
330      *     - <tt>username</tt>:
331      *       Alternative username to username in URL authority.
332      *     - <tt>password</tt>:
333      *       Alternative password to password in URL authority.
334      *     - <tt>user</tt>:
335      *       Alternative username (cifs specific variant)
336      *     - <tt>pass</tt>:
337      *       Alternative password (cifs specific variant)
338      *   - Authority:
339      *     The authority component has to provide a hostname. Optionally
340      *     also a username and password.
341      *   - Path name:
342      *     Mandatory URL component, that specifies the share name with
343      *     optional subdirectory, where the desired files are located.
344      *
345      * \subsection MediaCurl_Url MediaCurl - FTP/HTTP directory tree (ftp, http, https)
346      * The access handler to media directory tree on a ftp/http server.
347      *   - Scheme:
348      *     - <b>ftp</b>
349      *     - <b>http</b>
350      *     - <b>https</b>
351      *   - Examples:
352      *     \code
353      *       "ftp://server/relative/path/to/media/dir"
354      *       "ftp://server/%2fabsolute/path/to/media/dir"
355      *
356      *       "ftp://user:pass@server/path/to/media/dir"
357      *       "ftp://user:pass@server/%2f/home/user/path/to/media/dir"
358      *
359      *       "http://server/path/on/server"
360      *       "http://user:pass@server/path"
361      *       "https://user:pass@server/path?proxy=foo&proxyuser=me&proxypass=pw"
362      *     \endcode
363      *     Note: The "ftp" url scheme supports absolute and relative
364      *     paths to the default ftp server directory
365      *     (<a href="http://rfc.net/rfc1738.html">RFC1738, Section 3.2.2</a>).<br>
366      *     To use an absolute path, you have to prepend the path with an
367      *     additional slash, what results in a "/%2f" combination
368      *     (second "/" encoded to "%2f") at the begin of the URL path.
369      *     <br>
370      *     This is important, especially in user authenticated ftp,
371      *     where the users home is usually the default directory of the
372      *     server (except when the server chroots into the users home
373      *     directory).
374      *     <br>
375      *     For example, if the user "user" has a home directory
376      *     "/home/user", you can use either an URL with a relative path
377      *     to the home directory "ftp://user:pass@server/path/to/media"
378      *     or the absolute path
379      *     "ftp://user:pass@server/%2fhome/user/path/to/media" -- both
380      *     URLs points to the same directory on the server.
381      *   - Query parameters:
382      *     - <tt>cookies</tt>:
383      *       Turn off using cookies by setting it to "0" (or false, no, off).
384      *     - <tt>proxy</tt>:
385      *       A proxy hostname or hostname and port separated by ':'.
386      *     - <tt>proxyport</tt>:
387      *       Alternative way to provide the proxy port.
388      *     - <tt>proxyuser</tt>:
389      *       The proxy username.
390      *     - <tt>proxypass</tt>:
391      *       The proxy password.
392      *     - <tt>ssl_capath</tt>:
393      *       The absolute CA directory to use, default is /etc/ssl/certs.
394      *     - <tt>ssl_verify</tt>: Flag to modify the ssl verify behaviour.
395      *       Valid values are: 'yes', 'no' and a comma separated list of
396      *       'host' and 'peer' flags.
397      *       - 'no':
398      *         disables ssl verify
399      *       - 'yes':
400      *         enables ssl verify, this is the default
401      *         and is equivalent to 'host,peer'.
402      *       - 'host': The server is considered the intended one, when the
403      *         'Common Name' field or a 'Subject Alternate Name' field in
404      *         the certificate matches the host name in the URL.
405      *       - 'peer': Verifies whether the certificate provided by the
406      *         server is authentic against the chain of digital signatures
407      *         found in <tt>ssl_capath</tt>.
408      *     - <tt>timeout</tt>:
409      *       Transfer timeout in seconds between 0 and 3600, 0 disables
410      *       the timeout, default timeout is 180 seconds.
411      *     - <tt>auth</tt>: A comma separated list of http authentication
412      *       method names to use: 'basic', 'digest', 'ntlm', 'negotiate',
413      *       'spnego', 'gssnego'.
414      *       Note, that this list depends on the list of methods supported
415      *       by the curl library.
416      *     - <tt>mediahandler</tt>: Set the mediahandler for this url
417      *     Valid values are: 'curl', 'multicurl', 'aria2c'
418      *   - Authority:
419      *     The authority component has to provide a hostname. Optionally
420      *     also a username and password. In case of the 'ftp' scheme,
421      *     username and password defaults to 'anonymous' and 'yast2@'.
422      *   - Path name:
423      *     Mandatory URL component, that specifies the path name on the
424      *     server, where the desired files are located.
425      *
426      *   Proxy settings: If no proxy settings are present in tha URLs
427      *   query parameters, the media handler reads the system wide proxy
428      *   settings from the <tt>/etc/sysconfig/proxy</tt> file.
429      *   If a proxy setting was present, but the proxy password not,
430      *   it attempts to read the <tt>proxy-user</tt> variable from the
431      *   <tt>~/.curlrc</tt> (<tt>/root/.curlrc</tt>) file.
432      *   <br>
433      *   If no proxy setting was present, then libzypp does not pass any
434      *   proxy settings to curl, but curl fallbacks to use the content of
435      *   the <tt>http_proxy</tt>, <tt>ftp_proxy</tt>, etc environment
436      *   variables.
437      *
438      * \subsection MediaPlugin_Url MediaPlugin - custom media handler
439      * Media access is delegated to a script located in the libzypp
440      * media plugin directory. The URLs query options are translated
441      * into commandline arguments passed to the script.
442      *   - Scheme:
443      *     - <b>plugin</b>
444      *   - Examples:
445      *     \code
446      *       "plugin:script?loptv=lvalue&v=optv&lopt=&o&=foo"
447      *                      \__________/ \____/ \___/ | \_/
448      *                __________/__    ____/_    _|_  \   \___
449      *              /              \ /       \ /    \ /\ /    \
450      *       script --loptv "lvalue" -v "optv" --lopt -o -- foo
451      *     \endcode
452      *   - Query parameters:
453      *     - The URLs query options are translated into commandline
454      *       arguments passed to the script.
455      *     - \b Note: No option may appear twice, as the <tt>(option,value)</tt>
456      *       pairs are stored in a hash.
457      *     - \b Note: The order in which the query options are passes to the
458      *       script is arbitrary, except for an option with an empty key, which
459      *       is translated into <tt>'-- value'</tt> and passed as final option.
460      *     - <tt>'c[=[value]]'</tt> ist passed as <tt>'-c [value]'</tt>
461      *     - <tt>'word[=[value]]'</tt> ist passed as <tt>'--word [value]'</tt>
462      *     - <tt>'[=value]'</tt> ist passed as last args as <tt>'-- [value]'</tt>
463      *   - \c script<->libzypp communication:
464      *     - \TODO to be documented.
465      */
466     class MediaManager: private zypp::base::NonCopyable
467     {
468     public:
469       /**
470        * Creates a MediaManager envelope instance.
471        *
472        * In the case, that the inner implementation is not already
473        * allocated, and the MediaManager constructor was unable to
474        * allocate it, a std::bad_alloc exception is thrown.
475        *
476        * All further instances increase the use counter only.
477        *
478        * \throws std::bad_alloc
479        */
480       MediaManager();
481
482       /**
483        * Destroys MediaManager envelope instance.
484        * Decreases the use counter of the inner implementation.
485        */
486       ~MediaManager();
487
488       /**
489        * Opens the media access for specified with the url.
490        *
491        * If the \p preferred_attach_point parameter does not
492        * point to a usable attach point directory, the media
493        * manager automatically creates a temporary attach
494        * point in a default directory. This default directory
495        * can be changed using setAttachPrefix() function.
496        *
497        * Remember to close() each id you've opened and not
498        * need any more. It is like a new and delete!
499        *
500        * \param  url The \ref MediaAccessUrl.
501        * \param  preferred_attach_point The preferred, already
502        *         existing directory, where the media should be
503        *         attached.
504        * \return a new media access id.
505        * \throws std::bad_alloc
506        * \throws MediaException
507        */
508       MediaAccessId
509       open(const Url &url, const Pathname & preferred_attach_point = "");
510
511       /**
512        * Close the media access with specified id.
513        * \param accessId The media access id to close.
514        */
515       void
516       close(MediaAccessId accessId);
517
518       /**
519        * Query if the media access is open / exists.
520        *
521        * \param accessId The media access id to query.
522        * \return true, if access id is known and open.
523        */
524       bool
525       isOpen(MediaAccessId accessId) const;
526
527       /**
528        * Query the protocol name used by the media access
529        * handler. Similar to url().getScheme().
530        *
531        * \param accessId The media access id to query.
532        * \return The protocol name used by the media access
533        *         handler, otherwise 'unknown'.
534        * \throws MediaNotOpenException for invalid access id.
535        */
536       std::string
537       protocol(MediaAccessId accessId) const;
538
539       /**
540        * Hint if files are downloaded or not.
541        * \param accessId The media access id to query.
542        * \return True, if provideFile downloads files.
543        */
544       bool
545       downloads(MediaAccessId accessId) const;
546
547      /** \deprecated Use \ref Url::schemeIsDownloading */
548       static
549       ZYPP_DEPRECATED bool downloads(const Url &url)
550       { return url.schemeIsDownloading(); }
551
552       /**
553        * Returns the \ref MediaAccessUrl of the media access id.
554        *
555        * \param accessId The media access id to query.
556        * \return The \ref MediaAccessUrl used by the media access id.
557        * \throws MediaNotOpenException for invalid access id.
558        */
559       Url
560       url(MediaAccessId accessId) const;
561
562     public:
563       /**
564        * Add verifier implementation for the specified media id.
565        * By default, the NoVerifier is used.
566        *
567        * \param accessId A media access id.
568        * \param verifier The new verifier.
569        * \throws MediaNotOpenException for invalid access id.
570        */
571       void
572       addVerifier(MediaAccessId accessId,
573                   const MediaVerifierRef &verifier);
574
575       /**
576        * Remove verifier for specified media id.
577        * It resets the verifier to NoVerifier.
578        *
579        * \param accessId A media access id.
580        * \throws MediaNotOpenException for invalid access id.
581        */
582       void
583       delVerifier(MediaAccessId accessId);
584
585     public:
586       /**
587        * Set or resets the directory name, where the media manager
588        * handlers create their temporary attach points (see open()
589        * function).
590        * It has effect to newly created temporary attach points only.
591        *
592        * \param attach_prefix The new prefix for temporary attach
593        *        points, or empty pathname to reset to defaults.
594        * \return True on success, false if the \p attach_prefix
595        *         parameters contains a path name, that does not
596        *         point to a writable directory.
597        */
598       bool
599       setAttachPrefix(const Pathname &attach_prefix);
600
601       /**
602        * Attach the media using the concrete handler (checks all devices).
603        *
604        * Remember to release() or close() each id you've attached
605        * and not need any more. Attach is like an open of a file!
606        *
607        * \param accessId A media access id.
608        * \throws MediaNotOpenException for invalid access id.
609        */
610       void
611       attach(MediaAccessId accessId);
612
613       /** \deprecated Simply use \ref attach. */
614       ZYPP_DEPRECATED void attachDesiredMedia(MediaAccessId accessId)
615       { attach( accessId ); }
616
617       /**
618        * Release the attached media and optionally eject.
619        *
620        * If the \p ejectDev parameter is not empty all other access
621        * id's are released and the specified drive (CD/DVD drive) is
622        * ejected.
623        *
624        * \param accessId A media access id.
625        * \param ejectDev Device to eject. None if empty.
626        * \throws MediaNotOpenException for invalid access id.
627        */
628       void
629       release(MediaAccessId accessId, const std::string & ejectDev = "");
630
631       /**
632        * Release all attached media.
633        */
634       void
635       releaseAll();
636
637       /**
638        * Disconnect a remote media.
639        *
640        * This is useful for media which e.g. holds open a connection
641        * to a server like FTP. After calling disconnect() the media
642        * object (attach point) is still valid and files are present.
643        *
644        * But after calling disconnect() it's not possible to call
645        * fetch more data using the provideFile() or provideDir()
646        * functions anymore.
647        *
648        * \param accessId A media access id.
649        * \throws MediaNotOpenException for invalid access id.
650        */
651       void
652       disconnect(MediaAccessId accessId);
653
654       /**
655        * Check if media is attached or not.
656        *
657        * \param accessId A media access id.
658        * \return True if media is attached.
659        * \throws MediaNotOpenException for invalid access id.
660        */
661       bool
662       isAttached(MediaAccessId accessId) const;
663
664       /**
665        * Returns information if media is on a shared
666        * physical device or not.
667        *
668        * \param accessId A media access id.
669        * \return True if it is shared, false if not.
670        * \throws MediaNotOpenException for invalid access id.
671        */
672       bool
673       isSharedMedia(MediaAccessId accessId) const;
674
675       /**
676        * Ask the registered verifier if the attached
677        * media is the desired one or not.
678        *
679        * \param accessId A media access id.
680        * \return True if media is attached and desired
681        *         according to the actual verifier.
682        * \throws MediaNotOpenException for invalid access id.
683        */
684       bool
685       isDesiredMedia(MediaAccessId accessId) const;
686
687       /**
688        * Ask the specified verifier if the attached
689        * media is the desired one or not.
690        *
691        * \param accessId A media access id.
692        * \param verifier A verifier to use.
693        * \return True if media is attached and desired
694        *         according to the specified verifier.
695        * \throws MediaNotOpenException for invalid access id.
696        */
697       bool
698       isDesiredMedia(MediaAccessId           accessId,
699                      const MediaVerifierRef &verifier) const;
700
701       /**
702        * Simple check, based on media's URL scheme, telling whether the
703        * it is possible to physically change the media inside its drive, like
704        * CDs or DVDs. Useful to decide whether to request media change from
705        * user or not.
706        *
707        * \param accessId The media access id.
708        * \return <tt>false</tt> if the media is not changeable,
709        *         <tt>true</tt> otherwise.
710        * \throws MediaNotOpenException for invalid access id.
711        */
712       bool
713       isChangeable(MediaAccessId accessId);
714
715       /**
716        * Return the local directory that corresponds to medias url,
717        * no matter if media isAttached or not. Files requested will
718        * be available at 'localRoot() + filename' or even better
719        * 'localPath( filename )'
720        *
721        * \param accessId A media access id.
722        * \returns The directory name pointing to the media root
723        *          in local filesystem or an empty pathname if the
724        *          media is not attached.
725        * \throws MediaNotOpenException for invalid access id.
726        */
727       Pathname
728       localRoot(MediaAccessId accessId) const;
729
730       /**
731        * Shortcut for 'localRoot() + pathname', but returns an empty
732        * pathname if media is not attached.
733        * Files provided will be available at 'localPath(filename)'.
734        *
735        * \param accessId A media access id.
736        * \param pathname A path name relative to the localRoot().
737        * \returns The directory name in local filesystem pointing
738        *          to the desired relative pathname on the media
739        *          or an empty pathname if the media is not attached.
740        * \throws MediaNotOpenException for invalid access id.
741        */
742       Pathname
743       localPath(MediaAccessId accessId, const Pathname & pathname) const;
744
745     public:
746       /**
747        * Provide provide file denoted by relative path below of the
748        * 'attach point' of the specified media and the path prefix
749        * on the media.
750        *
751        * \param accessId  The media access id to use.
752        * \param filename  The filename to provide, relative to localRoot().
753        *
754        * \throws MediaNotOpenException in case of invalid access id.
755        * \throws MediaNotAttachedException in case, that the media is not attached.
756        * \throws MediaNotDesiredException in case, that the media verification failed.
757        * \throws MediaNotAFileException in case, that the requested filename is not a file.
758        * \throws MediaFileNotFoundException in case, that the requested filenamedoes not exists.
759        * \throws MediaWriteException in case, that the file can't be copied from from remote source.
760        * \throws MediaSystemException in case a system operation fails.
761        * \throws MediaException derived exception, depending on the url (handler).
762        */
763
764       void
765       provideFile(MediaAccessId   accessId,
766                   const Pathname &filename ) const;
767
768       /**
769        * FIXME: see MediaAccess class.
770        */
771       void
772       provideDir(MediaAccessId   accessId,
773                  const Pathname &dirname) const;
774
775       /**
776        * FIXME: see MediaAccess class.
777        */
778       void
779       provideDirTree(MediaAccessId  accessId,
780                      const Pathname &dirname) const;
781
782       /**
783        * FIXME: see MediaAccess class.
784        */
785       void
786       releaseFile(MediaAccessId   accessId,
787                   const Pathname &filename) const;
788
789       /**
790        * FIXME: see MediaAccess class.
791        */
792       void
793       releaseDir(MediaAccessId   accessId,
794                  const Pathname &dirname) const;
795
796       /**
797        * FIXME: see MediaAccess class.
798        */
799       void
800       releasePath(MediaAccessId   accessId,
801                   const Pathname &pathname) const;
802
803       /**
804        * FIXME: see MediaAccess class.
805        */
806       void
807       dirInfo(MediaAccessId           accessId,
808               std::list<std::string> &retlist,
809               const Pathname         &dirname,
810               bool                    dots = true) const;
811
812       /**
813        * FIXME: see MediaAccess class.
814        */
815       void
816       dirInfo(MediaAccessId           accessId,
817               filesystem::DirContent &retlist,
818               const Pathname         &dirname,
819               bool                   dots = true) const;
820
821       /**
822        * FIXME: see MediaAccess class.
823        */
824       bool doesFileExist(MediaAccessId  accessId,
825                          const Pathname & filename ) const;
826
827       /**
828        * Fill in a vector of detected ejectable devices and the index of the
829        * currently attached device within the vector. The contents of the vector
830        * are the device names (/dev/cdrom and such).
831        *
832        * \param accessId Medium id.
833        * \param devices  vector to load with the device names
834        * \param index    index of the currently used device in the devices vector
835        */
836       void
837       getDetectedDevices(MediaAccessId accessId,
838                          std::vector<std::string> & devices,
839                          unsigned int & index) const;
840
841       void
842       setDeltafile(MediaAccessId   accessId,
843                   const Pathname &filename ) const;
844
845     public:
846       /**
847        * Get the modification time of the /etc/mtab file.
848        * \return Modification time of the /etc/mtab file.
849        */
850       static time_t
851       getMountTableMTime();
852
853       /**
854        * Get current mount entries from /etc/mtab file.
855        * \return Current mount entries from /etc/mtab file.
856        */
857       static std::vector<MountEntry>
858       getMountEntries();
859
860       /**
861        * Check if the specified \p path is useable as
862        * attach point.
863        *
864        * \param path The attach point to check.
865        * \param mtab Whether to check against the mtab, too.
866        * \return True, if it is a directory and there are
867        *         no another attach points bellow of it.
868        */
869       bool
870       isUseableAttachPoint(const Pathname &path,
871                            bool            mtab=true) const;
872
873     private:
874       friend class MediaHandler;
875
876       /**
877        * \internal
878        * Return the attached media reference of the specified
879        * media access id. Used to resolve nested attachments
880        * as used in the MediaISO (iso-loop) handler.
881        * Causes temporary creation of a shared attachment
882        * (increases reference counters on attachedMedia).
883        * \param media A media access id.
884        */
885       AttachedMedia
886       getAttachedMedia(MediaAccessId &accessId) const;
887
888       /**
889        * \internal
890        * Called by media handler in while attach() to retrieve
891        * attached media reference matching the specified media
892        * source reference.
893        * Causes temporary creation of a shared attachment
894        * (increases reference counters on attachedMedia).
895        * \param media The media source reference to search for.
896        */
897       AttachedMedia
898       findAttachedMedia(const MediaSourceRef &media) const;
899
900       /**
901        * \internal
902        * Called by media handler in case of relase(eject=true)
903        * to release all access id's using the specified media.
904        * Causes temporary creation of a shared attachment
905        * (increases reference counters on attachedMedia).
906        * \param media The media source reference to release.
907        */
908       void
909       forceReleaseShared(const MediaSourceRef &media);
910
911     private:
912       /**
913        * Static reference to the implementation (singleton).
914        */
915       static zypp::RW_pointer<MediaManager_Impl> m_impl;
916     };
917
918
919     //////////////////////////////////////////////////////////////////
920   } // namespace media
921   ////////////////////////////////////////////////////////////////////
922
923   ////////////////////////////////////////////////////////////////////
924 } // namespace zypp
925 //////////////////////////////////////////////////////////////////////
926
927 #endif // ZYPP_MEDIA_MEDIAMANAGER_H
928
929 /*
930 ** vim: set ts=2 sts=2 sw=2 ai et:
931 */