1
0
mirror of https://github.com/Tha14/toxic.git synced 2024-12-23 20:23:25 +01:00

give groupchat logs unique names

This commit is contained in:
Jfreegman 2014-02-26 17:15:34 -05:00
parent 8e4db369bc
commit 817f763589
5 changed files with 26 additions and 15 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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) */