changeset 12349:2a1961c1a345

[gaim-migrate @ 14653] Get rid of oscar's copy of the available message and use the one in the status API everywhere. Also, I don't think 'available' message is technically correct. I think it could potentially be used for other stuff. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Mon, 05 Dec 2005 06:52:30 +0000
parents 4f7797a3024b
children 51c57ebb4ec8
files src/protocols/oscar/aim.h src/protocols/oscar/locate.c src/protocols/oscar/oscar.c src/protocols/oscar/service.c
diffstat 4 files changed, 107 insertions(+), 109 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/oscar/aim.h	Mon Dec 05 06:07:14 2005 +0000
+++ b/src/protocols/oscar/aim.h	Mon Dec 05 06:52:30 2005 +0000
@@ -640,7 +640,7 @@
 faim_export aim_conn_t *aim_getconn_fd(aim_session_t *, int fd);
 
 /* 0x0001 - service.c */
-faim_export int aim_srv_setavailmsg(aim_session_t *sess, const char *msg);
+faim_export int aim_srv_setstatusmsg(aim_session_t *sess, const char *msg);
 faim_export int aim_srv_setidle(aim_session_t *sess, fu32_t idletime);
 
 /* misc.c */
@@ -1088,9 +1088,9 @@
 	char *info_encoding;
 	fu16_t info_len;
 
-	char *avail;
-	char *avail_encoding;
-	fu16_t avail_len;
+	char *status;
+	char *status_encoding;
+	fu16_t status_len;
 
 	char *away;
 	char *away_encoding;
--- a/src/protocols/oscar/locate.c	Mon Dec 05 06:07:14 2005 +0000
+++ b/src/protocols/oscar/locate.c	Mon Dec 05 06:52:30 2005 +0000
@@ -490,8 +490,8 @@
 	free(info->iconcsum);
 	free(info->info);
 	free(info->info_encoding);
-	free(info->avail);
-	free(info->avail_encoding);
+	free(info->status);
+	free(info->status_encoding);
 	free(info->away);
 	free(info->away_encoding);
 }
@@ -718,18 +718,18 @@
 			/*
 			 * Type = 0x001d
 			 *
-			 * Buddy icon information and available messages.
+			 * Buddy icon information and status/available messages.
 			 *
-			 * This almost seems like the AIM protocol guys gave 
-			 * the iChat guys a Type, and the iChat guys tried to 
-			 * cram as much cool shit into it as possible.  Then 
-			 * the Windows AIM guys were like, "hey, that's 
+			 * This almost seems like the AIM protocol guys gave
+			 * the iChat guys a Type, and the iChat guys tried to
+			 * cram as much cool shit into it as possible.  Then
+			 * the Windows AIM guys were like, "hey, that's
 			 * pretty neat, let's copy those prawns."
 			 *
-			 * In that spirit, this can contain a custom message, 
-			 * kind of like an away message, but you're not away 
-			 * (it's called an "available" message).  Or it can 
-			 * contain information about the buddy icon the user 
+			 * In that spirit, this can contain a custom message,
+			 * kind of like an away message, but you're not away
+			 * (it's called an "available" message).  Or it can
+			 * contain information about the buddy icon the user
 			 * has stored on the server.
 			 */
 			int type2, number, length2;
@@ -755,24 +755,24 @@
 							aim_bstream_advance(bs, length2);
 					} break;
 
