$treeview $search $mathjax $extrastylesheet
librsync
2.3.0
$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 00023 * encoding output routines. 00024 * 00025 * \todo Pluggable encoding formats: gdiff-style, rsync 24, ed (text), Delta 00026 * HTTP. */ 00027 00028 #include "config.h" 00029 #include <assert.h> 00030 #include <stdlib.h> 00031 #include "librsync.h" 00032 #include "emit.h" 00033 #include "job.h" 00034 #include "netint.h" 00035 #include "command.h" 00036 #include "prototab.h" 00037 #include "trace.h" 00038 00039 /** Write the magic for the start of a delta. */ 00040 void rs_emit_delta_header(rs_job_t *job) 00041 { 00042 rs_trace("emit DELTA magic"); 00043 rs_squirt_n4(job, RS_DELTA_MAGIC); 00044 } 00045 00046 /** Write a LITERAL command. */ 00047 void rs_emit_literal_cmd(rs_job_t *job, int len) 00048 { 00049 int cmd; 00050 int param_len = len <= 64 ? 0 : rs_int_len(len); 00051 00052 if (param_len == 0) { 00053 cmd = len; 00054 rs_trace("emit LITERAL_%d, cmd_byte=%#04x", len, cmd); 00055 } else if (param_len == 1) { 00056 cmd = RS_OP_LITERAL_N1; 00057 rs_trace("emit LITERAL_N1(len=%d), cmd_byte=%#04x", len, cmd); 00058 } else if (param_len == 2) { 00059 cmd = RS_OP_LITERAL_N2; 00060 rs_trace("emit LITERAL_N2(len=%d), cmd_byte=%#04x", len, cmd); 00061 } else { 00062 assert(param_len == 4); 00063 cmd = RS_OP_LITERAL_N4; 00064 rs_trace("emit LITERAL_N4(len=%d), cmd_byte=%#04x", len, cmd); 00065 } 00066 00067 rs_squirt_byte(job, cmd); 00068 if (param_len) 00069 rs_squirt_netint(job, len, param_len); 00070 00071 job->stats.lit_cmds++; 00072 job->stats.lit_bytes += len; 00073 job->stats.lit_cmdbytes += 1 + param_len; 00074 } 00075 00076 /** Write a COPY command for given offset and length. 00077 * 00078 * There is a choice of variable-length encodings, depending on the size of 00079 * representation for the parameters. */ 00080 void rs_emit_copy_cmd(rs_job_t *job, rs_long_t where, rs_long_t len) 00081 { 00082 int cmd; 00083 rs_stats_t *stats = &job->stats; 00084 const int where_bytes = rs_int_len(where); 00085 const int len_bytes = rs_int_len(len); 00086 00087 /* Commands ascend (1,1), (1,2), ... (8, 8) */ 00088 if (where_bytes == 8) 00089 cmd = RS_OP_COPY_N8_N1; 00090 else if (where_bytes == 4) 00091 cmd = RS_OP_COPY_N4_N1; 00092 else if (where_bytes == 2) 00093 cmd = RS_OP_COPY_N2_N1; 00094 else { 00095 assert(where_bytes == 1); 00096 cmd = RS_OP_COPY_N1_N1; 00097 } 00098 00099 if (len_bytes == 1) ; 00100 else if (len_bytes == 2) 00101 cmd += 1; 00102 else if (len_bytes == 4) 00103 cmd += 2; 00104 else { 00105 assert(len_bytes == 8); 00106 cmd += 3; 00107 } 00108 00109 rs_trace("emit COPY_N%d_N%d(where=" FMT_LONG ", len=" FMT_LONG 00110 "), cmd_byte=%#04x", where_bytes, len_bytes, where, len, cmd); 00111 rs_squirt_byte(job, cmd); 00112 rs_squirt_netint(job, where, where_bytes); 00113 rs_squirt_netint(job, len, len_bytes); 00114 00115 stats->copy_cmds++; 00116 stats->copy_bytes += len; 00117 stats->copy_cmdbytes += 1 + where_bytes + len_bytes; 00118 00119 /* \todo All the stats */ 00120 } 00121 00122 /** Write an END command. */ 00123 void rs_emit_end_cmd(rs_job_t *job) 00124 { 00125 int cmd = RS_OP_END; 00126 00127 rs_trace("emit END, cmd_byte=%#04x", cmd); 00128 rs_squirt_byte(job, cmd); 00129 }