about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-05 01:20:42 +0000
committerJames Booth <boothj5@gmail.com>2014-01-05 01:20:42 +0000
commitf569845b40057dcc90d588e46147f7694a0b5e1b (patch)
tree79e098d84c25da9f481b2d965ae6156c4e7806ae /src
parente504c030a6325fc41d7daf667b2158cb31d8773e (diff)
parent5898da963a254294ce5dd24b8a9534256f7efd45 (diff)
downloadprofani-tty-f569845b40057dcc90d588e46147f7694a0b5e1b.tar.gz
Merge branch 'master' into otr
Conflicts:
	.gitignore
Diffstat (limited to 'src')
-rw-r--r--src/contact.c7
-rw-r--r--src/log.c58
2 files changed, 33 insertions, 32 deletions
diff --git a/src/contact.c b/src/contact.c
index 0b955548..f2f74349 100644
--- a/src/contact.c
+++ b/src/contact.c
@@ -172,11 +172,8 @@ p_contact_create_display_string(const PContact contact, const char * const resou
     GString *result_str = g_string_new("");
 
     // use nickname if exists
-    if (contact->name != NULL) {
-        g_string_append(result_str, contact->name);
-    } else {
-        g_string_append(result_str, contact->barejid);
-    }
+    const char *display_name = p_contact_name_or_jid(contact);
+    g_string_append(result_str, display_name);
 
     // add resource if not default provided by profanity
     if (strcmp(resource, "__prof_default") != 0) {
diff --git a/src/log.c b/src/log.c
index 4442dcfd..b82905cf 100644
--- a/src/log.c
+++ b/src/log.c
@@ -131,13 +131,15 @@ void
 log_close(void)
 {
     g_time_zone_unref(tz);
-    fclose(logp);
+    if (logp != NULL) {
+        fclose(logp);
+    }
 }
 
 void
 log_msg(log_level_t level, const char * const area, const char * const msg)
 {
-    if (level >= level_filter) {
+    if (level >= level_filter && logp != NULL) {
         long result;
         dt = g_date_time_new_now(tz);
 
@@ -238,25 +240,26 @@ chat_log_chat(const gchar * const login, gchar *other,
     date_fmt = g_date_time_format(dt, "%H:%M:%S");
 
     FILE *logp = fopen(dated_log->filename, "a");
-
-    if (direction == PROF_IN_LOG) {
-        if (strncmp(msg, "/me ", 4) == 0) {
-            fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4);
+    if (logp != NULL) {
+        if (direction == PROF_IN_LOG) {
+            if (strncmp(msg, "/me ", 4) == 0) {
+                fprintf(logp, "%s - *%s %s\n", date_fmt, other, msg + 4);
+            } else {
+                fprintf(logp, "%s - %s: %s\n", date_fmt, other, msg);
+            }
         } else {
-            fprintf(logp, "%s - %s: %s\n", date_fmt, other, msg);
+            if (strncmp(msg, "/me ", 4) == 0) {
+                fprintf(logp, "%s - *me %s\n", date_fmt, msg + 4);
+            } else {
+                fprintf(logp, "%s - me: %s\n", date_fmt, msg);
+            }
         }
-    } else {
-        if (strncmp(msg, "/me ", 4) == 0) {
-            fprintf(logp, "%s - *me %s\n", date_fmt, msg + 4);
-        } else {
-            fprintf(logp, "%s - me: %s\n", date_fmt, msg);
+        fflush(logp);
+        int result = fclose(logp);
+        if (result == EOF) {
+            log_error("Error closing file %s, errno = %d", dated_log->filename, errno);
         }
     }
-    fflush(logp);
-    int result = fclose(logp);
-    if (result == EOF) {
-        log_error("Error closing file %s, errno = %d", dated_log->filename, errno);
-    }
 
     g_free(date_fmt);
     g_date_time_unref(dt);
@@ -285,17 +288,18 @@ groupchat_log_chat(const gchar * const login, const gchar * const room,
     gchar *date_fmt = g_date_time_format(dt, "%H:%M:%S");
 
     FILE *logp = fopen(dated_log->filename, "a");
+    if (logp != NULL) {
+        if (strncmp(msg, "/me ", 4) == 0) {
+            fprintf(logp, "%s - *%s %s\n", date_fmt, nick, msg + 4);
+        } else {
+            fprintf(logp, "%s - %s: %s\n", date_fmt, nick, msg);
+        }
 
-    if (strncmp(msg, "/me ", 4) == 0) {
-        fprintf(logp, "%s - *%s %s\n", date_fmt, nick, msg + 4);
-    } else {
-        fprintf(logp, "%s - %s: %s\n", date_fmt, nick, msg);
-    }
-
-    fflush(logp);
-    int result = fclose(logp);
-    if (result == EOF) {
-        log_error("Error closing file %s, errno = %d", dated_log->filename, errno);
+        fflush(logp);
+        int result = fclose(logp);
+        if (result == EOF) {
+            log_error("Error closing file %s, errno = %d", dated_log->filename, errno);
+        }
     }
 
     g_free(date_fmt);