-					case 0x0002: { /* An available message */
-						free(outinfo->avail);
-						free(outinfo->avail_encoding);
+					case 0x0002: { /* An status/available message */
+						free(outinfo->status);
+						free(outinfo->status_encoding);
 						if (length2 >= 4) {
-							outinfo->avail_len = aimbs_get16(bs);
-							outinfo->avail = aimbs_getstr(bs, outinfo->avail_len);
+							outinfo->status_len = aimbs_get16(bs);
+							outinfo->status = aimbs_getstr(bs, outinfo->status_len);
 							if (aimbs_get16(bs) == 0x0001) { /* We have an encoding */
 								aimbs_get16(bs);
-								outinfo->avail_encoding = aimbs_getstr(bs, aimbs_get16(bs));
+								outinfo->status_encoding = aimbs_getstr(bs, aimbs_get16(bs));
 							} else {
 								/* No explicit encoding, client should use UTF-8 */
-								outinfo->avail_encoding = NULL;
+								outinfo->status_encoding = NULL;
 							}
 						} else {
 							aim_bstream_advance(bs, length2);
-							outinfo->avail_len = 0;
-							outinfo->avail = g_strdup("");
-							outinfo->avail_encoding = NULL;
+							outinfo->status_len = 0;
+							outinfo->status = g_strdup("");
+							outinfo->status_encoding = NULL;
 						}
 					} break;
 
--- a/src/protocols/oscar/oscar.c	Mon Dec 05 06:07:14 2005 +0000
+++ b/src/protocols/oscar/oscar.c	Mon Dec 05 06:52:30 2005 +0000
@@ -177,7 +177,6 @@
  */
 struct buddyinfo {
 	gboolean typingnot;
-	gchar *availmsg;
 	fu32_t ipaddr;
 
 	unsigned long ico_me_len;
@@ -320,7 +319,6 @@
 
 static void oscar_free_buddyinfo(void *data) {
 	struct buddyinfo *bi = data;
-	g_free(bi->availmsg);
 	g_free(bi);
 }
 
@@ -3467,10 +3465,12 @@
 	time_t time_idle = 0, signon = 0;
 	int type = 0;
 	int caps = 0;
+	gboolean buddy_is_away = FALSE;
+	const char *status_id;
+	gboolean have_status_message = FALSE;
+	char *message = NULL;
 	va_list ap;
 	aim_userinfo_t *info;
-	gboolean buddy_is_away = FALSE;
-	const char *status_id;
 
 	gc = sess->aux_data;
 	account = gaim_connection_get_account(gc);
@@ -3484,9 +3484,6 @@
 	g_return_val_if_fail(info != NULL, 1);
 	g_return_val_if_fail(info->sn != NULL, 1);
 
-	if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES)
-		caps = info->capabilities;
-
 	if (info->present & AIM_USERINFO_PRESENT_FLAGS) {
 		if (info->flags & AIM_FLAG_AWAY)
 			buddy_is_away = TRUE;
@@ -3499,13 +3496,58 @@
 		}
 	}
 
+	if (aim_sn_is_icq(info->sn)) {
+		if (type & AIM_ICQ_STATE_CHAT)
+			status_id = OSCAR_STATUS_ID_FREE4CHAT;
+		else if (type & AIM_ICQ_STATE_DND)
+			status_id = OSCAR_STATUS_ID_DND;
+		else if (type & AIM_ICQ_STATE_OUT)
+			status_id = OSCAR_STATUS_ID_NA;
+		else if (type & AIM_ICQ_STATE_BUSY)
+			status_id = OSCAR_STATUS_ID_OCCUPIED;
+		else if (type & AIM_ICQ_STATE_AWAY)
+			status_id = OSCAR_STATUS_ID_AWAY;
+		else if (type & AIM_ICQ_STATE_INVISIBLE)
+			status_id = OSCAR_STATUS_ID_INVISIBLE;
+		else
+			status_id = OSCAR_STATUS_ID_AVAILABLE;
+	} else {
+		if (buddy_is_away == TRUE)
+			status_id = OSCAR_STATUS_ID_AWAY;
+		else
+			status_id = OSCAR_STATUS_ID_AVAILABLE;
+	}
+
+	/*
+	 * Handle the available message.  If info->status is NULL then the user
+	 * may or may not have an available message, so don't do anything.  If
+	 * info->status is set to the empty string, then the user's client DOES
+	 * support available messages and the user DOES NOT have one set.
+	 * Otherwise info->status contains the available message.
+	 */
+	if (info->status != NULL)
+	{
+		have_status_message = TRUE;
+		if (info->status[0] != '\0')
+			message = oscar_encoding_to_utf8(info->status_encoding,
+											 info->status, info->status_len);
+	}
+
+	if (have_status_message)
+	{
+		gaim_prpl_got_user_status(account, info->sn, status_id,
+								  "message", message, NULL);
+		g_free(message);
+	}
+	else
+		gaim_prpl_got_user_status(account, info->sn, status_id, NULL);
+
+	if (info->present & AIM_USERINFO_PRESENT_CAPABILITIES)
+		caps = info->capabilities;
+
 	if (caps & AIM_CAPS_ICQ_DIRECT)
 		caps ^= AIM_CAPS_ICQ_DIRECT;
 
