Mercurial > pidgin
diff libpurple/protocols/null/nullprpl.c @ 25871:65cfc59858cf
propagate from branch 'im.pidgin.pidgin' (head d5bb29138cbe033bbfd8ec689203d73818765327)
to branch 'im.pidgin.pidgin.next.minor' (head 35ee8e40db640867e5b9239030cdc326e7f0a005)
| author | Gary Kramlich <grim@reaperworld.com> |
|---|---|
| date | Sat, 13 Dec 2008 05:45:27 +0000 |
| parents | 0edd1e140b6e c687fd9c379e |
| children | 2d4f0dd04334 |
line wrap: on
line diff
--- a/libpurple/protocols/null/nullprpl.c Wed Dec 03 01:58:45 2008 +0000 +++ b/libpurple/protocols/null/nullprpl.c Sat Dec 13 05:45:27 2008 +0000 @@ -160,8 +160,8 @@ static void discover_status(PurpleConnection *from, PurpleConnection *to, gpointer userdata) { - char *from_username = from->account->username; - char *to_username = to->account->username; + const char *from_username = from->account->username; + const char *to_username = to->account->username; if (purple_find_buddy(from->account, to_username)) { PurpleStatus *status = purple_account_get_active_status(to->account); @@ -244,7 +244,7 @@ } else { purple_debug_info("nullprpl", "...but %s is not logged in\n", buddy->name); - return "Not logged in"; + return g_strdup("Not logged in"); } } @@ -257,9 +257,10 @@ /* they're logged in */ PurplePresence *presence = purple_buddy_get_presence(buddy); PurpleStatus *status = purple_presence_get_active_status(presence); - const char *msg = nullprpl_status_text(buddy); + char *msg = nullprpl_status_text(buddy); purple_notify_user_info_add_pair(info, purple_status_get_name(status), msg); + g_free(msg); if (full) { const char *user_info = purple_account_get_user_info(gc->account); @@ -271,7 +272,7 @@ /* they're not logged in */ purple_notify_user_info_add_pair(info, _("User info"), _("not logged in")); } - + purple_debug_info("nullprpl", "showing %s tooltip for %s\n", (full) ? "full" : "short", buddy->name); } @@ -289,21 +290,21 @@ NULL, TRUE); purple_status_type_add_attr(type, "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING)); - types = g_list_append(types, type); + types = g_list_prepend(types, type); type = purple_status_type_new(PURPLE_STATUS_AWAY, NULL_STATUS_AWAY, NULL, TRUE); purple_status_type_add_attr(type, "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING)); - types = g_list_append(types, type); + types = g_list_prepend(types, type); type = purple_status_type_new(PURPLE_STATUS_OFFLINE, NULL_STATUS_OFFLINE, NULL, TRUE); purple_status_type_add_attr(type, "message", _("Message"), purple_value_new(PURPLE_TYPE_STRING)); - types = g_list_append(types, type); + types = g_list_prepend(types, type); - return types; + return g_list_reverse(types); } static void blist_example_menu_item(PurpleBlistNode *node, gpointer userdata) { @@ -337,7 +338,7 @@ purple_debug_info("nullprpl", "returning chat setting 'room'\n"); pce = g_new0(struct proto_chat_entry, 1); - pce->label = _(_("Chat _room")); + pce->label = _("Chat _room"); pce->identifier = "room"; pce->required = TRUE; @@ -459,7 +460,7 @@ gc->account->username, info); } -static char *typing_state_to_string(PurpleTypingState typing) { +static const char *typing_state_to_string(PurpleTypingState typing) { switch (typing) { case PURPLE_NOT_TYPING: return "is not typing"; case PURPLE_TYPING: return "is typing"; @@ -470,8 +471,8 @@ static void notify_typing(PurpleConnection *from, PurpleConnection *to, gpointer typing) { - char *from_username = from->account->username; - char *action = typing_state_to_string((PurpleTypingState)typing); + const char *from_username = from->account->username; + const char *action = typing_state_to_string((PurpleTypingState)typing); purple_debug_info("nullprpl", "notifying %s that %s %s\n", to->account->username, from_username, action); @@ -543,7 +544,7 @@ static void nullprpl_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) { - char *username = gc->account->username; + const char *username = gc->account->username; PurpleConnection *buddy_gc = get_nullprpl_gc(buddy->name); purple_debug_info("nullprpl", "adding %s to %s's buddy list\n", buddy->name, @@ -661,8 +662,8 @@ } static void nullprpl_join_chat(PurpleConnection *gc, GHashTable *components) { - char *username = gc->account->username; - char *room = g_hash_table_lookup(components, "room"); + const char *username = gc->account->username; + const char *room = g_hash_table_lookup(components, "room"); int chat_id = g_str_hash(room); purple_debug_info("nullprpl", "%s is joining chat room %s\n", username, room); @@ -672,20 +673,20 @@ /* tell everyone that we joined, and add them if they're already there */ foreach_gc_in_chat(joined_chat, gc, chat_id, NULL); } else { + char *tmp = g_strdup_printf(_("%s is already in chat room %s."), + username, + room); purple_debug_info("nullprpl", "%s is already in chat room %s\n", username, room); - purple_notify_info(gc, - _("Join chat"), - _("Join chat"), - g_strdup_printf("%s is already in chat room %s.", - username, room)); + purple_notify_info(gc, _("Join chat"), _("Join chat"), tmp); + g_free(tmp); } } static void nullprpl_reject_chat(PurpleConnection *gc, GHashTable *components) { - char *invited_by = g_hash_table_lookup(components, "invited_by"); - char *room = g_hash_table_lookup(components, "room"); - char *username = gc->account->username; + const char *invited_by = g_hash_table_lookup(components, "invited_by"); + const char *room = g_hash_table_lookup(components, "room"); + const char *username = gc->account->username; PurpleConnection *invited_by_gc = get_nullprpl_gc(invited_by); char *message = g_strdup_printf( "%s %s %s.", @@ -701,19 +702,20 @@ _("Chat invitation rejected"), _("Chat invitation rejected"), message); + g_free(message); } static char *nullprpl_get_chat_name(GHashTable *components) { - char *room = g_hash_table_lookup(components, "room"); + const char *room = g_hash_table_lookup(components, "room"); purple_debug_info("nullprpl", "reporting chat room name '%s'\n", room); - return room; + return g_strdup(room); } static void nullprpl_chat_invite(PurpleConnection *gc, int id, const char *message, const char *who) { - char *username = gc->account->username; + const char *username = gc->account->username; PurpleConversation *conv = purple_find_chat(gc, id); - char *room = conv->name; + const char *room = conv->name; PurpleAccount *to_acct = purple_accounts_find(who, NULLPRPL_ID); purple_debug_info("nullprpl", "%s is inviting %s to join chat room %s\n", @@ -722,18 +724,16 @@ if (to_acct) { PurpleConversation *to_conv = purple_find_chat(to_acct->gc, id); if (to_conv) { + char *tmp = g_strdup_printf("%s is already in chat room %s.", who, room); purple_debug_info("nullprpl", "%s is already in chat room %s; " "ignoring invitation from %s\n", who, room, username); - purple_notify_info(gc, - _("Chat invitation"), - _("Chat invitation"), - g_strdup_printf("%s is already in chat room %s.", - who, room)); + purple_notify_info(gc, _("Chat invitation"), _("Chat invitation"), tmp); + g_free(tmp); } else { GHashTable *components; - components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, free); + components = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, g_free); g_hash_table_replace(components, "room", g_strdup(room)); g_hash_table_replace(components, "invited_by", g_strdup(username)); serv_got_chat_invite(to_acct->gc, room, username, message, components); @@ -815,7 +815,7 @@ static void nullprpl_chat_whisper(PurpleConnection *gc, int id, const char *who, const char *message) { - char *username = gc->account->username; + const char *username = gc->account->username; PurpleConversation *conv = purple_find_chat(gc, id); purple_debug_info("nullprpl", "%s receives whisper from %s in chat room %s: %s\n", @@ -840,7 +840,7 @@ static int nullprpl_chat_send(PurpleConnection *gc, int id, const char *message, PurpleMessageFlags flags) { - char *username = gc->account->username; + const char *username = gc->account->username; PurpleConversation *conv = purple_find_chat(gc, id); if (conv) { @@ -963,7 +963,7 @@ } static PurpleRoomlist *nullprpl_roomlist_get_list(PurpleConnection *gc) { - char *username = gc->account->username; + const char *username = gc->account->username; PurpleRoomlist *roomlist = purple_roomlist_new(gc->account); GList *fields = NULL; PurpleRoomlistField *field; @@ -987,14 +987,17 @@ for (chats = purple_get_chats(); chats; chats = g_list_next(chats)) { PurpleConversation *conv = (PurpleConversation *)chats->data; PurpleRoomlistRoom *room; - char *name = conv->name; + const char *name = conv->name; int id = purple_conversation_get_chat_data(conv)->id; /* have we already added this room? */ if (g_list_find_custom(seen_ids, name, (GCompareFunc)strcmp)) continue; /* yes! try the next one. */ - seen_ids = g_list_append(seen_ids, name); /* no, it's new. */ + /* This cast is OK because this list is only staying around for the life + * of this function and none of the conversations are being deleted + * in that timespan. */ + seen_ids = g_list_prepend(seen_ids, (char *)name); /* no, it's new. */ purple_debug_info("nullprpl", "%s (%d), ", name, id); room = purple_roomlist_room_new(PURPLE_ROOMLIST_ROOMTYPE_ROOM, name, NULL); @@ -1003,6 +1006,7 @@ purple_roomlist_room_add(roomlist, room); } + g_list_free(seen_ids); purple_timeout_add(1 /* ms */, nullprpl_finish_get_roomlist, roomlist); return roomlist; }
