Allow to set friend channel.
[cascardo/sgp.git] / src / friend.c
index db5c457..3047a13 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;
 }
 
 /*
@@ -44,3 +64,9 @@ struct sgp_channel * sgp_friend_get_channel(struct sgp_friend *friend)
         */
        return friend->channel;
 }
+
+void sgp_friend_set_channel(struct sgp_friend *friend,
+                               struct sgp_channel *channel)
+{
+       friend->channel = channel;
+}