about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--jabber.c16
-rw-r--r--log.c7
-rw-r--r--log.h6
-rw-r--r--profanity.c10
-rw-r--r--windows.c9
-rw-r--r--windows.h1
6 files changed, 29 insertions, 20 deletions
diff --git a/jabber.c b/jabber.c
index 3c6746ed..331ab6c5 100644
--- a/jabber.c
+++ b/jabber.c
@@ -12,24 +12,18 @@ extern WINDOW *main_win;
 int in_message_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     void * const userdata)
 {
-    char *intext;
+    char *message;
 
     if(!xmpp_stanza_get_child_by_name(stanza, "body"))
         return 1;
     if(!strcmp(xmpp_stanza_get_attribute(stanza, "type"), "error"))
         return 1;
 
-    intext = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
+    message = xmpp_stanza_get_text(xmpp_stanza_get_child_by_name(stanza, "body"));
 
-    char in_line[200];
     char *from = xmpp_stanza_get_attribute(stanza, "from");
-
     char *short_from = strtok(from, "@");
-
-    sprintf(in_line, "%s: %s\n", short_from, intext);
-
-    wprintw(main_win, in_line);
-    wrefresh(main_win);
+    show_incomming_msg(short_from, message);
 
     return 1;
 }
@@ -42,7 +36,7 @@ void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
 
     if (status == XMPP_CONN_CONNECT) {
         xmpp_stanza_t* pres;
-        fprintf(logp, "DEBUG: connected\n");
+        logmsg(CONN, "connected");
         xmpp_handler_add(conn,in_message_handler, NULL, "message", NULL, ctx);
 
         pres = xmpp_stanza_new(ctx);
@@ -51,7 +45,7 @@ void conn_handler(xmpp_conn_t * const conn, const xmpp_conn_event_t status,
         xmpp_stanza_release(pres);
     }
     else {
-        fprintf(logp, "DEBUG: disconnected\n");
+        logmsg(CONN, "disconnected");
         xmpp_stop(ctx);
     }
 }
diff --git a/log.c b/log.c
index 4447ae3c..2eb49a1d 100644
--- a/log.c
+++ b/log.c
@@ -23,6 +23,11 @@ void xmpp_file_logger(void * const userdata, const xmpp_log_level_t level,
 
 void logmsg(const char * const area, const char * const msg)
 {
-    fprintf(logp, "%s DEBUG %s\n", area, msg);
+    fprintf(logp, "%s DEBUG: %s\n", area, msg);
 }
 
+void start_log(void)
+{
+    logp = fopen("profanity.log", "a");
+    logmsg(PROF, "Starting Profanity...");
+}
diff --git a/log.h b/log.h
index 1a5dad60..bf044b58 100644
--- a/log.h
+++ b/log.h
@@ -1,9 +1,13 @@
 #ifndef LOG_H
 #define LOG_H
 
-FILE *logp;
+#define PROF "prof"
+#define CONN "conn"
+
+FILE *logp; 
 
 xmpp_log_t *xmpp_get_file_logger();
 void logmsg(const char * const area, const char * const msg);
+void start_log(void);
 
 #endif
diff --git a/profanity.c b/profanity.c
index 7725c4ee..d423747f 100644
--- a/profanity.c
+++ b/profanity.c
@@ -9,12 +9,9 @@
 #include "windows.h"
 #include "jabber.h"
 
-// refernce to log
+// reference to log
 extern FILE *logp;
 
-// area for log message in profanity
-static const char *prof = "prof";
-
 // window references
 extern WINDOW *title_bar;
 extern WINDOW *cmd_bar;
@@ -32,8 +29,7 @@ int main(void)
     xmpp_conn_t *conn;
     xmpp_log_t *log;
 
-    logp = fopen("profanity.log", "a");
-    logmsg(prof, "Starting Profanity...");
+    start_log();
 
     // initialise curses, and create windows
     initgui();
@@ -70,7 +66,7 @@ int main(void)
 
             char loginmsg[100];
             sprintf(loginmsg, "User <%s> logged in", user);
-            logmsg(prof, loginmsg);
+            logmsg(PROF, loginmsg);
            
             xmpp_initialize();
             
diff --git a/windows.c b/windows.c
index a34c2ee0..9b534d88 100644
--- a/windows.c
+++ b/windows.c
@@ -80,3 +80,12 @@ static void create_main_window(void)
     main_win = newwin(rows-3, cols, 1, 0);
     scrollok(main_win, TRUE);
 }
+
+void show_incomming_msg(char *from, char *message) 
+{
+    char line[100];
+    sprintf(line, "%s: %s\n", from, message);
+
+    wprintw(main_win, line);
+    wrefresh(main_win);
+}
diff --git a/windows.h b/windows.h
index 62285f22..546f5b90 100644
--- a/windows.h
+++ b/windows.h
@@ -9,5 +9,6 @@ WINDOW *main_win;
 
 // window creation
 void initgui(void);
+void show_incomming_msg(char *from, char *message);
 
 #endif