comparison mcabber/src/roster.c @ 548:265c50238a48

Add buddy_{get,set}topic()
author Mikael Berthe <mikael@lilotux.net>
date Sun, 27 Nov 2005 21:26:55 +0100
parents ffdfddd351b8
children 7fc678ac3bc6
comparison
equal deleted inserted replaced
547:1df26ff0ed8c 548:265c50238a48
43 gchar *jid; 43 gchar *jid;
44 guint type; 44 guint type;
45 enum subscr subscription; 45 enum subscr subscription;
46 GSList *resource; 46 GSList *resource;
47 gchar *nickname; // For groupchats 47 gchar *nickname; // For groupchats
48 gchar *topic; // For groupchats
48 guint flags; 49 guint flags;
49 // list: user -> points to his group; group -> points to its users list 50 // list: user -> points to his group; group -> points to its users list
50 GSList *list; 51 GSList *list;
51 } roster; 52 } roster;
52 53
305 306
306 // Let's free memory (jid, name, status message) 307 // Let's free memory (jid, name, status message)
307 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); 308 if (roster_usr->jid) g_free((gchar*)roster_usr->jid);
308 if (roster_usr->name) g_free((gchar*)roster_usr->name); 309 if (roster_usr->name) g_free((gchar*)roster_usr->name);
309 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); 310 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname);
311 if (roster_usr->topic) g_free((gchar*)roster_usr->topic);
310 free_all_resources(&roster_usr->resource); 312 free_all_resources(&roster_usr->resource);
311 g_free(roster_usr); 313 g_free(roster_usr);
312 314
313 // That's a little complex, we need to dereference twice 315 // That's a little complex, we need to dereference twice
314 sl_group = ((roster*)sl_user->data)->list; 316 sl_group = ((roster*)sl_user->data)->list;
343 roster *roster_usr = (roster*)sl_usr->data; 345 roster *roster_usr = (roster*)sl_usr->data;
344 // Free name and jid 346 // Free name and jid
345 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); 347 if (roster_usr->jid) g_free((gchar*)roster_usr->jid);
346 if (roster_usr->name) g_free((gchar*)roster_usr->name); 348 if (roster_usr->name) g_free((gchar*)roster_usr->name);
347 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); 349 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname);
350 if (roster_usr->topic) g_free((gchar*)roster_usr->topic);
348 free_all_resources(&roster_usr->resource); 351 free_all_resources(&roster_usr->resource);
349 g_free(roster_usr); 352 g_free(roster_usr);
350 sl_usr = g_slist_next(sl_usr); 353 sl_usr = g_slist_next(sl_usr);
351 } 354 }
352 // Free group's users list 355 // Free group's users list
715 718
716 roster_clone->resource = roster_usr->resource; 719 roster_clone->resource = roster_usr->resource;
717 roster_usr->resource = NULL; 720 roster_usr->resource = NULL;
718 roster_clone->nickname = roster_usr->nickname; 721 roster_clone->nickname = roster_usr->nickname;
719 roster_usr->nickname = NULL; 722 roster_usr->nickname = NULL;
723 roster_clone->topic = roster_usr->topic;
724 roster_usr->topic = NULL;
720 725
721 // Free old buddy 726 // Free old buddy
722 if (roster_usr->jid) g_free((gchar*)roster_usr->jid); 727 if (roster_usr->jid) g_free((gchar*)roster_usr->jid);
723 if (roster_usr->name) g_free((gchar*)roster_usr->name); 728 if (roster_usr->name) g_free((gchar*)roster_usr->name);
724 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname); 729 if (roster_usr->nickname) g_free((gchar*)roster_usr->nickname);
730 if (roster_usr->topic) g_free((gchar*)roster_usr->topic);
725 free_all_resources(&roster_usr->resource); 731 free_all_resources(&roster_usr->resource);
726 g_free(roster_usr); 732 g_free(roster_usr);
727 733
728 buddylist = g_list_append(buddylist, roster_clone); 734 buddylist = g_list_append(buddylist, roster_clone);
729 // We must have current_buddy pointing to the cloned buddy, if this is 735 // We must have current_buddy pointing to the cloned buddy, if this is
768 { 774 {
769 roster *roster_usr = rosterdata; 775 roster *roster_usr = rosterdata;
770 return roster_usr->name; 776 return roster_usr->name;
771 } 777 }
772 778
779 // buddy_setnickname(buddy, newnickname)
780 // Only for chatrooms
773 void buddy_setnickname(gpointer rosterdata, const char *newname) 781 void buddy_setnickname(gpointer rosterdata, const char *newname)
774 { 782 {
775 roster *roster_usr = rosterdata; 783 roster *roster_usr = rosterdata;
776 784
777 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return; 785 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return;
786 794
787 const char *buddy_getnickname(gpointer rosterdata) 795 const char *buddy_getnickname(gpointer rosterdata)
788 { 796 {
789 roster *roster_usr = rosterdata; 797 roster *roster_usr = rosterdata;
790 return roster_usr->nickname; 798 return roster_usr->nickname;
799 }
800
801 // buddy_settopic(buddy, newtopic)
802 // Only for chatrooms
803 void buddy_settopic(gpointer rosterdata, const char *newtopic)
804 {
805 roster *roster_usr = rosterdata;
806
807 if (!(roster_usr->type & ROSTER_TYPE_ROOM)) return;
808
809 if (roster_usr->topic) {
810 g_free((gchar*)roster_usr->topic);
811 roster_usr->topic = NULL;
812 }
813 if (newtopic)
814 roster_usr->topic = g_strdup(newtopic);
815 }
816
817 const char *buddy_gettopic(gpointer rosterdata)
818 {
819 roster *roster_usr = rosterdata;
820 return roster_usr->topic;
791 } 821 }
792 822
793 // buddy_getgroupname() 823 // buddy_getgroupname()
794 // Returns a pointer on buddy's group name. 824 // Returns a pointer on buddy's group name.
795 const char *buddy_getgroupname(gpointer rosterdata) 825 const char *buddy_getgroupname(gpointer rosterdata)