2 * @file ymsg.h The Yahoo! Protocol
6 * Purple is the legal property of its developers, whose names are too numerous
7 * to list here. Please refer to the COPYRIGHT file distributed with this
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
28 #include "circularbuffer.h"
34 #define YAHOO_PAGER_HOST_REQ_URL "http://vcs2.msg.yahoo.com/capacity"
35 #define YAHOO_PAGER_HOST_FALLBACK "scsa.msg.yahoo.com"
36 #define YAHOO_PAGER_PORT 5050
37 #define YAHOO_PAGER_PORT_P2P 5101
38 #define YAHOO_LOGIN_URL "https://login.yahoo.com/config/pwtoken_login?src=ymsgr&ts=&token=%s"
39 #define YAHOO_TOKEN_URL "https://login.yahoo.com/config/pwtoken_get?src=ymsgr&ts=&login=%s&passwd=%s&chal=%s"
40 #define YAHOO_P2P_KEEPALIVE_SECS 300
41 #define YAHOO_P2P_SERVER_TIMEOUT 10
42 #define YAHOO_PROFILE_URL "http://profiles.yahoo.com/"
43 #define YAHOO_MAIL_URL "http://rd.yahoo.com/messenger/client/?http://mail.yahoo.com/"
44 #define YAHOO_XFER_HOST "filetransfer.msg.yahoo.com"
45 #define YAHOO_XFER_RELAY_HOST "relay.msg.yahoo.com"
46 #define YAHOO_XFER_RELAY_PORT 80
47 #define YAHOO_ROOMLIST_URL "http://insider.msg.yahoo.com/ycontent/"
48 #define YAHOO_ROOMLIST_LOCALE "us"
50 #define YAHOO_AUDIBLE_URL "http://l.yimg.com/pu/dl/aud"
52 #define WEBMESSENGER_URL "http://login.yahoo.com/config/login?.src=pg"
54 #define YAHOO_SMS_CARRIER_URL "http://validate.msg.yahoo.com"
56 #define YAHOO_USERINFO_URL "http://address.yahoo.com/yab/us?v=XM&sync=1&tags=short&useutf8=1&noclear=1&legenc=codepage-1252"
58 #define YAHOO_PICURL_SETTING "picture_url"
59 #define YAHOO_PICCKSUM_SETTING "picture_checksum"
60 #define YAHOO_PICEXPIRE_SETTING "picture_expire"
62 #define YAHOO_STATUS_TYPE_OFFLINE "offline"
63 #define YAHOO_STATUS_TYPE_AVAILABLE "available"
64 #define YAHOO_STATUS_TYPE_BRB "brb"
65 #define YAHOO_STATUS_TYPE_BUSY "busy"
66 #define YAHOO_STATUS_TYPE_NOTATHOME "notathome"
67 #define YAHOO_STATUS_TYPE_NOTATDESK "notatdesk"
68 #define YAHOO_STATUS_TYPE_NOTINOFFICE "notinoffice"
69 #define YAHOO_STATUS_TYPE_ONPHONE "onphone"
70 #define YAHOO_STATUS_TYPE_ONVACATION "onvacation"
71 #define YAHOO_STATUS_TYPE_OUTTOLUNCH "outtolunch"
72 #define YAHOO_STATUS_TYPE_STEPPEDOUT "steppedout"
73 #define YAHOO_STATUS_TYPE_AWAY "away"
74 #define YAHOO_STATUS_TYPE_INVISIBLE "invisible"
75 #define YAHOO_STATUS_TYPE_MOBILE "mobile"
77 #define YAHOO_CLIENT_VERSION_ID "4194239"
78 #define YAHOO_CLIENT_VERSION "9.0.0.2162"
80 #define YAHOO_CLIENT_USERAGENT "Mozilla/5.0"
81 #define YAHOO_CLIENT_USERAGENT_ALIAS "Mozilla/4.0 (compatible; MSIE 5.5)"
83 /* Index into attention types list. */
87 YAHOO_PKT_TYPE_SERVER
= 0,
92 YAHOO_P2P_WE_ARE_CLIENT
=0,
93 YAHOO_P2P_WE_ARE_SERVER
94 } yahoo_p2p_connection_type
;
97 YAHOO_STATUS_AVAILABLE
= 0,
100 YAHOO_STATUS_NOTATHOME
,
101 YAHOO_STATUS_NOTATDESK
,
102 YAHOO_STATUS_NOTINOFFICE
,
103 YAHOO_STATUS_ONPHONE
,
104 YAHOO_STATUS_ONVACATION
,
105 YAHOO_STATUS_OUTTOLUNCH
,
106 YAHOO_STATUS_STEPPEDOUT
,
107 YAHOO_STATUS_P2P
= 11,
108 YAHOO_STATUS_INVISIBLE
= 12,
109 YAHOO_STATUS_CUSTOM
= 99,
110 YAHOO_STATUS_IDLE
= 999,
111 YAHOO_STATUS_WEBLOGIN
= 0x5a55aa55,
112 YAHOO_STATUS_OFFLINE
= 0x5a55aa56, /* don't ask */
113 YAHOO_STATUS_TYPING
= 0x16,
114 YAHOO_STATUS_DISCONNECTED
= -1 /* 0xffffffff; in ymsg 15. doesnt mean the normal sense of 'disconnected' */
117 struct yahoo_buddy_icon_upload_data
{
118 PurpleConnection
*gc
;
120 GString
*picture_data
;
123 struct yahoo_p2p_data
{
124 PurpleConnection
*gc
;
131 yahoo_p2p_connection_type connection_type
;
136 typedef struct _YahooPersonalDetails
{
151 } YahooPersonalDetails
;
154 PurpleConnection
*gc
;
159 PurpleCircularBuffer
*txbuf
;
163 char **profiles
; /* Multiple profiles can be associated with an account */
164 YahooPersonalDetails ypd
;
167 * This is used to keep track of the IMVironment chosen
168 * by people you talk to. We don't do very much with
169 * this right now... but at least now if the remote user
170 * selects an IMVironment we won't reset it back to the
171 * default of nothing.
173 GHashTable
*imvironments
;
177 GString
*tmp_serv_blist
, *tmp_serv_ilist
, *tmp_serv_plist
;
179 unsigned int conf_id
; /* just a counter */
180 gboolean chat_online
;
183 char *pending_chat_room
;
184 char *pending_chat_id
;
185 char *pending_chat_topic
;
186 char *pending_chat_goto
;
192 gboolean wm
; /* connected w/ web messenger method */
193 /* picture aka buddy icon stuff */
195 int picture_checksum
;
197 /* ew. we have to check the icon before we connect,
198 * but can't upload it til we're connected. */
199 struct yahoo_buddy_icon_upload_data
*picture_upload_todo
;
200 PurpleHttpConnection
*picture_upload_hc
;
202 struct _YchtConn
*ycht
;
205 * This set contains HTTP connections
206 * for when we lookup people profile or photo information.
208 PurpleHttpConnectionSet
*http_reqs
;
210 GHashTable
*xfer_peer_idstring_map
;/* Hey, i dont know, but putting this HashTable next to friends gives a run time fault... */
211 GSList
*cookies
;/* contains all cookies, including _y and _t */
212 PurpleNetworkListenData
*listen_data
;
215 * We may receive a list15 in multiple packets with no prior warning as to how many we'll be getting;
216 * the server expects us to keep track of the group for which it is sending us contact names.
218 char *current_list15_grp
;
220 time_t last_keepalive
;
221 GHashTable
*peers
; /* information about p2p data */
223 int yahoo_local_p2p_server_fd
;
224 int yahoo_p2p_server_watcher
;
225 GHashTable
*sms_carrier
; /* sms carrier data */
226 guint yahoo_p2p_server_timeout_handle
;
229 #define YAHOO_MAX_STATUS_MESSAGE_LENGTH (255)
232 * Current Maximum Length for Instant Messages
234 * This was found by experiment.
236 * The YMSG protocol allows a message of up to 948 bytes, but the official client
237 * limits to 800 characters. According to experiments I conducted, it seems that
238 * the discrepancy is to allow some leeway for messages with mixed single- and
239 * multi-byte characters, as I was able to send messages of 840 and 932 bytes
240 * by using some multibyte characters (some random Chinese or Japanese characters,
241 * to be precise). - rekkanoryo
243 #define YAHOO_MAX_MESSAGE_LENGTH_BYTES 948
244 #define YAHOO_MAX_MESSAGE_LENGTH_CHARS 800
246 /* sometimes i wish prpls could #include things from other prpls. then i could just
247 * use the routines from libfaim and not have to admit to knowing how they work. */
248 #define yahoo_put16(buf, data) ( \
249 (*(buf) = (unsigned char)((data)>>8)&0xff), \
250 (*((buf)+1) = (unsigned char)(data)&0xff), \
252 #define yahoo_get16(buf) ((((*(buf))<<8)&0xff00) + ((*((buf)+1)) & 0xff))
253 #define yahoo_put32(buf, data) ( \
254 (*((buf)) = (unsigned char)((data)>>24)&0xff), \
255 (*((buf)+1) = (unsigned char)((data)>>16)&0xff), \
256 (*((buf)+2) = (unsigned char)((data)>>8)&0xff), \
257 (*((buf)+3) = (unsigned char)(data)&0xff), \
259 #define yahoo_get32(buf) ((((*(buf))<<24)&0xff000000) + \
260 (((*((buf)+1))<<16)&0x00ff0000) + \
261 (((*((buf)+2))<< 8)&0x0000ff00) + \
262 (((*((buf)+3) )&0x000000ff)))
265 void yahoo_init_colorht(void);
266 void yahoo_dest_colorht(void);
267 char *yahoo_codes_to_html(const char *x
);
270 * This function takes a normal HTML message and converts it to the message
271 * format used by Yahoo, which uses a frankensteinish combination of ANSI
272 * escape codes and broken HTML.
274 * It results in slightly different output than would be sent by official
275 * Yahoo clients. The two main differences are:
277 * 1. We always close all tags, whereas official Yahoo clients leave tags
278 * dangling open at the end of each message (and the client treats them
280 * 2. We always close inner tags first before closing outter tags.
282 * For example, if you want to send this message:
283 * <b> bold <i> bolditalic </i></b><i> italic </i>
284 * Official Yahoo clients would send:
285 * ESC[1m bold ESC[2m bolditalic ESC[x1m italic
287 * ESC[1m bold ESC[2m bolditalic ESC[x2mESC[x1mESC[2m italic ESC[x2m
289 char *yahoo_html_to_codes(const char *src
);
292 yahoo_account_use_http_proxy(PurpleConnection
*conn
);
295 * Encode some text to send to the yahoo server.
297 * @param gc The connection handle.
298 * @param str The null terminated utf8 string to encode.
299 * @param utf8 Whether to return a UTF-8 string.
300 * @return A g_malloc'ed string in the appropriate encoding. If utf8
301 * is true then the string is copied verbatim. Otherwise the
302 * encoding from account settings is used.
304 gchar
*yahoo_string_encode(PurpleConnection
*gc
, const char *str
, gboolean utf8
);
307 * Decode some text received from the server.
309 * @param gc The gc handle.
310 * @param str The null terminated string to decode.
311 * @param utf8 Did the server tell us it was supposed to be utf8?
312 * @return The decoded, utf-8 string, which must be g_free()'d.
314 char *yahoo_string_decode(PurpleConnection
*gc
, const char *str
, gboolean utf8
);
316 char *yahoo_convert_to_numeric(const char *str
);
318 /* yahoo_profile.c */
319 void yahoo_get_info(PurpleConnection
*gc
, const char *name
);
321 /* ymsg.h - these functions were formerly static but need not to be for the
322 * new two-protocol model. */
323 const char *yahoo_list_icon(PurpleAccount
*a
, PurpleBuddy
*b
);
324 const char *yahoo_list_emblem(PurpleBuddy
*b
);
325 char *yahoo_status_text(PurpleBuddy
*b
);
326 void yahoo_tooltip_text(PurpleBuddy
*b
, PurpleNotifyUserInfo
*user_info
, gboolean full
);
327 GList
*yahoo_status_types(PurpleAccount
*account
);
328 GList
*yahoo_blist_node_menu(PurpleBlistNode
*node
);
329 void yahoo_login(PurpleAccount
*account
);
330 void yahoo_close(PurpleConnection
*gc
);
331 int yahoo_send_im(PurpleConnection
*gc
, PurpleMessage
*msg
);
332 unsigned int yahoo_send_typing(PurpleConnection
*gc
, const char *who
, PurpleIMTypingState state
);
333 void yahoo_set_status(PurpleAccount
*account
, PurpleStatus
*status
);
334 void yahoo_set_idle(PurpleConnection
*gc
, int idle
);
335 void yahoo_add_buddy(PurpleConnection
*gc
, PurpleBuddy
*buddy
, PurpleGroup
*g
, const char *message
);
336 void yahoo_remove_buddy(PurpleConnection
*gc
, PurpleBuddy
*buddy
, PurpleGroup
*group
);
337 void yahoo_add_deny(PurpleConnection
*gc
, const char *who
);
338 void yahoo_rem_deny(PurpleConnection
*gc
, const char *who
);
339 void yahoo_set_permit_deny(PurpleConnection
*gc
);
340 void yahoo_keepalive(PurpleConnection
*gc
);
341 void yahoo_change_buddys_group(PurpleConnection
*gc
, const char *who
, const char *old_group
, const char *new_group
);
342 void yahoo_rename_group(PurpleConnection
*gc
, const char *old_name
, PurpleGroup
*group
, GList
*moved_buddies
);
343 gboolean
yahoo_offline_message(const PurpleBuddy
*buddy
);
344 gboolean
yahoo_send_attention(PurpleConnection
*gc
, const char *username
, guint type
);
345 GList
*yahoo_attention_types(PurpleAccount
*account
);
347 GList
*yahoo_get_actions(PurpleConnection
*gc
);
348 void yahoopurple_register_commands(void);
349 gssize
yahoo_get_max_message_size(PurpleConversation
*conv
);
351 PurpleCmdRet
yahoopurple_cmd_buzz(PurpleConversation
*c
, const gchar
*cmd
, gchar
**args
, gchar
**error
, void *data
);
352 PurpleCmdRet
yahoopurple_cmd_chat_join(PurpleConversation
*conv
, const char *cmd
, char **args
, char **error
, void *data
);
353 PurpleCmdRet
yahoopurple_cmd_chat_list(PurpleConversation
*conv
, const char *cmd
, char **args
, char **error
, void *data
);
354 /* needed for xfer, thought theyd be useful for other enhancements later on
355 Returns list of cookies stored in yahoo_data formatted as a single null terminated string
356 returned value must be g_freed
358 gchar
* yahoo_get_cookies(PurpleConnection
*gc
);
360 /* send p2p pkt containing our encoded ip, asking peer to connect to us */
361 void yahoo_send_p2p_pkt(PurpleConnection
*gc
, const char *who
, int val_13
);
363 #endif /* _YMSG_H_ */