ref: fa5d37089f461a9765301ef9c96094ffaa6cbc02
parent: e0cac8cff0fad58496578de0bf11f111f765d3a8
author: sirjofri <sirjofri@sirjofri.de>
date: Thu Nov 7 12:40:04 EST 2024
vcmserialize: make sure that version is printed first, always this is required for 3.0 and 4.0, and optional for 2.1
--- a/libvcard/vcard.c
+++ b/libvcard/vcard.c
@@ -144,28 +144,55 @@
}
static char*
+serializeline(Vline *l)
+{
+ char *ps, *ls;
+ char *upper;
+
+ ls = nil;
+ ps = serializeparams(l->params);
+ if (!ps)
+ goto Err;
+ upper = estrdup(l->name);
+ iltoupper(upper);
+ ls = smprint(
+ "%s%s" /* group string */
+ "%s%s:%s\r\n", /* name, param, value */
+ (l->group && *l->group ? l->group : ""), /* group string */
+ (l->group && *l->group ? "." : ""), /* group dot */
+ upper, ps, l->value);
+ free(upper);
+ if (!ls)
+ goto Err;
+ return ls;
+
+Err:
+ if (ls) free(ls);
+ if (ps) free(ps);
+ return nil;
+}
+
+static char*
serializelines(Vline *line)
{
Vline *l;
- char *s, *ns, *ls, *ps;
- char *upper;
+ char *s, *ns, *ls;
s = nil;
for (l = line; l; l = l->next) {
- ps = serializeparams(l->params);
- if (!ps) {
- if (s) free(s);
- return nil;
+ if (cistrcmp(l->name, "version") == 0) {
+ s = serializeline(l);
+ break;
}
- upper = estrdup(l->name);
- iltoupper(upper);
- ls = smprint(
- "%s%s" /* group string */
- "%s%s:%s\r\n", /* name, param, value */
- (l->group && *l->group ? l->group : ""), /* group string */
- (l->group && *l->group ? "." : ""), /* group dot */
- upper, ps, l->value);
- free(upper);
+ }
+ if (!s) {
+ werrstr("Vcard has no version property");
+ return nil;
+ }
+ for (l = line; l; l = l->next) {
+ if (cistrcmp(l->name, "version") == 0)
+ continue;
+ ls = serializeline(l);
if (!ls) {
if (s) free(s);
return nil;
@@ -172,12 +199,10 @@
}
if (!s) {
s = ls;
- free(ps);
} else {
ns = smprint("%s%s", s, ls);
free(s);
free(ls);
- free(ps);
s = ns;
if (!s)
return nil;
--- a/pim.c
+++ b/pim.c
@@ -21,6 +21,7 @@
Biobuf *b;
Vcard *vc, *card;
Vline *vl;
+ char *cs;
ARGBEGIN{
case 'h':
@@ -58,6 +59,10 @@
printparams(vl->params);
}
}
+
+ cs = vcmserialize(vc);
+ fprint(2, "\nserialize:\n\n%s", cs);
+ free(cs);
exits(nil);
}