1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Use SoftwareVersion in EntityCapabilities

This commit is contained in:
James Booth 2016-08-13 17:43:43 +01:00
parent 0bd5b5200a
commit ed75f1ec71
4 changed files with 137 additions and 125 deletions

View File

@ -579,23 +579,26 @@ cons_show_caps(const char *const fulljid, resource_presence_t presence)
win_newline(console);
}
if (caps->software) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "Software: %s", caps->software);
}
if (caps->software_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if (caps->software || caps->software_version) {
win_newline(console);
}
if (caps->os) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "OS: %s", caps->os);
}
if (caps->os_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if (caps->os || caps->os_version) {
win_newline(console);
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "Software: %s", software_version->software);
}
if (software_version->software_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->software_version);
}
if (software_version->software || software_version->software_version) {
win_newline(console);
}
if (software_version->os) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", "OS: %s", software_version->os);
}
if (software_version->os_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->os_version);
}
if (software_version->os || software_version->os_version) {
win_newline(console);
}
}
if (caps->features) {
@ -1030,24 +1033,28 @@ cons_show_account(ProfAccount *account)
win_newline(console);
}
if (caps->software) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if (caps->software || caps->software_version) {
win_newline(console);
}
if (caps->os) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if (caps->os || caps->os_version) {
win_newline(console);
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", software_version->software);
}
if (software_version->software_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->software_version);
}
if (software_version->software || software_version->software_version) {
win_newline(console);
}
if (software_version->os) {
win_vprint(console, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", software_version->os);
}
if (software_version->os_version) {
win_vprint(console, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->os_version);
}
if (software_version->os || software_version->os_version) {
win_newline(console);
}
}
caps_destroy(caps);
}

View File

@ -786,24 +786,28 @@ win_show_occupant_info(ProfWin *window, const char *const room, Occupant *occupa
win_newline(window);
}
if (caps->software) {
win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version) {
win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if (caps->software || caps->software_version) {
win_newline(window);
}
if (caps->os) {
win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version) {
win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if (caps->os || caps->os_version) {
win_newline(window);
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " Software: %s", software_version->software);
}
if (software_version->software_version) {
win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->software_version);
}
if (software_version->software || software_version->software_version) {
win_newline(window);
}
if (software_version->os) {
win_vprint(window, '!', 0, NULL, NO_EOL, 0, "", " OS: %s", software_version->os);
}
if (software_version->os_version) {
win_vprint(window, '!', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->os_version);
}
if (software_version->os || software_version->os_version) {
win_newline(window);
}
}
caps_destroy(caps);
}
@ -906,24 +910,28 @@ win_show_info(ProfWin *window, PContact contact)
win_newline(window);
}
if (caps->software) {
win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", caps->software);
}
if (caps->software_version) {
win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->software_version);
}
if (caps->software || caps->software_version) {
win_newline(window);
}
if (caps->os) {
win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", caps->os);
}
if (caps->os_version) {
win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", caps->os_version);
}
if (caps->os || caps->os_version) {
win_newline(window);
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " Software: %s", software_version->software);
}
if (software_version->software_version) {
win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->software_version);
}
if (software_version->software || software_version->software_version) {
win_newline(window);
}
if (software_version->os) {
win_vprint(window, '-', 0, NULL, NO_EOL, 0, "", " OS: %s", software_version->os);
}
if (software_version->os_version) {
win_vprint(window, '-', 0, NULL, NO_DATE | NO_EOL, 0, "", ", %s", software_version->os_version);
}
if (software_version->os || software_version->os_version) {
win_newline(window);
}
}
caps_destroy(caps);
}

View File

