#include <u.h>
#include <libc.h>
#include <auth.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include "ncp.h"
struct {
char *name;
int (*func)(Fmt *f);
char *buf;
int len;
} Infdir[] = {
{ "Who" , who },
{ "Users" , users },
{ "Groups" , groups },
{ "Session" , session },
{ "Servers" , servers },
{ "Printers" , printers },
{ "Bindery" , bindery },
{ "Whoami" , whoami },
{ "Volumes" , volumes },
{ "Ping" , ping },
};
int
walkinfo(char *name)
{
int i;
for (i = 0; i < nelem(Infdir); i++)
if (strcmp(Infdir[i].name, name) == 0)
return(i);
return(-1);
}
int
numinfo(void)
{
return nelem(Infdir);
}
int
dirgeninfo(int slot, Dir *d)
{
if (slot >= nelem(Infdir))
return -1;
memset(d, 0, sizeof(Dir));
d->type = 'N';
d->dev = 99;
d->name = estrdup9p(Infdir[slot].name);
d->uid = estrdup9p("supervisor");
d->muid = estrdup9p("supervisor");
d->gid = estrdup9p("none");
d->mode = 0666;
d->qid.vers = Vinfo;
d->qid.path = slot;
d->qid.type = 0;
return 0;
}
int
makeinfo(int path)
{
Fmt f;
if (Infdir[path].buf != nil)
return 0;
fmtstrinit(&f);
if ((*Infdir[path].func)(&f) == -1l)
return -1;
Infdir[path].buf = fmtstrflush(&f);
Infdir[path].len = strlen(Infdir[path].buf);
return 0;
}
int
readinfo(int path, char *buf, int len, int off)
{
if (off > Infdir[path].len)
return 0;
if (len + off > Infdir[path].len)
len = Infdir[path].len - off;
memmove(buf, Infdir[path].buf + off, len);
return len;
}
void
freeinfo(int path)
{
free(Infdir[path].buf);
Infdir[path].buf = nil;
}
|