1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Merge branch 'master' into plugins

This commit is contained in:
James Booth 2014-03-16 18:03:15 +00:00
commit 38e1ff22fc
8 changed files with 307 additions and 50 deletions

View File

@ -143,22 +143,22 @@ static struct cmd_t command_defs[] =
{ "/roster", { "/roster",
cmd_roster, parse_args_with_freetext, 0, 3, NULL, cmd_roster, parse_args_with_freetext, 0, 3, NULL,
{ "/roster [add|remove|nick] [jid] [handle]", "Manage your roster.", { "/roster [add|remove|nick|clearnick] [jid] [nickname]", "Manage your roster.",
{ "/roster [add|remove|nick] [jid] [handle]", { "/roster [add|remove|nick|clearnick] [jid] [nickname]",
"----------------------------------------", "----------------------------------------------------",
"View, add to, and remove from your roster.", "View, add to, and remove from your roster.",
"Passing no arguments lists all contacts in your roster.", "Passing no arguments lists all contacts in your roster.",
"The 'add' command will add a new item, the jid is required, the handle is an optional nickname", "The 'add' command will add a new item, jid is required, nickname is optional.",
"The 'remove' command removes a contact, the jid is required.", "The 'remove' command removes a contact, jid is required.",
"The 'nick' command changes a contacts nickname, the jid is required,", "The 'nick' command changes a contacts nickname, both jid and nickname are required,",
"if no handle is supplied, the current one is removed.", "The 'clearnick' command removes the current nickname, jid is required.",
"", "",
"Example : /roster (show your roster)", "Example : /roster (show your roster)",
"Example : /roster add someone@contacts.org (add the contact)", "Example : /roster add someone@contacts.org (add the contact)",
"Example : /roster add someone@contacts.org Buddy (add the contact with nickname 'Buddy')", "Example : /roster add someone@contacts.org Buddy (add the contact with nickname 'Buddy')",
"Example : /roster remove someone@contacts.org (remove the contact)", "Example : /roster remove someone@contacts.org (remove the contact)",
"Example : /roster nick myfriend@chat.org My Friend", "Example : /roster nick myfriend@chat.org My Friend",
"Example : /roster nick kai@server.com (clears handle)", "Example : /roster clearnick kai@server.com (clears nickname)",
NULL } } }, NULL } } },
{ "/group", { "/group",
@ -1022,6 +1022,7 @@ cmd_init(void)
roster_ac = autocomplete_new(); roster_ac = autocomplete_new();
autocomplete_add(roster_ac, "add"); autocomplete_add(roster_ac, "add");
autocomplete_add(roster_ac, "nick"); autocomplete_add(roster_ac, "nick");
autocomplete_add(roster_ac, "clearnick");
autocomplete_add(roster_ac, "remove"); autocomplete_add(roster_ac, "remove");
group_ac = autocomplete_new(); group_ac = autocomplete_new();
@ -1552,6 +1553,10 @@ _roster_autocomplete(char *input, int *size)
if (result != NULL) { if (result != NULL) {
return result; return result;
} }
result = autocomplete_param_with_func(input, size, "/roster clearnick", roster_find_jid);
if (result != NULL) {
return result;
}
result = autocomplete_param_with_func(input, size, "/roster remove", roster_find_jid); result = autocomplete_param_with_func(input, size, "/roster remove", roster_find_jid);
if (result != NULL) { if (result != NULL) {
return result; return result;

View File

@ -1203,49 +1203,41 @@ cmd_roster(gchar **args, struct cmd_help_t help)
GSList *list = roster_get_contacts(); GSList *list = roster_get_contacts();
cons_show_roster(list); cons_show_roster(list);
return TRUE; return TRUE;
}
// add contact // add contact
if (strcmp(args[0], "add") == 0) { } else if (strcmp(args[0], "add") == 0) {
if (args[1] == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *jid = args[1]; char *jid = args[1];
char *name = args[2]; if (jid == NULL) {
cons_show("Usage: %s", help.usage);
roster_send_add_new(jid, name); } else {
char *name = args[2];
roster_send_add_new(jid, name);
}
return TRUE; return TRUE;
}
// remove contact // remove contact
if (strcmp(args[0], "remove") == 0) { } else if (strcmp(args[0], "remove") == 0) {
if (args[1] == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
char *jid = args[1]; char *jid = args[1];
if (jid == NULL) {
roster_send_remove(jid); cons_show("Usage: %s", help.usage);
} else {
roster_send_remove(jid);
}
return TRUE; return TRUE;
}
// change nickname // change nickname
if (strcmp(args[0], "nick") == 0) { } else if (strcmp(args[0], "nick") == 0) {
char *jid = args[1];
if (args[1] == NULL) { if (jid == NULL) {
cons_show("Usage: %s", help.usage); cons_show("Usage: %s", help.usage);
return TRUE; return TRUE;
} }
char *jid = args[1];
char *name = args[2]; char *name = args[2];
if (name == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
// contact does not exist // contact does not exist
PContact contact = roster_get_contact(jid); PContact contact = roster_get_contact(jid);
@ -1259,17 +1251,37 @@ cmd_roster(gchar **args, struct cmd_help_t help)
GSList *groups = p_contact_groups(contact); GSList *groups = p_contact_groups(contact);
roster_send_name_change(barejid, name, groups); roster_send_name_change(barejid, name, groups);
if (name == NULL) { cons_show("Nickname for %s set to: %s.", jid, name);
cons_show("Nickname for %s removed.", jid);
} else {
cons_show("Nickname for %s set to: %s.", jid, name);
}
return TRUE; return TRUE;
}
cons_show("Usage: %s", help.usage); // remove nickname
return TRUE; } else if (strcmp(args[0], "clearnick") == 0) {
char *jid = args[1];
if (jid == NULL) {
cons_show("Usage: %s", help.usage);
return TRUE;
}
// contact does not exist
PContact contact = roster_get_contact(jid);
if (contact == NULL) {
cons_show("Contact not found in roster: %s", jid);
return TRUE;
}
const char *barejid = p_contact_barejid(contact);
roster_change_name(contact, NULL);
GSList *groups = p_contact_groups(contact);
roster_send_name_change(barejid, NULL, groups);
cons_show("Nickname for %s removed.", jid);
return TRUE;
} else {
cons_show("Usage: %s", help.usage);
return TRUE;
}
} }
gboolean gboolean

View File

@ -69,7 +69,7 @@ void cmd_roster_shows_roster_when_no_args(void **state)
roster_free(); roster_free();
} }
void cmd_roster_add_shows_message_when_no_jid(void) void cmd_roster_add_shows_message_when_no_jid(void **state)
{ {
mock_cons_show(); mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp)); CommandHelp *help = malloc(sizeof(CommandHelp));
@ -85,7 +85,7 @@ void cmd_roster_add_shows_message_when_no_jid(void)
free(help); free(help);
} }
void cmd_roster_add_sends_roster_add_request(void) void cmd_roster_add_sends_roster_add_request(void **state)
{ {
char *jid = "bob@server.org"; char *jid = "bob@server.org";
char *nick = "bob"; char *nick = "bob";
@ -101,3 +101,174 @@ void cmd_roster_add_sends_roster_add_request(void)
free(help); free(help);
} }
void cmd_roster_remove_shows_message_when_no_jid(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "remove", NULL };
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Usage: some usage");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}
void cmd_roster_remove_sends_roster_remove_request(void **state)
{
char *jid = "bob@server.org";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "remove", jid, NULL };
mock_roster_send_remove();
mock_connection_status(JABBER_CONNECTED);
roster_send_remove_expect(jid);
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}
void cmd_roster_nick_shows_message_when_no_jid(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "nick", NULL };
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Usage: some usage");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}
void cmd_roster_nick_shows_message_when_no_nick(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "nick", "bob@server.org", NULL };
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Usage: some usage");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}
void cmd_roster_nick_shows_message_when_no_contact_exists(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "nick", "bob@server.org", "bobster", NULL };
roster_init();
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Contact not found in roster: bob@server.org");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
roster_free();
}
void cmd_roster_nick_sends_name_change_request(void **state)
{
char *jid = "bob@server.org";
char *nick = "bobster";
mock_cons_show();
mock_roster_send_name_change();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "nick", jid, nick, NULL };
roster_init();
GSList *groups = NULL;
groups = g_slist_append(groups, "group1");
roster_add(jid, "bob", groups, "both", FALSE);
mock_connection_status(JABBER_CONNECTED);
roster_send_name_change_expect(jid, nick, groups);
expect_cons_show("Nickname for bob@server.org set to: bobster.");
gboolean result = cmd_roster(args, *help);
assert_true(result);
PContact contact = roster_get_contact(jid);
assert_string_equal(p_contact_name(contact), nick);
free(help);
roster_free();
}
void cmd_roster_clearnick_shows_message_when_no_jid(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "clearnick", NULL };
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Usage: some usage");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
}
void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state)
{
mock_cons_show();
CommandHelp *help = malloc(sizeof(CommandHelp));
help->usage = "some usage";
gchar *args[] = { "clearnick", "bob@server.org", NULL };
roster_init();
mock_connection_status(JABBER_CONNECTED);
expect_cons_show("Contact not found in roster: bob@server.org");
gboolean result = cmd_roster(args, *help);
assert_true(result);
free(help);
roster_free();
}
void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state)
{
char *jid = "bob@server.org";
mock_cons_show();
mock_roster_send_name_change();
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "clearnick", jid, NULL };
roster_init();
GSList *groups = NULL;
groups = g_slist_append(groups, "group1");
roster_add(jid, "bob", groups, "both", FALSE);
mock_connection_status(JABBER_CONNECTED);
roster_send_name_change_expect(jid, NULL, groups);
expect_cons_show("Nickname for bob@server.org removed.");
gboolean result = cmd_roster(args, *help);
assert_true(result);
PContact contact = roster_get_contact(jid);
assert_null(p_contact_name(contact));
free(help);
roster_free();
}

