CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
vcard_store.h File Reference
#include <cstddef>
#include <cstdint>

Go to the source code of this file.

Classes

struct  vcard_data_t
 Structured representation of an own vCard for editor/wizard use. More...

Macros

#define VCARD_MAX_LEN   768
#define VCARD_MAX_CARDS   100

Functions

bool vcard_store_set_own (const char *vcard, size_t len, char *err, size_t err_len)
 Stores local own-vCard after validation and field filtering.
size_t vcard_store_get_own (char *out, size_t max_len)
 Retrieves local own-vCard text.
size_t vcard_filter_empty_fields (char *vcard, size_t len)
 Removes empty optional fields from vCard text in-place.
bool vcard_store_has_own (void)
 Returns whether local own-vCard exists.
bool vcard_store_clear_own (void)
 Deletes local own-vCard from storage.
bool vcard_store_get_display_own (char *out, size_t max_len)
 Retrieves display name derived from local own-vCard.
void vcard_store_init (void)
 Initializes metadata cache for stored peer vCards.
uint16_t vcard_store_count (void)
 Returns number of stored peer vCards.
bool vcard_store_add (const char *vcard, size_t len, char *err, size_t err_len)
 Adds peer vCard to first free slot after validation and duplicate check.
bool vcard_store_contains (const char *vcard, size_t len)
 Reports whether an exact-text vCard is already stored.
bool vcard_store_delete (uint16_t slot)
 Deletes peer vCard at slot index.
bool vcard_store_update (uint16_t slot, const char *vcard, size_t len, char *err, size_t err_len)
 Overwrites the vCard stored at slot in place after validation.
size_t vcard_store_get (uint16_t slot, char *out, size_t max_len)
 Retrieves raw vCard text from slot.
bool vcard_store_get_display (uint16_t slot, char *out, size_t max_len)
 Retrieves cached display label for slot.
uint16_t vcard_store_get_sorted (uint16_t *out_slots, uint16_t max_slots)
 Returns slot indices of stored cards sorted by last name.
bool vcard_parse_to_struct (const char *raw, vcard_data_t *out)
 Parses vCard 4.0 raw text into a structured vcard_data_t.
size_t vcard_generate_from_struct (const vcard_data_t *data, char *out_buf, size_t buf_len)
 Generates vCard 4.0 text from a structured vcard_data_t. Empty fields are omitted. FN falls back to "given family" when empty.

Macro Definition Documentation

◆ VCARD_MAX_CARDS

◆ VCARD_MAX_LEN

Function Documentation

◆ vcard_filter_empty_fields()

size_t vcard_filter_empty_fields ( char * vcard,
size_t len )

Removes empty optional fields from vCard text in-place.

Parameters
vcardMutable vCard buffer.
lenInput length.
Returns
New filtered length.

Definition at line 126 of file vcard_store.cpp.

References vcard_line_has_content(), and VCARD_MAX_LEN.

Referenced by vcard_store_add(), vcard_store_set_own(), and vcard_store_update().

◆ vcard_generate_from_struct()

size_t vcard_generate_from_struct ( const vcard_data_t * data,
char * out_buf,
size_t buf_len )

Generates vCard 4.0 text from a structured vcard_data_t. Empty fields are omitted. FN falls back to "given family" when empty.

Parameters
dataInput struct.
out_bufOutput buffer.
buf_lenOutput buffer size (should be >= VCARD_MAX_LEN + 1).
Returns
Length of generated vCard text (excluding terminator), or 0 on failure.

Generates vCard 4.0 text from a structured vcard_data_t. Empty fields are omitted. FN falls back to "given family" when empty.

Definition at line 981 of file vcard_store.cpp.

References append_field(), vcard_data_t::email, vcard_data_t::family_name, vcard_data_t::formatted_name, vcard_data_t::given_name, vcard_data_t::impp_matrix, vcard_data_t::impp_signal, vcard_data_t::impp_telegram, vcard_data_t::impp_threema, vcard_data_t::note, vcard_data_t::organization, vcard_data_t::social_profile, vcard_data_t::tel_cell, vcard_data_t::tel_home, vcard_data_t::tel_work, vcard_data_t::title, and vcard_data_t::url.

Referenced by cdc::mod_vcard::wizardFinish().

◆ vcard_parse_to_struct()

