Skip to content

Commit

Permalink
[plugins] Support for SmartPoster handlers. JB#45439
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Sep 3, 2019
1 parent 162a0aa commit 0cb4598
Show file tree
Hide file tree
Showing 9 changed files with 433 additions and 5 deletions.
1 change: 1 addition & 0 deletions plugins/Makefile
Expand Up @@ -199,6 +199,7 @@ DBUS_HANDLERS_SRC = \
dbus_handlers_tag.c \
dbus_handlers_type_generic.c \
dbus_handlers_type_mediatype.c \
dbus_handlers_type_sp.c \
dbus_handlers_type_text.c \
dbus_handlers_type_uri.c \
dbus_handlers.c
Expand Down
55 changes: 54 additions & 1 deletion plugins/dbus_handlers/README
Expand Up @@ -132,7 +132,7 @@ Method signature:
</method>

Both [URI-Handler] and [URI-Listener] sections support additional
key that specifies URI pattern to match:
optional key that specifies URI pattern to match:

URI = <pattern>

Expand Down Expand Up @@ -175,3 +175,56 @@ Example:
[Text-Handler]
Service = my.service
Method = my.interface.HandleText

"Sp" (SmartPoster) NDEF record
------------------------------

[SmartPoster-Handler]

Method signature:

<method>
<arg name="uri" type="s" direction="in"/>
<arg name="title" type="s" direction="in"/>
<arg name="type" type="s" direction="in"/>
<arg name="size" type="u" direction="in"/>
<arg name="action" type="i" direction="in"/>
<arg name="icon" type="(say)" direction="in"/>
<arg name="status" type="i" direction="out"/>
</method>

[SmartPoster-Listener]

Method signature:

<method>
<arg name="handled" type="b" direction="in"/>
<arg name="uri" type="s" direction="in"/>
<arg name="title" type="s" direction="in"/>
<arg name="type" type="s" direction="in"/>
<arg name="size" type="u" direction="in"/>
<arg name="action" type="i" direction="in"/>
<arg name="icon" type="(say)" direction="in"/>
</method>

Action parameter has one of the following values:

-1 No action record provided
0 Perform the action
1 Save for later
2 Open for editing


Both [SmartPoster-Handler] and [SmartPoster-Listener] sections support
additional optional key that specifies URI pattern to match:

URI = <pattern>

The default pattern is '*' which matches everything.

Example:

[SmartPoster-Handler]
Service = my.service
Method = my.interface.HandleSmartPoster
URI = https://*
6 changes: 4 additions & 2 deletions plugins/dbus_handlers/dbus_handlers.h
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2018-2019 Jolla Ltd.
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -14,8 +15,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand Down Expand Up @@ -95,6 +96,7 @@ typedef struct dbus_handlers_config {
DBusListenerConfig* listeners;
} DBusHandlersConfig;

