File: mediaconfig.cc

package info (click to toggle)
libzypp 17.36.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 26,380 kB
  • sloc: cpp: 132,576; xml: 2,587; sh: 486; makefile: 26; python: 23
file content (130 lines) | stat: -rw-r--r-- 4,293 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
/*---------------------------------------------------------------------\
|                          ____ _   __ __ ___                          |
|                         |__  / \ / / . \ . \                         |
|                           / / \ V /|  _/  _/                         |
|                          / /__ | | | | | |                           |
|                         /_____||_| |_| |_|                           |
|                                                                      |
\---------------------------------------------------------------------*/
/** \file zypp-media/mediaconfig.cc
 *
*/

#include "mediaconfig.h"
#include <zypp-core/Pathname.h>
#include <zypp-core/base/String.h>

namespace zypp {

  class MediaConfigPrivate {
  public:

    MediaConfigPrivate()
      : download_max_concurrent_connections( 5 )
      , download_min_download_speed	( 0 )
      , download_max_download_speed	( 0 )
      , download_max_silent_tries	( 1 )
      , download_transfer_timeout	( 180 )
      , download_connect_timeout        ( 60 )
    { }

    Pathname credentials_global_dir_path;
    Pathname credentials_global_file_path;

    int download_max_concurrent_connections;
    int download_min_download_speed;
    int download_max_download_speed;
    int download_max_silent_tries;
    int download_transfer_timeout;
    int download_connect_timeout;

  };

  MediaConfig::MediaConfig() : d_ptr( new MediaConfigPrivate() )
  { }

  MediaConfig &MediaConfig::instance()
  {
    static MediaConfig instance;
    return instance;
  }

  bool MediaConfig::setConfigValue( const std::string &section, const std::string &entry, const std::string &value )
  {
    Z_D();
    if ( section == "main" ) {
      if ( entry == "credentials.global.dir" ) {
        d->credentials_global_dir_path = Pathname(value);
        return true;
      } else if ( entry == "credentials.global.file" ) {
        d->credentials_global_file_path = Pathname(value);
        return true;

      } else if ( entry == "download.max_concurrent_connections" ) {
        str::strtonum(value, d->download_max_concurrent_connections);
        return true;

      } else if ( entry == "download.min_download_speed" ) {
        str::strtonum(value, d->download_min_download_speed);
        return true;

      } else if ( entry == "download.max_download_speed" ) {
        str::strtonum(value, d->download_max_download_speed);
        return true;

      } else if ( entry == "download.max_silent_tries" ) {
        str::strtonum(value, d->download_max_silent_tries);
        return true;

      } else if ( entry == "download.connect_timeout" ) {
        str::strtonum(value, d->download_connect_timeout);
        if ( d->download_connect_timeout < 0 )
          d->download_connect_timeout = 0;
        return true;

      } else if ( entry == "download.transfer_timeout" ) {
        str::strtonum(value, d->download_transfer_timeout);
        if ( d->download_transfer_timeout < 0 )		d->download_transfer_timeout = 0;
        else if ( d->download_transfer_timeout > 3600 )	d->download_transfer_timeout = 3600;
        return true;
      }
    }
    return false;
  }

  Pathname MediaConfig::credentialsGlobalDir() const
  {
    Z_D();
    return ( d->credentials_global_dir_path.empty() ?
               Pathname("/etc/zypp/credentials.d") : d->credentials_global_dir_path );
  }

  Pathname MediaConfig::credentialsGlobalFile() const
  {
    Z_D();
    return ( d->credentials_global_file_path.empty() ?
               Pathname("/etc/zypp/credentials.cat") : d->credentials_global_file_path );
  }

  long MediaConfig::download_max_concurrent_connections() const
  { return d_func()->download_max_concurrent_connections; }

  long MediaConfig::download_min_download_speed() const
  { return d_func()->download_min_download_speed; }

  long MediaConfig::download_max_download_speed() const
  { return d_func()->download_max_download_speed; }

  long MediaConfig::download_max_silent_tries() const
  { return d_func()->download_max_silent_tries; }

  long MediaConfig::download_transfer_timeout() const
  { return d_func()->download_transfer_timeout; }

  long MediaConfig::download_connect_timeout() const
  { return d_func()->download_connect_timeout; }

  ZYPP_IMPL_PRIVATE(MediaConfig)
}