bool vcard_parse_to_struct ( const char * raw,
vcard_data_t * out )

Parses vCard 4.0 raw text into a structured vcard_data_t.

Parameters
rawNull-terminated vCard text (may contain CRLF or LF line endings).
outOutput struct (zeroed before parsing).
Returns
true if input looked like a vCard (BEGIN:VCARD seen).

Parses vCard 4.0 raw text into a structured vcard_data_t.

Definition at line 935 of file vcard_store.cpp.

References parse_line_into_struct().

Referenced by cdc::mod_vcard::VcardWizard::edit(), cdc::mod_vcard::VcardWizard::editReceived(), cdc::mod_vcard::showVcardDetails(), and cdc::mod_vcard::showVcardQr().

◆ vcard_store_add()

bool vcard_store_add ( const char * vcard,
size_t len,
char * err,
size_t err_len )

Adds peer vCard to first free slot after validation and duplicate check.

Parameters
vcardvCard text.
lenInput length.
errOutput error buffer.
err_lenError buffer size.
Returns
true on successful storage.

Definition at line 539 of file vcard_store.cpp.

References fnv1a_hash(), g_card_count, g_cards, set_err(), vcard_filter_empty_fields(), vcard_is_duplicate(), vcard_key_for_slot(), VCARD_MAX_CARDS, VCARD_MAX_LEN, VCARD_NAMESPACE, vcard_parse_names(), vcard_store_init(), and vcard_validate().

Referenced by cdc::mod_vcard::deliverVcard(), cdc::mod_vcard::importReceivedVcard(), and cdc::mod_vcard::wizardFinish().

◆ vcard_store_clear_own()

bool vcard_store_clear_own ( void )

Deletes local own-vCard from storage.

Returns
true on successful deletion.

Definition at line 429 of file vcard_store.cpp.

References g_own_loaded, g_own_present, g_own_vcard, VCARD_KEY_OWN, and VCARD_NAMESPACE.

Referenced by cdc::mod_vcard::cmdVcardDelete().

◆ vcard_store_contains()

bool vcard_store_contains ( const char * vcard,
size_t len )

Reports whether an exact-text vCard is already stored.

Parameters
vcardCandidate vCard text.
lenCandidate length.
Returns
true if a stored card matches vcard byte for byte.

Definition at line 518 of file vcard_store.cpp.

References fnv1a_hash(), vcard_is_duplicate(), VCARD_NAMESPACE, and vcard_store_init().

Referenced by cdc::mod_vcard::importReceivedVcard().

◆ vcard_store_count()

uint16_t vcard_store_count ( void )

Returns number of stored peer vCards.

Returns
Peer vCard count.

Definition at line 485 of file vcard_store.cpp.

References g_card_count, and vcard_store_init().

◆ vcard_store_delete()

bool vcard_store_delete ( uint16_t slot)

Deletes peer vCard at slot index.

Parameters
slotSlot index.
Returns
true on successful deletion.

Definition at line 654 of file vcard_store.cpp.

References g_card_count, g_cards, vcard_key_for_slot(), VCARD_MAX_CARDS, VCARD_NAMESPACE, and vcard_store_init().

Referenced by cdc::mod_vcard::cmdVcardDelete(), and cdc::mod_vcard::onReceivedDeleteConfirm().

◆ vcard_store_get()

size_t vcard_store_get ( uint16_t slot,
char * out,
size_t max_len )

Retrieves raw vCard text from slot.

Parameters
slotSlot index.
outOutput buffer.
max_lenOutput buffer size.
Returns
Number of copied bytes.

Definition at line 683 of file vcard_store.cpp.

References g_cards, vcard_key_for_slot(), VCARD_MAX_CARDS, VCARD_NAMESPACE, and vcard_store_init().

Referenced by cdc::mod_vcard::cmdVcardGet(), cdc::mod_vcard::ctxReceivedForward(), cdc::mod_vcard::ctxReceivedQr(), cdc::mod_vcard::VcardWizard::editReceived(), cdc::mod_vcard::VcardModule::exportBackup(), and cdc::mod_vcard::onReceivedSelect().

◆ vcard_store_get_display()

bool vcard_store_get_display ( uint16_t slot,
char * out,
size_t max_len )

Retrieves cached display label for slot.

