Skip to content

Commit

Permalink
Fix #130 don't export private symbols.
Browse files Browse the repository at this point in the history
In CMakeLists.txt use cmake's GenerateExportHeader support to generate
src/librsync_export.h and add it as a header to install. Set
"C_VISIBILITY_PRESET hidden" target property for rsync to hide all
not-explicitly-exported symbols. Do some minor indent tidying.

Add librsync_export.h to .gitignore and remove obsolete
librsync-config.h.

In librsync.h include librsync_export.h and explicitly export all
functions. Ensure it is correctly formated using "make tidyc".

In rdiff.c remove all includes and references to anything not
explicitly exported by librsync. This included usage of not exported
logging functions rs_error() and rs_log(). Update rdiff_usage() to
support formatted args with nicer output and use it everywhere we
report bad arguments instead of rs_error(). Always use exit() instead
of return for syntax errors to give neater termination output. Remove
PROGRAM define and just use "rdiff" instead.

In fileutil.[hc] move declarations for rs_file_open() and
rs_file_close() to librsync.h and explicitly export them. They are
used by rdiff.

In sumset.h move declaration of rs_signature_log_stats() to
librsync.h, and explicitly export it. It is used by rdiff.

In delta.c explicitly export rs_roll_paranoia and add it as an extern
in librsync.h. This is used by rdiff.

In sumset.c explicitly export RS_MD4_SUM_LENGTH and
RS_BLAKE2_SUM_LENGTH which are extern consts in librsync.h.

In whole.c explicitly export rs_inbuflen and rs_outbuflen which are
extern vars in librsync.h.

In version.c explicitly export rs_librsync_version which is an extern
const in librsync.h.
  • Loading branch information
dbaarda committed Aug 16, 2019
1 parent 7c21b88 commit c084f60
Show file tree
Hide file tree
Showing 11 changed files with 113 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -4,7 +4,7 @@ CMakeCache.txt
CTestTestfile.cmake
config.h
*.cbp
librsync-config.h
librsync_export.h
librsync.so*
librsync.a
librsync*.dylib
Expand Down
22 changes: 14 additions & 8 deletions CMakeLists.txt
Expand Up @@ -340,6 +340,9 @@ set(rsync_LIB_SRCS
${blake2_SRCS})

add_library(rsync SHARED ${rsync_LIB_SRCS})
include(GenerateExportHeader)
generate_export_header(rsync BASE_NAME librsync
EXPORT_FILE_NAME ${CMAKE_SOURCE_DIR}/src/librsync_export.h)
target_link_libraries(rsync ${blake2_LIBS})

# Optionally link zlib and bzip2 if
Expand All @@ -353,8 +356,10 @@ if (ENABLE_COMPRESSION)
endif (ZLIB_FOUND AND BZIP2_FOUND)
endif (ENABLE_COMPRESSION)

set_target_properties(rsync PROPERTIES VERSION ${LIBRSYNC_VERSION}
SOVERSION ${LIBRSYNC_MAJOR_VERSION})
set_target_properties(rsync PROPERTIES
VERSION ${LIBRSYNC_VERSION}
SOVERSION ${LIBRSYNC_MAJOR_VERSION}
C_VISIBILITY_PRESET hidden)
install(TARGETS rsync ${INSTALL_TARGETS_DEFAULT_ARGS} DESTINATION ${CMAKE_INSTALL_LIBDIR})


Expand All @@ -379,16 +384,17 @@ endif (BUILD_RDIFF)
########### install files ###############

