\doxysubsection{trace.\+c}
\label{trace_8c_source}\index{trace.c@{trace.c}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001 \textcolor{comment}{/*= -\/*-\/ c-\/basic-\/offset: 4; indent-\/tabs-\/mode: nil; -\/*-\/}}
\DoxyCodeLine{00002 \textcolor{comment}{ *}}
\DoxyCodeLine{00003 \textcolor{comment}{ * librsync -\/-\/ library for network deltas}}
\DoxyCodeLine{00004 \textcolor{comment}{ *}}
\DoxyCodeLine{00005 \textcolor{comment}{ * Copyright (C) 2000, 2001 by Martin Pool <mbp@sourcefrog.net>}}
\DoxyCodeLine{00006 \textcolor{comment}{ *}}
\DoxyCodeLine{00007 \textcolor{comment}{ * This program is free software; you can redistribute it and/or modify}}
\DoxyCodeLine{00008 \textcolor{comment}{ * it under the terms of the GNU Lesser General Public License as published by}}
\DoxyCodeLine{00009 \textcolor{comment}{ * the Free Software Foundation; either version 2.1 of the License, or}}
\DoxyCodeLine{00010 \textcolor{comment}{ * (at your option) any later version.}}
\DoxyCodeLine{00011 \textcolor{comment}{ *}}
\DoxyCodeLine{00012 \textcolor{comment}{ * This program is distributed in the hope that it will be useful,}}
\DoxyCodeLine{00013 \textcolor{comment}{ * but WITHOUT ANY WARRANTY; without even the implied warranty of}}
\DoxyCodeLine{00014 \textcolor{comment}{ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the}}
\DoxyCodeLine{00015 \textcolor{comment}{ * GNU Lesser General Public License for more details.}}
\DoxyCodeLine{00016 \textcolor{comment}{ *}}
\DoxyCodeLine{00017 \textcolor{comment}{ * You should have received a copy of the GNU Lesser General Public License}}
\DoxyCodeLine{00018 \textcolor{comment}{ * along with this program; if not, write to the Free Software}}
\DoxyCodeLine{00019 \textcolor{comment}{ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.}}
\DoxyCodeLine{00020 \textcolor{comment}{ */}}
\DoxyCodeLine{00021 }
\DoxyCodeLine{00022                                      \textcolor{comment}{/*=}}
\DoxyCodeLine{00023 \textcolor{comment}{                                      | Finality is death.}}
\DoxyCodeLine{00024 \textcolor{comment}{                                      | Perfection is finality.}}
\DoxyCodeLine{00025 \textcolor{comment}{                                      | Nothing is perfect.}}
\DoxyCodeLine{00026 \textcolor{comment}{                                      | There are lumps in it.}}
\DoxyCodeLine{00027 \textcolor{comment}{                                      */}}
\DoxyCodeLine{00028 }
\DoxyCodeLine{00029 \textcolor{preprocessor}{\#include "{}config.h"{}}             \textcolor{comment}{/* IWYU pragma: keep */}}
\DoxyCodeLine{00030 \textcolor{preprocessor}{\#include <stdio.h>}}
\DoxyCodeLine{00031 \textcolor{preprocessor}{\#include <stdarg.h>}}
\DoxyCodeLine{00032 \textcolor{preprocessor}{\#include "{}librsync.h"{}}}
\DoxyCodeLine{00033 \textcolor{preprocessor}{\#include "{}trace.h"{}}}
\DoxyCodeLine{00034 \textcolor{preprocessor}{\#include "{}util.h"{}}}
\DoxyCodeLine{00035 }
\DoxyCodeLine{00036 rs\_trace\_fn\_t *rs\_trace\_impl = rs\_trace\_stderr;}
\DoxyCodeLine{00037 }
\DoxyCodeLine{00038 \textcolor{keywordtype}{int} rs\_trace\_level = RS\_LOG\_INFO;}
\DoxyCodeLine{00039 }
\DoxyCodeLine{00040 \textcolor{preprocessor}{\#define MY\_NAME "{}librsync"{}}}
\DoxyCodeLine{00041 }
\DoxyCodeLine{00042 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_log\_va(\textcolor{keywordtype}{int} level, \textcolor{keywordtype}{char} \textcolor{keyword}{const} *fn, \textcolor{keywordtype}{char} \textcolor{keyword}{const} *fmt, va\_list va);}
\DoxyCodeLine{00043 \textcolor{comment}{}}
\DoxyCodeLine{00044 \textcolor{comment}{/** Log severity strings, if any. Must match ordering in ::rs\_loglevel. */}}
\DoxyCodeLine{00045 \textcolor{keyword}{static} \textcolor{keyword}{const} \textcolor{keywordtype}{char} *rs\_severities[] = \{}
\DoxyCodeLine{00046     \textcolor{stringliteral}{"{}EMERGENCY! "{}}, \textcolor{stringliteral}{"{}ALERT! "{}}, \textcolor{stringliteral}{"{}CRITICAL! "{}}, \textcolor{stringliteral}{"{}ERROR: "{}}, \textcolor{stringliteral}{"{}Warning: "{}},}
\DoxyCodeLine{00047     \textcolor{stringliteral}{"{}"{}}, \textcolor{stringliteral}{"{}"{}}, \textcolor{stringliteral}{"{}"{}}}
\DoxyCodeLine{00048 \};}
\DoxyCodeLine{00049 \textcolor{comment}{}}
\DoxyCodeLine{00050 \textcolor{comment}{/** Set the destination of trace information.}}
\DoxyCodeLine{00051 \textcolor{comment}{ *}}
\DoxyCodeLine{00052 \textcolor{comment}{ * The callback scheme allows for use within applications that may have their}}
\DoxyCodeLine{00053 \textcolor{comment}{ * own particular ways of reporting errors: log files for a web server,}}
\DoxyCodeLine{00054 \textcolor{comment}{ * perhaps, and an error dialog for a browser.}}
\DoxyCodeLine{00055 \textcolor{comment}{ *}}
\DoxyCodeLine{00056 \textcolor{comment}{ * \(\backslash\)todo Do we really need such fine-\/grained control, or just yes/no tracing? */}}
\DoxyCodeLine{00057 \textcolor{keywordtype}{void} rs\_trace\_to(rs\_trace\_fn\_t *new\_impl)}
\DoxyCodeLine{00058 \{}
\DoxyCodeLine{00059     rs\_trace\_impl = new\_impl;}
\DoxyCodeLine{00060 \}}
\DoxyCodeLine{00061 }
\DoxyCodeLine{00062 \textcolor{keywordtype}{void} rs\_trace\_set\_level(rs\_loglevel level)}
\DoxyCodeLine{00063 \{}
\DoxyCodeLine{00064     rs\_trace\_level = level;}
\DoxyCodeLine{00065 \}}
\DoxyCodeLine{00066 }
\DoxyCodeLine{00067 \textcolor{keyword}{static} \textcolor{keywordtype}{void} rs\_log\_va(\textcolor{keywordtype}{int} flags, \textcolor{keywordtype}{char} \textcolor{keyword}{const} *fn, \textcolor{keywordtype}{char} \textcolor{keyword}{const} *fmt, va\_list va)}
\DoxyCodeLine{00068 \{}
\DoxyCodeLine{00069     \textcolor{keywordtype}{int} level = flags \& RS\_LOG\_PRIMASK;}
\DoxyCodeLine{00070 }
\DoxyCodeLine{00071     \textcolor{keywordflow}{if} (rs\_trace\_impl \&\& level <= rs\_trace\_level) \{}
\DoxyCodeLine{00072         \textcolor{keywordtype}{char} buf[1000];}
\DoxyCodeLine{00073         \textcolor{keywordtype}{char} full\_buf[1040];}
\DoxyCodeLine{00074 }
\DoxyCodeLine{00075         vsnprintf(buf, \textcolor{keyword}{sizeof}(buf), fmt, va);}
\DoxyCodeLine{00076         \textcolor{keywordflow}{if} (flags \& RS\_LOG\_NONAME || !(*fn)) \{}
\DoxyCodeLine{00077             snprintf(full\_buf, \textcolor{keyword}{sizeof}(full\_buf), \textcolor{stringliteral}{"{}\%s: \%s\%s\(\backslash\)n"{}}, MY\_NAME,}
\DoxyCodeLine{00078                      rs\_severities[level], buf);}
\DoxyCodeLine{00079         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{00080             snprintf(full\_buf, \textcolor{keyword}{sizeof}(full\_buf), \textcolor{stringliteral}{"{}\%s: \%s(\%s) \%s\(\backslash\)n"{}}, MY\_NAME,}
\DoxyCodeLine{00081                      rs\_severities[level], fn, buf);}
\DoxyCodeLine{00082         \}}
\DoxyCodeLine{00083         rs\_trace\_impl(level, full\_buf);}
\DoxyCodeLine{00084     \}}
\DoxyCodeLine{00085 \}}
\DoxyCodeLine{00086 }
\DoxyCodeLine{00087 \textcolor{comment}{/* Called by a macro that prepends the calling function name, etc. */}}
\DoxyCodeLine{00088 \textcolor{keywordtype}{void} rs\_log0(\textcolor{keywordtype}{int} level, \textcolor{keywordtype}{char} \textcolor{keyword}{const} *fn, \textcolor{keywordtype}{char} \textcolor{keyword}{const} *fmt, ...)}
\DoxyCodeLine{00089 \{}
\DoxyCodeLine{00090     va\_list va;}
\DoxyCodeLine{00091 }
\DoxyCodeLine{00092     va\_start(va, fmt);}
\DoxyCodeLine{00093     rs\_log\_va(level, fn, fmt, va);}
\DoxyCodeLine{00094     va\_end(va);}
\DoxyCodeLine{00095 \}}
\DoxyCodeLine{00096 }
\DoxyCodeLine{00097 \textcolor{keywordtype}{void} rs\_trace\_stderr(rs\_loglevel UNUSED(level), \textcolor{keywordtype}{char} \textcolor{keyword}{const} *msg)}
\DoxyCodeLine{00098 \{}
\DoxyCodeLine{00099     fputs(msg, stderr);}
\DoxyCodeLine{00100 \}}
\DoxyCodeLine{00101 }
\DoxyCodeLine{00102 \textcolor{keywordtype}{int} rs\_supports\_trace(\textcolor{keywordtype}{void})}
\DoxyCodeLine{00103 \{}
\DoxyCodeLine{00104 \textcolor{preprocessor}{\#ifdef DO\_RS\_TRACE}}
\DoxyCodeLine{00105     \textcolor{keywordflow}{return} 1;}
\DoxyCodeLine{00106 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{00107     \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{00108 \textcolor{preprocessor}{\#endif                          }\textcolor{comment}{/* !DO\_RS\_TRACE */}\textcolor{preprocessor}{}}
\DoxyCodeLine{00109 \}}

\end{DoxyCode}
