Changeset b4e96d6
- Timestamp:
- 2015-03-15T14:41:48Z (10 years ago)
- Children:
- 89e0c94
- Parents:
- c408298
- git-author:
- dequis <dx@…> (14-03-15 12:00:58)
- git-committer:
- dequis <dx@…> (15-03-15 14:41:48)
- Location:
- protocols/msn
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/gw.c
rc408298 rb4e96d6 30 30 void msn_gw_free(struct msn_gw *gw) 31 31 { 32 if (gw->poll_timeout != -1) { 33 b_event_remove(gw->poll_timeout); 34 } 32 35 g_byte_array_free(gw->in, TRUE); 33 36 g_byte_array_free(gw->out, TRUE); … … 66 69 struct msn_gw *gw = req->data; 67 70 71 gw->waiting = FALSE; 72 73 if (!gw->open) { 74 /* the user tried to logout while the request was pending 75 * see msn_ns_close() */ 76 msn_gw_free(gw); 77 return; 78 } 79 80 if (getenv("BITLBEE_DEBUG")) { 81 fprintf(stderr, "\n\x1b[90mHTTP:%s\n", req->reply_body); 82 fprintf(stderr, "\n\x1b[97m\n"); 83 } 84 85 if (req->status_code != 200) { 86 gw->callback(gw->data, -1, B_EV_IO_READ); 87 return; 88 } 89 68 90 if ((value = get_rfc822_header(req->reply_headers, "X-MSN-Messenger", 0))) { 69 91 if (!msn_gw_parse_session_header(gw, value)) { 70 /* XXX handle this */ 92 gw->callback(gw->data, -1, B_EV_IO_READ); 93 g_free(value); 94 return; 71 95 } 72 96 g_free(value); … … 78 102 } 79 103 80 /* XXX handle reply */ 104 if (req->body_size) { 105 g_byte_array_append(gw->in, (const guint8 *) req->reply_body, req->body_size); 106 gw->callback(gw->data, -1, B_EV_IO_READ); 107 } 81 108 82 109 if (gw->poll_timeout != -1) { … … 104 131 105 132 http_dorequest(gw->last_host, gw->port, gw->ssl, request, msn_gw_callback, gw); 133 gw->open = TRUE; 106 134 gw->waiting = TRUE; 107 135 … … 113 141 { 114 142 msn_gw_dorequest(gw, "Action=open&Server=NS"); 115 gw->open = TRUE;116 143 } 117 144 … … 125 152 return FALSE; 126 153 } 154 155 ssize_t msn_gw_read(struct msn_gw *gw, char **buf) 156 { 157 size_t bodylen; 158 if (!gw->open) { 159 return 0; 160 } 161 162 bodylen = gw->in->len; 163 g_byte_array_append(gw->in, (guint8 *) "", 1); /* nullnullnull */ 164 *buf = (char *) g_byte_array_free(gw->in, FALSE); 165 gw->in = g_byte_array_new(); 166 return bodylen; 167 } 168 169 void msn_gw_write(struct msn_gw *gw, char *buf, size_t len) 170 { 171 g_byte_array_append(gw->out, (const guint8 *) buf, len); 172 if (!gw->open) { 173 msn_gw_open(gw); 174 } else if (!gw->waiting) { 175 msn_gw_dorequest(gw, NULL); 176 } 177 } -
protocols/msn/msn.c
rc408298 rb4e96d6 62 62 63 63 if (!server) { 64 imcb_error(ic, "The msn protocol is disabled in this version because most servers disabled MSNP18 over port 1863."); 65 imcb_error(ic, "If you find a working server, you can change the 'server' setting of this account. Good luck!"); 66 imcb_error(ic, "See also: http://ismsndeadyet.com/"); // shameless plug 67 imc_logout(ic, FALSE); 68 return; 64 server = "geo.gateway.messenger.live.com"; 69 65 } 70 66 … … 79 75 md->domaintree = g_tree_new(msn_domaintree_cmp); 80 76 md->fd = -1; 77 md->is_http = TRUE; 81 78 82 79 msn_connections = g_slist_prepend(msn_connections, ic); -
protocols/msn/msn.h
rc408298 rb4e96d6 263 263 const struct msn_status_code *msn_status_by_number(int number); 264 264 265 /* gw.c */ 266 struct msn_gw *msn_gw_new(struct msn_data *md); 267 void msn_gw_free(struct msn_gw *gw); 268 void msn_gw_open(struct msn_gw *gw); 269 ssize_t msn_gw_read(struct msn_gw *gw, char **buf); 270 void msn_gw_write(struct msn_gw *gw, char *buf, size_t len); 271 265 272 #endif //_MSN_H -
protocols/msn/msn_util.c
rc408298 rb4e96d6 168 168 void msn_queue_feed(struct msn_data *h, char *bytes, int st) 169 169 { 170 h->rxq = g_renew(char, h->rxq, h->rxlen + 1024);170 h->rxq = g_renew(char, h->rxq, h->rxlen + st); 171 171 memcpy(h->rxq + h->rxlen, bytes, st); 172 172 h->rxlen += st; … … 229 229 /* If we reached the end of the buffer, there's still an incomplete command there. 230 230 Return and wait for more data. */ 231 if (i == h->rxlen && h->rxq[i - 1] != '\r' && h->rxq[i - 1] != '\n') {231 if (i && i == h->rxlen && h->rxq[i - 1] != '\r' && h->rxq[i - 1] != '\n') { 232 232 break; 233 233 } -
protocols/msn/ns.c
rc408298 rb4e96d6 60 60 61 61 len = strlen(out); 62 st = write(fd, out, len); 62 63 if (md->is_http) { 64 st = len; 65 msn_gw_write(md->gw, out, len); 66 } else { 67 st = write(fd, out, len); 68 } 69 63 70 g_free(out); 64 71 if (st != len) { … … 79 86 } 80 87 81 handler->fd = proxy_connect(host, port, msn_ns_connected, handler); 82 if (handler->fd < 0) { 83 imcb_error(ic, "Could not connect to server"); 84 imc_logout(ic, TRUE); 85 return FALSE; 88 if (handler->is_http) { 89 handler->gw = msn_gw_new(handler); 90 handler->gw->callback = msn_ns_callback; 91 msn_ns_connected(handler, -1, B_EV_IO_READ); 92 } else { 93 handler->fd = proxy_connect(host, port, msn_ns_connected, handler); 94 if (handler->fd < 0) { 95 imcb_error(ic, "Could not connect to server"); 96 imc_logout(ic, TRUE); 97 return FALSE; 98 } 86 99 } 87 100 … … 95 108 struct im_connection *ic = md->ic; 96 109 97 if (source == -1 ) {110 if (source == -1 && !md->is_http) { 98 111 imcb_error(ic, "Could not connect to server"); 99 112 imc_logout(ic, TRUE); … … 121 134 122 135 if (msn_ns_write(ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER)) { 123 handler->inpa = b_input_add(handler->fd, B_EV_IO_READ, msn_ns_callback, handler); 136 if (!handler->is_http) { 137 handler->inpa = b_input_add(handler->fd, B_EV_IO_READ, msn_ns_callback, handler); 138 } 124 139 imcb_log(ic, "Connected to server, waiting for reply"); 125 140 } … … 130 145 void msn_ns_close(struct msn_data *handler) 131 146 { 147 if (handler->gw) { 148 if (handler->gw->waiting) { 149 /* mark it as closed, let the request callback clean it */ 150 handler->gw->open = FALSE; 151 } else { 152 msn_gw_free(handler->gw); 153 } 154 } 132 155 if (handler->fd >= 0) { 133 156 closesocket(handler->fd); … … 148 171 struct msn_data *handler = data; 149 172 struct im_connection *ic = handler->ic; 150 char bytes[1024];173 char *bytes; 151 174 int st; 152 175 153 st = read(handler->fd, bytes, 1024); 176 if (handler->is_http) { 177 st = msn_gw_read(handler->gw, &bytes); 178 } else { 179 bytes = g_malloc(1024); 180 st = read(handler->fd, bytes, 1024); 181 } 182 154 183 if (st <= 0) { 155 184 imcb_error(ic, "Error while reading from server"); … … 159 188 160 189 msn_queue_feed(handler, bytes, st); 190 191 g_free(bytes); 161 192 162 193 /* Ignore ret == 0, it's already disconnected then. */
Note: See TracChangeset
for help on using the changeset viewer.