static void init_contacts_menu(struct gtk_mod *mod) { struct le *le; GtkWidget *item; GtkMenuShell *contacts_menu = GTK_MENU_SHELL(mod->contacts_menu); /* Add contacts to submenu */ for (le = list_head(contact_list()); le; le = le->next) { struct contact *c = le->data; item = gtk_menu_item_new_with_label(contact_str(c)); gtk_menu_shell_append(contacts_menu, item); g_signal_connect(G_OBJECT(item), "activate", G_CALLBACK(menu_on_dial_contact), mod); } }
int test_contact(void) { struct contacts *contacts = NULL; struct contact *c; const char *addr = "Neil Young <sip:[email protected]>"; const char *uri = "sip:[email protected]"; struct pl pl_addr; int err; err = contact_init(&contacts); ASSERT_EQ(0, err); /* Verify that we have no contacts */ ASSERT_EQ(0, list_count(contact_list(contacts))); c = contact_find(contacts, "sip:[email protected]"); ASSERT_TRUE(c == NULL); /* Add one contact, list should have one entry and find should return the added contact */ pl_set_str(&pl_addr, addr); err = contact_add(contacts, &c, &pl_addr); ASSERT_EQ(0, err); ASSERT_TRUE(c != NULL); ASSERT_EQ(1, list_count(contact_list(contacts))); c = contact_find(contacts, uri); ASSERT_TRUE(c != NULL); ASSERT_STREQ(addr, contact_str(c)); ASSERT_STREQ(uri, contact_uri(c)); /* Delete 1 contact, verify that list is empty */ mem_deref(c); ASSERT_EQ(0, list_count(contact_list(contacts))); out: mem_deref(contacts); return err; }
static int cmd_contact(struct re_printf *pf, void *arg) { const struct cmd_arg *carg = arg; struct contacts *contacts = baresip_contacts(); struct contact *cnt = NULL; struct pl dname, user, pl; struct le *le; int err = 0; pl_set_str(&pl, carg->prm); dname.l = user.l = pl.l; err |= re_hprintf(pf, "\n"); for (le = list_head(contact_list(contacts)); le; le = le->next) { struct contact *c = le->data; dname.p = contact_addr(c)->dname.p; user.p = contact_addr(c)->uri.user.p; /* if displayname is set, try to match the displayname * otherwise we try to match the username only */ if (dname.p) { if (0 == pl_casecmp(&dname, &pl)) { err |= re_hprintf(pf, "%s\n", contact_str(c)); cnt = c; } } else if (user.p) { if (0 == pl_casecmp(&user, &pl)) { err |= re_hprintf(pf, "%s\n", contact_str(c)); cnt = c; } } } if (!cnt) err |= re_hprintf(pf, "(no matches)\n"); if (carg->complete && cnt) { switch (carg->key) { case '|': err = ua_connect(uag_current(), NULL, NULL, contact_str(cnt), NULL, VIDMODE_ON); if (err) { warning("contact: ua_connect failed: %m\n", err); } break; case '=': chat_peer = contact_str(cnt); (void)re_hprintf(pf, "Selected chat peer: %s\n", chat_peer); re_snprintf(cmd_desc, sizeof(cmd_desc), "Send MESSAGE to %s", chat_peer); break; default: break; } } return err; }