Mercurial > pidgin
annotate src/protocols/msn/state.c @ 19839:2b36697b05ea
[gaim-migrate @ 17288]
Update the contact update soap request method,
committer: Ethan Blanton <elb@pidgin.im>
| author | Ma Yuan <mayuan2006@gmail.com> |
|---|---|
| date | Sat, 16 Sep 2006 18:27:25 +0000 |
| parents | 0af038b3b7fe |
| children |
| rev | line source |
|---|---|
| 5361 | 1 /** |
| 2 * @file state.c State functions and definitions | |
| 3 * | |
| 4 * gaim | |
| 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 | 10 * This program is free software; you can redistribute it and/or modify |
| 11 * it under the terms of the GNU General Public License as published by | |
| 12 * the Free Software Foundation; either version 2 of the License, or | |
| 13 * (at your option) any later version. | |
| 14 * | |
| 15 * This program is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 * GNU General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU General Public License | |
| 21 * along with this program; if not, write to the Free Software | |
| 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 */ | |
| 24 #include "msn.h" | |
| 25 #include "state.h" | |
| 26 | |
| 27 static const char *away_text[] = | |
| 28 { | |
| 29 N_("Available"), | |
| 30 N_("Available"), | |
| 31 N_("Busy"), | |
| 32 N_("Idle"), | |
| 33 N_("Be Right Back"), | |
| 34 N_("Away From Computer"), | |
| 35 N_("On The Phone"), | |
| 36 N_("Out To Lunch"), | |
| 37 N_("Available"), | |
| 38 N_("Available") | |
| 39 }; | |
| 40 | |
| 19796 | 41 /* Local Function Prototype*/ |
| 42 char * msn_build_psm(char * psmstr,char *mediastr,char * guidstr); | |
| 43 | |
| 44 /* | |
| 45 * WLM media PSM info build prcedure | |
| 46 * | |
| 47 * Result can like: | |
| 48 * <CurrentMedia>\0Music\01\0{0} - {1}\0 Song Title\0Song Artist\0Song Album\0\0</CurrentMedia>\ | |
| 49 * <CurrentMedia>\0Games\01\0Playing {0}\0Game Name\0</CurrentMedia>\ | |
| 50 * <CurrentMedia>\0Office\01\0Office Message\0Office App Name\0</CurrentMedia>" | |
| 51 */ | |
| 19786 | 52 char * |
| 53 msn_build_psm(char * psmstr,char *mediastr,char * guidstr) | |
| 54 { | |
| 55 xmlnode *dataNode,*psmNode,*mediaNode,*guidNode; | |
| 56 char *result; | |
| 57 int length; | |
| 58 | |
| 59 dataNode = xmlnode_new("Data"); | |
| 60 | |
| 61 psmNode = xmlnode_new("PSM"); | |
| 62 if(psmstr != NULL){ | |
| 63 xmlnode_insert_data(psmNode,psmstr,strlen(psmstr)); | |
| 64 } | |
| 65 xmlnode_insert_child(dataNode,psmNode); | |
| 66 | |
| 67 mediaNode = xmlnode_new("CurrentMedia"); | |
| 68 if(mediastr != NULL){ | |
| 69 xmlnode_insert_data(psmNode,mediastr,strlen(mediastr)); | |
| 70 } | |
| 71 xmlnode_insert_child(dataNode,mediaNode); | |
| 72 | |
| 73 guidNode = xmlnode_new("MachineGuid"); | |
| 74 if(guidstr != NULL){ | |
| 75 xmlnode_insert_data(guidNode,guidstr,strlen(guidstr)); | |
| 76 } | |
| 77 xmlnode_insert_child(dataNode,guidNode); | |
| 78 | |
| 79 result = xmlnode_to_str(dataNode,&length); | |
| 80 return result; | |
| 81 } | |
| 82 | |
| 19818 | 83 /*get the PSM info from the XML string*/ |
| 84 const char * | |
| 85 msn_get_psm(char *xml_str,gsize len) | |
| 86 { | |
| 87 xmlnode *payloadNode, *psmNode; | |
| 88 char *psm_str,*psm; | |
| 19819 | 89 |
| 90 gaim_debug_info("Ma Yuan","msn get PSM\n"); | |
| 19818 | 91 payloadNode = xmlnode_from_str(xml_str, len); |
| 92 if (!payloadNode){ | |
| 93 gaim_debug_error("MaYuan","PSM XML parse Error!\n"); | |
| 94 return NULL; | |
| 95 } | |
| 96 psmNode = xmlnode_get_child(payloadNode, "PSM"); | |
| 19819 | 97 if (psmNode == NULL){ |
| 19818 | 98 gaim_debug_info("Ma Yuan","No PSM status Node"); |
| 99 g_free(payloadNode); | |
| 100 return NULL; | |
| 101 } | |
| 102 psm_str = xmlnode_get_data(psmNode); | |
| 103 psm = g_strdup(psm_str); | |
| 104 | |
| 105 g_free(psmNode); | |
| 106 g_free(payloadNode); | |
| 107 | |
| 108 return psm; | |
| 109 } | |
| 110 | |
| 19821 | 111 /* set the MSN's PSM info,Currently Read from the status Line |
| 112 * Thanks for Cris Code | |
| 113 */ | |
| 19786 | 114 void |
| 115 msn_set_psm(MsnSession *session) | |
| 116 { | |
| 19821 | 117 GaimAccount *account = session->account; |
| 118 GaimPresence *presence; | |
| 119 GaimStatus *status; | |
| 19786 | 120 MsnCmdProc *cmdproc; |
| 121 MsnTransaction *trans; | |
| 19821 | 122 char *payload,*statusline; |
| 123 | |
| 124 g_return_if_fail(session != NULL); | |
| 125 g_return_if_fail(session->notification != NULL); | |
| 19786 | 126 |
| 127 cmdproc = session->notification->cmdproc; | |
| 128 /*prepare PSM info*/ | |
| 129 if(session->psm){ | |
| 130 g_free(session->psm); | |
| 131 } | |
| 19821 | 132 /*Get the PSM string from Gaim's Status Line*/ |
| 133 presence = gaim_account_get_presence(account); | |
| 134 status = gaim_presence_get_active_status(presence); | |
| 135 statusline = gaim_status_get_attr_string(status, "message"); | |
| 136 session ->psm = g_strdup(msn_build_psm(statusline,NULL,NULL)); | |
| 19786 | 137 payload = session->psm; |
| 138 | |
| 139 gaim_debug_info("MaYuan","UUX{%s}\n",payload); | |
| 140 trans = msn_transaction_new(cmdproc, "UUX","%d",strlen(payload)); | |
| 141 msn_transaction_set_payload(trans, payload, strlen(payload)); | |
| 142 msn_cmdproc_send_trans(cmdproc, trans); | |
| 143 } | |
| 144 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
145 void |
| 11992 | 146 msn_change_status(MsnSession *session) |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
147 { |
| 11992 | 148 GaimAccount *account = session->account; |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
149 MsnCmdProc *cmdproc; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
150 MsnUser *user; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
151 MsnObject *msnobj; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
152 const char *state_text; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
153 |
| 10481 | 154 g_return_if_fail(session != NULL); |
| 155 g_return_if_fail(session->notification != NULL); | |
| 156 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
157 cmdproc = session->notification->cmdproc; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
158 user = session->user; |
| 11992 | 159 state_text = msn_state_get_text(msn_state_from_account(account)); |
| 10908 | 160 |
| 161 /* If we're not logged in yet, don't send the status to the server, | |
| 162 * it will be sent when login completes | |
| 163 */ | |
| 164 if (!session->logged_in) | |
| 165 return; | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
166 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
167 msnobj = msn_user_get_object(user); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
168 |
| 19786 | 169 if (msnobj == NULL){ |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
170 msn_cmdproc_send(cmdproc, "CHG", "%s %d", state_text, |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
171 MSN_CLIENT_ID); |
| 19786 | 172 }else{ |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
173 char *msnobj_str; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
174 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
175 msnobj_str = msn_object_to_string(msnobj); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
176 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
177 msn_cmdproc_send(cmdproc, "CHG", "%s %d %s", state_text, |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
178 MSN_CLIENT_ID, gaim_url_encode(msnobj_str)); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
179 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
180 g_free(msnobj_str); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
181 } |
| 19821 | 182 msn_set_psm(session); |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
183 } |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
184 |
| 5361 | 185 const char * |
| 186 msn_away_get_text(MsnAwayType type) | |
| 187 { | |
| 7631 | 188 g_return_val_if_fail(type <= MSN_HIDDEN, NULL); |
| 5361 | 189 |
| 5824 | 190 return _(away_text[type]); |
| 5361 | 191 } |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
192 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
193 const char * |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
194 msn_state_get_text(MsnAwayType state) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
195 { |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
196 static char *status_text[] = |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
197 { "NLN", "NLN", "BSY", "IDL", "BRB", "AWY", "PHN", "LUN", "HDN", "HDN" }; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
198 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
199 return status_text[state]; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
200 } |
| 11992 | 201 |
| 202 MsnAwayType | |
| 203 msn_state_from_account(GaimAccount *account) | |
| 204 { | |
| 205 MsnAwayType msnstatus; | |
| 206 GaimPresence *presence; | |
| 207 GaimStatus *status; | |
| 208 const char *status_id; | |
| 209 | |
| 210 presence = gaim_account_get_presence(account); | |
| 211 status = gaim_presence_get_active_status(presence); | |
| 212 status_id = gaim_status_get_id(status); | |
| 213 | |
| 214 if (!strcmp(status_id, "away")) | |
| 215 msnstatus = MSN_AWAY; | |
| 216 else if (!strcmp(status_id, "brb")) | |
| 217 msnstatus = MSN_BRB; | |
| 218 else if (!strcmp(status_id, "busy")) | |
| 219 msnstatus = MSN_BUSY; | |
| 220 else if (!strcmp(status_id, "phone")) | |
| 221 msnstatus = MSN_PHONE; | |
| 222 else if (!strcmp(status_id, "lunch")) | |
| 223 msnstatus = MSN_LUNCH; | |
| 224 else if (!strcmp(status_id, "invisible")) | |
| 225 msnstatus = MSN_HIDDEN; | |
| 226 else | |
| 227 msnstatus = MSN_ONLINE; | |
| 228 | |
| 229 if ((msnstatus == MSN_ONLINE) && gaim_presence_is_idle(presence)) | |
| 230 msnstatus = MSN_IDLE; | |
| 231 | |
| 232 return msnstatus; | |
| 233 } |
