shithub: vcardfs

Download patch

ref: cfe931321aced3c0a2e3c1377737f356b7aa04fa
parent: 2f487c06c35d1a8b325f03fe640dd6e46d29b35f
author: sirjofri <sirjofri@sirjofri.de>
date: Fri Oct 18 07:38:42 EDT 2024

set and create group and params

--- a/vcardfs.c
+++ b/vcardfs.c
@@ -233,6 +233,20 @@
 		condrenamecard(f);
 		break;
 	case Qgroup:
+		if (!f->line) goto Err;
+		s = mallocz(r->ifcall.count + 1, 1);
+		if (!s) {
+			responderror(r);
+			return;
+		}
+		memcpy(s, r->ifcall.data, r->ifcall.count);
+		
+		if (s[r->ifcall.count - 1] == '\n')
+			s[r->ifcall.count - 1] = 0;
+		
+		if (f->line->group)
+			free(f->line->group);
+		f->line->group = s;
 		break;
 	default:
 		respond(r, "file not found");
@@ -269,9 +283,84 @@
 	respond(r, "not implemented");
 }
 
+static Vparam*
+emkvparam(Vline *line, char *name)
+{
+	Vparam *vp, *p;
+	vp = mallocz(sizeof(Vparam), 1);
+	if (!vp)
+		sysfatal("%r");
+	vp->name = estrdup(name);
+	vp->value = estrdup("");
+	
+	if (!line->params) {
+		line->params = vp;
+		return vp;
+	}
+	for (p = line->params; p->next; p = p->next)
+		continue;
+	p->next = vp;
+	return vp;
+}
+
+static void
+fscreate(Req *r)
+{
+	File *f, *nf;
+	Vfile *vf;
+	Vparam *vp;
+	
+	nf = nil;
+	USED(nf);
+	f = r->fid->file;
+	vf = f->aux;
+	if (r->ifcall.perm&DMDIR)
+		goto Nil;
+	switch (vf->level) {
+	case Qline:
+		if (strcmp(r->ifcall.name, "group") != 0)
+			goto Nil;
+		nf = createfile(f, r->ifcall.name, user, 0666, nil);
+		if (!nf) {
+			responderror(r);
+			return;
+		}
+		nf->aux = emkvfile(Qgroup, vf->card, vf->line, nil, vf->cardfile);
+		vf->line->group = estrdup("");
+		break;
+	case Qparams:
+		nf = createfile(f, r->ifcall.name, user, 0666, nil);
+		if (!nf) {
+			responderror(r);
+			return;
+		}
+		vp = emkvparam(vf->line, r->ifcall.name);
+		nf->aux = emkvfile(Qparamdata, vf->card, vf->line, vp, vf->cardfile);
+		break;
+	default:
+		goto Nil;
+	}
+	
+	if (nf) {
+		r->fid->file = nf;
+		r->ofcall.qid = nf->qid;
+	}
+	
+	if (vf->cardfile->serialized)
+		free(vf->cardfile->serialized);
+	vf->cardfile->serialized = nil;
+	
+	respond(r, nil);
+	return;
+	
+Nil:
+	respond(r, "create prohibited");
+}
+
 Srv fs = {
 	.read = fsread,
 	.write = fswrite,
+	.create = fscreate,
 };
 
 /* TODO: LOOKAT:
@@ -324,7 +413,7 @@
 static void
 initcardfiles(Vcard *chain)
 {
-	File *fc, *fl, *fp, *f;
+	File *fc, *fl, *f;
 	Vcard *c;
 	Vline *l;
 	Vparam *p;
@@ -336,29 +425,29 @@
 		if (!s)
 			continue;
 		cf = emkvfile(Qcard, c, nil, nil, nil);
-		fc = createfile(fs.tree->root, s, user, DMDIR|0555, cf);
+		fc = createfile(fs.tree->root, s, user, DMDIR|0777, cf);
 		cf->file = fc;
 		free(s);
 		if (!fc)
 			sysfatal("%r");
 		vf = emkvfile(Qexport, c, nil, nil, cf);
-		f = createfile(fc, "export", user, 0444, vf);
+		createfile(fc, "export", user, 0444, vf);
 		
 		for (l = c->content; l; l = l->next) {
 			vf = emkvfile(Qline, c, l, nil, cf);
-			fl = createfile(fc, l->name, user, DMDIR|0555, vf);
+			fl = createfile(fc, l->name, user, DMDIR|0777, vf);
 			vf = emkvfile(Qdata, c, l, nil, cf);
-			f = createfile(fl, "data", user, 0666, vf);
+			createfile(fl, "data", user, 0666, vf);
 			if (l->group) {
 				vf = emkvfile(Qgroup, c, l, nil, cf);
-				f = createfile(fl, "group", user, 0666, vf);
+				createfile(fl, "group", user, 0666, vf);
 			}
 			vf = emkvfile(Qparams, c, l, nil, cf);
-			f = createfile(fl, "params", user, DMDIR|0555, vf);
+			f = createfile(fl, "params", user, DMDIR|0777, vf);
 			
 			for (p = l->params; p; p = p->next) {
 				vf = emkvfile(Qparamdata, c, l, p, cf);
-				fp = createfile(f, p->name, user, 0666, vf);
+				createfile(f, p->name, user, 0666, vf);
 			}
 		}
 	}