utils.h File Reference

Go to the source code of this file.

Defines

#define KLONE_FREE(p)   do {if (p) { free(p); p = NULL; }} while (0)
#define klone_die(...)   do { u_con(__VA_ARGS__); exit(EXIT_FAILURE); } while(0)
#define klone_die_if(cond,...)   do { dbg_ifb(cond) klone_die(__VA_ARGS__); } while(0)
#define RFC822_DATE_BUFSZ   32

Typedefs

typedef void(* u_sig_t )(int)

Enumerations

enum  { U_PATH_NOT_FOUND, U_PATH_IN_EMBFS, U_PATH_IN_FS }
enum  { U_COPY_VERBATIM, U_COPY_ENCODE, U_COPY_DECODE }
enum  { URLCPY_VERBATIM, URLCPY_ENCODE, URLCPY_DECODE }
enum  { HEXCPY_VERBATIM, HEXCPY_ENCODE, HEXCPY_DECODE }
enum  { HTMLCPY_VERBATIM, HTMLCPY_ENCODE, HTMLCPY_DECODE }
enum  { SQLCPY_VERBATIM, SQLCPY_ENCODE, SQLCPY_DECODE }

Functions

int u_file_exists (const char *)
int u_write_debug_message (const char *, const char *, int, const char *, const char *,...)
int u_foreach_dir_item (const char *, unsigned int, int(*)(struct dirent *, const char *, void *), void *)
char * u_strnrchr (const char *s, char c, size_t len)
char * u_stristr (const char *string, const char *sub)
char * u_strnstr (const char *string, const char *sub, size_t stringlen)
ssize_t u_urlncpy (char *dst, const char *src, size_t slen, int flags)
ssize_t u_hexncpy (char *dst, const char *src, size_t slen, int flags)
ssize_t u_htmlncpy (char *dst, const char *src, size_t slen, int flags)
ssize_t u_sqlncpy (char *dst, const char *src, size_t slen, int flags)
int u_printf_ccstr (io_t *o, const char *buf, size_t sz)
int u_file_open (const char *file, int flags, io_t **pio)
int u_tmpfile_open (const char *tmpdir, io_t **pio)
int u_getline (io_t *io, u_string_t *ln)
int u_fgetline (FILE *in, u_string_t *ln)
int u_io_unzip_copy (io_t *out, const char *data, size_t size)
void u_tohex (char *hex, const char *src, size_t sz)
char u_tochex (int n)
int u_md5 (const char *buf, size_t sz, char out[MD5_DIGEST_BUFSZ])
int u_md5io (io_t *io, char out[MD5_DIGEST_BUFSZ])
int u_signal (int sig, u_sig_t handler)
int u_sig_block (int sig)
int u_sig_unblock (int sig)
const char * u_guess_mime_type (const char *file_name)
const mime_map_tu_get_mime_map (const char *file_name)
int u_match_ext (const char *filename, const char *extension)
int u_tt_to_rfc822 (char dst[RFC822_DATE_BUFSZ], time_t ts)
int u_httpdate_to_tt (const char *str, time_t *tp)
int u_rfc822_to_tt (const char *str, time_t *tp)
int u_rfc850_to_tt (const char *str, time_t *tp)
int u_asctime_to_tt (const char *str, time_t *tp)
void u_print_version_and_exit (void)
int u_uri_normalize (char *fqn)
int u_path_where_art_thou (const char *fqn, int *where)
int u_pwd_init_agnostic (const char *fqn, int hashed, int in_memory, u_pwd_t **ppwd)

Define Documentation

#define klone_die ( ...   )     do { u_con(__VA_ARGS__); exit(EXIT_FAILURE); } while(0)

Definition at line 35 of file utils.h.

#define klone_die_if ( cond,
...   )     do { dbg_ifb(cond) klone_die(__VA_ARGS__); } while(0)

Definition at line 36 of file utils.h.

#define KLONE_FREE (  )     do {if (p) { free(p); p = NULL; }} while (0)

Definition at line 33 of file utils.h.

#define RFC822_DATE_BUFSZ   32

Definition at line 93 of file utils.h.


Typedef Documentation

typedef void(* u_sig_t)(int)

Definition at line 83 of file utils.h.


Enumeration Type Documentation

anonymous enum
Enumerator:
U_PATH_NOT_FOUND 
U_PATH_IN_EMBFS 
U_PATH_IN_FS 

Definition at line 39 of file utils.h.

anonymous enum
Enumerator:
U_COPY_VERBATIM 
U_COPY_ENCODE 
U_COPY_DECODE 

Definition at line 54 of file utils.h.

anonymous enum
Enumerator:
URLCPY_VERBATIM 
URLCPY_ENCODE 
URLCPY_DECODE 

Definition at line 56 of file utils.h.

anonymous enum
Enumerator:
HEXCPY_VERBATIM 
HEXCPY_ENCODE 
HEXCPY_DECODE 

Definition at line 59 of file utils.h.

anonymous enum
Enumerator:
HTMLCPY_VERBATIM 
HTMLCPY_ENCODE 
HTMLCPY_DECODE 

Definition at line 62 of file utils.h.

anonymous enum
Enumerator:
SQLCPY_VERBATIM 
SQLCPY_ENCODE 
SQLCPY_DECODE 

Definition at line 65 of file utils.h.


Function Documentation

int u_io_unzip_copy ( io_t out,
const char *  data,
size_t  size 
)
int u_path_where_art_thou ( const char *  fqn,
int *  where 
)

Check where the supplied path fqn is located.

Parameters:
fqn the fully qualified path to check
where one of U_PATH_IN_EMBFS, U_PATH_IN_FS or U_PATH_NOT_FOUND
Returns:
0 on success, ~0 on error

Definition at line 110 of file path.c.

void u_print_version_and_exit ( void   ) 

Definition at line 427 of file utils.c.

int u_printf_ccstr ( io_t o,
const char *  buf,
size_t  sz 
)

Definition at line 849 of file utils.c.

int u_pwd_init_agnostic ( const char *  fqn,
int  hashed,
int  in_memory,
u_pwd_t **  ppwd 
)

Create a pwd instance from a master password db stored at fqn.

Parameters:
fqn path name of the master password db (will be searched in embfs and then in the file system
hashed boolean to tell if passwords are hashed or cleartext
in_memory boolean to tell if a copy of the password db is also kept in memory as an hash map (meaningful only for on-disk password db's)
ppwd pwd instance as a result argument
Returns:
0 on success, ~0 on error

Definition at line 35 of file pwd.c.

int u_sig_block ( int  sig  ) 
int u_sig_unblock ( int  sig  ) 
int u_signal ( int  sig,
u_sig_t  handler 
)

Definition at line 1021 of file utils.c.

char u_tochex ( int  n  )  [inline]

Definition at line 408 of file utils.c.

int u_uri_normalize ( char *  path  ) 

Removes /./, /../ and // from the path.

Clean ups a path removing /./, /../ and multiple consecutive slashes from the given path.

Note that the function modifies the 'path' buffer.

Parameters:
path the path to normalize
Returns:
  • 0 successful
  • ~0 error

Definition at line 36 of file path.c.

int u_write_debug_message ( const char *  ,
const char *  ,
int  ,
const char *  ,
const char *  ,
  ... 
)