From: Richard L. <rl...@us...> - 2006-03-03 08:46:06
|
Update of /cvsroot/gaim/gaim/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6673/src Modified Files: log.c log.h Log Message: Implement a total_size function for the text and HTML loggers. This way, when we call gaim_log_get_total_size(), we don't have to create and then immediately destroy a bunch of GaimLog instances. Index: log.c =================================================================== RCS file: /cvsroot/gaim/gaim/src/log.c,v retrieving revision 1.154 retrieving revision 1.155 diff -u -d -p -r1.154 -r1.155 --- log.c 1 Mar 2006 05:37:26 -0000 1.154 +++ log.c 3 Mar 2006 08:45:59 -0000 1.155 @@ -51,6 +51,7 @@ static void html_logger_finalize(GaimLog static GList *html_logger_list(GaimLogType type, const char *sn, GaimAccount *account); static GList *html_logger_list_syslog(GaimAccount *account); static char *html_logger_read(GaimLog *log, GaimLogReadFlags *flags); +static int html_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); static GList *old_logger_list(GaimLogType type, const char *sn, GaimAccount *account); static int old_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); @@ -66,6 +67,7 @@ static void txt_logger_finalize(GaimLog static GList *txt_logger_list(GaimLogType type, const char *sn, GaimAccount *account); static GList *txt_logger_list_syslog(GaimAccount *account); static char *txt_logger_read(GaimLog *log, GaimLogReadFlags *flags); +static int txt_logger_total_size(GaimLogType type, const char *name, GaimAccount *account); /************************************************************************** * PUBLIC LOGGING FUNCTIONS *********************************************** @@ -551,7 +553,7 @@ void gaim_log_init(void) html_logger_list, html_logger_read, gaim_log_common_sizer, - NULL, + html_logger_total_size, html_logger_list_syslog); gaim_log_logger_add(html_logger); @@ -562,7 +564,7 @@ void gaim_log_init(void) txt_logger_list, txt_logger_read, gaim_log_common_sizer, - NULL, + txt_logger_total_size, txt_logger_list_syslog); gaim_log_logger_add(txt_logger); @@ -738,6 +740,48 @@ GList *gaim_log_common_lister(GaimLogTyp return list; } +int gaim_log_common_total_sizer(GaimLogType type, const char *name, GaimAccount *account, const char *ext) +{ + GDir *dir; + int size = 0; + const char *filename; + char *path; + + if(!account) + return 0; + + path = gaim_log_get_log_dir(type, name, account); + if (path == NULL) + return 0; + + if (!(dir = g_dir_open(path, 0, NULL))) + { + g_free(path); + return 0; + } + + while ((filename = g_dir_read_name(dir))) + { + if (gaim_str_has_suffix(filename, ext) && + strlen(filename) >= (17 + strlen(ext))) + { + char *tmp = g_build_filename(path, filename, NULL); + struct stat st; + if (g_stat(tmp, &st)) + { + gaim_debug_error("log", "Error stating log file: %s\n", tmp); + g_free(tmp); + continue; + } + g_free(tmp); + size += st.st_size; + } + } + g_dir_close(dir); + g_free(path); + return size; +} + int gaim_log_common_sizer(GaimLog *log) { struct stat st; @@ -1104,6 +1148,10 @@ static char *html_logger_read(GaimLog *l return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); } +static int html_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) +{ + return gaim_log_common_total_sizer(type, name, account, ".html"); +} /**************************** @@ -1228,6 +1276,10 @@ static char *txt_logger_read(GaimLog *lo return g_strdup_printf(_("<font color=\"red\"><b>Could not read file: %s</b></font>"), data->path); } +static int txt_logger_total_size(GaimLogType type, const char *name, GaimAccount *account) +{ + return gaim_log_common_total_sizer(type, name, account, ".txt"); +} /**************** Index: log.h =================================================================== RCS file: /cvsroot/gaim/gaim/src/log.h,v retrieving revision 1.31 retrieving revision 1.32 diff -u -d -p -r1.31 -r1.32 --- log.h 4 Feb 2006 20:55:51 -0000 1.31 +++ log.h 3 Mar 2006 08:45:59 -0000 1.32 @@ -349,6 +349,25 @@ GList *gaim_log_common_lister(GaimLogTyp GaimLogLogger *logger); /** + * Returns the total size of all the logs for a given user, with + * a given extension. This is the "common" implemention of a + * logger's total_size function. + * This function should only be used with logs that are written + * with gaim_log_common_writer(). + * + * @param type The type of the logs being sized. + * @param name The name of the logs to size + * (e.g. the username or chat name). + * @param account The account of the log. + * @param ext The file extension this log format uses. + * + * @return The size of all the logs with the specified extension + * for the specified user. + */ +int gaim_log_common_total_sizer(GaimLogType type, const char *name, + GaimAccount *account, const char *ext); + +/** * Returns the size of a given GaimLog. * This function should only be used with logs that are written * with gaim_log_common_writer(). |