comparison src/protocols/sametime/sametime.c @ 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 4824e4f0c6f3
children de25a063aebe
comparison
equal deleted inserted replaced
12004:8d5ebd7d4ec3 12005:5b3368008513
806 appropriately matching the st group entry from the st list */ 806 appropriately matching the st group entry from the st list */
807 static GaimGroup *group_ensure(GaimConnection *gc, 807 static GaimGroup *group_ensure(GaimConnection *gc,
808 struct mwSametimeGroup *stgroup) { 808 struct mwSametimeGroup *stgroup) {
809 GaimAccount *acct; 809 GaimAccount *acct;
810 GaimGroup *group; 810 GaimGroup *group;
811 GaimBuddyList *blist;
811 GaimBlistNode *gn; 812 GaimBlistNode *gn;
812 const char *name, *alias, *owner; 813 const char *name, *alias, *owner;
813 enum mwSametimeGroupType type; 814 enum mwSametimeGroupType type;
814 815
815 acct = gaim_connection_get_account(gc); 816 acct = gaim_connection_get_account(gc);
816 owner = gaim_account_get_username(acct); 817 owner = gaim_account_get_username(acct);
817 818
819 blist = gaim_get_blist();
820 g_return_val_if_fail(blist != NULL, NULL);
821
818 name = mwSametimeGroup_getName(stgroup); 822 name = mwSametimeGroup_getName(stgroup);
819 alias = mwSametimeGroup_getAlias(stgroup); 823 alias = mwSametimeGroup_getAlias(stgroup);
820 type = mwSametimeGroup_getType(stgroup); 824 type = mwSametimeGroup_getType(stgroup);
821 825
826 /* first attempt at finding the group, by the name key */
827 for(gn = blist->root; gn; gn = gn->next) {
828 const char *n;
829 if(! GAIM_BLIST_NODE_IS_GROUP(gn)) continue;
830 n = gaim_blist_node_get_string(gn, GROUP_KEY_NAME);
831
832 if(n && !strcmp(n, name)) {
833 group = (GaimGroup *) gn;
834 break;
835 }
836 }
837
838 /* try again, by alias */
822 group = gaim_find_group(alias); 839 group = gaim_find_group(alias);
840
841 /* oh well, no such group. Let's create it! */
823 if(! group) { 842 if(! group) {
824 group = gaim_group_new(alias); 843 group = gaim_group_new(alias);
825 gaim_blist_add_group(group, NULL); 844 gaim_blist_add_group(group, NULL);
826 } 845 }
827 846
828 gn = (GaimBlistNode *) group; 847 gn = (GaimBlistNode *) group;
829
830 gaim_blist_node_set_string(gn, GROUP_KEY_NAME, name); 848 gaim_blist_node_set_string(gn, GROUP_KEY_NAME, name);
831 gaim_blist_node_set_int(gn, GROUP_KEY_TYPE, type); 849 gaim_blist_node_set_int(gn, GROUP_KEY_TYPE, type);
832 850
833 if(type == mwSametimeGroup_DYNAMIC) { 851 if(type == mwSametimeGroup_DYNAMIC) {
834 gaim_blist_node_set_string(gn, GROUP_KEY_OWNER, owner); 852 gaim_blist_node_set_string(gn, GROUP_KEY_OWNER, owner);
3821 3839
3822 return ret; 3840 return ret;
3823 } 3841 }
3824 3842
3825 3843
3826 static char *im_encode(GaimConnection *gc, const char *msg) { 3844 static char *nb_im_encode(GaimConnection *gc, const char *message) {
3827 GaimAccount *acct; 3845 GaimAccount *acct;
3828 const char *enc; 3846 const char *enc;
3847 char *ret;
3848 GError *error = NULL;
3829 3849
3830 acct = gaim_connection_get_account(gc); 3850 acct = gaim_connection_get_account(gc);
3831 g_return_val_if_fail(acct != NULL, NULL); 3851 g_return_val_if_fail(acct != NULL, NULL);
3832 3852
3833 enc = gaim_account_get_string(acct, MW_KEY_ENCODING, 3853 enc = gaim_account_get_string(acct, MW_KEY_ENCODING,
3834 MW_PLUGIN_DEFAULT_ENCODING); 3854 MW_PLUGIN_DEFAULT_ENCODING);
3835 3855 g_return_val_if_fail(enc != NULL, NULL);
3836 return im_try_convert(msg, enc, "UTF-8"); 3856
3857 ret = g_convert_with_fallback(message, -1, enc, "UTF-8",
3858 "?", NULL, NULL, &error);
3859 if(error) {
3860 DEBUG_INFO("problem converting to %s: %s\n",
3861 enc, NSTR(error->message));
3862 g_error_free(error);
3863 }
3864 return ret;
3865 }
3866
3867
3868 static gboolean is_nb(struct mwConversation *conv) {
3869 struct mwLoginInfo *info;
3870
3871 info = mwConversation_getTargetInfo(conv);
3872 if(! info) return FALSE;
3873
3874 /* NotesBuddy can be at least three different type IDs (all in the
3875 0x1400 range), or it can show up as 0x1002. However, if we're
3876 calling this check, then we're already in HTML or MIME mode, so
3877 we can discount the real 0x1002 */
3878 /* I tried to avoid having any client-type-dependant code in here, I
3879 really did. Oh well. CURSE YOU NOTESBUDDY */
3880 return ((info->type == 0x1002) || (info->type & 0x1400));
3837 } 3881 }
3838 3882
3839 3883
3840 static int mw_prpl_send_im(GaimConnection *gc, 3884 static int mw_prpl_send_im(GaimConnection *gc,
3841 const char *name, 3885 const char *name,
3850 g_return_val_if_fail(gc != NULL, 0); 3894 g_return_val_if_fail(gc != NULL, 0);
3851 pd = gc->proto_data; 3895 pd = gc->proto_data;
3852 3896
3853 g_return_val_if_fail(pd != NULL, 0); 3897 g_return_val_if_fail(pd != NULL, 0);
3854 3898
3855 msg = im_encode(gc, message); 3899 msg = g_strdup(message);
3856 if(!msg) msg = g_strdup(message);
3857 3900
3858 conv = mwServiceIm_getConversation(pd->srvc_im, &who); 3901 conv = mwServiceIm_getConversation(pd->srvc_im, &who);
3859 3902
3860 /* this detection of features to determine how to send the message 3903 /* this detection of features to determine how to send the message
3861 (plain, html, or mime) is flawed because the other end of the 3904 (plain, html, or mime) is flawed because the other end of the
3874 3917
3875 if((flags & GAIM_CONV_IM_IMAGES) && 3918 if((flags & GAIM_CONV_IM_IMAGES) &&
3876 mwConversation_supports(conv, mwImSend_MIME)) { 3919 mwConversation_supports(conv, mwImSend_MIME)) {
3877 /* send a MIME message */ 3920 /* send a MIME message */
3878 3921
3922 /* mime messages need the notesbuddy hack */
3923 if(is_nb(conv)) {
3924 g_free(msg);
3925 msg = nb_im_encode(gc, message);
3926 }
3927
3879 tmp = im_mime_convert(msg); 3928 tmp = im_mime_convert(msg);
3880 g_free(msg); 3929 g_free(msg);
3881 3930
3882 ret = mwConversation_send(conv, mwImSend_MIME, tmp); 3931 ret = mwConversation_send(conv, mwImSend_MIME, tmp);
3883 g_free(tmp); 3932 g_free(tmp);
3884 3933
3885 } else if(mwConversation_supports(conv, mwImSend_HTML)) { 3934 } else if(mwConversation_supports(conv, mwImSend_HTML)) {
3886 /* send an HTML message */ 3935 /* send an HTML message */
3936
3937 /* html messages need the notesbuddy hack */
3938 if(is_nb(conv)) {
3939 g_free(msg);
3940 msg = nb_im_encode(gc, message);
3941 }
3887 3942
3888 /* need to do this to get the \n to <br> conversion */ 3943 /* need to do this to get the \n to <br> conversion */
3889 tmp = gaim_strdup_withhtml(msg); 3944 tmp = gaim_strdup_withhtml(msg);
3890 g_free(msg); 3945 g_free(msg);
3891 3946
5543 }; 5598 };
5544 5599
5545 5600
5546 static void mw_log_handler(const gchar *domain, GLogLevelFlags flags, 5601 static void mw_log_handler(const gchar *domain, GLogLevelFlags flags,
5547 const gchar *msg, gpointer data) { 5602 const gchar *msg, gpointer data) {
5548 char *nl; 5603
5549 5604 if(! (msg && *msg)) return;
5550 if(! msg) return;
5551
5552 /* annoying! */
5553 nl = g_strdup_printf("%s\n", msg);
5554 5605
5555 /* handle g_log requests via gaim's built-in debug logging */ 5606 /* handle g_log requests via gaim's built-in debug logging */
5556 if(flags & G_LOG_LEVEL_ERROR) { 5607 if(flags & G_LOG_LEVEL_ERROR) {
5557 gaim_debug_error(domain, nl); 5608 gaim_debug_error(domain, "%s\n", msg);
5558 5609
5559 } else if(flags & G_LOG_LEVEL_WARNING) { 5610 } else if(flags & G_LOG_LEVEL_WARNING) {
5560 gaim_debug_warning(domain, nl); 5611 gaim_debug_warning(domain, "%s\n", msg);
5561 5612
5562 } else { 5613 } else {
5563 gaim_debug_info(domain, nl); 5614 gaim_debug_info(domain, "%s\n", msg);
5564 } 5615 }
5565
5566 g_free(nl);
5567 } 5616 }
5568 5617
5569 5618
5570 static void mw_plugin_init(GaimPlugin *plugin) { 5619 static void mw_plugin_init(GaimPlugin *plugin) {
5571 GaimAccountOption *opt; 5620 GaimAccountOption *opt;
5590 /* port to connect to */ 5639 /* port to connect to */
5591 opt = gaim_account_option_int_new(_("Port"), MW_KEY_PORT, 5640 opt = gaim_account_option_int_new(_("Port"), MW_KEY_PORT,
5592 MW_PLUGIN_DEFAULT_PORT); 5641 MW_PLUGIN_DEFAULT_PORT);
5593 l = g_list_append(l, opt); 5642 l = g_list_append(l, opt);
5594 5643
5595 /* default attempted encoding */ 5644 /* notesbuddy hack encoding */
5596 opt = gaim_account_option_string_new(_("Encoding"), MW_KEY_ENCODING, 5645 opt = gaim_account_option_string_new(_("NotesBuddy Encoding"),
5646 MW_KEY_ENCODING,
5597 MW_PLUGIN_DEFAULT_ENCODING); 5647 MW_PLUGIN_DEFAULT_ENCODING);
5598 l = g_list_append(l, opt); 5648 l = g_list_append(l, opt);
5599 5649
5600 { /* copy the old force login setting from prefs if it's 5650 { /* copy the old force login setting from prefs if it's
5601 there. Don't delete the preference, since there may be more 5651 there. Don't delete the preference, since there may be more