Really set the friend alias.
authorThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Wed, 17 Jul 2013 21:47:23 +0000 (18:47 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@cascardo.info>
Wed, 17 Jul 2013 21:47:23 +0000 (18:47 -0300)
Set the friend alias, make it more robust to fail to create a friend and
allow it to be destroyed.

include/sgp/friend.h
src/friend.c

index 7087f48..91965f9 100644 (file)
@@ -24,6 +24,8 @@
 struct sgp_friend;
 
 struct sgp_friend * sgp_friend_new(char *);
+void sgp_friend_destroy(struct sgp_friend *);
+char * sgp_friend_get_alias(struct sgp_friend *);
 
 struct sgp_channel * sgp_friend_get_channel(struct sgp_friend *);
 
index db5c457..a8c1fc6 100644 (file)
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 
 struct sgp_friend {
+       char *alias;
        struct sgp_channel *channel;
 };
 
@@ -28,8 +29,27 @@ struct sgp_friend * sgp_friend_new(char *alias)
 {
        struct sgp_friend *friend;
        friend = malloc(sizeof(*friend));
+       if (!friend)
+               return NULL;
+       friend->alias = strdup(alias);
+       if (!friend->alias)
+               goto out;
        friend->channel = NULL;
        return friend;
+out:
+       free(friend);
+       return NULL;
+}
+
+void sgp_friend_destroy(struct sgp_friend *friend)
+{
+       free(friend->alias);
+       free(friend);
+}
+
+char * sgp_friend_get_alias(struct sgp_friend *friend)
+{
+       return friend->alias;
 }
 
 /*