View File

@ -5,3 +5,12 @@ void cmd_roster_shows_message_when_undefined(void **state);
void cmd_roster_shows_roster_when_no_args(void **state); void cmd_roster_shows_roster_when_no_args(void **state);
void cmd_roster_add_shows_message_when_no_jid(void **state); void cmd_roster_add_shows_message_when_no_jid(void **state);
void cmd_roster_add_sends_roster_add_request(void **state); void cmd_roster_add_sends_roster_add_request(void **state);
void cmd_roster_remove_shows_message_when_no_jid(void **state);
void cmd_roster_remove_sends_roster_remove_request(void **state);
void cmd_roster_nick_shows_message_when_no_jid(void **state);
void cmd_roster_nick_shows_message_when_no_nick(void **state);
void cmd_roster_nick_shows_message_when_no_contact_exists(void **state);
void cmd_roster_nick_sends_name_change_request(void **state);
void cmd_roster_clearnick_shows_message_when_no_jid(void **state);
void cmd_roster_clearnick_shows_message_when_no_contact_exists(void **state);
void cmd_roster_clearnick_sends_name_change_request_with_empty_nick(void **state);

View File

@ -509,6 +509,15 @@ int main(int argc, char* argv[]) {
unit_test(cmd_roster_shows_roster_when_no_args), unit_test(cmd_roster_shows_roster_when_no_args),
unit_test(cmd_roster_add_shows_message_when_no_jid), unit_test(cmd_roster_add_shows_message_when_no_jid),
unit_test(cmd_roster_add_sends_roster_add_request), unit_test(cmd_roster_add_sends_roster_add_request),
unit_test(cmd_roster_remove_shows_message_when_no_jid),
unit_test(cmd_roster_remove_sends_roster_remove_request),
unit_test(cmd_roster_nick_shows_message_when_no_jid),
unit_test(cmd_roster_nick_shows_message_when_no_nick),
unit_test(cmd_roster_nick_shows_message_when_no_contact_exists),
unit_test(cmd_roster_nick_sends_name_change_request),
unit_test(cmd_roster_clearnick_shows_message_when_no_jid),
unit_test(cmd_roster_clearnick_shows_message_when_no_contact_exists),
unit_test(cmd_roster_clearnick_sends_name_change_request_with_empty_nick),
}; };
return run_tests(all_tests); return run_tests(all_tests);

