summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuha Heinanen <jh@tutpro.com>2014-11-18 08:38:07 +0200
committerJuha Heinanen <jh@tutpro.com>2014-11-18 08:38:07 +0200
commit16308b599e9dd662b7be0d2da018a9dd063c8d99 (patch)
tree73783878504112da5e01bd8452f5bbfbe1a24b9a
parentda35d1b236ad2d0d4596c39980304c8a2b4f2c90 (diff)
presence: made presence status UA specific
-rw-r--r--include/baresip.h2
-rw-r--r--modules/presence/notifier.c4
-rw-r--r--modules/presence/presence.c40
-rw-r--r--modules/presence/presence.h2
-rw-r--r--modules/presence/publisher.c3
-rw-r--r--src/ua.c30
6 files changed, 53 insertions, 28 deletions
diff --git a/include/baresip.h b/include/baresip.h
index 17e3864..4685426 100644
--- a/include/baresip.h
+++ b/include/baresip.h
@@ -505,6 +505,8 @@ const char *ua_outbound(const struct ua *ua);
struct call *ua_call(const struct ua *ua);
struct account *ua_prm(const struct ua *ua);
struct list *ua_calls(const struct ua *ua);
+enum presence_status ua_presence_status(const struct ua *ua);
+void ua_presence_status_set(struct ua *ua, const enum presence_status status);
/* One instance */
diff --git a/modules/presence/notifier.c b/modules/presence/notifier.c
index f9b7c67..f099a11 100644
--- a/modules/presence/notifier.c
+++ b/modules/presence/notifier.c
@@ -177,7 +177,7 @@ static int notifier_add(struct sipevent_sock *sock, const struct sip_msg *msg,
if (err)
return err;
- (void)notify(not, my_status);
+ (void)notify(not, ua_presence_status(ua));
return 0;
}
@@ -191,7 +191,7 @@ void notifier_update_status(void)
struct notifier *not = le->data;
- (void)notify(not, my_status);
+ (void)notify(not, ua_presence_status(not->ua));
}
}
diff --git a/modules/presence/presence.c b/modules/presence/presence.c
index 92e982e..8f13bbc 100644
--- a/modules/presence/presence.c
+++ b/modules/presence/presence.c
@@ -7,23 +7,20 @@
#include <baresip.h>
#include "presence.h"
-enum presence_status my_status = PRESENCE_OPEN;
-
-static int cmd_online(struct re_printf *pf, void *arg)
+static int status_update(struct ua *current_ua,
+ const enum presence_status new_status)
{
- (void)pf;
- (void)arg;
-
- if (my_status == PRESENCE_OPEN)
+ if (ua_presence_status(current_ua) == new_status)
return 0;
- info("presence: update my status from '%s' to '%s'\n",
- contact_presence_str(my_status),
- contact_presence_str(PRESENCE_OPEN));
-
- my_status = PRESENCE_OPEN;
+ info("presence: update status of '%s' from '%s' to '%s'\n",
+ ua_aor(current_ua),
+ contact_presence_str(ua_presence_status(current_ua)),
+ contact_presence_str(new_status));
+ ua_presence_status_set(current_ua, new_status);
+
publisher_update_status();
notifier_update_status();
@@ -31,24 +28,21 @@ static int cmd_online(struct re_printf *pf, void *arg)
}
-static int cmd_offline(struct re_printf *pf, void *arg)
+static int cmd_online(struct re_printf *pf, void *arg)
{
(void)pf;
(void)arg;
- if (my_status == PRESENCE_CLOSED)
- return 0;
-
- info("presence: update my status from '%s' to '%s'\n",
- contact_presence_str(my_status),
- contact_presence_str(PRESENCE_CLOSED));
+ return status_update(uag_current(), PRESENCE_OPEN);
+}
- my_status = PRESENCE_CLOSED;
- publisher_update_status();
- notifier_update_status();
+static int cmd_offline(struct re_printf *pf, void *arg)
+{
+ (void)pf;
+ (void)arg;
- return 0;
+ return status_update(uag_current(), PRESENCE_CLOSED);
}
diff --git a/modules/presence/presence.h b/modules/presence/presence.h
index 430afde..38fa6a2 100644
--- a/modules/presence/presence.h
+++ b/modules/presence/presence.h
@@ -4,8 +4,6 @@
* Copyright (C) 2010 Creytiv.com
*/
-enum presence_status my_status;
-
int subscriber_init(void);
void subscriber_close(void);
diff --git a/modules/presence/publisher.c b/modules/presence/publisher.c
index 195b055..112d791 100644
--- a/modules/presence/publisher.c
+++ b/modules/presence/publisher.c
@@ -113,7 +113,8 @@ static int publish(struct publisher *pub)
" <contact>%s</contact>\r\n"
" </tuple>\r\n"
"</presence>\r\n"
- ,aor, presence_status_str(my_status), aor);
+ ,aor,
+ presence_status_str(ua_presence_status(pub->ua)), aor);
else
err = mbuf_printf(mb, "");
if (err)
diff --git a/src/ua.c b/src/ua.c
index d7592f0..ec472f3 100644
--- a/src/ua.c
+++ b/src/ua.c
@@ -33,6 +33,7 @@ struct ua {
char *cuser; /**< SIP Contact username */
char *pub_gruu; /**< SIP Public GRUU */
int af; /**< Preferred Address Family */
+ enum presence_status my_status; /**< Presence Status */
};
struct ua_eh {
@@ -828,6 +829,35 @@ const char *ua_aor(const struct ua *ua)
/**
+ * Get presence status of a User-Agent
+ *
+ * @param ua User-Agent object
+ *
+ * @return presence status
+ */
+enum presence_status ua_presence_status(const struct ua *ua)
+{
+ return ua ? ua->my_status : PRESENCE_UNKNOWN;
+}
+
+
+/**
+ * Set presence status of a User-Agent
+ *
+ * @param ua User-Agent object
+ *
+ * @param presence status
+ */
+void ua_presence_status_set(struct ua *ua, const enum presence_status status)
+{
+ if (!ua)
+ return;
+
+ ua->my_status = status;
+}
+
+
+/**
* Get the outbound SIP proxy of a User-Agent
*
* @param ua User-Agent object