-	/* info->idletime is the number of minutes that this user has been idle */
-	if (info->present & AIM_USERINFO_PRESENT_IDLE)
-		time_idle = time(NULL) - info->idletime * 60;
-
 	if (info->present & AIM_USERINFO_PRESENT_ONLINESINCE)
 		signon = info->onlinesince;
 	else if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN)
@@ -3525,22 +3567,6 @@
 	bi->ico_informed = FALSE;
 	bi->ipaddr = info->icqinfo.ipaddr;
 
-	/*
-	 * Handle the available message.  If info->avail is NULL then the user
-	 * may or may not have an available message, so don't do anything.  If
-	 * info->avail is set to the empty string, then the user's client DOES
-	 * support available messages and the user DOES NOT have one set.
-	 * Otherwise info->avail contains the available message.
-	 */
-	if (info->avail != NULL)
-	{
-		free(bi->availmsg);
-		if (info->avail[0] != '\0')
-			bi->availmsg = oscar_encoding_to_utf8(info->avail_encoding, info->avail, info->avail_len);
-		else
-			bi->availmsg = NULL;
-	}
-
 	/* Server stored icon stuff */
 	if (info->iconcsumlen) {
 		const char *filename = NULL, *saved_b16 = NULL;
@@ -3583,32 +3609,11 @@
 		g_free(b16);
 	}
 
-	if (aim_sn_is_icq(info->sn)) {
-		if (type & AIM_ICQ_STATE_CHAT)
-			status_id = OSCAR_STATUS_ID_FREE4CHAT;
-		else if (type & AIM_ICQ_STATE_DND)
-			status_id = OSCAR_STATUS_ID_DND;
-		else if (type & AIM_ICQ_STATE_OUT)
-			status_id = OSCAR_STATUS_ID_NA;
-		else if (type & AIM_ICQ_STATE_BUSY)
-			status_id = OSCAR_STATUS_ID_OCCUPIED;
-		else if (type & AIM_ICQ_STATE_AWAY)
-			status_id = OSCAR_STATUS_ID_AWAY;
-		else if (type & AIM_ICQ_STATE_INVISIBLE)
-			status_id = OSCAR_STATUS_ID_INVISIBLE;
-		else
-			status_id = OSCAR_STATUS_ID_AVAILABLE;
-	} else {
-		if (buddy_is_away == TRUE)
-			status_id = OSCAR_STATUS_ID_AWAY;
-		else
-			status_id = OSCAR_STATUS_ID_AVAILABLE;
-	}
-	gaim_prpl_got_user_status(account, info->sn, status_id, NULL);
 	gaim_prpl_got_user_login_time(account, info->sn, signon - od->timeoffset);
-#if 0
-	gaim_prpl_got_user_warning_level(account, info->sn, info->warnlevel/10.0 + 0.5);
-#endif
+
+	/* info->idletime is the number of minutes that this user has been idle */
+	if (info->present & AIM_USERINFO_PRESENT_IDLE)
+		time_idle = time(NULL) - info->idletime * 60;
 
 	if (time_idle > 0)
 		gaim_prpl_got_user_idle(account, info->sn, TRUE, time_idle);
@@ -3636,7 +3641,7 @@
 	info = va_arg(ap, aim_userinfo_t *);
 	va_end(ap);
 
-	gaim_prpl_got_user_status(account, info->sn, OSCAR_STATUS_ID_OFFLINE, NULL);	
+	gaim_prpl_got_user_status(account, info->sn, OSCAR_STATUS_ID_OFFLINE, NULL);
 
 	g_hash_table_remove(od->buddyinfo, gaim_normalize(gc->account, info->sn));
 
