about summary refs log tree commit diff stats
path: root/src/resource.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/resource.c')
-rw-r--r--src/resource.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/resource.c b/src/resource.c
index 3ec664ec..0a7838f3 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -49,6 +49,36 @@ Resource * resource_new(const char * const name, resource_presence_t presence,
     return new_resource;
 }
 
+int
+resource_compare_availability(Resource *first, Resource *second)
+{
+    if (first->priority > second->priority) {
+        return -1;
+    } else if (first->priority < second->priority) {
+        return 1;
+    } else { // priorities equal
+        if (first->presence == RESOURCE_CHAT) {
+            return -1;
+        } else if (second->presence == RESOURCE_CHAT) {
+            return 1;
+        } else if (first->presence == RESOURCE_ONLINE) {
+            return -1;
+        } else if (second->presence == RESOURCE_ONLINE) {
+            return 1;
+        } else if (first->presence == RESOURCE_AWAY) {
+            return -1;
+        } else if (second->presence == RESOURCE_AWAY) {
+            return 1;
+        } else if (first->presence == RESOURCE_XA) {
+            return -1;
+        } else if (second->presence == RESOURCE_XA) {
+            return 1;
+        } else {
+            return -1;
+        }
+    }
+}
+
 void resource_destroy(Resource *resource)
 {
     assert(resource != NULL);