about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-07-24 16:27:39 +0100
committerJames Booth <boothj5@gmail.com>2016-07-24 16:27:39 +0100
commit37742d71b638ba5343af7398842f84b530d11c29 (patch)
tree04fd9eca9b2aa6afa673c4efc3afd1608533e9e5
parentef942bd27a759b3016c473abba8066a8ddcb6ffe (diff)
downloadprofani-tty-37742d71b638ba5343af7398842f84b530d11c29.tar.gz
Move resource conversions
-rw-r--r--src/common.c71
-rw-r--r--src/common.h7
-rw-r--r--src/config/account.c1
-rw-r--r--src/log.c2
-rw-r--r--src/xmpp/resource.c69
-rw-r--r--src/xmpp/resource.h5
6 files changed, 78 insertions, 77 deletions
diff --git a/src/common.c b/src/common.c
index 98466231..035a0505 100644
--- a/src/common.c
+++ b/src/common.c
@@ -285,7 +285,7 @@ utf8_display_len(const char *const str)
 }
 
 char*
-prof_getline(FILE *stream)
+file_getline(FILE *stream)
 {
     char *buf;
     char *result;
@@ -380,75 +380,6 @@ release_is_new(char *found_version)
     }
 }
 
-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;
-    }
-}
-
 char*
 create_unique_id(char *prefix)
 {
diff --git a/src/common.h b/src/common.h
index 678a12ff..9d8c99a7 100644
--- a/src/common.h
+++ b/src/common.h
@@ -107,15 +107,10 @@ char* str_replace(const char *string, const char *substr, const char *replacemen
 int str_contains(const char str[], int size, char ch);
 gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg);
 int utf8_display_len(const char *const str);
-char* prof_getline(FILE *stream);
+char* file_getline(FILE *stream);
 char* release_get_latest(void);
 gboolean release_is_new(char *found_version);
 
-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);
-
 char* p_sha1_hash(char *str);
 char* create_unique_id(char *prefix);
 void reset_unique_id(void);
diff --git a/src/config/account.c b/src/config/account.c
index 879759f5..3e8c8cf1 100644
--- a/src/config/account.c
+++ b/src/config/account.c
@@ -42,6 +42,7 @@
 #include "log.h"
 #include "config/account.h"
 #include "xmpp/jid.h"
+#include "xmpp/resource.h"
 
 ProfAccount*
 account_new(const gchar *const name, const gchar *const jid,
diff --git a/src/log.c b/src/log.c
index e0a50055..7fcef45f 100644
--- a/src/log.c
+++ b/src/log.c
@@ -472,7 +472,7 @@ chat_log_get_previous(const gchar *const login, const gchar *const recipient)
             g_string_free(header, FALSE);
 
             char *line;
-            while ((line = prof_getline(logp)) != NULL) {
+            while ((line = file_getline(logp)) != NULL) {
                 history = g_slist_append(history, line);
             }
 
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