comparison mcabber/mcabber/commands.c @ 2013:8dc418af3e72

Allow to select to which buddy resource messages go. Closes issue #55
author Hermitifier
date Thu, 01 Mar 2012 15:10:41 +0100
parents a73ce708c2c9
children e9b6e168a45e
comparison
equal deleted inserted replaced
2012:2039ea6bd7a5 2013:8dc418af3e72
278 compl_add_category_word(COMPL_ROSTER, "alternate"); 278 compl_add_category_word(COMPL_ROSTER, "alternate");
279 compl_add_category_word(COMPL_ROSTER, "search"); 279 compl_add_category_word(COMPL_ROSTER, "search");
280 compl_add_category_word(COMPL_ROSTER, "unread_first"); 280 compl_add_category_word(COMPL_ROSTER, "unread_first");
281 compl_add_category_word(COMPL_ROSTER, "unread_next"); 281 compl_add_category_word(COMPL_ROSTER, "unread_next");
282 compl_add_category_word(COMPL_ROSTER, "note"); 282 compl_add_category_word(COMPL_ROSTER, "note");
283 compl_add_category_word(COMPL_ROSTER, "resource_lock");
284 compl_add_category_word(COMPL_ROSTER, "resource_unlock");
283 285
284 // Buffer category 286 // Buffer category
285 compl_add_category_word(COMPL_BUFFER, "clear"); 287 compl_add_category_word(COMPL_BUFFER, "clear");
286 compl_add_category_word(COMPL_BUFFER, "bottom"); 288 compl_add_category_word(COMPL_BUFFER, "bottom");
287 compl_add_category_word(COMPL_BUFFER, "top"); 289 compl_add_category_word(COMPL_BUFFER, "top");
618 update_roster = TRUE; 620 update_roster = TRUE;
619 } 621 }
620 } 622 }
621 } 623 }
622 624
625 static void roster_resourcelock(char *jidres, gboolean lock) {
626 gpointer bud = NULL;
627 char *resource = NULL;
628
629 if (!jidres) {
630 if (lock) return;
631 jidres = ".";
632 }
633
634 if (jidres[0] == '.' &&
635 (jidres[1] == '\0' || jidres[1] == JID_RESOURCE_SEPARATOR)) {
636 //Special jid: . or ./resource
637 switch (jidres[1]) {
638 case JID_RESOURCE_SEPARATOR:
639 resource = jidres+2;
640 case '\0':
641 if (current_buddy)
642 bud = BUDDATA(current_buddy);
643 }
644 } else {
645 char *tmp;
646 if (!check_jid_syntax(jidres) &&
647 (tmp = strchr(jidres, JID_RESOURCE_SEPARATOR))) {
648 //Any other valid full jid
649 *tmp = '\0'; // for roster search by bare jid;
650 resource = tmp+1;
651 GSList *roster_elt;
652 roster_elt = roster_find(jidres, jidsearch,
653 ROSTER_TYPE_USER|ROSTER_TYPE_AGENT);
654 if (roster_elt)
655 bud = roster_elt->data;
656 *tmp = JID_RESOURCE_SEPARATOR;
657 }
658 if (!bud) {
659 //Resource for current buddy
660 if (current_buddy)
661 bud = BUDDATA(current_buddy);
662 resource = jidres;
663 }
664 }
665
666 if (bud && buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT)) {
667 if (lock) {
668 GSList *resources, *p_res;
669 gboolean found = FALSE;
670 resources = buddy_getresources(bud);
671 for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) {
672 if (!g_strcmp0((char*)p_res->data, resource))
673 found = TRUE;
674 g_free(p_res->data);
675 }
676 g_slist_free(resources);
677 if (!found) {
678 scr_LogPrint(LPRINT_NORMAL, "No such resource <%s>...", jidres);
679 return;
680 }
681 } else {
682 resource = NULL;
683 }
684 buddy_setactiveresource(bud, resource);
685 scr_update_chat_status(TRUE);
686 }
687 }
623 // display_and_free_note(note, winId) 688 // display_and_free_note(note, winId)
624 // Display the note information in the winId buffer, and free note 689 // Display the note information in the winId buffer, and free note
625 // (winId is a bare jid or NULL for the status window, in which case we 690 // (winId is a bare jid or NULL for the status window, in which case we
626 // display the note jid too) 691 // display the note jid too)
627 static void display_and_free_note(struct annotation *note, const char *winId) 692 static void display_and_free_note(struct annotation *note, const char *winId)
823 scr_roster_prev_group(); 888 scr_roster_prev_group();
824 } else if (!strcasecmp(subcmd, "group_next")) { 889 } else if (!strcasecmp(subcmd, "group_next")) {
825 scr_roster_next_group(); 890 scr_roster_next_group();
826 } else if (!strcasecmp(subcmd, "note")) { 891 } else if (!strcasecmp(subcmd, "note")) {
827 roster_note(arg); 892 roster_note(arg);
893 } else if (!strcasecmp(subcmd, "resource_lock")) {
894 roster_resourcelock(arg, TRUE);
895 } else if (!strcasecmp(subcmd, "resource_unlock")) {
896 roster_resourcelock(arg, FALSE);
828 } else 897 } else
829 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 898 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
830 free_arg_lst(paramlst); 899 free_arg_lst(paramlst);
831 } 900 }
832 901
1284 // the network. 1353 // the network.
1285 static void send_message(const char *msg, const char *subj, 1354 static void send_message(const char *msg, const char *subj,
1286 LmMessageSubType type_overwrite) 1355 LmMessageSubType type_overwrite)
1287 { 1356 {
1288 const char *bjid; 1357 const char *bjid;
1358 char *jid;
1359 const char *activeres;
1289 1360
1290 if (!current_buddy) { 1361 if (!current_buddy) {
1291 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); 1362 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
1292 return; 1363 return;
1293 } 1364 }
1296 if (!bjid) { 1367 if (!bjid) {
1297 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); 1368 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
1298 return; 1369 return;
1299 } 1370 }
1300 1371
1301 send_message_to(bjid, msg, subj, type_overwrite, FALSE); 1372 activeres = buddy_getactiveresource(BUDDATA(current_buddy));
1373 if (activeres)
1374 jid = g_strdup_printf("%s/%s", bjid, activeres);
1375 else
1376 jid = g_strdup(bjid);
1377
1378 send_message_to(jid, msg, subj, type_overwrite, FALSE);
1379 g_free(jid);
1302 } 1380 }
1303 1381
1304 static LmMessageSubType scan_mtype(char **arg) 1382 static LmMessageSubType scan_mtype(char **arg)
1305 { 1383 {
1306 // Try splitting it 1384 // Try splitting it