helper.h File Reference

Helper functions header file. More...

#include <ctype.h>
#include "global.h"
#include "options.h"
Include dependency graph for helper.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  encoder_t
 Structure for an encoding process, with svn_stream_t input. More...

Defines

#define _bin2hex(b, h)
#define Mbin2hex(bin, hex, len)
#define SFF_WHITESPACE   (1)
 If this bit is set, whitespace at the start and the end is removed.
#define SFF_COMMENT   (2)
 With this flag comment lines (with '#' as first non-whitespace character) are ignored.
#define SFF_RESET_LINENUM   (0x4000)
 Can/should be used after opening the file.
#define SFF_GET_LINENUM   (0x8000)
 Get the line number of the last (current) FILE*, as return value.

Functions

int hlp__local2utf8 (const char *local_string, char **utf8_string, int len)
 Converts a string with local encoding to UTF8, suitable for storage in the repository.
int hlp__utf82local (const char *utf8_string, char **local_string, int len)
 Converts an UTF8 string to local encoding, to make it printable on the current console.
void hlp__copy_stats (struct stat *src, struct sstat_t *dest)
int hlp__lstat (const char *fn, struct sstat_t *st)
 A wrapper for lstat().
int hlp__fstat (int fd, struct sstat_t *st)
 A wrapper for fstat().
char * hlp__pathcopy (char *dst, int *len,...) __attribute__((sentinel))
 A function like strcpy, but cleaning up paths.
int hlp__parse_rev (char *stg, char **eos, svn_revnum_t *rev)
 Parses a string to a revision number.
int hlp__string_from_filep (FILE *input, char **string, char **eos, int flags)
 Reads a string from the given input into the (self-managed) buffer string, removes \r and/or \n at the end, and depending on flags strips whitespace or comments.
const char * hlp__get_uname (uid_t uid, char *not_found)
 Returns the name of the given user.
const char * hlp__get_grname (gid_t gid, char *not_found)
 Returns the name of the given group.
int hlp__safe_print (FILE *output, char *string, int maxlen)
 Print the given data to output, safely converting special characters to codes like \x1e.
int hlp__chrooter (void)
 Chroot helper function.
int hlp__match_path_envs (struct estat *root)
 Distribute the environment variables on the loaded entries.
int hlp__format_path (struct estat *sts, char *wc_relative_path, char **output)
 Return a path that gets displayed for the user.
int hlp__get_gid (char *group, gid_t *gid, apr_pool_t *pool)
 Find a GID by group name, cached.
int hlp__get_uid (char *user, uid_t *uid, apr_pool_t *pool)
 Find a UID by user name, cached.
char * hlp__rev_to_string (svn_revnum_t rev)
 Returns a string describing the revision number.
int hlp__strncmp_uline_eq_dash (char *always_ul, char *other, int max)
 Function to compare two strings for max bytes, but treating '-' and '_' as equal.
int hlp__is_special_property_name (const char *name)
 name is a subversion internal property.
int hlp__stream_md5 (svn_stream_t *stream, unsigned char md5[APR_MD5_DIGESTSIZE])
 Reads all data from stream and drops it.
int hlp__delay (time_t start, enum opt__delay_e which)
 Delay until time wraps.
int hlp__rename_to_unique (char *fn, char *extension, const char **unique_name, apr_pool_t *pool)
 Renames a local file to something like .mine.
int hlp__strnalloc (int len, char **dest, const char const *source)
 Allocates a buffer in *dest, and copies source.
int hlp__strmnalloc (int len, char **dest, const char const *source,...) __attribute__((sentinel))
 Like hlp__strnalloc, but concatenates strings until a NULL is found.
static int hlp__strdup (char **dest, const char const *src)
 Own implementation of strdup(), possibly returning ENOMEM.
int hlp__calloc (void *output, size_t nmemb, size_t count)
 Error returning calloc(); uses (void**) output.
int hlp__realloc (void *output, size_t size)
 Reallocate the (void**) output.
static int hlp__alloc (void *dest, size_t len)
 Allocates a buffer of len bytes in (void**) *dest; can return ENOMEM.
