Changeset 0605498 for protocols/jabber
- Timestamp:
- 2015-08-26T05:41:10Z (9 years ago)
- Branches:
- master
- Children:
- 3c23681
- Parents:
- 3e6cdb6
- git-author:
- dequis <dx@…> (26-08-15 05:08:03)
- git-committer:
- dequis <dx@…> (26-08-15 05:41:10)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/jabber/io.c
r3e6cdb6 r0605498 147 147 } 148 148 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) { 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 { 169 209 imcb_error(ic, "XML stream error"); 170 210 imc_logout(ic, TRUE); 171 211 return FALSE; 172 212 } 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. */ 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)) { 178 238 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 xmltree190 has nifty event handler stuff, it only calls handlers191 when nodes are complete. Since the server should only192 send an opening <stream:stream> tag, we have to check193 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, assume199 this is an old server that can't do SASL200 authentication. */201 if (!set_getbool(&ic->acc->set, "sasl") || !sasl_supported(ic)) {202 /* If there's no version= tag, we suppose203 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 }219 239 } 220 240 } else if (st == 0 || (st < 0 && !ssl_sockerr_again(jd->ssl))) {
Note: See TracChangeset
for help on using the changeset viewer.