comparison src/protocols/sametime/sametime.c @ 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 258871a62600
children aacda65b3449
comparison
equal deleted inserted replaced
12812:7e6de7079eeb 12813:547c199072c8
64 #include <mw_srvc_place.h> 64 #include <mw_srvc_place.h>
65 #include <mw_srvc_resolve.h> 65 #include <mw_srvc_resolve.h>
66 #include <mw_srvc_store.h> 66 #include <mw_srvc_store.h>
67 #include <mw_st_list.h> 67 #include <mw_st_list.h>
68 68
69 /* project includes */ 69 /* plugin includes */
70 #include "sametime.h" 70 #include "sametime.h"
71 71
72 72
73 /* considering that there's no display of this information for prpls, 73 /* considering that there's no display of this information for prpls,
74 I don't know why I even bother providing these. Oh valiant reader, 74 I don't know why I even bother providing these. Oh valiant reader,
89 #define MW_PRPL_OPT_FORCE_LOGIN MW_PRPL_OPT_BASE "/force_login" 89 #define MW_PRPL_OPT_FORCE_LOGIN MW_PRPL_OPT_BASE "/force_login"
90 #define MW_PRPL_OPT_SAVE_DYNAMIC MW_PRPL_OPT_BASE "/save_dynamic" 90 #define MW_PRPL_OPT_SAVE_DYNAMIC MW_PRPL_OPT_BASE "/save_dynamic"
91 91
92 92
93 /* stages of connecting-ness */ 93 /* stages of connecting-ness */
94 #define MW_CONNECT_STEPS 9 94 #define MW_CONNECT_STEPS 10
95 95
96 96
97 /* stages of conciousness */ 97 /* stages of conciousness */
98 #define MW_STATE_OFFLINE "offline" 98 #define MW_STATE_OFFLINE "offline"
99 #define MW_STATE_ACTIVE "active" 99 #define MW_STATE_ACTIVE "active"
1299 acct = gaim_connection_get_account(gc); 1299 acct = gaim_connection_get_account(gc);
1300 1300
1301 /* grab the buddy list from the server */ 1301 /* grab the buddy list from the server */
1302 unit = mwStorageUnit_new(mwStore_AWARE_LIST); 1302 unit = mwStorageUnit_new(mwStore_AWARE_LIST);
1303 mwServiceStorage_load(pd->srvc_store, unit, fetch_blist_cb, pd, NULL); 1303 mwServiceStorage_load(pd->srvc_store, unit, fetch_blist_cb, pd, NULL);
1304
1305 /* start watching for new conversations */
1306 gaim_signal_connect(gaim_conversations_get_handle(),
1307 "conversation-created", gc,
1308 GAIM_CALLBACK(conversation_created_cb), pd);
1309
1310 /* watch for group extended menu items */
1311 gaim_signal_connect(gaim_blist_get_handle(),
1312 "blist-node-extended-menu", gc,
1313 GAIM_CALLBACK(blist_node_menu_cb), pd);
1314 1304
1315 /* find all the NAB groups and subscribe to them */ 1305 /* find all the NAB groups and subscribe to them */
1316 blist = gaim_get_blist(); 1306 blist = gaim_get_blist();
1317 for(l = blist->root; l; l = l->next) { 1307 for(l = blist->root; l; l = l->next) {
1318 GaimGroup *group = (GaimGroup *) l; 1308 GaimGroup *group = (GaimGroup *) l;
1376 here */ 1366 here */
1377 static void session_started(struct mwGaimPluginData *pd) { 1367 static void session_started(struct mwGaimPluginData *pd) {
1378 GaimStatus *status; 1368 GaimStatus *status;
1379 GaimAccount *acct; 1369 GaimAccount *acct;
1380 1370
1371 /* set out initial status */
1381 acct = gaim_connection_get_account(pd->gc); 1372 acct = gaim_connection_get_account(pd->gc);
1382 status = gaim_account_get_active_status(acct); 1373 status = gaim_account_get_active_status(acct);
1383 mw_prpl_set_status(acct, status); 1374 mw_prpl_set_status(acct, status);
1375
1376 /* start watching for new conversations */
1377 gaim_signal_connect(gaim_conversations_get_handle(),
1378 "conversation-created", pd->gc,
1379 GAIM_CALLBACK(conversation_created_cb), pd);
1380
1381 /* watch for group extended menu items */
1382 gaim_signal_connect(gaim_blist_get_handle(),
1383 "blist-node-extended-menu", pd->gc,
1384 GAIM_CALLBACK(blist_node_menu_cb), pd);
1384 1385
1385 /* use our services to do neat things */ 1386 /* use our services to do neat things */
1386 services_starting(pd); 1387 services_starting(pd);
1387 } 1388 }
1388 1389
1432 msg = _("Login Acknowledged"); 1433 msg = _("Login Acknowledged");
1433 gaim_connection_update_progress(gc, msg, 8, MW_CONNECT_STEPS); 1434 gaim_connection_update_progress(gc, msg, 8, MW_CONNECT_STEPS);
1434 break; 1435 break;
1435 1436
1436 case mwSession_STARTED: 1437 case mwSession_STARTED:
1437 msg = _("Connected to Sametime Community Server"); 1438 msg = _("Starting Services");
1438 gaim_connection_update_progress(gc, msg, 9, MW_CONNECT_STEPS); 1439 gaim_connection_update_progress(gc, msg, 9, MW_CONNECT_STEPS);
1440
1441 session_started(pd);
1442
1443 msg = _("Connected");
1444 gaim_connection_update_progress(gc, msg, 10, MW_CONNECT_STEPS);
1439 gaim_connection_set_state(gc, GAIM_CONNECTED); 1445 gaim_connection_set_state(gc, GAIM_CONNECTED);
1440
1441 session_started(pd);
1442 break; 1446 break;
1443 1447
1444 case mwSession_STOPPING: 1448 case mwSession_STOPPING:
1445 if(GPOINTER_TO_UINT(info) & ERR_FAILURE) { 1449 if(GPOINTER_TO_UINT(info) & ERR_FAILURE) {
1446 msg = mwError(GPOINTER_TO_UINT(info)); 1450 msg = mwError(GPOINTER_TO_UINT(info));
1518 } 1522 }
1519 1523
1520 1524
1521 static void mw_session_admin(struct mwSession *session, 1525 static void mw_session_admin(struct mwSession *session,
1522 const char *text) { 1526 const char *text) {
1523 1527 GaimConnection *gc;
1524 GaimConnection *gc = session_to_gc(session); 1528 GaimAccount *acct;
1529 const char *host;
1530 char *prim;
1531
1532 gc = session_to_gc(session);
1525 g_return_if_fail(gc != NULL); 1533 g_return_if_fail(gc != NULL);
1526 1534
1527 /** @todo Admin alerts should probably be in a conversation window 1535 acct = gaim_connection_get_account(gc);
1528 rather than a gaim_notify_message. Or in some sort of updating 1536 g_return_if_fail(acct != NULL);
1529 dialog, or something. */ 1537
1530 1538 host = gaim_account_get_string(acct, MW_KEY_HOST, NULL);
1531 gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO, _("Admin Alert"), 1539
1532 text, NULL, NULL, NULL); 1540 prim = _("A Sametime administrator has issued the following announcement"
1541 " on server %s");
1542 prim = g_strdup_printf(prim, NSTR(host));
1543
1544 gaim_notify_message(gc, GAIM_NOTIFY_MSG_INFO,
1545 _("Sametime Administrator Announcement"),
1546 prim, text, NULL, NULL);
1547
1548 g_free(prim);
1533 } 1549 }
1534 1550
1535 1551
1536 /** called from read_cb, attempts to read available data from sock and 1552 /** called from read_cb, attempts to read available data from sock and
1537 pass it to the session, passing back the return code from the read 1553 pass it to the session, passing back the return code from the read
3709 const char *fn = gaim_imgstore_get_filename(img); 3725 const char *fn = gaim_imgstore_get_filename(img);
3710 return g_strdup_printf("attachment; filename=\"%s\"", fn); 3726 return g_strdup_printf("attachment; filename=\"%s\"", fn);
3711 } 3727 }
3712 3728
3713 3729
3730 #if NB_HACK
3714 static char *nb_im_encode(GaimConnection *gc, const char *message) { 3731 static char *nb_im_encode(GaimConnection *gc, const char *message) {
3715 GaimAccount *acct; 3732 GaimAccount *acct;
3716 const char *enc; 3733 const char *enc;
3717 char *ret; 3734 char *ret;
3718 GError *error = NULL; 3735 GError *error = NULL;
3719 3736
3720 acct = gaim_connection_get_account(gc); 3737 acct = gaim_connection_get_account(gc);
3721 g_return_val_if_fail(acct != NULL, NULL); 3738 g_return_val_if_fail(acct != NULL, NULL);
3722 3739
3723 enc = gaim_account_get_string(acct, MW_KEY_ENCODING, 3740 enc = gaim_account_get_string(acct, MW_KEY_ENCODING,
3724 MW_PLUGIN_DEFAULT_ENCODING); 3741 MW_PLUGIN_DEFAULT_ENCODING);
3737 /* something went so wrong that not even the fallback worked */ 3754 /* something went so wrong that not even the fallback worked */
3738 if(! ret) ret = g_strdup(message); 3755 if(! ret) ret = g_strdup(message);
3739 3756
3740 return ret; 3757 return ret;
3741 } 3758 }
3742 3759 #endif
3743 3760
3761
3762 #if NB_HACK
3744 static gboolean is_nb(struct mwConversation *conv) { 3763 static gboolean is_nb(struct mwConversation *conv) {
3745 struct mwLoginInfo *info; 3764 struct mwLoginInfo *info;
3746 3765
3747 info = mwConversation_getTargetInfo(conv); 3766 info = mwConversation_getTargetInfo(conv);
3748 if(! info) return FALSE; 3767 if(! info) return FALSE;
3753 we can discount the real 0x1000 */ 3772 we can discount the real 0x1000 */
3754 /* I tried to avoid having any client-type-dependant code in here, I 3773 /* I tried to avoid having any client-type-dependant code in here, I
3755 really did. Oh well. CURSE YOU NOTESBUDDY */ 3774 really did. Oh well. CURSE YOU NOTESBUDDY */
3756 return ((info->type == 0x1000) || ((info->type & 0xff00) == 0x1400)); 3775 return ((info->type == 0x1000) || ((info->type & 0xff00) == 0x1400));
3757 } 3776 }
3777 #endif
3758 3778
3759 3779
3760 /** turn an IM with embedded images into a multi-part mime document */ 3780 /** turn an IM with embedded images into a multi-part mime document */
3761 static char *im_mime_convert(GaimConnection *gc, 3781 static char *im_mime_convert(GaimConnection *gc,
3762 struct mwConversation *conv, 3782 struct mwConversation *conv,
3845 3865
3846 /* add the text/html part */ 3866 /* add the text/html part */
3847 part = gaim_mime_part_new(doc); 3867 part = gaim_mime_part_new(doc);
3848 gaim_mime_part_set_field(part, "Content-Disposition", "inline"); 3868 gaim_mime_part_set_field(part, "Content-Disposition", "inline");
3849 3869
3870 #if NB_HACK
3850 if(is_nb(conv)) { 3871 if(is_nb(conv)) {
3851 GaimAccount *acct = gaim_connection_get_account(gc); 3872 GaimAccount *acct = gaim_connection_get_account(gc);
3852 3873
3853 tmp = (char *) gaim_account_get_string(acct, MW_KEY_ENCODING, 3874 tmp = (char *) gaim_account_get_string(acct, MW_KEY_ENCODING,
3854 MW_PLUGIN_DEFAULT_ENCODING); 3875 MW_PLUGIN_DEFAULT_ENCODING);
3866 gaim_mime_part_set_field(part, "Content-Type", "text/html"); 3887 gaim_mime_part_set_field(part, "Content-Type", "text/html");
3867 gaim_mime_part_set_field(part, "Content-Transfer-Encoding", "8bit"); 3888 gaim_mime_part_set_field(part, "Content-Transfer-Encoding", "8bit");
3868 gaim_mime_part_set_data(part, str->str); 3889 gaim_mime_part_set_data(part, str->str);
3869 } 3890 }
3870 3891
3892 #else
3893 tmp = gaim_utf8_ncr_encode(str->str);
3894 gaim_mime_part_set_field(part, "Content-Type", "text/html");
3895 gaim_mime_part_set_field(part, "Content-Transfer-Encoding", "7bit");
3896 gaim_mime_part_set_data(part, str->str);
3897 g_free(tmp);
3898 #endif
3899
3871 g_string_free(str, TRUE); 3900 g_string_free(str, TRUE);
3872 3901
3873 str = g_string_new(NULL); 3902 str = g_string_new(NULL);
3874 gaim_mime_document_write(doc, str); 3903 gaim_mime_document_write(doc, str);
3875 tmp = str->str; 3904 tmp = str->str;
3919 g_free(tmp); 3948 g_free(tmp);
3920 3949
3921 } else if(mwConversation_supports(conv, mwImSend_HTML)) { 3950 } else if(mwConversation_supports(conv, mwImSend_HTML)) {
3922 /* send an HTML message */ 3951 /* send an HTML message */
3923 3952
3953 #if NB_HACK
3924 if(is_nb(conv)) { 3954 if(is_nb(conv)) {
3925 3955
3926 /* html messages need the notesbuddy hack */ 3956 /* html messages need the notesbuddy hack */
3927 char *msg = nb_im_encode(gc, message); 3957 char *msg = nb_im_encode(gc, message);
3928 tmp = gaim_strdup_withhtml(msg); 3958 tmp = gaim_strdup_withhtml(msg);
3930 3960
3931 } else { 3961 } else {
3932 /* need to do this to get the \n to <br> conversion */ 3962 /* need to do this to get the \n to <br> conversion */
3933 tmp = gaim_strdup_withhtml(message); 3963 tmp = gaim_strdup_withhtml(message);
3934 } 3964 }
3965
3966 #else
3967 char *ncr;
3968 ncr = gaim_utf8_ncr_encode(message);
3969 tmp = gaim_strdup_withhtml(ncr);
3970 g_free(ncr);
3971 #endif
3935 3972
3936 ret = mwConversation_send(conv, mwImSend_HTML, tmp); 3973 ret = mwConversation_send(conv, mwImSend_HTML, tmp);
3937 g_free(tmp); 3974 g_free(tmp);
3938 3975
3939 } else { 3976 } else {
5602 /* port to connect to */ 5639 /* port to connect to */
5603 opt = gaim_account_option_int_new(_("Port"), MW_KEY_PORT, 5640 opt = gaim_account_option_int_new(_("Port"), MW_KEY_PORT,
5604 MW_PLUGIN_DEFAULT_PORT); 5641 MW_PLUGIN_DEFAULT_PORT);
5605 l = g_list_append(l, opt); 5642 l = g_list_append(l, opt);
5606 5643
5644 #if NB_HACK
5607 /* notesbuddy hack encoding */ 5645 /* notesbuddy hack encoding */
5608 opt = gaim_account_option_string_new(_("NotesBuddy encoding"), 5646 opt = gaim_account_option_string_new(_("NotesBuddy encoding"),
5609 MW_KEY_ENCODING, 5647 MW_KEY_ENCODING,
5610 MW_PLUGIN_DEFAULT_ENCODING); 5648 MW_PLUGIN_DEFAULT_ENCODING);
5611 l = g_list_append(l, opt); 5649 l = g_list_append(l, opt);
5650 #endif
5612 5651
5613 { /* copy the old force login setting from prefs if it's 5652 { /* copy the old force login setting from prefs if it's
5614 there. Don't delete the preference, since there may be more 5653 there. Don't delete the preference, since there may be more
5615 than one account that wants to check for it. */ 5654 than one account that wants to check for it. */
5616 gboolean b = FALSE; 5655 gboolean b = FALSE;