diff --git a/src/chat_commands.c b/src/chat_commands.c index 2fd35bf..9fdedb3 100644 --- a/src/chat_commands.c +++ b/src/chat_commands.c @@ -108,7 +108,7 @@ void cmd_join_group(WINDOW *window, ToxWindow *self, Tox *m, int argc, char (*ar return; } - if (init_groupchat_win(prompt, m, groupnum, groupkey) == -1) { + if (init_groupchat_win(prompt, m, groupnum) == -1) { wprintw(window, "Group chat window failed to initialize.\n"); tox_del_groupchat(m, groupnum); return; diff --git a/src/groupchat.c b/src/groupchat.c index 738fe89..fd1980f 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -602,7 +602,7 @@ static void groupchat_onInit(ToxWindow *self, Tox *m) wmove(self->window, y-CURS_Y_OFFSET, 0); ctx->log.log_on = true; - init_logging_session(self->name, groupchats[self->num].groupkey, ctx); + init_logging_session(self->name, NULL, ctx); } ToxWindow new_group_chat(Tox *m, int groupnum) diff --git a/src/groupchat.h b/src/groupchat.h index 542510c..5b079d5 100644 --- a/src/groupchat.h +++ b/src/groupchat.h @@ -30,7 +30,6 @@ typedef struct { int side_pos; /* current position of the sidebar - used for scrolling up and down */ uint8_t *peer_names; uint8_t *oldpeer_names; - uint8_t groupkey[TOX_CLIENT_ID_SIZE]; } GroupChat; void kill_groupchat_window(ToxWindow *self); diff --git a/src/log.c b/src/log.c index 3ed1aea..f8d2de8 100644 --- a/src/log.c +++ b/src/log.c @@ -28,23 +28,36 @@ #include "toxic_windows.h" #include "misc_tools.h" -/* gets the log path by appending to the config dir the name and first 4 chars of key */ +/* gets the log path by appending to the config dir the name and a pseudo-unique identity */ void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx) { if (!ctx->log.log_on) return; char *user_config_dir = get_user_config_dir(); - int path_len = strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(name)\ - + (KEY_IDENT_DIGITS * 2) + 5; + int path_len = strlen(user_config_dir) + strlen(CONFIGDIR) + strlen(name); - if (path_len > MAX_STR_SIZE) + /* use first 4 digits of key as log ident. If no key use a timestamp */ + uint8_t ident[32]; + + if (key != NULL) { + path_len += (KEY_IDENT_DIGITS * 2 + 5); + + sprintf(&ident[0], "%02X", key[0] & 0xff); + sprintf(&ident[2], "%02X", key[2] & 0xff); + ident[KEY_IDENT_DIGITS*2+1] = '\0'; + } else { + struct tm *tminfo = get_time(); + snprintf(ident, 32, + "%04d-%02d-%02d-%02d:%02d:%02d", tminfo->tm_year+1900,tminfo->tm_mon+1, tminfo->tm_mday, + tminfo->tm_hour, tminfo->tm_min, tminfo->tm_sec); + path_len += strlen(ident) + 1; + } + + if (path_len > MAX_STR_SIZE) { + ctx->log.log_on = false; return; - - uint8_t ident[KEY_IDENT_DIGITS*2+1]; - sprintf(&ident[0], "%02X", key[0] & 0xff); - sprintf(&ident[2], "%02X", key[2] & 0xff); - ident[KEY_IDENT_DIGITS*2+1] = '\0'; + } snprintf(ctx->log.log_path, MAX_STR_SIZE, "%s%s%s-%s.log", user_config_dir, CONFIGDIR, name, ident); diff --git a/src/log.h b/src/log.h index 45b1c62..da50aa2 100644 --- a/src/log.h +++ b/src/log.h @@ -20,9 +20,8 @@ * */ -/* gets a log path by appending to the config dir the name and first 4 chars of the pub_key, - writes current date/time to log file. */ -void init_logging_session(uint8_t *name, uint8_t *pub_key, ChatContext *ctx); +/* gets the log path by appending to the config dir the name and a pseudo-unique identity */ +void init_logging_session(uint8_t *name, uint8_t *key, ChatContext *ctx) /* Adds msg to log_buf with timestamp and name. If buf is full, triggers write_to_log (which sets buf pos to 0) */