about summary refs log tree commit diff stats
path: root/src/common.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-10 11:41:30 +0000
committerJames Booth <boothj5@gmail.com>2013-02-10 11:41:30 +0000
commit3bee45fa76a43567146b3733962a1058104a2da2 (patch)
treea229096135ee69d751ec21a56da7641cf944528e /src/common.c
parent591f8a8dbf10b7bd64825cfea63a7ac21b6c89e2 (diff)
downloadprofani-tty-3bee45fa76a43567146b3733962a1058104a2da2.tar.gz
Added presence string functions to common
Diffstat (limited to 'src/common.c')
-rw-r--r--src/common.c56
1 files changed, 49 insertions, 7 deletions
diff --git a/src/common.c b/src/common.c
index dc03201c..f2b0f550 100644
--- a/src/common.c
+++ b/src/common.c
@@ -20,6 +20,7 @@
  *
  */
 
+#include <assert.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -262,19 +263,60 @@ release_get_latest()
 gboolean
 presence_valid_string(const char * const str)
 {
-    if (str == NULL) {
-        return FALSE;
-    } else if ((strcmp(str, "online") == 0) ||
-                (strcmp(str, "chat") == 0) ||
-                (strcmp(str, "away") == 0) ||
-                (strcmp(str, "xa") == 0) ||
-                (strcmp(str, "dnd") == 0)) {
+    assert(str != NULL);
+    if ((strcmp(str, "online") == 0) || (strcmp(str, "chat") == 0) ||
+            (strcmp(str, "away") == 0) || (strcmp(str, "xa") == 0) ||
+            (strcmp(str, "dnd") == 0)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
 
+const char *
+presence_display_string_from_type(presence_t presence)
+{
+    switch (presence)
+    {
+        case PRESENCE_ONLINE:
+            return "online";
+        case PRESENCE_CHAT:
+            return "chat";
+        case PRESENCE_AWAY:
+            return "away";
+        case PRESENCE_XA:
+            return "xa";
+        case PRESENCE_DND:
+            return "dnd";
+        case PRESENCE_OFFLINE:
+            return "offline";
+        default:
+            return NULL;
+    }
+}
+
+const char *
+presence_stanza_show_from_type(presence_t presence)
+{
+    assert(presence != PRESENCE_OFFLINE);
+
+    switch (presence)
+    {
+        case PRESENCE_ONLINE:
+            return NULL;
+        case PRESENCE_CHAT:
+            return "chat";
+        case PRESENCE_AWAY:
+            return "away";
+        case PRESENCE_XA:
+            return "xa";
+        case PRESENCE_DND:
+            return "dnd";
+        default:
+            return NULL;
+    }
+}
+
 gchar *
 xdg_get_config_home(void)
 {