static void email_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { MsnSession *session; PurpleConnection *gc; GHashTable *table; char *from, *subject, *tmp; session = cmdproc->session; gc = session->account->gc; if (!purple_account_get_check_mail (session->account)) return; if (strcmp(msg->remote_user, "Hotmail")) { pecan_warning ("unofficial message"); return; } if (!session->passport_info.mail_url) { pecan_error ("no url"); return; } table = msn_message_get_hashtable_from_body(msg); from = subject = NULL; tmp = g_hash_table_lookup(table, "From"); if (tmp != NULL) from = purple_mime_decode_field(tmp); tmp = g_hash_table_lookup(table, "Subject"); if (tmp != NULL) subject = purple_mime_decode_field(tmp); /** @todo go to the extact email */ purple_notify_email(gc, (subject != NULL ? subject : ""), (from != NULL ? from : ""), msn_session_get_username (session), session->passport_info.mail_url, NULL, NULL); g_free(from); g_free(subject); g_hash_table_destroy(table); }
static void system_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { GHashTable *table; const char *type_s; if (strcmp(msg->remote_user, "Hotmail")) { pecan_warning ("unofficial message"); return; } table = msn_message_get_hashtable_from_body(msg); if ((type_s = g_hash_table_lookup(table, "Type")) != NULL) { int type = atoi(type_s); char buf[MSN_BUF_LEN]; int minutes; switch (type) { case 1: minutes = atoi(g_hash_table_lookup(table, "Arg1")); g_snprintf(buf, sizeof(buf), dngettext(PACKAGE, "The MSN server will shut down for maintenance " "in %d minute. You will automatically be " "signed out at that time. Please finish any " "conversations in progress.\n\nAfter the " "maintenance has been completed, you will be " "able to successfully sign in.", "The MSN server will shut down for maintenance " "in %d minutes. You will automatically be " "signed out at that time. Please finish any " "conversations in progress.\n\nAfter the " "maintenance has been completed, you will be " "able to successfully sign in.", minutes), minutes); default: break; } if (*buf != '\0') purple_notify_info(cmdproc->session->account->gc, NULL, buf, NULL); } g_hash_table_destroy(table); }
static void profile_msg(MsnCmdProc *cmdproc, MsnMessage *msg) { MsnSession *session; const char *value; session = cmdproc->session; if (strcmp(msg->remote_user, "Hotmail")) { pecan_warning ("unofficial message"); return; } if ((value = msn_message_get_attr(msg, "kv")) != NULL) { g_free(session->passport_info.kv); session->passport_info.kv = g_strdup(value); } if ((value = msn_message_get_attr(msg, "sid")) != NULL) { g_free(session->passport_info.sid); session->passport_info.sid = g_strdup(value); } if ((value = msn_message_get_attr(msg, "MSPAuth")) != NULL) { g_free(session->passport_info.mspauth); session->passport_info.mspauth = g_strdup(value); } if ((value = msn_message_get_attr(msg, "ClientIP")) != NULL) { g_free(session->passport_info.client_ip); session->passport_info.client_ip = g_strdup(value); } if ((value = msn_message_get_attr(msg, "ClientPort")) != NULL) session->passport_info.client_port = g_ntohs(atoi(value)); if ((value = msn_message_get_attr(msg, "LoginTime")) != NULL) session->passport_info.sl = atol(value); if ((value = msn_message_get_attr(msg, "EmailEnabled")) != NULL) session->passport_info.email_enabled = atol(value); }
void msn_history_add (MsnHistory *history, MsnTransaction *trans) { GQueue *queue; g_return_if_fail (history); g_return_if_fail (trans); queue = history->queue; trans->trId = history->trId++; g_queue_push_tail (queue, trans); if (queue->length > MSN_HIST_ELEMS) { pecan_warning ("dropping transaction"); trans = g_queue_pop_head (queue); msn_transaction_destroy (trans); } }
static void initial_mdata_msg (MsnCmdProc *cmdproc, MsnMessage *msg) { MsnSession *session; PurpleConnection *gc; GHashTable *table; session = cmdproc->session; gc = session->account->gc; if (strcmp (msg->remote_user, "Hotmail")) { pecan_warning ("unofficial message"); return; } table = msn_message_get_hashtable_from_body (msg); { gchar *mdata; mdata = g_hash_table_lookup (table, "Mail-Data"); if (mdata) { gchar *iu = NULL; const gchar *start; const gchar *end; guint len; len = strlen (mdata); start = g_strstr_len (mdata, len, "<IU>"); if (start) { start += strlen ("<IU>"); end = g_strstr_len (start, len - (start - mdata), "</IU>"); if (end > start) iu = g_strndup (start, end - start); } if (iu) { session->inbox_unread_count = atoi (iu); g_free (iu); } do { start = g_strstr_len (start, len - (start - mdata), "<M>"); if (start) { start += strlen ("<M>"); end = g_strstr_len (start, len - (start - mdata), "</M>"); if (end > start) { gchar *read_set; #if 0 { gchar *field; gchar *tmp; tmp = pecan_get_xml_field ("N", start, end); field = purple_mime_decode_field (tmp); g_print ("field={%s}\n", field); g_free (field); g_free (tmp); } #endif read_set = pecan_get_xml_field ("RS", start, end); if (strcmp (read_set, "0") == 0) { gchar *passport; gchar *message_id; passport = pecan_get_xml_field ("E", start, end); message_id = pecan_get_xml_field ("I", start, end); pecan_oim_session_request (session->oim_session, passport, message_id); g_free (passport); g_free (message_id); } g_free (read_set); start = end + strlen ("</M>"); } } } while (start); } if (purple_account_get_check_mail (session->account) && session->passport_info.email_enabled == 1) { msn_cmdproc_send (cmdproc, "URL", "%s", "INBOX"); } } g_hash_table_destroy(table); }
void msn_slplink_process_msg(MsnSlpLink *slplink, MsnMessage *msg) { MsnSlpMessage *slpmsg; const char *data; gsize offset; gsize len; #ifdef PECAN_DEBUG_SLP msn_slpmsg_show(msg); #endif #ifdef PECAN_DEBUG_SLP_FILES debug_msg_to_file(msg, FALSE); #endif if (msg->msnslp_header.total_size < msg->msnslp_header.length) { pecan_error ("This can't be good"); g_return_if_reached(); } slpmsg = NULL; data = msn_message_get_bin_data(msg, &len); /* OVERHEAD! if (msg->msnslp_header.length < msg->msnslp_header.total_size) */ offset = msg->msnslp_header.offset; if (offset == 0) { slpmsg = msn_slpmsg_new(slplink); slpmsg->id = msg->msnslp_header.id; slpmsg->session_id = msg->msnslp_header.session_id; slpmsg->size = msg->msnslp_header.total_size; slpmsg->flags = msg->msnslp_header.flags; if (slpmsg->session_id) { if (slpmsg->slpcall == NULL) slpmsg->slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); if (slpmsg->slpcall != NULL) { if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) { PurpleXfer *xfer; xfer = slpmsg->slpcall->xfer; if (xfer != NULL) { purple_xfer_start(slpmsg->slpcall->xfer, 0, NULL, 0); slpmsg->fp = ((PurpleXfer *)slpmsg->slpcall->xfer)->dest_fp; xfer->dest_fp = NULL; /* Disable double fclose() */ } } } } if (!slpmsg->fp && slpmsg->size) { slpmsg->buffer = g_try_malloc(slpmsg->size); if (slpmsg->buffer == NULL) { pecan_error ("failed to allocate buffer for slpmsg"); return; } } } else { slpmsg = msn_slplink_message_find(slplink, msg->msnslp_header.session_id, msg->msnslp_header.id); } if (slpmsg == NULL) { /* Probably the transfer was canceled */ pecan_error ("couldn't find slpmsg"); return; } if (slpmsg->fp) { /* fseek(slpmsg->fp, offset, SEEK_SET); */ len = fwrite(data, 1, len, slpmsg->fp); } else if (slpmsg->size) { if ((offset + len) > slpmsg->size) { pecan_error ("oversized slpmsg"); g_return_if_reached(); } else memcpy(slpmsg->buffer + offset, data, len); } if ((slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) && (slpmsg->slpcall != NULL)) { slpmsg->slpcall->progress = TRUE; if (slpmsg->slpcall->progress_cb != NULL) { slpmsg->slpcall->progress_cb(slpmsg->slpcall, slpmsg->size, len, offset); } } #if 0 if (slpmsg->buffer == NULL) return; #endif if (msg->msnslp_header.offset + msg->msnslp_header.length >= msg->msnslp_header.total_size) { /* All the pieces of the slpmsg have been received */ MsnSlpCall *slpcall = NULL; slpcall = msn_slp_process_msg(slplink, slpmsg); #ifdef MSN_DIRECTCONN if (slpmsg->flags == 0x100) { MsnDirectConn *directconn; directconn = slplink->directconn; directconn->ack_recv = TRUE; if (!directconn->ack_sent) { pecan_warning ("bad ACK"); msn_directconn_send_handshake(directconn); } } else if (slpmsg->flags == 0x0 || slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) { /* Release all the messages and send the ACK */ msn_slplink_send_ack(slplink, msg); msn_slplink_unleash(slplink); } #else if (slpmsg->flags == 0x0 || slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) { /* Release all the messages and send the ACK */ msn_slplink_send_ack(slplink, msg); msn_slplink_unleash(slplink); } #endif /* MSN_DIRECTCONN */ msn_slpmsg_destroy(slpmsg); if (slpcall != NULL && slpcall->wasted) msn_slp_call_destroy(slpcall); } }
MsnSlpCall * msn_slp_sip_recv(MsnSlpLink *slplink, const char *body) { MsnSlpCall *slpcall; if (body == NULL) { pecan_warning ("received bogus message"); return NULL; } if (!strncmp(body, "INVITE", strlen("INVITE"))) { char *branch; char *content; char *content_type; slpcall = msn_slp_call_new(slplink); /* From: <msnmsgr:[email protected]> */ #if 0 slpcall->remote_user = get_token(body, "From: <msnmsgr:", ">\r\n"); #endif branch = get_token(body, ";branch={", "}"); slpcall->id = get_token(body, "Call-ID: {", "}"); #if 0 long content_len = -1; temp = get_token(body, "Content-Length: ", "\r\n"); if (temp != NULL) content_len = atoi(temp); g_free(temp); #endif content_type = get_token(body, "Content-Type: ", "\r\n"); content = get_token(body, "\r\n\r\n", NULL); got_invite(slpcall, branch, content_type, content); g_free(branch); g_free(content_type); g_free(content); } else if (!strncmp(body, "MSNSLP/1.0 ", strlen("MSNSLP/1.0 "))) { char *content; char *content_type; /* Make sure this is "OK" */ const char *status = body + strlen("MSNSLP/1.0 "); char *call_id; call_id = get_token(body, "Call-ID: {", "}"); slpcall = msn_slplink_find_slp_call(slplink, call_id); g_free(call_id); g_return_val_if_fail(slpcall != NULL, NULL); if (strncmp(status, "200 OK", 6)) { /* It's not valid. Kill this off. */ char temp[32]; const char *c; /* Eww */ if ((c = strchr(status, '\r')) || (c = strchr(status, '\n')) || (c = strchr(status, '\0'))) { size_t offset = c - status; if (offset >= sizeof(temp)) offset = sizeof(temp) - 1; strncpy(temp, status, offset); temp[offset] = '\0'; } pecan_error ("received non-OK result: %s", temp); slpcall->wasted = TRUE; /* msn_slp_call_destroy(slpcall); */ return slpcall; } content_type = get_token(body, "Content-Type: ", "\r\n"); content = get_token(body, "\r\n\r\n", NULL); got_ok(slpcall, content_type, content); g_free(content_type); g_free(content); } else if (!strncmp(body, "BYE", strlen("BYE"))) { char *call_id; call_id = get_token(body, "Call-ID: {", "}"); slpcall = msn_slplink_find_slp_call(slplink, call_id); g_free(call_id); if (slpcall != NULL) slpcall->wasted = TRUE; /* msn_slp_call_destroy(slpcall); */ } else slpcall = NULL; return slpcall; }