1
0
forked from bip/bip

Format the whole code using clang-format

This commit is contained in:
Pierre-Louis Bonicoli 2022-03-10 13:52:03 +01:00
parent 8d9658ca43
commit f2fd1824ca
Signed by untrusted user: pilou
GPG Key ID: 06914C4A5EDAA6DD
17 changed files with 1683 additions and 1467 deletions

836
src/bip.c

File diff suppressed because it is too large Load Diff

View File

@ -72,24 +72,25 @@ int do_pid_stuff(void);
static void usage(char *name) static void usage(char *name)
{ {
printf( printf("Usage: %s [-f config_file] [-h] [-n]\n"
"Usage: %s [-f config_file] [-h] [-n]\n" " -f config_file: Use config_file as the configuration file\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
" If no config file is given %s will try to open ~/.bip/" S_CONF "\n" "\n"
" -n: Don't daemonize, log in stderr\n" " -n: Don't daemonize, log in stderr\n"
" -s: Bip HOME, default parent directory for client certificate,\n" " -s: Bip HOME, default parent directory for client certificate,\n"
" configuration, logs, pid, oidentd\n" " configuration, logs, pid, oidentd\n"
" -v: Print version and exit\n" " -v: Print version and exit\n"
" -h: This help\n", name, name); " -h: This help\n",
name, name);
exit(1); exit(1);
} }
static void version(void) static void version(void)
{ {
printf( printf("Bip IRC Proxy - " PACKAGE_VERSION
"Bip IRC Proxy - " PACKAGE_VERSION "\n" "\n"
"Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n" "Copyright © Arnaud Cornet and Loïc Gomez (2004 - 2008)\n"
"Distributed under the GNU General Public License Version 2\n"); "Distributed under the GNU General Public License Version 2\n");
} }
static void log_file_setup(void) static void log_file_setup(void)
@ -99,7 +100,7 @@ static void log_file_setup(void)
if (conf_log_system && conf_daemonize) { if (conf_log_system && conf_daemonize) {
if (conf_global_log_file && conf_global_log_file != stderr) if (conf_global_log_file && conf_global_log_file != stderr)
fclose(conf_global_log_file); 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"); FILE *f = fopen(buf, "a");
if (!f) if (!f)
fatal("Can't open %s: %s", buf, strerror(errno)); 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 */ char *home = NULL; /* oidentd path searching ignores conf_biphome */
home = getenv("HOME"); home = getenv("HOME");
if (!home && !conf_biphome) { if (!home && !conf_biphome) {
conf_die(&bip, "no value for environment variable $HOME," conf_die(&bip,
"use '-s' parameter"); "no value for environment variable $HOME,"
"use '-s' parameter");
return 0; return 0;
} }
@ -220,16 +222,16 @@ int main(int argc, char **argv)
} }
if (!bip.oidentdpath) { if (!bip.oidentdpath) {
bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1 + bip.oidentdpath = bip_malloc(strlen(conf_biphome) + 1
strlen(OIDENTD_FILENAME) + 1); + strlen(OIDENTD_FILENAME) + 1);
strcpy(bip.oidentdpath, conf_biphome); strcpy(bip.oidentdpath, conf_biphome);
strcat(bip.oidentdpath, "/"); strcat(bip.oidentdpath, "/");
strcat(bip.oidentdpath, OIDENTD_FILENAME); strcat(bip.oidentdpath, OIDENTD_FILENAME);
} }
if (!confpath) { if (!confpath) {
confpath = bip_malloc(strlen(conf_biphome) + 1 + confpath = bip_malloc(strlen(conf_biphome) + 1 + strlen(S_CONF)
strlen(S_CONF) + 1); + 1);
strcpy(confpath, conf_biphome); strcpy(confpath, conf_biphome);
strcat(confpath, "/"); strcat(confpath, "/");
strcat(confpath, S_CONF); strcat(confpath, S_CONF);
@ -245,16 +247,16 @@ int main(int argc, char **argv)
if (!conf_log_root) { if (!conf_log_root) {
char *ap = "/logs"; char *ap = "/logs";
conf_log_root = bip_malloc(strlen(conf_biphome) + conf_log_root =
strlen(ap) + 1); bip_malloc(strlen(conf_biphome) + strlen(ap) + 1);
strcpy(conf_log_root, conf_biphome); strcpy(conf_log_root, conf_biphome);
strcat(conf_log_root, ap); strcat(conf_log_root, ap);
mylog(LOG_INFO, "Default log root: %s", conf_log_root); mylog(LOG_INFO, "Default log root: %s", conf_log_root);
} }
if (!conf_pid_file) { if (!conf_pid_file) {
char *pid = "/bip.pid"; char *pid = "/bip.pid";
conf_pid_file = bip_malloc(strlen(conf_biphome) + conf_pid_file =
strlen(pid) + 1); bip_malloc(strlen(conf_biphome) + strlen(pid) + 1);
strcpy(conf_pid_file, conf_biphome); strcpy(conf_pid_file, conf_biphome);
strcat(conf_pid_file, pid); strcat(conf_pid_file, pid);
mylog(LOG_INFO, "Default pid file: %s", conf_pid_file); mylog(LOG_INFO, "Default pid file: %s", conf_pid_file);
@ -266,19 +268,22 @@ int main(int argc, char **argv)
struct stat fs; struct stat fs;
if (!conf_ssl_certfile) { if (!conf_ssl_certfile) {
conf_ssl_certfile = default_path(conf_biphome, "bip.pem", conf_ssl_certfile = default_path(
"SSL certificate"); conf_biphome, "bip.pem", "SSL certificate");
} }
assert_path_exists(conf_ssl_certfile); assert_path_exists(conf_ssl_certfile);
e = stat(conf_ssl_certfile, &fs); e = stat(conf_ssl_certfile, &fs);
if (e) if (e)
mylog(LOG_WARN, "Unable to check PEM file, stat(%s): " mylog(LOG_WARN,
"%s", conf_ssl_certfile, strerror(errno)); "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)) else if ((fs.st_mode & S_IROTH) | (fs.st_mode & S_IWOTH))
mylog(LOG_ERROR, "PEM file %s should not be world " mylog(LOG_ERROR,
"readable / writable. Please fix the modes.", "PEM file %s should not be world "
conf_ssl_certfile); "readable / writable. Please fix the modes.",
conf_ssl_certfile);
if (conf_client_dh_file) { if (conf_client_dh_file) {
assert_path_exists(conf_client_dh_file); assert_path_exists(conf_client_dh_file);
@ -295,7 +300,7 @@ int main(int argc, char **argv)
pid = daemonize(); pid = daemonize();
else else
pid = getpid(); 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; ssize_t written;
written = write(fd, buf, strlen(buf)); written = write(fd, buf, strlen(buf));
if (written <= 0) if (written <= 0)

View File

@ -45,10 +45,11 @@ void readpass(char *buffer, int buflen)
bipmkpw_fatal("tcgetattr failed", strerror(errno)); bipmkpw_fatal("tcgetattr failed", strerror(errno));
memcpy(&tt, &ttback, sizeof(ttback)); 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 push
#pragma GCC diagnostic ignored "-Wsign-conversion" #pragma GCC diagnostic ignored "-Wsign-conversion"
tt.c_lflag &= ~(ICANON|ECHO); tt.c_lflag &= ~(ICANON | ECHO);
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
if (tcsetattr(ttyfd, TCSANOW, &tt) < 0) if (tcsetattr(ttyfd, TCSANOW, &tt) < 0)
bipmkpw_fatal("tcsetattr failed", strerror(errno)); bipmkpw_fatal("tcsetattr failed", strerror(errno));
@ -59,7 +60,7 @@ void readpass(char *buffer, int buflen)
int idx = 0; int idx = 0;
int valid = 1; int valid = 1;
while (idx < buflen) { 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) { if (rbytes <= 0) {
break; break;
} }
@ -94,9 +95,9 @@ int main(void)
readpass(str, 256); readpass(str, 256);
str[255] = 0; str[255] = 0;
// passing argument 1 of srand with different width due to prototype [-Werror=traditional-conversion] // passing argument 1 of srand with different width due to prototype
// conversion from time_t {aka long int} to unsigned int may change value [-Werror=conversion] // [-Werror=traditional-conversion] conversion from time_t {aka long int} to
// We don't care. // unsigned int may change value [-Werror=conversion] We don't care.
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wtraditional-conversion" #pragma GCC diagnostic ignored "-Wtraditional-conversion"
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"
@ -106,7 +107,7 @@ int main(void)
seed = (unsigned)rand(); // rand should be > 0 seed = (unsigned)rand(); // rand should be > 0
md5 = chash_double(str, seed); md5 = chash_double(str, seed);
for (i = 0; i < 20; i++) for (i = 0; i < 20; i++)
printf("%02x", md5[i]); printf("%02x", md5[i]);
printf("\n"); printf("\n");
free(md5); free(md5);

File diff suppressed because it is too large Load Diff

View File

@ -92,8 +92,9 @@ typedef struct connection {
} connection_t; } connection_t;
connection_t *connection_new(char *dsthostname, int dstport, char *srchostname, connection_t *connection_new(char *dsthostname, int dstport, char *srchostname,
int srcport, int ssl, char *ssl_ciphers, int ssl_check_mode, int srcport, int ssl, char *ssl_ciphers,
char *ssl_check_store, char *ssl_client_certfile, time_t timeout); 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 *listen_new(char *hostname, int port, int ssl);
connection_t *accept_new(connection_t *cn); connection_t *accept_new(connection_t *cn);
void connection_free(connection_t *cn); void connection_free(connection_t *cn);

635
src/irc.c

File diff suppressed because it is too large Load Diff

View File

@ -96,8 +96,7 @@ struct bipuser {
char in_use; /* for mark and sweep on reload */ char in_use; /* for mark and sweep on reload */
}; };
struct network struct network {
{
char *name; char *name;
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
int ssl; int ssl;
@ -111,7 +110,7 @@ struct network
#define SASL_AUTH_PLAIN 2 #define SASL_AUTH_PLAIN 2
struct link { struct link {
char *name; /* id */ char *name; /* id */
/** link live data **/ /** link live data **/
struct link_server *l_server; struct link_server *l_server;
@ -144,8 +143,8 @@ struct link {
list_t on_connect_send; list_t on_connect_send;
char *no_client_away_msg; char *no_client_away_msg;
char *away_nick; char *away_nick;
hash_t chan_infos; /* channels we want */ hash_t chan_infos; /* channels we want */
list_t chan_infos_order; /* for order only */ list_t chan_infos_order; /* for order only */
struct bipuser *user; struct bipuser *user;
@ -168,7 +167,7 @@ struct link {
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
int ssl_check_mode; int ssl_check_mode;
STACK_OF(X509) *untrusted_certs; STACK_OF(X509) * untrusted_certs;
#endif #endif
int in_use; /* for mark and sweep on reload */ int in_use; /* for mark and sweep on reload */
}; };
@ -189,9 +188,9 @@ struct link_any {
#define IRCC_NONE (0) #define IRCC_NONE (0)
#define IRCC_NICK (1) #define IRCC_NICK (1)
#define IRCC_USER (1<<1) #define IRCC_USER (1 << 1)
#define IRCC_PASS (1<<2) #define IRCC_PASS (1 << 2)
#define IRCC_READY (IRCC_NICK|IRCC_PASS|IRCC_USER) #define IRCC_READY (IRCC_NICK | IRCC_PASS | IRCC_USER)
struct link_client { struct link_client {
struct link_connection _link_c; 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" #define BIP_FAKEMASK "!bip@bip.bip.bip"
#endif #endif

View File

@ -16,7 +16,8 @@
#include "line.h" #include "line.h"
#include "util.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" #pragma GCC diagnostic ignored "-Wstrict-overflow"
void irc_line_init(struct line *l) 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++) for (i = 0; i < array_count(&l->words); i++)
len += strlen(array_get(&l->words, i)) + 1; len += strlen(array_get(&l->words, i)) + 1;
len += 1; /* remove one trailing space and add \r\n */ len += 1; /* remove one trailing space and add \r\n */
len++; /* last args ":" */ len++; /* last args ":" */
ret = bip_malloc(len + 1); ret = bip_malloc(len + 1);
ret[0] = 0; ret[0] = 0;

View File

@ -17,65 +17,65 @@
#include "connection.h" #include "connection.h"
#define WRITE_LINE0(con, org, com) \ #define WRITE_LINE0(con, org, com) \
do { \ do { \
struct line l; \ struct line l; \
irc_line_init(&l); \ irc_line_init(&l); \
l.origin = org; \ l.origin = org; \
_irc_line_append(&l, com); \ _irc_line_append(&l, com); \
irc_line_write(&l, con); \ irc_line_write(&l, con); \
_irc_line_deinit(&l); \ _irc_line_deinit(&l); \
} while(0) } while (0)
#define WRITE_LINE1(con, org, com, a) \ #define WRITE_LINE1(con, org, com, a) \
do { \ do { \
struct line l; \ struct line l; \
irc_line_init(&l); \ irc_line_init(&l); \
l.origin = org; \ l.origin = org; \
_irc_line_append(&l, com); \ _irc_line_append(&l, com); \
_irc_line_append(&l, a); \ _irc_line_append(&l, a); \
irc_line_write(&l, con); \ irc_line_write(&l, con); \
_irc_line_deinit(&l); \ _irc_line_deinit(&l); \
} while(0) } while (0)
#define WRITE_LINE2(con, org, com, a1, a2) \ #define WRITE_LINE2(con, org, com, a1, a2) \
do { \ do { \
struct line l; \ struct line l; \
irc_line_init(&l); \ irc_line_init(&l); \
l.origin = org; \ l.origin = org; \
_irc_line_append(&l, com); \ _irc_line_append(&l, com); \
_irc_line_append(&l, a1); \ _irc_line_append(&l, a1); \
_irc_line_append(&l, a2); \ _irc_line_append(&l, a2); \
irc_line_write(&l, con); \ irc_line_write(&l, con); \
_irc_line_deinit(&l); \ _irc_line_deinit(&l); \
} while(0) } while (0)
#define WRITE_LINE3(con, org, com, a1, a2, a3) \ #define WRITE_LINE3(con, org, com, a1, a2, a3) \
do { \ do { \
struct line l; \ struct line l; \
irc_line_init(&l); \ irc_line_init(&l); \
l.origin = org; \ l.origin = org; \
_irc_line_append(&l, com); \ _irc_line_append(&l, com); \
_irc_line_append(&l, a1); \ _irc_line_append(&l, a1); \
_irc_line_append(&l, a2); \ _irc_line_append(&l, a2); \
_irc_line_append(&l, a3); \ _irc_line_append(&l, a3); \
irc_line_write(&l, con); \ irc_line_write(&l, con); \
_irc_line_deinit(&l); \ _irc_line_deinit(&l); \
} while(0) } while (0)
#define WRITE_LINE4(con, org, com, a1, a2, a3, a4) \ #define WRITE_LINE4(con, org, com, a1, a2, a3, a4) \
do { \ do { \
struct line l; \ struct line l; \
irc_line_init(&l); \ irc_line_init(&l); \
l.origin = org; \ l.origin = org; \
_irc_line_append(&l, com); \ _irc_line_append(&l, com); \
_irc_line_append(&l, a1); \ _irc_line_append(&l, a1); \
_irc_line_append(&l, a2); \ _irc_line_append(&l, a2); \
_irc_line_append(&l, a3); \ _irc_line_append(&l, a3); \
_irc_line_append(&l, a4); \ _irc_line_append(&l, a4); \
irc_line_write(&l, con); \ irc_line_write(&l, con); \
_irc_line_deinit(&l); \ _irc_line_deinit(&l); \
} while(0) } while (0)
struct line { struct line {
char *origin; char *origin;

275
src/log.c
View File

@ -32,7 +32,7 @@ extern int conf_log;
extern FILE *conf_global_log_file; extern FILE *conf_global_log_file;
static size_t _log_write(log_t *logdata, logstore_t *lf, const char *d, 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); static char *_log_wrap(const char *dest, const char *line);
void logfile_free(logfile_t *lf); void logfile_free(logfile_t *lf);
void log_drop(log_t *log, const char *storename); void log_drop(log_t *log, const char *storename);
@ -53,16 +53,15 @@ int check_dir(char *filename, int is_fatal)
if (err) { if (err) {
if (is_fatal) if (is_fatal)
fatal("mkdir(%s) %s", filename, fatal("mkdir(%s) %s", filename,
strerror(errno)); strerror(errno));
mylog(LOG_ERROR, "mkdir(%s) %s", filename, mylog(LOG_ERROR, "mkdir(%s) %s", filename,
strerror(errno)); strerror(errno));
return 1; return 1;
} }
} else if (err) { } else if (err) {
if (is_fatal) if (is_fatal)
fatal("stat(%s) %s", filename, strerror(errno)); fatal("stat(%s) %s", filename, strerror(errno));
mylog(LOG_ERROR, "stat(%s) %s", filename, mylog(LOG_ERROR, "stat(%s) %s", filename, strerror(errno));
strerror(errno));
return 1; return 1;
} else if (!(statbuf.st_mode & S_IFDIR)) { } else if (!(statbuf.st_mode & S_IFDIR)) {
if (is_fatal) if (is_fatal)
@ -99,7 +98,7 @@ int check_dir_r(char *dirname)
tmp += pos; tmp += pos;
count += pos; count += pos;
*(dir + count) = '\0'; *(dir + count) = '\0';
mylog(LOG_DEBUGVERB,"check_dir_r: %s", dir); mylog(LOG_DEBUGVERB, "check_dir_r: %s", dir);
if (check_dir(dir, 0)) { if (check_dir(dir, 0)) {
free(dir); free(dir);
return 1; return 1;
@ -114,7 +113,8 @@ void strtolower(char *str)
char *c; char *c;
for (c = str; *c != '\0'; 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 lenvar = strlen(var);
size_t lenval = strlen(value); size_t lenval = strlen(value);
while((pos = strstr(str, var))) { while ((pos = strstr(str, var))) {
/* Make room */ /* Make room */
if (strlen(str) + lenval - lenvar >= max) if (strlen(str) + lenval - lenvar >= max)
return; return;
@ -154,7 +154,7 @@ char *log_build_filename(log_t *logdata, const char *destination)
strftime(month, (size_t)3, "%m", now); strftime(month, (size_t)3, "%m", now);
strftime(hour, (size_t)3, "%H", now); strftime(hour, (size_t)3, "%H", now);
snprintf(logfile, (size_t)MAX_PATH_LEN, "%s/%s", conf_log_root, 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, "%u", logdata->user->name, MAX_PATH_LEN);
replace_var(logfile, "%n", logdata->network, MAX_PATH_LEN); replace_var(logfile, "%n", logdata->network, MAX_PATH_LEN);
replace_var(logfile, "%c", dest, MAX_PATH_LEN); replace_var(logfile, "%c", dest, MAX_PATH_LEN);
@ -201,8 +201,8 @@ static void log_reset(logstore_t *store)
return; return;
} }
while ((olf = list_get_first(&store->file_group)) && while ((olf = list_get_first(&store->file_group))
olf != list_get_last(&store->file_group)) { && olf != list_get_last(&store->file_group)) {
logfile_free(olf); logfile_free(olf);
list_remove_first(&store->file_group); list_remove_first(&store->file_group);
} }
@ -225,7 +225,7 @@ static void log_reset(logstore_t *store)
void log_reinit(logstore_t *store) void log_reinit(logstore_t *store)
{ {
mylog(LOG_ERROR, "%s is inconsistent, droping backlog info", mylog(LOG_ERROR, "%s is inconsistent, droping backlog info",
store->name); store->name);
log_reset(store); log_reset(store);
} }
@ -253,10 +253,10 @@ static int log_has_file(log_t *logdata, const char *fname)
logstore_t *store; logstore_t *store;
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
hash_it_next(&hi)) { hash_it_next(&hi)) {
store = hash_it_item(&hi); store = hash_it_item(&hi);
for (list_it_init(&store->file_group, &li); list_it_item(&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); logfile_t *lf = list_it_item(&li);
if (strcmp(fname, lf->filename) == 0) if (strcmp(fname, lf->filename) == 0)
return 1; 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, static int log_add_file(log_t *logdata, const char *destination,
const char *filename) const char *filename)
{ {
FILE *f; FILE *f;
logstore_t *store; logstore_t *store;
@ -286,7 +286,7 @@ static int log_add_file(log_t *logdata, const char *destination,
f = fopen(uniq_fname, "a+"); f = fopen(uniq_fname, "a+");
if (!f) { if (!f) {
mylog(LOG_ERROR, "fopen(%s) %s", uniq_fname, mylog(LOG_ERROR, "fopen(%s) %s", uniq_fname,
strerror(errno)); strerror(errno));
free(uniq_fname); free(uniq_fname);
free(canonical_fname); free(canonical_fname);
return 0; 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) { if (fseek(f, (long)0, SEEK_END) == -1) {
mylog(LOG_ERROR, "fseek(%s) %s", uniq_fname, mylog(LOG_ERROR, "fseek(%s) %s", uniq_fname,
strerror(errno)); strerror(errno));
free(uniq_fname); free(uniq_fname);
free(canonical_fname); free(canonical_fname);
fclose(f); fclose(f);
@ -307,7 +307,7 @@ static int log_add_file(log_t *logdata, const char *destination,
lf->len = (size_t)ftell_r; lf->len = (size_t)ftell_r;
if (ftell_r < 0) { if (ftell_r < 0) {
mylog(LOG_ERROR, "log_add_file: ftell error %s", mylog(LOG_ERROR, "log_add_file: ftell error %s",
strerror(errno)); strerror(errno));
free(uniq_fname); free(uniq_fname);
free(canonical_fname); free(canonical_fname);
fclose(f); fclose(f);
@ -377,17 +377,17 @@ logstore_t *log_find_file(log_t *logdata, const char *destination)
if (!filename) if (!filename)
return NULL; return NULL;
mylog(LOG_DEBUG, "Creating new logfile for %s: %s", mylog(LOG_DEBUG, "Creating new logfile for %s: %s",
destination, filename); destination, filename);
} }
if (!log_add_file(logdata, destination, filename)) { if (!log_add_file(logdata, destination, filename)) {
if (filename) if (filename)
free(filename); free(filename);
return NULL; return NULL;
} }
store = hash_get(&logdata->logfgs, destination); store = hash_get(&logdata->logfgs, destination);
assert(store); assert(store);
/* ok we are allocating a new store now, let's set it up for /* 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->user);
assert(logdata->network); assert(logdata->network);
l = hash_get(&logdata->user->connections, 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); time(&t);
ltime = localtime(&t); ltime = localtime(&t);
if (ltime->tm_year != lf->last_log.tm_year || if (ltime->tm_year != lf->last_log.tm_year
ltime->tm_yday != lf->last_log.tm_yday) { || ltime->tm_yday != lf->last_log.tm_yday) {
logfile_t *oldlf; logfile_t *oldlf;
/* day changed, we might want to rotate logfile */ /* 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 */ /* we do want to rotate logfiles */
mylog(LOG_DEBUG, "Rotating logfile for %s %s %s", destination, mylog(LOG_DEBUG, "Rotating logfile for %s %s %s", destination,
lf->filename, filename); lf->filename, filename);
oldlf = list_get_last(&store->file_group); oldlf = list_get_last(&store->file_group);
if (!log_add_file(logdata, destination, filename)) { 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 */ /* remove oldlf from file_group */
assert(list_remove_first(&store->file_group) == oldlf); assert(list_remove_first(&store->file_group) == oldlf);
logfile_free(oldlf); logfile_free(oldlf);
assert(list_get_first(&store->file_group) == assert(list_get_first(&store->file_group)
list_get_last(&store->file_group)); == list_get_last(&store->file_group));
} else { } else {
fclose(oldlf->file); fclose(oldlf->file);
oldlf->file = NULL; 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) void log_join(log_t *logdata, const char *ircmask, const char *channel)
{ {
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has joined %s", timestamp(), ircmask, "%s -!- %s has joined %s", timestamp(), ircmask, channel);
channel);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_part(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)
{ {
if (message) if (message)
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has left %s [%s]", timestamp(), ircmask, "%s -!- %s has left %s [%s]", timestamp(), ircmask,
channel, message); channel, message);
else else
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has left %s", timestamp(), ircmask, "%s -!- %s has left %s", timestamp(), ircmask,
channel); channel);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_kick(log_t *logdata, const char *ircmask, const char *channel, 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, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has been kicked by %s [%s]", timestamp(), "%s -!- %s has been kicked by %s [%s]", timestamp(), who,
who, ircmask, message); ircmask, message);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_quit(log_t *logdata, const char *ircmask, const char *channel, 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, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s has quit [%s]", timestamp(), ircmask, "%s -!- %s has quit [%s]", timestamp(), ircmask, message);
message);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_nick(log_t *logdata, const char *ircmask, const char *channel, void log_nick(log_t *logdata, const char *ircmask, const char *channel,
const char *newnick) const char *newnick)
{ {
char *oldnick = nick_from_ircmask(ircmask); char *oldnick = nick_from_ircmask(ircmask);
logstore_t* oldstore; logstore_t *oldstore;
logstore_t* newstore; logstore_t *newstore;
if ((oldstore = hash_get(&logdata->logfgs, oldnick))) { if ((oldstore = hash_get(&logdata->logfgs, oldnick))) {
if ((newstore = hash_get(&logdata->logfgs, newnick)) if ((newstore = hash_get(&logdata->logfgs, newnick))
&& oldstore != newstore) { && oldstore != newstore) {
log_drop(logdata, newnick); log_drop(logdata, newnick);
} }
hash_rename_key(&logdata->logfgs, oldnick, 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); free(oldnick);
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s is now known as %s", "%s -!- %s is now known as %s", timestamp(), ircmask, newnick);
timestamp(), ircmask, newnick);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
static void do_log_privmsg(log_t *logdata, const char *storage, int src, 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 = '<'; char dir = '<';
@ -525,10 +522,11 @@ static void do_log_privmsg(log_t *logdata, const char *storage, int src,
if (src) if (src)
dir = '>'; dir = '>';
if (strlen(message) > 8 && ((*message == '\001' || if (strlen(message) > 8
((*message == '+' || *message == '-') && && ((*message == '\001'
(*(message + 1) == '\001'))) && || ((*message == '+' || *message == '-')
(*(message + strlen(message) - 1) == '\001'))) { && (*(message + 1) == '\001')))
&& (*(message + strlen(message) - 1) == '\001'))) {
char *msg; char *msg;
/* hack for freenode and the like */ /* hack for freenode and the like */
const char *real_message = message; 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 = bip_strdup(real_message);
*(msg + strlen(msg) - 1) = '\0'; *(msg + strlen(msg) - 1) = '\0';
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s %c * %s %s", timestamp(), dir, "%s %c * %s %s", timestamp(), dir, from, msg + 8);
from, msg + 8);
free(msg); free(msg);
} else { } else {
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s %c %s: %s", timestamp(), dir, "%s %c %s: %s", timestamp(), dir, from, message);
from, message);
} }
log_write(logdata, storage, logdata->buffer); log_write(logdata, storage, logdata->buffer);
} }
void log_privmsg(log_t *logdata, const char *ircmask, const char *destination, 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 // TODO resolve this issue from array_get
// passing argument X of .... with different width due to prototype // 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, 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); 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, 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); do_log_privmsg(logdata, destination, 1, ircmask, message);
} }
void log_topic(log_t *logdata, const char *ircmask, const char *channel, 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, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- %s changed topic of %s to: %s", timestamp(), "%s -!- %s changed topic of %s to: %s", timestamp(), ircmask,
ircmask, channel, message); channel, message);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_init_topic(log_t *logdata, const char *channel, const char *message) void log_init_topic(log_t *logdata, const char *channel, const char *message)
{ {
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Topic for %s: %s", timestamp(), channel, "%s -!- Topic for %s: %s", timestamp(), channel, message);
message);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_init_topic_time(log_t *logdata, const char *channel, const char *who, void log_init_topic_time(log_t *logdata, const char *channel, const char *who,
const char *when) const char *when)
{ {
struct tm *time; struct tm *time;
char *timestr; char *timestr;
@ -633,34 +628,33 @@ void log_init_topic_time(log_t *logdata, const char *channel, const char *who,
timestr[50] = '\0'; timestr[50] = '\0';
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
"%s -!- Topic set by %s [%s]", timestamp(), who, "%s -!- Topic set by %s [%s]", timestamp(), who, timestr);
timestr);
free(timestr); free(timestr);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
} }
void log_mode(log_t *logdata, const char *ircmask, const char *channel, 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; int i;
char *tmpbuf = bip_malloc((size_t)LOGLINE_MAXLEN + 1); char *tmpbuf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
char *tmpbuf2 = bip_malloc((size_t)LOGLINE_MAXLEN + 1); char *tmpbuf2 = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
char *tmp; char *tmp;
snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN, snprintf(tmpbuf, (size_t)LOGLINE_MAXLEN, "%s -!- mode/%s [%s",
"%s -!- mode/%s [%s", timestamp(), channel, modes); timestamp(), channel, modes);
if (mode_args) { if (mode_args) {
for (i = 0; i < array_count(mode_args); i++) { for (i = 0; i < array_count(mode_args); i++) {
snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s", tmpbuf, snprintf(tmpbuf2, (size_t)LOGLINE_MAXLEN, "%s %s",
(const char*)array_get(mode_args, i)); tmpbuf, (const char *)array_get(mode_args, i));
tmp = tmpbuf; tmp = tmpbuf;
tmpbuf = tmpbuf2; tmpbuf = tmpbuf2;
tmpbuf2 = tmp; tmpbuf2 = tmp;
} }
} }
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s", snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s] by %s", tmpbuf,
tmpbuf, ircmask); ircmask);
log_write(logdata, channel, logdata->buffer); log_write(logdata, channel, logdata->buffer);
free(tmpbuf); free(tmpbuf);
@ -670,10 +664,12 @@ void log_mode(log_t *logdata, const char *ircmask, const char *channel,
void log_disconnected(log_t *logdata) void log_disconnected(log_t *logdata)
{ {
hash_iterator_t hi; hash_iterator_t hi;
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Disconnected" snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
" from server...", timestamp()); "%s -!- Disconnected"
" from server...",
timestamp());
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); 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); log_write(logdata, hash_it_key(&hi), logdata->buffer);
} }
@ -683,7 +679,7 @@ void log_ping_timeout(log_t *logdata)
char *s; char *s;
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, 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))) { while ((s = list_remove_first(l))) {
log_write(logdata, s, logdata->buffer); log_write(logdata, s, logdata->buffer);
free(s); free(s);
@ -696,10 +692,12 @@ void log_connected(log_t *logdata)
{ {
hash_iterator_t hi; hash_iterator_t hi;
snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN, "%s -!- Connected to" snprintf(logdata->buffer, (size_t)LOGLINE_MAXLEN,
" server...", timestamp()); "%s -!- Connected to"
" server...",
timestamp());
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); 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); log_write(logdata, hash_it_key(&hi), logdata->buffer);
} }
} }
@ -740,7 +738,7 @@ void log_reset_all(log_t *logdata)
list_init(&drop, NULL); list_init(&drop, NULL);
for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi); for (hash_it_init(&logdata->logfgs, &hi); hash_it_item(&hi);
hash_it_next(&hi)) { hash_it_next(&hi)) {
store = hash_it_item(&hi); store = hash_it_item(&hi);
// TODO resolve this issue from array_get // TODO resolve this issue from array_get
// passing argument X of .... with different width due to prototype // passing argument X of .... with different width due to prototype
@ -793,11 +791,11 @@ void log_client_connected(log_t *logdata)
logdata->connected = 1; 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; 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) if (!store->track_backlog)
return; return;
@ -811,18 +809,20 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
logfile_t *lf; logfile_t *lf;
while ((lf = list_it_item(&store->file_it))) { 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) { if (!lf->file) {
lf->file = fopen(lf->filename, "r"); lf->file = fopen(lf->filename, "r");
if (!lf->file) { if (!lf->file) {
mylog(LOG_ERROR, "Can't open %s for reading", mylog(LOG_ERROR, "Can't open %s for reading",
lf->filename); lf->filename);
log_reinit(store); log_reinit(store);
return; return;
} }
} }
if (fseek(lf->file, store->file_offset, SEEK_SET)) { 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); log_reinit(store);
return; return;
} }
@ -830,16 +830,20 @@ void log_advance_backlogs(log_t* ld, logstore_t *store)
while ((c = fgetc(lf->file)) != EOF) { while ((c = fgetc(lf->file)) != EOF) {
store->file_offset++; store->file_offset++;
if (c == '\n') { 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; 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)) { 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; 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); fclose(lf->file);
lf->file = NULL; lf->file = NULL;
list_it_next(&store->file_it); list_it_next(&store->file_it);
@ -879,7 +883,7 @@ chan:
09-01-2009 14:16:21 < nohar!~nohar@haruka.t1r.net: chantestrepl 09-01-2009 14:16:21 < nohar!~nohar@haruka.t1r.net: chantestrepl
*/ */
char *log_beautify(log_t *logdata, const char *buf, const char *storename, char *log_beautify(log_t *logdata, const char *buf, const char *storename,
const char *dest) const char *dest)
{ {
int action = 0; int action = 0;
char *p; char *p;
@ -962,10 +966,10 @@ char *log_beautify(log_t *logdata, const char *buf, const char *storename,
return _log_wrap(dest, buf); return _log_wrap(dest, buf);
// action and out are 0 or 1, safe to cast // action and out are 0 or 1, safe to cast
p = ret = (char *)bip_malloc( p = ret = (char *)bip_malloc(1 + lon + strlen(LAMESTRING) + strlen(dest)
1 + lon + strlen(LAMESTRING) + strlen(dest) + 2 + lots + 2 + + 2 + lots + 2 + lom + 3
lom + 3 + (size_t)action * (2 + strlen("ACTION ")) + + (size_t)action * (2 + strlen("ACTION "))
(size_t)out * strlen(PMSG_ARROW)); + (size_t)out * strlen(PMSG_ARROW));
*p++ = ':'; *p++ = ':';
@ -977,8 +981,8 @@ char *log_beautify(log_t *logdata, const char *buf, const char *storename,
memcpy(p, dest, strlen(dest)); memcpy(p, dest, strlen(dest));
p += strlen(dest); p += strlen(dest);
//memcpy(p, sod, lod); // memcpy(p, sod, lod);
//p += lod; // p += lod;
*p++ = ' '; *p++ = ' ';
*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, 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; char *buf, *logbr;
int close = 0; int close = 0;
//mylog(LOG_ERROR, "log_backread_file store:", store->name); // mylog(LOG_ERROR, "log_backread_file store:", store->name);
if (!lf->file) { if (!lf->file) {
lf->file = fopen(lf->filename, "r"); lf->file = fopen(lf->filename, "r");
if (!lf->file) { if (!lf->file) {
mylog(LOG_ERROR, "Can't open %s for reading", mylog(LOG_ERROR, "Can't open %s for reading",
lf->filename); lf->filename);
list_add_last(res, _log_wrap("Error opening logfile", list_add_last(res, _log_wrap("Error opening logfile",
store->name)); store->name));
return 0; 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)) { if (fseek(lf->file, store->file_offset, SEEK_SET)) {
mylog(LOG_ERROR, "Can't seek in %s", lf->filename); 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")); "Error seeking in logfile"));
return 0; return 0;
} }
} else { } 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)) { if (fseek(lf->file, (long)0, SEEK_SET)) {
mylog(LOG_ERROR, "Can't seek in %s", lf->filename); 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")); "Error seeking in logfile"));
return 0; return 0;
} }
} }
buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1); buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
for(;;) { for (;;) {
if (!fgets(buf, LOGLINE_MAXLEN, lf->file)) { if (!fgets(buf, LOGLINE_MAXLEN, lf->file)) {
if (ferror(lf->file)) { if (ferror(lf->file)) {
list_add_last(res, _log_wrap("Error reading " list_add_last(res, _log_wrap("Error reading "
"logfile", store->name)); "logfile",
store->name));
} }
/* error or oef */ /* error or oef */
break; break;
@ -1098,8 +1105,8 @@ static int log_backread_file(log_t *log, logstore_t *store, logfile_t *lf,
/* parse error, don't backlog */ /* parse error, don't backlog */
if (linetime == (time_t)-1) { if (linetime == (time_t)-1) {
list_add_last(res, _log_wrap("Error in " list_add_last(res, _log_wrap("Error in "
"timestamp in %s", "timestamp in %s",
store->name)); store->name));
continue; continue;
} }
/* too old line, don't backlog */ /* 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); logbr = log_beautify(log, buf, store->name, dest);
if (logbr) if (logbr)
list_add_last(res, logbr); list_add_last(res, logbr);
} }
if (close) { if (close) {
fclose(lf->file); fclose(lf->file);
lf->file = NULL; lf->file = NULL;
} }
free(buf); 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; return 1;
} }
@ -1139,7 +1145,7 @@ static list_t *log_backread(log_t *log, const char *storename, const char *dest)
ret = list_new(NULL); ret = list_new(NULL);
for (list_it_init(store->memlog, &li); list_it_item(&li); 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))); list_add_last(ret, bip_strdup(list_it_item(&li)));
return ret; return ret;
} }
@ -1153,11 +1159,10 @@ static list_t *log_backread(log_t *log, const char *storename, const char *dest)
logfile_t *logf; logfile_t *logf;
ret = list_new(NULL); ret = list_new(NULL);
for (file_it = store->file_it; for (file_it = store->file_it; (logf = list_it_item(&file_it));
(logf = list_it_item(&file_it)); list_it_next(&file_it)) {
list_it_next(&file_it)) {
if (!log_backread_file(log, store, logf, ret, dest, if (!log_backread_file(log, store, logf, ret, dest,
(time_t)0)) { (time_t)0)) {
log_reinit(store); log_reinit(store);
return ret; return ret;
} }
@ -1172,10 +1177,10 @@ static char *_log_wrap(const char *dest, const char *line)
buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1); buf = bip_malloc((size_t)LOGLINE_MAXLEN + 1);
count = snprintf(buf, (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) { if (count < 0) {
mylog(LOG_ERROR, "_log_wrap: error on snprintf: %s", mylog(LOG_ERROR, "_log_wrap: error on snprintf: %s",
strerror(errno)); strerror(errno));
buf[LOGLINE_MAXLEN - 2] = '\r'; buf[LOGLINE_MAXLEN - 2] = '\r';
buf[LOGLINE_MAXLEN - 1] = '\n'; buf[LOGLINE_MAXLEN - 1] = '\n';
buf[LOGLINE_MAXLEN] = 0; 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, 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 nbwrite;
size_t len; size_t len;
@ -1201,8 +1206,8 @@ static size_t _log_write(log_t *logdata, logstore_t *store,
tmpstr[LOGLINE_MAXLEN] = 0; tmpstr[LOGLINE_MAXLEN] = 0;
if (store->memlog) { if (store->memlog) {
char *r = log_beautify(logdata, tmpstr, store->name, char *r =
destination); log_beautify(logdata, tmpstr, store->name, destination);
if (r != NULL) { if (r != NULL) {
list_add_last(store->memlog, r); list_add_last(store->memlog, r);
if (store->memc == logdata->user->backlog_lines) 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) { if (!store) {
mylog(LOG_ERROR, "Unable to find/create logfile for '%s'", mylog(LOG_ERROR, "Unable to find/create logfile for '%s'",
destination); destination);
return; return;
} }
written = _log_write(logdata, store, destination, str); written = _log_write(logdata, store, destination, str);
@ -1254,15 +1259,15 @@ void log_flush_all(void)
fflush(conf_global_log_file); fflush(conf_global_log_file);
for (list_it_init(log_all_logs, &li); list_it_item(&li); 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); log_t *log = list_it_item(&li);
hash_iterator_t hi; hash_iterator_t hi;
for (hash_it_init(&log->logfgs, &hi); hash_it_item(&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); logstore_t *store = hash_it_item(&hi);
list_iterator_t lj; list_iterator_t lj;
for (list_it_init(&store->file_group, &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); logfile_t *lf = list_it_item(&lj);
if (lf->file) if (lf->file)
fflush(lf->file); fflush(lf->file);
@ -1301,7 +1306,7 @@ void log_free(log_t *log)
free(log->buffer); free(log->buffer);
for (hash_it_init(&log->logfgs, &it); (store = hash_it_item(&it)); for (hash_it_init(&log->logfgs, &it); (store = hash_it_item(&it));
hash_it_next(&it)) { hash_it_next(&it)) {
log_reset(store); log_reset(store);
log_store_free(store); log_store_free(store);
} }
@ -1320,7 +1325,8 @@ array_t *str_split(const char *str, const char *splt)
const char *start = str; const char *start = str;
size_t len; size_t len;
char *extracted; char *extracted;
array_t *array = array_new();; array_t *array = array_new();
;
do { do {
if (!*p || strchr(splt, *p)) { 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 */ /* 26-12-2008 08:54:39 */
int log_parse_date(char *strdate, int *year, int *month, int *mday, int *hour, 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; array_t *fields;
char *sptr; char *sptr;
@ -1358,8 +1364,7 @@ int log_parse_date(char *strdate, int *year, int *month, int *mday, int *hour,
ret = 1; ret = 1;
} }
int i; int i;
array_each(fields, i, sptr) array_each(fields, i, sptr) free(sptr);
free(sptr);
array_free(fields); array_free(fields);
return ret; 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) 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); 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); logfile_t *lf = list_it_item(li);
if (mktime(&lf->last_log) > at) 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, 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; time_t blstarttime;
struct timeval tv; struct timeval tv;
@ -1397,10 +1402,9 @@ static list_t *log_backread_hours(log_t *log, const char *storename,
ret = list_new(NULL); ret = list_new(NULL);
for (logstore_get_file_at(store, blstarttime, &file_it); for (logstore_get_file_at(store, blstarttime, &file_it);
(logf = list_it_item(&file_it)); (logf = list_it_item(&file_it)); list_it_next(&file_it)) {
list_it_next(&file_it)) {
if (!log_backread_file(log, store, logf, ret, dest, if (!log_backread_file(log, store, logf, ret, dest,
blstarttime)) { blstarttime)) {
log_reinit(store); log_reinit(store);
return ret; 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, list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
int hours) int hours)
{ {
list_t *ret; list_t *ret;
struct line l; struct line l;
@ -1454,4 +1458,3 @@ list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
} }
return ret; return ret;
} }

View File

@ -29,8 +29,7 @@
struct list; struct list;
typedef struct logfile typedef struct logfile {
{
FILE *file; FILE *file;
char *filename; char *filename;
char *canonical_filename; char *canonical_filename;
@ -38,8 +37,7 @@ typedef struct logfile
size_t len; size_t len;
} logfile_t; } logfile_t;
typedef struct logstore typedef struct logstore {
{
char *name; char *name;
list_t file_group; list_t file_group;
int skip_advance; int skip_advance;
@ -51,8 +49,7 @@ typedef struct logstore
long file_offset; long file_offset;
} logstore_t; } logstore_t;
typedef struct log typedef struct log {
{
hash_t logfgs; hash_t logfgs;
char *network; char *network;
char *buffer; 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_join(log_t *logdata, const char *ircmask, const char *channel);
void log_part(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, 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, 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, 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, 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, void log_notice(log_t *logdata, const char *ircmask, const char *channel,
const char *message); const char *message);
void log_cli_privmsg(log_t *logdata, const char *ircmask, 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, 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_write(log_t *logdata, const char *str, const char *destination);
void log_mode(log_t *logdata, const char *ircmask, const char *channel, 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, 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(log_t *logdata, const char *channel, const char *message);
void log_init_topic_time(log_t *logdata, const char *channel, const char *who, 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_connected(log_t *logdata);
void log_disconnected(log_t *logdata); void log_disconnected(log_t *logdata);
void log_ping_timeout(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 *log_backlogs(log_t *log);
list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick, list_t *backlog_lines(log_t *log, const char *bl, const char *cli_nick,
int hours); int hours);
#endif #endif

480
src/md5.c
View File

@ -25,226 +25,218 @@
#include "md5.h" #include "md5.h"
#include "util.h" #include "util.h"
#define GET_UINT32(n,b,i) \ #define GET_UINT32(n, b, i) \
{ \ { \
(n) = ( (uint32) (b)[(i) ] ) \ (n) = ((uint32)(b)[(i)]) | ((uint32)(b)[(i) + 1] << 8) \
| ( (uint32) (b)[(i) + 1] << 8 ) \ | ((uint32)(b)[(i) + 2] << 16) \
| ( (uint32) (b)[(i) + 2] << 16 ) \ | ((uint32)(b)[(i) + 3] << 24); \
| ( (uint32) (b)[(i) + 3] << 24 ); \ }
}
#define PUT_UINT32(n,b,i) \ #define PUT_UINT32(n, b, i) \
{ \ { \
(b)[(i) ] = (uint8) ( (n) ); \ (b)[(i)] = (uint8)((n)); \
(b)[(i) + 1] = (uint8) ( (n) >> 8 ); \ (b)[(i) + 1] = (uint8)((n) >> 8); \
(b)[(i) + 2] = (uint8) ( (n) >> 16 ); \ (b)[(i) + 2] = (uint8)((n) >> 16); \
(b)[(i) + 3] = (uint8) ( (n) >> 24 ); \ (b)[(i) + 3] = (uint8)((n) >> 24); \
} }
void md5_starts( md5_context *ctx ) void md5_starts(md5_context *ctx)
{ {
ctx->total[0] = 0; ctx->total[0] = 0;
ctx->total[1] = 0; ctx->total[1] = 0;
ctx->state[0] = 0x67452301; ctx->state[0] = 0x67452301;
ctx->state[1] = 0xEFCDAB89; ctx->state[1] = 0xEFCDAB89;
ctx->state[2] = 0x98BADCFE; ctx->state[2] = 0x98BADCFE;
ctx->state[3] = 0x10325476; 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[0], data, 0);
GET_UINT32( X[1], data, 4 ); GET_UINT32(X[1], data, 4);
GET_UINT32( X[2], data, 8 ); GET_UINT32(X[2], data, 8);
GET_UINT32( X[3], data, 12 ); GET_UINT32(X[3], data, 12);
GET_UINT32( X[4], data, 16 ); GET_UINT32(X[4], data, 16);
GET_UINT32( X[5], data, 20 ); GET_UINT32(X[5], data, 20);
GET_UINT32( X[6], data, 24 ); GET_UINT32(X[6], data, 24);
GET_UINT32( X[7], data, 28 ); GET_UINT32(X[7], data, 28);
GET_UINT32( X[8], data, 32 ); GET_UINT32(X[8], data, 32);
GET_UINT32( X[9], data, 36 ); GET_UINT32(X[9], data, 36);
GET_UINT32( X[10], data, 40 ); GET_UINT32(X[10], data, 40);
GET_UINT32( X[11], data, 44 ); GET_UINT32(X[11], data, 44);
GET_UINT32( X[12], data, 48 ); GET_UINT32(X[12], data, 48);
GET_UINT32( X[13], data, 52 ); GET_UINT32(X[13], data, 52);
GET_UINT32( X[14], data, 56 ); GET_UINT32(X[14], data, 56);
GET_UINT32( X[15], data, 60 ); 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) \ #define P(a, b, c, d, k, s, t) \
{ \ { \
a += F(b,c,d) + X[k] + t; a = S(a,s) + b; \ a += F(b, c, d) + X[k] + t; \
} a = S(a, s) + b; \
}
A = ctx->state[0]; A = ctx->state[0];
B = ctx->state[1]; B = ctx->state[1];
C = ctx->state[2]; C = ctx->state[2];
D = ctx->state[3]; 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(A, B, C, D, 0, 7, 0xD76AA478);
P( D, A, B, C, 1, 12, 0xE8C7B756 ); P(D, A, B, C, 1, 12, 0xE8C7B756);
P( C, D, A, B, 2, 17, 0x242070DB ); P(C, D, A, B, 2, 17, 0x242070DB);
P( B, C, D, A, 3, 22, 0xC1BDCEEE ); P(B, C, D, A, 3, 22, 0xC1BDCEEE);
P( A, B, C, D, 4, 7, 0xF57C0FAF ); P(A, B, C, D, 4, 7, 0xF57C0FAF);
P( D, A, B, C, 5, 12, 0x4787C62A ); P(D, A, B, C, 5, 12, 0x4787C62A);
P( C, D, A, B, 6, 17, 0xA8304613 ); P(C, D, A, B, 6, 17, 0xA8304613);
P( B, C, D, A, 7, 22, 0xFD469501 ); P(B, C, D, A, 7, 22, 0xFD469501);
P( A, B, C, D, 8, 7, 0x698098D8 ); P(A, B, C, D, 8, 7, 0x698098D8);
P( D, A, B, C, 9, 12, 0x8B44F7AF ); P(D, A, B, C, 9, 12, 0x8B44F7AF);
P( C, D, A, B, 10, 17, 0xFFFF5BB1 ); P(C, D, A, B, 10, 17, 0xFFFF5BB1);
P( B, C, D, A, 11, 22, 0x895CD7BE ); P(B, C, D, A, 11, 22, 0x895CD7BE);
P( A, B, C, D, 12, 7, 0x6B901122 ); P(A, B, C, D, 12, 7, 0x6B901122);
P( D, A, B, C, 13, 12, 0xFD987193 ); P(D, A, B, C, 13, 12, 0xFD987193);
P( C, D, A, B, 14, 17, 0xA679438E ); P(C, D, A, B, 14, 17, 0xA679438E);
P( B, C, D, A, 15, 22, 0x49B40821 ); P(B, C, D, A, 15, 22, 0x49B40821);
#undef F #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(A, B, C, D, 1, 5, 0xF61E2562);
P( D, A, B, C, 6, 9, 0xC040B340 ); P(D, A, B, C, 6, 9, 0xC040B340);
P( C, D, A, B, 11, 14, 0x265E5A51 ); P(C, D, A, B, 11, 14, 0x265E5A51);
P( B, C, D, A, 0, 20, 0xE9B6C7AA ); P(B, C, D, A, 0, 20, 0xE9B6C7AA);
P( A, B, C, D, 5, 5, 0xD62F105D ); P(A, B, C, D, 5, 5, 0xD62F105D);
P( D, A, B, C, 10, 9, 0x02441453 ); P(D, A, B, C, 10, 9, 0x02441453);
P( C, D, A, B, 15, 14, 0xD8A1E681 ); P(C, D, A, B, 15, 14, 0xD8A1E681);
P( B, C, D, A, 4, 20, 0xE7D3FBC8 ); P(B, C, D, A, 4, 20, 0xE7D3FBC8);
P( A, B, C, D, 9, 5, 0x21E1CDE6 ); P(A, B, C, D, 9, 5, 0x21E1CDE6);
P( D, A, B, C, 14, 9, 0xC33707D6 ); P(D, A, B, C, 14, 9, 0xC33707D6);
P( C, D, A, B, 3, 14, 0xF4D50D87 ); P(C, D, A, B, 3, 14, 0xF4D50D87);
P( B, C, D, A, 8, 20, 0x455A14ED ); P(B, C, D, A, 8, 20, 0x455A14ED);
P( A, B, C, D, 13, 5, 0xA9E3E905 ); P(A, B, C, D, 13, 5, 0xA9E3E905);
P( D, A, B, C, 2, 9, 0xFCEFA3F8 ); P(D, A, B, C, 2, 9, 0xFCEFA3F8);
P( C, D, A, B, 7, 14, 0x676F02D9 ); P(C, D, A, B, 7, 14, 0x676F02D9);
P( B, C, D, A, 12, 20, 0x8D2A4C8A ); P(B, C, D, A, 12, 20, 0x8D2A4C8A);
#undef F
#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 );
#undef F #undef F
#define F(x,y,z) (y ^ (x | ~z)) #define F(x, y, z) (x ^ y ^ z)
P( A, B, C, D, 0, 6, 0xF4292244 ); P(A, B, C, D, 5, 4, 0xFFFA3942);
P( D, A, B, C, 7, 10, 0x432AFF97 ); P(D, A, B, C, 8, 11, 0x8771F681);
P( C, D, A, B, 14, 15, 0xAB9423A7 ); P(C, D, A, B, 11, 16, 0x6D9D6122);
P( B, C, D, A, 5, 21, 0xFC93A039 ); P(B, C, D, A, 14, 23, 0xFDE5380C);
P( A, B, C, D, 12, 6, 0x655B59C3 ); P(A, B, C, D, 1, 4, 0xA4BEEA44);
P( D, A, B, C, 3, 10, 0x8F0CCC92 ); P(D, A, B, C, 4, 11, 0x4BDECFA9);
P( C, D, A, B, 10, 15, 0xFFEFF47D ); P(C, D, A, B, 7, 16, 0xF6BB4B60);
P( B, C, D, A, 1, 21, 0x85845DD1 ); P(B, C, D, A, 10, 23, 0xBEBFBC70);
P( A, B, C, D, 8, 6, 0x6FA87E4F ); P(A, B, C, D, 13, 4, 0x289B7EC6);
P( D, A, B, C, 15, 10, 0xFE2CE6E0 ); P(D, A, B, C, 0, 11, 0xEAA127FA);
P( C, D, A, B, 6, 15, 0xA3014314 ); P(C, D, A, B, 3, 16, 0xD4EF3085);
P( B, C, D, A, 13, 21, 0x4E0811A1 ); P(B, C, D, A, 6, 23, 0x04881D05);
P( A, B, C, D, 4, 6, 0xF7537E82 ); P(A, B, C, D, 9, 4, 0xD9D4D039);
P( D, A, B, C, 11, 10, 0xBD3AF235 ); P(D, A, B, C, 12, 11, 0xE6DB99E5);
P( C, D, A, B, 2, 15, 0x2AD7D2BB ); P(C, D, A, B, 15, 16, 0x1FA27CF8);
P( B, C, D, A, 9, 21, 0xEB86D391 ); P(B, C, D, A, 2, 23, 0xC4AC5665);
#undef F #undef F
ctx->state[0] += A; #define F(x, y, z) (y ^ (x | ~z))
ctx->state[1] += B;
ctx->state[2] += C; P(A, B, C, D, 0, 6, 0xF4292244);
ctx->state[3] += D; 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;
} }
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; left = ctx->total[0] & 0x3F;
fill = 64 - left; fill = 64 - left;
ctx->total[0] += length; ctx->total[0] += length;
ctx->total[0] &= 0xFFFFFFFF; ctx->total[0] &= 0xFFFFFFFF;
if( ctx->total[0] < length ) if (ctx->total[0] < length)
ctx->total[1]++; ctx->total[1]++;
if( left && length >= fill ) if (left && length >= fill) {
{ memcpy((void *)(ctx->buffer + left), (void *)input, fill);
memcpy( (void *) (ctx->buffer + left), md5_process(ctx, ctx->buffer);
(void *) input, fill ); length -= fill;
md5_process( ctx, ctx->buffer ); input += fill;
length -= fill; left = 0;
input += fill; }
left = 0;
}
while( length >= 64 ) while (length >= 64) {
{ md5_process(ctx, input);
md5_process( ctx, input ); length -= 64;
length -= 64; input += 64;
input += 64; }
}
if( length ) if (length) {
{ memcpy((void *)(ctx->buffer + left), (void *)input, 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, uint32 last, padn;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint32 high, low;
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, uint8 msglen[8];
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] ) high = (ctx->total[0] >> 29) | (ctx->total[1] << 3);
{ low = (ctx->total[0] << 3);
uint32 last, padn;
uint32 high, low;
uint8 msglen[8];
high = ( ctx->total[0] >> 29 ) PUT_UINT32(low, msglen, 0);
| ( ctx->total[1] << 3 ); PUT_UINT32(high, msglen, 4);
low = ( ctx->total[0] << 3 );
PUT_UINT32( low, msglen, 0 ); last = ctx->total[0] & 0x3F;
PUT_UINT32( high, msglen, 4 ); padn = (last < 56) ? (56 - last) : (120 - last);
last = ctx->total[0] & 0x3F; md5_update(ctx, md5_padding, padn);
padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); md5_update(ctx, msglen, (unsigned long)8);
md5_update( ctx, md5_padding, padn ); PUT_UINT32(ctx->state[0], digest, 0);
md5_update( ctx, msglen, (unsigned long)8 ); PUT_UINT32(ctx->state[1], digest, 4);
PUT_UINT32(ctx->state[2], digest, 8);
PUT_UINT32( ctx->state[0], digest, 0 ); PUT_UINT32(ctx->state[3], digest, 12);
PUT_UINT32( ctx->state[1], digest, 4 );
PUT_UINT32( ctx->state[2], digest, 8 );
PUT_UINT32( ctx->state[3], digest, 12 );
} }
#ifdef TEST #ifdef TEST
@ -256,92 +248,76 @@ void md5_finish( md5_context *ctx, uint8 digest[16] )
* those are the standard RFC 1321 test vectors * 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[])
{ {
"", FILE *f;
"a", int i, j;
"abc", char output[33];
"message digest", md5_context ctx;
"abcdefghijklmnopqrstuvwxyz", unsigned char buf[1000];
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", unsigned char md5sum[16];
"12345678901234567890123456789012345678901234567890123456789012" \
"345678901234567890"
};
static char *val[] = if (argc < 2) {
{ printf("\n MD5 Validation Tests:\n\n");
"d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a"
};
int main( int argc, char *argv[] ) for (i = 0; i < 7; i++) {
{ printf(" Test %d ", i + 1);
FILE *f;
int i, j;
char output[33];
md5_context ctx;
unsigned char buf[1000];
unsigned char md5sum[16];
if( argc < 2 ) md5_starts(&ctx);
{ md5_update(&ctx, (uint8 *)msg[i], strlen(msg[i]));
printf( "\n MD5 Validation Tests:\n\n" ); md5_finish(&ctx, md5sum);
for( i = 0; i < 7; i++ ) for (j = 0; j < 16; j++) {
{ sprintf(output + j * 2, "%02x", md5sum[j]);
printf( " Test %d ", i + 1 ); }
md5_starts( &ctx ); if (memcmp(output, val[i], 32)) {
md5_update( &ctx, (uint8 *) msg[i], strlen( msg[i] ) ); printf("failed!\n");
md5_finish( &ctx, md5sum ); return (1);
}
for( j = 0; j < 16; j++ ) printf("passed.\n");
{ }
sprintf( output + j * 2, "%02x", md5sum[j] );
}
if( memcmp( output, val[i], 32 ) ) printf("\n");
{ } else {
printf( "failed!\n" ); if (!(f = fopen(argv[1], "rb"))) {
return( 1 ); perror("fopen");
} return (1);
}
printf( "passed.\n" ); md5_starts(&ctx);
}
printf( "\n" ); while ((i = fread(buf, 1, sizeof(buf), f)) > 0) {
} md5_update(&ctx, buf, i);
else }
{
if( ! ( f = fopen( argv[1], "rb" ) ) )
{
perror( "fopen" );
return( 1 );
}
md5_starts( &ctx ); md5_finish(&ctx, md5sum);
while( ( i = fread( buf, 1, sizeof( buf ), f ) ) > 0 ) for (j = 0; j < 16; j++) {
{ printf("%02x", md5sum[j]);
md5_update( &ctx, buf, i ); }
}
md5_finish( &ctx, md5sum ); printf(" %s\n", argv[1]);
}
for( j = 0; j < 16; j++ ) return (0);
{
printf( "%02x", md5sum[j] );
}
printf( " %s\n", argv[1] );
}
return( 0 );
} }
#endif #endif
@ -360,7 +336,8 @@ unsigned char *chash_double(char *str, unsigned int seed)
length = strlen(str); length = strlen(str);
length += 4; length += 4;
ptr = bip_malloc(length); 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 push
#pragma GCC diagnostic ignored "-Wconversion" #pragma GCC diagnostic ignored "-Wconversion"
ptr[0] = seed >> 24 & 0xff; ptr[0] = seed >> 24 & 0xff;
@ -399,4 +376,3 @@ int chash_cmp(char *try, unsigned char *pass, unsigned int seed)
free(try_hash); free(try_hash);
return 0; return 0;
} }

View File

@ -2,22 +2,19 @@
#define _MD5_H #define _MD5_H
#ifndef uint8 #ifndef uint8
#define uint8 unsigned char #define uint8 unsigned char
#endif #endif
#ifndef uint32 #ifndef uint32
#define uint32 unsigned long int #define uint32 unsigned long int
#endif #endif
typedef struct typedef struct {
{ uint32 total[2];
uint32 total[2]; uint32 state[4];
uint32 state[4]; uint8 buffer[64];
uint8 buffer[64]; } md5_context;
}
md5_context;
int chash_cmp(char *try, unsigned char *pass, int chash_cmp(char *try, unsigned char *pass, unsigned int seed);
unsigned int seed);
unsigned char *chash_double(char *str, unsigned int seed); unsigned char *chash_double(char *str, unsigned int seed);
#endif /* md5.h */ #endif /* md5.h */

View File

@ -107,8 +107,9 @@ char *bip_strcat_fit(size_t *remaining, char *str, const char *str2)
res = memccpy(str, str2, '\0', *remaining); res = memccpy(str, str2, '\0', *remaining);
if (!res) { if (!res) {
mylog(LOG_DEBUGTOOMUCH, "bip_strcat_fit: memccpy() failed, remaining %lu", mylog(LOG_DEBUGTOOMUCH,
*remaining); "bip_strcat_fit: memccpy() failed, remaining %lu",
*remaining);
return NULL; return NULL;
} }
@ -135,8 +136,9 @@ char *bip_strcatf_fit(size_t *remaining, char *str, const char *fmt, ...)
} }
if (*remaining > STRCATF_BUF_MAXLEN) { if (*remaining > STRCATF_BUF_MAXLEN) {
mylog(LOG_ERROR, "bip_strcatf_fit: remaining " mylog(LOG_ERROR,
"is over STRCATF_BUF_MAXLEN"); "bip_strcatf_fit: remaining "
"is over STRCATF_BUF_MAXLEN");
} }
va_start(ap, fmt); 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); written = vsnprintf(str2, *remaining, fmt, ap);
if (written < 0) { if (written < 0) {
mylog(LOG_ERROR, "bip_strcatf_fit: vsnprintf failed with: %s", mylog(LOG_ERROR, "bip_strcatf_fit: vsnprintf failed with: %s",
strerror(errno)); strerror(errno));
return NULL; return NULL;
} }
if ((unsigned)written >= *remaining) { 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; goto end;
} }
res = memccpy(str, str2, '\0', *remaining); res = memccpy(str, str2, '\0', *remaining);
if (!res) { if (!res) {
mylog(LOG_DEBUGTOOMUCH, "bip_strcatf_fit: memccpy() failed, " mylog(LOG_DEBUGTOOMUCH,
"remaining %lu", *remaining); "bip_strcatf_fit: memccpy() failed, "
"remaining %lu",
*remaining);
goto end; goto end;
} }
@ -194,10 +199,10 @@ int is_valid_nick(char *str)
return 0; return 0;
tmp = str; tmp = str;
while (*tmp != '\0' && (isalnum(*tmp) || *tmp == '-' || *tmp == '[' || while (*tmp != '\0'
*tmp == ']' || *tmp == '\\' || *tmp == '`' || && (isalnum(*tmp) || *tmp == '-' || *tmp == '[' || *tmp == ']'
*tmp == '^' || *tmp == '{' || *tmp == '}' || || *tmp == '\\' || *tmp == '`' || *tmp == '^' || *tmp == '{'
*tmp == '|' || *tmp == '_' )) || *tmp == '}' || *tmp == '|' || *tmp == '_'))
tmp++; tmp++;
return (*tmp == '\0'); return (*tmp == '\0');
} }
@ -209,8 +214,8 @@ int is_valid_username(char *str)
return 0; return 0;
tmp = str; tmp = str;
while (*tmp != '\0' && *tmp != ' ' && *tmp != '\0' && *tmp != '\r' && while (*tmp != '\0' && *tmp != ' ' && *tmp != '\0' && *tmp != '\r'
*tmp != '\n') && *tmp != '\n')
tmp++; tmp++;
return (*tmp == '\0'); return (*tmp == '\0');
} }
@ -266,27 +271,27 @@ void _mylog(int level, char *fmt, va_list ap)
return; return;
switch (level) { switch (level) {
case LOG_FATAL: case LOG_FATAL:
prefix = "FATAL: "; prefix = "FATAL: ";
break; break;
case LOG_DEBUGVERB: case LOG_DEBUGVERB:
prefix = "DEBUGVERB: "; prefix = "DEBUGVERB: ";
break; break;
case LOG_DEBUG: case LOG_DEBUG:
prefix = "DEBUG: "; prefix = "DEBUG: ";
break; break;
case LOG_ERROR: case LOG_ERROR:
prefix = "ERROR: "; prefix = "ERROR: ";
break; break;
case LOG_WARN: case LOG_WARN:
prefix = "WARNING: "; prefix = "WARNING: ";
break; break;
case LOG_INFO: case LOG_INFO:
prefix = ""; prefix = "";
break; break;
default: default:
prefix = ""; prefix = "";
break; break;
} }
fprintf(conf_global_log_file, "%s %s", timestamp(), prefix); fprintf(conf_global_log_file, "%s %s", timestamp(), prefix);
@ -606,13 +611,13 @@ void hash_init(hash_t *h, int options)
switch (options) { switch (options) {
case HASH_NOCASE: case HASH_NOCASE:
list_init(&h->lists[i], list_init(&h->lists[i],
(int (*)(const void*, const void*)) (int (*)(const void *,
hash_item_nocase_cmp); const void *))hash_item_nocase_cmp);
break; break;
case HASH_DEFAULT: case HASH_DEFAULT:
list_init(&h->lists[i], list_init(&h->lists[i],
(int (*)(const void*,const void*)) (int (*)(const void *,
hash_item_cmp); const void *))hash_item_cmp);
break; break;
default: default:
fatal("wrong hash option %d", options); fatal("wrong hash option %d", options);
@ -800,7 +805,7 @@ void hash_dump(hash_t *h)
{ {
hash_iterator_t it; hash_iterator_t it;
assert(h); 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)); 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->elemv = bip_realloc(a->elemv, sizeof(void *) * (size_t)(index + 1));
// a->elemc should be lower than index + 1 // a->elemc should be lower than index + 1
memset(a->elemv + a->elemc, 0, 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; a->elemc = index + 1;
} }

View File

@ -74,37 +74,42 @@ typedef struct array {
const void **elemv; const void **elemv;
} array_t; } array_t;
#define MOVE_STRING(dest, src) do {\ #define MOVE_STRING(dest, src) \
if (dest)\ do { \
free(dest);\ if (dest) \
(dest) = (src);\ free(dest); \
(src) = NULL;\ (dest) = (src); \
} while(0) (src) = NULL; \
} while (0)
#define FREE(a) free(a); (a) = NULL; #define FREE(a) \
free(a); \
(a) = NULL;
#define MAYFREE(a) do { \ #define MAYFREE(a) \
if (a) { \ do { \
free(a); \ if (a) { \
(a) = NULL; \ free(a); \
} \ (a) = NULL; \
} while(0); } \
} while (0);
#define assert(condition) \ #define assert(condition) \
do { \ do { \
if (!(condition)) \ if (!(condition)) \
fatal("Failed assertion in " __FILE__ "(%d): " \ fatal("Failed assertion in " __FILE__ \
#condition, __LINE__); \ "(%d): " #condition, \
} while(0) __LINE__); \
} while (0)
#define assert_msg(condition, msg) \ #define assert_msg(condition, msg) \
do { \ do { \
if (!(condition)) \ if (!(condition)) \
fatal("%s in " __FILE__ "(%d): " \ fatal("%s in " __FILE__ "(%d): " #condition, (msg), \
#condition, (msg), __LINE__); \ __LINE__); \
} while(0) } 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); int list_ptr_cmp(const void *a, const void *b);
list_t *list_new(int (*cmp)(const void *, const void *)); list_t *list_new(int (*cmp)(const void *, const void *));
void *list_remove(list_t *list, const void *ptr); 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_strcat_fit(size_t *remaining, char *str, const char *str2);
char *bip_strcatf_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); void bip_clock_gettime(clockid_t clockid, struct timespec *tp);
#define array_each(a, idx, ptr) for ((idx) = 0; \ #define array_each(a, idx, ptr) \
(idx) < (a)->elemc && (((ptr) = bip_strdup(array_get((a), (idx)))) || 1); \ for ((idx) = 0; (idx) < (a)->elemc \
(idx)++) && (((ptr) = bip_strdup(array_get((a), (idx)))) || 1); \
(idx)++)
void array_init(array_t *a); void array_init(array_t *a);
array_t *array_new(void); array_t *array_new(void);

View File

@ -29,8 +29,8 @@ static const unsigned char base64_table[65] =
* *
* BIP change: remove line returns. * BIP change: remove line returns.
*/ */
unsigned char * base64_encode(const unsigned char *src, size_t len, unsigned char *base64_encode(const unsigned char *src, size_t len,
size_t *out_len) size_t *out_len)
{ {
unsigned char *out, *pos; unsigned char *out, *pos;
const unsigned char *end, *in; const unsigned char *end, *in;
@ -38,8 +38,8 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
int line_len; int line_len;
olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */ olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
olen += olen / 72; /* line feeds */ olen += olen / 72; /* line feeds */
olen++; /* nul termination */ olen++; /* nul termination */
if (olen < len) if (olen < len)
return NULL; /* integer overflow */ return NULL; /* integer overflow */
out = malloc(olen); out = malloc(olen);
@ -57,7 +57,7 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
*pos++ = base64_table[in[2] & 0x3f]; *pos++ = base64_table[in[2] & 0x3f];
in += 3; in += 3;
line_len += 4; line_len += 4;
/* /*
* BIP change: remove line returns. * BIP change: remove line returns.
if (line_len >= 72) { if (line_len >= 72) {
*pos++ = '\n'; *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++ = base64_table[(in[0] & 0x03) << 4];
*pos++ = '='; *pos++ = '=';
} else { } else {
*pos++ = base64_table[((in[0] & 0x03) << 4) | *pos++ = base64_table[((in[0] & 0x03) << 4)
(in[1] >> 4)]; | (in[1] >> 4)];
*pos++ = base64_table[(in[1] & 0x0f) << 2]; *pos++ = base64_table[(in[1] & 0x0f) << 2];
} }
*pos++ = '='; *pos++ = '=';
line_len += 4; line_len += 4;
} }
/* /*
* BIP change: remove line returns. * BIP change: remove line returns.
if (line_len) if (line_len)
*pos++ = '\n'; *pos++ = '\n';
@ -91,4 +91,3 @@ unsigned char * base64_encode(const unsigned char *src, size_t len,
*out_len = (size_t)(pos - out); *out_len = (size_t)(pos - out);
return out; return out;
} }

View File

@ -10,7 +10,7 @@
#ifndef BASE64_H #ifndef BASE64_H
#define BASE64_H #define BASE64_H
unsigned char * base64_encode(const unsigned char *src, size_t len, unsigned char *base64_encode(const unsigned char *src, size_t len,
size_t *out_len); size_t *out_len);
#endif /* BASE64_H */ #endif /* BASE64_H */