Пример #1
0
static GtkMenuItem *accounts_menu_add_item(struct gtk_mod *mod,
		struct ua *ua)
{
	GtkMenuShell *accounts_menu = GTK_MENU_SHELL(mod->accounts_menu);
	GtkWidget *item;
	GSList *group = mod->accounts_menu_group;
	struct ua *ua_current = uag_current();
	char buf[256];

	re_snprintf(buf, sizeof buf, "%s%s", ua_aor(ua),
			ua_isregistered(ua) ? " (OK)" : "");
	item = gtk_radio_menu_item_new_with_label(group, buf);
	group = gtk_radio_menu_item_get_group(
			GTK_RADIO_MENU_ITEM (item));
	if (ua == ua_current)
		gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item),
				TRUE);
	g_object_set_data(G_OBJECT(item), "ua", ua);
	g_signal_connect(item, "toggled",
			G_CALLBACK(menu_on_account_toggled), mod);
	gtk_menu_shell_append(accounts_menu, item);
	mod->accounts_menu_group = group;

	return GTK_MENU_ITEM(item);
}
Пример #2
0
static void startup(void *arg)
{
	struct call *call = NULL;
	ua_connect(uag_current(), &call, NULL,
			"stream", NULL, VIDMODE_ON);
	system(command);
}
Пример #3
0
static int cmd_ua_debug(struct re_printf *pf, void *unused)
{
	const struct ua *ua = uag_current();
	(void)unused;

	if (ua)
		return ua_debug(pf, ua);
	else
		return re_hprintf(pf, "(no user-agent)\n");
}
Пример #4
0
static int cmd_message(struct re_printf *pf, void *arg)
{
	const struct cmd_arg *carg = arg;
	int err;

	(void)pf;

	err = message_send(uag_current(), chat_peer, carg->prm);
	if (err) {
		(void)re_hprintf(pf, "chat: ua_im_send() failed (%m)\n", err);
	}

	return err;
}
Пример #5
0
static struct call *get_call_from_gvariant(GVariant *param)
{
	gint64 call_ptr;
	struct call *call;
	struct list *calls = ua_calls(uag_current());
	struct le *le;

	call_ptr = g_variant_get_int64(param);
	call = GINT_TO_POINTER(call_ptr);

	for (le = list_head(calls); le; le = le->next)
		if (le->data == call)
			return call;

	return NULL;
}
Пример #6
0
static int cmd_message(struct re_printf *pf, void *arg)
{
    const struct cmd_arg *carg = arg;
    int err;

    if (!str_isset(chat_peer)) {
        return re_hprintf(pf, "contact: chat peer is not set\n");
    }

    err = message_send(uag_current(), chat_peer, carg->prm);
    if (err) {
        (void)re_hprintf(pf, "contact: message_send() failed (%m)\n",
                         err);
    }

    return err;
}
Пример #7
0
static void update_ua_presence(struct gtk_mod *mod)
{
	GtkCheckMenuItem *item = 0;
	enum presence_status cur_status;
	void *status;
	GtkMenuShell *status_menu = GTK_MENU_SHELL(mod->status_menu);
	GList *items = status_menu->children;

	cur_status = ua_presence_status(uag_current());

	for (; items; items = items->next) {
		item = items->data;
		status = g_object_get_data(G_OBJECT(item), "presence");
		if (cur_status == GPOINTER_TO_UINT(status))
			break;
	}
	if (!item)
		return;

	gtk_check_menu_item_set_active(item, TRUE);
}
Пример #8
0
static void mqueue_handler(int id, void *data, void *arg)
{
	struct gtk_mod *mod = arg;
	const char *uri;
	struct call *call;
	int err;
	struct ua *ua = uag_current();
	(void)mod;

	switch ((enum gtk_mod_events)id) {

	case MQ_POPUP:
		gdk_threads_enter();
		popup_menu(mod, NULL, NULL, 0, GPOINTER_TO_UINT(data));
		gdk_threads_leave();
		break;

	case MQ_CONNECT:
		uri = data;
		err = ua_connect(ua, &call, NULL, uri, NULL, VIDMODE_ON);
		if (err) {
			gdk_threads_enter();
			warning_dialog("Call failed",
					"Connecting to \"%s\" failed.\n"
					"Error: %m", uri, err);
			gdk_threads_leave();
			break;
		}
		gdk_threads_enter();
		err = new_call_window(mod, call) == NULL;
		gdk_threads_leave();
		if (err) {
			ua_hangup(ua, call, 500, "Server Error");
		}
		break;

	case MQ_HANGUP:
		call = data;
		ua_hangup(ua, call, 0, NULL);
		break;

	case MQ_QUIT:
		ua_stop_all(false);
		break;

	case MQ_ANSWER:
		call = data;
		err = ua_answer(ua, call);
		if (err) {
			gdk_threads_enter();
			warning_dialog("Call failed",
					"Answering the call "
					"from \"%s\" failed.\n"
					"Error: %m",
					call_peername(call), err);
			gdk_threads_leave();
			break;
		}

		gdk_threads_enter();
		err = new_call_window(mod, call) == NULL;
		gdk_threads_leave();
		if (err) {
			ua_hangup(ua, call, 500, "Server Error");
		}
		break;

	case MQ_SELECT_UA:
		ua = data;
		uag_current_set(ua);
		break;
	}
}
Пример #9
0
static void update_current_accounts_menu_item(struct gtk_mod *mod)
{
	GtkMenuItem *item = accounts_menu_get_item(mod,
			uag_current());
	gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(item), TRUE);
}
Пример #10
0
/**
 * Allocate a SIP User-Agent
 *
 * @param uap   Pointer to allocated User-Agent object
 * @param aor   SIP Address-of-Record (AOR)
 *
 * @return 0 if success, otherwise errorcode
 */
