summaryrefslogtreecommitdiff
path: root/profiles/alert
diff options
context:
space:
mode:
authorEder Ruiz Maria <eder.ruiz@openbossa.org>2012-10-03 08:49:15 -0400
committerJohan Hedberg <johan.hedberg@intel.com>2012-10-03 22:24:47 +0300
commit42515ee9c605b5577ee984ddb57c1bd8a4010701 (patch)
tree51ceaeafb9d0b233935282072a2327acccd88b23 /profiles/alert
parent985736634068cef480079b918d23231e8aa251b9 (diff)
downloadbluez-42515ee9c605b5577ee984ddb57c1bd8a4010701.tar.gz
alert: Implement category registration in RegisterAlert()
The given alert category is now validated and registered.
Diffstat (limited to 'profiles/alert')
-rw-r--r--profiles/alert/server.c102
1 files changed, 98 insertions, 4 deletions
diff --git a/profiles/alert/server.c b/profiles/alert/server.c
index c0434a41d..feb7b777c 100644
--- a/profiles/alert/server.c
+++ b/profiles/alert/server.c
@@ -77,19 +77,113 @@ enum {
RINGER_NORMAL,
};
+struct alert_data {
+ const char *category;
+ char *srv;
+ char *path;
+};
+
+static GSList *registered_alerts = NULL;
static uint8_t ringer_setting = RINGER_NORMAL;
static uint8_t alert_status = 0;
+static const char * const anp_categories[] = {
+ "simple",
+ "email",
+ "news",
+ "call",
+ "missed-call",
+ "sms-mms",
+ "voice-mail",
+ "schedule",
+ "high-priority",
+ "instant-message",
+};
+
+static const char * const pasp_categories[] = {
+ "ringer",
+ "vibrate",
+ "display",
+};
+
+static void alert_data_destroy(gpointer user_data)
+{
+ struct alert_data *alert = user_data;
+
+ g_free(alert->srv);
+ g_free(alert->path);
+ g_free(alert);
+}
+
+static void alert_destroy(gpointer user_data)
+{
+ g_slist_free_full(registered_alerts, alert_data_destroy);
+ registered_alerts = NULL;
+}
+
+static const char *valid_category(const char *category)
+{
+ unsigned i;
+
+ for (i = 0; i < G_N_ELEMENTS(anp_categories); i++) {
+ if (g_str_equal(anp_categories[i], category))
+ return anp_categories[i];
+ }
+
+ for (i = 0; i < G_N_ELEMENTS(pasp_categories); i++) {
+ if (g_str_equal(pasp_categories[i], category))
+ return pasp_categories[i];
+ }
+
+ return NULL;
+}
+
+static gboolean registered_category(const char *category)
+{
+ GSList *l;
+ struct alert_data *alert;
+
+ for (l = registered_alerts; l; l = g_slist_next(l)) {
+ alert = l->data;
+ if (g_str_equal(alert->category, category))
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
static DBusMessage *register_alert(DBusConnection *conn, DBusMessage *msg,
void *data)
{
+ const char *sender = dbus_message_get_sender(msg);
+ char *path;
const char *category;
+ const char *c;
+ struct alert_data *alert;
+
+ if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &c,
+ DBUS_TYPE_OBJECT_PATH, &path, DBUS_TYPE_INVALID))
+ return btd_error_invalid_args(msg);
- if (!dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &category,
- DBUS_TYPE_INVALID))
+ category = valid_category(c);
+ if (!category) {
+ DBG("Invalid category: %s", c);
return btd_error_invalid_args(msg);
+ }
+
+ if (registered_category(category)) {
+ DBG("Category %s already registered", category);
+ return dbus_message_new_method_return(msg);
+ }
+
+ alert = g_new0(struct alert_data, 1);
+ alert->srv = g_strdup(sender);
+ alert->path = g_strdup(path);
+ alert->category = category;
+
+ registered_alerts = g_slist_append(registered_alerts, alert);
- DBG("RegisterAlert: %s", category);
+ DBG("RegisterAlert(\"%s\", \"%s\")", alert->category, alert->path);
return dbus_message_new_method_return(msg);
}
@@ -290,7 +384,7 @@ int alert_server_init(void)
if (!g_dbus_register_interface(btd_get_dbus_connection(),
ALERT_OBJECT_PATH, ALERT_INTERFACE,
alert_methods, NULL, NULL, NULL,
- NULL)) {
+ alert_destroy)) {
error("D-Bus failed to register %s interface",
ALERT_INTERFACE);
return -EIO;