summaryrefslogtreecommitdiff
path: root/rsync/emit.c
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /rsync/emit.c
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'rsync/emit.c') (more/less context) (ignore whitespace changes)
-rw-r--r--rsync/emit.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/rsync/emit.c b/rsync/emit.c
new file mode 100644
index 0000000..bdfc6d1
--- a/dev/null
+++ b/rsync/emit.c
@@ -0,0 +1,131 @@
1/*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*-
2 *
3 * librsync -- dynamic caching and delta update in HTTP
4 * $Id$
5 *
6 * Copyright (C) 2000, 2001 by Martin Pool <mbp@samba.org>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 2.1 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23
24 /*
25 * [almost sobbing] They don't sleep
26 * anymore on the beach. They don't
27 * sleep on the beach anymore.
28 */
29
30/*
31 * TODO: Pluggable encoding formats:
32 *
33 * - gdiff-style
34 * - rsync 24
35 * - ed (text)
36 * - Delta HTTP
37 */
38
39
40#include <config_rsync.h>
41
42#include <assert.h>
43#include <stdlib.h>
44#include <stdio.h>
45
46#include "rsync.h"
47#include "command.h"
48#include "protocol.h"
49#include "trace.h"
50#include "emit.h"
51#include "prototab.h"
52#include "netint.h"
53#include "sumset.h"
54#include "job.h"
55
56
57/*
58 * Write the magic for the start of a delta.
59 */
60void
61rs_emit_delta_header(rs_job_t *job)
62{
63 rs_trace("emit DELTA magic");
64 rs_squirt_n4(job, RS_DELTA_MAGIC);
65}
66
67
68
69/* Write a LITERAL command. */
70void
71rs_emit_literal_cmd(rs_job_t *job, int len)
72{
73 int cmd;
74 int param_len;
75
76 switch (param_len = rs_int_len(len)) {
77 case 1:
78 cmd = RS_OP_LITERAL_N1;
79 break;
80 case 2:
81 cmd = RS_OP_LITERAL_N2;
82 break;
83 case 4:
84 cmd = RS_OP_LITERAL_N4;
85 break;
86 default:
87 rs_fatal("What?");
88 }
89
90 rs_trace("emit LITERAL_N%d(len=%d), cmd_byte=%#x", param_len, len, cmd);
91 rs_squirt_byte(job, cmd);
92 rs_squirt_netint(job, len, param_len);
93
94 job->stats.lit_cmds++;
95 job->stats.lit_bytes += len;
96 job->stats.lit_cmdbytes += 1 + param_len;
97}
98
99
100/** Write a COPY command. */
101void
102rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len)
103{
104 int cmd;
105 rs_stats_t *stats = &job->stats;
106
107 cmd = RS_OP_COPY_N4_N4;
108
109 rs_trace("emit COPY_N4_N4(where=%.0f, len=%.0f), cmd_byte=%#x",
110 (double) where, (double) len, cmd);
111 rs_squirt_byte(job, cmd);
112 rs_squirt_netint(job, where, 4);
113 rs_squirt_netint(job, len, 4);
114
115 stats->copy_cmds++;
116 stats->copy_bytes += len;
117 stats->copy_cmdbytes += 1 + 4 + 4;
118
119 /* TODO: All the stats */
120}
121
122
123/** Write an END command. */
124void
125rs_emit_end_cmd(rs_job_t *job)
126{
127 int cmd = RS_OP_END;
128
129 rs_trace("emit END, cmd_byte=%#x", cmd);
130 rs_squirt_byte(job, cmd);
131}