Add vCard support

Only nicknames, photos, birthdays, addresses, telephone numbers, emails,
JIDs, titles, roles, notes, and URLs are supported

Due to the synopsis array not having enough space, `/vcard photo
open-self` and `/vcard photo save-self` are not documented properly in
the synopsis section of the `/vcard` command, but they are documented in
the arguments section

Fixed memory leak in vcard autocomplete (thanks to debXwoody)
This commit is contained in:
Marouane L
2022-09-06 17:29:07 +01:00
parent fc8455ba34
commit f934c5b59f
25 changed files with 3688 additions and 7 deletions

View File

@@ -2687,6 +2687,25 @@ stanza_create_avatar_metadata_publish_iq(xmpp_ctx_t* ctx, const char* img_data,
return iq;
}
xmpp_stanza_t*
stanza_create_vcard_request_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const stanza_id)
{
xmpp_stanza_t* iq = xmpp_iq_new(ctx, STANZA_TYPE_GET, stanza_id);
xmpp_stanza_set_from(iq, connection_get_fulljid());
if (jid) {
xmpp_stanza_set_to(iq, jid);
}
xmpp_stanza_t* vcard = xmpp_stanza_new(ctx);
xmpp_stanza_set_name(vcard, STANZA_NAME_VCARD);
xmpp_stanza_set_ns(vcard, STANZA_NS_VCARD);
xmpp_stanza_add_child(iq, vcard);
xmpp_stanza_release(vcard);
return iq;
}
xmpp_stanza_t*
stanza_attach_correction(xmpp_ctx_t* ctx, xmpp_stanza_t* stanza, const char* const replace_id)
{

View File

@@ -123,6 +123,7 @@
#define STANZA_NAME_MOOD "mood"
#define STANZA_NAME_RECEIVED "received"
#define STANZA_NAME_SENT "sent"
#define STANZA_NAME_VCARD "vCard"
// error conditions
#define STANZA_NAME_BAD_REQUEST "bad-request"
@@ -249,6 +250,7 @@
#define STANZA_NS_MOOD_NOTIFY "http://jabber.org/protocol/mood+notify"
#define STANZA_NS_STREAMS "http://etherx.jabber.org/streams"
#define STANZA_NS_XMPP_STREAMS "urn:ietf:params:xml:ns:xmpp-streams"
#define STANZA_NS_VCARD "vcard-temp"
#define STANZA_DATAFORM_SOFTWARE "urn:xmpp:dataforms:softwareinfo"
@@ -413,6 +415,7 @@ void stanza_free_caps(XMPPCaps* caps);
xmpp_stanza_t* stanza_create_avatar_retrieve_data_request(xmpp_ctx_t* ctx, const char* stanza_id, const char* const item_id, const char* const jid);
xmpp_stanza_t* stanza_create_avatar_data_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsize len);
xmpp_stanza_t* stanza_create_avatar_metadata_publish_iq(xmpp_ctx_t* ctx, const char* img_data, gsize len, int height, int width);
xmpp_stanza_t* stanza_create_vcard_request_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const stanza_id);
xmpp_stanza_t* stanza_create_mam_iq(xmpp_ctx_t* ctx, const char* const jid, const char* const startdate, const char* const lastid);
xmpp_stanza_t* stanza_change_password(xmpp_ctx_t* ctx, const char* const user, const char* const password);
xmpp_stanza_t* stanza_register_new_account(xmpp_ctx_t* ctx, const char* const user, const char* const password);

1613
src/xmpp/vcard.c Normal file

File diff suppressed because it is too large Load Diff

171
src/xmpp/vcard.h Normal file
View File