Parameters
slotSlot index.
outOutput label buffer.
max_lenOutput buffer size.
Returns
true on success.

Definition at line 717 of file vcard_store.cpp.

References g_cards, VCARD_MAX_CARDS, and vcard_store_init().

Referenced by cdc::mod_vcard::cmdVcardList(), cdc::mod_vcard::cmdVcardSet(), and cdc::mod_vcard::rebuildReceivedList().

◆ vcard_store_get_display_own()

bool vcard_store_get_display_own ( char * out,
size_t max_len )

Retrieves display name derived from local own-vCard.

Parameters
outOutput buffer.
max_lenOutput buffer size.
Returns
true on success.

Definition at line 413 of file vcard_store.cpp.

References g_own_present, g_own_vcard, vcard_load_own(), and vcard_parse_names().

◆ vcard_store_get_own()

size_t vcard_store_get_own ( char * out,
size_t max_len )

Retrieves local own-vCard text.

Parameters
outOutput buffer.
max_lenOutput buffer size.
Returns
Number of copied bytes.

Definition at line 387 of file vcard_store.cpp.

References g_own_present, g_own_vcard, and vcard_load_own().

Referenced by cdc::mod_vcard::cmdVcardGet(), cdc::mod_vcard::VcardWizard::edit(), cdc::mod_vcard::VcardModule::exportBackup(), cdc::mod_vcard::onMainMenuSelect(), and cdc::mod_vcard::onMyVcardLockscreenSelect().

◆ vcard_store_get_sorted()

uint16_t vcard_store_get_sorted ( uint16_t * out_slots,
uint16_t max_slots )

Returns slot indices of stored cards sorted by last name.

Parameters
out_slotsOutput slot-index array.
max_slotsMaximum writable entries.
Returns
Number of returned slot indices.

Definition at line 1048 of file vcard_store.cpp.

References g_cards, VCARD_MAX_CARDS, and vcard_store_init().

Referenced by cdc::mod_vcard::cmdVcardList(), cdc::mod_vcard::VcardModule::exportBackup(), and cdc::mod_vcard::rebuildReceivedList().

◆ vcard_store_has_own()

bool vcard_store_has_own ( void )

Returns whether local own-vCard exists.

Returns
true if own-vCard is present.

Definition at line 402 of file vcard_store.cpp.

References g_own_present, and vcard_load_own().

Referenced by cdc::mod_vcard::onMainMenuSelect().

◆ vcard_store_init()

◆ vcard_store_set_own()

bool vcard_store_set_own ( const char * vcard,
size_t len,
char * err,
size_t err_len )

Stores local own-vCard after validation and field filtering.

Parameters
vcardvCard text.
lenInput length.
errOutput error buffer.
err_lenError buffer size.
Returns
true on successful persistence.

Definition at line 343 of file vcard_store.cpp.

References g_own_loaded, g_own_present, g_own_vcard, LOG_I, set_err(), TAG, vcard_filter_empty_fields(), VCARD_KEY_OWN, VCARD_MAX_LEN, VCARD_NAMESPACE, and vcard_validate().

Referenced by cdc::mod_vcard::VcardModule::importBackup(), cdc::mod_vcard::vcardLineInterceptor(), and cdc::mod_vcard::wizardFinish().

◆ vcard_store_update()

bool vcard_store_update ( uint16_t slot,
const char * vcard,
size_t len,
char * err,
size_t err_len )

Overwrites the vCard stored at slot in place after validation.

Parameters
slotSlot index of an existing stored card.
vcardNew vCard text.
lenNew vCard length.
errOutput error buffer.
err_lenError buffer size.
Returns
true on successful update.

Overwrites the vCard stored at slot in place after validation.

Parameters
slotSlot index of an existing stored card.
vcardNew vCard text.
lenNew vCard length.
errOutput error buffer.
err_lenError buffer size.
Returns
true on successful update.

Definition at line 610 of file vcard_store.cpp.

References fnv1a_hash(), g_cards, set_err(), vcard_filter_empty_fields(), vcard_key_for_slot(), VCARD_MAX_CARDS, VCARD_MAX_LEN, VCARD_NAMESPACE, vcard_parse_names(), vcard_store_init(), and vcard_validate().

Referenced by cdc::mod_vcard::vcardLineInterceptor(), and cdc::mod_vcard::wizardFinish().