- Timestamp:
- 2015-04-11T19:36:13Z (10 years ago)
- Branches:
- master
- Children:
- 951aefd
- Parents:
- 002fede
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/msn/ns.c
r002fede r5fbf815 38 38 static void msn_ns_send_adl_start(struct im_connection *ic); 39 39 static void msn_ns_send_adl(struct im_connection *ic); 40 static void msn_ns_structured_message(struct msn_data * handler, char *msg, int msglen, char **cmd);41 static void msn_ns_sdg(struct msn_data * handler, char *who, char **parts, char *action);42 static void msn_ns_nfy(struct msn_data * handler, char *who, char **parts, char *action, gboolean is_put);40 static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd); 41 static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action); 42 static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put); 43 43 44 44 int msn_ns_write(struct im_connection *ic, int fd, const char *fmt, ...) … … 83 83 gboolean msn_ns_connect(struct im_connection *ic, const char *host, int port) 84 84 { 85 struct msn_data * handler= ic->proto_data;86 87 if ( handler->fd >= 0) {88 closesocket( handler->fd);89 } 90 91 if ( handler->is_http) {92 handler->gw = msn_gw_new(handler);93 handler->gw->callback = msn_ns_callback;94 msn_ns_connected( handler, -1, B_EV_IO_READ);85 struct msn_data *md = ic->proto_data; 86 87 if (md->fd >= 0) { 88 closesocket(md->fd); 89 } 90 91 if (md->is_http) { 92 md->gw = msn_gw_new(md); 93 md->gw->callback = msn_ns_callback; 94 msn_ns_connected(md, -1, B_EV_IO_READ); 95 95 } else { 96 handler->fd = proxy_connect(host, port, msn_ns_connected, handler);97 if ( handler->fd < 0) {96 md->fd = proxy_connect(host, port, msn_ns_connected, md); 97 if (md->fd < 0) { 98 98 imcb_error(ic, "Could not connect to server"); 99 99 imc_logout(ic, TRUE); … … 108 108 { 109 109 struct msn_data *md = data; 110 struct msn_data *handler = md;111 110 struct im_connection *ic = md->ic; 112 111 … … 117 116 } 118 117 119 g_free( handler->rxq);120 handler->rxlen = 0;121 handler->rxq = g_new0(char, 1);118 g_free(md->rxq); 119 md->rxlen = 0; 120 md->rxq = g_new0(char, 1); 122 121 123 122 if (md->uuid == NULL) { … … 137 136 138 137 if (msn_ns_write(ic, source, "VER %d %s CVR0\r\n", ++md->trId, MSNP_VER)) { 139 if (! handler->is_http) {140 handler->inpa = b_input_add(handler->fd, B_EV_IO_READ, msn_ns_callback, handler);138 if (!md->is_http) { 139 md->inpa = b_input_add(md->fd, B_EV_IO_READ, msn_ns_callback, md); 141 140 } 142 141 imcb_log(ic, "Connected to server, waiting for reply"); … … 146 145 } 147 146 148 void msn_ns_close(struct msn_data * handler)149 { 150 if ( handler->gw) {151 if ( handler->gw->waiting) {147 void msn_ns_close(struct msn_data *md) 148 { 149 if (md->gw) { 150 if (md->gw->waiting) { 152 151 /* mark it as closed, let the request callback clean it */ 153 handler->gw->open = FALSE;152 md->gw->open = FALSE; 154 153 } else { 155 msn_gw_free( handler->gw);156 } 157 } 158 if ( handler->fd >= 0) {159 closesocket( handler->fd);160 b_event_remove( handler->inpa);161 } 162 163 handler->fd = handler->inpa = -1;164 g_free( handler->rxq);165 g_free( handler->cmd_text);166 167 handler->rxlen = 0;168 handler->rxq = NULL;169 handler->cmd_text = NULL;154 msn_gw_free(md->gw); 155 } 156 } 157 if (md->fd >= 0) { 158 closesocket(md->fd); 159 b_event_remove(md->inpa); 160 } 161 162 md->fd = md->inpa = -1; 163 g_free(md->rxq); 164 g_free(md->cmd_text); 165 166 md->rxlen = 0; 167 md->rxq = NULL; 168 md->cmd_text = NULL; 170 169 } 171 170 172 171 static gboolean msn_ns_callback(gpointer data, gint source, b_input_condition cond) 173 172 { 174 struct msn_data * handler= data;175 struct im_connection *ic = handler->ic;173 struct msn_data *md = data; 174 struct im_connection *ic = md->ic; 176 175 char *bytes; 177 176 int st; 178 177 179 if ( handler->is_http) {180 st = msn_gw_read( handler->gw, &bytes);178 if (md->is_http) { 179 st = msn_gw_read(md->gw, &bytes); 181 180 } else { 182 181 bytes = g_malloc(1024); 183 st = read( handler->fd, bytes, 1024);182 st = read(md->fd, bytes, 1024); 184 183 } 185 184 … … 190 189 } 191 190 192 msn_queue_feed( handler, bytes, st);191 msn_queue_feed(md, bytes, st); 193 192 194 193 g_free(bytes); 195 194 196 195 /* Ignore ret == 0, it's already disconnected then. */ 197 msn_handler( handler);196 msn_handler(md); 198 197 199 198 return TRUE; … … 201 200 } 202 201 203 int msn_ns_command(struct msn_data *handler, char **cmd, int num_parts) 204 { 205 struct im_connection *ic = handler->ic; 206 struct msn_data *md = handler; 202 int msn_ns_command(struct msn_data *md, char **cmd, int num_parts) 203 { 204 struct im_connection *ic = md->ic; 207 205 208 206 if (num_parts == 0) { … … 218 216 } 219 217 220 return(msn_ns_write(ic, handler->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s VmVyc2lvbjogMQ0KWGZyQ291bnQ6IDINClhmclNlbnRVVENUaW1lOiA2MzU2MTQ3OTU5NzgzOTAwMDANCklzR2VvWGZyOiB0cnVlDQo=\r\n",218 return(msn_ns_write(ic, md->fd, "CVR %d 0x0409 mac 10.2.0 ppc macmsgs 3.5.1 macmsgs %s VmVyc2lvbjogMQ0KWGZyQ291bnQ6IDINClhmclNlbnRVVENUaW1lOiA2MzU2MTQ3OTU5NzgzOTAwMDANCklzR2VvWGZyOiB0cnVlDQo=\r\n", 221 219 ++md->trId, ic->acc->user)); 222 220 } else if (strcmp(cmd[0], "CVR") == 0) { 223 221 /* We don't give a damn about the information we just received */ 224 return msn_ns_write(ic, handler->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user);222 return msn_ns_write(ic, md->fd, "USR %d SSO I %s\r\n", ++md->trId, ic->acc->user); 225 223 } else if (strcmp(cmd[0], "XFR") == 0) { 226 224 char *server; … … 228 226 229 227 if (num_parts >= 6 && strcmp(cmd[2], "NS") == 0) { 230 b_event_remove( handler->inpa);231 handler->inpa = -1;228 b_event_remove(md->inpa); 229 md->inpa = -1; 232 230 233 231 server = strchr(cmd[3], ':'); … … 276 274 } 277 275 278 handler->msglen = atoi(cmd[3]);279 280 if ( handler->msglen <= 0) {276 md->msglen = atoi(cmd[3]); 277 278 if (md->msglen <= 0) { 281 279 imcb_error(ic, "Syntax error"); 282 280 imc_logout(ic, TRUE); … … 288 286 return msn_ns_finish_login(ic); 289 287 } else if (num_parts >= 3) { 290 handler->msglen = atoi(cmd[2]);288 md->msglen = atoi(cmd[2]); 291 289 } 292 290 } else if (strcmp(cmd[0], "CHL") == 0) { … … 327 325 /* Coming up is cmd[2] bytes of stuff we're supposed to 328 326 censore. Meh. */ 329 handler->msglen = atoi(cmd[2]);327 md->msglen = atoi(cmd[2]); 330 328 } else if ((strcmp(cmd[0], "NFY") == 0) || (strcmp(cmd[0], "SDG") == 0)) { 331 329 if (num_parts >= 3) { 332 handler->msglen = atoi(cmd[2]);330 md->msglen = atoi(cmd[2]); 333 331 } 334 332 } else if (strcmp(cmd[0], "PUT") == 0) { 335 333 if (num_parts >= 4) { 336 handler->msglen = atoi(cmd[3]);334 md->msglen = atoi(cmd[3]); 337 335 } 338 336 } else if (strcmp(cmd[0], "NOT") == 0) { 339 337 if (num_parts >= 2) { 340 handler->msglen = atoi(cmd[1]);338 md->msglen = atoi(cmd[1]); 341 339 } 342 340 } else if (strcmp(cmd[0], "QNG") == 0) { … … 355 353 /* Oh yes, errors can have payloads too now. Discard them for now. */ 356 354 if (num_parts >= 3) { 357 handler->msglen = atoi(cmd[2]);355 md->msglen = atoi(cmd[2]); 358 356 } 359 357 } else { … … 364 362 } 365 363 366 int msn_ns_message(struct msn_data * handler, char *msg, int msglen, char **cmd, int num_parts)367 { 368 struct im_connection *ic = handler->ic;364 int msn_ns_message(struct msn_data *md, char *msg, int msglen, char **cmd, int num_parts) 365 { 366 struct im_connection *ic = md->ic; 369 367 char *body; 370 368 int blen = 0; … … 493 491 } 494 492 } else if ((strcmp(cmd[0], "SDG") == 0) || (strcmp(cmd[0], "NFY") == 0)) { 495 msn_ns_structured_message( handler, msg, msglen, cmd);493 msn_ns_structured_message(md, msg, msglen, cmd); 496 494 } 497 495 … … 499 497 } 500 498 501 static void msn_ns_structured_message(struct msn_data * handler, char *msg, int msglen, char **cmd)499 static void msn_ns_structured_message(struct msn_data *md, char *msg, int msglen, char **cmd) 502 500 { 503 501 char **parts = NULL; … … 519 517 520 518 if ((strcmp(cmd[0], "SDG") == 0) && (action = get_rfc822_header(parts[2], "Message-Type", 0))) { 521 msn_ns_sdg( handler, who, parts, action);519 msn_ns_sdg(md, who, parts, action); 522 520 523 521 } else if ((strcmp(cmd[0], "NFY") == 0) && (action = get_rfc822_header(parts[2], "Uri", 0))) { 524 522 gboolean is_put = (strcmp(cmd[1], "PUT") == 0); 525 msn_ns_nfy( handler, who, parts, action, is_put);523 msn_ns_nfy(md, who, parts, action, is_put); 526 524 } 527 525 … … 533 531 } 534 532 535 static void msn_ns_sdg(struct msn_data * handler, char *who, char **parts, char *action)536 { 537 struct im_connection *ic = handler->ic;533 static void msn_ns_sdg(struct msn_data *md, char *who, char **parts, char *action) 534 { 535 struct im_connection *ic = md->ic; 538 536 539 537 if (strcmp(action, "Control/Typing") == 0) { … … 544 542 } 545 543 546 static void msn_ns_nfy(struct msn_data * handler, char *who, char **parts, char *action, gboolean is_put)547 { 548 struct im_connection *ic = handler->ic;544 static void msn_ns_nfy(struct msn_data *md, char *who, char **parts, char *action, gboolean is_put) 545 { 546 struct im_connection *ic = md->ic; 549 547 struct xt_node *body = NULL; 550 548 struct xt_node *s = NULL;
Note: See TracChangeset
for help on using the changeset viewer.