1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Move resource conversions

This commit is contained in:
James Booth 2016-07-24 16:27:39 +01:00
parent ef942bd27a
commit 37742d71b6
6 changed files with 78 additions and 77 deletions

View File

@ -285,7 +285,7 @@ utf8_display_len(const char *const str)
} }
char* char*
prof_getline(FILE *stream) file_getline(FILE *stream)
{ {
char *buf; char *buf;
char *result; 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* char*
create_unique_id(char *prefix) create_unique_id(char *prefix)
{ {

View File

@ -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); int str_contains(const char str[], int size, char ch);
gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg); gboolean strtoi_range(char *str, int *saveptr, int min, int max, char **err_msg);
int utf8_display_len(const char *const str); int utf8_display_len(const char *const str);
char* prof_getline(FILE *stream); char* file_getline(FILE *stream);
char* release_get_latest(void); char* release_get_latest(void);
gboolean release_is_new(char *found_version); 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* p_sha1_hash(char *str);
char* create_unique_id(char *prefix); char* create_unique_id(char *prefix);
void reset_unique_id(void); void reset_unique_id(void);

View File

@ -42,6 +42,7 @@
#include "log.h" #include "log.h"
#include "config/account.h" #include "config/account.h"
#include "xmpp/jid.h" #include "xmpp/jid.h"
#include "xmpp/resource.h"
ProfAccount* ProfAccount*
account_new(const gchar *const name, const gchar *const jid, account_new(const gchar *const name, const gchar *const jid,

View File

@ -472,7 +472,7 @@ chat_log_get_previous(const gchar *const login, const gchar *const recipient)
g_string_free(header, FALSE); g_string_free(header, FALSE);
char *line; char *line;
while ((line = prof_getline(logp)) != NULL) { while ((line = file_getline(logp)) != NULL) {
history = g_slist_append(history, line); history = g_slist_append(history, line);
} }

View File

@ -95,3 +95,72 @@ resource_destroy(Resource *resource)
free(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;
}
}

View File

@ -49,4 +49,9 @@ Resource* resource_new(const char *const name, resource_presence_t presence, con
void resource_destroy(Resource *resource); void resource_destroy(Resource *resource);
int resource_compare_availability(Resource *first, Resource *second); 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 #endif