src/protocols/jabber/jabber.c

changeset 3074
b6510843df8f
parent 3059
bd4d661482f5
child 3105
8c23b0ec1036
equal deleted inserted replaced
3073:db068034b0bc 3074:b6510843df8f
74 #define DEFAULT_GROUPCHAT "conference.jabber.org" 74 #define DEFAULT_GROUPCHAT "conference.jabber.org"
75 #define DEFAULT_PORT 5222 75 #define DEFAULT_PORT 5222
76 76
77 #define USEROPT_PORT 0 77 #define USEROPT_PORT 0
78 78
79 /*
80 * Note: "was_connected" may seem redundant, but it was needed and I
81 * didn't want to touch the Jabber state stuff not specific to Gaim.
82 */
79 typedef struct gjconn_struct { 83 typedef struct gjconn_struct {
80 /* Core structure */ 84 /* Core structure */
81 pool p; /* Memory allocation pool */ 85 pool p; /* Memory allocation pool */
82 int state; /* Connection state flag */ 86 int state; /* Connection state flag */
87 int was_connected; /* We were once connected */
83 int fd; /* Connection file descriptor */ 88 int fd; /* Connection file descriptor */
84 jid user; /* User info */ 89 jid user; /* User info */
85 char *pass; /* User passwd */ 90 char *pass; /* User passwd */
86 91
87 /* Stream stuff */ 92 /* Stream stuff */
207 212
208 gjc->user = jid_new(p, user); 213 gjc->user = jid_new(p, user);
209 gjc->pass = pstrdup(p, pass); 214 gjc->pass = pstrdup(p, pass);
210 215
211 gjc->state = JCONN_STATE_OFF; 216 gjc->state = JCONN_STATE_OFF;
217 gjc->was_connected = 0;
212 gjc->id = 1; 218 gjc->id = 1;
213 gjc->fd = -1; 219 gjc->fd = -1;
214 220
215 gjc->priv = priv; 221 gjc->priv = priv;
216 222
247 if (!gjc || gjc->state == JCONN_STATE_OFF) 253 if (!gjc || gjc->state == JCONN_STATE_OFF)
248 return; 254 return;
249 255
250 gjab_send_raw(gjc, "</stream:stream>"); 256 gjab_send_raw(gjc, "</stream:stream>");
251 gjc->state = JCONN_STATE_OFF; 257 gjc->state = JCONN_STATE_OFF;
258 gjc->was_connected = 0;
252 close(gjc->fd); 259 close(gjc->fd);
253 gjc->fd = -1; 260 gjc->fd = -1;
254 XML_ParserFree(gjc->parser); 261 XML_ParserFree(gjc->parser);
255 gjc->parser = NULL; 262 gjc->parser = NULL;
256 } 263 }
1399 1406
1400 static void jabber_handlestate(gjconn gjc, int state) 1407 static void jabber_handlestate(gjconn gjc, int state)
1401 { 1408 {
1402 switch (state) { 1409 switch (state) {
1403 case JCONN_STATE_OFF: 1410 case JCONN_STATE_OFF:
1404 hide_login_progress(GJ_GC(gjc), _("Unable to connect")); 1411 if(gjc->was_connected) {
1412 hide_login_progress_error(GJ_GC(gjc), _("Connection lost"));
1413 } else {
1414 hide_login_progress(GJ_GC(gjc), _("Unable to connect"));
1415 }
1405 signoff(GJ_GC(gjc)); 1416 signoff(GJ_GC(gjc));
1406 break; 1417 break;
1407 case JCONN_STATE_CONNECTED: 1418 case JCONN_STATE_CONNECTED:
1419 gjc->was_connected = 1;
1408 set_login_progress(GJ_GC(gjc), 2, _("Connected")); 1420 set_login_progress(GJ_GC(gjc), 2, _("Connected"));
1409 break; 1421 break;
1410 case JCONN_STATE_ON: 1422 case JCONN_STATE_ON:
1411 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method")); 1423 set_login_progress(GJ_GC(gjc), 3, _("Requesting Authentication Method"));
1412 gjab_reqauth(gjc); 1424 gjab_reqauth(gjc);
2802 */ 2814 */
2803 static void jabber_handle_registration_state(gjconn gjc, int state) 2815 static void jabber_handle_registration_state(gjconn gjc, int state)
2804 { 2816 {
2805 switch (state) { 2817 switch (state) {
2806 case JCONN_STATE_OFF: 2818 case JCONN_STATE_OFF:
2807 hide_login_progress(GJ_GC(gjc), _("Unable to connect")); 2819 if(gjc->was_connected) {
2820 hide_login_progress_error(GJ_GC(gjc), _("Connection lost"));
2821 } else {
2822 hide_login_progress(GJ_GC(gjc), _("Unable to connect"));
2823 }
2808 signoff(GJ_GC(gjc)); 2824 signoff(GJ_GC(gjc));
2809 break; 2825 break;
2810 case JCONN_STATE_CONNECTED: 2826 case JCONN_STATE_CONNECTED:
2827 gjc->was_connected = 1;
2811 /* 2828 /*
2812 * TBD? 2829 * TBD?
2813 set_login_progress(GJ_GC(gjc), 2, _("Connected")); 2830 set_login_progress(GJ_GC(gjc), 2, _("Connected"));
2814 */ 2831 */
2815 break; 2832 break;

mercurial