changeset 12813:547c199072c8

[gaim-migrate @ 15161] - fixes to sametime administrative notification message dialog to make them a little less obscure as to what the heck they are - added an extra step to the sametime connection login between authenticating and starting services - fix to outgoing encoding of html formatted messages in sametime to use NCR encoding - addition of gaim_utf8_ncr_encode to util.h - fix of minor possible (unlikely) memleak in gaim_utf8_ncr_decode committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Wed, 11 Jan 2006 03:07:01 +0000
parents 7e6de7079eeb
children f88f145884c0
files plugins/ChangeLog.API src/protocols/sametime/sametime.c src/protocols/sametime/sametime.h src/util.c src/util.h
diffstat 5 files changed, 115 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/ChangeLog.API	Wed Jan 11 01:13:20 2006 +0000
+++ b/plugins/ChangeLog.API	Wed Jan 11 03:07:01 2006 +0000
@@ -222,6 +222,7 @@
 	* gaim_log_uninit()
 	* GAIM_SUBTYPE_LOG
 	* gaim_marshal_POINTER__POINTER_POINTER
+	* gaim_utf8_ncr_encode()
 
 	Signals - Changed:  (See the Doxygen docs for details on all signals.)
 	* Signal propagation now stops after a handler returns a non-NULL value.
--- a/src/protocols/sametime/sametime.c	Wed Jan 11 01:13:20 2006 +0000
+++ b/src/protocols/sametime/sametime.c	Wed Jan 11 03:07:01 2006 +0000
@@ -66,7 +66,7 @@
 #include <mw_srvc_store.h>
 #include <mw_st_list.h>
 
-/* project includes */
+/* plugin includes */
 #include "sametime.h"
 
 
@@ -91,7 +91,7 @@
 
 
 /* stages of connecting-ness */
-#define MW_CONNECT_STEPS  9
+#define MW_CONNECT_STEPS  10
 
 
 /* stages of conciousness */
@@ -1301,16 +1301,6 @@
   /* grab the buddy list from the server */
   unit = mwStorageUnit_new(mwStore_AWARE_LIST);
   mwServiceStorage_load(pd->srvc_store, unit, fetch_blist_cb, pd, NULL); 
-  
-  /* start watching for new conversations */
-  gaim_signal_connect(gaim_conversations_get_handle(),
-		      "conversation-created", gc,
-		      GAIM_CALLBACK(conversation_created_cb), pd);
-
-  /* watch for group extended menu items */
-  gaim_signal_connect(gaim_blist_get_handle(),
-		      "blist-node-extended-menu", gc,
-		      GAIM_CALLBACK(blist_node_menu_cb), pd);
 
   /* find all the NAB groups and subscribe to them */
   blist = gaim_get_blist();
@@ -1378,9 +1368,20 @@
   GaimStatus *status;
   GaimAccount *acct;
 
+  /* set out initial status */
   acct = gaim_connection_get_account(pd->gc);
   status = gaim_account_get_active_status(acct);
   mw_prpl_set_status(acct, status);
+  
+  /* start watching for new conversations */
+  gaim_signal_connect(gaim_conversations_get_handle(),
+		      "conversation-created", pd->gc,
+		      GAIM_CALLBACK(conversation_created_cb), pd);
+
+  /* watch for group extended menu items */
+  gaim_signal_connect(gaim_blist_get_handle(),
+		      "blist-node-extended-menu", pd->gc,
+		      GAIM_CALLBACK(blist_node_menu_cb), pd);
 
   /* use our services to do neat things */
   services_starting(pd);
@@ -1434,11 +1435,14 @@
     break;
 
   case mwSession_STARTED:
-    msg = _("Connected to Sametime Community Server");
+    msg = _("Starting Services");
     gaim_connection_update_progress(gc, msg, 9, MW_CONNECT_STEPS);
-    gaim_connection_set_state(gc, GAIM_CONNECTED);
 
     session_started(pd);
+
+    msg = _("Connected");
+    gaim_connection_update_progress(gc, msg, 10, MW_CONNECT_STEPS);
+    gaim_connection_set_state(gc, GAIM_CONNECTED);
     break;
 
   case mwSession_STOPPING:
@@ -1520,16 +1524,28 @@
 
 static void mw_session_admin(struct mwSession *session,
 			     const char *text) {
-
-  GaimConnection *gc = session_to_gc(session);
+  GaimConnection *gc;
+  GaimAccount *acct;
+  const char *host;
+  char *prim;
+
+  gc = session_to_gc(session);
   g_return_if_fail(gc != NULL);
 
-  /** @todo Admin alerts should probably be in a conversation window
-      rather than a gaim_notify_message. Or in some sort of updating
-      dialog, or something. */
-
-  gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO, _("Admin Alert"),
-		      text, NULL, NULL, NULL);
+  acct = gaim_connection_get_account(gc);
+  g_return_if_fail(acct != NULL);
+
+  host = gaim_account_get_string(acct, MW_KEY_HOST, NULL);
+
+  prim = _("A Sametime administrator has issued the following announcement"
+	   " on server %s");
+  prim = g_strdup_printf(prim, NSTR(host));
+
+  gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO,
+		      _("Sametime Administrator Announcement"),
+		      prim, text, NULL, NULL);
+
+  g_free(prim);
 }
 
 
@@ -3711,12 +3727,13 @@
 }
 
 
+#if NB_HACK
 static char *nb_im_encode(GaimConnection *gc, const char *message) {
   GaimAccount *acct;
   const char *enc;
   char *ret;
   GError *error = NULL;
-  
+
   acct = gaim_connection_get_account(gc);
   g_return_val_if_fail(acct != NULL, NULL);
 
@@ -3739,8 +3756,10 @@
 
  return ret;
 }
