00001 #ifndef __rconfig_h__
00002 #define __rconfig_h__
00003
00004 #include <iostream>
00005 #include <fstream>
00006 #include <string>
00007 #include <vector>
00008 #include <map>
00009
00010 #include "asserts.h"
00011 #include "types.h"
00012 #include "tstamp.h"
00013
00014
00015
00016 class parser;
00017 class parse_job;
00018
00019
00020
00021
00022
00023 class archive_path_element
00024 {
00025 public:
00026 enum element_type {
00027 jobname,
00028 groupname,
00029 hostname,
00030 pathname,
00031 permutation,
00032 literal
00033 };
00034
00035 void clear(void);
00036
00037 archive_path_element();
00038 archive_path_element(const archive_path_element& a_class);
00039 archive_path_element(const element_type& a_enum);
00040 archive_path_element(const std::string& a_str);
00041
00042 void assign(const archive_path_element& a_class);
00043 void assign(const element_type& a_enum);
00044 void assign(const std::string& a_str);
00045
00046 const element_type& type(void) const;
00047 const std::string& value(void) const;
00048 const std::string str(void) const;
00049
00050 archive_path_element& operator=(const archive_path_element& a_class);
00051 archive_path_element& operator=(const element_type a_enum);
00052 archive_path_element& operator=(const std::string& a_str);
00053
00054 private:
00055 element_type m_type;
00056 std::string m_literal;
00057 };
00058
00059
00060
00061
00062
00063 class archive_path : public std::vector<archive_path_element>
00064 {
00065 public:
00066 typedef std::vector<archive_path_element> type;
00067
00068 void reset(void);
00069
00070 archive_path();
00071 archive_path(const archive_path& a_class);
00072 archive_path(const archive_path_element& a_class);
00073 archive_path(const std::string& a_class);
00074
00075 void push_back(const archive_path& a_class);
00076 void push_back(const archive_path_element& a_class);
00077 void push_back(const std::string& a_str);
00078
00079 void assign(const archive_path& a_class);
00080 void assign(const archive_path_element& a_class);
00081 void assign(const std::string& a_str);
00082
00083 const std::string str(void) const;
00084
00085 archive_path& operator=(const archive_path& a_class);
00086 archive_path& operator=(const archive_path_element& a_class);
00087 archive_path& operator=(const std::string& a_str);
00088
00089 private:
00090 };
00091
00092
00093
00094
00095 class rsync_behavior
00096 {
00097 public:
00098 enum behavior_type {
00099 quit,
00100 fail,
00101 retry,
00102 retry_without_hardlinks,
00103 ok
00104 };
00105 typedef behavior_type value_type;
00106 typedef std::map<uint16, value_type> map_type;
00107 static const uint16 default_behavior = ((uint16)-1);
00108
00109 void clear(void);
00110 void reset(void);
00111
00112 rsync_behavior();
00113 rsync_behavior(const rsync_behavior& a_class);
00114
00115 void assign(const uint16 a_code, const value_type a_action);
00116 void assign(const rsync_behavior& a_class);
00117 void assign(const std::string& a_str);
00118
00119 const value_type operator[](const uint16 a_code) const;
00120 value_type& operator[](const uint16 a_code);
00121 rsync_behavior& operator=(const rsync_behavior& a_class);
00122 rsync_behavior& operator=(const behavior_type a_enum);
00123 rsync_behavior& operator=(const std::string& a_str);
00124
00125 const value_type default_value(void) const;
00126 const map_type& map_value(void) const;
00127
00128 private:
00129 map_type m_map;
00130 value_type m_default;
00131 };
00132
00133 class configuration_manager;
00134
00135
00136 class job
00137 {
00138 public:
00139 enum rsync_connection_type {
00140 connection_remote,
00141 connection_local,
00142 connection_server
00143 };
00144 enum rsync_behavior_type {
00145 behavior_ok,
00146 behavior_fail,
00147 behavior_retry,
00148 behavior_retry_without_hardlinks
00149 };
00150 typedef std::vector<std::string> excludes_type;
00151 typedef std::vector<std::string> includes_type;
00152 typedef std::vector<std::string> paths_type;
00153
00154 job();
00155 job(const job& a_job);
00156
00157 void clear(void);
00158 void assign(const job& a_job);
00159
00160 job& operator=(const job& a_job);
00161
00162 std::string default_config_path;
00163 uint16 default_config_line;
00164 std::string config_path;
00165 uint16 config_line;
00166 class archive_path archive_path;
00167 excludes_type excludes;
00168 includes_type includes;
00169 std::string groupname;
00170 std::string hostname;
00171 std::string jobname;
00172 paths_type paths;
00173 class rsync_behavior rsync_behavior;
00174 rsync_connection_type rsync_connection;
00175 bool rsync_hardlink;
00176 std::string rsync_options;
00177 std::string rsync_remote_user;
00178 std::string rsync_remote_path;
00179 std::string rsync_remote_module;
00180 uint16 rsync_remote_port;
00181 uint16 rsync_retry_count;
00182 uint16 rsync_timeout;
00183
00184 const std::string generate_archive_path(const std::string& a_path) const;
00185 const std::string generate_source_path(const std::string& a_path) const;
00186 const std::string generate_job_id(void) const;
00187 void check(void);
00188
00189 private:
00190
00191 friend class parser;
00192 };
00193
00194
00195 class configuration_manager
00196 {
00197 public:
00198 enum action_type {
00199 action_help,
00200 action_version,
00201 action_archive,
00202 action_relink,
00203 action_check_config
00204 };
00205 enum cfgfile_type {
00206 config_file,
00207 job_file,
00208 };
00209 enum overflow_type {
00210 overflow_quit,
00211 overflow_delete_oldest,
00212 overflow_delete_until_free
00213 };
00214 enum selection_type {
00215 selection_round_robin,
00216 selection_max_free
00217 };
00218 enum logging_type {
00219 logging_manager,
00220 logging_child,
00221 logging_rsync
00222 };
00223 typedef std::pair<cfgfile_type, std::string> cfgfile_element;
00224 typedef std::vector<cfgfile_element> cfgfiles_type;
00225 typedef std::vector<job> jobs_type;
00226 typedef std::vector<std::string> vaults_type;
00227
00228 void clear(void);
00229
00230 configuration_manager();
00231
00232 void init(int argc, char *argv[]);
00233 void check(void) const;
00234 const bool initialized(void) const;
00235
00236 const action_type action(void) const;
00237 const bool use_default(void) const;
00238 void default_file(const std::string& a_path);
00239 const std::string& default_file(void) const;
00240 void default_logdir(const std::string& a_path);
00241 const class timestamp& timestamp(void) const;
00242 const std::string& link_catalog_dir(void) const;
00243 const std::string& log_dir(void) const;
00244 const std::string& rsync_local_path(void) const;
00245 const uint16& rsync_parallel(void) const;
00246 const uint16& io_poll_interval(void) const;
00247 const timestamp::resolution_type timestamp_resolution(void) const;
00248 const vaults_type& vaults(void) const;
00249 const overflow_type& vault_overflow_behavior(void) const;
00250 const uint16& vault_overflow_blocks(void) const;
00251 const uint16& vault_overflow_inodes(void) const;
00252 const selection_type& vault_selection_behavior(void) const;
00253 const job& default_job(void) const;
00254 const jobs_type& jobs(void) const;
00255 const logging_type& logging_level(void) const;
00256
00257 private:
00258 bool m_initialized;
00259 uint16 m_configs_read;
00260 std::string m_default_file;
00261 action_type m_action;
00262 bool m_default;
00263 class timestamp m_timestamp;
00264 class cfgfiles_type m_cfgfiles;
00265 std::string m_link_catalog_dir;
00266 std::string m_log_dir;
00267 std::string m_rsync_local_path;
00268 uint16 m_rsync_parallel;
00269 uint16 m_io_poll_interval;
00270 std::vector<std::string> m_vaults;
00271 overflow_type m_vault_overflow_behavior;
00272 uint16 m_vault_overflow_blocks;
00273 uint16 m_vault_overflow_inodes;
00274 selection_type m_vault_selection_behavior;
00275 job m_default_job;
00276 jobs_type m_jobs;
00277 logging_type m_logging_level;
00278
00279 friend class global_parser;
00280 friend class job_parser;
00281
00282 void read_config(const std::string& a_path);
00283 void read_job(const std::string& a_path);
00284 };
00285
00286 void parse_line(
00287 std::istream& a_in,
00288 std::string& a_keyword,
00289 std::string& a_value
00290 );
00291
00292
00293
00294
00295 class global_parser
00296 {
00297 public:
00298 global_parser(
00299 const std::string& a_path,
00300 uint16& a_line,
00301 std::istream& a_in
00302 );
00303
00304 private:
00305 const std::string* m_path;
00306 std::istream* m_in;
00307 uint16* m_line;
00308
00309 const std::string location(void);
00310 void read_config(const std::string& a_path);
00311 void read_job(const std::string& a_path, job& a_job);
00312
00313 void parse(void);
00314 void parse_default(const std::string& a_value);
00315 void parse_include(const std::string& a_value);
00316 void parse_include_job(const std::string& a_value);
00317 void parse_job(const std::string& a_value);
00318 void parse_link_catalog_dir(const std::string& a_value);
00319 void parse_log_dir(const std::string& a_value);
00320 void parse_logging_level(const std::string& a_value);
00321 void parse_rsync_local_path(const std::string& a_value);
00322 void parse_rsync_parallel(const std::string& a_value);
00323 void parse_io_poll_interval(const std::string& a_value);
00324 void parse_timestamp_resolution(const std::string& a_value);
00325 void parse_vault(const std::string& a_value);
00326 void parse_vault_overflow_behavior(const std::string& a_value);
00327 void parse_vault_overflow_blocks(const std::string& a_value);
00328 void parse_vault_overflow_inodes(const std::string& a_value);
00329 void parse_vault_selection_behavior(const std::string& a_value);
00330 };
00331
00332
00333
00334
00335 class job_parser
00336 {
00337 public:
00338 job_parser(
00339 job * a_job,
00340 const std::string& a_path,
00341 uint16& a_line,
00342 std::istream& a_in,
00343 const std::string& a_block_delimiter,
00344 const bool a_default_context
00345 );
00346
00347 private:
00348 job* m_job;
00349 const std::string* m_path;
00350 std::istream* m_in;
00351 uint16* m_line;
00352 const std::string* m_delimiter;
00353 bool m_default_context;
00354
00355 const std::string location(void);
00356 void job_parser::read_job(const std::string& a_path);
00357
00358 void parse(void);
00359 void parse_archive_path(const std::string& a_value);
00360 void parse_clear(const std::string& a_value);
00361 void parse_exclude_from(const std::string& a_value);
00362 void parse_include_from(const std::string& a_value);
00363 void parse_groupname(const std::string& a_value);
00364 void parse_hostname(const std::string& a_value);
00365 void parse_include(const std::string& a_value);
00366 void parse_jobname(const std::string& a_value);
00367 void parse_path(const std::string& a_value);
00368 void parse_rsync_behavior(const std::string& a_value);
00369 void parse_rsync_connection_type(const std::string& a_value);
00370 void parse_rsync_hardlink(const std::string& a_value);
00371 void parse_rsync_options(const std::string& a_value);
00372 void parse_rsync_options_context(const std::string& a_value);
00373 void parse_rsync_remote_user(const std::string& a_value);
00374 void parse_rsync_remote_path(const std::string& a_value);
00375 void parse_rsync_remote_port(const std::string& a_value);
00376 void parse_rsync_remote_module(const std::string& a_value);
00377 void parse_rsync_retry_count(const std::string& a_value);
00378 void parse_rsync_timeout(const std::string& a_value);
00379 };
00380
00381 extern configuration_manager config;
00382
00383 #endif