char * hlp__get_word (char *input, char **word_start)
 Stores the first non-whitespace character position from input in word_start, and returns the next whitespace position in word_end.
static char * hlp__skip_ws (char *input)
 Skips all whitespace, returns first non-whitespace character.
int hlp__get_svn_config (apr_hash_t **config)
 Reads the subversion config file(s), found by Configuration directory for the subversion libraries.
static int hlp__rightmost_0_bit (int i)
 Algorithm for finding the rightmost 0 bit.
int hlp__compare_string_pointers (const void *a, const void *b)

Variables

static const char hex_chars [] = "0123456789abcdef"

f_encoder Encoder and decoder



#define ENCODE_BLOCKSIZE   (32*1024)
 Blocksize for encoding pipes; we use a not too small value.
int hlp__encode_filter (svn_stream_t *s_stream, const char *command, int is_writer, char *path, svn_stream_t **output, struct encoder_t **encoder_out, apr_pool_t *pool)
 Encode svn_stream_t filter.

Detailed Description

Helper functions header file.

Definition in file helper.h.


Define Documentation

#define _bin2hex ( b,
 ) 
Value:
do {                \
        *(h++) = hex_chars[*b >> 4];        \
        *(h++) = hex_chars[*b & 0x0f];      \
        b++;                                \
    } while(0)

Definition at line 23 of file helper.h.

#define ENCODE_BLOCKSIZE   (32*1024)

Blocksize for encoding pipes; we use a not too small value.

Definition at line 93 of file helper.h.

#define Mbin2hex ( bin,
hex,
len   ) 
Value:
do {        \
        switch(len)                         \
        {                                   \
            case  4: _bin2hex(bin, hex);    \
            case  3: _bin2hex(bin, hex);    \
            case  2: _bin2hex(bin, hex);    \
            case  1: _bin2hex(bin, hex);    \
            case  0: break;                 \
            default:                        \
             { int i=len;                   \
                 while (i--)                \
                     _bin2hex(bin, hex);    \
             }                              \
        }                                   \
                                            \
        *hex='\0';                      \
    } while(0)

Definition at line 29 of file helper.h.

Referenced by waa__get_waa_directory().

#define SFF_COMMENT   (2)

With this flag comment lines (with '#' as first non-whitespace character) are ignored.

Definition at line 74 of file helper.h.

Referenced by hlp__string_from_filep(), ign___load_group(), and opt__load_settings().

#define SFF_GET_LINENUM   (0x8000)

Get the line number of the last (current) FILE*, as return value.

Definition at line 78 of file helper.h.

Referenced by hlp__string_from_filep(), ign___load_group(), and opt__load_settings().

#define SFF_RESET_LINENUM   (0x4000)

Can/should be used after opening the file.

Definition at line 76 of file helper.h.

Referenced by cm__work(), hlp__string_from_filep(), ign___load_group(), and opt__load_settings().

#define SFF_WHITESPACE   (1)

If this bit is set, whitespace at the start and the end is removed.

Definition at line 71 of file helper.h.

Referenced by cm__work(), hlp__string_from_filep(), ign___load_group(), ign__work(), opt__load_settings(), and url__work().


Function Documentation

static int hlp__alloc ( void *  dest,
size_t  len 
) [inline, static]

Allocates a buffer of len bytes in (void**) *dest; can return ENOMEM.

Definition at line 198 of file helper.h.

References hlp__realloc().

Referenced by cch__entry_set(), dir__enumerator(), hlp__encode_filter(), hlp__match_path_envs(), hlp__stream_md5(), hlp__string_from_filep(), hlp__strmnalloc(), hlp__strnalloc(), ign__compile_pattern(), log__receiver(), ops__read_special_entry(), url__load_list(), waa__find_common_base2(), waa__init(), waa__input_tree(), and waa__new_entry_block().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__calloc ( void *  output,
size_t  nmemb,
size_t  count 
)

Error returning calloc(); uses (void**) output.

Error returning calloc(); uses (void**) output.

