librsync  2.3.4
job.h
Go to the documentation of this file.
1 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2  *
3  * librsync -- the library for network deltas
4  *
5  * Copyright (C) 2000, 2001, 2014 by Martin Pool <mbp@sourcefrog.net>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 /** \file job.h
23  * Generic state-machine interface.
24  *
25  * The point of this is that we need to be able to suspend and resume
26  * processing at any point at which the buffers may block.
27  *
28  * \sa \ref api_streaming \sa rs_job_iter() \sa ::rs_job */
29 #ifndef JOB_H
30 # define JOB_H
31 
32 # include <assert.h>
33 # include <stddef.h>
34 # include "mdfour.h"
35 # include "checksum.h"
36 # include "librsync.h"
37 
38 /** Magic job tag number for checking jobs have been initialized. */
39 # define RS_JOB_TAG 20010225
40 
41 /** Max length of a singled delta command is including command bytes.
42  *
43  * This is used to constrain and set the internal buffer sizes. */
44 # define MAX_DELTA_CMD (1<<16)
45 
46 /** The contents of this structure are private. */
47 struct rs_job {
48  int dogtag;
49 
50  /** Human-readable job operation name. */
51  const char *job_name;
52 
53  rs_buffers_t *stream;
54 
55  /** Callback for each processing step. */
57 
58  /** Final result of processing job. Used by rs_job_s_failed(). */
60 
61  /* Arguments for initializing the signature used by mksum.c and readsums.c.
62  */
63  int sig_magic;
64  int sig_block_len;
65  int sig_strong_len;
66 
67  /** The size of the signature file if available. Used by loadsums.c when
68  * initializing the signature to preallocate memory. */
69  rs_long_t sig_fsize;
70 
71  /** Pointer to the signature that's being used by the operation. */
73 
74  /** Flag indicating signature should be destroyed with the job. */
76 
77  /** Command byte currently being processed, if any. */
78  unsigned char op;
79 
80  /** The weak signature digest used by readsums.c */
81  rs_weak_sum_t weak_sig;
82 
83  /** The rollsum weak signature accumulator used by delta.c */
85 
86  /** Lengths of expected parameters. */
87  rs_long_t param1, param2;
88 
89  struct rs_prototab_ent const *cmd;
90  rs_mdfour_t output_md4;
91 
92  /** Encoding statistics. */
94 
95  /** Buffer of data in the scoop. Allocation is scoop_buf[0..scoop_alloc],
96  * and scoop_next[0..scoop_avail] contains data yet to be processed. */
97  rs_byte_t *scoop_buf; /**< The buffer allocation pointer. */
98  rs_byte_t *scoop_next; /**< The next data pointer. */
99  size_t scoop_alloc; /**< The buffer allocation size. */
100  size_t scoop_avail; /**< The amount of data available. */
101 
102  /** The delta scan buffer, where scan_buf[scan_pos..scan_len] is the data
103  * yet to be scanned. */
104  rs_byte_t *scan_buf; /**< The delta scan buffer pointer. */
105  size_t scan_len; /**< The delta scan buffer length. */
106  size_t scan_pos; /**< The delta scan position. */
107 
108  /** If USED is >0, then buf contains that much write data to be sent out. */
109  rs_byte_t write_buf[36];
110  size_t write_len;
111 
112  /** If \p copy_len is >0, then that much data should be copied through
113  * from the input. */
114  size_t copy_len;
115 
116  /** Copy from the basis position. */
117  rs_long_t basis_pos, basis_len;
118 
119  /** Callback used to copy data from the basis into the output. */
121  void *copy_arg;
122 };
123 
124 rs_job_t *rs_job_new(const char *, rs_result (*statefn)(rs_job_t *));
125 
126 /** Assert that a job is valid.
127  *
128  * We don't use a static inline function here so that assert failure output
129  * points at where rs_job_check() was called from. */
130 # define rs_job_check(job) do {\
131  assert(job->dogtag == RS_JOB_TAG);\
132 } while (0)
133 
134 #endif /* !JOB_H */
Description of input and output buffers.
Definition: librsync.h:328
rs_copy_cb * copy_cb
Callback used to copy data from the basis into the output.
Definition: job.h:120
size_t scoop_alloc
The buffer allocation size.
Definition: job.h:99
rs_result final_result
Final result of processing job.
Definition: job.h:59
MD4 message digest algorithm.
rs_byte_t write_buf[36]
If USED is &gt;0, then buf contains that much write data to be sent out.
Definition: job.h:109
unsigned char op
Command byte currently being processed, if any.
Definition: job.h:78
rs_signature_t * signature
Pointer to the signature that&#39;s being used by the operation.
Definition: job.h:72
rs_byte_t * scan_buf
The delta scan buffer, where scan_buf[scan_pos..scan_len] is the data yet to be scanned.
Definition: job.h:104
weaksum_t weak_sum
The rollsum weak signature accumulator used by delta.c.
Definition: job.h:84
int job_owns_sig
Flag indicating signature should be destroyed with the job.
Definition: job.h:75
rs_long_t param1
Lengths of expected parameters.
Definition: job.h:87
rs_weak_sum_t weak_sig
The weak signature digest used by readsums.c.
Definition: job.h:81
The rs_mdfour state type.
Definition: mdfour.h:46
rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len, void **buf)
Callback used to retrieve parts of the basis file.
Definition: librsync.h:502
size_t scoop_avail
The amount of data available.
Definition: job.h:100
rs_byte_t * scoop_next
The next data pointer.
Definition: job.h:98
rs_long_t basis_pos
Copy from the basis position.
Definition: job.h:117
size_t scan_pos
The delta scan position.
Definition: job.h:106
rs_stats_t stats
Encoding statistics.
Definition: job.h:93
size_t scan_len
The delta scan buffer length.
Definition: job.h:105
rs_long_t sig_fsize
The size of the signature file if available.
Definition: job.h:69
Public header for librsync.
size_t copy_len
If copy_len is &gt;0, then that much data should be copied through from the input.
Definition: job.h:114
const char * job_name
Human-readable job operation name.
Definition: job.h:51
Signature of a whole file.
Definition: sumset.h:44
Performance statistics from a librsync encoding or decoding operation.
Definition: librsync.h:210
rs_result
Return codes from nonblocking rsync operations.
Definition: librsync.h:180
rs_byte_t * scoop_buf
Buffer of data in the scoop.
Definition: job.h:97
Abstract wrappers around different weaksum and strongsum implementations.
rs_result(* statefn)(rs_job_t *)
Callback for each processing step.
Definition: job.h:56
Abstract wrapper around weaksum implementations.
Definition: checksum.h:56
The contents of this structure are private.
Definition: job.h:47