install(FILES
src/librsync.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
src/librsync.h
src/librsync_export.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

message (STATUS "CMAKE_C_FLAGS = ${CMAKE_C_FLAGS}")

install(FILES
doc/librsync.3
DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
doc/librsync.3
DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
install(FILES
doc/rdiff.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
doc/rdiff.1
DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)

# vim: shiftwidth=4 expandtab
2 changes: 1 addition & 1 deletion src/delta.c
Expand Up @@ -104,7 +104,7 @@
#include "rollsum.h"

/* used by rdiff, but now redundant */
int rs_roll_paranoia = 0;
LIBRSYNC_EXPORT int rs_roll_paranoia = 0;

static rs_result rs_delta_s_scan(rs_job_t *job);
static rs_result rs_delta_s_flush(rs_job_t *job);
Expand Down
7 changes: 0 additions & 7 deletions src/fileutil.c
Expand Up @@ -73,13 +73,6 @@
# define fileno(f) _fileno((f))
#endif

/** Open a file with special handling for '-' or unspecified filenames.
*
* \param filename - The filename to open.
*
* \param mode - fopen style mode string.
*
* \param force - bool to force overwriting of existing files. */
FILE *rs_file_open(char const *filename, char const *mode, int force)
{
FILE *f;
Expand Down
2 changes: 0 additions & 2 deletions src/fileutil.h
Expand Up @@ -19,6 +19,4 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

FILE *rs_file_open(char const *filename, char const *mode, int force);
int rs_file_close(FILE *file);
void rs_get_filesize(FILE *f, rs_long_t *size);
109 changes: 70 additions & 39 deletions src/librsync.h
Expand Up @@ -36,6 +36,7 @@
# include <stdio.h>
# include <stdint.h>
# include <time.h>
# include "librsync_export.h"

# ifdef __cplusplus
extern "C" {
Expand All @@ -49,6 +50,9 @@ extern char const rs_librsync_version[];
/** Summary of the licence for librsync. */
extern char const rs_licence_string[];

/** Flag to turn on signature rollsum paranoia mode. */
extern int rs_roll_paranoia;

typedef uint8_t rs_byte_t;
typedef intmax_t rs_long_t;

Expand Down Expand Up @@ -120,19 +124,19 @@ typedef void rs_trace_fn_t(rs_loglevel level, char const *msg);
/** Set the least important message severity that will be output.
*
* \sa \ref api_trace */
void rs_trace_set_level(rs_loglevel level);
LIBRSYNC_EXPORT void rs_trace_set_level(rs_loglevel level);

/** Set trace callback.
*
* \sa \ref api_trace */
void rs_trace_to(rs_trace_fn_t *);
LIBRSYNC_EXPORT void rs_trace_to(rs_trace_fn_t *);

/** Default trace callback that writes to stderr.
*
* Implements ::rs_trace_fn_t, and may be passed to rs_trace_to().
*
* \sa \ref api_trace */
void rs_trace_stderr(rs_loglevel level, char const *msg);
LIBRSYNC_EXPORT void rs_trace_stderr(rs_loglevel level, char const *msg);

/** Check whether the library was compiled with debugging trace.
*
Expand All @@ -141,19 +145,20 @@ void rs_trace_stderr(rs_loglevel level, char const *msg);
* If this returns false, then trying to turn trace on will achieve nothing.
*
* \sa \ref api_trace */
int rs_supports_trace(void);
LIBRSYNC_EXPORT int rs_supports_trace(void);

/** Convert \p from_len bytes at \p from_buf into a hex representation in \p
* to_buf, which must be twice as long plus one byte for the null terminator. */
void rs_hexify(char *to_buf, void const *from_buf, int from_len);
LIBRSYNC_EXPORT void rs_hexify(char *to_buf, void const *from_buf,
int from_len);

/** Decode a base64 buffer in place.
*
* \returns The number of binary bytes. */
size_t rs_unbase64(char *s);
LIBRSYNC_EXPORT size_t rs_unbase64(char *s);

/** Encode a buffer as base64. */
void rs_base64(unsigned char const *buf, int n, char *out);
LIBRSYNC_EXPORT void rs_base64(unsigned char const *buf, int n, char *out);

/** Return codes from nonblocking rsync operations.
*
Expand Down Expand Up @@ -183,7 +188,7 @@ typedef enum rs_result {
} rs_result;

/** Return an English description of a ::rs_result value. */
char const *rs_strerror(rs_result r);
LIBRSYNC_EXPORT char const *rs_strerror(rs_result r);

/** Performance statistics from a librsync encoding or decoding operation.
*
Expand Down Expand Up @@ -223,8 +228,8 @@ extern const int RS_MD4_SUM_LENGTH, RS_BLAKE2_SUM_LENGTH;
typedef uint32_t rs_weak_sum_t;
typedef unsigned char rs_strong_sum_t[RS_MAX_STRONG_SUM_LENGTH];

void rs_mdfour(unsigned char *out, void const *in, size_t);
void rs_mdfour_begin( /* @out@ */ rs_mdfour_t *md);
LIBRSYNC_EXPORT void rs_mdfour(unsigned char *out, void const *in, size_t);
LIBRSYNC_EXPORT void rs_mdfour_begin( /* @out@ */ rs_mdfour_t *md);

/** Feed some data into the MD4 accumulator.
*
Expand All @@ -233,8 +238,9 @@ void rs_mdfour_begin( /* @out@ */ rs_mdfour_t *md);
* \param in_void Data to add.
*
* \param n Number of bytes fed in. */
void rs_mdfour_update(rs_mdfour_t *md, void const *in_void, size_t n);
void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out);
LIBRSYNC_EXPORT void rs_mdfour_update(rs_mdfour_t *md, void const *in_void,
size_t n);
LIBRSYNC_EXPORT void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out);

