Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webapp: add auto contact connect #246

Draft
wants to merge 1 commit into
base: v21.xx.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/modules/webapp/contact.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static int contact_register(const struct odict_entry *o)
le = (void *)&o->le;
}

for (le=le; le; le=le->next) {
for (; le; le=le->next) {
const struct odict_entry *e = le->data;

if (e->type != ODICT_STRING) {
Expand Down Expand Up @@ -66,6 +66,9 @@ static int contact_register(const struct odict_entry *o)

void webapp_contact_add(const struct odict_entry *contact)
{
if (!contact)
return;

contact_register(contact);
webapp_odict_add(contacts, contact);
webapp_write_file_json(contacts, filename);
Expand All @@ -75,6 +78,10 @@ void webapp_contact_add(const struct odict_entry *contact)
void webapp_contact_delete(const char *sip)
{
struct le *le;

if (!sip)
return;

for (le = contacts->lst.head; le; le = le->next) {
char o_sip[100];
const struct odict_entry *o = le->data;
Expand All @@ -98,6 +105,32 @@ void webapp_contact_delete(const char *sip)
}


bool webapp_contact_exists(const char *sip)
{
struct le *le;

if (!sip)
return false;

for (le = contacts->lst.head; le; le = le->next) {
char o_sip[100];
const struct odict_entry *o = le->data;
const struct odict_entry *e;

e = odict_lookup(o->u.odict, "sip");
if (!e)
continue;
re_snprintf(o_sip, sizeof(o_sip), "sip:%s", e->u.str);
warning("cmp %s == %s\n", o_sip, sip);
if (!str_cmp(o_sip, sip)) {
return true;
}
}

return false;
}


int webapp_contacts_init(void)
{
char path[256] = "";
Expand Down
10 changes: 5 additions & 5 deletions src/modules/webapp/webapp.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ static void ua_event_handler(struct ua *ua, enum ua_event ev,
if (!key)
return;

if (!auto_answer) {
if (webapp_contact_exists(call_peeruri(call))) {
debug("auto answering call\n");
ua_answer(call_get_ua(call), call, VIDMODE_OFF);
}
else {
re_snprintf(webapp_call_json, sizeof(webapp_call_json),
"{ \"callback\": \"INCOMING\",\
\"peeruri\": \"%s\",\
\"key\": \"%d\" }",
call_peeruri(call), key);
}
else {
debug("auto answering call\n");
ua_answer(call_get_ua(call), call, VIDMODE_OFF);
}
ws_send_all(WS_CALLS, webapp_call_json);
break;

Expand Down
1 change: 1 addition & 0 deletions src/modules/webapp/webapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ int webapp_contacts_init(void);
void webapp_contacts_close(void);
void webapp_contact_add(const struct odict_entry *contact);
void webapp_contact_delete(const char *sip);
bool webapp_contact_exists(const char *sip);
const struct odict* webapp_contacts_get(void);

/*
Expand Down