00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __HELPER_H__
00010 #define __HELPER_H__
00011
00012 #include <ctype.h>
00013
00014 #include "global.h"
00015 #include "options.h"
00016
00021 static const char hex_chars[] = "0123456789abcdef";
00022
00023 #define _bin2hex(b, h) do { \
00024 *(h++) = hex_chars[*b >> 4]; \
00025 *(h++) = hex_chars[*b & 0x0f]; \
00026 b++; \
00027 } while(0)
00028
00029 #define Mbin2hex(bin, hex, len) do { \
00030 switch(len) \
00031 { \
00032 case 4: _bin2hex(bin, hex); \
00033 case 3: _bin2hex(bin, hex); \
00034 case 2: _bin2hex(bin, hex); \
00035 case 1: _bin2hex(bin, hex); \
00036 case 0: break; \
00037 default: \
00038 { int i=len; \
00039 while (i--) \
00040 _bin2hex(bin, hex); \
00041 } \
00042 } \
00043 \
00044 *hex='\0'; \
00045 } while(0)
00046
00047
00050 int hlp__local2utf8(const char* local_string, char** utf8_string, int len);
00054 int hlp__utf82local(const char* utf8_string, char** local_string, int len);
00055
00056 void hlp__copy_stats(struct stat *src, struct sstat_t *dest);
00057 int hlp__lstat(const char *fn, struct sstat_t *st);
00058 int hlp__fstat(int fd, struct sstat_t *st);
00059
00061 char *hlp__pathcopy (char *dst, int *len, ...) __attribute__((sentinel)) ;
00062
00064 int hlp__parse_rev(char *stg, char **eos, svn_revnum_t *rev);
00065
00069 int hlp__string_from_filep(FILE *input, char **string, char **eos, int flags);
00071 #define SFF_WHITESPACE (1)
00072
00074 #define SFF_COMMENT (2)
00075
00076 #define SFF_RESET_LINENUM (0x4000)
00077
00078 #define SFF_GET_LINENUM (0x8000)
00079
00081 const char *hlp__get_uname(uid_t uid, char *not_found);
00083 const char *hlp__get_grname(gid_t gid, char *not_found);
00084
00087 int hlp__safe_print(FILE *output, char *string, int maxlen);
00088
00089
00093 #define ENCODE_BLOCKSIZE (32*1024)
00094
00100 struct encoder_t {
00102 svn_stream_t *orig;
00103
00105 md5_digest_t *output_md5;
00106
00108 apr_md5_ctx_t md5_ctx;
00110 apr_size_t bytes_left;
00111
00113 pid_t child;
00114
00116 int is_writer;
00118 int pipe_in;
00120 int pipe_out;
00122 int eof;
00124 int data_pos;
00125
00127 char buffer[ENCODE_BLOCKSIZE];
00128 };
00129
00130
00132 int hlp__encode_filter(svn_stream_t *s_stream, const char *command,
00133 int is_writer,
00134 char *path,
00135 svn_stream_t **output,
00136 struct encoder_t **encoder_out,
00137 apr_pool_t *pool);
00142 int hlp__chrooter(void);
00143
00145 int hlp__match_path_envs(struct estat *root);
00146
00148 int hlp__format_path(struct estat *sts, char *wc_relative_path,
00149 char **output);
00150
00152 int hlp__get_gid(char *group, gid_t *gid, apr_pool_t *pool);
00154 int hlp__get_uid(char *user, uid_t *uid, apr_pool_t *pool);
00155
00157 char *hlp__rev_to_string(svn_revnum_t rev);
00158
00161 int hlp__strncmp_uline_eq_dash(char *always_ul, char *other, int max);
00162
00163
00165 int hlp__is_special_property_name(const char *name);
00167 int hlp__stream_md5(svn_stream_t *stream,
00168 unsigned char md5[APR_MD5_DIGESTSIZE]);
00169
00171 int hlp__delay(time_t start, enum opt__delay_e which);
00172
00174 int hlp__rename_to_unique(char *fn, char *extension,
00175 const char **unique_name,
00176 apr_pool_t *pool);
00177
00178
00179
00180
00181
00182
00184 int hlp__strnalloc(int len, char **dest, const char const *source);
00187 int hlp__strmnalloc(int len, char **dest,
00188 const char const *source, ...) __attribute__((sentinel));
00190 inline static int hlp__strdup(char **dest, const char const *src)
00191 { return hlp__strnalloc(strlen(src), dest, src); }
00193 int hlp__calloc(void *output, size_t nmemb, size_t count);
00195 int hlp__realloc(void *output, size_t size);
00198 inline static int hlp__alloc(void *dest, size_t len)
00199 {
00200 *(void**)dest=NULL;
00201 return hlp__realloc(dest, len);
00202 }
00203
00204
00207 char* hlp__get_word(char *input, char **word_start);
00209 inline static char *hlp__skip_ws(char *input)
00210 {
00211 while (isspace(*input)) input++;
00212 return input;
00213 }
00214
00215
00217 int hlp__get_svn_config(apr_hash_t **config);
00218
00219
00228 static inline int hlp__rightmost_0_bit(int i)
00229 {
00230 return (i ^ (i+1)) & (i+1);
00231 }
00232
00233 int hlp__compare_string_pointers(const void *a, const void *b);
00234
00235 #endif