Skip to content

Commit

Permalink
[nfcd] Encoding and decoding of SmartPoster NDEF records. JB#45439
Browse files Browse the repository at this point in the history
  • Loading branch information
monich committed Aug 2, 2019
1 parent 4bf54d2 commit 19ca16e
Show file tree
Hide file tree
Showing 15 changed files with 1,690 additions and 167 deletions.
1 change: 1 addition & 0 deletions core/Makefile
Expand Up @@ -34,6 +34,7 @@ SRC = \
nfc_locale.c \
nfc_manager.c \
nfc_ndef_rec.c \
nfc_ndef_rec_sp.c \
nfc_ndef_rec_u.c \
nfc_ndef_rec_t.c \
nfc_plugins.c \
Expand Down
68 changes: 63 additions & 5 deletions core/include/nfc_ndef.h
Expand Up @@ -14,8 +14,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 @@ -49,7 +49,8 @@ typedef enum nfc_ndef_rec_flags {
typedef enum nfc_ndef_rtd {
NFC_NDEF_RTD_UNKNOWN,
NFC_NDEF_RTD_URI, /* "U" */
NFC_NDEF_RTD_TEXT /* "T" */
NFC_NDEF_RTD_TEXT, /* "T" */
NFC_NDEF_RTD_SMART_POSTER /* "Sp" */
} NFC_NDEF_RTD;

/* TNF = Type name format */
Expand Down Expand Up @@ -157,17 +158,74 @@ nfc_ndef_rec_t_new_enc(
const char* lang,
NFC_NDEF_REC_T_ENC enc);

#define nfc_ndef_rec_t_new(text,lang) \
#define nfc_ndef_rec_t_new(text, lang) \
nfc_ndef_rec_t_new_enc(text, lang, NFC_NDEF_REC_T_ENC_UTF8)

NFC_LANG_MATCH
nfc_ndef_rec_t_lang_match(
NfcNdefRecT* rec,
const NfcLanguage* lang); /* Since 1.0.15 */

gint
nfc_ndef_rec_t_lang_compare(
gconstpointer a, /* NfcNdefRecT* */
gconstpointer b, /* NfcNdefRecT* */
gpointer user_data /* NfcLanguage* */); /* Since 1.0.18 */

/* Smart poster */

typedef enum nfc_ndef_sp_act {
NFC_NDEF_SP_ACT_DEFAULT = -1, /* No action record */
NFC_NDEF_SP_ACT_OPEN, /* Perform the action */
NFC_NDEF_SP_ACT_SAVE, /* Save for later */
NFC_NDEF_SP_ACT_EDIT /* Open for editing */
} NFC_NDEF_SP_ACT;

typedef struct nfc_ndef_rec_sp_priv NfcNdefRecSpPriv;

typedef struct nfc_ndef_media {
GUtilData data;
const char* type;
} NfcNdefMedia;

typedef struct nfc_ndef_rec_sp {
NfcNdefRec rec;
NfcNdefRecSpPriv* priv;
const char* uri;
const char* title;
const char* lang;
const char* type;
guint size;
NFC_NDEF_SP_ACT act;
NfcNdefMedia* icon;
} NfcNdefRecSp;

GType nfc_ndef_rec_sp_get_type(void);
#define NFC_TYPE_NDEF_REC_SP (nfc_ndef_rec_sp_get_type())
#define NFC_NDEF_REC_SP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \
NFC_TYPE_NDEF_REC_SP, NfcNdefRecSp))
#define NFC_IS_NDEF_REC_SP(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, \
NFC_TYPE_NDEF_REC_SP)

NfcNdefRecSp*
nfc_ndef_rec_sp_new(
const char* uri,
const char* title,
const char* lang,
const char* type,
guint size,
NFC_NDEF_SP_ACT act,
const NfcNdefMedia* icon); /* Since 1.0.18 */

/* Utilities */

gboolean
nfc_ndef_valid_mediatype(
const GUtilData* type,
gboolean wildcard); /* Since 1.0.18 */

