changeset 12005:5b3368008513

[gaim-migrate @ 14298] fixes from elsewhere committer: Tailor Script <tailor@pidgin.im>
author Christopher O'Brien <siege@pidgin.im>
date Tue, 08 Nov 2005 17:56:39 +0000
parents 8d5ebd7d4ec3
children de25a063aebe
files src/protocols/sametime/meanwhile/common.c src/protocols/sametime/meanwhile/mw_common.h src/protocols/sametime/sametime.c
diffstat 3 files changed, 82 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/protocols/sametime/meanwhile/common.c	Tue Nov 08 05:30:44 2005 +0000
+++ b/src/protocols/sametime/meanwhile/common.c	Tue Nov 08 17:56:39 2005 +0000
@@ -944,15 +944,19 @@
     return "Lotus Sametime Links";
 
   case mwLogin_NOTES_6_5:
+  case mwLogin_NOTES_6_5_3:
+  case mwLogin_NOTES_7_0_beta:
   case mwLogin_NOTES_7_0:
     return "Lotus Notes Client";
 
   case mwLogin_ICT:
   case mwLogin_ICT_1_7_8_2:
+  case mwLogin_ICT_SIP:
     return "IBM Community Tools";
 
-  case mwLogin_NOTESBUDDY:
+  case mwLogin_NOTESBUDDY_4_14:
   case mwLogin_NOTESBUDDY_4_15:
+  case mwLogin_NOTESBUDDY_4_16:
     return "Alphaworks NotesBuddy";
 
   case mwLogin_SANITY:
--- a/src/protocols/sametime/meanwhile/mw_common.h	Tue Nov 08 05:30:44 2005 +0000
+++ b/src/protocols/sametime/meanwhile/mw_common.h	Tue Nov 08 17:56:39 2005 +0000
@@ -100,12 +100,16 @@
   mwLogin_LINKS         = 0x100a,  /**< official Sametime Links toolkit */
 
   /* now we're getting crazy */
-  mwLogin_NOTES_6_5        = 0x1200,
-  mwLogin_NOTES_7_0        = 0x1210,
-  mwLogin_ICT              = 0x1300,
+  mwLogin_NOTES_6_5        = 0x1200,  /**< 0xff00 mask? */
+  mwLogin_NOTES_6_5_3      = 0x1203,
+  mwLogin_NOTES_7_0_beta   = 0x1210,
+  mwLogin_NOTES_7_0        = 0x1214,
+  mwLogin_ICT              = 0x1300,  /**< 0xff00 mask? */
   mwLogin_ICT_1_7_8_2      = 0x1302,
-  mwLogin_NOTESBUDDY       = 0x1400,  /**< 0xff00 mask? */
+  mwLogin_ICT_SIP          = 0x1303,
+  mwLogin_NOTESBUDDY_4_14  = 0x1400,  /**< 0xff00 mask? */
   mwLogin_NOTESBUDDY_4_15  = 0x1405,
+  mwLogin_NOTESBUDDY_4_16  = 0x1406,
   mwLogin_SANITY           = 0x1600,
   mwLogin_ST_PERL          = 0x1625,
   mwLogin_PMR_ALERT        = 0x1650,
--- a/src/protocols/sametime/sametime.c	Tue Nov 08 05:30:44 2005 +0000
+++ b/src/protocols/sametime/sametime.c	Tue Nov 08 17:56:39 2005 +0000
@@ -808,6 +808,7 @@
 			       struct mwSametimeGroup *stgroup) {
   GaimAccount *acct;
   GaimGroup *group;
+  GaimBuddyList *blist;
   GaimBlistNode *gn;
   const char *name, *alias, *owner;
   enum mwSametimeGroupType type;
@@ -815,18 +816,35 @@
   acct = gaim_connection_get_account(gc);
   owner = gaim_account_get_username(acct);
 
+  blist = gaim_get_blist();
+  g_return_val_if_fail(blist != NULL, NULL);
+
   name = mwSametimeGroup_getName(stgroup);
   alias = mwSametimeGroup_getAlias(stgroup);
   type = mwSametimeGroup_getType(stgroup);
 
+  /* first attempt at finding the group, by the name key */
+  for(gn = blist->root; gn; gn = gn->next) {
+    const char *n;
+    if(! GAIM_BLIST_NODE_IS_GROUP(gn)) continue;
+    n = gaim_blist_node_get_string(gn, GROUP_KEY_NAME);
+
+    if(n && !strcmp(n, name)) {
+      group = (GaimGroup *) gn;
+      break;
+    }
+  }  
+
+  /* try again, by alias */
   group = gaim_find_group(alias);
+
+  /* oh well, no such group. Let's create it! */
   if(! group) {
     group = gaim_group_new(alias);
     gaim_blist_add_group(group, NULL);
   }
 
   gn = (GaimBlistNode *) group;
-
   gaim_blist_node_set_string(gn, GROUP_KEY_NAME, name);
   gaim_blist_node_set_int(gn, GROUP_KEY_TYPE, type);
 
@@ -3823,17 +3841,43 @@
 }
 
 
