示例#1
0
static int module_close(void)
{
    cmd_unregister(baresip_commands(), cmdv);
    list_flush(contact_list(baresip_contacts()));

    return 0;
}
示例#2
0
文件: contact.c 项目: GGGO/baresip
int contacts_print(struct re_printf *pf, const struct contacts *contacts)
{
	const struct list *lst;
	struct le *le;
	int err;

	if (!contacts)
		return 0;

	lst = contact_list(contacts);

	err = re_hprintf(pf, "\n--- Contacts: (%u) ---\n",
			 list_count(lst));

	for (le = list_head(lst); le && !err; le = le->next) {
		const struct contact *c = le->data;
		const struct sip_addr *addr = &c->addr;

		err = re_hprintf(pf, "%20s  %r <%r>\n",
				 contact_presence_str(c->status),
				 &addr->dname, &addr->auri);
	}

	err |= re_hprintf(pf, "\n");

	return err;
}
示例#3
0
static int module_init(void)
{
    struct contacts *contacts = baresip_contacts();
    char path[256] = "", file[256] = "";
    int err;

    err = conf_path_get(path, sizeof(path));
    if (err)
        return err;

    if (re_snprintf(file, sizeof(file), "%s/contacts", path) < 0)
        return ENOMEM;

    if (!conf_fileexist(file)) {

        (void)fs_mkdir(path, 0700);

        err = write_template(file);
        if (err)
            return err;
    }

    err = conf_parse(file, confline_handler, contacts);
    if (err)
        return err;

    err = cmd_register(baresip_commands(), cmdv, ARRAY_SIZE(cmdv));
    if (err)
        return err;

    info("Populated %u contacts\n",
         list_count(contact_list(contacts)));

    return err;
}
示例#4
0
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;
}
示例#5
0
文件: contact.c 项目: QXIP/baresip
int contacts_print(struct re_printf *pf, void *unused)
{
	struct le *le;
	int err;

	(void)unused;

	err = re_hprintf(pf, "\n--- Contacts: (%u) ---\n",
			 list_count(contact_list()));

	for (le = list_head(contact_list()); le && !err; le = le->next) {
		const struct contact *c = le->data;
		const struct sip_addr *addr = &c->addr;

		err = re_hprintf(pf, "%20s  %r <%r>\n",
				 contact_presence_str(c->status),
				 &addr->dname, &addr->auri);
	}

	err |= re_hprintf(pf, "\n");

	return err;
}
示例#6
0
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);
	}
}
示例#7
0
文件: subscriber.c 项目: QXIP/baresip
int subscriber_init(void)
{
	struct le *le;
	int err = 0;

	for (le = list_head(contact_list()); le; le = le->next) {

		struct contact *c = le->data;
		struct sip_addr *addr = contact_addr(c);
		struct pl val;

		if (0 == msg_param_decode(&addr->params, "presence", &val) &&
		    0 == pl_strcasecmp(&val, "p2p")) {

			err |= presence_alloc(le->data);
		}
	}

	info("Subscribing to %u contacts\n", list_count(&presencel));

	return err;
}
示例#8
0
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;
}