]> andersk Git - libfaim.git/blob - utils/faimtest/login.c
- Mon Sep 10 06:15:43 PDT 2001
[libfaim.git] / utils / faimtest / login.c
1 /*
2  * Most of the stuff used for login.
3  *
4  */
5
6 #include "faimtest.h"
7
8 int logout(aim_session_t *sess)
9 {
10         struct faimtest_priv *priv = (struct faimtest_priv *)sess->aux_data;
11
12         if (priv->ohcaptainmycaptain)
13                 aim_send_im(sess, aim_getconn_type(sess, AIM_CONN_TYPE_BOS), priv->ohcaptainmycaptain, 0, "ta ta...");
14
15         aim_session_kill(sess);
16
17         if (faimtest_init() == -1)
18                 dprintf("faimtest_init failed\n");
19
20         return 0;
21 }
22
23 static int faimtest_parse_login(aim_session_t *sess, aim_frame_t *fr, ...)
24 {
25         struct faimtest_priv *priv = (struct faimtest_priv *)sess->aux_data;
26         struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD;
27         char *key;
28         va_list ap;
29
30         va_start(ap, fr);
31         key = va_arg(ap, char *);
32         va_end(ap);
33
34         aim_send_login(sess, fr->conn, priv->screenname, priv->password, &info, key);
35
36         return 1;
37 }
38
39 /* Does this thing even work anymore? */
40 static int faimtest_debugconn_connect(aim_session_t *sess, aim_frame_t *fr, ...)
41 {
42
43         dprintf("faimtest: connecting to an aimdebugd!\n");
44
45         /* convert the authorizer connection to a BOS connection */
46         fr->conn->type = AIM_CONN_TYPE_BOS;
47
48 #if 0
49         aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
50 #endif
51
52         /* tell the aimddebugd we're ready */
53         aim_debugconn_sendconnect(sess, fr->conn); 
54
55         /* go right into main loop (don't open a BOS connection, etc) */
56         return 1;
57 }
58
59
60 /*
61  * This marks the end of authorization, and probably the beginning of BOS.
62  *
63  * If there was an error, everything ends here.  Otherwise, we use the cookie
64  * and IP from the authorizer to connect to our assigned BOS.  This connection
65  * will be used for the major stuff.  New connections may be opened later for
66  * things like chat.
67  *
68  */
69 static int faimtest_parse_authresp(aim_session_t *sess, aim_frame_t *fr, ...)
70 {
71         va_list ap;
72         aim_conn_t *bosconn;
73         char *sn, *bosip, *errurl, *email;
74         fu8_t *cookie;
75         int errorcode, regstatus;
76         int latestbuild, latestbetabuild;
77         char *latestrelease, *latestbeta;
78         char *latestreleaseurl, *latestbetaurl;
79         char *latestreleaseinfo, *latestbetainfo;
80
81         va_start(ap, fr);
82         sn = va_arg(ap, char *);
83         errorcode = va_arg(ap, int);
84         errurl = va_arg(ap, char *);
85         regstatus = va_arg(ap, int);
86         email = va_arg(ap, char *);
87         bosip = va_arg(ap, char *);
88         cookie = va_arg(ap, fu8_t *);
89
90         latestrelease = va_arg(ap, char *);
91         latestbuild = va_arg(ap, int);
92         latestreleaseurl = va_arg(ap, char *);
93         latestreleaseinfo = va_arg(ap, char *);
94
95         latestbeta = va_arg(ap, char *);
96         latestbetabuild = va_arg(ap, int);
97         latestbetaurl = va_arg(ap, char *);
98         latestbetainfo = va_arg(ap, char *);
99
100         va_end(ap);
101
102         dvprintf("Screen name: %s\n", sn);
103
104         /*
105          * Check for error.
106          */
107         if (errorcode || !bosip || !cookie) {
108                 dvprintf("Login Error Code 0x%04x\n", errorcode);
109                 dvprintf("Error URL: %s\n", errurl);
110                 aim_conn_kill(sess, &fr->conn);
111                 return 1;
112         }
113
114         dvprintf("Reg status: %2d\n", regstatus);
115         dvprintf("Email: %s\n", email);
116         dvprintf("BOS IP: %s\n", bosip);
117
118         if (latestbeta)
119                 dvprintf("Latest beta version: %s, build %d, at %s (more info at %s)\n", latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
120
121         if (latestrelease)
122                 dvprintf("Latest released version: %s, build %d, at %s (more info at %s)\n", latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo);
123
124         dprintf("Closing auth connection...\n");
125         aim_conn_kill(sess, &fr->conn);
126
127         if (!(bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, bosip))) {
128                 dprintf("could not connect to BOS: internal error\n");
129                 return 1;
130         } else if (bosconn->status & AIM_CONN_STATUS_CONNERR) { 
131                 dprintf("could not connect to BOS\n");
132                 aim_conn_kill(sess, &bosconn);
133                 return 1;
134         }
135
136         addcb_bos(sess, bosconn);
137
138         aim_auth_sendcookie(sess, bosconn, cookie);
139
140         return 1;
141 }
142
143 int login(aim_session_t *sess, const char *sn, const char *passwd)
144 {
145         struct faimtest_priv *priv = (struct faimtest_priv *)sess->aux_data;
146         aim_conn_t *authconn;
147
148         if (sn)
149                 priv->screenname = strdup(sn);
150         if (passwd)
151                 priv->password = strdup(passwd);
152
153         if (priv->proxy)
154                 aim_setupproxy(sess, priv->proxy, priv->proxyusername, priv->proxypass);
155
156         if (!priv->screenname || !priv->password) {
157                 dprintf("need SN and password\n");
158                 return -1;
159         }
160
161         if (!(authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, 
162                         priv->server ? priv->server : FAIM_LOGIN_SERVER))) {
163                 dprintf("internal connection error during login\n");
164                 return -1;
165         } else if (authconn->fd == -1) {
166
167                 if (authconn->status & AIM_CONN_STATUS_RESOLVERR) {
168                         dprintf("could not resolve authorizer name\n");
169                 } else if (authconn->status & AIM_CONN_STATUS_CONNERR) {
170                         dprintf("could not connect to authorizer\n");
171                 }
172                 aim_conn_kill(sess, &authconn);
173
174                 return -1;
175         }
176
177         aim_conn_addhandler(sess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_FLAPVER, faimtest_flapversion, 0);
178         aim_conn_addhandler(sess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, faimtest_conncomplete, 0);
179         aim_conn_addhandler(sess, authconn, 0x0017, 0x0007, faimtest_parse_login, 0);
180         aim_conn_addhandler(sess, authconn, 0x0017, 0x0003, faimtest_parse_authresp, 0);    
181
182         aim_conn_addhandler(sess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT, faimtest_debugconn_connect, 0);
183
184         /* If the connection is in progress, this will just be queued */
185         aim_request_login(sess, authconn, priv->screenname);
186
187         dprintf("login request sent\n");
188
189         return 0;
190 }
191
192
This page took 0.106757 seconds and 5 git commands to generate.