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

Use null check convention in contact.c

This commit is contained in:
James Booth 2015-05-04 23:26:57 +01:00
parent 1d002e5bdc
commit 1bfaa49fb3

View File

@ -63,7 +63,7 @@ p_contact_new(const char * const barejid, const char * const name,
PContact contact = malloc(sizeof(struct p_contact_t)); PContact contact = malloc(sizeof(struct p_contact_t));
contact->barejid = strdup(barejid); contact->barejid = strdup(barejid);
if (name != NULL) { if (name) {
contact->name = strdup(name); contact->name = strdup(name);
} else { } else {
contact->name = NULL; contact->name = NULL;
@ -71,12 +71,12 @@ p_contact_new(const char * const barejid, const char * const name,
contact->groups = groups; contact->groups = groups;
if (subscription != NULL) if (subscription)
contact->subscription = strdup(subscription); contact->subscription = strdup(subscription);
else else
contact->subscription = strdup("none"); contact->subscription = strdup("none");
if (offline_message != NULL) if (offline_message)
contact->offline_message = strdup(offline_message); contact->offline_message = strdup(offline_message);
else else
contact->offline_message = NULL; contact->offline_message = NULL;
@ -96,7 +96,7 @@ void
p_contact_set_name(const PContact contact, const char * const name) p_contact_set_name(const PContact contact, const char * const name)
{ {
FREE_SET_NULL(contact->name); FREE_SET_NULL(contact->name);
if (name != NULL) { if (name) {
contact->name = strdup(name); contact->name = strdup(name);
} }
} }
@ -104,7 +104,7 @@ p_contact_set_name(const PContact contact, const char * const name)
void void
p_contact_set_groups(const PContact contact, GSList *groups) p_contact_set_groups(const PContact contact, GSList *groups)
{ {
if (contact->groups != NULL) { if (contact->groups) {
g_slist_free_full(contact->groups, g_free); g_slist_free_full(contact->groups, g_free);
contact->groups = NULL; contact->groups = NULL;
} }
@ -116,7 +116,7 @@ gboolean
p_contact_in_group(const PContact contact, const char * const group) p_contact_in_group(const PContact contact, const char * const group)
{ {
GSList *groups = contact->groups; GSList *groups = contact->groups;
while (groups != NULL) { while (groups) {
if (strcmp(groups->data, group) == 0) { if (strcmp(groups->data, group) == 0) {
return TRUE; return TRUE;
} }
@ -144,17 +144,17 @@ p_contact_remove_resource(PContact contact, const char * const resource)
void void
p_contact_free(PContact contact) p_contact_free(PContact contact)
{ {
if (contact != NULL) { if (contact) {
free(contact->barejid); free(contact->barejid);
free(contact->name); free(contact->name);
free(contact->subscription); free(contact->subscription);
free(contact->offline_message); free(contact->offline_message);
if (contact->groups != NULL) { if (contact->groups) {
g_slist_free_full(contact->groups, g_free); g_slist_free_full(contact->groups, g_free);
} }
if (contact->last_activity != NULL) { if (contact->last_activity) {
g_date_time_unref(contact->last_activity); g_date_time_unref(contact->last_activity);
} }
@ -179,7 +179,7 @@ p_contact_name(const PContact contact)
const char * const char *
p_contact_name_or_jid(const PContact contact) p_contact_name_or_jid(const PContact contact)
{ {
if (contact->name != NULL) { if (contact->name) {
return contact->name; return contact->name;
} else { } else {
return contact->barejid; return contact->barejid;
@ -247,7 +247,7 @@ _get_most_available_resource(PContact contact)
Resource *current = curr->data; Resource *current = curr->data;
Resource *highest = current; Resource *highest = current;
curr = g_list_next(curr); curr = g_list_next(curr);
while (curr != NULL) { while (curr) {
current = curr->data; current = curr->data;
// priority is same as current highest, choose presence // priority is same as current highest, choose presence
@ -388,7 +388,7 @@ void
p_contact_set_subscription(const PContact contact, const char * const subscription) p_contact_set_subscription(const PContact contact, const char * const subscription)
{ {
FREE_SET_NULL(contact->subscription); FREE_SET_NULL(contact->subscription);
if (subscription != NULL) { if (subscription) {
contact->subscription = strdup(subscription); contact->subscription = strdup(subscription);
} }
} }
@ -402,12 +402,12 @@ p_contact_set_pending_out(const PContact contact, gboolean pending_out)
void void
p_contact_set_last_activity(const PContact contact, GDateTime *last_activity) p_contact_set_last_activity(const PContact contact, GDateTime *last_activity)
{ {
if (contact->last_activity != NULL) { if (contact->last_activity) {
g_date_time_unref(contact->last_activity); g_date_time_unref(contact->last_activity);
contact->last_activity = NULL; contact->last_activity = NULL;
} }
if (last_activity != NULL) { if (last_activity) {
contact->last_activity = g_date_time_ref(last_activity); contact->last_activity = g_date_time_ref(last_activity);
} }
} }