@ -130,18 +130,23 @@ caps_add_by_ver(const char *const ver, EntityCapabilities *caps)
g_key_file_set_string(cache, ver, "type", identity->type);
}
}
if (caps->software) {
g_key_file_set_string(cache, ver, "software", caps->software);
}
if (caps->software_version) {
g_key_file_set_string(cache, ver, "software_version", caps->software_version);
}
if (caps->os) {
g_key_file_set_string(cache, ver, "os", caps->os);
}
if (caps->os_version) {
g_key_file_set_string(cache, ver, "os_version", caps->os_version);
SoftwareVersion *software_version = caps->software_version;
if (software_version->software) {
g_key_file_set_string(cache, ver, "software", software_version->software);
}
if (software_version->software_version) {
g_key_file_set_string(cache, ver, "software_version", software_version->software_version);
}
if (software_version->os) {
g_key_file_set_string(cache, ver, "os", software_version->os);
}
if (software_version->os_version) {
g_key_file_set_string(cache, ver, "os_version", software_version->os_version);
}
}
if (caps->features) {
GSList *curr_feature = caps->features;
int num = g_slist_length(caps->features);
@ -195,33 +200,20 @@ _caps_by_ver(const char *const ver)
}
char *software = g_key_file_get_string(cache, ver, "software", NULL);
if (software) {
new_caps->software = software;
} else {
new_caps->software = NULL;
}
char *software_version = g_key_file_get_string(cache, ver, "software_version", NULL);
if (software_version) {
new_caps->software_version = software_version;
char *os = g_key_file_get_string(cache, ver, "os", NULL);
char *os_version = g_key_file_get_string(cache, ver, "os_version", NULL);
if (software || software_version || os || os_version) {
SoftwareVersion *software_versionp = malloc(sizeof(struct software_version_t));
software_versionp->software = software;
software_versionp->software_version = software_version;
software_versionp->os = os;
software_versionp->os_version = os_version;
new_caps->software_version = software_versionp;
} else {
new_caps->software_version = NULL;
}
char *os = g_key_file_get_string(cache, ver, "os", NULL);
if (os) {
new_caps->os = os;
} else {
new_caps->os = NULL;
}
char *os_version = g_key_file_get_string(cache, ver, "os_version", NULL);
if (os_version) {
new_caps->os_version = os_version;
} else {
new_caps->os_version = NULL;
}
gsize features_len = 0;
gchar **features = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
if (features && features_len > 0) {
@ -287,10 +279,15 @@ _caps_copy(EntityCapabilities *caps)
result->identity = NULL;
}
result->software = caps->software ? strdup(caps->software) : NULL;
result->software_version = caps->software_version ? strdup(caps->software_version) : NULL;
result->os = caps->os ? strdup(caps->os) : NULL;
result->os_version = caps->os_version ? strdup(caps->os_version) : NULL;
if (caps->software_version) {
SoftwareVersion *software_version = (SoftwareVersion*)malloc(sizeof(SoftwareVersion));
software_version->software = caps->software_version->software ? strdup(caps->software_version->software) : NULL;
software_version->software_version = caps->software_version->software_version ? strdup(caps->software_version->software_version) : NULL;
software_version->os = caps->software_version->os ? strdup(caps->software_version->os) : NULL;
software_version->os_version = caps->software_version->os_version ? strdup(caps->software_version->os_version) : NULL;
} else {
result->software_version = NULL;
}
result->features = NULL;
GSList *curr = caps->features;
@ -522,26 +519,14 @@ caps_create(xmpp_stanza_t *query)
new_caps->identity = NULL;
}
if (software) {
new_caps->software = software;
} else {
new_caps->software = NULL;
}
if (software_version) {
new_caps->software_version = software_version;
} else {
new_caps->software_version = NULL;
}
if (os) {
new_caps->os = os;
} else {
new_caps->os = NULL;
}
if (os_version) {
new_caps->os_version = os_version;
} else {
new_caps->os_version = NULL;
if (software || software_version || os || os_version) {
SoftwareVersion *software_versionp = malloc(sizeof(struct software_version_t));
software_versionp->software = software;
software_versionp->software_version = software_version;
software_versionp->os = os;
software_versionp->os_version = os_version;
}
if (features) {
new_caps->features = features;
} else {
@ -651,15 +636,23 @@ _disco_identity_destroy(DiscoIdentity *disco_identity)
}
}
static void
_software_version_destroy(SoftwareVersion *software_version)
{
if (software_version) {
free(software_version->software);
free(software_version->software_version);
free(software_version->os);
free(software_version->os_version);
}
}
void
caps_destroy(EntityCapabilities *caps)
{
if (caps) {
_disco_identity_destroy(caps->identity);
free(caps->software);
free(caps->software_version);
free(caps->os);
free(caps->os_version);
_software_version_destroy(caps->software_version);
if (caps->features) {
g_slist_free_full(caps->features, free);
}

View File

@ -88,12 +88,16 @@ typedef struct disco_identity_t {
char *category;
} DiscoIdentity;
typedef struct entity_capabilities_t {
DiscoIdentity *identity;
typedef struct software_version_t {
char *software;
char *software_version;
char *os;
char *os_version;
} SoftwareVersion;
typedef struct entity_capabilities_t {
DiscoIdentity *identity;
SoftwareVersion *software_version;
GSList *features;
} EntityCapabilities;