summaryrefslogtreecommitdiff
path: root/job.h
blob: 843649f49033cc061f2342b2eac33a0e9bb71825 (plain)
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
/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
 *
 * librsync -- the library for network deltas
 * $Id$
 * 
 * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "mdfour.h"
#include "rollsum.h"

struct rs_job {
    int                 dogtag;

    /** Human-readable job operation name. */
    const char          *job_name;
    
    rs_buffers_t *stream;

    /** Callback for each processing step. */
    rs_result           (*statefn)(rs_job_t *);

    /** Final result of processing job.  Used by rs_job_s_failed(). */
    rs_result final_result;

    /* XXX: These next two are redundant with their equivalents in the
     * signature field.  Perhaps we should get rid of them, but
     * they're also used in the mksum operation. */
    int                 block_len;
    int                 strong_sum_len;

    /** Signature that's either being read in, or used for
     * generating a delta. */
    rs_signature_t      *signature;
    
    /** Command byte currently being processed, if any. */
    unsigned char       op;

    /** The weak signature digest used by readsums.c */
    rs_weak_sum_t       weak_sig;
    
    /** The rollsum weak signature accumulator used by delta.c */
    Rollsum             weak_sum;

    /** Lengths of expected parameters. */
    rs_long_t           param1, param2;
    
    struct rs_prototab_ent const *cmd;
    rs_mdfour_t      output_md4;

    /** Encoding statistics. */
    rs_stats_t          stats;

    /** 
     * Buffer of data in the scoop.  Allocation is
     *  scoop_buf[0..scoop_alloc], and scoop_next[0..scoop_avail] contains
     *  data yet to be processed. scoop_next[scoop_pos..scoop_avail] is the
     *  data yet to be scanned.  */
    char       *scoop_buf;             /* the allocation pointer */
    char       *scoop_next;            /* the data pointer */
    size_t      scoop_alloc;           /* the allocation size */
    size_t      scoop_avail;           /* the data size */
    size_t      scoop_pos;             /* the scan position */
        
    /** If USED is >0, then buf contains that much write data to
     * be sent out. */
    char        write_buf[20];
    int         write_len;

    /** If \p copy_len is >0, then that much data should be copied
     * through from the input. */
    rs_long_t   copy_len;

    /** Copy from the basis position. */
    rs_long_t       basis_pos, basis_len;

    /** Callback used to copy data from the basis into the output. */
    rs_copy_cb      *copy_cb;
    void            *copy_arg;
};


rs_job_t * rs_job_new(const char *, rs_result (*statefn)(rs_job_t *));

void rs_job_check(rs_job_t *job);

int rs_job_input_is_ending(rs_job_t *job);