int ua_alloc(struct ua **uap, const char *aor)
{
	struct ua *ua;
	int err;

	if (!aor)
		return EINVAL;

	ua = mem_zalloc(sizeof(*ua), ua_destructor);
	if (!ua)
		return ENOMEM;

	MAGIC_INIT(ua);

	list_init(&ua->calls);

#if HAVE_INET6
	ua->af   = uag.prefer_ipv6 ? AF_INET6 : AF_INET;
#else
	ua->af   = AF_INET;
#endif

	/* Decode SIP address */

	err = account_alloc(&ua->acc, aor);
	if (err)
		goto out;

	/* generate a unique contact-user, this is needed to route
	   incoming requests when using multiple useragents */
	err = re_sdprintf(&ua->cuser, "%r-%p", &ua->acc->luri.user, ua);
	if (err)
		goto out;

	if (ua->acc->sipnat) {
		ua_printf(ua, "Using sipnat: `%s'\n", ua->acc->sipnat);
	}

	if (ua->acc->mnat) {
		ua_printf(ua, "Using medianat `%s'\n",
			  ua->acc->mnat->id);

		if (0 == str_casecmp(ua->acc->mnat->id, "ice"))
			add_extension(ua, "ice");
	}

	if (ua->acc->menc) {
		ua_printf(ua, "Using media encryption `%s'\n",
			  ua->acc->menc->id);
	}

	/* Register clients */
	if (str_isset(uag.cfg->uuid))
	        add_extension(ua, "gruu");

	if (0 == str_casecmp(ua->acc->sipnat, "outbound")) {

		size_t i;

		add_extension(ua, "path");
		add_extension(ua, "outbound");

		if (!str_isset(uag.cfg->uuid)) {

			warning("ua: outbound requires valid UUID!\n");
			err = ENOSYS;
			goto out;
		}

		for (i=0; i<ARRAY_SIZE(ua->acc->outbound); i++) {

			if (ua->acc->outbound[i] && ua->acc->regint) {
				err = reg_add(&ua->regl, ua, (int)i+1);
				if (err)
					break;
			}
		}
	}
	else if (ua->acc->regint) {
		err = reg_add(&ua->regl, ua, 0);
	}
	if (err)
		goto out;

	list_append(&uag.ual, &ua->le, ua);

	if (ua->acc->regint) {
		err = ua_register(ua);
	}

	if (!uag_current())
		uag_current_set(ua);

 out:
	if (err)
		mem_deref(ua);
	else if (uap) {
		*uap = ua;

		ua->uap = uap;
	}

	return err;
}
Пример #11
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;
}