Beispiel #1
0
static bool set_notification_registration(struct map_data *map, bool status)
{
	struct obc_transfer *transfer;
	GError *err = NULL;
	GObexApparam *apparam;
	char contents[2];

	contents[0] = FILLER_BYTE;
	contents[1] = '\0';

	transfer = obc_transfer_put("x-bt/MAP-NotificationRegistration", NULL,
					NULL, contents, sizeof(contents), &err);

	if (transfer == NULL)
		return false;

	apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_NOTIFICATIONSTATUS,
									status);

	obc_transfer_set_apparam(transfer, apparam);

	if (obc_session_queue(map->session, transfer, NULL, map, &err))
		return true;

	return false;
}
Beispiel #2
0
static GObexApparam *parse_filter_type(GObexApparam *apparam,
							DBusMessageIter *iter)
{
	DBusMessageIter array;
	guint8 types = 0;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_ARRAY)
		return NULL;

	dbus_message_iter_recurse(iter, &array);

	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_STRING) {
		const char *string;

		dbus_message_iter_get_basic(&array, &string);

		if (!g_ascii_strcasecmp(string, "sms"))
			types |= 0x03; /* sms-gsm and sms-cdma */
		else if (!g_ascii_strcasecmp(string, "email"))
			types |= 0x04; /* email */
		else if (!g_ascii_strcasecmp(string, "mms"))
			types |= 0x08; /* mms */
		else
			return NULL;

		dbus_message_iter_next(&array);
	}

	return g_obex_apparam_set_uint8(apparam, MAP_AP_FILTERMESSAGETYPE,
									types);
}
static void test_apparam_set_multi(void)
{
	GObexApparam *apparam;
	guint8 buf[1024];
	gsize len;

	apparam = g_obex_apparam_set_uint8(NULL, TAG_U8, 0x01);

	g_assert(apparam != NULL);

	apparam = g_obex_apparam_set_uint16(apparam, TAG_U16, 0x0102);

	g_assert(apparam != NULL);

	apparam = g_obex_apparam_set_uint32(apparam, TAG_U32, 0x01020304);

	g_assert(apparam != NULL);

	apparam = g_obex_apparam_set_uint64(apparam, TAG_U64,
							0x0102030405060708);

	g_assert(apparam != NULL);

	apparam = g_obex_apparam_set_string(apparam, TAG_STRING, "ABC");

	g_assert(apparam != NULL);

	len = g_obex_apparam_encode(apparam, buf, sizeof(buf));

	g_assert_cmpuint(len, ==, sizeof(tag_multi));

	g_obex_apparam_free(apparam);
}
Beispiel #4
0
static void set_status(const GDBusPropertyTable *property,
			DBusMessageIter *iter, GDBusPendingPropertySet id,
			uint8_t status, void *data)
{
	struct map_msg *msg = data;
	struct obc_transfer *transfer;
	gboolean value;
	GError *err = NULL;
	GObexApparam *apparam;
	char contents[2];

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN) {
		g_dbus_pending_property_error(id,
					ERROR_INTERFACE ".InvalidArguments",
					"Invalid arguments in method call");
		return;
	}

	dbus_message_iter_get_basic(iter, &value);

	contents[0] = FILLER_BYTE;
	contents[1] = '\0';

	transfer = obc_transfer_put("x-bt/messageStatus", msg->handle, NULL,
					contents, sizeof(contents), &err);
	if (transfer == NULL)
		goto fail;

	apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_STATUSINDICATOR,
								status);
	apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_STATUSVALUE,
								value);
	obc_transfer_set_apparam(transfer, apparam);

	if (!obc_session_queue(msg->data->session, transfer,
				set_message_status_cb, msg, &err))
		goto fail;

	msg->pending = id;
	return;

fail:
	g_dbus_pending_property_error(id, ERROR_INTERFACE ".Failed", "%s",
								err->message);
	g_error_free(err);
}
Beispiel #5
0
static DBusMessage *map_msg_get(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct map_msg *msg = user_data;
	struct obc_transfer *transfer;
	const char *target_file;
	gboolean attachment;
	GError *err = NULL;
	DBusMessage *reply;
	GObexApparam *apparam;

	if (dbus_message_get_args(message, NULL,
				DBUS_TYPE_STRING, &target_file,
				DBUS_TYPE_BOOLEAN, &attachment,
				DBUS_TYPE_INVALID) == FALSE)
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".InvalidArguments", NULL);

	transfer = obc_transfer_get("x-bt/message", msg->handle, target_file,
									&err);
	if (transfer == NULL)
		goto fail;

	apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_ATTACHMENT,
								attachment);
	apparam = g_obex_apparam_set_uint8(apparam, MAP_AP_CHARSET,
								CHARSET_UTF8);

	obc_transfer_set_apparam(transfer, apparam);

	if (!obc_session_queue(msg->data->session, transfer, NULL, NULL, &err))
		goto fail;

	return obc_transfer_create_dbus_reply(transfer, message);

