Changes in protocols/jabber/io.c [0605498:5ebff60]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/io.c
r0605498 r5ebff60 147 147 } 148 148 149 static gboolean jabber_feed_input(struct im_connection *ic, char *buf, int size) 150 { 151 struct jabber_data *jd = ic->proto_data; 152 153 /* Allow not passing a size for debugging purposes. 154 * This never happens when reading from the socket */ 155 if (size == -1) { 156 size = strlen(buf); 157 } 158 159 /* Parse. */ 160 if (xt_feed(jd->xt, buf, size) < 0) { 161 imcb_error(ic, "XML stream error"); 162 imc_logout(ic, TRUE); 163 return FALSE; 164 } 165 166 /* Execute all handlers. */ 167 if (!xt_handle(jd->xt, NULL, 1)) { 168 /* Don't do anything, the handlers should have 169 aborted the connection already. */ 170 return FALSE; 171 } 172 173 if (jd->flags & JFLAG_STREAM_RESTART) { 174 jd->flags &= ~JFLAG_STREAM_RESTART; 175 jabber_start_stream(ic); 176 } 177 178 /* Garbage collection. */ 179 xt_cleanup(jd->xt, NULL, 1); 180 181 /* This is a bit hackish, unfortunately. Although xmltree 182 has nifty event handler stuff, it only calls handlers 183 when nodes are complete. Since the server should only 184 send an opening <stream:stream> tag, we have to check 185 this by hand. :-( */ 186 if (!(jd->flags & JFLAG_STREAM_STARTED) && jd->xt && jd->xt->root) { 187 if (g_strcasecmp(jd->xt->root->name, "stream:stream") == 0) { 188 jd->flags |= JFLAG_STREAM_STARTED; 189 190 /* If there's no version attribute, assume 191 this is an old server that can't do SASL 192 authentication. */ 193 if (!set_getbool(&ic->acc->set, "sasl") || !sasl_supported(ic)) { 194 /* If there's no version= tag, we suppose 195 this server does NOT implement: XMPP 1.0, 196 SASL and TLS. */ 197 if (set_getbool(&ic->acc->set, "tls")) { 198 imcb_error(ic, "TLS is turned on for this " 199 "account, but is not supported by this server"); 200 imc_logout(ic, FALSE); 201 return FALSE; 202 } else { 203 if (!jabber_init_iq_auth(ic)) { 204 return FALSE; 205 } 206 } 207 } 208 } else { 149 static gboolean jabber_read_callback(gpointer data, gint fd, b_input_condition cond) 150 { 151 struct im_connection *ic = data; 152 struct jabber_data *jd = ic->proto_data; 153 char buf[512]; 154 int st; 155 156 if (jd->fd == -1) { 157 return FALSE; 158 } 159 160 if (jd->ssl) { 161 st = ssl_read(jd->ssl, buf, sizeof(buf)); 162 } else { 163 st = read(jd->fd, buf, sizeof(buf)); 164 } 165 166 if (st > 0) { 167 /* Parse. */ 168 if (xt_feed(jd->xt, buf, st) < 0) { 209 169 imcb_error(ic, "XML stream error"); 210 170 imc_logout(ic, TRUE); 211 171 return FALSE; 212 172 } 213 } 214 215 return TRUE; 216 } 217 218 219 static gboolean jabber_read_callback(gpointer data, gint fd, b_input_condition cond) 220 { 221 struct im_connection *ic = data; 222 struct jabber_data *jd = ic->proto_data; 223 char buf[512]; 224 int st; 225 226 if (jd->fd == -1) { 227 return FALSE; 228 } 229 230 if (jd->ssl) { 231 st = ssl_read(jd->ssl, buf, sizeof(buf)); 232 } else { 233 st = read(jd->fd, buf, sizeof(buf)); 234 } 235 236 if (st > 0) { 237 if (!jabber_feed_input(ic, buf, st)) { 173 174 /* Execute all handlers. */ 175 if (!xt_handle(jd->xt, NULL, 1)) { 176 /* Don't do anything, the handlers should have 177 aborted the connection already. */ 238 178 return FALSE; 179 } 180 181 if (jd->flags & JFLAG_STREAM_RESTART) { 182 jd->flags &= ~JFLAG_STREAM_RESTART; 183 jabber_start_stream(ic); 184 } 185 186 /* Garbage collection. */ 187 xt_cleanup(jd->xt, NULL, 1); 188 189 /* This is a bit hackish, unfortunately. Although xmltree 190 has nifty event handler stuff, it only calls handlers 191 when nodes are complete. Since the server should only 192 send an opening <stream:stream> tag, we have to check 193 this by hand. :-( */ 194 if (!(jd->flags & JFLAG_STREAM_STARTED) && jd->xt && jd->xt->root) { 195 if (g_strcasecmp(jd->xt->root->name, "stream:stream") == 0) { 196 jd->flags |= JFLAG_STREAM_STARTED; 197 198 /* If there's no version attribute, assume 199 this is an old server that can't do SASL 200 authentication. */ 201 if (!set_getbool(&ic->acc->set, "sasl") || !sasl_supported(ic)) { 202 /* If there's no version= tag, we suppose 203 this server does NOT implement: XMPP 1.0, 204 SASL and TLS. */ 205 if (set_getbool(&ic->acc->set, "tls")) { 206 imcb_error(ic, "TLS is turned on for this " 207 "account, but is not supported by this server"); 208 imc_logout(ic, FALSE); 209 return FALSE; 210 } else { 211 return jabber_init_iq_auth(ic); 212 } 213 } 214 } else { 215 imcb_error(ic, "XML stream error"); 216 imc_logout(ic, TRUE); 217 return FALSE; 218 } 239 219 } 240 220 } else if (st == 0 || (st < 0 && !ssl_sockerr_again(jd->ssl))) {
Note: See TracChangeset
for help on using the changeset viewer.