ref: b466085c9ff2765a85dd12000ba6348937bc3db5
parent: a9ca97f3154d7cf8951a4e80940e623952722a1a
author: Michael Misch <michaelmisch1985@gmail.com>
date: Sun Jun 16 11:21:27 EDT 2024
Updates to get the feed file working correctly
--- a/alt.h
+++ b/alt.h
@@ -8,7 +8,6 @@
char *status;
char *aside;
int fd;
- long offset;
Notify *notify;
Buffer *next;
--- a/buffer.c
+++ b/buffer.c
@@ -37,6 +37,7 @@
bufferPush(Buffer *base, char *name)
{Buffer *b, *ep;
+ char p[1024];
for(ep = base; ep->next; ep = ep->next){if(ep && strcmp(ep->name, name) == 0)
@@ -49,6 +50,12 @@
b->name = estrdup(name);
b->notify = nil;
b->input = base->input;
+ snprint(p, sizeof(p), "%s/%s/%s", logdir, base->name, name);
+ if(access(p, 0) == 0)
+ b->fd = open(p, OWRITE);
+ else
+ b->fd = create(p, OWRITE, 0644);
+ seek(b->fd, 0, 2);
ep->next = b;
return nil;
@@ -71,7 +78,7 @@
Buffer *b;
b = emalloc(sizeof(*b));
- b->name = "root";
+ b->name = nil;;
b->input = input;
b->ctl = ctl;
b->notify = nil;
--- a/client.c
+++ b/client.c
@@ -44,6 +44,8 @@
Ref;
Buffer *current;
+ int fd;
+ int offset;
int showmarkdown;
};
@@ -187,13 +189,6 @@
void
clopen(Req *r)
{- Clfid *f;
-
- f = r->fid->aux;
- if(f->level == Qfeed){- // open the actual backing file
- // don't double open if already open though.
- }
respond(r, nil);
}
@@ -222,6 +217,7 @@
return;
case Qtitle:
if(f->cl->current){+ memset(buf, 0, sizeof(buf));
snprint(buf, sizeof(buf), "%s", f->cl->current->title);
readstr(r, buf);
respond(r, nil);
@@ -231,8 +227,12 @@
//case Qstatus:
//case Qaside:
//case Qnotify:
- //case Qfeed:
- // return a pread with our offset on our open fid
+ case Qfeed:
+ memset(buf, 0, sizeof(buf));
+ pread(f->cl->fd, buf, sizeof(buf), f->cl->offset);
+ readstr(r, buf);
+ respond(r, nil);
+ return;
}
respond(r, "not implemented");
}
@@ -241,7 +241,7 @@
clwrite(Req *r)
{Clfid *f;
- char *s, *t;
+ char *s, *t, path[1024];
int n;
f = r->fid->aux;
@@ -253,7 +253,13 @@
t = strtok(s, " ");
s = strtok(nil, "\n");
if(strcmp(t, "buffer") == 0){+ if(f->cl->fd)
+ close(f->cl->fd);
f->cl->current = bufferSearch(root, s);
+ memset(path, sizeof(path), 0);
+ snprint(path, sizeof(path), "%s/%s/%s", logdir, root->name, s);
+ f->cl->fd = open(path, OREAD);
+ f->cl->offset = 0;
r->fid->aux = f;
respond(r, nil);
} else
@@ -297,7 +303,6 @@
clstart(Srv *s)
{root = emalloc(sizeof(*root));
- USED(root);
root = (Buffer*)s->aux;
time0 = time(0);
}
--- a/service.c
+++ b/service.c
@@ -129,6 +129,7 @@
d->mode |= DMDIR | 0111;
switch(level){case Qservices:
+ memset(buf, 0, sizeof(buf));
snprint(buf, sizeof(buf), "%d", SERVICEID(aux));
d->name = estrdup(buf);
break;
@@ -291,6 +292,7 @@
respond(r, nil);
return;
case Qctl:
+ memset(buf, 0, sizeof(buf));
snprint(buf, sizeof(buf), "%d\n", SERVICEID(f->svc));
readstr(r, buf);
respond(r, nil);
@@ -302,7 +304,7 @@
static char*
svcctl(Service *svc, char *s, char *data)
{- // Hashing the buffername would be nice
+ // Probably notifications as well?
Buffer *b;
char *cmd, *targ;
@@ -309,7 +311,12 @@
cmd = strtok(s, " ");
targ = strtok(nil, "\n");
if(strcmp(cmd, "feed")==0) {- // Updoot teh feedfile
+ if(b = bufferSearch(svc->base, targ)) {+ seek(b->fd, 0, 2);
+ write(b->fd, data, strlen(data));
+ return nil;
+ }
+ return "buffer not found";
} else if(strcmp(cmd, "status")==0){ if(b = bufferSearch(svc->base, targ)) {b->status = data;
@@ -322,6 +329,18 @@
return nil;
}
return "buffer not found";
+ } else if(strcmp(cmd, "status")==0){+ if(b = bufferSearch(svc->base, targ)) {+ b->status = data;
+ return nil;
+ }
+ return "buffer not found";
+ } else if(strcmp(cmd, "aside")==0){+ if(b = bufferSearch(svc->base, targ)) {+ b->aside = data;
+ return nil;
+ }
+ return "buffer not found";
} else if(strcmp(cmd, "create")==0)
return bufferPush(svc->base, targ);
else if(strcmp(cmd, "close")==0)
@@ -329,7 +348,6 @@
else
// snprintf not found: %s cmd
return "command not found";
- return nil;
}
void
@@ -338,6 +356,7 @@
int n;
char *s, *t;
Svcfid *f;
+ char path[1024];
f = r->fid->aux;
@@ -357,7 +376,12 @@
t = svcctl(f->svc, s, t);
respond(r, t);
} else {+ // Set a short limit on this probably
f->svc->name = estrdup(s);
+ f->svc->base->name = estrdup(s);
+ memset(path, 0, sizeof(path));
+ snprint(path, sizeof(path), "%s/%s", logdir, s);
+ close(create(path, OREAD, DMDIR | 0755));
clfs.aux = f->svc->base;
f->svc->childpid = threadpostsrv(&clfs, s);
if(f->svc->childpid >= 0){--
⑨