[ekg2-commit] r4194 - trunk/plugins/icq: trunk/plugins/icq/icq_snac_handlers_03buddy.c trunk/plugins/icq/misc.c trunk/plugins/icq/misc.h

SVN commit svn w toxygen.net
Śro, 6 Sie 2008, 11:27:28 CEST


Author: wiechu
Date: 2008-08-06 11:27:27 +0200 (Wed, 06 Aug 2008)
New Revision: 4194

Modified:
   trunk/plugins/icq/icq_snac_handlers_03buddy.c
   trunk/plugins/icq/misc.c
   trunk/plugins/icq/misc.h
Log:
    icq: User online notification

Modified: trunk/plugins/icq/icq_snac_handlers_03buddy.c
===================================================================
--- trunk/plugins/icq/icq_snac_handlers_03buddy.c	2008-08-06 09:09:33 UTC (rev 4193)
+++ trunk/plugins/icq/icq_snac_handlers_03buddy.c	2008-08-06 09:27:27 UTC (rev 4194)
@@ -37,7 +37,7 @@
 }
 
 SNAC_SUBHANDLER(icq_snac_buddy_reply) {
-	struct icq_tlv_list *tlvs;	
+	struct icq_tlv_list *tlvs;
 
 	if ((tlvs = icq_unpack_tlvs(buf, len, 0))) {
 		icq_tlv_t *t_max_uins = icq_tlv_get(tlvs, 1);
@@ -56,9 +56,75 @@
 }
 
 SNAC_SUBHANDLER(icq_snac_buddy_online) {
-	debug_error("icq_snac_buddy_online() XXX\n");
-	icq_hexdump(DEBUG_ERROR, buf, len);
-	return -3;
+	/*
+	 * Handle SNAC(0x3,0xb) -- User online notification
+	 *
+	 * Server sends this snac when user from your contact list goes online.
+	 * Also you'll receive this snac on user status change.
+	 */
+
+	struct icq_tlv_list *tlvs;
+	icq_tlv_t *t;
+	char *uid, *tmp;
+	uint16_t warning, count, status, status2;
+
+	if (!icq_unpack(buf, &buf, &len, "uWW", &tmp, &warning, &count))
+		return -1;
+
+	uid = saprintf("icq:%s", tmp);
+
+	tlvs = icq_unpack_tlvs(buf, len, count);
+
+	for (t = tlvs; t; t = t->next) {
+
+		switch (t->type) {
+			case 0x06:
+				/* User status
+				 *
+				 * ICQ service presence notifications use user status field which consist
+				 * of two parts. First is a various flags (birthday flag, webaware flag,
+				 * etc). Second is a user status (online, away, busy, etc) flags.
+				 */
+				status  = t->nr & 0xffff;
+				status2 = t->nr >> 16;
+				debug_white("icq_snac_buddy_online()  %s status2=0x%04x status=0x%04x\n", uid, status2, status);
+				protocol_status_emit(s, uid, icq2ekg_status(status), NULL, time(NULL));
+				break;
+
+			case 0x0a: /* IP address */
+				/* XXX (?wo?) add to private */
+				debug_white("icq_snac_buddy_online()  %s IP=%d.%d.%d.%d\n", uid, t->buf[0], t->buf[1], t->buf[2], t->buf[3]);
+				break;
+
+			case 0x01: /* User class */
+				debug_white("icq_snac_buddy_online()  %s class 0x%02x\n", uid, t->nr);
+				break;
+			case 0x03: /* Time when client gone online (unix time_t) */
+				debug_white("icq_snac_buddy_online()  %s online since %d\n", uid, t->nr);
+				break;
+			case 0x05: /* Time when this account was registered (unix time_t) */
+				debug_white("icq_snac_buddy_online()  %s is ICQ Member since %d\n", uid, t->nr);
+				break;
+			case 0x0f: /* Online time in seconds */
+				debug_white("icq_snac_buddy_online()  %s is %d seconds online\n", uid, t->nr);
+				break;
+
+			case 0x0c: /* DC info */
+			case 0x0d: /* Client capabilities list */
+			case 0x1d: /* user icon id & hash */
+				debug_white("icq_snac_buddy_online() Not supported type=0x%02x\n", t->type);
+				break;
+
+			default:
+				debug_error("icq_snac_buddy_online() Unknown type=0x%02x\n", t->type);
+		}
+
+	}
+
+	icq_tlvs_destroy(&tlvs);
+	xfree(uid);
+
+	return 0;
 }
 
 SNAC_SUBHANDLER(icq_snac_buddy_offline) {

Modified: trunk/plugins/icq/misc.c
===================================================================
--- trunk/plugins/icq/misc.c	2008-08-06 09:09:33 UTC (rev 4193)
+++ trunk/plugins/icq/misc.c	2008-08-06 09:27:27 UTC (rev 4194)
@@ -436,6 +436,20 @@
 	}
 }
 
+status_t icq2ekg_status(int icq_status) {
+	switch (icq_status) {
+		case ICQ_STATUS_ONLINE:		return EKG_STATUS_AVAIL;
+		case ICQ_STATUS_AWAY:		return EKG_STATUS_AWAY;
+		case ICQ_STATUS_DND:		return EKG_STATUS_DND;
+		case ICQ_STATUS_NA:		return EKG_STATUS_NA;
+		case ICQ_STATUS_OCCUPIED:	return EKG_STATUS_XA;
+		case ICQ_STATUS_FFC:		return EKG_STATUS_FFC;
+		case ICQ_STATUS_INVISIBLE:	return EKG_STATUS_INVISIBLE;
+
+		default:			return EKG_STATUS_UNKNOWN;
+	}
+}
+
 /* hash password, ripped from micq */
 char *icq_encryptpw(const char *pw) {
 	uint8_t tb[] = { 0xf3, 0x26, 0x81, 0xc4, 0x39, 0x86, 0xdb, 0x92, 0x71, 0xa3, 0xb9, 0xe6, 0x53, 0x7a, 0x95, 0x7c };

Modified: trunk/plugins/icq/misc.h
===================================================================
--- trunk/plugins/icq/misc.h	2008-08-06 09:09:33 UTC (rev 4193)
+++ trunk/plugins/icq/misc.h	2008-08-06 09:27:27 UTC (rev 4194)
@@ -44,4 +44,6 @@
 
 #define ICQ_UNPACK(endbuf, args...) (icq_unpack(buf, endbuf, &len, args))
 
+status_t icq2ekg_status(int icq_status);
+
 #endif



Więcej informacji o liście dyskusyjnej ekg2-commit