/* These are not yet implemented: */

typedef struct nfc_ndef_rec_sp NfcNdefRecSp; /* Smart poster */
typedef struct nfc_ndef_rec_hs NfcNdefRecHs; /* Handover select */
typedef struct nfc_ndef_rec_hr NfcNdefRecHr; /* Handover request */
typedef struct nfc_ndef_rec_Hc NfcNdefRecHc; /* Handover carrier */
Expand Down
44 changes: 39 additions & 5 deletions core/src/nfc_ndef_p.h
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2018 Jolla Ltd.
* Copyright (C) 2018 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018-2019 Jolla Ltd.
* Copyright (C) 2018-2019 Slava Monich <slava.monich@jolla.com>
* Copyright (C) 2018 Bogdan Pankovsky <b.pankovsky@omprussia.ru>
*
* You may use this file under the terms of BSD license as follows:
Expand All @@ -15,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 All @@ -41,11 +41,18 @@
/* Add _ prefix so that they don't get exported */
#define nfc_ndef_payload _nfc_ndef_payload
#define nfc_ndef_rec_initialize _nfc_ndef_rec_initialize
#define nfc_ndef_rec_clear_flags _nfc_ndef_rec_clear_flags
#define nfc_ndef_rec_u_new_from_data _nfc_ndef_rec_u_new_from_data
#define nfc_ndef_rec_u_steal_uri _nfc_ndef_rec_u_steal_uri
#define nfc_ndef_rec_t_new_from_data _nfc_ndef_rec_t_new_from_data
#define nfc_ndef_rec_t_steal_lang _nfc_ndef_rec_t_steal_lang
#define nfc_ndef_rec_t_steal_text _nfc_ndef_rec_t_steal_text
#define nfc_ndef_rec_sp_new_from_data _nfc_ndef_rec_sp_new_from_data
#define nfc_ndef_rec_new_well_known _nfc_ndef_rec_new_well_known
#define nfc_ndef_rec_new_media _nfc_ndef_rec_new_media
#define nfc_ndef_rec_type_u _nfc_ndef_rec_type_u
#define nfc_ndef_rec_type_t _nfc_ndef_rec_type_t
#define nfc_ndef_rec_type_sp _nfc_ndef_rec_type_sp

typedef struct nfc_ndef_rec_class {
GObjectClass parent;
Expand All @@ -69,6 +76,7 @@ typedef struct nfc_ndef_data {

extern const GUtilData nfc_ndef_rec_type_u; /* "U" */
extern const GUtilData nfc_ndef_rec_type_t; /* "T" */
extern const GUtilData nfc_ndef_rec_type_sp; /* "Sp" */

gboolean
nfc_ndef_type(
Expand All @@ -86,6 +94,16 @@ nfc_ndef_rec_initialize(
NFC_NDEF_RTD rtd,
const NfcNdefData* ndef);

void
nfc_ndef_rec_clear_flags(
NfcNdefRec* rec,
NFC_NDEF_REC_FLAGS flags);

NfcNdefRec*
nfc_ndef_rec_new_media(
const GUtilData* type,
const GUtilData* payload);

NfcNdefRec*
nfc_ndef_rec_new_well_known(
GType gtype,
Expand All @@ -97,9 +115,25 @@ NfcNdefRecU*
nfc_ndef_rec_u_new_from_data(
const NfcNdefData* ndef);

char*
nfc_ndef_rec_u_steal_uri(
NfcNdefRecU* ndef);

NfcNdefRecT*
nfc_ndef_rec_t_new_from_data(
const NfcNdefData* ndef);
const NfcNdefData* ndef);

char*
nfc_ndef_rec_t_steal_lang(
NfcNdefRecT* self);

char*
nfc_ndef_rec_t_steal_text(
NfcNdefRecT* self);

NfcNdefRecSp*
nfc_ndef_rec_sp_new_from_data(
const NfcNdefData* ndef);

#endif /* NFC_NDEF_PRIVATE_H */

Expand Down

0 comments on commit 19ca16e

Please sign in to comment.