comparison mcabber/src/jabglue.c @ 112:edb5591e2e64

[/trunk] Changeset 126 by mikael * Fix keepalive.
author mikael
date Sun, 24 Apr 2005 17:38:48 +0000
parents 60eac956ce18
children 8ac67e951eab
comparison
equal deleted inserted replaced
111:d896962c16fa 112:edb5591e2e64
29 29
30 #define JABBERPORT 5222 30 #define JABBERPORT 5222
31 #define JABBERSSLPORT 5223 31 #define JABBERSSLPORT 5223
32 32
33 jconn jc; 33 jconn jc;
34 time_t LastPingTime;
35 unsigned int KeepaliveDelay;
34 static int s_id = 1; // FIXME which use?? 36 static int s_id = 1; // FIXME which use??
35 static int regmode, regdone; 37 static int regmode, regdone;
38 unsigned char online;
36 39
37 char imstatus2char[imstatus_size] = { 40 char imstatus2char[imstatus_size] = {
38 '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a' 41 '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a'
39 }; 42 };
40 43
114 jab_logger(jc, file_logger); 117 jab_logger(jc, file_logger);
115 jab_packet_handler(jc, &packethandler); 118 jab_packet_handler(jc, &packethandler);
116 jab_state_handler(jc, &statehandler); 119 jab_state_handler(jc, &statehandler);
117 120
118 if (jc->user) { 121 if (jc->user) {
119 //fonline = TRUE; 122 online = TRUE;
120 jstate = STATE_CONNECTING; 123 jstate = STATE_CONNECTING;
121 statehandler(0, -1); 124 statehandler(0, -1);
122 jab_start(jc); 125 jab_start(jc);
123 } 126 }
124 127
128 void jb_disconnect(void) 131 void jb_disconnect(void)
129 { 132 {
130 statehandler(jc, JCONN_STATE_OFF); 133 statehandler(jc, JCONN_STATE_OFF);
131 } 134 }
132 135
136 inline void jb_reset_keepalive()
137 {
138 time(&LastPingTime);
139 }
140
133 void jb_keepalive() 141 void jb_keepalive()
134 { 142 {
135 if (jc) { 143 if (jc) {
136 // XXX Only if connected... 144 // XXX Only if connected...
137 jab_send_raw(jc, " "); 145 jab_send_raw(jc, " \t ");
138 } 146 scr_LogPrint("Sent keepalive");
147 }
148 jb_reset_keepalive();
149 }
150
151 void jb_set_keepalive_delay(unsigned int delay)
152 {
153 KeepaliveDelay = delay;
139 } 154 }
140 155
141 void jb_main() 156 void jb_main()
142 { 157 {
143 xmlnode x, z; 158 xmlnode x, z;
144 char *cid; 159 char *cid;
145 160
161 if (!online)
162 return;
146 if (jc && jc->state == JCONN_STATE_CONNECTING) { 163 if (jc && jc->state == JCONN_STATE_CONNECTING) {
147 jab_start(jc); 164 jab_start(jc);
148 return; 165 return;
149 } 166 }
150 167
165 jstate = STATE_GETAUTH; 182 jstate = STATE_GETAUTH;
166 } 183 }
167 184
168 if (!jc || jc->state == JCONN_STATE_OFF) { 185 if (!jc || jc->state == JCONN_STATE_OFF) {
169 scr_LogPrint("Unable to connect to the server"); 186 scr_LogPrint("Unable to connect to the server");
170 // fonline = FALSE; 187 online = FALSE;
171 } 188 }
172 } 189 }
173 190
174 if (!jc) { 191 if (!jc) {
175 statehandler(jc, JCONN_STATE_OFF); 192 statehandler(jc, JCONN_STATE_OFF);
176 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { 193 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
177 statehandler(jc, JCONN_STATE_OFF); 194 statehandler(jc, JCONN_STATE_OFF);
195 }
196
197 // Keepalive
198 if (KeepaliveDelay) {
199 time_t now;
200 time(&now);
201 if (now > LastPingTime + KeepaliveDelay)
202 jb_keepalive();
178 } 203 }
179 } 204 }
180 205
181 void setjabberstatus(enum imstatus st, char *msg) 206 void setjabberstatus(enum imstatus st, char *msg)
182 { 207 {
360 ut_WriteLog("StateHandler called (state=%d).\n", state); 385 ut_WriteLog("StateHandler called (state=%d).\n", state);
361 386
362 switch(state) { 387 switch(state) {
363 case JCONN_STATE_OFF: 388 case JCONN_STATE_OFF:
364 389
365 /* jhook.flogged = jhook.fonline = FALSE; */ 390 online = FALSE;
366 391
367 if (previous_state != JCONN_STATE_OFF) { 392 if (previous_state != JCONN_STATE_OFF) {
368 scr_LogPrint("+ JCONN_STATE_OFF"); 393 scr_LogPrint("+ JCONN_STATE_OFF");
369 /* 394 /*
370 jhook.roster.clear(); 395 jhook.roster.clear();
381 scr_LogPrint("+ JCONN_STATE_AUTH"); 406 scr_LogPrint("+ JCONN_STATE_AUTH");
382 break; 407 break;
383 408
384 case JCONN_STATE_ON: 409 case JCONN_STATE_ON:
385 scr_LogPrint("+ JCONN_STATE_ON"); 410 scr_LogPrint("+ JCONN_STATE_ON");
386 // if (regmode) jhook.fonline = TRUE; 411 online = TRUE;
387 break; 412 break;
388 413
389 case JCONN_STATE_CONNECTING: 414 case JCONN_STATE_CONNECTING:
390 scr_LogPrint("+ JCONN_STATE_CONNECTING"); 415 scr_LogPrint("+ JCONN_STATE_CONNECTING");
391 break; 416 break;
405 char *ns=NULL; 430 char *ns=NULL;
406 char *id=NULL; 431 char *id=NULL;
407 enum imstatus ust; 432 enum imstatus ust;
408 // int npos; 433 // int npos;
409 434
435 jb_reset_keepalive(); // reset keepalive delay
410 jpacket_reset(packet); 436 jpacket_reset(packet);
411 437
412 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p; 438 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
413 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p; 439 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
414 440