gaim/gaim

Backport that logging error checking patch from head
oldstatus
2005-02-05, Mark Doliner
f8510b047ca1
Parents 6863623ef311
Children d23d5e6c93c9
Backport that logging error checking patch from head
  • +30 -12
    src/log.c
  • --- a/src/log.c Sat Feb 05 13:41:17 2005 -0500
    +++ b/src/log.c Sat Feb 05 16:57:34 2005 -0500
    @@ -173,16 +173,24 @@
    return size;
    }
    -static char* gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account) {
    - char *acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account,
    - gaim_account_get_username(account))));
    +static char *
    +gaim_log_get_log_dir(GaimLogType type, const char *name, GaimAccount *account)
    +{
    + GaimPlugin *prpl;
    + GaimPluginProtocolInfo *prpl_info;
    + const char *prpl_name;
    + char *acct_name;
    const char *target;
    - /* does this seem like a bad way to get this component of the path to anyone else? --Nathan */
    - const char *prpl = GAIM_PLUGIN_PROTOCOL_INFO(
    - gaim_find_prpl(gaim_account_get_protocol_id(account))
    - )->list_icon(account, NULL);
    + char *dir;
    - char *dir;
    + prpl = gaim_find_prpl(gaim_account_get_protocol_id(account));
    + if (!prpl)
    + return NULL;
    + prpl_info = GAIM_PLUGIN_PROTOCOL_INFO(prpl);
    + prpl_name = prpl_info->list_icon(account, NULL);
    +
    + acct_name = g_strdup(gaim_escape_filename(gaim_normalize(account,
    + gaim_account_get_username(account))));
    if (type == GAIM_LOG_CHAT) {
    char *temp = g_strdup_printf("%s.chat", gaim_normalize(account, name));
    @@ -194,10 +202,10 @@
    target = gaim_escape_filename(gaim_normalize(account, name));
    }
    -
    - dir = g_build_filename(gaim_user_dir(), "logs", prpl, acct_name, target, NULL);
    + dir = g_build_filename(gaim_user_dir(), "logs", prpl_name, acct_name, target, NULL);
    g_free(acct_name);
    +
    return dir;
    }
    @@ -367,8 +375,11 @@
    if(!data) {
    /* This log is new */
    char *dir, *filename, *path;
    -
    +
    dir = gaim_log_get_log_dir(log->type, log->name, log->account);
    + if (dir == NULL)
    + return;
    +
    gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);
    strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S", localtime(&log->time));
    @@ -389,7 +400,7 @@
    return;
    }
    g_free(path);
    - }
    + }
    }
    static GList *log_lister_common(GaimLogType type, const char *name, GaimAccount *account, const char *ext, GaimLogLogger *logger)
    @@ -403,6 +414,8 @@
    return NULL;
    path = gaim_log_get_log_dir(type, name, account);
    + if (path == NULL)
    + return NULL;
    if (!(dir = g_dir_open(path, 0, NULL))) {
    g_free(path);
    @@ -458,6 +471,7 @@
    {
    char date[64];
    char *xhtml = NULL;
    +
    if (!log->logger_data) {
    /* This log is new. We could use the loggers 'new' function, but
    * creating a new file there would result in empty files in the case
    @@ -465,6 +479,10 @@
    */
    char *dir = gaim_log_get_log_dir(log->type, log->name, log->account);
    FILE *file;
    +
    + if (dir == NULL)
    + return;
    +
    strftime(date, sizeof(date), "%Y-%m-%d.%H%M%S.xml", localtime(&log->time));
    gaim_build_dir (dir, S_IRUSR | S_IWUSR | S_IXUSR);