1 | /********************************************************************\ |
---|
2 | * BitlBee -- An IRC to other IM-networks gateway * |
---|
3 | * * |
---|
4 | * Copyright 2002-2012 Wilmer van der Gaast and others * |
---|
5 | \********************************************************************/ |
---|
6 | |
---|
7 | /* MSN module */ |
---|
8 | |
---|
9 | /* |
---|
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 with |
---|
21 | the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL; |
---|
22 | if not, write to the Free Software Foundation, Inc., 51 Franklin St., |
---|
23 | Fifth Floor, Boston, MA 02110-1301 USA |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef _MSN_H |
---|
27 | #define _MSN_H |
---|
28 | |
---|
29 | #define MSN_SSL_HOST "s.gateway.messenger.live.com" |
---|
30 | #define MSN_SSL_PORT 443 |
---|
31 | |
---|
32 | #define MSN_HTTP_HOST "geo.gateway.messenger.live.com" |
---|
33 | #define MSN_HTTP_PORT 443 |
---|
34 | |
---|
35 | #define MSNP11_PROD_KEY "YMM8C_H7KCQ2S_KL" |
---|
36 | #define MSNP11_PROD_ID "PROD0090YUAUV{2B" |
---|
37 | |
---|
38 | #define MSN_CAP1 0xC000 |
---|
39 | #define MSN_CAP2 0x0000 |
---|
40 | |
---|
41 | #define MSN_BASE_HEADERS \ |
---|
42 | "Routing: 1.0\r\n" \ |
---|
43 | "To: 1:%s\r\n" \ |
---|
44 | "From: 1:%s;epid={%s}\r\n" \ |
---|
45 | "\r\n" \ |
---|
46 | "Reliability: 1.0\r\n" \ |
---|
47 | "\r\n" |
---|
48 | |
---|
49 | #define MSN_MESSAGE_HEADERS MSN_BASE_HEADERS \ |
---|
50 | "Messaging: 2.0\r\n" \ |
---|
51 | "Message-Type: %s\r\n" \ |
---|
52 | "Content-Length: %zd\r\n" \ |
---|
53 | "Content-Type: text/plain; charset=UTF-8\r\n" \ |
---|
54 | "X-MMS-IM-Format: FN=Segoe%%20UI; EF=; CO=0; CS=0; PF=0\r\n" \ |
---|
55 | "\r\n" \ |
---|
56 | "%s" |
---|
57 | |
---|
58 | #define MSN_PUT_HEADERS MSN_BASE_HEADERS \ |
---|
59 | "Publication: 1.0\r\n" \ |
---|
60 | "Uri: %s\r\n" \ |
---|
61 | "Content-Type: %s\r\n" \ |
---|
62 | "Content-Length: %zd\r\n" \ |
---|
63 | "\r\n" \ |
---|
64 | "%s" |
---|
65 | |
---|
66 | #define MSN_PUT_USER_BODY \ |
---|
67 | "<user>" \ |
---|
68 | "<s n=\"PE\"><UserTileLocation></UserTileLocation><FriendlyName>%s</FriendlyName><PSM>%s</PSM><DDP></DDP>" \ |
---|
69 | "<Scene></Scene><ASN></ASN><ColorScheme>-3</ColorScheme><BDG></BDG><RUM>%s</RUM><RUL></RUL><RLT>0</RLT>" \ |
---|
70 | "<RID></RID><SUL></SUL><MachineGuid>%s</MachineGuid></s>" \ |
---|
71 | "<s n=\"IM\"><Status>%s</Status><CurrentMedia></CurrentMedia></s>" \ |
---|
72 | "<sep n=\"PD\"><ClientType>1</ClientType><EpName>%s</EpName><Idle>%s</Idle><State>%s</State></sep>" \ |
---|
73 | "<sep n=\"PE\"><VER>BitlBee:" BITLBEE_VERSION "</VER><TYP>1</TYP><Capabilities>%d:%d</Capabilities></sep>" \ |
---|
74 | "<sep n=\"IM\"><Capabilities>%d:%d</Capabilities></sep>" \ |
---|
75 | "</user>" |
---|
76 | |
---|
77 | #define PROFILE_URL "http://members.msn.com/" |
---|
78 | |
---|
79 | typedef enum { |
---|
80 | MSN_GOT_PROFILE = 1, |
---|
81 | MSN_GOT_PROFILE_DN = 2, |
---|
82 | MSN_DONE_ADL = 4, |
---|
83 | MSN_REAUTHING = 8, |
---|
84 | MSN_EMAIL_UNVERIFIED = 16, |
---|
85 | MSN_DONE_BND = 32, |
---|
86 | } msn_flags_t; |
---|
87 | |
---|
88 | struct msn_gw { |
---|
89 | char *last_host; |
---|
90 | int port; |
---|
91 | gboolean ssl; |
---|
92 | |
---|
93 | char *session_id; |
---|
94 | |
---|
95 | GByteArray *in; |
---|
96 | GByteArray *out; |
---|
97 | |
---|
98 | int poll_timeout; |
---|
99 | |
---|
100 | b_event_handler callback; |
---|
101 | |
---|
102 | struct im_connection *ic; |
---|
103 | struct msn_data *md; |
---|
104 | |
---|
105 | gboolean open; |
---|
106 | gboolean waiting; |
---|
107 | gboolean polling; |
---|
108 | }; |
---|
109 | |
---|
110 | struct msn_data { |
---|
111 | int fd, inpa; |
---|
112 | int rxlen; |
---|
113 | char *rxq; |
---|
114 | |
---|
115 | int msglen; |
---|
116 | char *cmd_text; |
---|
117 | |
---|
118 | struct im_connection *ic; |
---|
119 | |
---|
120 | msn_flags_t flags; |
---|
121 | |
---|
122 | int trId; |
---|
123 | char *tokens[4]; |
---|
124 | char *uuid; |
---|
125 | |
---|
126 | GSList *msgq, *grpq, *soapq; |
---|
127 | |
---|
128 | const struct msn_away_state *away_state; |
---|
129 | GSList *groups; |
---|
130 | char *profile_rid; |
---|
131 | |
---|
132 | /* Mostly used for sending the ADL command; since MSNP13 the client |
---|
133 | is responsible for downloading the contact list and then sending |
---|
134 | it to the MSNP server. */ |
---|
135 | GTree *domaintree; |
---|
136 | int adl_todo; |
---|
137 | |
---|
138 | gboolean is_http; |
---|
139 | struct msn_gw *gw; |
---|
140 | void *ssl; |
---|
141 | }; |
---|
142 | |
---|
143 | struct msn_away_state { |
---|
144 | char code[4]; |
---|
145 | char name[16]; |
---|
146 | }; |
---|
147 | |
---|
148 | struct msn_status_code { |
---|
149 | int number; |
---|
150 | char *text; |
---|
151 | int flags; |
---|
152 | }; |
---|
153 | |
---|
154 | struct msn_message { |
---|
155 | char *who; |
---|
156 | char *text; |
---|
157 | }; |
---|
158 | |
---|
159 | struct msn_groupadd { |
---|
160 | char *who; |
---|
161 | char *group; |
---|
162 | }; |
---|
163 | |
---|
164 | typedef enum { |
---|
165 | MSN_BUDDY_FL = 1, /* Warning: FL,AL,BL *must* be 1,2,4. */ |
---|
166 | MSN_BUDDY_AL = 2, |
---|
167 | MSN_BUDDY_BL = 4, |
---|
168 | MSN_BUDDY_RL = 8, |
---|
169 | MSN_BUDDY_PL = 16, |
---|
170 | MSN_BUDDY_ADL_SYNCED = 256, |
---|
171 | MSN_BUDDY_FED = 512, |
---|
172 | } msn_buddy_flags_t; |
---|
173 | |
---|
174 | struct msn_buddy_data { |
---|
175 | char *cid; |
---|
176 | msn_buddy_flags_t flags; |
---|
177 | }; |
---|
178 | |
---|
179 | struct msn_group { |
---|
180 | char *name; |
---|
181 | char *id; |
---|
182 | }; |
---|
183 | |
---|
184 | /* Bitfield values for msn_status_code.flags */ |
---|
185 | #define STATUS_FATAL 1 |
---|
186 | #define STATUS_SB_FATAL 2 |
---|
187 | |
---|
188 | extern int msn_chat_id; |
---|
189 | extern const struct msn_away_state msn_away_state_list[]; |
---|
190 | extern const struct msn_status_code msn_status_code_list[]; |
---|
191 | |
---|
192 | /* Keep a list of all the active connections. We need these lists because |
---|
193 | "connected" callbacks might be called when the connection they belong too |
---|
194 | is down already (for example, when an impatient user disabled the |
---|
195 | connection), the callback should check whether it's still listed here |
---|
196 | before doing *anything* else. */ |
---|
197 | extern GSList *msn_connections; |
---|
198 | |
---|
199 | /* ns.c */ |
---|
200 | int msn_ns_write(struct im_connection *ic, const char *fmt, ...) G_GNUC_PRINTF(2, 3); |
---|
201 | gboolean msn_ns_connect(struct im_connection *ic, const char *host, int port); |
---|
202 | void msn_ns_close(struct msn_data *handler); |
---|
203 | void msn_auth_got_passport_token(struct im_connection *ic, const char *token, const char *error); |
---|
204 | void msn_auth_got_contact_list(struct im_connection *ic); |
---|
205 | int msn_ns_finish_login(struct im_connection *ic); |
---|
206 | int msn_ns_send_typing(struct im_connection *ic, struct bee_user *bu); |
---|
207 | int msn_ns_send_message(struct im_connection *ic, struct bee_user *bu, const char *text); |
---|
208 | int msn_ns_command(struct msn_data *md, char **cmd, int num_parts, char *msg, int msglen); |
---|
209 | int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int num_parts); |
---|
210 | |
---|
211 | /* msn_util.c */ |
---|
212 | int msn_buddy_list_add(struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *realname_, |
---|
213 | const char *group); |
---|
214 | int msn_buddy_list_remove(struct im_connection *ic, msn_buddy_flags_t list, const char *who, const char *group); |
---|
215 | void msn_buddy_ask(bee_user_t *bu); |
---|
216 | void msn_queue_feed(struct msn_data *h, char *bytes, int st); |
---|
217 | int msn_handler(struct msn_data *h); |
---|
218 | char *msn_p11_challenge(char *challenge); |
---|
219 | gint msn_domaintree_cmp(gconstpointer a_, gconstpointer b_); |
---|
220 | struct msn_group *msn_group_by_name(struct im_connection *ic, const char *name); |
---|
221 | struct msn_group *msn_group_by_id(struct im_connection *ic, const char *id); |
---|
222 | int msn_ns_set_display_name(struct im_connection *ic, const char *value); |
---|
223 | const char *msn_normalize_handle(const char *handle); |
---|
224 | |
---|
225 | /* tables.c */ |
---|
226 | const struct msn_away_state *msn_away_state_by_number(int number); |
---|
227 | const struct msn_away_state *msn_away_state_by_code(char *code); |
---|
228 | const struct msn_away_state *msn_away_state_by_name(char *name); |
---|
229 | const struct msn_status_code *msn_status_by_number(int number); |
---|
230 | |
---|
231 | /* gw.c */ |
---|
232 | struct msn_gw *msn_gw_new(struct im_connection *ic); |
---|
233 | void msn_gw_free(struct msn_gw *gw); |
---|
234 | void msn_gw_open(struct msn_gw *gw); |
---|
235 | ssize_t msn_gw_read(struct msn_gw *gw, char **buf); |
---|
236 | void msn_gw_write(struct msn_gw *gw, char *buf, size_t len); |
---|
237 | |
---|
238 | #endif //_MSN_H |
---|