static void message_handler(const struct pl *peer, const struct pl *ctype, struct mbuf *body, void *arg) { (void)ctype; (void)arg; char message[256] = {0}; char s_peer[50] = {0}; struct contacts *contacts = baresip_contacts(); (void)re_snprintf(message, sizeof(message), "%b", mbuf_buf(body), mbuf_get_left(body)); (void)re_snprintf(s_peer, sizeof(s_peer), "%r", peer); warning("message from %s: %s\n", s_peer, message); struct contact *c = contact_find(contacts, s_peer); if (c) { const struct sip_addr *addr = contact_addr(c); (void)re_snprintf(s_peer, sizeof(s_peer), "%r", &addr->dname); (void)webapp_chat_add(s_peer, message, false); ws_send_json(WS_CHAT, webapp_messages_get()); } }
static int module_close(void) { cmd_unregister(baresip_commands(), cmdv); list_flush(contact_list(baresip_contacts())); return 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; }
static void init_contacts_menu(struct gtk_mod *mod) { struct contacts *contacts = baresip_contacts(); struct le *le; GtkWidget *item; GtkMenuShell *contacts_menu = GTK_MENU_SHELL(mod->contacts_menu); /* Add contacts to submenu */ for (le = list_head(contact_list(contacts)); 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); } }
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; }
static int print_contacts(struct re_printf *pf, void *unused) { (void)unused; return contacts_print(pf, baresip_contacts()); }