-static char *im_encode(GaimConnection *gc, const char *msg) {
+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);
 
   enc = gaim_account_get_string(acct, MW_KEY_ENCODING,
 				MW_PLUGIN_DEFAULT_ENCODING);
-
-  return im_try_convert(msg, enc, "UTF-8");
+  g_return_val_if_fail(enc != NULL, NULL);
+
+  ret = g_convert_with_fallback(message, -1, enc, "UTF-8",
+				"?", NULL, NULL, &error);
+  if(error) {
+    DEBUG_INFO("problem converting to %s: %s\n",
+	       enc, NSTR(error->message));
+    g_error_free(error);
+  }
+  return ret;
+}
+
+
+static gboolean is_nb(struct mwConversation *conv) {
+  struct mwLoginInfo *info;
+
+  info = mwConversation_getTargetInfo(conv);
+  if(! info) return FALSE;
+
+  /* NotesBuddy can be at least three different type IDs (all in the
+     0x1400 range), or it can show up as 0x1002. However, if we're
+     calling this check, then we're already in HTML or MIME mode, so
+     we can discount the real 0x1002 */
+  /* I tried to avoid having any client-type-dependant code in here, I
+     really did. Oh well. CURSE YOU NOTESBUDDY */
+  return ((info->type == 0x1002) || (info->type & 0x1400));
 }
 
 
@@ -3852,8 +3896,7 @@
 
   g_return_val_if_fail(pd != NULL, 0);
 
-  msg = im_encode(gc, message);
-  if(!msg) msg = g_strdup(message);
+  msg = g_strdup(message);
 
   conv = mwServiceIm_getConversation(pd->srvc_im, &who);
 
@@ -3876,6 +3919,12 @@
        mwConversation_supports(conv, mwImSend_MIME)) {
       /* send a MIME message */
 
+      /* mime messages need the notesbuddy hack */
+      if(is_nb(conv)) {
+	g_free(msg);
+	msg = nb_im_encode(gc, message);
+      }
+
       tmp = im_mime_convert(msg);
       g_free(msg);
 
@@ -3885,6 +3934,12 @@
     } else if(mwConversation_supports(conv, mwImSend_HTML)) {
       /* send an HTML message */
 
+      /* html messages need the notesbuddy hack */
+      if(is_nb(conv)) {
+	g_free(msg);
+	msg = nb_im_encode(gc, message);
+      }
+
       /* need to do this to get the \n to <br> conversion */
       tmp = gaim_strdup_withhtml(msg);
       g_free(msg);
@@ -5545,25 +5600,19 @@
 
 static void mw_log_handler(const gchar *domain, GLogLevelFlags flags,
 			   const gchar *msg, gpointer data) {
-  char *nl;
-
-  if(! msg) return;
-
-  /* annoying! */
-  nl = g_strdup_printf("%s\n", msg);
+
+  if(! (msg && *msg)) return;
 
   /* handle g_log requests via gaim's built-in debug logging */
   if(flags & G_LOG_LEVEL_ERROR) {
-    gaim_debug_error(domain, nl);
+    gaim_debug_error(domain, "%s\n", msg);
 
   } else if(flags & G_LOG_LEVEL_WARNING) {
-    gaim_debug_warning(domain, nl);
+    gaim_debug_warning(domain, "%s\n", msg);
 
   } else {
-    gaim_debug_info(domain, nl);
+    gaim_debug_info(domain, "%s\n", msg);
   }
-
-  g_free(nl);
 }
 
 
@@ -5592,8 +5641,9 @@
 				    MW_PLUGIN_DEFAULT_PORT);
   l = g_list_append(l, opt);
 
-  /* default attempted encoding */
-  opt = gaim_account_option_string_new(_("Encoding"), MW_KEY_ENCODING,
+  /* notesbuddy hack encoding */
+  opt = gaim_account_option_string_new(_("NotesBuddy Encoding"),
+				       MW_KEY_ENCODING,
 				       MW_PLUGIN_DEFAULT_ENCODING);
   l = g_list_append(l, opt);