Mercurial > pidgin
comparison plugins/msn/msn.c @ 1584:30a4ecea466a
[gaim-migrate @ 1594]
I Suck.
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Fri, 16 Mar 2001 01:17:10 +0000 |
parents | d60672672a13 |
children | f367ea8020fb |
comparison
equal
deleted
inserted
replaced
1583:78effb5b2e4b | 1584:30a4ecea466a |
---|---|
76 int inpa; | 76 int inpa; |
77 int fd; | 77 int fd; |
78 struct gaim_connection *gc; | 78 struct gaim_connection *gc; |
79 char *secret; | 79 char *secret; |
80 char *session; | 80 char *session; |
81 time_t last_trid; | |
82 char *txqueue; | |
81 }; | 83 }; |
82 | 84 |
83 GSList *msn_connections = NULL; | 85 GSList *msn_connections = NULL; |
84 | 86 |
85 unsigned long long globalc = 0; | 87 unsigned long long globalc = 0; |
86 static void msn_callback(gpointer data, gint source, GdkInputCondition condition); | 88 static void msn_callback(gpointer data, gint source, GdkInputCondition condition); |
89 | |
90 struct msn_conn *find_msn_conn_by_user(gchar * user) | |
91 { | |
92 struct msn_conn *mc; | |
93 GSList *conns = msn_connections; | |
94 | |
95 while (conns) { | |
96 mc = (struct msn_conn *)conns->data; | |
97 | |
98 if (mc != NULL) { | |
99 if (strcasecmp(mc->user, user) == 0) { | |
100 return mc; | |
101 } | |
102 } | |
103 | |
104 conns = g_slist_next(conns); | |
105 } | |
106 | |
107 return NULL; | |
108 } | |
109 | |
110 struct msn_conn *find_msn_conn_by_trid(time_t trid) | |
111 { | |
112 struct msn_conn *mc; | |
113 GSList *conns = msn_connections; | |
114 | |
115 while (conns) { | |
116 mc = (struct msn_conn *)conns->data; | |
117 | |
118 if (mc != NULL) { | |
119 | |
120 printf("Comparing: %d <==> %d\n", mc->last_trid, trid); | |
121 if (mc->last_trid == trid) { | |
122 return mc; | |
123 } | |
124 } | |
125 | |
126 conns = g_slist_next(conns); | |
127 } | |
128 | |
129 return NULL; | |
130 } | |
87 | 131 |
88 static char *msn_name() | 132 static char *msn_name() |
89 { | 133 { |
90 return "MSN"; | 134 return "MSN"; |
91 } | 135 } |
125 gdk_input_remove(mc->inpa); | 169 gdk_input_remove(mc->inpa); |
126 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | 170 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); |
127 | 171 |
128 /* Append our connection */ | 172 /* Append our connection */ |
129 msn_connections = g_slist_append(msn_connections, mc); | 173 msn_connections = g_slist_append(msn_connections, mc); |
174 } | |
175 | |
176 static void msn_invite_callback(gpointer data, gint source, GdkInputCondition condition) | |
177 { | |
178 struct msn_conn *mc = data; | |
179 struct msn_data *md = (struct msn_data *)mc->gc->proto_data; | |
180 char buf[MSN_BUF_LEN]; | |
181 struct gaim_connection *gc = mc->gc; | |
182 int i = 0; | |
183 | |
184 fcntl(source, F_SETFL, 0); | |
185 | |
186 if (condition == GDK_INPUT_WRITE) | |
187 { | |
188 /* We just got in here */ | |
189 gdk_input_remove(mc->inpa); | |
190 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_invite_callback, mc); | |
191 | |
192 /* Write our signon request */ | |
193 g_snprintf(buf, MSN_BUF_LEN, "USR %d %s %s\n", mc->last_trid, mc->gc->username, mc->secret); | |
194 msn_write(source, buf); | |
195 return; | |
196 } | |
197 | |
198 bzero(buf, MSN_BUF_LEN); | |
199 | |
200 do | |
201 { | |
202 if (read(source, buf + i, 1) < 0) | |
203 { | |
204 hide_login_progress(gc, "Read error"); | |
205 signoff(gc); | |
206 return; | |
207 } | |
208 | |
209 } while (buf[i++] != '\n'); | |
210 | |
211 g_strchomp(buf); | |
212 | |
213 printf("MSN(%d) ==> %s\n", source, buf); | |
214 | |
215 if (!strncmp("USR ", buf, 4)) | |
216 { | |
217 char **res; | |
218 | |
219 res = g_strsplit(buf, " ", 0); | |
220 if (strcasecmp("OK", res[2])) | |
221 { | |
222 g_strfreev(res); | |
223 close(mc->fd); | |
224 return; | |
225 } | |
226 | |
227 /* We've authorized. Let's send an invite request */ | |
228 g_snprintf(buf, MSN_BUF_LEN, "CAL %d %s\n", trId(md), mc->user); | |
229 msn_write(source, buf); | |
230 return; | |
231 } | |
232 | |
233 else if (!strncmp("JOI ", buf, 4)) | |
234 { | |
235 /* Looks like they just joined! Write their queued message */ | |
236 g_snprintf(buf, MSN_BUF_LEN, "MSG %d N %d\r\n%s%s", trId(md), strlen(mc->txqueue) + strlen(MIME_HEADER), MIME_HEADER, mc->txqueue); | |
237 | |
238 msn_write(source, buf); | |
239 | |
240 gdk_input_remove(mc->inpa); | |
241 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_READ, msn_callback, mc->gc); | |
242 | |
243 return; | |
244 | |
245 } | |
130 } | 246 } |
131 | 247 |
132 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) | 248 static void msn_callback(gpointer data, gint source, GdkInputCondition condition) |
133 { | 249 { |
134 struct gaim_connection *gc = data; | 250 struct gaim_connection *gc = data; |
270 g_strfreev(address); | 386 g_strfreev(address); |
271 g_strfreev(res); | 387 g_strfreev(res); |
272 | 388 |
273 return; | 389 return; |
274 } | 390 } |
391 else if (!strncmp("XFR ", buf, 4)) | |
392 { | |
393 char **res; | |
394 char *host; | |
395 char *port; | |
396 struct msn_conn *mc; | |
397 | |
398 res = g_strsplit(buf, " ", 0); | |
399 | |
400 printf("Last trid is: %d\n", md->last_trid); | |
401 printf("This TrId is: %d\n", atoi(res[1])); | |
402 | |
403 mc = find_msn_conn_by_trid(atoi(res[1])); | |
404 | |
405 if (!mc) | |
406 { | |
407 g_strfreev(res); | |
408 return; | |
409 } | |
410 | |
411 strcpy(buf, res[3]); | |
412 | |
413 mc->secret = g_strdup(res[5]); | |
414 mc->session = g_strdup(res[1]); | |
415 | |
416 g_strfreev(res); | |
417 | |
418 res = g_strsplit(buf, ":", 0); | |
419 | |
420 close(md->fd); | |
421 | |
422 /* Now we have the host and port */ | |
423 if (!(md->fd = msn_connect(res[0], atoi(res[1])))) | |
424 return; | |
425 | |
426 printf("Connected to: %s:%s\n", res[0], res[1]); | |
427 | |
428 mc->inpa = gdk_input_add(mc->fd, GDK_INPUT_WRITE, msn_invite_callback, mc); | |
429 | |
430 g_strfreev(res); | |
431 | |
432 return; | |
433 } | |
275 else if (!strncmp("LST ", buf, 4)) | 434 else if (!strncmp("LST ", buf, 4)) |
276 { | 435 { |
277 char **res; | 436 char **res; |
278 | 437 |
279 res = g_strsplit(buf, " ", 0); | 438 res = g_strsplit(buf, " ", 0); |
571 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); | 730 md->inpa = gdk_input_add(md->fd, GDK_INPUT_WRITE, msn_login_callback, gc); |
572 | 731 |
573 printf("Connected.\n"); | 732 printf("Connected.\n"); |
574 } | 733 } |
575 | 734 |
735 void msn_send_im(struct gaim_connection *gc, char *who, char *message, int away) | |
736 { | |
737 struct msn_conn *mc; | |
738 struct msn_data *md = (struct msn_data *)gc->proto_data; | |
739 char buf[MSN_BUF_LEN]; | |
740 | |
741 if (!g_strcasecmp(who, gc->username)) | |
742 { | |
743 do_error_dialog("You can not send a message to yourself!", "Gaim: MSN Error"); | |
744 return; | |
745 } | |
746 | |
747 mc = find_msn_conn_by_user(who); | |
748 | |
749 /* If we're not already in a conversation with | |
750 * this person then we have to do some tricky things. */ | |
751 | |
752 if (!mc) | |
753 { | |
754 gchar buf2[MSN_BUF_LEN]; | |
755 gchar *address; | |
756 gchar *auth; | |
757 gchar **res; | |
758 | |
759 /* Request a new switchboard connection */ | |
760 g_snprintf(buf, MSN_BUF_LEN, "XFR %d SB\n", trId(md)); | |
761 msn_write(md->fd, buf); | |
762 | |
763 mc = g_new0(struct msn_conn, 1); | |
764 | |
765 mc->user = g_strdup(who); | |
766 mc->gc = gc; | |
767 mc->last_trid = md->last_trid; | |
768 mc->txqueue = g_strdup(message); | |
769 | |
770 /* Append our connection */ | |
771 msn_connections = g_slist_append(msn_connections, mc); | |
772 } | |
773 | |
774 } | |
775 | |
576 static char **msn_list_icon(int uc) | 776 static char **msn_list_icon(int uc) |
577 { | 777 { |
578 if (uc == UC_UNAVAILABLE) | 778 if (uc == UC_UNAVAILABLE) |
579 return msn_away_xpm; | 779 return msn_away_xpm; |
580 else if (uc == UC_NORMAL) | 780 else if (uc == UC_NORMAL) |
592 ret->list_icon = msn_list_icon; | 792 ret->list_icon = msn_list_icon; |
593 ret->buddy_menu = NULL; | 793 ret->buddy_menu = NULL; |
594 ret->user_opts = NULL; | 794 ret->user_opts = NULL; |
595 ret->login = msn_login; | 795 ret->login = msn_login; |
596 ret->close = NULL; | 796 ret->close = NULL; |
597 ret->send_im = NULL; | 797 ret->send_im = msn_send_im; |
598 ret->set_info = NULL; | 798 ret->set_info = NULL; |
599 ret->get_info = NULL; | 799 ret->get_info = NULL; |
600 ret->set_away = NULL; | 800 ret->set_away = NULL; |
601 ret->get_away_msg = NULL; | 801 ret->get_away_msg = NULL; |
602 ret->set_dir = NULL; | 802 ret->set_dir = NULL; |