ref: b6856322e21e458c9dcc4adf475c39604704b827
parent: 9828f53e5b542da92dfdffc124dd9941d308cb1d
author: sirjofri <sirjofri@sirjofri.de>
date: Mon Oct 21 11:08:38 EDT 2024
grouped properties: name as group.property to prevent name collision
--- a/vcardfs.c
+++ b/vcardfs.c
@@ -70,6 +70,20 @@
Qparamdata,
};
+static char *qnames[] = {
+ [Qroot] "root",
+ [Qctl] "ctl",
+ [Qimport] "import",
+ [Qgexport] "gexport",
+ [Qcard] "card",
+ [Qexport] "export",
+ [Qline] "line",
+ [Qdata] "data",
+ [Qgroup] "group",
+ [Qparams] "params",
+ [Qparamdata] "paramdata",
+};
+
typedef struct Vfile Vfile;
struct Vfile {
int level;
@@ -81,6 +95,22 @@
char *serialized;
};
+static char*
+vfqn(Vfile *f)
+{
+ if (f->level > Qparamdata || f->level < 0)
+ return "<Q>";
+ return qnames[f->level];
+}
+
+static char*
+fqn(File *f)
+{
+ Vfile *vf;
+ vf = f->aux;
+ return vfqn(vf);
+}
+
char *user = nil;
char *mtpt = "/mnt/vcard";
char *service = nil;
@@ -184,6 +214,28 @@
}
static void
+condrenameline(File *f)
+{
+ Vfile *vf;
+ Vline *l;
+ char *s;
+
+ vf = f->aux;
+ l = vf->line;
+
+ if (!(l->group && *l->group)) {
+ if (f->name)
+ free(f->name);
+ f->name = strdup(l->name);
+ return;
+ }
+ s = smprint("%s.%s", l->group, l->name);
+ if (f->name)
+ free(f->name);
+ f->name = s;
+}
+
+static void
condrenamecard(Vfile *f)
{
char *s;
@@ -214,6 +266,7 @@
writedata(Req *r, Vfile *f)
{
char *s;
+ File *file;
switch (f->level) {
case Qparamdata:
@@ -265,6 +318,12 @@
if (f->line->group)
free(f->line->group);
f->line->group = s;
+
+ /* rename line file to match group */
+ file = r->fid->file->parent;
+ if (!file || !file->name)
+ break;
+ condrenameline(file);
break;
default:
respond(r, "file not found");
@@ -702,7 +761,14 @@
for (l = c->content; l; l = l->next) {
vf = emkvfile(Qline, c, l, nil, cf);
- fl = createfile(fc, l->name, user, DMDIR|0777, vf);
+ if (l->group && *l->group) {
+ s = smprint("%s.%s", l->group, l->name);
+ }
+ fl = createfile(fc, (l->group && *l->group ? s : l->name), user, DMDIR|0777, vf);
+ if (l->group) {
+ free(s);
+ s = nil;
+ }
vf = emkvfile(Qdata, c, l, nil, cf);
createfile(fl, "data", user, 0666, vf);
if (l->group) {
@@ -757,7 +823,7 @@
if (!cards)
sysfatal("%r");
- fs.tree = alloctree("vcf", "vcf", DMDIR|0555, nil);
+ fs.tree = alloctree("vcard", "vcard", DMDIR|0555, nil);
createfile(fs.tree->root, "ctl", user, 0222,
emkvfile(Qctl, nil, nil, nil, nil));
createfile(fs.tree->root, "import", user, 0222,