View File

@ -350,7 +350,7 @@ expect_cons_show_contact_online(PContact contact, Resource *resource, GDateTime
expect_memory(_mock_cons_show_contact_online, contact, contact, sizeof(contact)); expect_memory(_mock_cons_show_contact_online, contact, contact, sizeof(contact));
expect_memory(_mock_cons_show_contact_online, resource, resource, sizeof(Resource)); expect_memory(_mock_cons_show_contact_online, resource, resource, sizeof(Resource));
if (last_activity == NULL) { if (last_activity == NULL) {
expect_any(_mock_cons_show_contact_online, last_activity); expect_value(_mock_cons_show_contact_online, last_activity, NULL);
} else { } else {
expect_memory(_mock_cons_show_contact_online, last_activity, last_activity, sizeof(last_activity)); expect_memory(_mock_cons_show_contact_online, last_activity, last_activity, sizeof(last_activity));
} }

View File

@ -103,6 +103,21 @@ _mock_roster_send_add_new(const char *const barejid, const char * const name)
check_expected(name); check_expected(name);
} }
static void
_mock_roster_send_remove(const char * const barejid)
{
check_expected(barejid);
}
static void
_mock_roster_send_name_change(const char * const barejid, const char * const new_name,
GSList *groups)
{
check_expected(barejid);
check_expected(new_name);
check_expected(groups);
}
void void
mock_jabber_connect_with_details(void) mock_jabber_connect_with_details(void)
{ {
@ -152,6 +167,18 @@ mock_roster_send_add_new(void)
roster_send_add_new = _mock_roster_send_add_new; roster_send_add_new = _mock_roster_send_add_new;
} }
void
mock_roster_send_remove(void)
{
roster_send_remove = _mock_roster_send_remove;
}
void
mock_roster_send_name_change(void)
{
roster_send_name_change = _mock_roster_send_name_change;
}
void void
bookmark_get_list_returns(GList *bookmarks) bookmark_get_list_returns(GList *bookmarks)
{ {
@ -187,7 +214,7 @@ jabber_connect_with_details_expect_and_return(char *jid,
expect_string(_mock_jabber_connect_with_details, jid, jid); expect_string(_mock_jabber_connect_with_details, jid, jid);
expect_string(_mock_jabber_connect_with_details, passwd, password); expect_string(_mock_jabber_connect_with_details, passwd, password);
if (altdomain == NULL) { if (altdomain == NULL) {
expect_any(_mock_jabber_connect_with_details, altdomain); expect_value(_mock_jabber_connect_with_details, altdomain, NULL);
} else { } else {
expect_string(_mock_jabber_connect_with_details, altdomain, altdomain); expect_string(_mock_jabber_connect_with_details, altdomain, altdomain);
} }
@ -237,7 +264,7 @@ expect_and_return_bookmark_add(char *expected_jid, char *expected_nick,
if (expected_nick != NULL) { if (expected_nick != NULL) {
expect_string(_mock_bookmark_add, nick, expected_nick); expect_string(_mock_bookmark_add, nick, expected_nick);
} else { } else {
expect_any(_mock_bookmark_add, nick); expect_value(_mock_bookmark_add, nick, NULL);
} }
expect_value(_mock_bookmark_add, autojoin, expected_autojoin); expect_value(_mock_bookmark_add, autojoin, expected_autojoin);
@ -268,7 +295,7 @@ presence_join_room_expect(char *room, char *nick, char *passwd)
expect_string(_mock_presence_join_room, room, room); expect_string(_mock_presence_join_room, room, room);
expect_string(_mock_presence_join_room, nick, nick); expect_string(_mock_presence_join_room, nick, nick);
if (passwd == NULL) { if (passwd == NULL) {
expect_any(_mock_presence_join_room, passwd); expect_value(_mock_presence_join_room, passwd, NULL);
} else { } else {
expect_string(_mock_presence_join_room, passwd, passwd); expect_string(_mock_presence_join_room, passwd, passwd);
} }
@ -280,3 +307,21 @@ roster_send_add_new_expect(char *jid, char *nick)
expect_string(_mock_roster_send_add_new, barejid, jid); expect_string(_mock_roster_send_add_new, barejid, jid);
expect_string(_mock_roster_send_add_new, name, nick); expect_string(_mock_roster_send_add_new, name, nick);
} }
void
roster_send_remove_expect(char *jid)
{
expect_string(_mock_roster_send_remove, barejid, jid);
}
void
roster_send_name_change_expect(char *jid, char *nick, GSList *groups)
{
expect_string(_mock_roster_send_name_change, barejid, jid);
if (nick == NULL) {
expect_value(_mock_roster_send_name_change, new_name, NULL);
} else {
expect_string(_mock_roster_send_name_change, new_name, nick);
}
expect_memory(_mock_roster_send_name_change, groups, groups, sizeof(GSList));
}

View File

@ -39,4 +39,10 @@ void presence_join_room_expect(char *room, char *nick, char *passwd);
void mock_roster_send_add_new(void); void mock_roster_send_add_new(void);
void roster_send_add_new_expect(char *jid, char *nick); void roster_send_add_new_expect(char *jid, char *nick);
void mock_roster_send_remove(void);
void roster_send_remove_expect(char *jid);
void mock_roster_send_name_change(void);
void roster_send_name_change_expect(char *jid, char *name, GSList *groups);
#endif #endif