extern const DBusHandlerType dbus_handlers_type_sp;
extern const DBusHandlerType dbus_handlers_type_uri;
extern const DBusHandlerType dbus_handlers_type_text;
extern const DBusHandlerType dbus_handlers_type_mediatype_wildcard;
Expand Down
6 changes: 4 additions & 2 deletions plugins/dbus_handlers/dbus_handlers_config.c
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2018-2019 Jolla Ltd.
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
Expand All @@ -14,8 +15,8 @@
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Expand Down Expand Up @@ -419,6 +420,7 @@ dbus_handlers_config_load(
* handled first.
*/
static const DBusHandlerType* available_types[] = {
&dbus_handlers_type_sp,
&dbus_handlers_type_uri,
&dbus_handlers_type_text,
&dbus_handlers_type_mediatype_exact
Expand Down
152 changes: 152 additions & 0 deletions plugins/dbus_handlers/dbus_handlers_type_sp.c
@@ -0,0 +1,152 @@
/*
* Copyright (C) 2019 Jolla Ltd.
* Copyright (C) 2019 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2019 Open Mobile Platform LLC.
*
* You may use this file under the terms of BSD license as follows:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the names of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "dbus_handlers.h"

static
gboolean
dbus_handlers_type_sp_supported_record(
NfcNdefRec* ndef)
{
return G_TYPE_CHECK_INSTANCE_TYPE(ndef, NFC_TYPE_NDEF_REC_SP);
}

static
gboolean
dbus_handlers_type_sp_match(
GKeyFile* file,
const char* group,
NfcNdefRecSp* rec)
{
char* pattern = dbus_handlers_config_get_string(file, group, "URI");
gboolean match = (!pattern || g_pattern_match_simple(pattern, rec->uri));

g_free(pattern);
return match;
}

static
DBusHandlerConfig*
dbus_handlers_type_sp_new_handler_config(
GKeyFile* file,
NfcNdefRec* ndef)
{
static const char group[] = "SmartPoster-Handler";

return dbus_handlers_type_sp_match(file, group, NFC_NDEF_REC_SP(ndef)) ?
dbus_handlers_new_handler_config(file, group) : NULL;
}

static
DBusListenerConfig*
dbus_handlers_type_sp_new_listener_config(
GKeyFile* file,
NfcNdefRec* ndef)
{
static const char group[] = "SmartPoster-Listener";

return dbus_handlers_type_sp_match(file, group, NFC_NDEF_REC_SP(ndef)) ?
dbus_handlers_new_listener_config(file, group) : NULL;
}

static
GVariant*
dbus_handlers_type_sp_handler_args(
NfcNdefRec* ndef)
{
NfcNdefRecSp* sp = NFC_NDEF_REC_SP(ndef);
const NfcNdefMedia* icon = sp->icon;
const char* icon_type;
GVariant* icon_data;

if (icon) {
icon_type = icon->type ? icon->type : "";
icon_data = g_variant_new_from_data(G_VARIANT_TYPE("ay"),
icon->data.bytes, icon->data.size, TRUE,
g_object_unref, g_object_ref(sp));
} else {
icon_type = "";
icon_data = g_variant_new_from_data(G_VARIANT_TYPE("ay"),
NULL, 0, TRUE, NULL, NULL);
}

return g_variant_new("(sssui(s@ay))", sp->uri, sp->title ? sp->title : "",
sp->type ? sp->type : "", sp->size, sp->act, icon_type, icon_data);
}

static
GVariant*
dbus_handlers_type_sp_listener_args(
gboolean handled,
NfcNdefRec* ndef)
{
NfcNdefRecSp* sp = NFC_NDEF_REC_SP(ndef);
const NfcNdefMedia* icon = sp->icon;
const char* icon_type;
GVariant* icon_data;

if (icon) {
icon_type = icon->type ? icon->type : "";
icon_data = g_variant_new_from_data(G_VARIANT_TYPE("ay"),
icon->data.bytes, icon->data.size, TRUE,
g_object_unref, g_object_ref(sp));
} else {
icon_type = "";
icon_data = g_variant_new_from_data(G_VARIANT_TYPE("ay"),
NULL, 0, TRUE, NULL, NULL);
}

return g_variant_new("(bsssui(s@ay))", handled, sp->uri,
sp->title ? sp->title : "", sp->type ? sp->type : "",
sp->size, sp->act, icon_type, icon_data);
}

const DBusHandlerType dbus_handlers_type_sp = {
.name = "SmartPoster",
.priority = DBUS_HANDLER_PRIORITY_DEFAULT,
.supported_record = dbus_handlers_type_sp_supported_record,
.new_handler_config = dbus_handlers_type_sp_new_handler_config,
.new_listener_config = dbus_handlers_type_sp_new_listener_config,
.free_handler_config = dbus_handlers_free_handler_config,
.free_listener_config = dbus_handlers_free_listener_config,
.handler_args = dbus_handlers_type_sp_handler_args,
.listener_args = dbus_handlers_type_sp_listener_args
};

/*
* Local Variables:
* mode: C
* c-basic-offset: 4
* indent-tabs-mode: nil
* End:
*/
1 change: 1 addition & 0 deletions unit/Makefile
Expand Up @@ -20,6 +20,7 @@ all:
@$(MAKE) -C plugins_dbus_handlers_config $*
@$(MAKE) -C plugins_dbus_handlers_type_generic $*
@$(MAKE) -C plugins_dbus_handlers_type_mediatype $*
@$(MAKE) -C plugins_dbus_handlers_type_sp $*
@$(MAKE) -C plugins_dbus_handlers_type_text $*
@$(MAKE) -C plugins_dbus_handlers_type_uri $*
@$(MAKE) -C plugins_dbus_service_adapter $*
Expand Down
1 change: 1 addition & 0 deletions unit/coverage/run
Expand Up @@ -22,6 +22,7 @@ plugins_dbus_handlers \
plugins_dbus_handlers_config \
plugins_dbus_handlers_type_generic \
plugins_dbus_handlers_type_mediatype \
plugins_dbus_handlers_type_sp \
plugins_dbus_handlers_type_text \
plugins_dbus_handlers_type_uri \
plugins_dbus_service_adapter \
Expand Down
5 changes: 5 additions & 0 deletions unit/plugins_dbus_handlers_type_sp/Makefile
@@ -0,0 +1,5 @@
# -*- Mode: makefile-gmake -*-

EXE = test_plugins_dbus_handlers_type_sp

include ../common/Makefile.plugins

0 comments on commit 0cb4598

Please sign in to comment.