\doxysubsection{readsums.\+c}
\label{readsums_8c_source}\index{readsums.c@{readsums.c}}
\mbox{\hyperlink{readsums_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ the library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 1999, 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ * Copyright (C) 1999 by Andrew Tridgell <tridge@samba.org>}}
\DoxyCodeLine{00007 \textcolor{comment}{ *}}
\DoxyCodeLine{00008 \textcolor{comment}{ * This program is free software; you can redistribute it and/or}}
\DoxyCodeLine{00009 \textcolor{comment}{ * modify it under the terms of the GNU Lesser General Public License}}
\DoxyCodeLine{00010 \textcolor{comment}{ * as published by the Free Software Foundation; either version 2.1 of}}
\DoxyCodeLine{00011 \textcolor{comment}{ * the License, or (at your option) any later version.}}
\DoxyCodeLine{00012 \textcolor{comment}{ *}}
\DoxyCodeLine{00013 \textcolor{comment}{ * This program is distributed in the hope that it will be useful, but}}
\DoxyCodeLine{00014 \textcolor{comment}{ * WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00015 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU}}
\DoxyCodeLine{00016 \textcolor{comment}{ * Lesser General Public License for more details.}}
\DoxyCodeLine{00017 \textcolor{comment}{ *}}
\DoxyCodeLine{00018 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public}}
\DoxyCodeLine{00019 \textcolor{comment}{ * License along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00020 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00021 \textcolor{comment}{ */}}
\DoxyCodeLine{00022 \textcolor{comment}{}}
\DoxyCodeLine{00023 \textcolor{comment}{/** \(\backslash\)file readsums.c}}
\DoxyCodeLine{00024 \textcolor{comment}{ * Load signatures from a file. */}}
\DoxyCodeLine{00025 }
\DoxyCodeLine{00026 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00027 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00028 \textcolor{preprocessor}{\#include "{}job.h"{}}}
\DoxyCodeLine{00029 \textcolor{preprocessor}{\#include "{}sumset.h"{}}}
\DoxyCodeLine{00030 \textcolor{preprocessor}{\#include "{}scoop.h"{}}}
\DoxyCodeLine{00031 \textcolor{preprocessor}{\#include "{}netint.h"{}}}
\DoxyCodeLine{00032 \textcolor{preprocessor}{\#include "{}trace.h"{}}}
\DoxyCodeLine{00033 \textcolor{preprocessor}{\#include "{}util.h"{}}}
\DoxyCodeLine{00034 }
\DoxyCodeLine{00035 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_weak(rs\_job\_t *job);}
\DoxyCodeLine{00036 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_strong(rs\_job\_t *job);}
\DoxyCodeLine{00037 \textcolor{comment}{}}
\DoxyCodeLine{00038 \textcolor{comment}{/** Add a just-\/read-\/in checksum pair to the signature block. */}}
\DoxyCodeLine{00039 \textcolor{keyword}{static} rs\_result rs\_loadsig\_add\_sum(rs\_job\_t *job, rs\_strong\_sum\_t *strong)}
\DoxyCodeLine{00040 \{}
\DoxyCodeLine{00041     rs\_signature\_t *sig = job-\/>signature;}
\DoxyCodeLine{00042 }
\DoxyCodeLine{00043     \textcolor{keywordflow}{if} (rs\_trace\_enabled()) \{}
\DoxyCodeLine{00044         \textcolor{keywordtype}{char} hexbuf[RS\_MAX\_STRONG\_SUM\_LENGTH * 2 + 2];}
\DoxyCodeLine{00045         rs\_hexify(hexbuf, strong, sig-\/>strong\_sum\_len);}
\DoxyCodeLine{00046         rs\_trace(\textcolor{stringliteral}{"{}got block: weak="{}} FMT\_WEAKSUM \textcolor{stringliteral}{"{}, strong=\%s"{}}, job-\/>weak\_sig,}
\DoxyCodeLine{00047                  hexbuf);}
\DoxyCodeLine{00048     \}}
\DoxyCodeLine{00049     rs\_signature\_add\_block(job-\/>signature, job-\/>weak\_sig, strong);}
\DoxyCodeLine{00050     job-\/>stats.sig\_blocks++;}
\DoxyCodeLine{00051     \textcolor{keywordflow}{return} RS\_RUNNING;}
\DoxyCodeLine{00052 \}}
\DoxyCodeLine{00053 }
\DoxyCodeLine{00054 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_weak(rs\_job\_t *job)}
\DoxyCodeLine{00055 \{}
\DoxyCodeLine{00056     \textcolor{keywordtype}{int} l;}
\DoxyCodeLine{00057     rs\_result result;}
\DoxyCodeLine{00058 }
\DoxyCodeLine{00059     \textcolor{keywordflow}{if} ((result = rs\_suck\_n4(job, \&l)) != RS\_DONE) \{}
\DoxyCodeLine{00060         \textcolor{keywordflow}{if} (result == RS\_INPUT\_ENDED)   \textcolor{comment}{/* ending here is OK */}}
\DoxyCodeLine{00061             \textcolor{keywordflow}{return} RS\_DONE;}
\DoxyCodeLine{00062         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00063     \}}
\DoxyCodeLine{00064     job-\/>weak\_sig = l;}
\DoxyCodeLine{00065     job-\/>statefn = rs\_loadsig\_s\_strong;}
\DoxyCodeLine{00066     \textcolor{keywordflow}{return} RS\_RUNNING;}
\DoxyCodeLine{00067 \}}
\DoxyCodeLine{00068 }
\DoxyCodeLine{00069 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_strong(rs\_job\_t *job)}
\DoxyCodeLine{00070 \{}
\DoxyCodeLine{00071     rs\_result result;}
\DoxyCodeLine{00072     rs\_strong\_sum\_t *strongsum;}
\DoxyCodeLine{00073 }
\DoxyCodeLine{00074     \textcolor{keywordflow}{if} ((result =}
\DoxyCodeLine{00075          rs\_scoop\_read(job, job-\/>signature-\/>strong\_sum\_len,}
\DoxyCodeLine{00076                        (\textcolor{keywordtype}{void} **)\&strongsum)) != RS\_DONE)}
\DoxyCodeLine{00077         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00078     job-\/>statefn = rs\_loadsig\_s\_weak;}
\DoxyCodeLine{00079     \textcolor{keywordflow}{return} rs\_loadsig\_add\_sum(job, strongsum);}
\DoxyCodeLine{00080 \}}
\DoxyCodeLine{00081 }
\DoxyCodeLine{00082 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_stronglen(rs\_job\_t *job)}
\DoxyCodeLine{00083 \{}
\DoxyCodeLine{00084     \textcolor{keywordtype}{int} l;}
\DoxyCodeLine{00085     rs\_result result;}
\DoxyCodeLine{00086 }
\DoxyCodeLine{00087     \textcolor{keywordflow}{if} ((result = rs\_suck\_n4(job, \&l)) != RS\_DONE)}
\DoxyCodeLine{00088         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00089     \textcolor{keywordflow}{if} (l < 0 || l > RS\_MAX\_STRONG\_SUM\_LENGTH) \{}
\DoxyCodeLine{00090         rs\_error(\textcolor{stringliteral}{"{}strong sum length \%d is implausible"{}}, l);}
\DoxyCodeLine{00091         \textcolor{keywordflow}{return} RS\_CORRUPT;}
\DoxyCodeLine{00092     \}}
\DoxyCodeLine{00093     rs\_trace(\textcolor{stringliteral}{"{}got strong sum length \%d"{}}, l);}
\DoxyCodeLine{00094     job-\/>sig\_strong\_len = l;}
\DoxyCodeLine{00095     \textcolor{comment}{/* Initialize the signature. */}}
\DoxyCodeLine{00096     \textcolor{keywordflow}{if} ((result =}
\DoxyCodeLine{00097          rs\_signature\_init(job-\/>signature, job-\/>sig\_magic, job-\/>sig\_block\_len,}
\DoxyCodeLine{00098                            job-\/>sig\_strong\_len, job-\/>sig\_fsize)) != RS\_DONE)}
\DoxyCodeLine{00099         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00100     job-\/>statefn = rs\_loadsig\_s\_weak;}
\DoxyCodeLine{00101     \textcolor{keywordflow}{return} RS\_RUNNING;}
\DoxyCodeLine{00102 \}}
\DoxyCodeLine{00103 }
\DoxyCodeLine{00104 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_blocklen(rs\_job\_t *job)}
\DoxyCodeLine{00105 \{}
\DoxyCodeLine{00106     \textcolor{keywordtype}{int} l;}
\DoxyCodeLine{00107     rs\_result result;}
\DoxyCodeLine{00108 }
\DoxyCodeLine{00109     \textcolor{keywordflow}{if} ((result = rs\_suck\_n4(job, \&l)) != RS\_DONE)}
\DoxyCodeLine{00110         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00111     \textcolor{keywordflow}{if} (l < 1) \{}
\DoxyCodeLine{00112         rs\_error(\textcolor{stringliteral}{"{}block length of \%d is bogus"{}}, l);}
\DoxyCodeLine{00113         \textcolor{keywordflow}{return} RS\_CORRUPT;}
\DoxyCodeLine{00114     \}}
\DoxyCodeLine{00115     rs\_trace(\textcolor{stringliteral}{"{}got block length \%d"{}}, l);}
\DoxyCodeLine{00116     job-\/>sig\_block\_len = l;}
\DoxyCodeLine{00117     job-\/>stats.block\_len = l;}
\DoxyCodeLine{00118     job-\/>statefn = rs\_loadsig\_s\_stronglen;}
\DoxyCodeLine{00119     \textcolor{keywordflow}{return} RS\_RUNNING;}
\DoxyCodeLine{00120 \}}
\DoxyCodeLine{00121 }
\DoxyCodeLine{00122 \textcolor{keyword}{static} rs\_result rs\_loadsig\_s\_magic(rs\_job\_t *job)}
\DoxyCodeLine{00123 \{}
\DoxyCodeLine{00124     \textcolor{keywordtype}{int} l;}
\DoxyCodeLine{00125     rs\_result result;}
\DoxyCodeLine{00126 }
\DoxyCodeLine{00127     \textcolor{keywordflow}{if} ((result = rs\_suck\_n4(job, \&l)) != RS\_DONE)}
\DoxyCodeLine{00128         \textcolor{keywordflow}{return} result;}
\DoxyCodeLine{00129     rs\_trace(\textcolor{stringliteral}{"{}got signature magic \%\#x"{}}, l);}
\DoxyCodeLine{00130     job-\/>sig\_magic = l;}
\DoxyCodeLine{00131     job-\/>statefn = rs\_loadsig\_s\_blocklen;}
\DoxyCodeLine{00132     \textcolor{keywordflow}{return} RS\_RUNNING;}
\DoxyCodeLine{00133 \}}
\DoxyCodeLine{00134 }
\DoxyCodeLine{00135 rs\_job\_t *rs\_loadsig\_begin(rs\_signature\_t **signature)}
\DoxyCodeLine{00136 \{}
\DoxyCodeLine{00137     rs\_job\_t *job;}
\DoxyCodeLine{00138 }
\DoxyCodeLine{00139     job = rs\_job\_new(\textcolor{stringliteral}{"{}loadsig"{}}, rs\_loadsig\_s\_magic);}
\DoxyCodeLine{00140     *signature = job-\/>signature = rs\_alloc\_struct(rs\_signature\_t);}
\DoxyCodeLine{00141     \textcolor{keywordflow}{return} job;}
\DoxyCodeLine{00142 \}}

\end{DoxyCode}
