annotate plugins/yay/conn.c @ 1610:f018f0faddda

[gaim-migrate @ 1620] this should have been committed before pre7 was released. it went into pre7 either way though. committer: Tailor Script <tailor@pidgin.im>
author Eric Warmenhoven <eric@warmenhoven.org>
date Sat, 17 Mar 2001 13:02:57 +0000
parents e9faf5dfdba0
children 6497ee3751cf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
1 /*
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
2 * libyay
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
3 *
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
4 * Copyright (C) 2001 Eric Warmenhoven <warmenhoven@yahoo.com>
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
5 *
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
9 * (at your option) any later version.
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
10 *
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
14 * GNU General Public License for more details.
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
15 *
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
19 *
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
20 */
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
21
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
22 #include "internal.h"
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
23
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
24 void (*yahoo_socket_notify)(struct yahoo_session *, int, int, gboolean) = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
25 void (*yahoo_print)(struct yahoo_session *, int, const char *) = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
26
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
27 struct yahoo_session *yahoo_new()
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
28 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
29 struct yahoo_session *sess;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
30
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
31 if (!(sess = g_new0(struct yahoo_session, 1)))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
32 return NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
33
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
34 return sess;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
35 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
36
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
37 void yahoo_set_proxy(struct yahoo_session *session, int proxy_type, char *proxy_host, int proxy_port)
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
38 {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
39 if (!session || !proxy_type || !proxy_host)
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
40 return;
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
41
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
42 session->proxy_type = proxy_type;
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
43 session->proxy_host = g_strdup(proxy_host);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
44 session->proxy_port = proxy_port;
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
45 }
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
46
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
47 static int yahoo_connect_host(struct yahoo_session *sess, const char *host, int port, int *statusret)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
48 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
49 struct sockaddr_in sa;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
50 struct hostent *hp;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
51 int fd;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
52
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
53 if (!(hp = gethostbyname(host))) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
54 YAHOO_PRINT(sess, YAHOO_LOG_WARNING, "Resolve error");
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
55 if (statusret)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
56 *statusret = (h_errno | YAHOO_CONN_STATUS_RESOLVERR);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
57 return -1;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
58 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
59
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
60 memset(&sa, 0, sizeof(struct sockaddr_in));
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
61 sa.sin_port = htons(port);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
62 memcpy(&sa.sin_addr, hp->h_addr, hp->h_length);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
63 sa.sin_family = hp->h_addrtype;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
64
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
65 fd = socket(hp->h_addrtype, SOCK_STREAM, 0);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
66
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
67 fcntl(fd, F_SETFL, O_NONBLOCK);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
68
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
69 if (connect(fd, (struct sockaddr *)&sa, sizeof(struct sockaddr_in)) < 0) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
70 if ((errno == EINPROGRESS) || (errno == EINTR)) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
71 YAHOO_PRINT(sess, YAHOO_LOG_NOTICE, "Connect would block");
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
72 if (statusret)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
73 *statusret |= YAHOO_CONN_STATUS_INPROGRESS;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
74 return fd;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
75 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
76 close(fd);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
77 fd = -1;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
78 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
79
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
80 return fd;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
81 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
82
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
83 struct yahoo_conn *yahoo_new_conn(struct yahoo_session *session, int type, const char *host, int port)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
84 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
85 struct yahoo_conn *conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
86 int status;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
87
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
88 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
89 return NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
90
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
91 conn = g_new0(struct yahoo_conn, 1);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
92 conn->type = type;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
93
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
94 if (host) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
95 conn->socket = yahoo_connect_host(session, host, port, &status);
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
96 } else if (session->proxy_type) {
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
97 YAHOO_PRINT(session, YAHOO_LOG_DEBUG, "connecting to proxy");
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
98 conn->socket = yahoo_connect_host(session, session->proxy_host,
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
99 session->proxy_port, &status);
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
100 if (type == YAHOO_CONN_TYPE_MAIN)
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
101 conn->type = YAHOO_CONN_TYPE_PROXY;
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
102 } else {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
103 switch (type) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
104 case YAHOO_CONN_TYPE_AUTH:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
105 conn->socket = yahoo_connect_host(session, YAHOO_AUTH_HOST,
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
106 YAHOO_AUTH_PORT, &status);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
107 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
108 case YAHOO_CONN_TYPE_MAIN:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
109 conn->socket = yahoo_connect_host(session, YAHOO_PAGER_HOST,
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
110 YAHOO_PAGER_PORT, &status);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
111 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
112 case YAHOO_CONN_TYPE_DUMB:
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
113 conn->socket = yahoo_connect_host(session, YAHOO_DATA_HOST,
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
114 YAHOO_DATA_PORT, &status);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
115 break;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
116 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
117 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
118
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
119 if (conn->socket < 0) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
120 g_free(conn);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
121 return NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
122 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
123
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
124 if (yahoo_socket_notify)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
125 (*yahoo_socket_notify)(session, conn->socket, YAHOO_SOCKET_WRITE, TRUE);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
126 else
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
127 YAHOO_PRINT(session, YAHOO_LOG_CRITICAL, "yahoo_socket_notify not set up");
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
128
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
129 session->connlist = g_list_append(session->connlist, conn);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
130
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
131 return conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
132 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
133
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
134 struct yahoo_conn *yahoo_getconn_type(struct yahoo_session *sess, int type)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
135 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
136 GList *c;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
137 struct yahoo_conn *conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
138
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
139 if (!sess)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
140 return NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
141
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
142 c = sess->connlist;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
143 while (c) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
144 conn = c->data;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
145 if (conn->type == type)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
146 return conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
147 c = g_list_next(c);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
148 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
149
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
150 return NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
151 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
152
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
153 struct yahoo_conn *yahoo_find_conn(struct yahoo_session *sess, int socket)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
154 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
155 GList *c;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
156 struct yahoo_conn *conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
157
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
158 c = sess->connlist;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
159 while (c) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
160 conn = c->data;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
161 if (conn->socket == socket)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
162 return conn;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
163 c = g_list_next(c);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
164 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
165
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
166 return NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
167 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
168
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
169 int yahoo_connect(struct yahoo_session *session, const char *host, int port)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
170 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
171 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
172 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
173
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
174 if (!yahoo_new_conn(session, YAHOO_CONN_TYPE_AUTH, host, port))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
175 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
176
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
177 return 1;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
178 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
179
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
180 int yahoo_major_connect(struct yahoo_session *session, const char *host, int port)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
181 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
182 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
183 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
184
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
185 if (!yahoo_new_conn(session, YAHOO_CONN_TYPE_MAIN, host, port))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
186 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
187
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
188 return 1;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
189 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
190
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
191 void yahoo_close(struct yahoo_session *session, struct yahoo_conn *conn)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
192 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
193 if (!session || !conn)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
194 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
195
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
196 if (!g_list_find(session->connlist, conn))
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
197 return;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
198
1566
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
199 if (yahoo_socket_notify) {
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
200 if (conn->connected)
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
201 (*yahoo_socket_notify)(session, conn->socket, YAHOO_SOCKET_READ, FALSE);
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
202 else
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
203 (*yahoo_socket_notify)(session, conn->socket, YAHOO_SOCKET_WRITE, FALSE);
e9faf5dfdba0 [gaim-migrate @ 1576]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1565
diff changeset
204 }
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
205 close(conn->socket);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
206
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
207 session->connlist = g_list_remove(session->connlist, conn);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
208 if (conn->txqueue)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
209 g_free(conn->txqueue);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
210 g_free(conn);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
211 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
212
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
213 int yahoo_disconnect(struct yahoo_session *session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
214 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
215 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
216 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
217 if (session->name)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
218 g_free(session->name);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
219 yahoo_logoff(session);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
220 session->name = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
221 while (session->connlist)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
222 yahoo_close(session, session->connlist->data);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
223 if (session->cookie)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
224 g_free(session->cookie);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
225 session->cookie = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
226 if (session->login_cookie)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
227 g_free(session->login_cookie);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
228 session->login_cookie = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
229 while (session->ignored) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
230 g_free(session->ignored->data);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
231 session->ignored = g_list_remove(session->ignored, session->ignored->data);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
232 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
233 if (session->identities)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
234 g_strfreev(session->identities);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
235 session->identities = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
236 if (session->login)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
237 g_free(session->login);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
238 session->login = NULL;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
239 while (session->groups) {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
240 struct yahoo_group *grp = session->groups->data;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
241 g_strfreev(grp->buddies);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
242 g_free(grp->name);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
243 g_free(grp);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
244 session->groups = g_list_remove(session->groups, grp);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
245 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
246 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
247 }
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
248
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
249 int yahoo_delete(struct yahoo_session *session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
250 {
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
251 if (!session)
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
252 return 0;
1565
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
253 if (session->proxy_host)
2c66d386be90 [gaim-migrate @ 1575]
Eric Warmenhoven <eric@warmenhoven.org>
parents: 1546
diff changeset
254 g_free(session->proxy_host);
1546
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
255 g_free(session);
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
256 return 0;
92b3dd1e4129 [gaim-migrate @ 1556]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
diff changeset
257 }