-
-
+#endif
+
+
+#if NB_HACK
 static gboolean is_nb(struct mwConversation *conv) {
   struct mwLoginInfo *info;
 
@@ -3755,6 +3774,7 @@
      really did. Oh well. CURSE YOU NOTESBUDDY */
   return ((info->type == 0x1000) || ((info->type & 0xff00) == 0x1400));
 }
+#endif
 
 
 /** turn an IM with embedded images into a multi-part mime document */
@@ -3847,6 +3867,7 @@
   part = gaim_mime_part_new(doc);
   gaim_mime_part_set_field(part, "Content-Disposition", "inline");
 
+#if NB_HACK
   if(is_nb(conv)) {
     GaimAccount *acct = gaim_connection_get_account(gc);
 
@@ -3868,6 +3889,14 @@
     gaim_mime_part_set_data(part, str->str);
   }
 
+#else
+  tmp = gaim_utf8_ncr_encode(str->str);
+  gaim_mime_part_set_field(part, "Content-Type", "text/html");
+  gaim_mime_part_set_field(part, "Content-Transfer-Encoding", "7bit");
+  gaim_mime_part_set_data(part, str->str);
+  g_free(tmp);
+#endif
+
   g_string_free(str, TRUE);
 
   str = g_string_new(NULL);
@@ -3921,6 +3950,7 @@
     } else if(mwConversation_supports(conv, mwImSend_HTML)) {
       /* send an HTML message */
 
+#if NB_HACK
       if(is_nb(conv)) {
 
 	/* html messages need the notesbuddy hack */
@@ -3933,6 +3963,13 @@
 	tmp = gaim_strdup_withhtml(message);
       }
 
+#else
+      char *ncr;
+      ncr = gaim_utf8_ncr_encode(message);
+      tmp = gaim_strdup_withhtml(ncr);
+      g_free(ncr);
+#endif
+
       ret = mwConversation_send(conv, mwImSend_HTML, tmp);
       g_free(tmp);
 
@@ -5604,11 +5641,13 @@
 				    MW_PLUGIN_DEFAULT_PORT);
   l = g_list_append(l, opt);
 
+#if NB_HACK
   /* notesbuddy hack encoding */
   opt = gaim_account_option_string_new(_("NotesBuddy encoding"),
 				       MW_KEY_ENCODING,
 				       MW_PLUGIN_DEFAULT_ENCODING);
   l = g_list_append(l, opt);
+#endif
 
   { /* copy the old force login setting from prefs if it's
        there. Don't delete the preference, since there may be more
--- a/src/protocols/sametime/sametime.h	Wed Jan 11 01:13:20 2006 +0000
+++ b/src/protocols/sametime/sametime.h	Wed Jan 11 03:07:01 2006 +0000
@@ -25,3 +25,9 @@
 #endif
 /* ISO-8859-1 */
 
+
+/** use the notesbuddy encoding hack, or try for NCR encoding */
+#ifndef NB_HACK
+#define NB_HACK 0
+#endif
+/* 0 */
--- a/src/util.c	Wed Jan 11 01:13:20 2006 +0000
+++ b/src/util.c	Wed Jan 11 03:07:01 2006 +0000
@@ -3450,15 +3450,43 @@
 	return g_string_free(workstr, FALSE);
 }
 
+
+char *
+gaim_utf8_ncr_encode(const char *in)
+{
+	GString *out;
+
+	g_return_val_if_fail(in != NULL, NULL);
+	g_return_val_if_fail(g_utf8_validate(in, -1, NULL), NULL);
+
+	out = g_string_new("");
+
+	for(; *in; in = g_utf8_next_char(in)) {
+		gunichar wc = g_utf8_get_char(in);
+		
+		if(wc >= 0x80) { /* super simple check. hopefully not too wrong. */
+			g_string_append_printf(out, "&#%u;", (guint32) wc);
+		} else {
+			g_string_append_unichar(out, wc);
+		}
+	}
+
+	return g_string_free(out, FALSE);
+}
+
+
 char *
 gaim_utf8_ncr_decode(const char *in)
 {
-	GString *out = g_string_new("");
+	GString *out;
 	int i;
 
 	g_return_val_if_fail(in != NULL, NULL);
 	g_return_val_if_fail(g_utf8_validate(in, -1, NULL), NULL);
 
+	out = g_string_new("");
+
+	/** @todo doesn't this break with hex formats? */
 	for (i = 0; in[i]; i += 1) {
 		gboolean ncr_found_p = FALSE;
 		if (in[i] == '&' && in[i + 1] == '#' && isdigit(in[i + 2])) {
--- a/src/util.h	Wed Jan 11 01:13:20 2006 +0000
+++ b/src/util.h	Wed Jan 11 03:07:01 2006 +0000
@@ -637,6 +637,20 @@
 gchar *gaim_strreplace(const char *string, const char *delimiter,
 					   const char *replacement);
 
+
+/**
+ * Given a string, this replaces any utf-8 substrings in that string with
+ * the corresponding numerical character reference, and returns a newly
+ * allocated string.
+ *
+ * @param in The string which might contain utf-8 substrings
+ *
+ * @return A new string, with utf-8 replaced with numerical character
+ *         references, free this with g_free()
+*/
+char *gaim_utf8_ncr_encode(const char *in);
+
+
 /**
  * Given a string, this replaces any numerical character references
  * in that string with the corresponding actual utf-8 substrings,
@@ -649,6 +663,7 @@
  */
 char *gaim_utf8_ncr_decode(const char *in);
 
+
 /**
  * Given a string, this replaces one substring with another
  * ignoring case and returns a newly allocated string.