@@ -5100,10 +5105,9 @@
 static int gaim_got_infoblock(aim_session_t *sess, aim_frame_t *fr, ...)
 {
 	GaimConnection *gc = sess->aux_data;
-	OscarData *od = gc->proto_data;
 	GaimBuddy *b;
 	GaimPresence *presence;
-	GaimStatus *active_status;
+	GaimStatus *status;
 	gchar *message = NULL;
 
 	va_list ap;
@@ -5118,28 +5122,22 @@
 		return 1;
 
 	presence = gaim_buddy_get_presence(b);
-	active_status = gaim_presence_get_active_status(presence);
-
-	if (gaim_status_is_available(active_status))
+	status = gaim_presence_get_active_status(presence);
+
+	if (!gaim_status_is_available(status))
 	{
-		struct buddyinfo *bi;
-
-		bi = g_hash_table_lookup(od->buddyinfo, gaim_normalize(b->account, b->name));
-		if ((bi != NULL) && (bi->availmsg != NULL))
-			message = g_markup_escape_text(bi->availmsg, strlen(bi->availmsg));
-	} else {
 		if ((userinfo != NULL) && (userinfo->flags & AIM_FLAG_AWAY) &&
 			(userinfo->away_len > 0) && (userinfo->away != NULL) && (userinfo->away_encoding != NULL)) {
 			gchar *charset = oscar_encoding_extract(userinfo->away_encoding);
 			message = oscar_encoding_to_utf8(charset, userinfo->away, userinfo->away_len);
 			g_free(charset);
 		}
-	}
-
-	gaim_status_set_attr_string(active_status, "message", message);
-	g_free(message);
-
-	gaim_blist_update_buddy_status(b, active_status);
+
+		gaim_status_set_attr_string(status, "message", message);
+		g_free(message);
+
+		gaim_blist_update_buddy_status(b, status);
+	}
 
 	return 1;
 }
@@ -5878,7 +5876,7 @@
 	else
 		message = NULL;
 	tmp = gaim_markup_strip_html(message);
-	aim_srv_setavailmsg(sess, tmp);
+	aim_srv_setstatusmsg(sess, tmp);
 	free(tmp);
 
 	aim_srv_setidle(sess, 0);
@@ -6610,15 +6608,15 @@
 	}
 	else if (primitive == GAIM_STATUS_AVAILABLE)
 	{
-		const char *avail_html;
-		char *avail_text;
-
-		avail_html = gaim_status_get_attr_string(status, "message");
-		if (avail_html != NULL)
+		const char *status_html;
+		char *status_text;
+
+		status_html = gaim_status_get_attr_string(status, "message");
+		if (status_html != NULL)
 		{
-			avail_text = gaim_markup_strip_html(avail_html);
-			aim_srv_setavailmsg(od->sess, avail_text);
-			g_free(avail_text);
+			status_text = gaim_markup_strip_html(status_html);
+			aim_srv_setstatusmsg(od->sess, status_text);
+			g_free(status_text);
 		}
 
 		/* This is needed for us to un-set any previous away message. */
--- a/src/protocols/oscar/service.c	Mon Dec 05 06:07:14 2005 +0000
+++ b/src/protocols/oscar/service.c	Mon Dec 05 06:52:30 2005 +0000
@@ -793,7 +793,7 @@
  * if your status is visible on ICQ web sites, and you can set
  * your IP address info and what not.
  *
- * These are the same TLVs seen in user info.  You can 
+ * These are the same TLVs seen in user info.  You can
  * also set 0x0008 and 0x000c.
  */
 faim_export int aim_setextstatus(aim_session_t *sess, fu32_t status)
@@ -829,16 +829,16 @@
 	return 0;
 }
 
-/* 
+/*
  * Subtype 0x001e - Extended Status.
  *
- * Sets your "available" message.  This is currently only supported by iChat 
+ * Sets your "available" message.  This is currently only supported by iChat
  * and Gaim.
  *
- * These are the same TLVs seen in user info.  You can 
+ * These are the same TLVs seen in user info.  You can
  * also set 0x0008 and 0x000c.
  */
-faim_export int aim_srv_setavailmsg(aim_session_t *sess, const char *msg)
+faim_export int aim_srv_setstatusmsg(aim_session_t *sess, const char *msg)
 {
 	aim_conn_t *conn;
 	aim_frame_t *fr;