about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/resource.c69
-rw-r--r--src/xmpp/resource.h5
2 files changed, 74 insertions, 0 deletions
diff --git a/src/xmpp/resource.c b/src/xmpp/resource.c
index 6e6bc5f0..2309883c 100644
--- a/src/xmpp/resource.c
+++ b/src/xmpp/resource.c
@@ -95,3 +95,72 @@ resource_destroy(Resource *resource)
         free(resource);
     }
 }
+
+gboolean
+valid_resource_presence_string(const char *const str)
+{
+    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*
+string_from_resource_presence(resource_presence_t presence)
+{
+    switch(presence)
+    {
+        case RESOURCE_CHAT:
+            return "chat";
+        case RESOURCE_AWAY:
+            return "away";
+        case RESOURCE_XA:
+            return "xa";
+        case RESOURCE_DND:
+            return "dnd";
+        default:
+            return "online";
+    }
+}
+
+resource_presence_t
+resource_presence_from_string(const char *const str)
+{
+    if (str == NULL) {
+        return RESOURCE_ONLINE;
+    } else if (strcmp(str, "online") == 0) {
+        return RESOURCE_ONLINE;
+    } else if (strcmp(str, "chat") == 0) {
+        return RESOURCE_CHAT;
+    } else if (strcmp(str, "away") == 0) {
+        return RESOURCE_AWAY;
+    } else if (strcmp(str, "xa") == 0) {
+        return RESOURCE_XA;
+    } else if (strcmp(str, "dnd") == 0) {
+        return RESOURCE_DND;
+    } else {
+        return RESOURCE_ONLINE;
+    }
+}
+
+contact_presence_t
+contact_presence_from_resource_presence(resource_presence_t resource_presence)
+{
+    switch(resource_presence)
+    {
+        case RESOURCE_CHAT:
+            return CONTACT_CHAT;
+        case RESOURCE_AWAY:
+            return CONTACT_AWAY;
+        case RESOURCE_XA:
+            return CONTACT_XA;
+        case RESOURCE_DND:
+            return CONTACT_DND;
+        default:
+            return CONTACT_ONLINE;
+    }
+}
diff --git a/src/xmpp/resource.h b/src/xmpp/resource.h
index 22681013..ec22569a 100644
--- a/src/xmpp/resource.h
+++ b/src/xmpp/resource.h
@@ -49,4 +49,9 @@ Resource* resource_new(const char *const name, resource_presence_t presence, con
 void resource_destroy(Resource *resource);
 int resource_compare_availability(Resource *first, Resource *second);
 
+gboolean valid_resource_presence_string(const char *const str);
+const char* string_from_resource_presence(resource_presence_t presence);
+resource_presence_t resource_presence_from_string(const char *const str);
+contact_presence_t contact_presence_from_resource_presence(resource_presence_t resource_presence);
+
 #endif