That is not defined in terms of hlp__alloc(), because glibc might do some magic to get automagically 0-initialized memory (like mapping /dev/zero).

Definition at line 1985 of file helper.c.

References STOPIF_CODE_ERR.

Referenced by cs__read_manber_hashes(), hsh__new(), ign___new_group(), ops__allocate(), url__allocate(), waa__copy_entries(), and waa__output_tree().

Here is the caller graph for this function:

int hlp__chrooter ( void   ) 

Chroot helper function.

Chroot helper function.

See HOWTO: About running fsvs on older systems.

Definition at line 1363 of file helper.c.

References CHROOTER_CWD_ENV, CHROOTER_LIBS_ENV, CHROOTER_ROOT_ENV, DEBUGP, filename, and STOPIF_CODE_ERR.

Referenced by main().

Here is the caller graph for this function:

int hlp__compare_string_pointers ( const void *  a,
const void *  b 
)

Definition at line 2072 of file helper.c.

Referenced by log__receiver().

Here is the caller graph for this function:

void hlp__copy_stats ( struct stat *  src,
struct sstat_t dest 
)

Referenced by hlp__fstat(), and hlp__lstat().

Here is the caller graph for this function:

int hlp__delay ( time_t  start,
enum opt__delay_e  which 
)

Delay until time wraps.

Delay until time wraps.

Needed because of filesystem granularities; FSVS only stores seconds, not more.

Definition at line 1841 of file helper.c.

References DEBUGP, and OPT__DELAY.

Referenced by ci__work(), co__work(), delay__work(), rev__work(), and up__work().

Here is the caller graph for this function:

int hlp__encode_filter ( svn_stream_t *  s_stream,
const char *  command,
int  is_writer,
char *  path,
svn_stream_t **  output,
struct encoder_t **  encoder_out,
apr_pool_t *  pool 
)

Encode svn_stream_t filter.

Encode svn_stream_t filter.

For is_writer data gets written into s_stream, gets piped as STDIN into command, and the resulting STDOUT can be read back with output; if is_writer is zero, data must be read from output to get processed.

After finishing the returned pointer *encoder_out can be used to retrieve the MD5.

*encoder_out must not be free()d; delta editors that store data locally get driven by the subversion libraries, and the only place where we can be sure that it's no longer in use is when the streams get closed. Therefore the free()ing has to be done in hlp___encode_close(); callers that want to get the final MD5 can set the encoder->output_md5 pointer to the destination address.

Definition at line 1293 of file helper.c.

References encoder_t::bytes_left, encoder_t::child, DEBUGP, encoder_t::eof, hlp___encode_close(), hlp___encode_filter_child(), hlp___encode_read(), hlp___encode_write(), hlp__alloc(), encoder_t::is_writer, encoder_t::md5_ctx, encoder_t::orig, encoder_t::output_md5, encoder_t::pipe_in, encoder_t::pipe_out, STOPIF, STOPIF_CODE_ERR, and STOPIF_ENOMEM.

Referenced by ci__nondir(), rev__get_text_to_stream(), and up__apply_textdelta().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__format_path ( struct estat sts,
char *  wc_relative_path,
char **  output 
)

Return a path that gets displayed for the user.

Return a path that gets displayed for the user.

Todo:
Build the wc_relative_path only if necessary - remove the parameter from the caller chains.

Todo:
We should set it beginning from a command line parameter, if we have one. Preferably the nearest one ...

Definition at line 1569 of file helper.c.

References estat::arg, BUG_ON, cch__entry_set(), DEBUGP, environ, ENVIRONMENT_START, hlp___is_valid_env(), hlp__pathcopy(), estat::name, OPT__PATH, estat::parent, PATH_ABSOLUTE, PATH_CACHEDENVIRON, PATH_FULLENVIRON, estat::path_len, PATH_PARMRELATIVE, PATH_SEPARATOR, PATH_WCRELATIVE, STOPIF, wc_path, and wc_path_len.

Referenced by cm___match(), df___repos_repos(), df__do_diff(), and st__print_status().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__get_gid ( char *  group,
gid_t *  gid,
apr_pool_t *  pool 
)

