diff libpurple/protocols/oscar/family_icbm.c @ 22337:a8c025929245

Add support for offline messages for AIM, thanks to some info from Matthew Goldstein. The new protocol bits used for offline messaging for AIM are very nice. It fits in with the rest of the oscar protocol very well (the old, ICQ-style offline messages were a bit of a hack). The offline messages arrive in the same way as every other message (except that they have a timestamp), so we can use the same message parsing that we use for all other IMs. This means that all our encoding stuff works just as well with offline messages. AND the new offline message stuff works for ICQ accounts, too. So I switched ICQ over to use it, which fixes offline message timestamps (if that was still a problem, I'm not sure) and offline message encoding bugs. Fixes #1229 (feature request for AIM offline messages) Fixes #1761 (ICQ offline message timestamp is wrong) Fixes #4300 (crash when receiving offline messages) Fixes #4464 (can't send IMs to invisible users)
author Mark Doliner <mark@kingant.net>
date Wed, 27 Feb 2008 09:18:06 +0000
parents bb1190d6961c
children 03b2b21b4c42 969a2aeae461
line wrap: on
line diff
--- a/libpurple/protocols/oscar/family_icbm.c	Wed Feb 27 04:49:20 2008 +0000
+++ b/libpurple/protocols/oscar/family_icbm.c	Wed Feb 27 09:18:06 2008 +0000
@@ -221,7 +221,7 @@
 	params.maxrecverwarn = byte_stream_get16(bs);
 	params.minmsginterval = byte_stream_get32(bs);
 
-	params.flags = 0x0000000b;
+	params.flags = 0x0000000b | AIM_IMPARAM_FLAG_SUPPORT_OFFLINEMSGS;
 	params.maxmsglen = 8000;
 	params.minmsginterval = 0;
 
@@ -1626,7 +1626,10 @@
 
 		} else if (type == 0x0006) { /* Message was received offline. */
 
-			/* XXX - not sure if this actually gets sent. */
+			/*
+			 * This flag is set on incoming offline messages for both
+			 * AIM and ICQ accounts.
+			 */
 			args.icbmflags |= AIM_IMFLAGS_OFFLINE;
 
 		} else if (type == 0x0008) { /* I-HAVE-A-REALLY-PURTY-ICON Flag */
@@ -1657,6 +1660,14 @@
 
 			args.icbmflags |= AIM_IMFLAGS_TYPINGNOT;
 
+		} else if (type == 0x0016) {
+
+			/*
+			 * UTC timestamp for when the message was sent.  Only
+			 * provided for offline messages.
+			 */
+			args.timestamp = byte_stream_get32(bs);
+
 		} else if (type == 0x0017) {
 
 			if (length > byte_stream_empty(bs))
@@ -2589,6 +2600,30 @@
 }
 
 /*
+ * Subtype 0x0010 - Request any offline messages that are waiting for
+ * us.  This is the "new" way of handling offline messages which is
+ * used for both AIM and ICQ.  The old way is to use the ugly
+ * aim_icq_reqofflinemsgs() function, but that is no longer necessary.
+ *
+ * We set the 0x00000100 flag on the ICBM message parameters, which
+ * tells the oscar servers that we support offline messages.  When we
+ * set that flag the servers do not automatically send us offline
+ * messages.  Instead we must request them using this function.  This
+ * should happen after sending the 0x0001/0x0002 "client online" SNAC.
+ */
+int aim_im_reqofflinemsgs(OscarData *od)
+{
+	FlapConnection *conn;
+
+	if (!od || !(conn = flap_connection_findbygroup(od, 0x0002)))
+		return -EINVAL;
+
+	aim_genericreq_n(od, conn, 0x0004, 0x0010);
+
+	return 0;
+}
+
+/*
  * Subtype 0x0014 - Send a mini typing notification (mtn) packet.
  *
  * This is supported by winaim5 and newer, MacAIM bleh and newer, iChat bleh and newer,