$treeview $search $mathjax $extrastylesheet
librsync
2.0.2
$projectbrief
|
$projectbrief
|
$searchbox |
00001 /*= -*- c-basic-offset: 4; indent-tabs-mode: nil; -*- 00002 * 00003 * librsync -- dynamic caching and delta update in HTTP 00004 * 00005 * Copyright (C) 2000, 2001, 2004 by Martin Pool <mbp@sourcefrog.net> 00006 * 00007 * This program is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, but 00013 * WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00020 */ 00021 00022 /** \file emit.c encoding output routines. 00023 * 00024 * \todo Pluggable encoding formats: gdiff-style, rsync 24, ed (text), Delta 00025 * HTTP. */ 00026 00027 #include "config.h" 00028 00029 #include <assert.h> 00030 #include <stdlib.h> 00031 #include <stdio.h> 00032 00033 #include "librsync.h" 00034 #include "command.h" 00035 #include "trace.h" 00036 #include "emit.h" 00037 #include "prototab.h" 00038 #include "netint.h" 00039 #include "sumset.h" 00040 #include "job.h" 00041 00042 /** Write the magic for the start of a delta. */ 00043 void rs_emit_delta_header(rs_job_t *job) 00044 { 00045 rs_trace("emit DELTA magic"); 00046 rs_squirt_n4(job, RS_DELTA_MAGIC); 00047 } 00048 00049 /** Write a LITERAL command. */ 00050 void rs_emit_literal_cmd(rs_job_t *job, int len) 00051 { 00052 int cmd; 00053 int param_len = rs_int_len(len); 00054 00055 if (param_len == 1) 00056 cmd = RS_OP_LITERAL_N1; 00057 else if (param_len == 2) 00058 cmd = RS_OP_LITERAL_N2; 00059 else { 00060 assert(param_len == 4); 00061 cmd = RS_OP_LITERAL_N4; 00062 } 00063 00064 rs_trace("emit LITERAL_N%d(len=%d), cmd_byte=%#04x", param_len, len, cmd); 00065 rs_squirt_byte(job, cmd); 00066 rs_squirt_netint(job, len, param_len); 00067 00068 job->stats.lit_cmds++; 00069 job->stats.lit_bytes += len; 00070 job->stats.lit_cmdbytes += 1 + param_len; 00071 } 00072 00073 /** Write a COPY command for given offset and length. 00074 * 00075 * There is a choice of variable-length encodings, depending on the size of 00076 * representation for the parameters. */ 00077 void rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len) 00078 { 00079 int cmd; 00080 rs_stats_t *stats = &job->stats; 00081 const int where_bytes = rs_int_len(where); 00082 const int len_bytes = rs_int_len(len); 00083 00084 /* Commands ascend (1,1), (1,2), ... (8, 8) */ 00085 if (where_bytes == 8) 00086 cmd = RS_OP_COPY_N8_N1; 00087 else if (where_bytes == 4) 00088 cmd = RS_OP_COPY_N4_N1; 00089 else if (where_bytes == 2) 00090 cmd = RS_OP_COPY_N2_N1; 00091 else { 00092 assert(where_bytes == 1); 00093 cmd = RS_OP_COPY_N1_N1; 00094 } 00095 00096 if (len_bytes == 1) ; 00097 else if (len_bytes == 2) 00098 cmd += 1; 00099 else if (len_bytes == 4) 00100 cmd += 2; 00101 else { 00102 assert(len_bytes == 8); 00103 cmd += 3; 00104 } 00105 00106 rs_trace("emit COPY_N%d_N%d(where=" FMT_LONG ", len=" FMT_LONG 00107 "), cmd_byte=%#04x", where_bytes, len_bytes, where, len, cmd); 00108 rs_squirt_byte(job, cmd); 00109 rs_squirt_netint(job, where, where_bytes); 00110 rs_squirt_netint(job, len, len_bytes); 00111 00112 stats->copy_cmds++; 00113 stats->copy_bytes += len; 00114 stats->copy_cmdbytes += 1 + where_bytes + len_bytes; 00115 00116 /* \todo All the stats */ 00117 } 00118 00119 /** Write an END command. */ 00120 void rs_emit_end_cmd(rs_job_t *job) 00121 { 00122 int cmd = RS_OP_END; 00123 00124 rs_trace("emit END, cmd_byte=%#04x", cmd); 00125 rs_squirt_byte(job, cmd); 00126 }