Find a GID by group name, cached.

Find a GID by group name, cached.

Uses a simple hash function.

Definition at line 705 of file helper.c.

References cch__hash_add(), cch__hash_find(), and STOPIF.

Referenced by up__parse_prop().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* hlp__get_grname ( gid_t  gid,
char *  not_found 
)

Returns the name of the given group.

Returns the name of the given group.

Has a few buffers for these operations.

The cache is statically allocated, as we cannot return ENOMEM.

If we cannot store a cache during querying, we'll return the value, but forget that we already know it.

Todo:
Keep most-used?

Definition at line 631 of file helper.c.

References CACHE_DEFAULT, cch__add(), cch__find(), and cache_t::max.

Referenced by ci___set_props(), df__do_diff(), and st__print_entry_info().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__get_svn_config ( apr_hash_t **  config  ) 

Reads the subversion config file(s), found by Configuration directory for the subversion libraries.

Reads the subversion config file(s), found by Configuration directory for the subversion libraries.

Caches the result, so that the configuration is only fetched a single time.

Definition at line 1911 of file helper.c.

References global_pool, OPT__CONFIG_DIR, and STOPIF_SVNERR.

Referenced by cb__init(), and url__open_session().

Here is the caller graph for this function:

int hlp__get_uid ( char *  user,
uid_t *  uid,
apr_pool_t *  pool 
)

Find a UID by user name, cached.

Find a UID by user name, cached.

Uses a simple hash function.

Definition at line 673 of file helper.c.

References cch__hash_add(), cch__hash_find(), and STOPIF.

Referenced by up__parse_prop().

Here is the call graph for this function:

Here is the caller graph for this function:

const char* hlp__get_uname ( uid_t  uid,
char *  not_found 
)

Returns the name of the given user.

Returns the name of the given user.

Has a few buffers for these operations; the cache is statically allocated, as we cannot return ENOMEM.

If we cannot store a cache during querying, we'll return the value, but forget that we already know it.

Definition at line 655 of file helper.c.

References CACHE_DEFAULT, cch__add(), cch__find(), and cache_t::max.

Referenced by ci___set_props(), df__do_diff(), and st__print_entry_info().

Here is the call graph for this function:

Here is the caller graph for this function:

char* hlp__get_word ( char *  input,
char **  word_start 
)

Stores the first non-whitespace character position from input in word_start, and returns the next whitespace position in word_end.

Definition at line 2019 of file helper.c.

References hlp__skip_ws().

Referenced by ign___load_group(), and ops__load_1entry().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__is_special_property_name ( const char *  name  ) 

name is a subversion internal property.

Definition at line 1790 of file helper.c.

Referenced by ci___send_user_props(), and up__parse_prop().

Here is the caller graph for this function:

int hlp__local2utf8 ( const char *  local_string,
char **  utf8_string,
int  len 
)

Converts a string with local encoding to UTF8, suitable for storage in the repository.

Converts a string with local encoding to UTF8, suitable for storage in the repository.

If len ==-1, a strlen() is done.

Definition at line 227 of file helper.c.

References hlp___do_convert(), hlp___dummy_convert(), hlp___get_conv_handle(), local_codeset, and STOPIF.

Referenced by ci__nondir(), ci__work(), rev__get_props(), rev__get_text_to_stream(), sync___recurse(), and up__apply_textdelta().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__match_path_envs ( struct estat root  ) 

Distribute the environment variables on the loaded entries.

Definition at line 1508 of file helper.c.

References estat::arg, DEBUGP, environ, ENVIRONMENT_START, hlp___is_valid_env(), hlp__alloc(), estat::name, ops__traverse(), STOPIF, wc_path, and wc_path_len.

Referenced by waa__read_or_build_tree().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__parse_rev ( char *  stg,
char **  eos,
svn_revnum_t *  rev 
)

Parses a string to a revision number.

Parses a string to a revision number.

Normally a number; currently a special case is recogniced, namely HEAD .

If the parameter eos is not NULL, it gets set to the character behind the parsed part, which is ignored. If it is NULL, the string must end here.