/** Return a human-readable representation of statistics.
*
Expand All @@ -250,21 +256,25 @@ void rs_mdfour_result(rs_mdfour_t *md, unsigned char *out);
* \return \p buf.
*
* \sa \ref api_stats */
char *rs_format_stats(rs_stats_t const *stats, char *buf, size_t size);
LIBRSYNC_EXPORT char *rs_format_stats(rs_stats_t const *stats, char *buf,
size_t size);

/** Write statistics into the current log as text.
*
* \sa \ref api_stats \sa \ref api_trace */
int rs_log_stats(rs_stats_t const *stats);
LIBRSYNC_EXPORT int rs_log_stats(rs_stats_t const *stats);

/** The signature datastructure type. */
typedef struct rs_signature rs_signature_t;

/** Log the rs_signature_delta match stats. */
LIBRSYNC_EXPORT void rs_signature_log_stats(rs_signature_t const *sig);

/** Deep deallocation of checksums. */
void rs_free_sumset(rs_signature_t *);
LIBRSYNC_EXPORT void rs_free_sumset(rs_signature_t *);

/** Dump signatures to the log. */
void rs_sumset_dump(rs_signature_t const *);
LIBRSYNC_EXPORT void rs_sumset_dump(rs_signature_t const *);

/** Description of input and output buffers.
*
Expand Down Expand Up @@ -358,7 +368,7 @@ typedef struct rs_job rs_job_t;
* there, without trying to accumulate anything else.
*
* \sa \ref api_streaming */
rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);
LIBRSYNC_EXPORT rs_result rs_job_iter(rs_job_t *job, rs_buffers_t *buffers);

/** Type of application-supplied function for rs_job_drive().
*
Expand All @@ -368,14 +378,15 @@ typedef rs_result rs_driven_cb(rs_job_t *job, rs_buffers_t *buf,

/** Actively process a job, by making callbacks to fill and empty the buffers
* until the job is done. */
rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf, rs_driven_cb in_cb,
void *in_opaque, rs_driven_cb out_cb, void *out_opaque);
LIBRSYNC_EXPORT rs_result rs_job_drive(rs_job_t *job, rs_buffers_t *buf,
rs_driven_cb in_cb, void *in_opaque,
rs_driven_cb out_cb, void *out_opaque);

/** Return a pointer to the statistics in a job. */
const rs_stats_t *rs_job_statistics(rs_job_t *job);
LIBRSYNC_EXPORT const rs_stats_t *rs_job_statistics(rs_job_t *job);

/** Deallocate job state. */
rs_result rs_job_free(rs_job_t *);
LIBRSYNC_EXPORT rs_result rs_job_free(rs_job_t *);

/** Start generating a signature.
*
Expand All @@ -392,14 +403,15 @@ rs_result rs_job_free(rs_job_t *);
* at zero to get the full strength.
*
* \sa rs_sig_file() */
rs_job_t *rs_sig_begin(size_t new_block_len, size_t strong_sum_len,
rs_magic_number sig_magic);
LIBRSYNC_EXPORT rs_job_t *rs_sig_begin(size_t new_block_len,
size_t strong_sum_len,
rs_magic_number sig_magic);

/** Prepare to compute a streaming delta.
*
* \todo Add a version of this that takes a ::rs_magic_number controlling the
* delta format. */
rs_job_t *rs_delta_begin(rs_signature_t *);
LIBRSYNC_EXPORT rs_job_t *rs_delta_begin(rs_signature_t *);

