#ifndef EXTERN_H
#define EXTERN_H
#include <openssl/md4.h>
#define RSYNC_PROTOCOL (27)
#define MAX_CHUNK (32 * 1024)
#define BLOCK_SIZE_MIN (700)
#define MAX_BASEDIR 20
#define BASE_MODE_COMPARE 1
#define BASE_MODE_COPY 2
#define BASE_MODE_LINK 3
#define CSUM_LENGTH_PHASE1 (2)
#define CSUM_LENGTH_PHASE2 (16)
#define ERR_SYNTAX 1
#define ERR_PROTOCOL 2
#define ERR_SOCK_IO 10
#define ERR_FILE_IO 11
#define ERR_WIREPROTO 12
#define ERR_IPC 14
#define ERR_TERMIMATED 16
#define ERR_WAITPID 21
#define ERR_NOMEM 22
extern int poll_timeout;
extern int poll_contimeout;
enum fmode {
FARGS_SENDER,
FARGS_RECEIVER
};
struct fargs {
char *host;
char **sources;
size_t sourcesz;
char *sink;
enum fmode mode;
int remote;
char *module;
};
struct flstat {
mode_t mode;
uid_t uid;
gid_t gid;
dev_t rdev;
off_t size;
time_t mtime;
unsigned int flags;
#define FLSTAT_TOP_DIR 0x01
};
struct flist {
char *path;
const char *wpath;
struct flstat st;
char *link;
};
struct opts {
int sender;
int server;
int recursive;
int dry_run;
int preserve_times;
int preserve_perms;
int preserve_links;
int preserve_gids;
int preserve_uids;
int del;
int devices;
int specials;
int no_motd;
int numeric_ids;
int one_file_system;
int ignore_times;
int ignore_dir_times;
int ignore_link_times;
int size_only;
int alt_base_mode;
off_t max_size;
off_t min_size;
char *rsync_path;
char *ssh_prog;
char *port;
char *address;
char *basedir[MAX_BASEDIR];
char *basedir_abs[MAX_BASEDIR];
};
enum rule_type {
RULE_NONE,
RULE_EXCLUDE,
RULE_INCLUDE,
RULE_CLEAR,
#ifdef NOTYET
RULE_MERGE,
RULE_DIR_MERGE,
RULE_SHOW,
RULE_HIDE,
RULE_PROTECT,
RULE_RISK,
#endif
};
struct blk {
off_t offs;
size_t idx;
size_t len;
uint32_t chksum_short;
unsigned char chksum_long[CSUM_LENGTH_PHASE2];
};
enum blkstatst {
BLKSTAT_NONE = 0,
BLKSTAT_NEXT,
BLKSTAT_DATA,
BLKSTAT_TOK,
BLKSTAT_HASH,
BLKSTAT_DONE,
BLKSTAT_PHASE,
};
struct blkstat {
off_t offs;
off_t total;
off_t dirty;
size_t hint;
void *map;
size_t mapsz;
int fd;
enum blkstatst curst;
off_t curpos;
off_t curlen;
int32_t curtok;
struct blktab *blktab;
uint32_t s1;
uint32_t s2;
MD4_CTX ctx;
};
struct blkset {
off_t size;
size_t rem;
size_t len;
size_t csum;
struct blk *blks;
size_t blksz;
};
struct sess {
const struct opts *opts;
int32_t seed;
int32_t lver;
int32_t rver;
uint64_t total_read;
uint64_t total_size;
uint64_t total_write;
int mplex_reads;
size_t mplex_read_remain;
int mplex_writes;
};
struct ident {
int32_t id;
int32_t mapped;
char *name;
};
typedef struct arglist arglist;
struct arglist {
char **list;
u_int num;
u_int nalloc;
};
void addargs(arglist *, const char *, ...)
__attribute__((format(printf, 2, 3)));
void freeargs(arglist *);
struct download;
struct upload;
extern int verbose;
#define MINIMUM(a, b) (((a) < (b)) ? (a) : (b))
#define LOG0(_fmt, ...) \
rsync_log( -1, (_fmt), ##__VA_ARGS__)
#define LOG1(_fmt, ...) \
rsync_log( 0, (_fmt), ##__VA_ARGS__)
#define LOG2(_fmt, ...) \
rsync_log( 1, (_fmt), ##__VA_ARGS__)
#define LOG3(_fmt, ...) \
rsync_log( 2, (_fmt), ##__VA_ARGS__)
#define LOG4(_fmt, ...) \
rsync_log( 3, (_fmt), ##__VA_ARGS__)
#define ERRX1(_fmt, ...) \
rsync_errx1( (_fmt), ##__VA_ARGS__)
#define WARNX(_fmt, ...) \
rsync_warnx( (_fmt), ##__VA_ARGS__)
#define WARN(_fmt, ...) \
rsync_warn(0, (_fmt), ##__VA_ARGS__)
#define WARN1(_fmt, ...) \
rsync_warn(1, (_fmt), ##__VA_ARGS__)
#define WARN2(_fmt, ...) \
rsync_warn(2, (_fmt), ##__VA_ARGS__)
#define ERR(_fmt, ...) \
rsync_err( (_fmt), ##__VA_ARGS__)
#define ERRX(_fmt, ...) \
rsync_errx( (_fmt), ##__VA_ARGS__)
void rsync_log(int, const char *, ...)
__attribute__((format(printf, 2, 3)));
void rsync_warn(int, const char *, ...)
__attribute__((format(printf, 2, 3)));
void rsync_warnx(const char *, ...)
__attribute__((format(printf, 1, 2)));
void rsync_err(const char *, ...)
__attribute__((format(printf, 1, 2)));
void rsync_errx(const char *, ...)
__attribute__((format(printf, 1, 2)));
void rsync_errx1(const char *, ...)
__attribute__((format(printf, 1, 2)));
int flist_del(struct sess *, int, const struct flist *, size_t);
int flist_gen(struct sess *, size_t, char **, struct flist **, size_t *);
void flist_free(struct flist *, size_t);
int flist_recv(struct sess *, int, struct flist **, size_t *);
int flist_send(struct sess *, int, int, const struct flist *, size_t);
int flist_gen_dels(struct sess *, const char *, struct flist **, size_t *,
const struct flist *, size_t);
const char *alt_base_mode(int);
char **fargs_cmdline(struct sess *, const struct fargs *, size_t *);
int io_read_buf(struct sess *, int, void *, size_t);
int io_read_byte(struct sess *, int, uint8_t *);
int io_read_check(int);
int io_read_flush(struct sess *, int);
int io_read_int(struct sess *, int, int32_t *);
int io_read_uint(struct sess *, int, uint32_t *);
int io_read_long(struct sess *, int, int64_t *);
int io_read_size(struct sess *, int, size_t *);
int io_read_ulong(struct sess *, int, uint64_t *);
int io_write_buf(struct sess *, int, const void *, size_t);
int io_write_byte(struct sess *, int, uint8_t);
int io_write_int(struct sess *, int, int32_t);
int io_write_uint(struct sess *, int, uint32_t);
int io_write_line(struct sess *, int, const char *);
int io_write_long(struct sess *, int, int64_t);
int io_write_ulong(struct sess *, int, uint64_t);
int io_lowbuffer_alloc(struct sess *, void **, size_t *, size_t *, size_t);
void io_lowbuffer_int(struct sess *, void *, size_t *, size_t, int32_t);
void io_lowbuffer_buf(struct sess *, void *, size_t *, size_t, const void *,
size_t);
void io_buffer_int(void *, size_t *, size_t, int32_t);
void io_buffer_buf(void *, size_t *, size_t, const void *, size_t);
void io_unbuffer_int(const void *, size_t *, size_t, int32_t *);
int io_unbuffer_size(const void *, size_t *, size_t, size_t *);
void io_unbuffer_buf(const void *, size_t *, size_t, void *, size_t);
int rsync_receiver(struct sess *, int, int, const char *);
int rsync_sender(struct sess *, int, int, size_t, char **);
int rsync_client(const struct opts *, int, const struct fargs *);
int rsync_connect(const struct opts *, int *, const struct fargs *);
int rsync_socket(const struct opts *, int, const struct fargs *);
int rsync_server(const struct opts *, size_t, char *[]);
int rsync_downloader(struct download *, struct sess *, int *);
int rsync_set_metadata(struct sess *, int, int, const struct flist *,
const char *);
int rsync_set_metadata_at(struct sess *, int, int, const struct flist *,
const char *);
int rsync_uploader(struct upload *, int *, struct sess *, int *);
int rsync_uploader_tail(struct upload *, struct sess *);
struct download *download_alloc(struct sess *, int, const struct flist *,
size_t, int);
void download_free(struct download *);
struct upload *upload_alloc(const char *, int, int, size_t,
const struct flist *, size_t, mode_t);
void upload_free(struct upload *);
struct blktab *blkhash_alloc(void);
int blkhash_set(struct blktab *, const struct blkset *);
void blkhash_free(struct blktab *);
struct blkset *blk_recv(struct sess *, int, const char *);
void blk_recv_ack(char [20], const struct blkset *, int32_t);
void blk_match(struct sess *, const struct blkset *,
const char *, struct blkstat *);
int blk_send(struct sess *, int, size_t, const struct blkset *,
const char *);
int blk_send_ack(struct sess *, int, struct blkset *);
uint32_t hash_fast(const void *, size_t);
void hash_slow(const void *, size_t, unsigned char *,
const struct sess *);
void hash_file_start(MD4_CTX *, const struct sess *);
void hash_file_buf(MD4_CTX *, const void *, size_t);
void hash_file_final(MD4_CTX *, unsigned char *);
void copy_file(int, const char *, const struct flist *);
int mkpath(char *);
int mkstempat(int, char *);
char *mkstemplinkat(char*, int, char *);
char *mkstempfifoat(int, char *);
char *mkstempnodat(int, char *, mode_t, dev_t);
char *mkstempsock(const char *, char *);
int mktemplate(char **, const char *, int);
int parse_rule(char *line, enum rule_type);
void parse_file(const char *, enum rule_type);
void send_rules(struct sess *, int);
void recv_rules(struct sess *, int);
int rules_match(const char *, int);
int rmatch(const char *, const char *, int);
char *symlink_read(const char *);
char *symlinkat_read(int, const char *);
int sess_stats_send(struct sess *, int);
int sess_stats_recv(struct sess *, int);
int idents_add(int, struct ident **, size_t *, int32_t);
void idents_assign_gid(struct sess *, struct flist *, size_t,
const struct ident *, size_t);
void idents_assign_uid(struct sess *, struct flist *, size_t,
const struct ident *, size_t);
void idents_free(struct ident *, size_t);
int idents_recv(struct sess *, int, struct ident **, size_t *);
void idents_remap(struct sess *, int, struct ident *, size_t);
int idents_send(struct sess *, int, const struct ident *, size_t);
#endif