Definition at line 591 of file helper.c.

References opt_target_revision, and STOPIF_CODE_ERR.

Referenced by main(), url__mark_todo(), and url__parse().

Here is the caller graph for this function:

char* hlp__pathcopy ( char *  dst,
int *  len,
  ... 
)

A function like strcpy, but cleaning up paths.

A function like strcpy, but cleaning up paths.

Parameters:
dst A target buffer
len An optional length-saving field
... A NULL -terminated list of pointers, which will be concatenated.
Returns:
dst as target buffer.

This works like strcpy, but removes sequences like /./ and //.

Warning:
The buffer dst will be overwritten and has to have enough space!

If the first path has no PATH_SEPARATOR as first character, the start_path is used as beginning - so that always full paths are returned.

Used for cases where we cannot run realpath() (as this follows symlinks, something we don't want), but need to take care of some strange pathnames.

Note:
Not as easy as it sounds - try to do cases like a//..//.///b/c//.

For people reading JoelOnSoftware and related pages - yes, this is cheating, but it works and is fast :-).

Definition at line 438 of file helper.c.

References DEBUGP, PATH_SEPARATOR, start_path, and start_path_len.

Referenced by cm___absolute_path(), hlp__format_path(), opt___normalized_path(), waa___get_path_md5(), waa__find_common_base2(), and waa__init().

Here is the caller graph for this function:

int hlp__realloc ( void *  output,
size_t  size 
)
int hlp__rename_to_unique ( char *  fn,
char *  extension,
const char **  unique_name,
apr_pool_t *  pool 
)

Renames a local file to something like .mine.

Renames a local file to something like .mine.

We could either generate a name ourself, or just use this function - and have in mind that we open and close a file, just to overwrite it immediately.

But by using that function we get the behaviour that subversion users already know.

Definition at line 1864 of file helper.c.

References DEBUGP, PATH_SEPARATOR, STOPIF, and STOPIF_SVNERR.

Referenced by rev___undo_change().

Here is the caller graph for this function:

char* hlp__rev_to_string ( svn_revnum_t  rev  ) 

Returns a string describing the revision number.

Returns a string describing the revision number.

Can be non-numeric, like HEAD.

Definition at line 1735 of file helper.c.

References BUG_ON.

Referenced by log__work(), rev___revert_to_base(), rev__get_text_to_stream(), url___dump(), url__iterator2(), and url__parse().

Here is the caller graph for this function:

static int hlp__rightmost_0_bit ( int  i  )  [inline, static]

Algorithm for finding the rightmost 0 bit.

orig i: ... x 0 1 1 1 i+1: ... x 1 0 0 0 XOR gives: ... x 1 1 1 1 AND i+1: ... 0 1 0 0 0

Maybe there's an easier way ... don't have "Numerical Recipes" here with me.

Definition at line 228 of file helper.h.

Referenced by main().

Here is the caller graph for this function:

int hlp__safe_print ( FILE *  output,
char *  string,
int  maxlen 
)

Print the given data to output, safely converting special characters to codes like \x1e.

Print the given data to output, safely converting special characters to codes like \x1e.

Some special values are recogniced - eg. \r, \n.

Definition at line 829 of file helper.c.

References STOPIF_CODE_EPIPE.

Referenced by prp__l_work().

Here is the caller graph for this function:

static char* hlp__skip_ws ( char *  input  )  [inline, static]

Skips all whitespace, returns first non-whitespace character.

Definition at line 209 of file helper.h.

Referenced by cm___string_to_rev_path(), hlp__get_word(), hlp__string_from_filep(), ign___load_group(), ops__load_1entry(), opt__parse(), opt__parse_option(), and up__parse_prop().

Here is the caller graph for this function:

static int hlp__strdup ( char **  dest,
const char const *  src 
) [inline, static]

Own implementation of strdup(), possibly returning ENOMEM.

Definition at line 190 of file helper.h.

References hlp__strnalloc().

