diff libpurple/protocols/oscar/family_icbm.c @ 30511:9623db527d1e

merged from im.pidgin.pidgin
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Tue, 25 May 2010 22:21:47 +0900
parents 2a19f7385ba5 f18b6eb0ed02
children 81ffeb069847
line wrap: on
line diff
--- a/libpurple/protocols/oscar/family_icbm.c	Tue May 18 02:29:24 2010 +0900
+++ b/libpurple/protocols/oscar/family_icbm.c	Tue May 25 22:21:47 2010 +0900
@@ -52,8 +52,28 @@
 #endif
 
 #include "util.h"
-/* yaz */
-#include "debug.h"
+#include "debug.h" /* yaz */
+
+static const char * const errcodereason[] = {
+	N_("Invalid error"),
+	N_("Not logged in"),
+	N_("Cannot receive IM due to parental controls"),
+	N_("Cannot send SMS without accepting terms"),
+	N_("Cannot send SMS"), /* SMS_WITHOUT_DISCLAIMER is weird */
+	N_("Cannot send SMS to this country"),
+	N_("Unknown error"), /* Undocumented */
+	N_("Unknown error"), /* Undocumented */
+	N_("Cannot send SMS to unknown country"),
+	N_("Bot accounts cannot initiate IMs"),
+	N_("Bot account cannot IM this user"),
+	N_("Bot account reached IM limit"),
+	N_("Bot account reached daily IM limit"),
+	N_("Bot account reached monthly IM limit"),
+	N_("Unable to receive offline messages"),
+	N_("Offline message store full")
+};
+static const int errcodereasonlen = G_N_ELEMENTS(errcodereason);
+
 /**
  * Add a standard ICBM header to the given bstream with the given
  * information.
@@ -157,29 +177,37 @@
 static int
 error(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs)
 {
-	int ret = 0;
-	aim_rxcallback_t userfunc;
 	aim_snac_t *snac2;
 	guint16 reason, errcode = 0;
-	char *bn;
+	const char *bn;
 	GSList *tlvlist;
-
-	if (!(snac2 = aim_remsnac(od, snac->id))) {
+	PurpleConnection *gc = od->gc;
+#ifdef TODOFT
+	PurpleXfer *xfer;
+#endif
+	const char *reason_str;
+	char *buf;
+
+	snac2 = aim_remsnac(od, snac->id);
+	if (!snac2) {
 		purple_debug_misc("oscar", "icbm error: received response from unknown request!\n");
-		return 0;
+		return 1;
 	}
 
 	if (snac2->family != SNAC_FAMILY_ICBM) {
 		purple_debug_misc("oscar", "icbm error: received response from invalid request! %d\n", snac2->family);
 		g_free(snac2->data);
 		g_free(snac2);
-		return 0;
+		return 1;
 	}
 
-	if (!(bn = snac2->data)) {
+	/* Data is assumed to be the destination bn */
+	bn = snac2->data;
+	if (!bn || bn[0] == '\0') {
 		purple_debug_misc("oscar", "icbm error: received response from request without a buddy name!\n");
+		g_free(snac2->data);
 		g_free(snac2);
-		return 0;
+		return 1;
 	}
 
 	reason = byte_stream_get16(bs);
@@ -189,15 +217,46 @@
 		errcode = aim_tlv_get16(tlvlist, 0x0008, 1);
 	aim_tlvlist_free(tlvlist);
 
+	purple_debug_error("oscar",
+			   "Message error with bn %s and reason %hu and errcode %hu\n",
+				(bn != NULL ? bn : ""), reason, errcode);
+
+#ifdef TODOFT
+	/* If this was a file transfer request, bn is a cookie */
+	if ((xfer = oscar_find_xfer_by_cookie(od->file_transfers, bn))) {
+		purple_xfer_cancel_remote(xfer);
+		return 1;
+	}
+#endif
+
 	/* Notify the user that the message wasn't delivered */
-	if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
-		ret = userfunc(od, conn, frame, reason, errcode, bn);
-
-	if (snac2)
-		g_free(snac2->data);
+	reason_str = oscar_get_msgerr_reason(reason);
+	if (errcode != 0 && errcode < errcodereasonlen)
+		buf = g_strdup_printf(_("Unable to send message: %s (%s)"), reason_str,
+		                      _(errcodereason[errcode]));
+	else
+		buf = g_strdup_printf(_("Unable to send message: %s"), reason_str);
+
+	if (!purple_conv_present_error(bn, purple_connection_get_account(gc), buf)) {
+		g_free(buf);
+		if (errcode != 0 && errcode < errcodereasonlen)
+			buf = g_strdup_printf(_("Unable to send message to %s: %s (%s)"),
+			                      bn ? bn : "(unknown)", reason_str,
+			                      _(errcodereason[errcode]));
+		else
+			buf = g_strdup_printf(_("Unable to send message to %s: %s"),
+			                      bn ? bn : "(unknown)", reason_str);
+		purple_notify_error(od->gc, NULL, buf, reason_str);
+	}
+	g_free(buf);
+
+
+
+
+	g_free(snac2->data);
 	g_free(snac2);
 
-	return ret;
+	return 1;
 }
 
 /**