Format the whole code using clang-format
This commit is contained in:
parent
8d9658ca43
commit
f2fd1824ca
@ -72,24 +72,25 @@ int do_pid_stuff(void);
|
||||
|
||||
static void usage(char *name)
|
||||
{
|
||||
printf(
|
||||
"Usage: %s [-f config_file] [-h] [-n]\n"
|
||||
" -f config_file: Use config_file as the configuration file\n"
|
||||
" If no config file is given %s will try to open ~/.bip/" S_CONF "\n"
|
||||
" -n: Don't daemonize, log in stderr\n"
|
||||
" -s: Bip HOME, default parent directory for client certificate,\n"
|
||||
" configuration, logs, pid, oidentd\n"
|
||||
" -v: Print version and exit\n"
|
||||
" -h: This help\n", name, name);
|
||||
printf("Usage: %s [-f config_file] [-h] [-n]\n"
|
||||
" -f config_file: Use config_file as the configuration file\n"
|
||||
" If no config file is given %s will try to open ~/.bip/" S_CONF
|
||||
"\n"
|
||||
" -n: Don't daemonize, log in stderr\n"
|
||||
" -s: Bip HOME, default parent directory for client certificate,\n"
|
||||
" configuration, logs, pid, oidentd\n"
|
||||
" -v: Print version and exit\n"
|
||||
" -h: This help\n",
|
||||
name, name);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void version(void)
|
||||
{
|
||||
printf(
|
||||
"Bip IRC Proxy - " PACKAGE_VERSION "\n"
|
||||
"Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n"
|
||||
"Distributed under the GNU General Public License Version 2\n");
|
||||
printf("Bip IRC Proxy - " PACKAGE_VERSION
|
||||
"\n"
|
||||
"Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n"
|
||||
"Distributed under the GNU General Public License Version 2\n");
|
||||
}
|
||||
|
||||
static void log_file_setup(void)
|
||||
@ -99,7 +100,7 @@ static void log_file_setup(void)
|
||||
if (conf_log_system && conf_daemonize) {
|
||||
if (conf_global_log_file && conf_global_log_file != stderr)
|
||||
fclose(conf_global_log_file);
|
||||
snprintf(buf, (size_t) 4095, "%s/bip.log", conf_log_root);
|
||||
snprintf(buf, (size_t)4095, "%s/bip.log", conf_log_root);
|
||||
FILE *f = fopen(buf, "a");
|
||||
if (!f)
|
||||
fatal("Can't open %s: %s", buf, strerror(errno));
|
||||
@ -208,8 +209,9 @@ int main(int argc, char **argv)
|
||||
char *home = NULL; /* oidentd path searching ignores conf_biphome */
|
||||
home = getenv("HOME");
|
||||
if (!home && !conf_biphome) {
|
||||
conf_die(&bip, "no value for environment variable $HOME,"
|
||||
"use '-s' parameter");
|
||||
conf_die(&bip,
|
||||
"no value for environment variable $HOME,"
|
||||
"use '-s' parameter");
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -220,16 +222,16 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (!bip.oidentdpath) {
|
||||
bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1 +
|
||||
strlen(OIDENTD_FILENAME) + 1);
|
||||
bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1
|
||||
+ strlen(OIDENTD_FILENAME) + 1);
|
||||
strcpy(bip.oidentdpath, conf_biphome);
|
||||
strcat(bip.oidentdpath, "/");
|
||||
strcat(bip.oidentdpath, OIDENTD_FILENAME);
|
||||
}
|
||||
|
||||
if (!confpath) {
|
||||
confpath = bip_malloc(strlen(conf_biphome) + 1 +
|
||||
strlen(S_CONF) + 1);
|
||||
confpath = bip_malloc(strlen(conf_biphome) + 1 + strlen(S_CONF)
|
||||
+ 1);
|
||||
strcpy(confpath, conf_biphome);
|
||||
strcat(confpath, "/");
|
||||
strcat(confpath, S_CONF);
|
||||
@ -245,16 +247,16 @@ int main(int argc, char **argv)
|
||||
|
||||
if (!conf_log_root) {
|
||||
char *ap = "/logs";
|
||||
conf_log_root = bip_malloc(strlen(conf_biphome) +
|
||||
strlen(ap) + 1);
|
||||
conf_log_root =
|
||||
bip_malloc(strlen(conf_biphome) + strlen(ap) + 1);
|
||||
strcpy(conf_log_root, conf_biphome);
|
||||
strcat(conf_log_root, ap);
|
||||
mylog(LOG_INFO, "Default log root: %s", conf_log_root);
|
||||
}
|
||||
if (!conf_pid_file) {
|
||||
char *pid = "/bip.pid";
|
||||
conf_pid_file = bip_malloc(strlen(conf_biphome) +
|
||||
strlen(pid) + 1);
|
||||
conf_pid_file =
|
||||
bip_malloc(strlen(conf_biphome) + strlen(pid) + 1);
|
||||
strcpy(conf_pid_file, conf_biphome);
|
||||
strcat(conf_pid_file, pid);
|
||||
mylog(LOG_INFO, "Default pid file: %s", conf_pid_file);
|
||||
@ -266,19 +268,22 @@ int main(int argc, char **argv)
|
||||
struct stat fs;
|
||||
|
||||
if (!conf_ssl_certfile) {
|
||||
conf_ssl_certfile = default_path(conf_biphome, "bip.pem",
|
||||
"SSL certificate");
|
||||
conf_ssl_certfile = default_path(
|
||||
conf_biphome, "bip.pem", "SSL certificate");
|
||||
}
|
||||
assert_path_exists(conf_ssl_certfile);
|
||||
|
||||
e = stat(conf_ssl_certfile, &fs);
|
||||
if (e)
|
||||
mylog(LOG_WARN, "Unable to check PEM file, stat(%s): "
|
||||
"%s", conf_ssl_certfile, strerror(errno));
|
||||
mylog(LOG_WARN,
|
||||
"Unable to check PEM file, stat(%s): "
|
||||
"%s",
|
||||
conf_ssl_certfile, strerror(errno));
|
||||
else if ((fs.st_mode & S_IROTH) | (fs.st_mode & S_IWOTH))
|
||||
mylog(LOG_ERROR, "PEM file %s should not be world "
|
||||
"readable / writable. Please fix the modes.",
|
||||
conf_ssl_certfile);
|
||||
mylog(LOG_ERROR,
|
||||
"PEM file %s should not be world "
|
||||
"readable / writable. Please fix the modes.",
|
||||
conf_ssl_certfile);
|
||||
|
||||
if (conf_client_dh_file) {
|
||||
assert_path_exists(conf_client_dh_file);
|
||||
@ -295,7 +300,7 @@ int main(int argc, char **argv)
|
||||
pid = daemonize();
|
||||
else
|
||||
pid = getpid();
|
||||
snprintf(buf, (size_t) 29, "%lu\n", (unsigned long int)pid);
|
||||
snprintf(buf, (size_t)29, "%lu\n", (unsigned long int)pid);
|
||||
ssize_t written;
|
||||
written = write(fd, buf, strlen(buf));
|
||||
if (written <= 0)
|
||||
|
@ -45,10 +45,11 @@ void readpass(char *buffer, int buflen)
|
||||
bipmkpw_fatal("tcgetattr failed", strerror(errno));
|
||||
|
||||
memcpy(&tt, &ttback, sizeof(ttback));
|
||||
// unsigned conversion from ‘int’ to ‘tcflag_t’ {aka ‘unsigned int’} changes value from ‘-11’ to ‘4294967285’
|
||||
// unsigned conversion from ‘int’ to ‘tcflag_t’ {aka ‘unsigned int’} changes
|
||||
// value from ‘-11’ to ‘4294967285’
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
tt.c_lflag &= ~(ICANON|ECHO);
|
||||
tt.c_lflag &= ~(ICANON | ECHO);
|
||||
#pragma GCC diagnostic pop
|
||||
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0)
|
||||
bipmkpw_fatal("tcsetattr failed", strerror(errno));
|
||||
@ -59,7 +60,7 @@ void readpass(char *buffer, int buflen)
|
||||
int idx = 0;
|
||||
int valid = 1;
|
||||
while (idx < buflen) {
|
||||
ssize_t rbytes = read(ttyfd, buffer+idx, (size_t)1);
|
||||
ssize_t rbytes = read(ttyfd, buffer + idx, (size_t)1);
|
||||
if (rbytes <= 0) {
|
||||
break;
|
||||
}
|
||||
@ -94,9 +95,9 @@ int main(void)
|
||||
readpass(str, 256);
|
||||
str[255] = 0;
|
||||
|
||||
// passing argument 1 of ‘srand’ with different width due to prototype [-Werror=traditional-conversion]
|
||||
// conversion from ‘time_t’ {aka ‘long int’} to ‘unsigned int’ may change value [-Werror=conversion]
|
||||
// We don't care.
|
||||
// passing argument 1 of ‘srand’ with different width due to prototype
|
||||
// [-Werror=traditional-conversion] conversion from ‘time_t’ {aka ‘long int’} to
|
||||
// ‘unsigned int’ may change value [-Werror=conversion] We don't care.
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wtraditional-conversion"
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
@ -106,7 +107,7 @@ int main(void)
|
||||
seed = (unsigned)rand(); // rand should be > 0
|
||||
|
||||
md5 = chash_double(str, seed);
|
||||
for (i = 0; i < 20; i++)
|
||||
for (i = 0; i < 20; i++)
|
||||
printf("%02x", md5[i]);
|
||||
printf("\n");
|
||||
free(md5);
|
||||
|
482
src/connection.c
482
src/connection.c
File diff suppressed because it is too large
Load Diff
@ -92,8 +92,9 @@ typedef struct connection {
|
||||
} connection_t;
|
||||
|
||||
connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
|
||||
int srcport, int ssl, char *ssl_ciphers, int ssl_check_mode,
|
||||
char *ssl_check_store, char *ssl_client_certfile, time_t timeout);
|
||||
int srcport, int ssl, char *ssl_ciphers,
|
||||
int ssl_check_mode, char *ssl_check_store,
|
||||
char *ssl_client_certfile, time_t timeout);
|
||||
connection_t *listen_new(char *hostname, int port, int ssl);
|
||||
connection_t *accept_new(connection_t *cn);
|
||||
void connection_free(connection_t *cn);
|
||||
|
18
src/irc.h
18
src/irc.h
@ -96,8 +96,7 @@ struct bipuser {
|
||||
char in_use; /* for mark and sweep on reload */
|
||||
};
|
||||
|
||||
struct network
|
||||
{
|
||||
struct network {
|
||||
char *name;
|
||||
#ifdef HAVE_LIBSSL
|
||||
int ssl;
|
||||
@ -111,7 +110,7 @@ struct network
|
||||
#define SASL_AUTH_PLAIN 2
|
||||
|
||||
struct link {
|
||||
char *name; /* id */
|
||||
char *name; /* id */
|
||||
|
||||
/** link live data **/
|
||||
struct link_server *l_server;
|
||||
@ -144,8 +143,8 @@ struct link {
|
||||
list_t on_connect_send;
|
||||
char *no_client_away_msg;
|
||||
char *away_nick;
|
||||
hash_t chan_infos; /* channels we want */
|
||||
list_t chan_infos_order; /* for order only */
|
||||
hash_t chan_infos; /* channels we want */
|
||||
list_t chan_infos_order; /* for order only */
|
||||
|
||||
struct bipuser *user;
|
||||
|
||||
@ -168,7 +167,7 @@ struct link {
|
||||
|
||||
#ifdef HAVE_LIBSSL
|
||||
int ssl_check_mode;
|
||||
STACK_OF(X509) *untrusted_certs;
|
||||
STACK_OF(X509) * untrusted_certs;
|
||||
#endif
|
||||
int in_use; /* for mark and sweep on reload */
|
||||
};
|
||||
@ -189,9 +188,9 @@ struct link_any {
|
||||
|
||||
#define IRCC_NONE (0)
|
||||
#define IRCC_NICK (1)
|
||||
#define IRCC_USER (1<<1)
|
||||
#define IRCC_PASS (1<<2)
|
||||
#define IRCC_READY (IRCC_NICK|IRCC_PASS|IRCC_USER)
|
||||
#define IRCC_USER (1 << 1)
|
||||
#define IRCC_PASS (1 << 2)
|
||||
#define IRCC_READY (IRCC_NICK | IRCC_PASS | IRCC_USER)
|
||||
|
||||
struct link_client {
|
||||
struct link_connection _link_c;
|
||||
@ -284,4 +283,3 @@ void irc_cli_backlog(struct link_client *ic, int hours);
|
||||
#define BIP_FAKEMASK "!bip@bip.bip.bip"
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
#include "line.h"
|
||||
#include "util.h"
|
||||
|
||||
// TODO resolve assuming signed overflow does not occur when changing X +- C1 cmp C2 to X cmp C2 -+ C1
|
||||
// TODO resolve assuming signed overflow does not occur when changing X +- C1
|
||||
// cmp C2 to X cmp C2 -+ C1
|
||||
#pragma GCC diagnostic ignored "-Wstrict-overflow"
|
||||
|
||||
void irc_line_init(struct line *l)
|
||||
@ -85,7 +86,7 @@ char *irc_line_to_string(struct line *l)
|
||||
for (i = 0; i < array_count(&l->words); i++)
|
||||
len += strlen(array_get(&l->words, i)) + 1;
|
||||
len += 1; /* remove one trailing space and add \r\n */
|
||||
len++; /* last args ":" */
|
||||
len++; /* last args ":" */
|
||||
ret = bip_malloc(len + 1);
|
||||
ret[0] = 0;
|
||||
|
||||
|
110
src/line.h
110
src/line.h
@ -17,65 +17,65 @@
|
||||
|
||||
#include "connection.h"
|
||||
|
||||
#define WRITE_LINE0(con, org, com) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while(0)
|
||||
#define WRITE_LINE0(con, org, com) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE_LINE1(con, org, com, a) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while(0)
|
||||
#define WRITE_LINE1(con, org, com, a) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE_LINE2(con, org, com, a1, a2) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a1); \
|
||||
_irc_line_append(&l, a2); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while(0)
|
||||
#define WRITE_LINE2(con, org, com, a1, a2) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a1); \
|
||||
_irc_line_append(&l, a2); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE_LINE3(con, org, com, a1, a2, a3) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a1); \
|
||||
_irc_line_append(&l, a2); \
|
||||
_irc_line_append(&l, a3); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while(0)
|
||||
#define WRITE_LINE3(con, org, com, a1, a2, a3) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a1); \
|
||||
_irc_line_append(&l, a2); \
|
||||
_irc_line_append(&l, a3); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while (0)
|
||||
|
||||
#define WRITE_LINE4(con, org, com, a1, a2, a3, a4) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a1); \
|
||||
_irc_line_append(&l, a2); \
|
||||
_irc_line_append(&l, a3); \
|
||||
_irc_line_append(&l, a4); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while(0)
|
||||
#define WRITE_LINE4(con, org, com, a1, a2, a3, a4) \
|
||||
do { \
|
||||
struct line l; \
|
||||
irc_line_init(&l); \
|
||||
l.origin = org; \
|
||||
_irc_line_append(&l, com); \
|
||||
_irc_line_append(&l, a1); \
|
||||
_irc_line_append(&l, a2); \
|
||||
_irc_line_append(&l, a3); \
|
||||
_irc_line_append(&l, a4); \
|
||||
irc_line_write(&l, con); \
|
||||
_irc_line_deinit(&l); \
|
||||
} while (0)
|
||||
|
||||
struct line {
|
||||
char *origin;
|
||||
|
275
src/log.c
275
src/log.c
@ -32,7 +32,7 @@ extern int conf_log;
|
||||
extern FILE *conf_global_log_file;
|
||||
|
||||
static size_t _log_write(log_t *logdata, logstore_t *lf, const char *d,
|
||||
const char *str);
|
||||
const char *str);
|
||||
static char *_log_wrap(const char *dest, const char *line);
|
||||
void logfile_free(logfile_t *lf);
|
||||
void log_drop(log_t *log, const char *storename);
|
||||
@ -53,16 +53,15 @@ int check_dir(char *filename, int is_fatal)
|
||||
if (err) {
|
||||
if (is_fatal)
|
||||
fatal("mkdir(%s) %s", filename,
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
mylog(LOG_ERROR, "mkdir(%s) %s", filename,
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
} else if (err) {
|
||||
if (is_fatal)
|
||||
fatal("stat(%s) %s", filename, strerror(errno));
|
||||
mylog(LOG_ERROR, "stat(%s) %s", filename,
|
||||
strerror(errno));
|
||||
mylog(LOG_ERROR, "stat(%s) %s", filename, strerror(errno));
|
||||
return 1;
|
||||
} else if (!(statbuf.st_mode & S_IFDIR)) {
|
||||
if (is_fatal)
|
||||
@ -99,7 +98,7 @@ int check_dir_r(char *dirname)
|
||||
tmp += pos;
|
||||
count += pos;
|
||||
*(dir + count) = '\0';
|
||||
mylog(LOG_DEBUGVERB,"check_dir_r: %s", dir);
|
||||
mylog(LOG_DEBUGVERB, "check_dir_r: %s", dir);
|
||||
if (check_dir(dir, 0)) {
|
||||
free(dir);
|
||||
return 1;
|
||||
@ -114,7 +113,8 @@ void strtolower(char *str)
|
||||
char *c;
|
||||
|
||||
for (c = str; *c != '\0'; c++)
|
||||
*c = (char)tolower(*c); // tolower()->int but should be safe to cast
|
||||
*c = (char)tolower(
|
||||
*c); // tolower()->int but should be safe to cast
|
||||
}
|
||||
|
||||
/*
|
||||
@ -128,7 +128,7 @@ void replace_var(char *str, char *var, char *value, unsigned int max)
|
||||
size_t lenvar = strlen(var);
|
||||
size_t lenval = strlen(value);
|
||||
|
||||
while((pos = strstr(str, var))) {
|
||||
while ((pos = strstr(str, var))) {
|
||||
/* Make room */
|
||||
if (strlen(str) + lenval - lenvar >= max)
|
||||
return;
|
||||
@ -154,7 +154,7 @@ char *log_build_filename(log_t *logdata, const char *destination)
|
||||
strftime(month, (size_t)3, "%m", now);
|
||||
strftime(hour, (size_t)3, "%H", now);
|
||||
snprintf(logfile, (size_t)MAX_PATH_LEN, "%s/%s", conf_log_root,
|
||||
conf_log_format);
|
||||
conf_log_format);
|
||||
replace_var(logfile, "%u", logdata->user->name, MAX_PATH_LEN);
|
||||
replace_var(logfile, "%n", logdata->network, MAX_PATH_LEN);
|
||||
replace_var(logfile, "%c", dest, MAX_PATH_LEN);
|
||||
@ -201,8 +201,8 @@ static void log_reset(logstore_t *store)
|
||||
return;
|
||||
}
|
||||
|
||||
while ((olf = list_get_first(&store->file_group)) &&
|
||||
olf != list_get_last(&store->file_group)) {
|
||||
while ((olf = list_get_first(&store->file_group))
|
||||
&& olf != list_get_last(&store->file_group)) {
|
||||
logfile_free(olf);
|
||||
list_remove_first(&store->file_group);
|
||||
}
|
||||
@ -225,7 +225,7 @@ static void log_reset(logstore_t *store)
|
||||
void log_reinit(logstore_t *store)
|
||||
{
|
||||
mylog(LOG_ERROR, "%s is inconsistent, droping backlog info",
|
||||
store->name);
|
||||
store->name);
|
||||
log_reset(store);
|
||||
}
|
||||
|
||||
@ -253,10 +253,10 @@ static int log_has_file(log_t *logdata, const char *fname)
|
||||
logstore_t *store;
|
||||
|
||||
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi)) {
|
||||
hash_it_next(&hi)) {
|
||||
store = hash_it_item(&hi);
|
||||
for (list_it_init(&store->file_group, &li); list_it_item(&li);
|
||||
list_it_next(&li)) {
|
||||
list_it_next(&li)) {
|
||||
logfile_t *lf = list_it_item(&li);
|
||||
if (strcmp(fname, lf->filename) == 0)
|
||||
return 1;
|
||||
@ -266,7 +266,7 @@ static int log_has_file(log_t *logdata, const char *fname)
|
||||
}
|
||||
|
||||
static int log_add_file(log_t *logdata, const char *destination,
|
||||
const char *filename)
|
||||
const char *filename)
|
||||
{
|
||||
FILE *f;
|
||||
logstore_t *store;
|
||||
@ -286,7 +286,7 @@ static int log_add_file(log_t *logdata, const char *destination,
|
||||
f = fopen(uniq_fname, "a+");
|
||||
if (!f) {
|
||||
mylog(LOG_ERROR, "fopen(%s) %s", uniq_fname,
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
free(uniq_fname);
|
||||
free(canonical_fname);
|
||||
return 0;
|
||||
@ -294,7 +294,7 @@ static int log_add_file(log_t *logdata, const char *destination,
|
||||
|
||||
if (fseek(f, (long)0, SEEK_END) == -1) {
|
||||
mylog(LOG_ERROR, "fseek(%s) %s", uniq_fname,
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
free(uniq_fname);
|
||||
free(canonical_fname);
|
||||
fclose(f);
|
||||
@ -307,7 +307,7 @@ static int log_add_file(log_t *logdata, const char *destination,
|
||||
lf->len = (size_t)ftell_r;
|
||||
if (ftell_r < 0) {
|
||||
mylog(LOG_ERROR, "log_add_file: ftell error %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
free(uniq_fname);
|
||||
free(canonical_fname);
|
||||
fclose(f);
|
||||
@ -377,17 +377,17 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
|
||||
if (!filename)
|
||||
return NULL;
|
||||
mylog(LOG_DEBUG, "Creating new logfile for %s: %s",
|
||||
destination, filename);
|
||||
destination, filename);
|
||||
}
|
||||
if (!log_add_file(logdata, destination, filename)) {
|
||||
if (filename)
|
||||
free(filename);
|
||||
if (filename)
|
||||
free(filename);
|
||||
return NULL;
|
||||
}
|
||||
store = hash_get(&logdata->logfgs, destination);
|
||||
assert(store);
|
||||
/* ok we are allocating a new store now, let's set it up for
|
||||
* backlogging if applicable */
|
||||
* backlogging if applicable */
|
||||
assert(logdata->user);
|
||||
assert(logdata->network);
|
||||
l = hash_get(&logdata->user->connections, logdata->network);
|
||||
@ -413,8 +413,8 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
|
||||
|
||||
time(&t);
|
||||
ltime = localtime(&t);
|
||||
if (ltime->tm_year != lf->last_log.tm_year ||
|
||||
ltime->tm_yday != lf->last_log.tm_yday) {
|
||||
if (ltime->tm_year != lf->last_log.tm_year
|
||||
|| ltime->tm_yday != lf->last_log.tm_yday) {
|
||||
logfile_t *oldlf;
|
||||
|
||||
/* day changed, we might want to rotate logfile */
|
||||
@ -430,7 +430,7 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
|
||||
|
||||
/* we do want to rotate logfiles */
|
||||
mylog(LOG_DEBUG, "Rotating logfile for %s %s %s", destination,
|
||||
lf->filename, filename);
|
||||
lf->filename, filename);
|
||||
|
||||
oldlf = list_get_last(&store->file_group);
|
||||
if (!log_add_file(logdata, destination, filename)) {
|
||||
@ -443,8 +443,8 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
|
||||
/* remove oldlf from file_group */
|
||||
assert(list_remove_first(&store->file_group) == oldlf);
|
||||
logfile_free(oldlf);
|
||||
assert(list_get_first(&store->file_group) ==
|
||||
list_get_last(&store->file_group));
|
||||
assert(list_get_first(&store->file_group)
|
||||
== list_get_last(&store->file_group));
|
||||
} else {
|
||||
fclose(oldlf->file);
|
||||
oldlf->file = NULL;
|
||||
@ -456,53 +456,51 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
|
||||
void log_join(log_t *logdata, const char *ircmask, const char *channel)
|
||||
{
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s has joined %s", timestamp(), ircmask,
|
||||
channel);
|
||||
"%s -!- %s has joined %s", timestamp(), ircmask, channel);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_part(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message)
|
||||
const char *message)
|
||||
{
|
||||
if (message)
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s has left %s [%s]", timestamp(), ircmask,
|
||||
channel, message);
|
||||
"%s -!- %s has left %s [%s]", timestamp(), ircmask,
|
||||
channel, message);
|
||||
else
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s has left %s", timestamp(), ircmask,
|
||||
channel);
|
||||
"%s -!- %s has left %s", timestamp(), ircmask,
|
||||
channel);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_kick(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *who, const char *message)
|
||||
const char *who, const char *message)
|
||||
{
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s has been kicked by %s [%s]", timestamp(),
|
||||
who, ircmask, message);
|
||||
"%s -!- %s has been kicked by %s [%s]", timestamp(), who,
|
||||
ircmask, message);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_quit(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message)
|
||||
const char *message)
|
||||
{
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s has quit [%s]", timestamp(), ircmask,
|
||||
message);
|
||||
"%s -!- %s has quit [%s]", timestamp(), ircmask, message);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_nick(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *newnick)
|
||||
const char *newnick)
|
||||
{
|
||||
char *oldnick = nick_from_ircmask(ircmask);
|
||||
logstore_t* oldstore;
|
||||
logstore_t* newstore;
|
||||
logstore_t *oldstore;
|
||||
logstore_t *newstore;
|
||||
|
||||
if ((oldstore = hash_get(&logdata->logfgs, oldnick))) {
|
||||
if ((newstore = hash_get(&logdata->logfgs, newnick))
|
||||
&& oldstore != newstore) {
|
||||
&& oldstore != newstore) {
|
||||
log_drop(logdata, newnick);
|
||||
}
|
||||
hash_rename_key(&logdata->logfgs, oldnick, newnick);
|
||||
@ -510,13 +508,12 @@ void log_nick(log_t *logdata, const char *ircmask, const char *channel,
|
||||
free(oldnick);
|
||||
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s is now known as %s",
|
||||
timestamp(), ircmask, newnick);
|
||||
"%s -!- %s is now known as %s", timestamp(), ircmask, newnick);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
static void do_log_privmsg(log_t *logdata, const char *storage, int src,
|
||||
const char *from, const char *message)
|
||||
const char *from, const char *message)
|
||||
{
|
||||
char dir = '<';
|
||||
|
||||
@ -525,10 +522,11 @@ static void do_log_privmsg(log_t *logdata, const char *storage, int src,
|
||||
if (src)
|
||||
dir = '>';
|
||||
|
||||
if (strlen(message) > 8 && ((*message == '\001' ||
|
||||
((*message == '+' || *message == '-') &&
|
||||
(*(message + 1) == '\001'))) &&
|
||||
(*(message + strlen(message) - 1) == '\001'))) {
|
||||
if (strlen(message) > 8
|
||||
&& ((*message == '\001'
|
||||
|| ((*message == '+' || *message == '-')
|
||||
&& (*(message + 1) == '\001')))
|
||||
&& (*(message + strlen(message) - 1) == '\001'))) {
|
||||
char *msg;
|
||||
/* hack for freenode and the like */
|
||||
const char *real_message = message;
|
||||
@ -541,19 +539,17 @@ static void do_log_privmsg(log_t *logdata, const char *storage, int src,
|
||||
msg = bip_strdup(real_message);
|
||||
*(msg + strlen(msg) - 1) = '\0';
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s %c * %s %s", timestamp(), dir,
|
||||
from, msg + 8);
|
||||
"%s %c * %s %s", timestamp(), dir, from, msg + 8);
|
||||
free(msg);
|
||||
} else {
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s %c %s: %s", timestamp(), dir,
|
||||
from, message);
|
||||
"%s %c %s: %s", timestamp(), dir, from, message);
|
||||
}
|
||||
log_write(logdata, storage, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_privmsg(log_t *logdata, const char *ircmask, const char *destination,
|
||||
const char *message)
|
||||
const char *message)
|
||||
{
|
||||
// TODO resolve this issue from array_get
|
||||
// passing argument X of .... with different width due to prototype
|
||||
@ -570,7 +566,7 @@ void log_privmsg(log_t *logdata, const char *ircmask, const char *destination,
|
||||
}
|
||||
|
||||
void log_cli_privmsg(log_t *logdata, const char *ircmask,
|
||||
const char *destination, const char *message)
|
||||
const char *destination, const char *message)
|
||||
{
|
||||
do_log_privmsg(logdata, destination, 1, ircmask, message);
|
||||
}
|
||||
@ -595,30 +591,29 @@ void log_notice(log_t *logdata, const char *ircmask, const char *destination,
|
||||
}
|
||||
|
||||
void log_cli_notice(log_t *logdata, const char *ircmask,
|
||||
const char *destination, const char *message)
|
||||
const char *destination, const char *message)
|
||||
{
|
||||
do_log_privmsg(logdata, destination, 1, ircmask, message);
|
||||
}
|
||||
|
||||
void log_topic(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message)
|
||||
const char *message)
|
||||
{
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- %s changed topic of %s to: %s", timestamp(),
|
||||
ircmask, channel, message);
|
||||
"%s -!- %s changed topic of %s to: %s", timestamp(), ircmask,
|
||||
channel, message);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_init_topic(log_t *logdata, const char *channel, const char *message)
|
||||
{
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- Topic for %s: %s", timestamp(), channel,
|
||||
message);
|
||||
"%s -!- Topic for %s: %s", timestamp(), channel, message);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_init_topic_time(log_t *logdata, const char *channel, const char *who,
|
||||
const char *when)
|
||||
const char *when)
|
||||
{
|
||||
struct tm *time;
|
||||
char *timestr;
|
||||
@ -633,34 +628,33 @@ void log_init_topic_time(log_t *logdata, const char *channel, const char *who,
|
||||
timestr[50] = '\0';
|
||||
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- Topic set by %s [%s]", timestamp(), who,
|
||||
timestr);
|
||||
"%s -!- Topic set by %s [%s]", timestamp(), who, timestr);
|
||||
free(timestr);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
}
|
||||
|
||||
void log_mode(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *modes, array_t *mode_args)
|
||||
const char *modes, array_t *mode_args)
|
||||
{
|
||||
int i;
|
||||
char *tmpbuf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
|
||||
char *tmpbuf2 = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
|
||||
char *tmp;
|
||||
|
||||
snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- mode/%s [%s", timestamp(), channel, modes);
|
||||
snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN, "%s -!- mode/%s [%s",
|
||||
timestamp(), channel, modes);
|
||||
if (mode_args) {
|
||||
for (i = 0; i < array_count(mode_args); i++) {
|
||||
snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s", tmpbuf,
|
||||
(const char*)array_get(mode_args, i));
|
||||
snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s",
|
||||
tmpbuf, (const char *)array_get(mode_args, i));
|
||||
tmp = tmpbuf;
|
||||
tmpbuf = tmpbuf2;
|
||||
tmpbuf2 = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s",
|
||||
tmpbuf, ircmask);
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s", tmpbuf,
|
||||
ircmask);
|
||||
log_write(logdata, channel, logdata->buffer);
|
||||
|
||||
free(tmpbuf);
|
||||
@ -670,10 +664,12 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel,
|
||||
void log_disconnected(log_t *logdata)
|
||||
{
|
||||
hash_iterator_t hi;
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Disconnected"
|
||||
" from server...", timestamp());
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- Disconnected"
|
||||
" from server...",
|
||||
timestamp());
|
||||
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi))
|
||||
hash_it_next(&hi))
|
||||
log_write(logdata, hash_it_key(&hi), logdata->buffer);
|
||||
}
|
||||
|
||||
@ -683,7 +679,7 @@ void log_ping_timeout(log_t *logdata)
|
||||
char *s;
|
||||
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- Ping timeout with server...", timestamp());
|
||||
"%s -!- Ping timeout with server...", timestamp());
|
||||
while ((s = list_remove_first(l))) {
|
||||
log_write(logdata, s, logdata->buffer);
|
||||
free(s);
|
||||
@ -696,10 +692,12 @@ void log_connected(log_t *logdata)
|
||||
{
|
||||
hash_iterator_t hi;
|
||||
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Connected to"
|
||||
" server...", timestamp());
|
||||
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
|
||||
"%s -!- Connected to"
|
||||
" server...",
|
||||
timestamp());
|
||||
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi)) {
|
||||
hash_it_next(&hi)) {
|
||||
log_write(logdata, hash_it_key(&hi), logdata->buffer);
|
||||
}
|
||||
}
|
||||
@ -740,7 +738,7 @@ void log_reset_all(log_t *logdata)
|
||||
list_init(&drop, NULL);
|
||||
|
||||
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi)) {
|
||||
hash_it_next(&hi)) {
|
||||
store = hash_it_item(&hi);
|
||||
// TODO resolve this issue from array_get
|
||||
// passing argument X of .... with different width due to prototype
|
||||
@ -793,11 +791,11 @@ void log_client_connected(log_t *logdata)
|
||||
logdata->connected = 1;
|
||||
}
|
||||
|
||||
void log_advance_backlogs(log_t* ld, logstore_t *store)
|
||||
void log_advance_backlogs(log_t *ld, logstore_t *store)
|
||||
{
|
||||
int c;
|
||||
|
||||
//mylog(LOG_ERROR, "LOG: log_advance_backlogs %s", store->name);
|
||||
// mylog(LOG_ERROR, "LOG: log_advance_backlogs %s", store->name);
|
||||
if (!store->track_backlog)
|
||||
return;
|
||||
|
||||
@ -811,18 +809,20 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
|
||||
|
||||
logfile_t *lf;
|
||||
while ((lf = list_it_item(&store->file_it))) {
|
||||
//mylog(LOG_ERROR, "LOG: %s %d", lf->filename, store->file_offset);
|
||||
// mylog(LOG_ERROR, "LOG: %s %d", lf->filename,
|
||||
// store->file_offset);
|
||||
if (!lf->file) {
|
||||
lf->file = fopen(lf->filename, "r");
|
||||
if (!lf->file) {
|
||||
mylog(LOG_ERROR, "Can't open %s for reading",
|
||||
lf->filename);
|
||||
lf->filename);
|
||||
log_reinit(store);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (fseek(lf->file, store->file_offset, SEEK_SET)) {
|
||||
//mylog(LOG_ERROR, "LOG: fseek FAIL %s %d", lf->filename, store->file_offset);
|
||||
// mylog(LOG_ERROR, "LOG: fseek FAIL %s %d",
|
||||
// lf->filename, store->file_offset);
|
||||
log_reinit(store);
|
||||
return;
|
||||
}
|
||||
@ -830,16 +830,20 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
|
||||
while ((c = fgetc(lf->file)) != EOF) {
|
||||
store->file_offset++;
|
||||
if (c == '\n') {
|
||||
//mylog(LOG_ERROR, "LOG: %s advanced at %d", lf->filename, store->file_offset);
|
||||
// mylog(LOG_ERROR, "LOG: %s advanced at %d",
|
||||
// lf->filename, store->file_offset);
|
||||
return;
|
||||
}
|
||||
}
|
||||
//mylog(LOG_ERROR, "LOG: %s advanced at %d", lf->filename, store->file_offset);
|
||||
// mylog(LOG_ERROR, "LOG: %s advanced at %d", lf->filename,
|
||||
// store->file_offset);
|
||||
if (lf == list_get_last(&store->file_group)) {
|
||||
//mylog(LOG_ERROR, "LOG: %s is last of file_group", lf->filename, store->file_offset);
|
||||
// mylog(LOG_ERROR, "LOG: %s is last of file_group",
|
||||
// lf->filename, store->file_offset);
|
||||
return;
|
||||
}
|
||||
//mylog(LOG_ERROR, "LOG: next file %s %d", lf->filename, store->file_offset);
|
||||
// mylog(LOG_ERROR, "LOG: next file %s %d", lf->filename,
|
||||
// store->file_offset);
|
||||
fclose(lf->file);
|
||||
lf->file = NULL;
|
||||
list_it_next(&store->file_it);
|
||||
@ -879,7 +883,7 @@ chan:
|
||||
09-01-2009 14:16:21 < nohar!~nohar@haruka.t1r.net: chantestrepl
|
||||
*/
|
||||
char *log_beautify(log_t *logdata, const char *buf, const char *storename,
|
||||
const char *dest)
|
||||
const char *dest)
|
||||
{
|
||||
int action = 0;
|
||||
char *p;
|
||||
@ -962,10 +966,10 @@ char *log_beautify(log_t *logdata, const char *buf, const char *storename,
|
||||
return _log_wrap(dest, buf);
|
||||
|
||||
// action and out are 0 or 1, safe to cast
|
||||
p = ret = (char *)bip_malloc(
|
||||
1 + lon + strlen(LAMESTRING) + strlen(dest) + 2 + lots + 2 +
|
||||
lom + 3 + (size_t)action * (2 + strlen("ACTION ")) +
|
||||
(size_t)out * strlen(PMSG_ARROW));
|
||||
p = ret = (char *)bip_malloc(1 + lon + strlen(LAMESTRING) + strlen(dest)
|
||||
+ 2 + lots + 2 + lom + 3
|
||||
+ (size_t)action * (2 + strlen("ACTION "))
|
||||
+ (size_t)out * strlen(PMSG_ARROW));
|
||||
|
||||
*p++ = ':';
|
||||
|
||||
@ -977,8 +981,8 @@ char *log_beautify(log_t *logdata, const char *buf, const char *storename,
|
||||
|
||||
memcpy(p, dest, strlen(dest));
|
||||
p += strlen(dest);
|
||||
//memcpy(p, sod, lod);
|
||||
//p += lod;
|
||||
// memcpy(p, sod, lod);
|
||||
// p += lod;
|
||||
|
||||
*p++ = ' ';
|
||||
*p++ = ':';
|
||||
@ -1032,20 +1036,20 @@ static time_t compute_time(const char *buf)
|
||||
}
|
||||
|
||||
static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
|
||||
list_t *res, const char *dest, time_t start)
|
||||
list_t *res, const char *dest, time_t start)
|
||||
{
|
||||
char *buf, *logbr;
|
||||
int close = 0;
|
||||
|
||||
//mylog(LOG_ERROR, "log_backread_file store:", store->name);
|
||||
// mylog(LOG_ERROR, "log_backread_file store:", store->name);
|
||||
|
||||
if (!lf->file) {
|
||||
lf->file = fopen(lf->filename, "r");
|
||||
if (!lf->file) {
|
||||
mylog(LOG_ERROR, "Can't open %s for reading",
|
||||
lf->filename);
|
||||
lf->filename);
|
||||
list_add_last(res, _log_wrap("Error opening logfile",
|
||||
store->name));
|
||||
store->name));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1059,26 +1063,29 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
|
||||
*/
|
||||
if (fseek(lf->file, store->file_offset, SEEK_SET)) {
|
||||
mylog(LOG_ERROR, "Can't seek in %s", lf->filename);
|
||||
list_add_last(res, _log_wrap(store->name,
|
||||
list_add_last(res,
|
||||
_log_wrap(store->name,
|
||||
"Error seeking in logfile"));
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
//mylog(LOG_ERROR, "bread Seeking %s to %d", lf->filename, 0);
|
||||
// mylog(LOG_ERROR, "bread Seeking %s to %d", lf->filename, 0);
|
||||
if (fseek(lf->file, (long)0, SEEK_SET)) {
|
||||
mylog(LOG_ERROR, "Can't seek in %s", lf->filename);
|
||||
list_add_last(res, _log_wrap(store->name,
|
||||
list_add_last(res,
|
||||
_log_wrap(store->name,
|
||||
"Error seeking in logfile"));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
|
||||
for(;;) {
|
||||
for (;;) {
|
||||
if (!fgets(buf, LOGLINE_MAXLEN, lf->file)) {
|
||||
if (ferror(lf->file)) {
|
||||
list_add_last(res, _log_wrap("Error reading "
|
||||
"logfile", store->name));
|
||||
"logfile",
|
||||
store->name));
|
||||
}
|
||||
/* error or oef */
|
||||
break;
|
||||
@ -1098,8 +1105,8 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
|
||||
/* parse error, don't backlog */
|
||||
if (linetime == (time_t)-1) {
|
||||
list_add_last(res, _log_wrap("Error in "
|
||||
"timestamp in %s",
|
||||
store->name));
|
||||
"timestamp in %s",
|
||||
store->name));
|
||||
continue;
|
||||
}
|
||||
/* too old line, don't backlog */
|
||||
@ -1109,14 +1116,13 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
|
||||
logbr = log_beautify(log, buf, store->name, dest);
|
||||
if (logbr)
|
||||
list_add_last(res, logbr);
|
||||
|
||||
}
|
||||
if (close) {
|
||||
fclose(lf->file);
|
||||
lf->file = NULL;
|
||||
}
|
||||
free(buf);
|
||||
//mylog(LOG_ERROR, "end of log_backread_file store: %s", store->name);
|
||||
// mylog(LOG_ERROR, "end of log_backread_file store: %s", store->name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -1139,7 +1145,7 @@ static list_t *log_backread(log_t *log, const char *storename, const char *dest)
|
||||
ret = list_new(NULL);
|
||||
|
||||
for (list_it_init(store->memlog, &li); list_it_item(&li);
|
||||
list_it_next(&li))
|
||||
list_it_next(&li))
|
||||
list_add_last(ret, bip_strdup(list_it_item(&li)));
|
||||
return ret;
|
||||
}
|
||||
@ -1153,11 +1159,10 @@ static list_t *log_backread(log_t *log, const char *storename, const char *dest)
|
||||
logfile_t *logf;
|
||||
|
||||
ret = list_new(NULL);
|
||||
for (file_it = store->file_it;
|
||||
(logf = list_it_item(&file_it));
|
||||
list_it_next(&file_it)) {
|
||||
for (file_it = store->file_it; (logf = list_it_item(&file_it));
|
||||
list_it_next(&file_it)) {
|
||||
if (!log_backread_file(log, store, logf, ret, dest,
|
||||
(time_t)0)) {
|
||||
(time_t)0)) {
|
||||
log_reinit(store);
|
||||
return ret;
|
||||
}
|
||||
@ -1172,10 +1177,10 @@ static char *_log_wrap(const char *dest, const char *line)
|
||||
|
||||
buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
|
||||
count = snprintf(buf, (size_t)LOGLINE_MAXLEN + 1,
|
||||
":" P_IRCMASK " PRIVMSG %s :%s\r\n", dest, line);
|
||||
":" P_IRCMASK " PRIVMSG %s :%s\r\n", dest, line);
|
||||
if (count < 0) {
|
||||
mylog(LOG_ERROR, "_log_wrap: error on snprintf: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
buf[LOGLINE_MAXLEN - 2] = '\r';
|
||||
buf[LOGLINE_MAXLEN - 1] = '\n';
|
||||
buf[LOGLINE_MAXLEN] = 0;
|
||||
@ -1191,7 +1196,7 @@ static char *_log_wrap(const char *dest, const char *line)
|
||||
}
|
||||
|
||||
static size_t _log_write(log_t *logdata, logstore_t *store,
|
||||
const char *destination, const char *str)
|
||||
const char *destination, const char *str)
|
||||
{
|
||||
size_t nbwrite;
|
||||
size_t len;
|
||||
@ -1201,8 +1206,8 @@ static size_t _log_write(log_t *logdata, logstore_t *store,
|
||||
tmpstr[LOGLINE_MAXLEN] = 0;
|
||||
|
||||
if (store->memlog) {
|
||||
char *r = log_beautify(logdata, tmpstr, store->name,
|
||||
destination);
|
||||
char *r =
|
||||
log_beautify(logdata, tmpstr, store->name, destination);
|
||||
if (r != NULL) {
|
||||
list_add_last(store->memlog, r);
|
||||
if (store->memc == logdata->user->backlog_lines)
|
||||
@ -1236,7 +1241,7 @@ void log_write(log_t *logdata, const char *destination, const char *str)
|
||||
|
||||
if (!store) {
|
||||
mylog(LOG_ERROR, "Unable to find/create logfile for '%s'",
|
||||
destination);
|
||||
destination);
|
||||
return;
|
||||
}
|
||||
written = _log_write(logdata, store, destination, str);
|
||||
@ -1254,15 +1259,15 @@ void log_flush_all(void)
|
||||
|
||||
fflush(conf_global_log_file);
|
||||
for (list_it_init(log_all_logs, &li); list_it_item(&li);
|
||||
list_it_next(&li)) {
|
||||
list_it_next(&li)) {
|
||||
log_t *log = list_it_item(&li);
|
||||
hash_iterator_t hi;
|
||||
for (hash_it_init(&log->logfgs, &hi); hash_it_item(&hi);
|
||||
hash_it_next(&hi)) {
|
||||
hash_it_next(&hi)) {
|
||||
logstore_t *store = hash_it_item(&hi);
|
||||
list_iterator_t lj;
|
||||
for (list_it_init(&store->file_group, &lj);
|
||||
list_it_item(&lj); list_it_next(&lj)) {
|
||||
list_it_item(&lj); list_it_next(&lj)) {
|
||||
logfile_t *lf = list_it_item(&lj);
|
||||
if (lf->file)
|
||||
fflush(lf->file);
|
||||
@ -1301,7 +1306,7 @@ void log_free(log_t *log)
|
||||
free(log->buffer);
|
||||
|
||||
for (hash_it_init(&log->logfgs, &it); (store = hash_it_item(&it));
|
||||
hash_it_next(&it)) {
|
||||
hash_it_next(&it)) {
|
||||
log_reset(store);
|
||||
log_store_free(store);
|
||||
}
|
||||
@ -1320,7 +1325,8 @@ array_t *str_split(const char *str, const char *splt)
|
||||
const char *start = str;
|
||||
size_t len;
|
||||
char *extracted;
|
||||
array_t *array = array_new();;
|
||||
array_t *array = array_new();
|
||||
;
|
||||
|
||||
do {
|
||||
if (!*p || strchr(splt, *p)) {
|
||||
@ -1341,7 +1347,7 @@ array_t *str_split(const char *str, const char *splt)
|
||||
|
||||
/* 26-12-2008 08:54:39 */
|
||||
int log_parse_date(char *strdate, int *year, int *month, int *mday, int *hour,
|
||||
int *min, int *sec)
|
||||
int *min, int *sec)
|
||||
{
|
||||
array_t *fields;
|
||||
char *sptr;
|
||||
@ -1358,8 +1364,7 @@ int log_parse_date(char *strdate, int *year, int *month, int *mday, int *hour,
|
||||
ret = 1;
|
||||
}
|
||||
int i;
|
||||
array_each(fields, i, sptr)
|
||||
free(sptr);
|
||||
array_each(fields, i, sptr) free(sptr);
|
||||
|
||||
array_free(fields);
|
||||
return ret;
|
||||
@ -1368,7 +1373,7 @@ int log_parse_date(char *strdate, int *year, int *month, int *mday, int *hour,
|
||||
void logstore_get_file_at(logstore_t *store, time_t at, list_iterator_t *li)
|
||||
{
|
||||
for (list_it_init(&store->file_group, li); list_it_item(li);
|
||||
list_it_next(li)) {
|
||||
list_it_next(li)) {
|
||||
logfile_t *lf = list_it_item(li);
|
||||
|
||||
if (mktime(&lf->last_log) > at)
|
||||
@ -1377,7 +1382,7 @@ void logstore_get_file_at(logstore_t *store, time_t at, list_iterator_t *li)
|
||||
}
|
||||
|
||||
static list_t *log_backread_hours(log_t *log, const char *storename,
|
||||
const char *dest, int hours)
|
||||
const char *dest, int hours)
|
||||
{
|
||||
time_t blstarttime;
|
||||
struct timeval tv;
|
||||
@ -1397,10 +1402,9 @@ static list_t *log_backread_hours(log_t *log, const char *storename,
|
||||
|
||||
ret = list_new(NULL);
|
||||
for (logstore_get_file_at(store, blstarttime, &file_it);
|
||||
(logf = list_it_item(&file_it));
|
||||
list_it_next(&file_it)) {
|
||||
(logf = list_it_item(&file_it)); list_it_next(&file_it)) {
|
||||
if (!log_backread_file(log, store, logf, ret, dest,
|
||||
blstarttime)) {
|
||||
blstarttime)) {
|
||||
log_reinit(store);
|
||||
return ret;
|
||||
}
|
||||
@ -1409,7 +1413,7 @@ static list_t *log_backread_hours(log_t *log, const char *storename,
|
||||
}
|
||||
|
||||
list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
|
||||
int hours)
|
||||
int hours)
|
||||
{
|
||||
list_t *ret;
|
||||
struct line l;
|
||||
@ -1454,4 +1458,3 @@ list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
31
src/log.h
31
src/log.h
@ -29,8 +29,7 @@
|
||||
|
||||
struct list;
|
||||
|
||||
typedef struct logfile
|
||||
{
|
||||
typedef struct logfile {
|
||||
FILE *file;
|
||||
char *filename;
|
||||
char *canonical_filename;
|
||||
@ -38,8 +37,7 @@ typedef struct logfile
|
||||
size_t len;
|
||||
} logfile_t;
|
||||
|
||||
typedef struct logstore
|
||||
{
|
||||
typedef struct logstore {
|
||||
char *name;
|
||||
list_t file_group;
|
||||
int skip_advance;
|
||||
@ -51,8 +49,7 @@ typedef struct logstore
|
||||
long file_offset;
|
||||
} logstore_t;
|
||||
|
||||
typedef struct log
|
||||
{
|
||||
typedef struct log {
|
||||
hash_t logfgs;
|
||||
char *network;
|
||||
char *buffer;
|
||||
@ -69,29 +66,29 @@ void logdata_free(log_t *logdata);
|
||||
|
||||
void log_join(log_t *logdata, const char *ircmask, const char *channel);
|
||||
void log_part(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message);
|
||||
const char *message);
|
||||
void log_kick(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *who, const char *message);
|
||||
const char *who, const char *message);
|
||||
void log_quit(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message);
|
||||
const char *message);
|
||||
void log_nick(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *newnick);
|
||||
const char *newnick);
|
||||
void log_privmsg(log_t *logdata, const char *ircmask, const char *destination,
|
||||
const char *message);
|
||||
const char *message);
|
||||
void log_notice(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message);
|
||||
void log_cli_privmsg(log_t *logdata, const char *ircmask,
|
||||
const char *destination, const char *message);
|
||||
const char *destination, const char *message);
|
||||
void log_cli_notice(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message);
|
||||
const char *message);
|
||||
void log_write(log_t *logdata, const char *str, const char *destination);
|
||||
void log_mode(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *modes, array_t *mode_args);
|
||||
const char *modes, array_t *mode_args);
|
||||
void log_topic(log_t *logdata, const char *ircmask, const char *channel,
|
||||
const char *message);
|
||||
const char *message);
|
||||
void log_init_topic(log_t *logdata, const char *channel, const char *message);
|
||||
void log_init_topic_time(log_t *logdata, const char *channel, const char *who,
|
||||
const char *when);
|
||||
const char *when);
|
||||
void log_connected(log_t *logdata);
|
||||
void log_disconnected(log_t *logdata);
|
||||
void log_ping_timeout(log_t *logdata);
|
||||
@ -108,5 +105,5 @@ void log_drop(log_t *log, const char *storename);
|
||||
|
||||
list_t *log_backlogs(log_t *log);
|
||||
list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
|
||||
int hours);
|
||||
int hours);
|
||||
#endif
|
||||
|
472
src/md5.c
472
src/md5.c
@ -25,226 +25,218 @@
|
||||
#include "md5.h"
|
||||
#include "util.h"
|
||||
|
||||
#define GET_UINT32(n,b,i) \
|
||||
{ \
|
||||
(n) = ( (uint32) (b)[(i) ] ) \
|
||||
| ( (uint32) (b)[(i) + 1] << 8 ) \
|
||||
| ( (uint32) (b)[(i) + 2] << 16 ) \
|
||||
| ( (uint32) (b)[(i) + 3] << 24 ); \
|
||||
}
|
||||
#define GET_UINT32(n, b, i) \
|
||||
{ \
|
||||
(n) = ((uint32)(b)[(i)]) | ((uint32)(b)[(i) + 1] << 8) \
|
||||
| ((uint32)(b)[(i) + 2] << 16) \
|
||||
| ((uint32)(b)[(i) + 3] << 24); \
|
||||
}
|
||||
|
||||
#define PUT_UINT32(n,b,i) \
|
||||
{ \
|
||||
(b)[(i) ] = (uint8) ( (n) ); \
|
||||
(b)[(i) + 1] = (uint8) ( (n) >> 8 ); \
|
||||
(b)[(i) + 2] = (uint8) ( (n) >> 16 ); \
|
||||
(b)[(i) + 3] = (uint8) ( (n) >> 24 ); \
|
||||
}
|
||||
#define PUT_UINT32(n, b, i) \
|
||||
{ \
|
||||
(b)[(i)] = (uint8)((n)); \
|
||||
(b)[(i) + 1] = (uint8)((n) >> 8); \
|
||||
(b)[(i) + 2] = (uint8)((n) >> 16); \
|
||||
(b)[(i) + 3] = (uint8)((n) >> 24); \
|
||||
}
|
||||
|
||||
void md5_starts( md5_context *ctx )
|
||||
void md5_starts(md5_context *ctx)
|
||||
{
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
ctx->total[0] = 0;
|
||||
ctx->total[1] = 0;
|
||||
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
ctx->state[0] = 0x67452301;
|
||||
ctx->state[1] = 0xEFCDAB89;
|
||||
ctx->state[2] = 0x98BADCFE;
|
||||
ctx->state[3] = 0x10325476;
|
||||
}
|
||||
|
||||
void md5_process( md5_context *ctx, uint8 data[64] )
|
||||
void md5_process(md5_context *ctx, uint8 data[64])
|
||||
{
|
||||
uint32 X[16], A, B, C, D;
|
||||
uint32 X[16], A, B, C, D;
|
||||
|
||||
GET_UINT32( X[0], data, 0 );
|
||||
GET_UINT32( X[1], data, 4 );
|
||||
GET_UINT32( X[2], data, 8 );
|
||||
GET_UINT32( X[3], data, 12 );
|
||||
GET_UINT32( X[4], data, 16 );
|
||||
GET_UINT32( X[5], data, 20 );
|
||||
GET_UINT32( X[6], data, 24 );
|
||||
GET_UINT32( X[7], data, 28 );
|
||||
GET_UINT32( X[8], data, 32 );
|
||||
GET_UINT32( X[9], data, 36 );
|
||||
GET_UINT32( X[10], data, 40 );
|
||||
GET_UINT32( X[11], data, 44 );
|
||||
GET_UINT32( X[12], data, 48 );
|
||||
GET_UINT32( X[13], data, 52 );
|
||||
GET_UINT32( X[14], data, 56 );
|
||||
GET_UINT32( X[15], data, 60 );
|
||||
GET_UINT32(X[0], data, 0);
|
||||
GET_UINT32(X[1], data, 4);
|
||||
GET_UINT32(X[2], data, 8);
|
||||
GET_UINT32(X[3], data, 12);
|
||||
GET_UINT32(X[4], data, 16);
|
||||
GET_UINT32(X[5], data, 20);
|
||||
GET_UINT32(X[6], data, 24);
|
||||
GET_UINT32(X[7], data, 28);
|
||||
GET_UINT32(X[8], data, 32);
|
||||
GET_UINT32(X[9], data, 36);
|
||||
GET_UINT32(X[10], data, 40);
|
||||
GET_UINT32(X[11], data, 44);
|
||||
GET_UINT32(X[12], data, 48);
|
||||
GET_UINT32(X[13], data, 52);
|
||||
GET_UINT32(X[14], data, 56);
|
||||
GET_UINT32(X[15], data, 60);
|
||||
|
||||
#define S(x,n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
#define S(x, n) ((x << n) | ((x & 0xFFFFFFFF) >> (32 - n)))
|
||||
|
||||
#define P(a,b,c,d,k,s,t) \
|
||||
{ \
|
||||
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \
|
||||
}
|
||||
#define P(a, b, c, d, k, s, t) \
|
||||
{ \
|
||||
a += F(b, c, d) + X[k] + t; \
|
||||
a = S(a, s) + b; \
|
||||
}
|
||||
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
A = ctx->state[0];
|
||||
B = ctx->state[1];
|
||||
C = ctx->state[2];
|
||||
D = ctx->state[3];
|
||||
|
||||
#define F(x,y,z) (z ^ (x & (y ^ z)))
|
||||
#define F(x, y, z) (z ^ (x & (y ^ z)))
|
||||
|
||||
P( A, B, C, D, 0, 7, 0xD76AA478 );
|
||||
P( D, A, B, C, 1, 12, 0xE8C7B756 );
|
||||
P( C, D, A, B, 2, 17, 0x242070DB );
|
||||
P( B, C, D, A, 3, 22, 0xC1BDCEEE );
|
||||
P( A, B, C, D, 4, 7, 0xF57C0FAF );
|
||||
P( D, A, B, C, 5, 12, 0x4787C62A );
|
||||
P( C, D, A, B, 6, 17, 0xA8304613 );
|
||||
P( B, C, D, A, 7, 22, 0xFD469501 );
|
||||
P( A, B, C, D, 8, 7, 0x698098D8 );
|
||||
P( D, A, B, C, 9, 12, 0x8B44F7AF );
|
||||
P( C, D, A, B, 10, 17, 0xFFFF5BB1 );
|
||||
P( B, C, D, A, 11, 22, 0x895CD7BE );
|
||||
P( A, B, C, D, 12, 7, 0x6B901122 );
|
||||
P( D, A, B, C, 13, 12, 0xFD987193 );
|
||||
P( C, D, A, B, 14, 17, 0xA679438E );
|
||||
P( B, C, D, A, 15, 22, 0x49B40821 );
|
||||
P(A, B, C, D, 0, 7, 0xD76AA478);
|
||||
P(D, A, B, C, 1, 12, 0xE8C7B756);
|
||||
P(C, D, A, B, 2, 17, 0x242070DB);
|
||||
P(B, C, D, A, 3, 22, 0xC1BDCEEE);
|
||||
P(A, B, C, D, 4, 7, 0xF57C0FAF);
|
||||
P(D, A, B, C, 5, 12, 0x4787C62A);
|
||||
P(C, D, A, B, 6, 17, 0xA8304613);
|
||||
P(B, C, D, A, 7, 22, 0xFD469501);
|
||||
P(A, B, C, D, 8, 7, 0x698098D8);
|
||||
P(D, A, B, C, 9, 12, 0x8B44F7AF);
|
||||
P(C, D, A, B, 10, 17, 0xFFFF5BB1);
|
||||
P(B, C, D, A, 11, 22, 0x895CD7BE);
|
||||
P(A, B, C, D, 12, 7, 0x6B901122);
|
||||
P(D, A, B, C, 13, 12, 0xFD987193);
|
||||
P(C, D, A, B, 14, 17, 0xA679438E);
|
||||
P(B, C, D, A, 15, 22, 0x49B40821);
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (z & (x ^ y)))
|
||||
#define F(x, y, z) (y ^ (z & (x ^ y)))
|
||||
|
||||
P( A, B, C, D, 1, 5, 0xF61E2562 );
|
||||
P( D, A, B, C, 6, 9, 0xC040B340 );
|
||||
P( C, D, A, B, 11, 14, 0x265E5A51 );
|
||||
P( B, C, D, A, 0, 20, 0xE9B6C7AA );
|
||||
P( A, B, C, D, 5, 5, 0xD62F105D );
|
||||
P( D, A, B, C, 10, 9, 0x02441453 );
|
||||
P( C, D, A, B, 15, 14, 0xD8A1E681 );
|
||||
P( B, C, D, A, 4, 20, 0xE7D3FBC8 );
|
||||
P( A, B, C, D, 9, 5, 0x21E1CDE6 );
|
||||
P( D, A, B, C, 14, 9, 0xC33707D6 );
|
||||
P( C, D, A, B, 3, 14, 0xF4D50D87 );
|
||||
P( B, C, D, A, 8, 20, 0x455A14ED );
|
||||
P( A, B, C, D, 13, 5, 0xA9E3E905 );
|
||||
P( D, A, B, C, 2, 9, 0xFCEFA3F8 );
|
||||
P( C, D, A, B, 7, 14, 0x676F02D9 );
|
||||
P( B, C, D, A, 12, 20, 0x8D2A4C8A );
|
||||
P(A, B, C, D, 1, 5, 0xF61E2562);
|
||||
P(D, A, B, C, 6, 9, 0xC040B340);
|
||||
P(C, D, A, B, 11, 14, 0x265E5A51);
|
||||
P(B, C, D, A, 0, 20, 0xE9B6C7AA);
|
||||
P(A, B, C, D, 5, 5, 0xD62F105D);
|
||||
P(D, A, B, C, 10, 9, 0x02441453);
|
||||
P(C, D, A, B, 15, 14, 0xD8A1E681);
|
||||
P(B, C, D, A, 4, 20, 0xE7D3FBC8);
|
||||
P(A, B, C, D, 9, 5, 0x21E1CDE6);
|
||||
P(D, A, B, C, 14, 9, 0xC33707D6);
|
||||
P(C, D, A, B, 3, 14, 0xF4D50D87);
|
||||
P(B, C, D, A, 8, 20, 0x455A14ED);
|
||||
P(A, B, C, D, 13, 5, 0xA9E3E905);
|
||||
P(D, A, B, C, 2, 9, 0xFCEFA3F8);
|
||||
P(C, D, A, B, 7, 14, 0x676F02D9);
|
||||
P(B, C, D, A, 12, 20, 0x8D2A4C8A);
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (x ^ y ^ z)
|
||||
#define F(x, y, z) (x ^ y ^ z)
|
||||
|
||||
P( A, B, C, D, 5, 4, 0xFFFA3942 );
|
||||
P( D, A, B, C, 8, 11, 0x8771F681 );
|
||||
P( C, D, A, B, 11, 16, 0x6D9D6122 );
|
||||
P( B, C, D, A, 14, 23, 0xFDE5380C );
|
||||
P( A, B, C, D, 1, 4, 0xA4BEEA44 );
|
||||
P( D, A, B, C, 4, 11, 0x4BDECFA9 );
|
||||
P( C, D, A, B, 7, 16, 0xF6BB4B60 );
|
||||
P( B, C, D, A, 10, 23, 0xBEBFBC70 );
|
||||
P( A, B, C, D, 13, 4, 0x289B7EC6 );
|
||||
P( D, A, B, C, 0, 11, 0xEAA127FA );
|
||||
P( C, D, A, B, 3, 16, 0xD4EF3085 );
|
||||
P( B, C, D, A, 6, 23, 0x04881D05 );
|
||||
P( A, B, C, D, 9, 4, 0xD9D4D039 );
|
||||
P( D, A, B, C, 12, 11, 0xE6DB99E5 );
|
||||
P( C, D, A, B, 15, 16, 0x1FA27CF8 );
|
||||
P( B, C, D, A, 2, 23, 0xC4AC5665 );
|
||||
P(A, B, C, D, 5, 4, 0xFFFA3942);
|
||||
P(D, A, B, C, 8, 11, 0x8771F681);
|
||||
P(C, D, A, B, 11, 16, 0x6D9D6122);
|
||||
P(B, C, D, A, 14, 23, 0xFDE5380C);
|
||||
P(A, B, C, D, 1, 4, 0xA4BEEA44);
|
||||
P(D, A, B, C, 4, 11, 0x4BDECFA9);
|
||||
P(C, D, A, B, 7, 16, 0xF6BB4B60);
|
||||
P(B, C, D, A, 10, 23, 0xBEBFBC70);
|
||||
P(A, B, C, D, 13, 4, 0x289B7EC6);
|
||||
P(D, A, B, C, 0, 11, 0xEAA127FA);
|
||||
P(C, D, A, B, 3, 16, 0xD4EF3085);
|
||||
P(B, C, D, A, 6, 23, 0x04881D05);
|
||||
P(A, B, C, D, 9, 4, 0xD9D4D039);
|
||||
P(D, A, B, C, 12, 11, 0xE6DB99E5);
|
||||
P(C, D, A, B, 15, 16, 0x1FA27CF8);
|
||||
P(B, C, D, A, 2, 23, 0xC4AC5665);
|
||||
|
||||
#undef F
|
||||
|
||||
#define F(x,y,z) (y ^ (x | ~z))
|
||||
#define F(x, y, z) (y ^ (x | ~z))
|
||||
|
||||
P( A, B, C, D, 0, 6, 0xF4292244 );
|
||||
P( D, A, B, C, 7, 10, 0x432AFF97 );
|
||||
P( C, D, A, B, 14, 15, 0xAB9423A7 );
|
||||
P( B, C, D, A, 5, 21, 0xFC93A039 );
|
||||
P( A, B, C, D, 12, 6, 0x655B59C3 );
|
||||
P( D, A, B, C, 3, 10, 0x8F0CCC92 );
|
||||
P( C, D, A, B, 10, 15, 0xFFEFF47D );
|
||||
P( B, C, D, A, 1, 21, 0x85845DD1 );
|
||||
P( A, B, C, D, 8, 6, 0x6FA87E4F );
|
||||
P( D, A, B, C, 15, 10, 0xFE2CE6E0 );
|
||||
P( C, D, A, B, 6, 15, 0xA3014314 );
|
||||
P( B, C, D, A, 13, 21, 0x4E0811A1 );
|
||||
P( A, B, C, D, 4, 6, 0xF7537E82 );
|
||||
P( D, A, B, C, 11, 10, 0xBD3AF235 );
|
||||
P( C, D, A, B, 2, 15, 0x2AD7D2BB );
|
||||
P( B, C, D, A, 9, 21, 0xEB86D391 );
|
||||
P(A, B, C, D, 0, 6, 0xF4292244);
|
||||
P(D, A, B, C, 7, 10, 0x432AFF97);
|
||||
P(C, D, A, B, 14, 15, 0xAB9423A7);
|
||||
P(B, C, D, A, 5, 21, 0xFC93A039);
|
||||
P(A, B, C, D, 12, 6, 0x655B59C3);
|
||||
P(D, A, B, C, 3, 10, 0x8F0CCC92);
|
||||
P(C, D, A, B, 10, 15, 0xFFEFF47D);
|
||||
P(B, C, D, A, 1, 21, 0x85845DD1);
|
||||
P(A, B, C, D, 8, 6, 0x6FA87E4F);
|
||||
P(D, A, B, C, 15, 10, 0xFE2CE6E0);
|
||||
P(C, D, A, B, 6, 15, 0xA3014314);
|
||||
P(B, C, D, A, 13, 21, 0x4E0811A1);
|
||||
P(A, B, C, D, 4, 6, 0xF7537E82);
|
||||
P(D, A, B, C, 11, 10, 0xBD3AF235);
|
||||
P(C, D, A, B, 2, 15, 0x2AD7D2BB);
|
||||
P(B, C, D, A, 9, 21, 0xEB86D391);
|
||||
|
||||
#undef F
|
||||
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
ctx->state[0] += A;
|
||||
ctx->state[1] += B;
|
||||
ctx->state[2] += C;
|
||||
ctx->state[3] += D;
|
||||
}
|
||||
|
||||
void md5_update( md5_context *ctx, uint8 *input, uint32 length )
|
||||
void md5_update(md5_context *ctx, uint8 *input, uint32 length)
|
||||
{
|
||||
uint32 left, fill;
|
||||
uint32 left, fill;
|
||||
|
||||
if( ! length ) return;
|
||||
if (!length)
|
||||
return;
|
||||
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
left = ctx->total[0] & 0x3F;
|
||||
fill = 64 - left;
|
||||
|
||||
ctx->total[0] += length;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
ctx->total[0] += length;
|
||||
ctx->total[0] &= 0xFFFFFFFF;
|
||||
|
||||
if( ctx->total[0] < length )
|
||||
ctx->total[1]++;
|
||||
if (ctx->total[0] < length)
|
||||
ctx->total[1]++;
|
||||
|
||||
if( left && length >= fill )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, fill );
|
||||
md5_process( ctx, ctx->buffer );
|
||||
length -= fill;
|
||||
input += fill;
|
||||
left = 0;
|
||||
}
|
||||
if (left && length >= fill) {
|
||||
memcpy((void *)(ctx->buffer + left), (void *)input, fill);
|
||||
md5_process(ctx, ctx->buffer);
|
||||
length -= fill;
|
||||
input += fill;
|
||||
left = 0;
|
||||
}
|
||||
|
||||
while( length >= 64 )
|
||||
{
|
||||
md5_process( ctx, input );
|
||||
length -= 64;
|
||||
input += 64;
|
||||
}
|
||||
while (length >= 64) {
|
||||
md5_process(ctx, input);
|
||||
length -= 64;
|
||||
input += 64;
|
||||
}
|
||||
|
||||
if( length )
|
||||
{
|
||||
memcpy( (void *) (ctx->buffer + left),
|
||||
(void *) input, length );
|
||||
}
|
||||
if (length) {
|
||||
memcpy((void *)(ctx->buffer + left), (void *)input, length);
|
||||
}
|
||||
}
|
||||
|
||||
static uint8 md5_padding[64] =
|
||||
static uint8 md5_padding[64] = {
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
||||
|
||||
void md5_finish(md5_context *ctx, uint8 digest[16])
|
||||
{
|
||||
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
};
|
||||
uint32 last, padn;
|
||||
uint32 high, low;
|
||||
uint8 msglen[8];
|
||||
|
||||
void md5_finish( md5_context *ctx, uint8 digest[16] )
|
||||
{
|
||||
uint32 last, padn;
|
||||
uint32 high, low;
|
||||
uint8 msglen[8];
|
||||
high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
|
||||
low = (ctx->total[0] << 3);
|
||||
|
||||
high = ( ctx->total[0] >> 29 )
|
||||
| ( ctx->total[1] << 3 );
|
||||
low = ( ctx->total[0] << 3 );
|
||||
PUT_UINT32(low, msglen, 0);
|
||||
PUT_UINT32(high, msglen, 4);
|
||||
|
||||
PUT_UINT32( low, msglen, 0 );
|
||||
PUT_UINT32( high, msglen, 4 );
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = (last < 56) ? (56 - last) : (120 - last);
|
||||
|
||||
last = ctx->total[0] & 0x3F;
|
||||
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
|
||||
md5_update(ctx, md5_padding, padn);
|
||||
md5_update(ctx, msglen, (unsigned long)8);
|
||||
|
||||
md5_update( ctx, md5_padding, padn );
|
||||
md5_update( ctx, msglen, (unsigned long)8 );
|
||||
|
||||
PUT_UINT32( ctx->state[0], digest, 0 );
|
||||
PUT_UINT32( ctx->state[1], digest, 4 );
|
||||
PUT_UINT32( ctx->state[2], digest, 8 );
|
||||
PUT_UINT32( ctx->state[3], digest, 12 );
|
||||
PUT_UINT32(ctx->state[0], digest, 0);
|
||||
PUT_UINT32(ctx->state[1], digest, 4);
|
||||
PUT_UINT32(ctx->state[2], digest, 8);
|
||||
PUT_UINT32(ctx->state[3], digest, 12);
|
||||
}
|
||||
|
||||
#ifdef TEST
|
||||
@ -256,92 +248,76 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
|
||||
* those are the standard RFC 1321 test vectors
|
||||
*/
|
||||
|
||||
static char *msg[] =
|
||||
static char *msg[] = {
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"12345678901234567890123456789012345678901234567890123456789012"
|
||||
"345678901234567890"};
|
||||
|
||||
static char *val[] = {
|
||||
"d41d8cd98f00b204e9800998ecf8427e", "0cc175b9c0f1b6a831c399e269772661",
|
||||
"900150983cd24fb0d6963f7d28e17f72", "f96b697d7cb7938d525a2f31aaf161d0",
|
||||
"c3fcd3d76192e4007dfb496cca67e13b", "d174ab98d277d9f5a5611c2c9f419d9f",
|
||||
"57edf4a22be3c955ac49da2e2107b67a"};
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
"",
|
||||
"a",
|
||||
"abc",
|
||||
"message digest",
|
||||
"abcdefghijklmnopqrstuvwxyz",
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||
"12345678901234567890123456789012345678901234567890123456789012" \
|
||||
"345678901234567890"
|
||||
};
|
||||
FILE *f;
|
||||
int i, j;
|
||||
char output[33];
|
||||
md5_context ctx;
|
||||
unsigned char buf[1000];
|
||||
unsigned char md5sum[16];
|
||||
|
||||
static char *val[] =
|
||||
{
|
||||
"d41d8cd98f00b204e9800998ecf8427e",
|
||||
"0cc175b9c0f1b6a831c399e269772661",
|
||||
"900150983cd24fb0d6963f7d28e17f72",
|
||||
"f96b697d7cb7938d525a2f31aaf161d0",
|
||||
"c3fcd3d76192e4007dfb496cca67e13b",
|
||||
"d174ab98d277d9f5a5611c2c9f419d9f",
|
||||
"57edf4a22be3c955ac49da2e2107b67a"
|
||||
};
|
||||
if (argc < 2) {
|
||||
printf("\n MD5 Validation Tests:\n\n");
|
||||
|
||||
int main( int argc, char *argv[] )
|
||||
{
|
||||
FILE *f;
|
||||
int i, j;
|
||||
char output[33];
|
||||
md5_context ctx;
|
||||
unsigned char buf[1000];
|
||||
unsigned char md5sum[16];
|
||||
for (i = 0; i < 7; i++) {
|
||||
printf(" Test %d ", i + 1);
|
||||
|
||||
if( argc < 2 )
|
||||
{
|
||||
printf( "\n MD5 Validation Tests:\n\n" );
|
||||
md5_starts(&ctx);
|
||||
md5_update(&ctx, (uint8 *)msg[i], strlen(msg[i]));
|
||||
md5_finish(&ctx, md5sum);
|
||||
|
||||
for( i = 0; i < 7; i++ )
|
||||
{
|
||||
printf( " Test %d ", i + 1 );
|
||||
for (j = 0; j < 16; j++) {
|
||||
sprintf(output + j * 2, "%02x", md5sum[j]);
|
||||
}
|
||||
|
||||
md5_starts( &ctx );
|
||||
md5_update( &ctx, (uint8 *) msg[i], strlen( msg[i] ) );
|
||||
md5_finish( &ctx, md5sum );
|
||||
if (memcmp(output, val[i], 32)) {
|
||||
printf("failed!\n");
|
||||
return (1);
|
||||
}
|
||||
|
||||
for( j = 0; j < 16; j++ )
|
||||
{
|
||||
sprintf( output + j * 2, "%02x", md5sum[j] );
|
||||
}
|
||||
printf("passed.\n");
|
||||
}
|
||||
|
||||
if( memcmp( output, val[i], 32 ) )
|
||||
{
|
||||
printf( "failed!\n" );
|
||||
return( 1 );
|
||||
}
|
||||
printf("\n");
|
||||
} else {
|
||||
if (!(f = fopen(argv[1], "rb"))) {
|
||||
perror("fopen");
|
||||
return (1);
|
||||
}
|
||||
|
||||
printf( "passed.\n" );
|
||||
}
|
||||
md5_starts(&ctx);
|
||||
|
||||
printf( "\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( ! ( f = fopen( argv[1], "rb" ) ) )
|
||||
{
|
||||
perror( "fopen" );
|
||||
return( 1 );
|
||||
}
|
||||
while ((i = fread(buf, 1, sizeof(buf), f)) > 0) {
|
||||
md5_update(&ctx, buf, i);
|
||||
}
|
||||
|
||||
md5_starts( &ctx );
|
||||
md5_finish(&ctx, md5sum);
|
||||
|
||||
while( ( i = fread( buf, 1, sizeof( buf ), f ) ) > 0 )
|
||||
{
|
||||
md5_update( &ctx, buf, i );
|
||||
}
|
||||
for (j = 0; j < 16; j++) {
|
||||
printf("%02x", md5sum[j]);
|
||||
}
|
||||
|
||||
md5_finish( &ctx, md5sum );
|
||||
printf(" %s\n", argv[1]);
|
||||
}
|
||||
|
||||
for( j = 0; j < 16; j++ )
|
||||
{
|
||||
printf( "%02x", md5sum[j] );
|
||||
}
|
||||
|
||||
printf( " %s\n", argv[1] );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return (0);
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -360,7 +336,8 @@ unsigned char *chash_double(char *str, unsigned int seed)
|
||||
length = strlen(str);
|
||||
length += 4;
|
||||
ptr = bip_malloc(length);
|
||||
// conversion from ‘unsigned int’ to ‘unsigned char’ may change value [-Werror=conversion]
|
||||
// conversion from ‘unsigned int’ to ‘unsigned char’ may change value
|
||||
// [-Werror=conversion]
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wconversion"
|
||||
ptr[0] = seed >> 24 & 0xff;
|
||||
@ -399,4 +376,3 @@ int chash_cmp(char *try, unsigned char *pass, unsigned int seed)
|
||||
free(try_hash);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
17
src/md5.h
17
src/md5.h
@ -2,22 +2,19 @@
|
||||
#define _MD5_H
|
||||
|
||||
#ifndef uint8
|
||||
#define uint8 unsigned char
|
||||
#define uint8 unsigned char
|
||||
#endif
|
||||
|
||||
#ifndef uint32
|
||||
#define uint32 unsigned long int
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32 total[2];
|
||||
uint32 state[4];
|
||||
uint8 buffer[64];
|
||||
}
|
||||
md5_context;
|
||||
typedef struct {
|
||||
uint32 total[2];
|
||||
uint32 state[4];
|
||||
uint8 buffer[64];
|
||||
} md5_context;
|
||||
|
||||
int chash_cmp(char *try, unsigned char *pass,
|
||||
unsigned int seed);
|
||||
int chash_cmp(char *try, unsigned char *pass, unsigned int seed);
|
||||
unsigned char *chash_double(char *str, unsigned int seed);
|
||||
#endif /* md5.h */
|
||||
|
87
src/util.c
87
src/util.c
@ -107,8 +107,9 @@ char *bip_strcat_fit(size_t *remaining, char *str, const char *str2)
|
||||
|
||||
res = memccpy(str, str2, '\0', *remaining);
|
||||
if (!res) {
|
||||
mylog(LOG_DEBUGTOOMUCH, "bip_strcat_fit: memccpy() failed, remaining %lu",
|
||||
*remaining);
|
||||
mylog(LOG_DEBUGTOOMUCH,
|
||||
"bip_strcat_fit: memccpy() failed, remaining %lu",
|
||||
*remaining);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -135,8 +136,9 @@ char *bip_strcatf_fit(size_t *remaining, char *str, const char *fmt, ...)
|
||||
}
|
||||
|
||||
if (*remaining > STRCATF_BUF_MAXLEN) {
|
||||
mylog(LOG_ERROR, "bip_strcatf_fit: remaining "
|
||||
"is over STRCATF_BUF_MAXLEN");
|
||||
mylog(LOG_ERROR,
|
||||
"bip_strcatf_fit: remaining "
|
||||
"is over STRCATF_BUF_MAXLEN");
|
||||
}
|
||||
|
||||
va_start(ap, fmt);
|
||||
@ -144,19 +146,22 @@ char *bip_strcatf_fit(size_t *remaining, char *str, const char *fmt, ...)
|
||||
written = vsnprintf(str2, *remaining, fmt, ap);
|
||||
if (written < 0) {
|
||||
mylog(LOG_ERROR, "bip_strcatf_fit: vsnprintf failed with: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((unsigned)written >= *remaining) {
|
||||
mylog(LOG_DEBUGVERB, "bip_strcatf_fit,vsnprintf: no space left");
|
||||
mylog(LOG_DEBUGVERB,
|
||||
"bip_strcatf_fit,vsnprintf: no space left");
|
||||
goto end;
|
||||
}
|
||||
|
||||
res = memccpy(str, str2, '\0', *remaining);
|
||||
if (!res) {
|
||||
mylog(LOG_DEBUGTOOMUCH, "bip_strcatf_fit: memccpy() failed, "
|
||||
"remaining %lu", *remaining);
|
||||
mylog(LOG_DEBUGTOOMUCH,
|
||||
"bip_strcatf_fit: memccpy() failed, "
|
||||
"remaining %lu",
|
||||
*remaining);
|
||||
goto end;
|
||||
}
|
||||
|
||||
@ -194,10 +199,10 @@ int is_valid_nick(char *str)
|
||||
return 0;
|
||||
|
||||
tmp = str;
|
||||
while (*tmp != '\0' && (isalnum(*tmp) || *tmp == '-' || *tmp == '[' ||
|
||||
*tmp == ']' || *tmp == '\\' || *tmp == '`' ||
|
||||
*tmp == '^' || *tmp == '{' || *tmp == '}' ||
|
||||
*tmp == '|' || *tmp == '_' ))
|
||||
while (*tmp != '\0'
|
||||
&& (isalnum(*tmp) || *tmp == '-' || *tmp == '[' || *tmp == ']'
|
||||
|| *tmp == '\\' || *tmp == '`' || *tmp == '^' || *tmp == '{'
|
||||
|| *tmp == '}' || *tmp == '|' || *tmp == '_'))
|
||||
tmp++;
|
||||
return (*tmp == '\0');
|
||||
}
|
||||
@ -209,8 +214,8 @@ int is_valid_username(char *str)
|
||||
return 0;
|
||||
|
||||
tmp = str;
|
||||
while (*tmp != '\0' && *tmp != ' ' && *tmp != '\0' && *tmp != '\r' &&
|
||||
*tmp != '\n')
|
||||
while (*tmp != '\0' && *tmp != ' ' && *tmp != '\0' && *tmp != '\r'
|
||||
&& *tmp != '\n')
|
||||
tmp++;
|
||||
return (*tmp == '\0');
|
||||
}
|
||||
@ -266,27 +271,27 @@ void _mylog(int level, char *fmt, va_list ap)
|
||||
return;
|
||||
|
||||
switch (level) {
|
||||
case LOG_FATAL:
|
||||
prefix = "FATAL: ";
|
||||
break;
|
||||
case LOG_DEBUGVERB:
|
||||
prefix = "DEBUGVERB: ";
|
||||
break;
|
||||
case LOG_DEBUG:
|
||||
prefix = "DEBUG: ";
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
prefix = "ERROR: ";
|
||||
break;
|
||||
case LOG_WARN:
|
||||
prefix = "WARNING: ";
|
||||
break;
|
||||
case LOG_INFO:
|
||||
prefix = "";
|
||||
break;
|
||||
default:
|
||||
prefix = "";
|
||||
break;
|
||||
case LOG_FATAL:
|
||||
prefix = "FATAL: ";
|
||||
break;
|
||||
case LOG_DEBUGVERB:
|
||||
prefix = "DEBUGVERB: ";
|
||||
break;
|
||||
case LOG_DEBUG:
|
||||
prefix = "DEBUG: ";
|
||||
break;
|
||||
case LOG_ERROR:
|
||||
prefix = "ERROR: ";
|
||||
break;
|
||||
case LOG_WARN:
|
||||
prefix = "WARNING: ";
|
||||
break;
|
||||
case LOG_INFO:
|
||||
prefix = "";
|
||||
break;
|
||||
default:
|
||||
prefix = "";
|
||||
break;
|
||||
}
|
||||
|
||||
fprintf(conf_global_log_file, "%s %s", timestamp(), prefix);
|
||||
@ -606,13 +611,13 @@ void hash_init(hash_t *h, int options)
|
||||
switch (options) {
|
||||
case HASH_NOCASE:
|
||||
list_init(&h->lists[i],
|
||||
(int (*)(const void*, const void*))
|
||||
hash_item_nocase_cmp);
|
||||
(int (*)(const void *,
|
||||
const void *))hash_item_nocase_cmp);
|
||||
break;
|
||||
case HASH_DEFAULT:
|
||||
list_init(&h->lists[i],
|
||||
(int (*)(const void*,const void*))
|
||||
hash_item_cmp);
|
||||
(int (*)(const void *,
|
||||
const void *))hash_item_cmp);
|
||||
break;
|
||||
default:
|
||||
fatal("wrong hash option %d", options);
|
||||
@ -800,7 +805,7 @@ void hash_dump(hash_t *h)
|
||||
{
|
||||
hash_iterator_t it;
|
||||
assert(h);
|
||||
for (hash_it_init(h, &it); hash_it_key(&it) ;hash_it_next(&it))
|
||||
for (hash_it_init(h, &it); hash_it_key(&it); hash_it_next(&it))
|
||||
printf("%s => %p\n", hash_it_key(&it), hash_it_item(&it));
|
||||
}
|
||||
|
||||
@ -869,7 +874,7 @@ void array_ensure(array_t *a, int index)
|
||||
a->elemv = bip_realloc(a->elemv, sizeof(void *) * (size_t)(index + 1));
|
||||
// a->elemc should be lower than index + 1
|
||||
memset(a->elemv + a->elemc, 0,
|
||||
sizeof(void *) * (size_t)(index + 1 - a->elemc));
|
||||
sizeof(void *) * (size_t)(index + 1 - a->elemc));
|
||||
a->elemc = index + 1;
|
||||
}
|
||||
|
||||
|
64
src/util.h
64
src/util.h
@ -74,37 +74,42 @@ typedef struct array {
|
||||
const void **elemv;
|
||||
} array_t;
|
||||
|
||||
#define MOVE_STRING(dest, src) do {\
|
||||
if (dest)\
|
||||
free(dest);\
|
||||
(dest) = (src);\
|
||||
(src) = NULL;\
|
||||
} while(0)
|
||||
#define MOVE_STRING(dest, src) \
|
||||
do { \
|
||||
if (dest) \
|
||||
free(dest); \
|
||||
(dest) = (src); \
|
||||
(src) = NULL; \
|
||||
} while (0)
|
||||
|
||||
#define FREE(a) free(a); (a) = NULL;
|
||||
#define FREE(a) \
|
||||
free(a); \
|
||||
(a) = NULL;
|
||||
|
||||
#define MAYFREE(a) do { \
|
||||
if (a) { \
|
||||
free(a); \
|
||||
(a) = NULL; \
|
||||
} \
|
||||
} while(0);
|
||||
#define MAYFREE(a) \
|
||||
do { \
|
||||
if (a) { \
|
||||
free(a); \
|
||||
(a) = NULL; \
|
||||
} \
|
||||
} while (0);
|
||||
|
||||
#define assert(condition) \
|
||||
do { \
|
||||
if (!(condition)) \
|
||||
fatal("Failed assertion in " __FILE__ "(%d): " \
|
||||
#condition, __LINE__); \
|
||||
} while(0)
|
||||
#define assert(condition) \
|
||||
do { \
|
||||
if (!(condition)) \
|
||||
fatal("Failed assertion in " __FILE__ \
|
||||
"(%d): " #condition, \
|
||||
__LINE__); \
|
||||
} while (0)
|
||||
|
||||
#define assert_msg(condition, msg) \
|
||||
do { \
|
||||
if (!(condition)) \
|
||||
fatal("%s in " __FILE__ "(%d): " \
|
||||
#condition, (msg), __LINE__); \
|
||||
} while(0)
|
||||
#define assert_msg(condition, msg) \
|
||||
do { \
|
||||
if (!(condition)) \
|
||||
fatal("%s in " __FILE__ "(%d): " #condition, (msg), \
|
||||
__LINE__); \
|
||||
} while (0)
|
||||
|
||||
void list_init(list_t *list, int (*cmp)(const void*, const void*));
|
||||
void list_init(list_t *list, int (*cmp)(const void *, const void *));
|
||||
int list_ptr_cmp(const void *a, const void *b);
|
||||
list_t *list_new(int (*cmp)(const void *, const void *));
|
||||
void *list_remove(list_t *list, const void *ptr);
|
||||
@ -183,9 +188,10 @@ char *bip_strdup(const char *str);
|
||||
char *bip_strcat_fit(size_t *remaining, char *str, const char *str2);
|
||||
char *bip_strcatf_fit(size_t *remaining, char *str, const char *str2, ...);
|
||||
void bip_clock_gettime(clockid_t clockid, struct timespec *tp);
|
||||
#define array_each(a, idx, ptr) for ((idx) = 0; \
|
||||
(idx) < (a)->elemc && (((ptr) = bip_strdup(array_get((a), (idx)))) || 1); \
|
||||
(idx)++)
|
||||
#define array_each(a, idx, ptr) \
|
||||
for ((idx) = 0; (idx) < (a)->elemc \
|
||||
&& (((ptr) = bip_strdup(array_get((a), (idx)))) || 1); \
|
||||
(idx)++)
|
||||
|
||||
void array_init(array_t *a);
|
||||
array_t *array_new(void);
|
||||
|
@ -29,8 +29,8 @@ static const unsigned char base64_table[65] =
|
||||
*
|
||||
* BIP change: remove line returns.
|
||||
*/
|
||||
unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
size_t *out_len)
|
||||
unsigned char *base64_encode(const unsigned char *src, size_t len,
|
||||
size_t *out_len)
|
||||
{
|
||||
unsigned char *out, *pos;
|
||||
const unsigned char *end, *in;
|
||||
@ -38,8 +38,8 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
int line_len;
|
||||
|
||||
olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
|
||||
olen += olen / 72; /* line feeds */
|
||||
olen++; /* nul termination */
|
||||
olen += olen / 72; /* line feeds */
|
||||
olen++; /* nul termination */
|
||||
if (olen < len)
|
||||
return NULL; /* integer overflow */
|
||||
out = malloc(olen);
|
||||
@ -57,7 +57,7 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
*pos++ = base64_table[in[2] & 0x3f];
|
||||
in += 3;
|
||||
line_len += 4;
|
||||
/*
|
||||
/*
|
||||
* BIP change: remove line returns.
|
||||
if (line_len >= 72) {
|
||||
*pos++ = '\n';
|
||||
@ -72,15 +72,15 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
*pos++ = base64_table[(in[0] & 0x03) << 4];
|
||||
*pos++ = '=';
|
||||
} else {
|
||||
*pos++ = base64_table[((in[0] & 0x03) << 4) |
|
||||
(in[1] >> 4)];
|
||||
*pos++ = base64_table[((in[0] & 0x03) << 4)
|
||||
| (in[1] >> 4)];
|
||||
*pos++ = base64_table[(in[1] & 0x0f) << 2];
|
||||
}
|
||||
*pos++ = '=';
|
||||
line_len += 4;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
* BIP change: remove line returns.
|
||||
if (line_len)
|
||||
*pos++ = '\n';
|
||||
@ -91,4 +91,3 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
*out_len = (size_t)(pos - out);
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
#ifndef BASE64_H
|
||||
#define BASE64_H
|
||||
|
||||
unsigned char * base64_encode(const unsigned char *src, size_t len,
|
||||
size_t *out_len);
|
||||
unsigned char *base64_encode(const unsigned char *src, size_t len,
|
||||
size_t *out_len);
|
||||
|
||||
#endif /* BASE64_H */
|
||||
|
Loading…
Reference in New Issue
Block a user