Referenced by cb__add_entry(), ci___send_user_props(), cm__work(), df__do_diff(), hsh___new_bare(), ign___load_group(), ign__work(), ops__traverse(), up__fetch_decoder(), up__parse_prop(), url__parse(), waa__given_or_current_wd(), and waa__open().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__stream_md5 ( svn_stream_t *  stream,
unsigned char  md5[APR_MD5_DIGESTSIZE] 
)

Reads all data from stream and drops it.

Reads all data from stream and drops it.

md5, if not NULL, must point to at least MD5_DIGEST_LENGTH bytes.

Definition at line 1805 of file helper.c.

References DEBUGP, hlp__alloc(), estat::md5, STOPIF, and STOPIF_SVNERR.

Referenced by ci__nondir().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__string_from_filep ( FILE *  input,
char **  string,
char **  eos,
int  flags 
)

Reads a string from the given input into the (self-managed) buffer string, removes \r and/or \n at the end, and depending on flags strips whitespace or comments.

Reads a string from the given input into the (self-managed) buffer string, removes \r and/or \n at the end, and depending on flags strips whitespace or comments.

Returns 0 for success, EOF for no more data.

Empty lines (only whitespace) are ignored (but counted).

If no_ws is set, the returned pointer has whitespace at beginning and end removed; \r and \n at the end are always removed.

Only a single statically allocated buffer is used, so the line has to be copied if needed over several invocations.

eos is set to the last non-whitespace character in the line.

Definition at line 746 of file helper.c.

References DEBUGP, hlp__alloc(), hlp__skip_ws(), SFF_COMMENT, SFF_GET_LINENUM, SFF_RESET_LINENUM, SFF_WHITESPACE, STOPIF, and STRING_LENGTH.

Referenced by cm__work(), ign___load_group(), ign__work(), opt__load_settings(), url__load_list(), and url__work().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__strmnalloc ( int  len,
char **  dest,
const char const *  source,
  ... 
)

Like hlp__strnalloc, but concatenates strings until a NULL is found.

Definition at line 1949 of file helper.c.

References BUG_ON, hlp__alloc(), and STOPIF.

Referenced by ci__getmsg(), ign___init_pattern_into(), ign___load_group(), log__receiver(), and log__work().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__strnalloc ( int  len,
char **  dest,
const char const *  source 
)

Allocates a buffer in *dest, and copies source.

Allocates a buffer in *dest, and copies source.

If source is not NULL len bytes are copied. The buffer is always \0 terminated.

Definition at line 1934 of file helper.c.

References hlp__alloc(), and STOPIF.

Referenced by ci__work(), cm___get_base_source(), hlp__strdup(), ign___init_pattern_into(), ign___load_group(), log__work(), opt___store_string(), url__open_session(), url__parse(), waa__find_common_base2(), and waa__set_working_copy().

Here is the call graph for this function:

Here is the caller graph for this function:

int hlp__strncmp_uline_eq_dash ( char *  always_ul,
char *  other,
int  max 
)

Function to compare two strings for max bytes, but treating '-' and '_' as equal.

Function to compare two strings for max bytes, but treating '-' and '_' as equal.

If max<0, the comparision is done until the \0. max is the maximum number of characters to compare; the result is always equal (==0), if max==0.

Not useable for lesser/greater compares.

Definition at line 1762 of file helper.c.

Referenced by opt__parse().

Here is the caller graph for this function:

int hlp__utf82local ( const char *  utf8_string,
char **  local_string,
int  len 
)

Converts an UTF8 string to local encoding, to make it printable on the current console.

Converts an UTF8 string to local encoding, to make it printable on the current console.

If len ==-1, a strlen() is done.

Definition at line 255 of file helper.c.

References hlp___do_convert(), hlp___dummy_convert(), hlp___get_conv_handle(), local_codeset, and STOPIF.

Referenced by cb___delete_entry(), cb__add_entry(), log__receiver(), sync___recurse(), up__handle_special(), and up__parse_prop().

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const char hex_chars[] = "0123456789abcdef" [static]

Definition at line 21 of file helper.h.


Generated for fsvs by  doxygen 1.6.1