/** Read a signature from a file into an ::rs_signature structure in memory.
*
Expand All @@ -408,12 +420,12 @@ rs_job_t *rs_delta_begin(rs_signature_t *);
*
* \note After loading the signatures, you must call \ref rs_build_hash_table()
* before you can use them. */
rs_job_t *rs_loadsig_begin(rs_signature_t **);
LIBRSYNC_EXPORT rs_job_t *rs_loadsig_begin(rs_signature_t **);

/** Call this after loading a signature to index it.
*
* Use rs_free_sumset() to release it after use. */
rs_result rs_build_hash_table(rs_signature_t *sums);
LIBRSYNC_EXPORT rs_result rs_build_hash_table(rs_signature_t *sums);

/** Callback used to retrieve parts of the basis file.
*
Expand Down Expand Up @@ -444,11 +456,31 @@ typedef rs_result rs_copy_cb(void *opaque, rs_long_t pos, size_t *len,
* \todo Implement COPY commands.
*
* \sa rs_patch_file() \sa \ref api_streaming */
rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg);
LIBRSYNC_EXPORT rs_job_t *rs_patch_begin(rs_copy_cb * copy_cb, void *copy_arg);

# ifndef RSYNC_NO_STDIO_INTERFACE
# include <stdio.h>

/** Open a file with special handling for '-' or unspecified filenames.
*
* This provides a platform independent way to open large binary files. A
* filename "" or "-" means stdin for reading, or stdout for writing.
*
* \param filename - The filename to open.
*
* \param mode - fopen style mode string.
*
* \param force - bool to force overwriting of existing files. */
LIBRSYNC_EXPORT FILE *rs_file_open(char const *filename, char const *mode,
int force);

/** Close a file with special handling for stdin or stdout. */
LIBRSYNC_EXPORT int rs_file_close(FILE *file);

/** ::rs_copy_cb that reads from a stdio file. */
LIBRSYNC_EXPORT rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len,
void **buf);

/** Buffer sizes for file IO.
*
* The default 0 means use the recommended buffer size for the operation being
Expand All @@ -471,9 +503,10 @@ extern int rs_inbuflen, rs_outbuflen;
* \param stats Optional pointer to receive statistics.
*
* \sa \ref api_whole */
rs_result rs_sig_file(FILE *old_file, FILE *sig_file, size_t block_len,
size_t strong_len, rs_magic_number sig_magic,
rs_stats_t *stats);
LIBRSYNC_EXPORT rs_result rs_sig_file(FILE *old_file, FILE *sig_file,
size_t block_len, size_t strong_len,
rs_magic_number sig_magic,
rs_stats_t *stats);

/** Load signatures from a signature file into memory.
*
Expand All @@ -484,23 +517,21 @@ rs_result rs_sig_file(FILE *old_file, FILE *sig_file, size_t block_len,
* \param stats Optional pointer to receive statistics.
*
* \sa \ref api_whole */
rs_result rs_loadsig_file(FILE *sig_file, rs_signature_t **sumset,
rs_stats_t *stats);

/** ::rs_copy_cb that reads from a stdio file. */
rs_result rs_file_copy_cb(void *arg, rs_long_t pos, size_t *len, void **buf);
LIBRSYNC_EXPORT rs_result rs_loadsig_file(FILE *sig_file,
rs_signature_t **sumset,
rs_stats_t *stats);

/** Generate a delta between a signature and a new file into a delta file.
*
* \sa \ref api_whole */
rs_result rs_delta_file(rs_signature_t *, FILE *new_file, FILE *delta_file,
rs_stats_t *);
LIBRSYNC_EXPORT rs_result rs_delta_file(rs_signature_t *, FILE *new_file,
FILE *delta_file, rs_stats_t *);

/** Apply a patch, relative to a basis, into a new file.
*
* \sa \ref api_whole */
rs_result rs_patch_file(FILE *basis_file, FILE *delta_file, FILE *new_file,
rs_stats_t *);
LIBRSYNC_EXPORT rs_result rs_patch_file(FILE *basis_file, FILE *delta_file,
FILE *new_file, rs_stats_t *);
# endif /* !RSYNC_NO_STDIO_INTERFACE */

# ifdef __cplusplus
Expand Down

0 comments on commit c084f60

Please sign in to comment.