annotate src/protocols/msn/state.c @ 12949:9a5b9680aaeb

[gaim-migrate @ 15302] SF Patch #1406080 from Sadrul "Gaim leaks when you are away on AIM without any away message and autoreply is enabled for `When Away'. This patch fixes that. It also updates the timestamp for last-sent autoreply only when the autoreply was actually sent." It also removes some duplicated code. I tweaked a couple other things in the function to narrow variable scope a little more. It looked good and even compiled. What more can you ask for? committer: Tailor Script <tailor@pidgin.im>
author Richard Laager <rlaager@wiktel.com>
date Thu, 19 Jan 2006 07:36:38 +0000
parents c824e39db0e7
children 23258253c7a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5361
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
1 /**
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
2 * @file state.c State functions and definitions
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
3 *
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
4 * gaim
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
5 *
9198
ab6636c5a136 [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
6 * Gaim is the legal property of its developers, whose names are too numerous
ab6636c5a136 [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
ab6636c5a136 [gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents: 9193
diff changeset
8 * source distribution.
6701
b7e113a59b51 [gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents: 5824
diff changeset
9 *
5361
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
13 * (at your option) any later version.
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
14 *
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
18 * GNU General Public License for more details.
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
19 *
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
23 */
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
24 #include "msn.h"
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
25 #include "state.h"
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
26
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
27 static const char *away_text[] =
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
28 {
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
29 N_("Available"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
30 N_("Available"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
31 N_("Busy"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
32 N_("Idle"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
33 N_("Be Right Back"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
34 N_("Away From Computer"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
35 N_("On The Phone"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
36 N_("Out To Lunch"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
37 N_("Available"),
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
38 N_("Available")
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
39 };
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
40
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
41 void
11992
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
42 msn_change_status(MsnSession *session)
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
43 {
11992
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
44 GaimAccount *account = session->account;
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
45 MsnCmdProc *cmdproc;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
46 MsnUser *user;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
47 MsnObject *msnobj;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
48 const char *state_text;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
49
10481
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9262
diff changeset
50 g_return_if_fail(session != NULL);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9262
diff changeset
51 g_return_if_fail(session->notification != NULL);
bcfea6c3d5c9 [gaim-migrate @ 11769]
Stu Tomlinson <stu@nosnilmot.com>
parents: 9262
diff changeset
52
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
53 cmdproc = session->notification->cmdproc;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
54 user = session->user;
11992
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
55 state_text = msn_state_get_text(msn_state_from_account(account));
10908
0317ad172e8d [gaim-migrate @ 12640]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
56
0317ad172e8d [gaim-migrate @ 12640]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
57 /* If we're not logged in yet, don't send the status to the server,
0317ad172e8d [gaim-migrate @ 12640]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
58 * it will be sent when login completes
0317ad172e8d [gaim-migrate @ 12640]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
59 */
0317ad172e8d [gaim-migrate @ 12640]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
60 if (!session->logged_in)
0317ad172e8d [gaim-migrate @ 12640]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10481
diff changeset
61 return;
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
62
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
63 msnobj = msn_user_get_object(user);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
64
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
65 if (msnobj == NULL)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
66 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
67 msn_cmdproc_send(cmdproc, "CHG", "%s %d", state_text,
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
68 MSN_CLIENT_ID);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
69 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
70 else
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
71 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
72 char *msnobj_str;
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
73
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
74 msnobj_str = msn_object_to_string(msnobj);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
75
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
76 msn_cmdproc_send(cmdproc, "CHG", "%s %d %s", state_text,
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
77 MSN_CLIENT_ID, gaim_url_encode(msnobj_str));
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
78
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
79 g_free(msnobj_str);
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
80 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
81 }
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
82
5361
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
83 const char *
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
84 msn_away_get_text(MsnAwayType type)
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
85 {
7631
ea2d07ad05a9 [gaim-migrate @ 8255]
Nathan Walp <nwalp@pidgin.im>
parents: 6701
diff changeset
86 g_return_val_if_fail(type <= MSN_HIDDEN, NULL);
5361
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
87
5824
c93884a14866 [gaim-migrate @ 6254]
Luke Schierer <lschiere@pidgin.im>
parents: 5361
diff changeset
88 return _(away_text[type]);
5361
953aa05279f4 [gaim-migrate @ 5737]
Christian Hammond <chipx86@chipx86.com>
parents:
diff changeset
89 }
9193
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
90
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
91 const char *
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
92 msn_state_get_text(MsnAwayType state)
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
93 {
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
94 static char *status_text[] =
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
95 { "NLN", "NLN", "BSY", "IDL", "BRB", "AWY", "PHN", "LUN", "HDN", "HDN" };
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
96
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
97 return status_text[state];
502707ca1836 [gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents: 8475
diff changeset
98 }
11992
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
99
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
100 MsnAwayType
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
101 msn_state_from_account(GaimAccount *account)
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
102 {
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
103 MsnAwayType msnstatus;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
104 GaimPresence *presence;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
105 GaimStatus *status;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
106 const char *status_id;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
107
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
108 presence = gaim_account_get_presence(account);
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
109 status = gaim_presence_get_active_status(presence);
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
110 status_id = gaim_status_get_id(status);
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
111
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
112 if (!strcmp(status_id, "away"))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
113 msnstatus = MSN_AWAY;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
114 else if (!strcmp(status_id, "brb"))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
115 msnstatus = MSN_BRB;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
116 else if (!strcmp(status_id, "busy"))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
117 msnstatus = MSN_BUSY;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
118 else if (!strcmp(status_id, "phone"))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
119 msnstatus = MSN_PHONE;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
120 else if (!strcmp(status_id, "lunch"))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
121 msnstatus = MSN_LUNCH;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
122 else if (!strcmp(status_id, "invisible"))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
123 msnstatus = MSN_HIDDEN;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
124 else
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
125 msnstatus = MSN_ONLINE;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
126
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
127 if ((msnstatus == MSN_ONLINE) && gaim_presence_is_idle(presence))
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
128 msnstatus = MSN_IDLE;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
129
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
130 return msnstatus;
c824e39db0e7 [gaim-migrate @ 14285]
Stu Tomlinson <stu@nosnilmot.com>
parents: 10908
diff changeset
131 }