Mercurial > pidgin
view src/protocols/msn/user.c @ 5309:e2e53316a21d
[gaim-migrate @ 5681]
Announcing the new MSN prpl! It probably has some bugs, and for the time
being, there is no file transfer. That's good though, because the current
MSN file transfer is a little broken. I've had many corrupted files. I'll
commit new file transfer code when it's written.
I want this heavily tested before 0.63! If you use MSN, please talk to
people on it. Let me know of any oddities, crashes, bugs, whatever. I'll
fix things as I find them.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Tue, 06 May 2003 02:06:56 +0000 |
parents | |
children | d5690ed70085 |
line wrap: on
line source
/** * @file user.c User functions * * gaim * * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "msn.h" #include "user.h" MsnUser * msn_user_new(MsnSession *session, const char *passport, const char *name) { MsnUser *user; user = msn_users_find_with_passport(session->users, passport); if (user != NULL) { if (name != NULL) msn_user_set_name(user, name); msn_user_ref(user); return user; } user = g_new0(MsnUser, 1); user->session = session; if (name != NULL) msn_user_set_name(user, name); msn_user_set_passport(user, passport); msn_user_set_group_id(user, -1); msn_users_add(session->users, user); msn_user_ref(user); return user; } void msn_user_destroy(MsnUser *user) { g_return_if_fail(user != NULL); if (user->ref_count > 0) { msn_user_unref(user); return; } if (user->session != NULL && user->session->users != NULL) msn_users_remove(user->session->users, user); if (user->passport != NULL) g_free(user->passport); if (user->name != NULL) g_free(user->name); g_free(user); } MsnUser * msn_user_ref(MsnUser *user) { g_return_val_if_fail(user != NULL, NULL); user->ref_count++; return user; } MsnUser * msn_user_unref(MsnUser *user) { g_return_val_if_fail(user != NULL, NULL); if (user->ref_count <= 0) return NULL; user->ref_count--; if (user->ref_count == 0) { msn_user_destroy(user); return NULL; } return user; } void msn_user_set_passport(MsnUser *user, const char *passport) { g_return_if_fail(user != NULL); if (user->passport != NULL) g_free(user->passport); user->passport = g_strdup(passport); } void msn_user_set_name(MsnUser *user, const char *name) { g_return_if_fail(user != NULL); if (user->name != NULL) g_free(user->name); user->name = g_strdup(name); } void msn_user_set_group_id(MsnUser *user, int id) { g_return_if_fail(user != NULL); user->group_id = id; } const char * msn_user_get_passport(const MsnUser *user) { g_return_val_if_fail(user != NULL, NULL); return user->passport; } const char * msn_user_get_name(const MsnUser *user) { g_return_val_if_fail(user != NULL, NULL); return user->name; } int msn_user_get_group_id(const MsnUser *user) { g_return_val_if_fail(user != NULL, -1); return user->group_id; } MsnUsers * msn_users_new(void) { MsnUsers *users = g_new0(MsnUsers, 1); return users; } void msn_users_destroy(MsnUsers *users) { g_return_if_fail(users != NULL); while (users->users != NULL) msn_user_destroy(users->users->data); /* See if we've leaked anybody. */ while (users->users != NULL) { gaim_debug(GAIM_DEBUG_WARNING, "msn", "Leaking user %s\n", msn_user_get_passport(users->users->data)); } g_free(users); } void msn_users_add(MsnUsers *users, MsnUser *user) { g_return_if_fail(users != NULL); g_return_if_fail(user != NULL); users->users = g_list_append(users->users, user); } void msn_users_remove(MsnUsers *users, MsnUser *user) { g_return_if_fail(users != NULL); g_return_if_fail(user != NULL); users->users = g_list_remove(users->users, user); } MsnUser * msn_users_find_with_passport(MsnUsers *users, const char *passport) { GList *l; g_return_val_if_fail(users != NULL, NULL); g_return_val_if_fail(passport != NULL, NULL); for (l = users->users; l != NULL; l = l->next) { MsnUser *user = (MsnUser *)l->data; if (user->passport != NULL && !g_ascii_strcasecmp(passport, user->passport)) { return user; } } return NULL; }