X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=libcitadel%2Flib%2Fvcard.c;h=3a4b21c465378fa200b802486171f041834cc3cf;hb=7df04bd286205d65e4a6f872dfddc0b8a519db32;hp=5223da6b7c95a6b599808ce7d9cfeb7a0ac6d560;hpb=56d69e5d8434e98835a2582c59b771ba69475431;p=citadel.git diff --git a/libcitadel/lib/vcard.c b/libcitadel/lib/vcard.c index 5223da6b7..3a4b21c46 100644 --- a/libcitadel/lib/vcard.c +++ b/libcitadel/lib/vcard.c @@ -1,10 +1,9 @@ -/* - * vCard implementation for Citadel - * - * Copyright (C) 1999-2008 by the citadel.org development team. - * This code is freely redistributable under the terms of the GNU General - * Public License. All other rights reserved. - */ +// vCard implementation for Citadel +// +// Copyright (C) 1999-2023 by the citadel.org development team. +// +// This program is open source software. Use, duplication, or disclosure +// is subject to the terms of the GNU General Public License, version 3. #include @@ -12,18 +11,7 @@ #include #include #include - -#if TIME_WITH_SYS_TIME -# include -# include -#else -# if HAVE_SYS_TIME_H -# include -# else -# include -# endif -#endif - +#include #include #include #include @@ -32,10 +20,8 @@ #include -/* - * Constructor (empty vCard) - * Returns an empty vcard - */ +// Constructor (empty vCard) +// Returns an empty vcard struct vCard *vcard_new() { struct vCard *v; @@ -49,19 +35,15 @@ struct vCard *vcard_new() { return v; } -/* - * Remove the "charset=" attribute from a vCard property name - * - */ -void remove_charset_attribute(char *strbuf) -{ +// Remove the "charset=" attribute from a vCard property name +void remove_charset_attribute(char *strbuf) { int i, t; char compare[256]; t = num_tokens(strbuf, ';'); for (i=0; imagic != CTDL_VCARD_MAGIC) return; /* Self-check */ + if (v->magic != CTDL_VCARD_MAGIC) return; // Self-check if (v->numprops) for (i=0; i<(v->numprops); ++i) { free(v->prop[i].name); @@ -244,21 +213,17 @@ void vcard_free(struct vCard *v) { } - - -/* - * Set a name/value pair in the card - * v vCard to manipulate - * name key to set - * value the value to assign to key - * append if nonzero, append rather than replace if this key already exists. - */ +// Set a name/value pair in the card +// v vCard to manipulate +// name key to set +// value the value to assign to key +// append if nonzero, append rather than replace if this key already exists. void vcard_set_prop(struct vCard *v, char *name, char *value, int append) { int i; - if (v->magic != CTDL_VCARD_MAGIC) return; /* Self-check */ + if (v->magic != CTDL_VCARD_MAGIC) return; // Self-check - /* If this key is already present, replace it */ + // If this key is already present, replace it if (!append) if (v->numprops) for (i=0; i<(v->numprops); ++i) { if (!strcasecmp(v->prop[i].name, name)) { free(v->prop[i].name); @@ -269,7 +234,7 @@ void vcard_set_prop(struct vCard *v, char *name, char *value, int append) { } } - /* Otherwise, append it */ + // Otherwise, append it ++v->numprops; v->prop = realloc(v->prop, (v->numprops * sizeof(struct vCardProp)) ); @@ -278,26 +243,21 @@ void vcard_set_prop(struct vCard *v, char *name, char *value, int append) { } - - -/* - * Serialize a 'struct vcard' into an actual vcard. - */ -char *vcard_serialize(struct vCard *v) -{ +// Serialize a 'struct vcard' into an actual vcard. +char *vcard_serialize(struct vCard *v) { char *ser; int i, j; size_t len; int is_utf8 = 0; - if (v == NULL) return NULL; /* self check */ - if (v->magic != CTDL_VCARD_MAGIC) return NULL; /* self check */ + if (v == NULL) return NULL; // self check + if (v->magic != CTDL_VCARD_MAGIC) return NULL; // self check - /* Set the vCard version number to 2.1 at this time. */ + // Set the vCard version number to 2.1 at this time. vcard_set_prop(v, "VERSION", "2.1", 0); - /* Figure out how big a buffer we need to allocate */ - len = 64; /* for begin, end, and a little padding for safety */ + // Figure out how big a buffer we need to allocate + len = 64; // for begin, end, and a little padding for safety if (v->numprops) for (i=0; i<(v->numprops); ++i) { len = len + strlen(v->prop[i].name) + @@ -326,19 +286,15 @@ char *vcard_serialize(struct vCard *v) } } strcat(ser, "end:vcard\r\n"); - return ser; } - -/* - * Convert FN (Friendly Name) into N (Name) - * - * vname Supplied friendly-name - * n Target buffer to store Name - * vname_size Size of buffer - */ +// Convert FN (Friendly Name) into N (Name) +// +// vname Supplied friendly-name +// n Target buffer to store Name +// vname_size Size of buffer void vcard_fn_to_n(char *vname, char *n, size_t vname_size) { char lastname[256]; char firstname[256]; @@ -349,48 +305,40 @@ void vcard_fn_to_n(char *vname, char *n, size_t vname_size) { safestrncpy(buf, n, sizeof buf); - /* Try to intelligently convert the screen name to a - * fully expanded vCard name based on the number of - * words in the name - */ + // Try to intelligently convert the screen name to a fully expanded vCard name based on the number of words in the name safestrncpy(lastname, "", sizeof lastname); safestrncpy(firstname, "", sizeof firstname); safestrncpy(middlename, "", sizeof middlename); safestrncpy(honorific_prefixes, "", sizeof honorific_prefixes); safestrncpy(honorific_suffixes, "", sizeof honorific_suffixes); - /* Honorific suffixes */ + // Honorific suffixes if (num_tokens(buf, ',') > 1) { extract_token(honorific_suffixes, buf, (num_tokens(buf, ' ') - 1), ',', sizeof honorific_suffixes); remove_token(buf, (num_tokens(buf, ',') - 1), ','); } - /* Find a last name */ + // Find a last name extract_token(lastname, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof lastname); remove_token(buf, (num_tokens(buf, ' ') - 1), ' '); - /* Find honorific prefixes */ + // Find honorific prefixes if (num_tokens(buf, ' ') > 2) { extract_token(honorific_prefixes, buf, 0, ' ', sizeof honorific_prefixes); remove_token(buf, 0, ' '); } - /* Find a middle name */ + // Find a middle name if (num_tokens(buf, ' ') > 1) { extract_token(middlename, buf, (num_tokens(buf, ' ') - 1), ' ', sizeof middlename); remove_token(buf, (num_tokens(buf, ' ') - 1), ' '); } - /* Anything left is probably the first name */ + // Anything left is probably the first name safestrncpy(firstname, buf, sizeof firstname); - striplt(firstname); + string_trim(firstname); - /* Compose the structured name */ - snprintf(vname, vname_size, "%s;%s;%s;%s;%s", lastname, firstname, middlename, - honorific_prefixes, honorific_suffixes); + // Compose the structured name + snprintf(vname, vname_size, "%s;%s;%s;%s;%s", lastname, firstname, middlename, honorific_prefixes, honorific_suffixes); } - - - -