@@ -0,0 +1,171 @@
/*
* vcard.h
* vim: expandtab:ts=4:sts=4:sw=4
*
* Copyright (C) 2022 Marouane L. <techmetx11@disroot.org>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
*/
#ifndef XMPP_VCARD_H
#define XMPP_VCARD_H
#include <glib.h>
// 17 bits are currently used, out of (a possible) 32 bits
typedef enum {
VCARD_HOME = 1,
VCARD_WORK = 2,
VCARD_POSTAL = 4,
VCARD_PARCEL = 8,
VCARD_INTL = 16,
VCARD_PREF = 32,
VCARD_TEL_VOICE = 64,
VCARD_TEL_FAX = 128,
VCARD_TEL_PAGER = 256,
VCARD_TEL_MSG = 512,
VCARD_TEL_CELL = 1024,
VCARD_TEL_VIDEO = 2048,
VCARD_TEL_BBS = 4096,
VCARD_TEL_MODEM = 8192,
VCARD_TEL_ISDN = 16384,
VCARD_TEL_PCS = 32768,
VCARD_EMAIL_X400 = 65536,
VCARD_EMAIL_INTERNET = 131072,
VCARD_DOM = 262144
} vcard_element_options_t;
typedef struct _vcard_name
{
char *family, *given, *middle, *prefix, *suffix;
} vcard_name_t;
typedef struct _vcard_element_photo
{
union {
struct
{
guchar* data;
char* type;
gsize length;
};
char* extval;
};
gboolean external;
} vcard_element_photo_t;
typedef struct _vcard_element_address
{
char *pobox, *extaddr, *street, *locality, *region, *pcode, *country;
// Options used:
// VCARD_HOME
// VCARD_WORK
// VCARD_POSTAL
// VCARD_PARCEL
// VCARD_DOM
// VCARD_INTL
// VCARD_PREF
vcard_element_options_t options;
} vcard_element_address_t;
typedef struct _vcard_element_telephone
{
char* number;
// Options used:
// VCARD_HOME
// VCARD_WORK
// VCARD_TEL_VOICE
// VCARD_TEL_FAX
// VCARD_TEL_PAGER
// VCARD_TEL_MSG
// VCARD_TEL_CELL
// VCARD_TEL_VIDEO
// VCARD_TEL_BBS
// VCARD_TEL_MODEM
// VCARD_TEL_ISDN
// VCARD_TEL_PCS
// VCARD_PREF
vcard_element_options_t options;
} vcard_element_telephone_t;
typedef struct _vcard_element_email
{
char* userid;
// Options used:
// VCARD_HOME
// VCARD_WORK
// VCARD_EMAIL_X400
// VCARD_PREF
vcard_element_options_t options;
} vcard_element_email_t;
typedef enum _vcard_element_type {
VCARD_NICKNAME,
VCARD_PHOTO,
VCARD_BIRTHDAY,
VCARD_ADDRESS,
VCARD_TELEPHONE,
VCARD_EMAIL,
VCARD_JID,
VCARD_TITLE,
VCARD_ROLE,
VCARD_NOTE,
VCARD_URL
} vcard_element_type;
typedef struct _vcard_element
{
vcard_element_type type;
union {
char *nickname, *jid, *title, *role, *note, *url;
vcard_element_photo_t photo;
GDateTime* birthday;
vcard_element_address_t address;
vcard_element_telephone_t telephone;
vcard_element_email_t email;
};
} vcard_element_t;
typedef struct _vcard
{
// These elements are only meant to appear once (per DTD)
vcard_name_t name;
char* fullname;
gboolean modified;
// GQueue of vcard_element*
GQueue* elements;
} vCard;
#endif

66
src/xmpp/vcard_funcs.h Normal file
View File

@@ -0,0 +1,66 @@
/*
* vcard_funcs.h
* vim: expandtab:ts=4:sts=4:sw=4
*
* Copyright (C) 2022 Marouane L. <techmetx11@disroot.org>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
*/
#ifndef XMPP_VCARD_FUNCS_H
#define XMPP_VCARD_FUNCS_H
#include "ui/win_types.h"
#include "xmpp/vcard.h"
vCard* vcard_new();
void vcard_free(vCard* vcard);
void vcard_free_full(vCard* vcard);
gboolean vcard_parse(xmpp_stanza_t* vcard_xml, vCard* vcard);
void vcard_print(xmpp_ctx_t* ctx, ProfWin* window, char* jid);
void vcard_photo(xmpp_ctx_t* ctx, char* jid, char* filename, int index, gboolean open);
void vcard_user_refresh(void);
void vcard_user_save(void);
void vcard_user_set_fullname(char* fullname);
void vcard_user_set_name_family(char* family);
void vcard_user_set_name_given(char* given);
void vcard_user_set_name_middle(char* middle);
void vcard_user_set_name_prefix(char* prefix);
void vcard_user_set_name_suffix(char* suffix);
void vcard_user_add_element(vcard_element_t* element);
void vcard_user_remove_element(unsigned int index);
vcard_element_t* vcard_user_get_element_index(unsigned int index);
ProfWin* vcard_user_create_win();
void vcard_user_free(void);
#endif