Commit 7627702b authored by Kyle Evans's avatar Kyle Evans
Browse files

Initial MMSD support



This patch sends the SMS Push data to MMSD via a 'Simple' interface,
which was created for this support, and listens for the MessgeAdded
signal on the 'Service' interface.

It does not include send support, and only rough metadata display.
Signed-off-by: Kyle Evans's avatarKyle Evans <kvans32@gmail.com>
parent a48071a9
......@@ -48,12 +48,18 @@
#define SMS_VALIDITY_NOT_SET 0
static pur_mm_data_t pur_mm_data;
static pur_mmsd_data_t pur_mmsd_data;
pur_mm_data_t *pur_mm_get_data (void)
{
return &pur_mm_data;
}
pur_mmsd_data_t *pur_mmsd_get_data (void)
{
return &pur_mmsd_data;
}
typedef struct {
MMObject *object;
MMModem *modem;
......@@ -66,6 +72,8 @@ typedef struct {
const gchar *number;
const gchar *message;
guint message_ref;
const guint8 *data;
gsize data_len;
time_t t_stamp;
const gchar *path;
gchar *sms_id;
......@@ -470,6 +478,40 @@ pur_mm_send_code_to_sim (const gchar *code)
}
}
static void
cb_pur_mmsd_push_notify (GObject *interface,
GAsyncResult *res,
gpointer sms_props)
{
pur_mm_data_t *mm_sms = pur_mm_get_data ();
pur_mmsd_data_t *mmsd = pur_mmsd_get_data ();
g_debug("%s",__func__);
g_dbus_proxy_call_finish (mmsd->simple_proxy,
res,
NULL);
if (mm_sms->sms_delete_received) {
pur_mm_delete_sms (sms_props);
}
}
static void
pur_mmsd_push_notify (PurSmsProps *sms_props)
{
pur_mmsd_data_t *mmsd = pur_mmsd_get_data ();
GVariant *args = mm_gdbus_sms_get_data(MM_GDBUS_SMS (sms_props->sms));
g_dbus_proxy_call(mmsd->simple_proxy,
"PushNotify",
g_variant_new ( "(@ay)", args),
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback)cb_pur_mmsd_push_notify,
sms_props);
}
static void
pur_mm_send_sms_to_purple_serv (PurSmsProps *sms_props)
......@@ -506,6 +548,7 @@ pur_mm_get_sms_properties (PurSmsProps *sms_props)
MMSms *sms;
const char *mm_time;
struct tm t_8601;
sms_props->data_len = 0;
sms = sms_props->sms;
......@@ -513,6 +556,7 @@ pur_mm_get_sms_properties (PurSmsProps *sms_props)
sms_props->path = mm_sms_get_path (sms);
sms_props->number = mm_sms_get_number (sms);
sms_props->message = mm_sms_get_text (sms);
sms_props->data = mm_sms_get_data(sms, &sms_props->data_len);
mm_time = mm_sms_get_timestamp (sms);
......@@ -663,6 +707,103 @@ pur_mm_delete_sms (PurSmsProps *sms_props)
}
}
static void
pur_mmsd_receive_message (GVariant *message_t)
{
GVariant *properties, *recipients, *attachments, *attach;
GVariantDict dict;
GVariantIter iter;
gchar *objectpath, *date, *subject, *sender, *smil;
gchar *containerpath, *filename, *mimetype;
guint data, size;
pur_mm_data_t *mm_sms = pur_mm_get_data ();
PurpleConnection *pc = purple_account_get_connection (mm_sms->account);
g_variant_get (message_t, "(o@a{?*})", &objectpath, &properties);
g_debug ("%s: New MMS at %s", __func__, objectpath);
g_debug ("%s", g_variant_print (properties, FALSE));
g_variant_dict_init (&dict, properties);
g_variant_dict_lookup (&dict, "Date", "s", &date);
g_variant_dict_lookup (&dict, "Subject", "s", &subject);
g_variant_dict_lookup (&dict, "Sender", "s", &sender);
g_variant_dict_lookup (&dict, "Smil", "s", &smil);
recipients = g_variant_dict_lookup_value (&dict, "Recipients", G_VARIANT_TYPE_STRING_ARRAY);
attachments = g_variant_dict_lookup_value (&dict, "Attachments", G_VARIANT_TYPE_ARRAY);
g_debug ("%s", g_variant_print (recipients, FALSE));
g_debug ("%s", g_variant_print (attachments, FALSE));
g_variant_iter_init (&iter, attachments);
serv_got_im (pc, sender, subject, PURPLE_MESSAGE_RECV,
time (NULL));
while ((attach = g_variant_iter_next_value (&iter))) {
g_variant_get (attach, "(ssstt)", &filename,
&mimetype,
&container,
&data,
&size);
serv_got_im (pc, sender, mimetype, PURPLE_MESSAGE_RECV |
PURPLE_MESSAGE_RAW, time (NULL));
}
}
static void
pur_mmsd_get_new_mms_cb (GDBusConnection *connection,
const gchar *sender_name,
const gchar *object_path,
const gchar *interface_name,
const gchar *signal_name,
GVariant *parameters,
gpointer user_data)
{
g_debug ("%s", __func__);
pur_mmsd_receive_message (parameters);
}
static void
pur_mmsd_get_all_mms_cb (GObject *service,
GAsyncResult *res,
gpointer user_data)
{
GVariant *ret, *msg_pack;
GVariantIter iter;
gsize num;
pur_mmsd_data_t *mmsd = (pur_mmsd_data_t *)user_data;
g_debug ("%s", __func__);
ret = g_dbus_proxy_call_finish (mmsd->service_proxy,
res,
NULL);
msg_pack = g_variant_get_child_value (ret, 0);
/*TODO: This list is all received MMS. If they are to be saved somewhere
* else then they will need to be removed from mmsd.*/
if ((num = g_variant_iter_init (&iter, msg_pack))) {
GVariant *message_t;
g_debug ("%lu MMS message(s)", num);
while ((message_t = g_variant_iter_next_value (&iter))) {
pur_mmsd_receive_message (message_t);
}
}
}
static char *
strip_phone_number (const char *number)
......@@ -991,6 +1132,140 @@ pur_mm_get_modem_manager (void)
NULL, NULL);
}
static void
pur_mmsd_get_service_cb (GObject *service,
GAsyncResult *res,
gpointer user_data)
{
gulong sig;
pur_mmsd_data_t *mmsd = (pur_mmsd_data_t *)user_data;
mmsd->service_proxy = g_dbus_proxy_new_finish (res, NULL);
g_debug ("got service");
sig = g_dbus_connection_signal_subscribe (mmsd->connection,
"org.ofono.mms",
"org.ofono.mms.Service",
"MessageAdded",
"/org/ofono/mms/any",
NULL,
G_DBUS_SIGNAL_FLAGS_NONE,
(GDBusSignalCallback)pur_mmsd_get_new_mms_cb,
NULL,
NULL);
if (sig) {
g_debug ("Listening for new messages");
} else {
g_warning("Failed to connect 'MessageAdded' signal");
}
g_dbus_proxy_call(mmsd->service_proxy,
"GetMessages",
NULL,
G_DBUS_CALL_FLAGS_NONE,
-1,
NULL,
(GAsyncReadyCallback)pur_mmsd_get_all_mms_cb,
mmsd);
}
static void
pur_mmsd_get_simple_cb (GObject *simple,
GAsyncResult *res,
gpointer user_data)
{
pur_mmsd_data_t *mmsd = (pur_mmsd_data_t *)user_data;
mmsd->simple_proxy = g_dbus_proxy_new_finish (res, NULL);
g_debug ("got mmsd Simple");
}
static void
pur_mmsd_get_manager_cb (GObject *manager,
GAsyncResult *res,
gpointer user_data)
{
pur_mmsd_data_t *mmsd = (pur_mmsd_data_t *)user_data;
mmsd->manager_proxy = g_dbus_proxy_new_finish (res, NULL);
g_debug ("got mmsd Manager");
}
static void
mmsd_appeared_cb (GDBusConnection *connection,
const gchar *name,
const gchar *name_owner,
gpointer user_data)
{
g_assert (G_IS_DBUS_CONNECTION (connection));
pur_mmsd_data_t *mmsd = (pur_mmsd_data_t *)user_data;
mmsd->connection = connection;
g_debug ("MMSD appeared");
g_dbus_proxy_new (mmsd->connection,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
NULL,
name,
"/org/ofono/mms",
"org.ofono.mms.Manager",
NULL,
pur_mmsd_get_manager_cb,
mmsd);
g_dbus_proxy_new (mmsd->connection,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
NULL,
name,
"/org/ofono/mms/any",
"org.ofono.mms.Service",
NULL,
pur_mmsd_get_service_cb,
mmsd);
g_dbus_proxy_new (mmsd->connection,
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
NULL,
name,
"/org/ofono/mms",
"org.ofono.mms.Simple",
NULL,
pur_mmsd_get_simple_cb,
mmsd);
}
static void
mmsd_vanished_cb (GDBusConnection *connection,
const gchar *name,
gpointer user_data)
{
g_assert (G_IS_DBUS_CONNECTION (connection));
g_debug ("MMSD vanished");
//TODO: free stuf
}
static void
pur_mmsd_get_service ()
{
pur_mmsd_data_t *mmsd = pur_mmsd_get_data ();
mmsd->mmsd_watch_id = g_bus_watch_name (G_BUS_TYPE_SESSION,
"org.ofono.mms",
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
(GBusNameAppearedCallback)mmsd_appeared_cb,
(GBusNameVanishedCallback)mmsd_vanished_cb,
mmsd, NULL);
}
static void
pur_mm_signal_emit (gchar *sms_id,
......@@ -1288,6 +1563,7 @@ pur_mm_login (PurpleAccount *account)
purple_connection_set_state (pc, PURPLE_CONNECTING);
pur_mm_get_modem_manager ();
pur_mmsd_get_service ();
}
......
......@@ -25,7 +25,18 @@ typedef struct {
guint mm_watch_id;
} pur_mm_data_t;
typedef struct {
GDBusConnection *connection;
GDBusProxy *manager_proxy;
GDBusProxy *service_proxy;
GDBusProxy *simple_proxy;
guint mmsd_watch_id;
} pur_mmsd_data_t;
pur_mm_data_t *pur_mm_get_data (void);
pur_mmsd_data_t *pur_mmsd_get_data (void);
enum {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment