213 void send_message(const char *msg) |
213 void send_message(const char *msg) |
214 { |
214 { |
215 const char *jid; |
215 const char *jid; |
216 |
216 |
217 if (!current_buddy) { |
217 if (!current_buddy) { |
218 scr_LogPrint("No buddy currently selected."); |
218 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); |
219 return; |
219 return; |
220 } |
220 } |
221 |
221 |
222 jid = CURRENT_JID; |
222 jid = CURRENT_JID; |
223 if (!jid) { |
223 if (!jid) { |
224 scr_LogPrint("No buddy currently selected."); |
224 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); |
225 return; |
225 return; |
226 } |
226 } |
227 |
227 |
228 // local part (UI, logging, etc.) |
228 // local part (UI, logging, etc.) |
229 hk_message_out(jid, 0, msg); |
229 hk_message_out(jid, 0, msg); |
267 |
267 |
268 // Commands handling |
268 // Commands handling |
269 curcmd = cmd_get(xpline); |
269 curcmd = cmd_get(xpline); |
270 |
270 |
271 if (!curcmd) { |
271 if (!curcmd) { |
272 scr_LogPrint("Unrecognized command, sorry."); |
272 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command, sorry."); |
273 if (xpline != line) g_free(xpline); |
273 if (xpline != line) g_free(xpline); |
274 return 0; |
274 return 0; |
275 } |
275 } |
276 if (!curcmd->func) { |
276 if (!curcmd->func) { |
277 scr_LogPrint("Not yet implemented, sorry."); |
277 scr_LogPrint(LPRINT_NORMAL, "Not yet implemented, sorry."); |
278 if (xpline != line) g_free(xpline); |
278 if (xpline != line) g_free(xpline); |
279 return 0; |
279 return 0; |
280 } |
280 } |
281 // Lets go to the command parameters |
281 // Lets go to the command parameters |
282 for (p = xpline+1; *p && (*p != ' ') ; p++) |
282 for (p = xpline+1; *p && (*p != ' ') ; p++) |
353 } else if (!strcasecmp(arg, "alternate")) { |
353 } else if (!strcasecmp(arg, "alternate")) { |
354 scr_RosterJumpAlternate(); |
354 scr_RosterJumpAlternate(); |
355 } else if (!strncasecmp(arg, "search", 6)) { |
355 } else if (!strncasecmp(arg, "search", 6)) { |
356 char *string = arg+6; |
356 char *string = arg+6; |
357 if (*string && (*string != ' ')) { |
357 if (*string && (*string != ' ')) { |
358 scr_LogPrint("Unrecognized parameter!"); |
358 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
359 return; |
359 return; |
360 } |
360 } |
361 while (*string == ' ') |
361 while (*string == ' ') |
362 string++; |
362 string++; |
363 if (!*string) { |
363 if (!*string) { |
364 scr_LogPrint("What name or jid are you looking for?"); |
364 scr_LogPrint(LPRINT_NORMAL, "What name or jid are you looking for?"); |
365 return; |
365 return; |
366 } |
366 } |
367 scr_RosterSearch(string); |
367 scr_RosterSearch(string); |
368 update_roster = TRUE; |
368 update_roster = TRUE; |
369 } else |
369 } else |
370 scr_LogPrint("Unrecognized parameter!"); |
370 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
371 } |
371 } |
372 |
372 |
373 static void do_status(char *arg) |
373 static void do_status(char *arg) |
374 { |
374 { |
375 enum imstatus st; |
375 enum imstatus st; |
376 int len; |
376 int len; |
377 char *msg; |
377 char *msg; |
378 |
378 |
379 if (!arg || (*arg == 0)) { |
379 if (!arg || (*arg == 0)) { |
380 scr_LogPrint("Your status is: %c", imstatus2char[jb_getstatus()]); |
380 scr_LogPrint(LPRINT_NORMAL, "Your status is: %c", |
|
381 imstatus2char[jb_getstatus()]); |
381 return; |
382 return; |
382 } |
383 } |
383 |
384 |
384 msg = strchr(arg, ' '); |
385 msg = strchr(arg, ' '); |
385 if (!msg) |
386 if (!msg) |
394 else if (!strncasecmp(arg, "invisible", len)) st = invisible; |
395 else if (!strncasecmp(arg, "invisible", len)) st = invisible; |
395 else if (!strncasecmp(arg, "dnd", len)) st = dontdisturb; |
396 else if (!strncasecmp(arg, "dnd", len)) st = dontdisturb; |
396 else if (!strncasecmp(arg, "notavail", len)) st = notavail; |
397 else if (!strncasecmp(arg, "notavail", len)) st = notavail; |
397 else if (!strncasecmp(arg, "free", len)) st = freeforchat; |
398 else if (!strncasecmp(arg, "free", len)) st = freeforchat; |
398 else { |
399 else { |
399 scr_LogPrint("Unrecognized parameter!"); |
400 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
400 return; |
401 return; |
401 } |
402 } |
402 |
403 |
403 if (msg && st != offline && st != invisible) { |
404 if (msg && st != offline && st != invisible) { |
404 for (msg++ ; *msg && *msg == ' ' ; msg++) ; |
405 for (msg++ ; *msg && *msg == ' ' ; msg++) ; |
426 } |
427 } |
427 |
428 |
428 // FIXME check id =~ jabber id |
429 // FIXME check id =~ jabber id |
429 // 2nd parameter = optional nickname |
430 // 2nd parameter = optional nickname |
430 jb_addbuddy(id, nick, NULL); |
431 jb_addbuddy(id, nick, NULL); |
431 scr_LogPrint("Sent presence notfication request to <%s>", id); |
432 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notfication request to <%s>", id); |
432 g_free(id); |
433 g_free(id); |
433 } |
434 } |
434 |
435 |
435 static void do_del(char *arg) |
436 static void do_del(char *arg) |
436 { |
437 { |
437 const char *jid; |
438 const char *jid; |
438 |
439 |
439 if (arg && (*arg)) { |
440 if (arg && (*arg)) { |
440 scr_LogPrint("Wrong usage"); |
441 scr_LogPrint(LPRINT_NORMAL, "Wrong usage"); |
441 return; |
442 return; |
442 } |
443 } |
443 |
444 |
444 if (!current_buddy) return; |
445 if (!current_buddy) return; |
445 jid = buddy_getjid(BUDDATA(current_buddy)); |
446 jid = buddy_getjid(BUDDATA(current_buddy)); |
446 if (!jid) return; |
447 if (!jid) return; |
447 |
448 |
448 scr_LogPrint("Removing <%s>...", jid); |
449 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid); |
449 jb_delbuddy(jid); |
450 jb_delbuddy(jid); |
450 } |
451 } |
451 |
452 |
452 static void do_group(char *arg) |
453 static void do_group(char *arg) |
453 { |
454 { |
454 gpointer group; |
455 gpointer group; |
455 guint leave_windowbuddy; |
456 guint leave_windowbuddy; |
456 |
457 |
457 if (!arg || (*arg == 0)) { |
458 if (!arg || (*arg == 0)) { |
458 scr_LogPrint("Missing parameter"); |
459 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
459 return; |
460 return; |
460 } |
461 } |
461 |
462 |
462 if (!current_buddy) return; |
463 if (!current_buddy) return; |
463 |
464 |
466 // entry itself, because it means we'll have to leave the current buddy |
467 // entry itself, because it means we'll have to leave the current buddy |
467 // chat window. |
468 // chat window. |
468 leave_windowbuddy = (group != BUDDATA(current_buddy)); |
469 leave_windowbuddy = (group != BUDDATA(current_buddy)); |
469 |
470 |
470 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) { |
471 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) { |
471 scr_LogPrint("You need to select a group"); |
472 scr_LogPrint(LPRINT_NORMAL, "You need to select a group"); |
472 return; |
473 return; |
473 } |
474 } |
474 |
475 |
475 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) { |
476 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) { |
476 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE); |
477 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE); |
478 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE); |
479 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE); |
479 } else if (!strcasecmp(arg, "toggle")) { |
480 } else if (!strcasecmp(arg, "toggle")) { |
480 buddy_setflags(group, ROSTER_FLAG_HIDE, |
481 buddy_setflags(group, ROSTER_FLAG_HIDE, |
481 !(buddy_getflags(group) & ROSTER_FLAG_HIDE)); |
482 !(buddy_getflags(group) & ROSTER_FLAG_HIDE)); |
482 } else { |
483 } else { |
483 scr_LogPrint("Unrecognized parameter!"); |
484 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
484 return; |
485 return; |
485 } |
486 } |
486 |
487 |
487 buddylist_build(); |
488 buddylist_build(); |
488 update_roster = TRUE; |
489 update_roster = TRUE; |
494 gpointer bud; |
495 gpointer bud; |
495 |
496 |
496 scr_set_chatmode(TRUE); |
497 scr_set_chatmode(TRUE); |
497 |
498 |
498 if (!current_buddy) { |
499 if (!current_buddy) { |
499 scr_LogPrint("Who are you talking to??"); |
500 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); |
500 return; |
501 return; |
501 } |
502 } |
502 |
503 |
503 bud = BUDDATA(current_buddy); |
504 bud = BUDDATA(current_buddy); |
504 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { |
505 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { |
505 scr_LogPrint("This is not a user"); |
506 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); |
506 return; |
507 return; |
507 } |
508 } |
508 |
509 |
509 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
510 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
510 send_message(arg); |
511 send_message(arg); |
515 /* Parameters: begin verbatim abort send */ |
516 /* Parameters: begin verbatim abort send */ |
516 gpointer bud; |
517 gpointer bud; |
517 |
518 |
518 if (!strcasecmp(arg, "abort")) { |
519 if (!strcasecmp(arg, "abort")) { |
519 if (scr_get_multimode()) |
520 if (scr_get_multimode()) |
520 scr_LogPrint("Leaving multi-line message mode"); |
521 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode"); |
521 scr_set_multimode(FALSE); |
522 scr_set_multimode(FALSE); |
522 return; |
523 return; |
523 } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) { |
524 } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) { |
524 if (!strcasecmp(arg, "verbatim")) |
525 if (!strcasecmp(arg, "verbatim")) |
525 scr_set_multimode(2); |
526 scr_set_multimode(2); |
526 else |
527 else |
527 scr_set_multimode(1); |
528 scr_set_multimode(1); |
528 |
529 |
529 scr_LogPrint("Entered multi-line message mode."); |
530 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); |
530 scr_LogPrint("Select a buddy and use \"/msay send\" " |
531 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " |
531 "when your message is ready."); |
532 "when your message is ready."); |
532 return; |
533 return; |
533 } else if (*arg == 0) { |
534 } else if (*arg == 0) { |
534 scr_LogPrint("Please read the manual before using the /msay command."); |
535 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " |
535 scr_LogPrint("(Use /msay begin to enter multi-line mode...)"); |
536 "the /msay command."); |
|
537 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter " |
|
538 "multi-line mode...)"); |
536 return; |
539 return; |
537 } else if (strcasecmp(arg, "send")) { |
540 } else if (strcasecmp(arg, "send")) { |
538 scr_LogPrint("Unrecognized parameter!"); |
541 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
539 return; |
542 return; |
540 } |
543 } |
541 |
544 |
542 // send command |
545 // send command |
543 |
546 |
544 if (!scr_get_multimode()) { |
547 if (!scr_get_multimode()) { |
545 scr_LogPrint("No message to send. Use \"/msay begin\" first."); |
548 scr_LogPrint(LPRINT_NORMAL, "No message to send. " |
|
549 "Use \"/msay begin\" first."); |
546 return; |
550 return; |
547 } |
551 } |
548 |
552 |
549 scr_set_chatmode(TRUE); |
553 scr_set_chatmode(TRUE); |
550 |
554 |
551 if (!current_buddy) { |
555 if (!current_buddy) { |
552 scr_LogPrint("Who are you talking to??"); |
556 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); |
553 return; |
557 return; |
554 } |
558 } |
555 |
559 |
556 bud = BUDDATA(current_buddy); |
560 bud = BUDDATA(current_buddy); |
557 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { |
561 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { |
558 scr_LogPrint("This is not a user"); |
562 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); |
559 return; |
563 return; |
560 } |
564 } |
561 |
565 |
562 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
566 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); |
563 send_message(scr_get_multiline()); |
567 send_message(scr_get_multiline()); |
577 } else if (!strncasecmp(arg, "search_backward", 15)) { |
581 } else if (!strncasecmp(arg, "search_backward", 15)) { |
578 arg += 15; |
582 arg += 15; |
579 if (*arg++ == ' ') |
583 if (*arg++ == ' ') |
580 search_dir = -1; |
584 search_dir = -1; |
581 else |
585 else |
582 scr_LogPrint("Missing parameter"); |
586 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
583 } else if (!strncasecmp(arg, "search_forward", 14)) { |
587 } else if (!strncasecmp(arg, "search_forward", 14)) { |
584 arg += 14; |
588 arg += 14; |
585 if (*arg++ == ' ') |
589 if (*arg++ == ' ') |
586 search_dir = 1; |
590 search_dir = 1; |
587 else |
591 else |
588 scr_LogPrint("Missing parameter"); |
592 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
589 } else |
593 } else |
590 scr_LogPrint("Unrecognized parameter!"); |
594 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
591 |
595 |
592 if (search_dir) { // It is a string search command |
596 if (search_dir) { // It is a string search command |
593 for ( ; *arg && *arg == ' ' ; arg++) |
597 for ( ; *arg && *arg == ' ' ; arg++) |
594 ; |
598 ; |
595 scr_BufferSearch(search_dir, arg); |
599 scr_BufferSearch(search_dir, arg); |
638 else if (type == ROSTER_TYPE_AGENT) typestr = "agent"; |
642 else if (type == ROSTER_TYPE_AGENT) typestr = "agent"; |
639 |
643 |
640 snprintf(buffer, 127, "Type: %s", typestr); |
644 snprintf(buffer, 127, "Type: %s", typestr); |
641 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
645 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
642 } else { |
646 } else { |
643 if (name) scr_LogPrint("Name: %s", name); |
647 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name); |
644 scr_LogPrint("Type: %s", |
648 scr_LogPrint(LPRINT_NORMAL, "Type: %s", |
645 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown")); |
649 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown")); |
646 } |
650 } |
647 |
651 |
648 g_free(buffer); |
652 g_free(buffer); |
649 } |
653 } |
666 jid = buddy_getjid(bud); |
670 jid = buddy_getjid(bud); |
667 group = buddy_getgroupname(bud); |
671 group = buddy_getgroupname(bud); |
668 type = buddy_gettype(bud); |
672 type = buddy_gettype(bud); |
669 |
673 |
670 if (type & ROSTER_TYPE_GROUP) { |
674 if (type & ROSTER_TYPE_GROUP) { |
671 scr_LogPrint("You can't rename groups"); |
675 scr_LogPrint(LPRINT_NORMAL, "You can't rename groups"); |
672 return; |
676 return; |
673 } |
677 } |
674 |
678 |
675 newname = g_strdup(arg); |
679 newname = g_strdup(arg); |
676 // Remove trailing space |
680 // Remove trailing space |
697 jid = buddy_getjid(bud); |
701 jid = buddy_getjid(bud); |
698 name = buddy_getname(bud); |
702 name = buddy_getname(bud); |
699 type = buddy_gettype(bud); |
703 type = buddy_gettype(bud); |
700 |
704 |
701 if (type & ROSTER_TYPE_GROUP) { |
705 if (type & ROSTER_TYPE_GROUP) { |
702 scr_LogPrint("You can't move groups!"); |
706 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!"); |
703 return; |
707 return; |
704 } |
708 } |
705 |
709 |
706 newgroupname = g_strdup(arg); |
710 newgroupname = g_strdup(arg); |
707 // Remove trailing space |
711 // Remove trailing space |
723 guint assign; |
727 guint assign; |
724 const gchar *option, *value; |
728 const gchar *option, *value; |
725 |
729 |
726 assign = parse_assigment(arg, &option, &value); |
730 assign = parse_assigment(arg, &option, &value); |
727 if (!option) { |
731 if (!option) { |
728 scr_LogPrint("Huh?"); |
732 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
729 return; |
733 return; |
730 } |
734 } |
731 if (!assign) { |
735 if (!assign) { |
732 // This is a query |
736 // This is a query |
733 value = settings_opt_get(option); |
737 value = settings_opt_get(option); |
734 if (value) { |
738 if (value) { |
735 scr_LogPrint("%s = [%s]", option, value); |
739 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option, value); |
736 } else |
740 } else |
737 scr_LogPrint("Option %s is not set", option); |
741 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option); |
738 return; |
742 return; |
739 } |
743 } |
740 // Update the option |
744 // Update the option |
741 // XXX Maybe some options should be protected when user is connected |
745 // XXX Maybe some options should be protected when user is connected |
742 // (server, username, etc.). And we should catch some options here, too |
746 // (server, username, etc.). And we should catch some options here, too |
753 guint assign; |
757 guint assign; |
754 const gchar *alias, *value; |
758 const gchar *alias, *value; |
755 |
759 |
756 assign = parse_assigment(arg, &alias, &value); |
760 assign = parse_assigment(arg, &alias, &value); |
757 if (!alias) { |
761 if (!alias) { |
758 scr_LogPrint("Huh?"); |
762 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
759 return; |
763 return; |
760 } |
764 } |
761 if (!assign) { |
765 if (!assign) { |
762 // This is a query |
766 // This is a query |
763 value = settings_get(SETTINGS_TYPE_ALIAS, alias); |
767 value = settings_get(SETTINGS_TYPE_ALIAS, alias); |
764 if (value) { |
768 if (value) { |
765 scr_LogPrint("%s = %s", alias, value); |
769 scr_LogPrint(LPRINT_NORMAL, "%s = %s", alias, value); |
766 } else |
770 } else |
767 scr_LogPrint("Alias '%s' does not exist", alias); |
771 scr_LogPrint(LPRINT_NORMAL, "Alias '%s' does not exist", alias); |
768 return; |
772 return; |
769 } |
773 } |
770 // Check the alias does not conflict with a registered command |
774 // Check the alias does not conflict with a registered command |
771 if (cmd_get(alias)) { |
775 if (cmd_get(alias)) { |
772 scr_LogPrint("'%s' is a reserved word!", alias); |
776 scr_LogPrint(LPRINT_NORMAL, "'%s' is a reserved word!", alias); |
773 return; |
777 return; |
774 } |
778 } |
775 // Update the alias |
779 // Update the alias |
776 if (!value) { |
780 if (!value) { |
777 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { |
781 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { |
792 guint assign; |
796 guint assign; |
793 const gchar *keycode, *value; |
797 const gchar *keycode, *value; |
794 |
798 |
795 assign = parse_assigment(arg, &keycode, &value); |
799 assign = parse_assigment(arg, &keycode, &value); |
796 if (!keycode) { |
800 if (!keycode) { |
797 scr_LogPrint("Huh?"); |
801 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
798 return; |
802 return; |
799 } |
803 } |
800 if (!assign) { |
804 if (!assign) { |
801 // This is a query |
805 // This is a query |
802 value = settings_get(SETTINGS_TYPE_BINDING, keycode); |
806 value = settings_get(SETTINGS_TYPE_BINDING, keycode); |
803 if (value) { |
807 if (value) { |
804 scr_LogPrint("Key %s is bound to: %s", keycode, value); |
808 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", keycode, value); |
805 } else |
809 } else |
806 scr_LogPrint("Key %s is not bound", keycode); |
810 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound", keycode); |
807 return; |
811 return; |
808 } |
812 } |
809 // Update the key binding |
813 // Update the key binding |
810 if (!value) |
814 if (!value) |
811 settings_del(SETTINGS_TYPE_BINDING, keycode); |
815 settings_del(SETTINGS_TYPE_BINDING, keycode); |