1 // 2 // omi.h 3 // 4 // Oliver Fromme <olli@fromme.com> 5 // @(#)$Id: omi.h,v 1.36 1998/12/04 09:04:47 olli Exp $ 6 // 7 8 #ifndef HAVE_OMI_H 9 #define HAVE_OMI_H 10 11 static const char cvsid_omi_h[] 12 = "@(#)$Id: omi.h,v 1.36 1998/12/04 09:04:47 olli Exp $"; 13 14 #include <sys/types.h> 15 #include <sys/stat.h> 16 17 #include "utils.h" 18 #include "bas.h" 19 #include "lst.h" 20 #include "dir.h" 21 #include "stt.h" 22 23 #define OMI_VERSION "20030719" 24 25 // 26 // Debug flags. 27 // 28 // This is a large bunch of flags, so it is possible to 29 // select the kind (and amount) of debug autput very exactly. 30 // However, these are the most useful ones: 31 // 32 // REPORT Report only on changes to the local mirror, 33 // and why they have changed. This will not 34 // produce any output at all if no updates have 35 // to be done. 36 // 37 // PROGRESS Display progress for long data transfers. 38 // 39 // VERBOSE Verbosely report mirroring activity and FTP 40 // server input/output per file. 41 // 42 // STATS Print final summary statistics if mirroring 43 // activity took place. This will not produce 44 // any output at all if no updates had to be 45 // done. 46 // 47 // STATISTICS Print statistics for every remote / local 48 // directory tree pair, as well as final summary 49 // statistics. 50 // 51 // ALL Report on everything. Warning: this can 52 // generate several megabytes of debug output! 53 // 54 // NONE Report on nothing, be quiet while mirroring. 55 // 56 // The default is REPORT + STATS. Note that error messages 57 // will _always_ be printed, no matter what debug flags are 58 // used. 59 // 60 61 #define DEBUG_ALL 0xfffffff // everything 62 #define DEBUG_NONE 0x0000000 // nothing 63 64 #define DEBUG_OUTPUT 0x0000001 // output to the FTP server 65 #define DEBUG_INPUT 0x0000002 // input from the FTP server 66 #define DEBUG_CREATE_DIRS 0x0000004 // creation of local directories 67 #define DEBUG_CREATE_FILES 0x0000008 // creation of local plain files 68 #define DEBUG_CREATE_LINKS 0x0000010 // creation of local symlinks 69 #define DEBUG_REMOVE_DIRS 0x0000020 // removal of local directories 70 #define DEBUG_REMOVE_FILES 0x0000040 // removal of local plain files 71 #define DEBUG_REMOVE_LINKS 0x0000080 // removal of local symlinks 72 #define DEBUG_REASONING 0x0000100 // reasons for file transfers 73 #define DEBUG_RETRY 0x0000200 // FTP reconnects/retries 74 #define DEBUG_REPORT 0x0000400 // report on mirroring 75 #define DEBUG_STATS 0x0000800 // summary statistics (if activity) 76 #define DEBUG_STATISTICS 0x0001000 // per-pair statistics (always) 77 #define DEBUG_DNS 0x0002000 // DNS look-ups 78 #define DEBUG_CONNECT 0x0004000 // network connections 79 #define DEBUG_XFERRATE 0x0008000 // transfer rates per file 80 #define DEBUG_MULTI 0x0010000 // multi-line server replies & ls -lR 81 #define DEBUG_PARSE 0x0020000 // parse-tree of the remote ls -lR 82 #define DEBUG_CHX 0x0040000 // chmod(), chgrp(), rename() 83 #define DEBUG_REMOTE_REGEX 0x0080000 // remote regular expression matches 84 #define DEBUG_LOCAL_REGEX 0x0100000 // local regular expression matches 85 #define DEBUG_PROGRESS 0x0200000 // progress display 86 87 #define DEBUG_DIRS (DEBUG_CREATE_DIRS | DEBUG_REMOVE_DIRS) 88 #define DEBUG_FILES (DEBUG_CREATE_FILES | DEBUG_REMOVE_FILES) 89 #define DEBUG_LINKS (DEBUG_CREATE_LINKS | DEBUG_REMOVE_LINKS) 90 91 #define DEBUG_CREATE (DEBUG_CREATE_DIRS | DEBUG_CREATE_FILES \ 92 | DEBUG_CREATE_LINKS) 93 94 #define DEBUG_REMOVE (DEBUG_REMOVE_DIRS | DEBUG_REMOVE_FILES \ 95 | DEBUG_REMOVE_LINKS) 96 97 #define DEBUG_SERVER (DEBUG_OUTPUT | DEBUG_INPUT | DEBUG_XFERRATE \ 98 | DEBUG_DNS | DEBUG_CONNECT | DEBUG_RETRY \ 99 | DEBUG_PROGRESS) 100 101 #define DEBUG_MIRROR (DEBUG_CREATE | DEBUG_REMOVE | DEBUG_REASONING) 102 103 #define DEBUG_VERBOSE (DEBUG_SERVER | DEBUG_MIRROR) 104 105 #define DEBUG_REGEX (DEBUG_REMOTE_REGEX | DEBUG_LOCAL_REGEX) 106 107 // 108 // Mirror flags. The default is 0 (i.e. no flags at all). 109 // 110 // GETOLDERFILES Normally, if a file on the local host has 111 // a newer datestamp than the remote file, it 112 // not be retrieved. If you set this flag, 113 // it will be retrieved if the timestamp is 114 // different (no matter whether it's older or 115 // newer). 116 // 117 // PRESERVEDIRS Normally, if a local directory does not 118 // exist anymore on the remote server, it is 119 // removed locally (including all files and 120 // subdirectories in it). If you set this 121 // flag, it will be preserved, and a warning 122 // will be printed (unless you have set the 123 // debug flags to DEBUG_NONE). You will then 124 // have to remove that directory manually, or 125 // (if you want to keep it) add it to the 126 // local exclude list. This is useful if the 127 // remote server is unreliable (i.e. if parts 128 // of it disappear sometimes and then are 129 // back the next day). 130 // 131 // IGNORETIME Ignore the timestamps of remote and local 132 // files when mirroring. I.e. only retrieve 133 // a remote file if it doesn't already exist 134 // locally, or if the file sizes mismatch. 135 // Useful if some stupid cronjob touches all 136 // files on the remote site, even though 137 // their contents don't change. 138 // 139 // DONTTOUCH Do not update the time stamps of local files 140 // to be the same as those of the remote files. 141 // This only makes sense if you also use the 142 // "IgnoreTime" option flag, or the "deviation" 143 // config entry (-t option). 144 // 145 // LOCALTIME Assume that the time stamps of the remote 146 // server are local time. The default (if 147 // this flag is not set) is to use GMT. Most 148 // UNIX-based FTP servers seem to use GMT, so 149 // this flag should not be used normally. 150 // (Note that RFC 959 does not specify the 151 // time zone.) 152 // 153 // EXCLUDEALL Exclude all files by default. In this 154 // case you have to use "Include" (or the -y 155 // command line option) to include files for 156 // mirroring. 157 // 158 // TEST This is for testing / debugging purposes. 159 // If this flag is set, no modifications are 160 // performed (no retrieval or deletion of 161 // files). Useful to test exclusion patterns 162 // etc. without the risk to kill any files if 163 // something doesn't work as expected. 164 // 165 // ACTIVE Use "active" FTP transfers (the default is 166 // to use "passive" FTP transfers). This can 167 // be useful if the FTP server is behind a 168 // firewall, of if the passive mode support 169 // of the server is broken. 170 // 171 // NOSTAT Do not use the "STAT" command to retrieve 172 // a directory listing (use "LIST" instead). 173 // "STAT" (the default) is more efficient, 174 // but some FTP servers don't implement it 175 // correctly. Note that omi automatically 176 // falls back to "LIST", but sometimes it 177 // requires a rather long timeout, so better 178 // use this flag if needed. 179 // 180 // PERMISSIONS Normally, new files and directories will 181 // get permissions according to the umask of 182 // the omi process, or use the mode specified 183 // by the user (-m option). But when this 184 // flag is set, omi tries to parse and copy 185 // the permission modes from the FTP server. 186 // 187 188 #define MIRROR_NONE 0x00000 // nothing 189 #define MIRROR_GETOLDERFILES 0x00001 // update old files from remote site 190 #define MIRROR_PRESERVEDIRS 0x00002 // don't kill local directories 191 #define MIRROR_IGNORETIME 0x00004 // ignore time when mirroring 192 #define MIRROR_DONTTOUCH 0x00008 // Don't set local mtimes 193 #define MIRROR_LOCALTIME 0x00010 // handle remote time as non-GMT 194 #define MIRROR_EXCLUDEALL 0x00020 // exclude everything by default 195 #define MIRROR_TEST 0x00040 // test only (don't mirror) 196 #define MIRROR_ACTIVE 0x00080 // use active transfer mode 197 #define MIRROR_NOSTAT 0x00100 // avoid "stat" command 198 #define MIRROR_PERMISSIONS 0x00200 // copy permissions from server 199 200 // 201 // Struct for configuration information. 202 // Timeouts are in seconds, 0 means no timeout. 203 // Deviation: If a file has an mtime difference within this 204 // deviation, it will not be mirrored. 205 // 206 207 typedef struct { 208 char *pidfilemask; // PID filename (with % macros) 209 char *pidfilename; // PID filename (expanded) 210 int pidfiledesc; // PID file FD 211 char *login, *email; // FTP login and email (password) 212 char *account; // FTP account information 213 char *local_addr; // local address to bind to (or NULL) 214 unsigned long debug; // debug flags, see above 215 unsigned long flags; // mirror flags, see above 216 unsigned int timeout_dns; // timeout for DNS look-ups 217 unsigned int timeout_connect; // timeout for server connect 218 unsigned int timeout_command; // timeout for server commands 219 unsigned int timeout_read; // timeout for reading from server 220 unsigned int maxsretry; // max. number of soft retries 221 unsigned int maxhretry; // max. number of hard retries 222 unsigned int maxremfail; // max. number of remote failures 223 unsigned int maxlocfail; // max. number of local failures 224 unsigned int reopendelay; // delay before re-open: start value 225 unsigned int reopeninc; // delay before re-open: increment 226 unsigned int reopenmax; // delay before re-open: maximum 227 unsigned long deviation; // maximum mtime deviation 228 int removelimit; // local remove limit (percent) 229 int newest; // mirror newest n files (if n > 0) 230 mode_t perms_dir; // permission modes for files 231 mode_t perms_file; // permission modes for directories 232 gid_t newgroup; // new group ownership 233 bool changegroup; // TRUE == change the group 234 bool havereporthead; // TRUE == printed report header 235 simple_list *exclude; // list of remote (mirror) exclude REs 236 simple_list *locexclude; // list of local (delete) exclude REs 237 } omiconf; 238 239 // 240 // Global configuration, and pointer to the current configuration. 241 // 242 243 extern omiconf globalconfig; 244 extern omiconf *cc; 245 246 // 247 // The time when the mirror started. 248 // 249 250 extern time_t now; 251 extern struct tm start; 252 253 // 254 // Struct for storing directory pair (remote/local) information. 255 // 256 257 typedef struct { 258 char *localdir; // local directory name 259 char *remotedir; // remote directory name 260 omifile *omidir; // remote dir struct 261 omiconf *conf; // configuration info for this pair 262 omistats *stats; // statistics info for this pair 263 } omipair; 264 265 // 266 // Current directory pair. 267 // 268 269 extern omipair *cp; 270 271 // 272 // Struct for storing remote site information. 273 // 274 275 typedef struct { 276 char *name; // name of the site 277 unsigned int port; // port number (control connection) 278 omiconf *conf; // configuration info for this site 279 omistats *stats; // statistics info for this site 280 int num; // number of directory pairs 281 omipair *pair; // list of directory pairs 282 } omisite; 283 284 // 285 // Current site. 286 // 287 288 extern omisite *ct; 289 290 #endif // HAVE_OMI_H 291 292 //-- 293