Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals

utils.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2005, 2006 by KoanLogic s.r.l. <http://www.koanlogic.com>
00003  * All rights reserved.
00004  *
00005  * This file is part of KLone, and as such it is subject to the license stated
00006  * in the LICENSE file which you have received as part of this distribution.
00007  *
00008  * $Id: utils.h,v 1.26 2006/04/22 13:14:46 tat Exp $
00009  */
00010 
00011 #ifndef _KLONE_UTILS_H_
00012 #define _KLONE_UTILS_H_
00013 
00014 #include "klone_conf.h"
00015 #ifdef HAVE_STDINT
00016 #include <stdint.h>
00017 #endif /* HAVE_STDINT */
00018 #include <stdarg.h>
00019 #include <stdio.h>
00020 #include <limits.h>
00021 #include <time.h>
00022 #include <signal.h>
00023 #include <u/libu.h>
00024 #include <klone/io.h>
00025 #include <klone/md5.h>
00026 #include <klone/os.h>
00027 #include <klone/mime_map.h>
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 #ifndef MIN
00034 #define MIN(a,b)    (a < b ? a : b)
00035 #endif
00036 
00037 #ifndef MAX
00038 #define MAX(a,b)    (a > b ? a : b)
00039 #endif
00040 
00041 #define KLONE_FREE(p) do {if (p) { free(p); p = NULL; }} while (0)
00042 
00043 #define klone_die(...) do { con(__VA_ARGS__); exit(EXIT_FAILURE); } while(0)
00044 #define klone_die_if(cond, ...) \
00045     do { dbg_ifb(cond) klone_die(__VA_ARGS__); } while(0)
00046 
00047 int u_file_exists(const char*);
00048 int u_write_debug_message(const char*, const char*, int, const char*, 
00049     const char*, ...);
00050 
00051 struct dirent;
00052 int u_foreach_dir_item(const char *, unsigned int,
00053     int (*)(struct dirent*, const char *, void*), 
00054     void*);
00055 
00056 char* u_strnrchr(const char *s, char c, size_t len);
00057 char *u_stristr(const char *string, const char *sub);
00058 char *u_strnstr(const char *string, const char *sub, size_t stringlen);
00059 
00060 enum { URLCPY_VERBATIM, URLCPY_ENCODE, URLCPY_DECODE };
00061 ssize_t u_urlncpy(char *dst, const char *src, size_t slen, int flags);
00062 
00063 enum { HEXCPY_VERBATIM, HEXCPY_ENCODE, HEXCPY_DECODE };
00064 ssize_t u_hexncpy(char *dst, const char *src, size_t slen, int flags);
00065 
00066 enum { HTMLCPY_VERBATIM, HTMLCPY_ENCODE, HTMLCPY_DECODE };
00067 ssize_t u_htmlncpy(char *dst, const char *src, size_t slen, int flags);
00068 
00069 enum { SQLCPY_VERBATIM, SQLCPY_ENCODE, SQLCPY_DECODE };
00070 ssize_t u_sqlncpy(char *dst, const char *src, size_t slen, int flags);
00071 
00072 
00073 int u_printf_ccstr(io_t *o, const char *buf, size_t sz);
00074 
00075 int u_file_open(const char *file, int flags, io_t **pio);
00076 int u_tmpfile_open(io_t **pio);
00077 int u_getline(io_t *io, u_string_t *ln);
00078 int u_fgetline(FILE *in, u_string_t *ln);
00079 
00080 int u_io_unzip_copy(io_t *out, const unsigned char *data, size_t size);
00081 
00082 void u_tohex(char *hex, const char *src, size_t sz);
00083 char u_tochex(int n);
00084 
00085 int u_md5(char *buf, size_t sz, char out[MD5_DIGEST_BUFSZ]);
00086 int u_md5io(io_t *io, char out[MD5_DIGEST_BUFSZ]);
00087 
00088 typedef void (*u_sig_t)(int);
00089 int u_signal(int sig, u_sig_t handler);
00090 int u_sig_block(int sig);
00091 int u_sig_unblock(int sig);
00092 
00093 const char* u_guess_mime_type(const char *file_name);
00094 const mime_map_t* u_get_mime_map(const char *file_name);
00095 int u_match_ext(const char *filename, const char *extension);
00096 
00097 /* date time conversion funcs */
00098 int u_tt_to_rfc822(char dst[], time_t ts);
00099 int u_httpdate_to_tt(const char *str, time_t *tp);
00100 int u_rfc822_to_tt(const char *str, time_t *tp);
00101 int u_rfc850_to_tt(const char *str, time_t *tp);
00102 int u_asctime_to_tt(const char *str, time_t *tp);
00103 
00104 void u_print_version_and_exit(void);
00105 
00106 #ifdef HAVE_LIBOPENSSL
00107 int u_cipher_encrypt(const EVP_CIPHER *cipher, unsigned char *key, 
00108     unsigned char *iv, char *dst, size_t *dcount, const char *src, size_t ssz);
00109 int u_cipher_decrypt(const EVP_CIPHER *cipher, unsigned char *key, 
00110     unsigned char *iv, char *dst, size_t *dcount, const char *src, size_t ssz);
00111 #endif
00112 
00113 #ifdef __cplusplus
00114 }
00115 #endif 
00116 
00117 #endif

←Products
© 2005-2006 - KoanLogic S.r.l. - All rights reserved