fail:
	reply = g_dbus_create_error(message, ERROR_INTERFACE ".Failed", "%s",
								err->message);
	g_error_free(err);
	return reply;
}
Beispiel #6
0
static GObexApparam *parse_retry(GObexApparam *apparam, DBusMessageIter *iter)
{
	dbus_bool_t retry;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN)
		return NULL;

	dbus_message_iter_get_basic(iter, &retry);

	return g_obex_apparam_set_uint8(apparam, MAP_AP_RETRY,
							retry ? TRUE : FALSE);
}
Beispiel #7
0
static GObexApparam *parse_subject_length(GObexApparam *apparam,
							DBusMessageIter *iter)
{
	guint8 num;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BYTE)
		return NULL;

	dbus_message_iter_get_basic(iter, &num);

	return g_obex_apparam_set_uint8(apparam, MAP_AP_SUBJECTLENGTH, num);
}
Beispiel #8
0
static GObexApparam *parse_transparent(GObexApparam *apparam,
							DBusMessageIter *iter)
{
	dbus_bool_t transparent;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN)
		return NULL;

	dbus_message_iter_get_basic(iter, &transparent);

	return g_obex_apparam_set_uint8(apparam, MAP_AP_TRANSPARENT,
						transparent ? TRUE : FALSE);
}
static void test_apparam_set_uint8(void)
{
	GObexApparam *apparam;
	guint8 buf[1024];
	gsize len;

	apparam = g_obex_apparam_set_uint8(NULL, TAG_U8, 0x01);
	g_assert(apparam != NULL);

	len = g_obex_apparam_encode(apparam, buf, sizeof(buf));
	assert_memequal(tag_uint8, sizeof(tag_uint8), buf, len);

	g_obex_apparam_free(apparam);
}
Beispiel #10
0
static GObexApparam *parse_charset(GObexApparam *apparam, DBusMessageIter *iter)
{
	guint8 charset = 0;
	const char *string;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_STRING)
		return NULL;

	dbus_message_iter_get_basic(iter, &string);

	if (strcasecmp(string, "native") == 0)
		charset = CHARSET_NATIVE;
	else if (strcasecmp(string, "utf8") == 0)
		charset = CHARSET_UTF8;
	else
		return NULL;

	return g_obex_apparam_set_uint8(apparam, MAP_AP_CHARSET, charset);
}
Beispiel #11
0
static GObexApparam *parse_filter_priority(GObexApparam *apparam,
							DBusMessageIter *iter)
{
	guint8 priority = FILTER_PRIORITY_NONE;
	dbus_bool_t dbus_priority = FALSE;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN)
		return NULL;

	dbus_message_iter_get_basic(iter, &dbus_priority);

	if (dbus_priority)
		priority = FILTER_PRIORITY_ONLY_HIGH;
	else
		priority = FILTER_PRIORITY_ONLY_NONHIGH;

	return g_obex_apparam_set_uint8(apparam, MAP_AP_FILTERPRIORITY,
								priority);
}
Beispiel #12
0
static GObexApparam *parse_filter_read(GObexApparam *apparam,
							DBusMessageIter *iter)
{
	guint8 status = FILTER_READ_STATUS_NONE;
	dbus_bool_t dbus_status = FALSE;

	if (dbus_message_iter_get_arg_type(iter) != DBUS_TYPE_BOOLEAN)
		return NULL;

	dbus_message_iter_get_basic(iter, &dbus_status);

	if (dbus_status)
		status = FILTER_READ_STATUS_ONLY_READ;
	else
		status = FILTER_READ_STATUS_ONLY_UNREAD;

	return g_obex_apparam_set_uint8(apparam, MAP_AP_FILTERREADSTATUS,
								status);
}
Beispiel #13
0
static DBusMessage *map_push_message(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct map_data *map = user_data;
	char *filename;
	char *folder;
	GObexApparam *apparam;
	DBusMessageIter args;

	dbus_message_iter_init(message, &args);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING)
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".InvalidArguments", NULL);

	dbus_message_iter_get_basic(&args, &filename);

	dbus_message_iter_next(&args);

	if (dbus_message_iter_get_arg_type(&args) != DBUS_TYPE_STRING) {
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".InvalidArguments", NULL);
	}

	dbus_message_iter_get_basic(&args, &folder);

	dbus_message_iter_next(&args);

	apparam = g_obex_apparam_set_uint8(NULL, MAP_AP_CHARSET, CHARSET_UTF8);

	if (parse_push_options(apparam, &args) == NULL) {
		g_obex_apparam_free(apparam);
		return g_dbus_create_error(message,
				ERROR_INTERFACE ".InvalidArguments", NULL);
	}

	return push_message(map, message, filename, folder, apparam);
}
Beispiel #14
0
static void get_messages_listing_cb(void *session, int err, uint16_t size,
					gboolean newmsg,
					const struct messages_message *entry,
					void *user_data)
{
	struct mas_session *mas = user_data;
	uint16_t max = 1024;
	gchar *mse_time;

	if (err < 0 && err != -EAGAIN) {
		obex_object_set_io_flags(mas, G_IO_ERR, err);
		return;
	}

	if (mas->inparams)
		g_obex_apparam_get_uint16(mas->inparams, MAP_AP_MAXLISTCOUNT,
									&max);

	if (max == 0) {
		if (!entry)
			mas->finished = TRUE;

		goto proceed;
	}

	if (!mas->nth_call) {
		g_string_append(mas->buffer, ML_BODY_BEGIN);
		mas->nth_call = TRUE;
	}

	if (!entry) {
		g_string_append(mas->buffer, ML_BODY_END);
		mas->finished = TRUE;

		goto proceed;
	}

	g_string_append(mas->buffer, "<msg");

	g_string_append_escaped_printf(mas->buffer, " handle=\"%s\"",
								entry->handle);

	if (entry->mask & PMASK_SUBJECT)
		g_string_append_escaped_printf(mas->buffer, " subject=\"%s\"",
				entry->subject);

	if (entry->mask & PMASK_DATETIME)
		g_string_append_escaped_printf(mas->buffer, " datetime=\"%s\"",
				entry->datetime);

	if (entry->mask & PMASK_SENDER_NAME)
		g_string_append_escaped_printf(mas->buffer,
						" sender_name=\"%s\"",
						entry->sender_name);

	if (entry->mask & PMASK_SENDER_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" sender_addressing=\"%s\"",
						entry->sender_addressing);

	if (entry->mask & PMASK_REPLYTO_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" replyto_addressing=\"%s\"",
						entry->replyto_addressing);

	if (entry->mask & PMASK_RECIPIENT_NAME)
		g_string_append_escaped_printf(mas->buffer,
						" recipient_name=\"%s\"",
						entry->recipient_name);

	if (entry->mask & PMASK_RECIPIENT_ADDRESSING)
		g_string_append_escaped_printf(mas->buffer,
						" recipient_addressing=\"%s\"",
						entry->recipient_addressing);

	if (entry->mask & PMASK_TYPE)
		g_string_append_escaped_printf(mas->buffer, " type=\"%s\"",
				entry->type);

	if (entry->mask & PMASK_RECEPTION_STATUS)
		g_string_append_escaped_printf(mas->buffer,
						" reception_status=\"%s\"",
						entry->reception_status);

	if (entry->mask & PMASK_SIZE)
		g_string_append_escaped_printf(mas->buffer, " size=\"%s\"",
				entry->size);

	if (entry->mask & PMASK_ATTACHMENT_SIZE)
		g_string_append_escaped_printf(mas->buffer,
						" attachment_size=\"%s\"",
						entry->attachment_size);

	if (entry->mask & PMASK_TEXT)
		g_string_append_escaped_printf(mas->buffer, " text=\"%s\"",
				yesorno(entry->text));

	if (entry->mask & PMASK_READ)
		g_string_append_escaped_printf(mas->buffer, " read=\"%s\"",
				yesorno(entry->read));

	if (entry->mask & PMASK_SENT)
		g_string_append_escaped_printf(mas->buffer, " sent=\"%s\"",
				yesorno(entry->sent));

	if (entry->mask & PMASK_PROTECTED)
		g_string_append_escaped_printf(mas->buffer, " protected=\"%s\"",
				yesorno(entry->protect));

	if (entry->mask & PMASK_PRIORITY)
		g_string_append_escaped_printf(mas->buffer, " priority=\"%s\"",
				yesorno(entry->priority));

	g_string_append(mas->buffer, "/>\n");

proceed:
	if (!entry) {
		mas->outparams = g_obex_apparam_set_uint16(mas->outparams,
						MAP_AP_MESSAGESLISTINGSIZE,
						size);
		mas->outparams = g_obex_apparam_set_uint8(mas->outparams,
						MAP_AP_NEWMESSAGE,
						newmsg ? 1 : 0);
		/* Response to report the local time of MSE */
		mse_time = get_mse_timestamp();
		if (mse_time) {
			g_obex_apparam_set_string(mas->outparams,
						MAP_AP_MSETIME, mse_time);
			g_free(mse_time);
		}
	}

	if (err != -EAGAIN)
		obex_object_set_io_flags(mas, G_IO_IN, 0);
}