wmii/cmd/wm/fs.c

1621 lines
43 KiB
C
Raw Normal View History

/*
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <sys/socket.h>
2006-01-31 15:25:23 +03:00
#include "wm.h"
static char E9pversion[] = "9P version not supported";
static char Enoperm[] = "permission denied";
static char Enofile[] = "file not found";
static char Efidinuse[] = "fid in use";
static char Enomode[] = "mode not supported";
static char Enofunc[] = "function not supported";
static char Enocommand[] = "command not supported";
static char Ebadvalue[] = "bad value";
2006-04-06 09:55:33 +04:00
enum { WMII_IOUNIT = 2048 };
/*
* filesystem specification
2006-05-01 21:39:26 +04:00
* / FsDroot
* /def/ FsDdef
* /def/border FsFborder 0..n
* /def/font FsFfont xlib font name
* /def/selcolors FsFselcolors selected colors
* /def/normcolors FsFnormcolors normal colors
2006-05-01 21:39:26 +04:00
* /def/rules FsFrules rules
* /def/keys FsFkeys keys
* /def/grabmod FsFgrabmod grab modifier
* /def/colmode FsFmode column mode
* /def/colwidth FsFcolw column width
* /tags FsFtags
* /bar/ FsDbars
* /bar/lab/ FsDbar
2006-05-01 21:39:26 +04:00
* /bar/lab/data FsFdata <arbitrary data which gets displayed>
* /bar/lab/colors FsFcolors <#RRGGBB> <#RRGGBB> <#RRGGBB>
* /client/ FsDclients
* /client/1/ FsDGclient see /view/X/X/X/ namespace below
* /event FsFevent
* /ctl FsFctl command interface (root)
* /view/ FsDview
* /view/ FsDview
* /view/ctl FsFctl command interface (tag)
* /view/name FsFname current view name
* /view/sel/ FsDarea
2006-05-01 21:39:26 +04:00
* /view/1/ FsDarea
* /view/1/ctl FsFctl command interface (area)
* /view/1/mode FsFmode column mode
* /view/1/sel/ FsDclient
2006-05-01 21:39:26 +04:00
* /view/1/1/class FsFclass Class:instance of client
* /view/1/1/index FsFindex index of client in /client
* /view/1/1/name FsFname name of client
* /view/1/1/tags FsFtags tag of client
* /view/1/geom FsFgeom geometry of client
* /view/1/ctl FsFctl command interface (client)
*/
2006-02-06 17:20:25 +03:00
Qid root_qid;
const char *err;
/* IXP stuff */
2006-03-23 18:07:18 +03:00
/*
* Qid->path is calculated related to the index of the associated structure.
2006-04-13 18:52:33 +04:00
* i1 is associated to tag, key, global client, or bar
* i2 is associated to area
* i3 is associated to client
* ie /view/sel/ctl is i1id = sel tag id, i2id = sel area id , i3id = 0 (no id)
*/
2006-02-02 16:50:04 +03:00
unsigned long long
2006-05-01 21:39:26 +04:00
pack_qpath(unsigned char type, unsigned short i1id, unsigned short i2id, unsigned short i3id)
{
2006-03-23 18:07:18 +03:00
return ((unsigned long long) type << 48) | ((unsigned long long) i1id << 32)
| ((unsigned long long) i2id << 16) | (unsigned long long) i3id;
}
static unsigned char
2006-05-01 21:39:26 +04:00
unpack_type(unsigned long long path)
{
2006-03-23 18:07:18 +03:00
return (path >> 48) & 0xff;
}
2006-01-31 15:25:23 +03:00
static unsigned short
2006-05-01 21:39:26 +04:00
unpack_i1id(unsigned long long path)
2006-01-31 15:25:23 +03:00
{
2006-03-23 18:07:18 +03:00
return (path >> 32) & 0xffff;
2006-01-31 15:25:23 +03:00
}
static unsigned short
2006-05-01 21:39:26 +04:00
unpack_i2id(unsigned long long path)
2006-01-31 01:48:41 +03:00
{
2006-03-23 18:07:18 +03:00
return (path >> 16) & 0xffff;
2006-01-31 01:48:41 +03:00
}
static unsigned short
2006-05-01 21:39:26 +04:00
unpack_i3id(unsigned long long path)
{
2006-03-23 18:07:18 +03:00
return path & 0xffff;
}
2006-05-01 21:39:26 +04:00
static unsigned char
dir_of_qid(Qid wqid[IXP_MAX_WELEM], unsigned short qsel)
{
return qsel ? unpack_type(wqid[qsel - 1].path) : FsDroot;
}
static void
2006-05-01 21:39:26 +04:00
unpack_qpath(Qid wqid[IXP_MAX_WELEM], unsigned short qsel,
unsigned char *type, int *i1, int *i2, int *i3)
{
2006-05-01 21:39:26 +04:00
unsigned short i1id = unpack_i1id(wqid[qsel].path);
unsigned short i2id = unpack_i2id(wqid[qsel].path);
unsigned short i3id = unpack_i3id(wqid[qsel].path);
*type = unpack_type(wqid[qsel].path);
if(i1id) {
2006-05-01 21:39:26 +04:00
unsigned char dir_type = dir_of_qid(wqid, qsel);
if((dir_type == FsDGclient) || (dir_type == FsDclients))
2006-04-12 12:44:07 +04:00
*i1 = idx_of_client_id(i1id);
2006-03-07 19:22:36 +03:00
else {
switch(*type) {
2006-05-01 21:39:26 +04:00
case FsFdata:
case FsFcolors:
case FsDbar: *i1 = idx_of_bar_id(i1id); break;
default: *i1 = idx_of_view_id(i1id); break;
2006-03-07 19:22:36 +03:00
}
}
if(i2id && (*i1 != -1)) {
2006-04-12 12:44:07 +04:00
*i2 = idx_of_area_id(view.data[*i1], i2id);
if(i3id && (*i2 != -1))
2006-04-12 12:44:07 +04:00
*i3 = idx_of_frame_id(view.data[*i1]->area.data[*i2], i3id);
}
}
}
static char *
2006-05-01 21:39:26 +04:00
name_of_qid(Qid wqid[IXP_MAX_WELEM], unsigned short qsel)
{
2006-05-01 21:39:26 +04:00
unsigned char dir_type, type;
int i1 = -1, i2 = -1, i3 = -1;
static char buf[256];
2006-05-01 21:39:26 +04:00
unpack_qpath(wqid, qsel, &type, &i1, &i2, &i3);
dir_type = dir_of_qid(wqid, qsel);
2006-02-03 20:11:22 +03:00
switch(type) {
2006-03-23 18:07:18 +03:00
case FsDroot: return "/"; break;
case FsDdef: return "def"; break;
case FsDclients: return "client"; break;
case FsDbars: return "bar"; break;
2006-03-23 18:07:18 +03:00
case FsDview:
2006-05-01 21:39:26 +04:00
if(dir_type != FsDroot)
return nil;
if(i1 == sel)
return "view";
return view.data[i1]->name;
2006-03-23 18:07:18 +03:00
break;
case FsDbar:
2006-03-23 18:07:18 +03:00
if(i1 == -1)
return nil;
2006-04-13 18:52:33 +04:00
return bar.data[i1]->name;
2006-03-23 18:07:18 +03:00
break;
case FsDarea:
if(i1 == -1 || i2 == -1)
return nil;
if(view.data[i1]->sel == i2)
2006-03-23 18:07:18 +03:00
return "sel";
snprintf(buf, sizeof(buf), "%u", i2);
return buf;
break;
case FsDGclient:
if(i1 == -1)
return nil;
snprintf(buf, sizeof(buf), "%u", i1);
return buf;
break;
case FsDclient:
if(i1 == -1 || i2 == -1 || i3 == -1)
return nil;
if(view.data[i1]->area.data[i2]->sel == i3)
2006-03-23 18:07:18 +03:00
return "sel";
snprintf(buf, sizeof(buf), "%u", i3);
return buf;
break;
case FsFselcolors: return "selcolors"; break;
case FsFnormcolors: return "normcolors"; break;
case FsFfont: return "font"; break;
case FsFcolw: return "colwidth"; break;
case FsFgrabmod: return "grabmod"; break;
2006-03-23 18:07:18 +03:00
case FsFrules: return "rules"; break;
case FsFkeys: return "keys"; break;
case FsFcolors: return "colors"; break;
case FsFdata:
if(i1 == -1)
return nil;
return "data";
break;
case FsFctl: return "ctl"; break;
case FsFborder: return "border"; break;
case FsFgeom:
2006-05-01 21:39:26 +04:00
if((dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
2006-03-23 18:07:18 +03:00
return nil;
else if(i1 == -1)
return nil;
return "geom";
break;
case FsFtags:
2006-05-01 21:39:26 +04:00
if((dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
return nil;
2006-05-01 21:39:26 +04:00
else if((dir_type == FsDGclient) && (i1 == -1))
return nil;
return "tags";
break;
2006-03-23 18:07:18 +03:00
case FsFclass:
case FsFindex:
2006-03-23 18:07:18 +03:00
case FsFname:
2006-05-01 21:39:26 +04:00
if((dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
2006-03-23 18:07:18 +03:00
return nil;
else if(i1 == -1)
return nil;
switch(type) {
case FsFname:
2006-03-23 18:07:18 +03:00
return "name";
break;
case FsFclass:
return "class";
break;
case FsFindex:
return "index";
break;
default:
break;
}
2006-03-23 18:07:18 +03:00
break;
case FsFmode:
2006-05-01 21:39:26 +04:00
if((dir_type == FsDarea) && (i1 == -1 || i2 == -1))
return nil;
2006-05-01 21:39:26 +04:00
if(dir_type == FsDdef)
return "colmode";
else
return "mode";
2006-03-23 18:07:18 +03:00
break;
case FsFevent: return "event"; break;
default: return nil; break;
}
return nil;
}
static unsigned char
2006-05-01 21:39:26 +04:00
type_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
{
2006-05-01 21:39:26 +04:00
unsigned char dir_type;
int i1 = -1, i2 = -1, i3 = -1;
2006-03-23 18:07:18 +03:00
unsigned int i;
2006-05-01 21:39:26 +04:00
unpack_qpath(wqid, qsel, &dir_type, &i1, &i2, &i3);
if(!name || !name[0] || !strncmp(name, "/", 2))
2006-03-05 16:16:48 +03:00
return FsDroot;
if(!strncmp(name, "tags", 5))
return FsFtags;
if(!strncmp(name, "client", 7))
2006-03-07 19:22:36 +03:00
return FsDclients;
if(!strncmp(name, "view", 5))
return FsDview;
if(!strncmp(name, "bar", 4))
return FsDbars;
if(!strncmp(name, "def", 4))
2006-03-05 16:16:48 +03:00
return FsDdef;
if(!strncmp(name, "ctl", 4))
2006-03-05 16:16:48 +03:00
return FsFctl;
if(!strncmp(name, "event", 6))
2006-03-05 16:16:48 +03:00
return FsFevent;
if(!strncmp(name, "class", 6))
2006-03-10 13:59:26 +03:00
return FsFclass;
if(!strncmp(name, "index", 6))
return FsFindex;
2006-01-31 11:27:54 +03:00
if(!strncmp(name, "name", 5))
2006-03-05 16:16:48 +03:00
return FsFname;
2006-01-31 11:27:54 +03:00
if(!strncmp(name, "border", 7))
2006-03-05 16:16:48 +03:00
return FsFborder;
if(!strncmp(name, "geom", 5))
2006-03-05 16:16:48 +03:00
return FsFgeom;
if(!strncmp(name, "colors", 7))
2006-03-05 16:16:48 +03:00
return FsFcolors;
if(!strncmp(name, "selcolors", 10))
2006-03-05 16:16:48 +03:00
return FsFselcolors;
if(!strncmp(name, "normcolors", 11))
2006-03-05 16:16:48 +03:00
return FsFnormcolors;
2006-03-10 16:55:44 +03:00
if(!strncmp(name, "font", 5))
return FsFfont;
if(!strncmp(name, "colwidth", 9))
return FsFcolw;
if(!strncmp(name, "grabmod", 8))
return FsFgrabmod;
if(!strncmp(name, "keys", 5))
return FsFkeys;
2006-03-10 16:39:46 +03:00
if(!strncmp(name, "rules", 6))
return FsFrules;
if(!strncmp(name, "data", 5))
2006-03-05 16:16:48 +03:00
return FsFdata;
if(!strncmp(name, "mode", 5) || !strncmp(name, "colmode", 8))
2006-03-05 16:16:48 +03:00
return FsFmode;
if((dir_type == FsDbars) && bar_of_name(name))
return FsDbar;
if((dir_type == FsDroot) && view_of_name(name))
return FsDview;
if(!strncmp(name, "sel", 4))
2006-01-31 19:52:14 +03:00
goto dyndir;
2006-03-23 18:07:18 +03:00
i = (unsigned short) cext_strtonum(name, 0, 0xffff, &err);
if(err)
return FsLast;
2006-01-31 19:52:14 +03:00
dyndir:
switch(dir_type) {
case FsDbars: return FsDbar; break;
case FsDview: return FsDarea; break;
2006-03-07 19:22:36 +03:00
case FsDclients: return FsDGclient; break;
2006-03-05 16:16:48 +03:00
case FsDarea: return FsDclient; break;
2006-01-31 11:27:54 +03:00
}
return FsLast;
}
2006-05-01 21:39:26 +04:00
static Qid *
qid_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name)
{
2006-05-01 21:39:26 +04:00
int i1 = -1, i2 = -1, i3 = -1, i;
unsigned char dir_type, type;
static Qid new;
2006-05-01 21:39:26 +04:00
unpack_qpath(wqid, qsel, &dir_type, &i1, &i2, &i3);
type = type_of_name(wqid, qsel, name);
switch(type) {
2006-03-05 16:16:48 +03:00
case FsDroot:
2006-05-01 21:39:26 +04:00
new = root_qid;
break;
2006-03-05 16:16:48 +03:00
case FsDdef:
2006-03-07 19:22:36 +03:00
case FsDclients:
case FsDbars:
if(dir_type != FsDroot)
2006-05-01 21:39:26 +04:00
return nil;
new.type = IXP_QTDIR;
new.path = pack_qpath(type, 0, 0, 0);
break;
case FsDview:
if(dir_type != FsDroot || !view.size)
2006-05-01 21:39:26 +04:00
return nil;
new.type = IXP_QTDIR;
if(!strncmp(name, "view", 5))
new.path = pack_qpath(FsDview, view.data[sel]->id, 0, 0);
else {
View *v;
2006-05-01 21:39:26 +04:00
if(!(v = view_of_name(name)))
return nil;
new.path = pack_qpath(FsDview, v->id, 0, 0);
}
break;
2006-03-05 16:16:48 +03:00
case FsDarea:
2006-05-01 21:39:26 +04:00
if(i1 == -1 || dir_type != FsDview)
return nil;
{
2006-05-01 21:39:26 +04:00
View *p = view.data[i1];
new.type = IXP_QTDIR;
if(!strncmp(name, "sel", 4)) {
new.path = pack_qpath(FsDarea, p->id, p->area.data[p->sel]->id, 0);
2006-02-16 13:53:10 +03:00
}
else {
2006-05-01 21:39:26 +04:00
i = cext_strtonum(name, 0, 0xffff, &err);
if(err || (i >= p->area.size))
2006-05-01 21:39:26 +04:00
return nil;
new.path = pack_qpath(FsDarea, p->id, p->area.data[i]->id, 0);
}
2006-01-31 19:52:14 +03:00
}
2006-01-31 15:25:23 +03:00
break;
2006-03-05 16:16:48 +03:00
case FsDclient:
2006-05-01 21:39:26 +04:00
if(i1 == -1 || i2 == -1 || dir_type != FsDarea)
return nil;
{
2006-05-01 21:39:26 +04:00
View *p = view.data[i1];
Area *a = p->area.data[i2];
new.type = IXP_QTDIR;
if(!strncmp(name, "sel", 4)) {
if(!a->frame.size)
2006-05-01 21:39:26 +04:00
return nil;
new.path = pack_qpath(FsDclient, p->id, a->id, a->frame.data[a->sel]->id);
}
else {
2006-05-01 21:39:26 +04:00
i = cext_strtonum(name, 0, 0xffff, &err);
if(err || (i >= a->frame.size))
2006-05-01 21:39:26 +04:00
return nil;
new.path = pack_qpath(FsDclient, p->id, a->id, a->frame.data[i]->id);
}
2006-01-31 19:52:14 +03:00
}
2006-01-31 15:25:23 +03:00
break;
2006-03-07 19:22:36 +03:00
case FsDGclient:
if(dir_type != FsDclients)
2006-05-01 21:39:26 +04:00
return nil;
i = cext_strtonum(name, 0, 0xffff, &err);
if(err || (i >= client.size))
2006-05-01 21:39:26 +04:00
return nil;
new.path = pack_qpath(FsDGclient, client.data[i]->id, 0, 0);
2006-03-07 19:22:36 +03:00
break;
case FsDbar:
if(dir_type != FsDbars)
2006-05-01 21:39:26 +04:00
return nil;
2006-03-09 04:15:43 +03:00
{
2006-04-12 12:44:07 +04:00
Bar *l;
2006-05-01 21:39:26 +04:00
if(!(l = bar_of_name(name)))
return nil;
new.type = IXP_QTDIR;
new.path = pack_qpath(FsDbar, l->id, 0, 0);
2006-03-09 04:15:43 +03:00
}
break;
2006-03-05 16:16:48 +03:00
case FsFdata:
case FsFcolors:
2006-05-01 21:39:26 +04:00
if((i1 == -1) || (dir_type != FsDbar))
return nil;
2006-03-22 21:57:18 +03:00
goto Mkfile;
break;
case FsFmode:
2006-05-01 21:39:26 +04:00
if((dir_type == FsDarea) && (i1 == -1 || i2 == -1))
return nil;
2006-03-22 21:57:18 +03:00
goto Mkfile;
break;
case FsFgeom:
case FsFname:
case FsFindex:
2006-03-10 13:59:26 +03:00
case FsFclass:
2006-03-21 20:14:50 +03:00
if(dir_type == FsDroot)
2006-05-01 21:39:26 +04:00
return nil;
case FsFtags:
2006-05-01 21:39:26 +04:00
if((dir_type != FsDroot) && (dir_type != FsDview)
&& (dir_type != FsDGclient) && (dir_type != FsDclient))
return nil;
if((dir_type == FsDclient) && ((i1 == -1 || i2 == -1 || i3 == -1)))
return nil;
else if((dir_type == FsDGclient) && (i1 == -1))
return nil;
2006-03-22 21:57:18 +03:00
goto Mkfile;
break;
2006-03-10 16:55:44 +03:00
case FsFborder:
case FsFgrabmod:
2006-03-10 16:55:44 +03:00
case FsFfont:
case FsFcolw:
2006-03-10 16:55:44 +03:00
case FsFrules:
case FsFselcolors:
case FsFnormcolors:
case FsFkeys:
2006-03-23 18:07:18 +03:00
if(dir_type != FsDdef)
2006-05-01 21:39:26 +04:00
return nil;
case FsFctl:
case FsFevent:
2006-03-22 21:57:18 +03:00
Mkfile:
2006-05-01 21:39:26 +04:00
new.type = IXP_QTFILE;
new.path = pack_qpath(type, unpack_i1id(wqid[qsel].path), unpack_i2id(wqid[qsel].path),
unpack_i3id(wqid[qsel].path));
break;
default:
2006-05-01 21:39:26 +04:00
return nil;
break;
}
2006-05-01 21:39:26 +04:00
return &new;
}
static unsigned int
2006-05-01 21:39:26 +04:00
pack_stat(Stat *stat, Qid wqid[IXP_MAX_WELEM], unsigned short qsel,
char *name, unsigned long long length, unsigned int mode)
{
2006-05-01 21:39:26 +04:00
Qid *qid;
2006-03-23 18:07:18 +03:00
stat->mode = mode;
stat->atime = stat->mtime = time(0);
cext_strlcpy(stat->uid, getenv("USER"), sizeof(stat->uid));
cext_strlcpy(stat->gid, getenv("USER"), sizeof(stat->gid));
cext_strlcpy(stat->muid, getenv("USER"), sizeof(stat->muid));
2006-03-23 18:07:18 +03:00
cext_strlcpy(stat->name, name, sizeof(stat->name));
stat->length = length;
2006-05-01 21:39:26 +04:00
if((qid = qid_of_name(wqid, qsel ? qsel - 1 : 0, name)))
stat->qid = *qid;
return ixp_sizeof_stat(stat);
}
static unsigned int
2006-05-01 21:39:26 +04:00
stat_of_name(Stat *stat, char *name, Qid wqid[IXP_MAX_WELEM], unsigned short qsel)
{
unsigned char dir_type, type;
2006-05-01 21:39:26 +04:00
int i1 = 0, i2 = 0, i3 = 0;
char buf[256];
Frame *f;
2006-05-01 21:39:26 +04:00
unpack_qpath(wqid, qsel, &dir_type, &i1, &i2, &i3);
if((i1 == -1) || (i2 == -1) || (i3 == -1))
return 0;
2006-05-01 21:39:26 +04:00
type = type_of_name(wqid, qsel, name);
2006-02-03 22:02:37 +03:00
2006-03-23 18:07:18 +03:00
switch (type) {
case FsDclient:
case FsDGclient:
case FsDarea:
case FsDview:
case FsDdef:
2006-03-07 19:22:36 +03:00
case FsDclients:
case FsDbar:
2006-03-23 18:07:18 +03:00
case FsDroot:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, 0, IXP_DMDIR | IXP_DMREAD | IXP_DMEXEC);
2006-03-23 18:07:18 +03:00
break;
case FsDbars:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, 0, IXP_DMDIR | IXP_DMREAD | IXP_DMWRITE | IXP_DMEXEC);
2006-03-23 18:07:18 +03:00
break;
2006-03-05 16:16:48 +03:00
case FsFctl:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, 0, IXP_DMWRITE);
2006-03-07 19:22:36 +03:00
break;
2006-03-23 18:07:18 +03:00
case FsFevent:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, 0, IXP_DMREAD | IXP_DMWRITE);
break;
2006-03-23 18:07:18 +03:00
case FsFborder:
snprintf(buf, sizeof(buf), "%d", def.border);
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
2006-03-23 18:07:18 +03:00
break;
case FsFgeom:
2006-03-07 19:22:36 +03:00
if(dir_type == FsDclient) {
2006-05-01 21:39:26 +04:00
f = view.data[i1]->area.data[i2]->frame.data[i3];
2006-03-07 19:22:36 +03:00
snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y,
f->rect.width, f->rect.height);
}
else {
2006-05-01 21:39:26 +04:00
Client *c = client.data[i1];
2006-03-07 19:22:36 +03:00
snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y,
c->rect.width, c->rect.height);
}
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
2006-03-23 18:07:18 +03:00
break;
case FsFclass:
2006-03-10 13:59:26 +03:00
if(dir_type == FsDclient) {
2006-05-01 21:39:26 +04:00
f = view.data[i1]->area.data[i2]->frame.data[i3];
return pack_stat(stat, wqid, qsel, name, strlen(f->client->classinst), IXP_DMREAD);
2006-03-10 13:59:26 +03:00
}
2006-03-23 18:07:18 +03:00
else
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(client.data[i1]->classinst), IXP_DMREAD);
2006-03-23 18:07:18 +03:00
break;
case FsFindex:
if(dir_type == FsDclient) {
2006-05-01 21:39:26 +04:00
f = view.data[i1]->area.data[i2]->frame.data[i3];
snprintf(buf, sizeof(buf), "%d", idx_of_client_id(f->client->id));
}
else
2006-05-01 21:39:26 +04:00
snprintf(buf, sizeof(buf), "%d", i1);
return pack_stat(stat, wqid, qsel, name, strlen(buf), IXP_DMREAD);
break;
2006-03-23 18:07:18 +03:00
case FsFname:
2006-03-07 19:22:36 +03:00
if(dir_type == FsDclient) {
2006-05-01 21:39:26 +04:00
f = view.data[i1]->area.data[i2]->frame.data[i3];
return pack_stat(stat, wqid, qsel, name, strlen(f->client->name), IXP_DMREAD);
2006-03-07 19:22:36 +03:00
}
else if(dir_type == FsDview)
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name,
view.size ? strlen(view.data[i1]->name) : 0, IXP_DMREAD);
2006-03-23 18:07:18 +03:00
else
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(client.data[i1]->name), IXP_DMREAD);
2006-03-23 18:07:18 +03:00
break;
case FsFtags:
switch(dir_type) {
case FsDclient:
2006-05-01 21:39:26 +04:00
f = view.data[i1]->area.data[i2]->frame.data[i3];
return pack_stat(stat, wqid, qsel, name, strlen(f->client->tags), IXP_DMREAD | IXP_DMWRITE);
break;
case FsDGclient:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel,
name, strlen(client.data[i1]->tags), IXP_DMREAD | IXP_DMWRITE);
break;
default:
{
unsigned int i, len = 0;
for(i = 0; i < view.size; i++)
len += strlen(view.data[i]->name) + 1;
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, len, IXP_DMREAD);
}
break;
}
break;
2006-03-23 18:07:18 +03:00
case FsFdata:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name,
(i1 == bar.size) ? 0 : strlen(bar.data[i1]->data), IXP_DMREAD | IXP_DMWRITE);
2006-03-23 18:07:18 +03:00
break;
case FsFmode:
{
int i;
if(dir_type == FsDarea)
2006-05-01 21:39:26 +04:00
i = view.data[i1]->area.data[i2]->mode;
else
i = def.colmode;
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name,
strlen(str_of_column_mode(i)), IXP_DMREAD | IXP_DMWRITE);
}
2006-03-23 18:07:18 +03:00
break;
case FsFcolors:
case FsFselcolors:
case FsFnormcolors:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, 23, IXP_DMREAD | IXP_DMWRITE);
2006-03-10 16:55:44 +03:00
break;
2006-03-23 18:07:18 +03:00
case FsFkeys:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, def.keys ? strlen(def.keys) : 0, IXP_DMREAD | IXP_DMWRITE);
break;
2006-03-23 18:07:18 +03:00
case FsFrules:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, def.rules ? strlen(def.rules) : 0, IXP_DMREAD | IXP_DMWRITE);
2006-03-10 16:39:46 +03:00
break;
case FsFcolw:
snprintf(buf, sizeof(buf), "%d", def.colw);
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(buf), IXP_DMREAD | IXP_DMWRITE);
2006-03-23 18:07:18 +03:00
case FsFfont:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(def.font), IXP_DMREAD | IXP_DMWRITE);
case FsFgrabmod:
2006-05-01 21:39:26 +04:00
return pack_stat(stat, wqid, qsel, name, strlen(def.grabmod), IXP_DMREAD | IXP_DMWRITE);
break;
2006-03-23 18:07:18 +03:00
}
return 0;
}
static char *
xversion(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
if(strncmp(fcall->version, IXP_VERSION, strlen(IXP_VERSION)))
return E9pversion;
else if(fcall->maxmsg > IXP_MAX_MSG)
fcall->maxmsg = IXP_MAX_MSG;
fcall->id = RVERSION;
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
static char *
xattach(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *new = cext_emallocz(sizeof(IXPMap));
cext_vattach(ixp_vector_of_maps(&c->map), new);
2006-05-01 21:39:26 +04:00
new->wqid[0] = root_qid;
new->nwqid = 1;
2006-03-23 18:07:18 +03:00
new->fid = fcall->fid;
fcall->id = RATTACH;
fcall->qid = new->wqid[new->sel];
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
static char *
xwalk(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *m;
unsigned int qsel, nwqid;
Qid wqid[IXP_MAX_WELEM], *qid;
2006-03-23 18:07:18 +03:00
if(!(m = ixp_server_fid2map(c, fcall->fid)))
return Enofile;
if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid)))
return Efidinuse;
2006-05-01 21:39:26 +04:00
for(qsel = 0; qsel < m->nwqid; qsel++)
wqid[qsel] = m->wqid[qsel];
if(qsel)
qsel--;
2006-05-01 21:39:26 +04:00
for(nwqid = 0; nwqid < fcall->nwname; nwqid++) {
if(qsel >= IXP_MAX_WELEM)
2006-05-01 21:39:26 +04:00
break;
if(!strncmp(fcall->wname[nwqid], "..", 3)) {
if(qsel)
qsel--;
qid = &wqid[qsel];
}
else {
qid = qid_of_name(wqid, qsel, fcall->wname[nwqid]);
if(!qid)
break;
qsel++;
}
fcall->wqid[nwqid] = wqid[qsel] = *qid;
2006-03-23 18:07:18 +03:00
}
2006-05-01 21:39:26 +04:00
if(fcall->nwname && !nwqid)
return Enofile;
2006-03-23 18:07:18 +03:00
/* a fid will only be valid, if the walk was complete */
if(nwqid == fcall->nwname) {
unsigned int i;
2006-03-23 18:07:18 +03:00
if(fcall->fid != fcall->newfid) {
m = cext_emallocz(sizeof(IXPMap));
2006-04-13 17:35:10 +04:00
cext_vattach(ixp_vector_of_maps(&c->map), m);
2006-03-23 18:07:18 +03:00
}
for(i = 0; i <= qsel; i++)
2006-05-01 21:39:26 +04:00
m->wqid[i] = wqid[i];
m->nwqid = qsel + 1;
m->sel = qsel;
2006-03-23 18:07:18 +03:00
m->fid = fcall->newfid;
}
fcall->id = RWALK;
fcall->nwqid = nwqid;
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
static char *
xcreate(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
2006-05-01 21:39:26 +04:00
Qid *qid;
unsigned char type;
2006-03-23 18:07:18 +03:00
if(!(fcall->mode | IXP_OWRITE))
return Enomode;
if(!m)
return Enofile;
if(!strncmp(fcall->name, ".", 2) || !strncmp(fcall->name, "..", 3))
return "illegal file name";
2006-05-01 21:39:26 +04:00
type = unpack_type(m->wqid[m->sel].path);
switch(type) {
case FsDbars:
2006-04-12 12:44:07 +04:00
create_bar(fcall->name, False);
2006-03-09 04:15:43 +03:00
break;
default:
return Enofile;
break;
}
2006-05-01 21:39:26 +04:00
if(!(qid = qid_of_name(m->wqid, m->sel, fcall->name)))
return Enofile;
m->wqid[m->nwqid++] = fcall->qid = *qid;
m->sel++;
fcall->id = RCREATE;
fcall->iounit = WMII_IOUNIT;
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
static char *
xopen(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
2006-03-23 18:07:18 +03:00
if(!m)
return Enofile;
if(!(fcall->mode | IXP_OREAD) && !(fcall->mode | IXP_OWRITE))
return Enomode;
fcall->id = ROPEN;
2006-05-01 21:39:26 +04:00
fcall->qid = m->wqid[m->sel];
2006-03-23 18:07:18 +03:00
fcall->iounit = WMII_IOUNIT;
ixp_server_respond_fcall(c, fcall);
2006-05-01 21:39:26 +04:00
2006-03-23 18:07:18 +03:00
return nil;
}
static char *
xremove(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
unsigned char type;
int i1 = 0, i2 = 0, i3 = 0;
2006-03-23 18:07:18 +03:00
if(!m)
return Enofile;
2006-05-01 21:39:26 +04:00
unpack_qpath(m->wqid, m->sel, &type, &i1, &i2, &i3);
if((i1 == -1) || (i2 == -1) || (i3 == -1))
return Enofile;
if(type != FsDbar)
2006-03-09 04:15:43 +03:00
return Enoperm;
/* clunk */
2006-04-13 17:35:10 +04:00
cext_vdetach(ixp_vector_of_maps(&c->map), m);
2006-03-09 04:15:43 +03:00
free(m);
switch(type) {
case FsDbar:
{
2006-05-02 02:00:16 +04:00
Bar *b = bar.data[i1];
if(b->intern)
return Enoperm;
2006-04-13 18:52:33 +04:00
/* now detach the bar */
2006-05-02 02:00:16 +04:00
destroy_bar(b);
draw_bar();
}
break;
default:
break;
}
2006-03-23 18:07:18 +03:00
fcall->id = RREMOVE;
ixp_server_respond_fcall(c, fcall);
return nil;
}
2006-02-03 20:11:22 +03:00
static char *
xread(IXPConn *c, Fcall *fcall)
{
Stat stat;
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
2006-05-01 21:39:26 +04:00
int i1 = 0, i2 = 0, i3 = 0;
2006-01-31 21:57:14 +03:00
unsigned int i, len;
2006-05-01 21:39:26 +04:00
unsigned char dir_type, type, *p = fcall->data;
char buf[256];
Frame *f;
2006-03-23 18:07:18 +03:00
if(!m)
return Enofile;
2006-05-01 21:39:26 +04:00
unpack_qpath(m->wqid, m->sel, &type, &i1, &i2, &i3);
if((i1 == -1) || (i2 == -1) || (i3 == -1))
2006-02-03 20:11:22 +03:00
return Enofile;
2006-05-01 21:39:26 +04:00
dir_type = dir_of_qid(m->wqid, m->sel);
2006-02-03 20:11:22 +03:00
fcall->count = 0;
if(fcall->offset) {
switch (type) {
case FsDroot:
/* jump to offset */
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, "ctl", m->wqid, m->sel);
len += stat_of_name(&stat, "event", m->wqid, m->sel);
len += stat_of_name(&stat, "def", m->wqid, m->sel);
len += stat_of_name(&stat, "bar", m->wqid, m->sel);
if(client.size)
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, "client", m->wqid, m->sel);
if(view.size) {
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, "tags", m->wqid, m->sel);
len += stat_of_name(&stat, "view", m->wqid, m->sel);
}
for(i = 0; i < view.size; i++) {
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, view.data[i]->name, m->wqid, m->sel);
if(len <= fcall->offset)
continue;
break;
}
/* offset found, proceeding */
for(; i < view.size; i++) {
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, view.data[i]->name, m->wqid, m->sel);
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
}
break;
2006-03-07 19:22:36 +03:00
case FsDclients:
/* jump to offset */
len = 0;
for(i = 0; i < client.size; i++) {
2006-03-07 19:22:36 +03:00
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, buf, m->wqid, m->sel);
2006-03-07 19:22:36 +03:00
if(len <= fcall->offset)
continue;
break;
}
/* offset found, proceeding */
for(; i < client.size; i++) {
2006-03-07 19:22:36 +03:00
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, buf, m->wqid, m->sel);
2006-03-07 19:22:36 +03:00
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
2006-03-07 19:22:36 +03:00
}
break;
case FsDbars:
/* jump to offset */
len = 0;
2006-04-13 18:52:33 +04:00
for(i = 0; i < bar.size; i++) {
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, bar.data[i]->name, m->wqid, m->sel);
if(len <= fcall->offset)
continue;
break;
}
/* offset found, proceeding */
2006-04-13 18:52:33 +04:00
for(; i < bar.size; i++) {
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, bar.data[i]->name, m->wqid, m->sel);
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
}
break;
case FsDview:
/* jump to offset */
len = 0;
if(view.size) {
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, "name", m->wqid, m->sel);
len += stat_of_name(&stat, "ctl", m->wqid, m->sel);
if(view.data[i1]->area.size)
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, "sel", m->wqid, m->sel);
for(i = 0; i < view.data[i1]->area.size; i++) {
2006-03-22 15:02:41 +03:00
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, buf, m->wqid, m->sel);
2006-03-22 15:02:41 +03:00
if(len <= fcall->offset)
continue;
break;
2006-03-22 15:02:41 +03:00
}
/* offset found, proceeding */
for(; i < view.data[i1]->area.size; i++) {
2006-03-22 15:02:41 +03:00
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, buf, m->wqid, m->sel);
2006-03-22 15:02:41 +03:00
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
2006-03-22 15:02:41 +03:00
}
}
break;
2006-03-05 16:16:48 +03:00
case FsDarea:
/* jump to offset */
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, "ctl", m->wqid, m->sel);
if(i2)
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, "mode", m->wqid, m->sel);
if(view.data[i1]->area.data[i2]->frame.size)
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, "sel", m->wqid, m->sel);
for(i = 0; i < view.data[i1]->area.data[i2]->frame.size; i++) {
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len += stat_of_name(&stat, buf, m->wqid, m->sel);
2006-02-03 20:11:22 +03:00
if(len <= fcall->offset)
continue;
break;
}
/* offset found, proceeding */
for(; i < view.data[i1]->area.data[i2]->frame.size; i++) {
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, buf, m->wqid, m->sel);
2006-02-03 20:11:22 +03:00
if(fcall->count + len > fcall->iounit)
break;
2006-02-03 20:11:22 +03:00
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
}
break;
2006-03-05 16:16:48 +03:00
case FsFevent:
2006-02-12 02:49:38 +03:00
memcpy(&c->pending, fcall, sizeof(Fcall));
c->is_pending = 1;
2006-02-03 20:11:22 +03:00
return nil;
break;
case FsFkeys:
len = def.keys ? strlen(def.keys) : 0;
if(len <= fcall->offset) {
fcall->count = 0;
break;
}
fcall->count = len - fcall->offset;
if(fcall->count > fcall->iounit) {
memcpy(p, def.keys + fcall->offset, fcall->iounit);
fcall->count = fcall->iounit;
}
else if(fcall->count)
memcpy(p, def.keys + fcall->offset, fcall->count);
break;
case FsFrules:
len = def.rules ? strlen(def.rules) : 0;
if(len <= fcall->offset) {
fcall->count = 0;
break;
}
fcall->count = len - fcall->offset;
if(fcall->count > fcall->iounit) {
memcpy(p, def.rules + fcall->offset, fcall->iounit);
fcall->count = fcall->iounit;
}
else if(fcall->count)
memcpy(p, def.rules + fcall->offset, fcall->count);
break;
case FsFtags:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDroot) {
len = 0;
/* jump to offset */
for(i = 0; i < view.size; i++) {
len += strlen(view.data[i]->name) + 1;
if(len <= fcall->offset)
continue;
}
/* offset found, proceeding */
for(; i < view.size; i++) {
len = strlen(view.data[i]->name) + 1;
if(fcall->count + len > fcall->iounit)
break;
memcpy(p + fcall->count, view.data[i]->name, len - 1);
memcpy(p + fcall->count + len - 1, "\n", 1);
fcall->count += len;
}
}
break;
default:
break;
}
}
else {
switch (type) {
2006-03-05 16:16:48 +03:00
case FsDroot:
2006-05-01 21:39:26 +04:00
fcall->count = stat_of_name(&stat, "ctl", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "event", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "def", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "bar", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
if(client.size) {
2006-05-01 21:39:26 +04:00
fcall->count += stat_of_name(&stat, "client", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
2006-03-22 15:02:41 +03:00
}
if(view.size) {
2006-05-01 21:39:26 +04:00
fcall->count += stat_of_name(&stat, "tags", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "view", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
2006-03-22 15:02:41 +03:00
}
for(i = 0; i < view.size; i++) {
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, view.data[i]->name, m->wqid, m->sel);
2006-03-07 19:22:36 +03:00
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
2006-03-07 19:22:36 +03:00
}
break;
case FsDclients:
for(i = 0; i < client.size; i++) {
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, buf, m->wqid, m->sel);
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
}
break;
case FsDbars:
2006-04-13 18:52:33 +04:00
for(i = 0; i < bar.size; i++) {
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, bar.data[i]->name, m->wqid, m->sel);
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
}
break;
case FsDbar:
2006-04-13 18:52:33 +04:00
if(i1 >= bar.size)
return Enofile;
2006-05-01 21:39:26 +04:00
fcall->count = stat_of_name(&stat, "colors", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "data", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
break;
2006-03-05 16:16:48 +03:00
case FsDdef:
2006-05-01 21:39:26 +04:00
fcall->count = stat_of_name(&stat, "border", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "selcolors", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "normcolors", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "font", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "keys", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "rules", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "grabmod", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "colmode", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "colwidth", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
break;
case FsDview:
if(view.size) {
2006-05-01 21:39:26 +04:00
fcall->count = stat_of_name(&stat, "name", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "ctl", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
if(view.data[i1]->area.size) {
2006-05-01 21:39:26 +04:00
fcall->count += stat_of_name(&stat, "sel", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
2006-03-22 15:02:41 +03:00
}
for(i = 0; i < view.data[i1]->area.size; i++) {
2006-03-22 15:02:41 +03:00
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, buf, m->wqid, m->sel);
2006-03-22 15:02:41 +03:00
if(fcall->count + len > fcall->iounit)
break;
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
2006-03-22 15:02:41 +03:00
}
}
break;
2006-03-05 16:16:48 +03:00
case FsDarea:
2006-05-01 21:39:26 +04:00
fcall->count = stat_of_name(&stat, "ctl", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
if(i2) {
2006-05-01 21:39:26 +04:00
fcall->count += stat_of_name(&stat, "mode", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
}
if(view.data[i1]->area.data[i2]->frame.size) {
2006-05-01 21:39:26 +04:00
fcall->count += stat_of_name(&stat, "sel", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
}
for(i = 0; i < view.data[i1]->area.data[i2]->frame.size; i++) {
snprintf(buf, sizeof(buf), "%u", i);
2006-05-01 21:39:26 +04:00
len = stat_of_name(&stat, buf, m->wqid, m->sel);
2006-02-03 20:11:22 +03:00
if(fcall->count + len > fcall->iounit)
break;
2006-02-03 20:11:22 +03:00
fcall->count += len;
2006-05-01 21:39:26 +04:00
p = ixp_pack_stat(p, &stat);
}
break;
2006-03-07 19:22:36 +03:00
case FsDGclient:
2006-03-05 16:16:48 +03:00
case FsDclient:
2006-05-01 21:39:26 +04:00
fcall->count = stat_of_name(&stat, "class", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "name", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "index", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "tags", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "geom", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
fcall->count += stat_of_name(&stat, "ctl", m->wqid, m->sel);
p = ixp_pack_stat(p, &stat);
break;
2006-03-05 16:16:48 +03:00
case FsFctl:
return Enoperm;
break;
2006-03-05 16:16:48 +03:00
case FsFevent:
2006-02-12 02:49:38 +03:00
memcpy(&c->pending, fcall, sizeof(Fcall));
c->is_pending = 1;
2006-02-03 20:11:22 +03:00
return nil;
break;
2006-03-05 16:16:48 +03:00
case FsFborder:
snprintf(buf, sizeof(buf), "%u", def.border);
2006-02-03 20:11:22 +03:00
fcall->count = strlen(buf);
memcpy(p, buf, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFgeom:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDclient) {
f = view.data[i1]->area.data[i2]->frame.data[i3];
2006-03-07 19:22:36 +03:00
snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y,
f->rect.width, f->rect.height);
}
else {
Client *c = client.data[i1];
2006-03-07 19:22:36 +03:00
snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y,
c->rect.width, c->rect.height);
}
2006-02-03 20:11:22 +03:00
fcall->count = strlen(buf);
memcpy(p, buf, fcall->count);
break;
2006-03-10 13:59:26 +03:00
case FsFclass:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDclient) {
if((fcall->count = strlen(view.data[i1]->area.data[i2]->frame.data[i3]->client->classinst)))
memcpy(p, view.data[i1]->area.data[i2]->frame.data[i3]->client->classinst, fcall->count);
2006-03-10 13:59:26 +03:00
}
else {
if((fcall->count = strlen(client.data[i1]->classinst)))
memcpy(p, client.data[i1]->classinst, fcall->count);
2006-03-10 13:59:26 +03:00
}
break;
case FsFindex:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDclient)
snprintf(buf, sizeof(buf), "%d",
idx_of_client_id(view.data[i1]->area.data[i2]->frame.data[i3]->client->id));
else
snprintf(buf, sizeof(buf), "%d", i1);
if((fcall->count = strlen(buf)))
memcpy(p, buf, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFname:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDclient) {
if((fcall->count = strlen(view.data[i1]->area.data[i2]->frame.data[i3]->client->name)))
memcpy(p, view.data[i1]->area.data[i2]->frame.data[i3]->client->name, fcall->count);
2006-03-07 19:22:36 +03:00
}
2006-05-01 21:39:26 +04:00
else if(dir_type == FsDview) {
if((fcall->count = strlen(view.data[i1]->name)))
memcpy(p, view.data[i1]->name, fcall->count);
}
2006-03-07 19:22:36 +03:00
else {
if((fcall->count = strlen(client.data[i1]->name)))
memcpy(p, client.data[i1]->name, fcall->count);
2006-03-07 19:22:36 +03:00
}
break;
case FsFtags:
2006-05-01 21:39:26 +04:00
switch(dir_type) {
case FsDclient:
{
Client *c = view.data[i1]->area.data[i2]->frame.data[i3]->client;
if((fcall->count = strlen(c->tags)))
memcpy(p, c->tags, fcall->count);
}
break;
case FsDGclient:
2006-04-06 13:31:54 +04:00
if((fcall->count = strlen(client.data[i1]->tags)))
memcpy(p, client.data[i1]->tags, fcall->count);
break;
default:
for(i = 0; i < view.size; i++) {
len = strlen(view.data[i]->name) + 1;
if(fcall->count + len > fcall->iounit)
break;
memcpy(p + fcall->count, view.data[i]->name, len - 1);
memcpy(p + fcall->count + len - 1, "\n", 1);
fcall->count += len;
}
break;
2006-03-07 19:22:36 +03:00
}
break;
2006-03-05 16:16:48 +03:00
case FsFdata:
2006-04-13 18:52:33 +04:00
if(i1 >= bar.size)
return Enofile;
2006-04-13 18:52:33 +04:00
if((fcall->count = strlen(bar.data[i1]->data)))
memcpy(p, bar.data[i1]->data, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFcolors:
2006-04-13 18:52:33 +04:00
if(i1 >= bar.size)
return Enofile;
2006-04-13 18:52:33 +04:00
if((fcall->count = strlen(bar.data[i1]->colstr)))
memcpy(p, bar.data[i1]->colstr, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFselcolors:
if((fcall->count = strlen(def.selcolor)))
memcpy(p, def.selcolor, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFnormcolors:
if((fcall->count = strlen(def.normcolor)))
memcpy(p, def.normcolor, fcall->count);
break;
case FsFkeys:
fcall->count = def.keys ? strlen(def.keys) : 0;
if(fcall->count > fcall->iounit) {
memcpy(p, def.keys, fcall->iounit);
fcall->count = fcall->iounit;
}
else if(fcall->count)
memcpy(p, def.keys, fcall->count);
break;
2006-03-10 16:39:46 +03:00
case FsFrules:
fcall->count = def.rules ? strlen(def.rules) : 0;
if(fcall->count > fcall->iounit) {
memcpy(p, def.rules, fcall->iounit);
fcall->count = fcall->iounit;
}
else if(fcall->count)
memcpy(p, def.rules, fcall->count);
2006-03-10 16:39:46 +03:00
break;
case FsFgrabmod:
if((fcall->count = strlen(def.grabmod)))
memcpy(p, def.grabmod, fcall->count);
break;
case FsFcolw:
snprintf(buf, sizeof(buf), "%d", def.colw);
if((fcall->count = strlen(buf)))
memcpy(p, buf, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFfont:
if((fcall->count = strlen(def.font)))
memcpy(p, def.font, fcall->count);
break;
2006-03-05 16:16:48 +03:00
case FsFmode:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDarea) {
if(!i2)
return Enofile;
i = view.data[i1]->area.data[i2]->mode;
}
else
i = def.colmode;
snprintf(buf, sizeof(buf), "%s", str_of_column_mode(i));
fcall->count = strlen(buf);
memcpy(p, buf, fcall->count);
2006-03-23 18:07:18 +03:00
break;
default:
return Enoperm;
break;
}
}
2006-02-03 20:11:22 +03:00
fcall->id = RREAD;
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
2006-02-03 20:11:22 +03:00
static char *
xstat(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
char *name;
2006-03-23 18:07:18 +03:00
if(!m)
return Enofile;
2006-05-01 21:39:26 +04:00
if(!(name = name_of_qid(m->wqid, m->sel)))
return Enofile;
if(!stat_of_name(&fcall->stat, name, m->wqid, m->sel ? m->sel - 1 : 0))
2006-02-03 20:11:22 +03:00
return Enofile;
2006-03-23 18:07:18 +03:00
fcall->id = RSTAT;
2006-02-03 20:11:22 +03:00
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
2006-02-03 20:11:22 +03:00
static char *
xwrite(IXPConn *c, Fcall *fcall)
{
char buf[256], *tmp;
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
int i, i1 = 0, i2 = 0, i3 = 0;
2006-05-01 21:39:26 +04:00
unsigned char dir_type, type;
unsigned int len;
Frame *f;
2006-04-06 13:31:54 +04:00
Client *cl;
2006-03-23 18:07:18 +03:00
if(!m)
return Enofile;
2006-05-01 21:39:26 +04:00
unpack_qpath(m->wqid, m->sel, &type, &i1, &i2, &i3);
if((i1 == -1) || (i2 == -1) || (i3 == -1))
2006-02-03 20:11:22 +03:00
return Enofile;
2006-05-01 21:39:26 +04:00
dir_type = dir_of_qid(m->wqid, m->sel);
2006-03-07 19:22:36 +03:00
switch(type) {
2006-03-05 16:16:48 +03:00
case FsFctl:
2006-02-06 11:46:52 +03:00
if(fcall->count > sizeof(buf) - 1)
return Enocommand;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
2006-05-01 21:39:26 +04:00
switch(dir_type) {
2006-03-05 16:16:48 +03:00
case FsDroot:
2006-02-06 11:46:52 +03:00
if(!strncmp(buf, "quit", 5))
srv.running = 0;
else if(!strncmp(buf, "view ", 5))
select_view(&buf[5]);
else
return Enocommand;
break;
case FsDview:
if(!strncmp(buf, "select ", 7))
if(view.size)
select_area(view.data[i1]->area.data[view.data[i1]->sel], &buf[7]);
break;
2006-03-05 16:16:48 +03:00
case FsDarea:
2006-02-14 14:06:16 +03:00
if(!strncmp(buf, "select ", 7)) {
Area *a = view.data[i1]->area.data[i2];
if(a->frame.size)
select_client(a->frame.data[a->sel]->client, &buf[7]);
2006-02-14 14:06:16 +03:00
}
break;
2006-03-05 16:16:48 +03:00
case FsDclient:
f = view.data[i1]->area.data[i2]->frame.data[i3];
2006-02-16 17:28:51 +03:00
if(!strncmp(buf, "kill", 5))
kill_client(f->client);
else if(!strncmp(buf, "newcol ", 7))
newcol_client(f->client, &buf[7]);
else if(!strncmp(buf, "move ", 5))
move_client(f->client, &buf[5]);
break;
2006-03-07 19:22:36 +03:00
case FsDGclient:
if(!strncmp(buf, "kill", 5))
kill_client(client.data[i1]);
2006-03-07 19:22:36 +03:00
break;
default:
2006-02-06 11:46:52 +03:00
break;
}
break;
2006-03-05 16:16:48 +03:00
case FsFborder:
2006-02-03 20:11:22 +03:00
if(fcall->count > sizeof(buf))
return Ebadvalue;
2006-02-03 20:11:22 +03:00
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
i = cext_strtonum(buf, 0, 0xffff, &err);
2006-02-03 20:11:22 +03:00
if(err)
return Ebadvalue;
def.border = i;
resize_all_clients();
break;
case FsFtags:
2006-05-01 21:39:26 +04:00
if(dir_type == FsDroot)
return Enoperm;
2006-03-24 17:17:50 +03:00
if(!fcall->count || (fcall->count > sizeof(buf)))
return Ebadvalue;
2006-03-09 18:41:11 +03:00
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
cext_trim(buf, " \t");
if(!permit_tags(buf))
return Ebadvalue;
2006-05-01 21:39:26 +04:00
if(dir_type == FsDclient)
2006-04-06 13:31:54 +04:00
cl = view.data[i1]->area.data[i2]->frame.data[i3]->client;
2006-03-09 18:41:11 +03:00
else
2006-04-06 13:31:54 +04:00
cl = client.data[i1];
cext_strlcpy(cl->tags, buf, sizeof(cl->tags));
2006-04-11 12:16:01 +04:00
update_views();
2006-04-06 13:31:54 +04:00
draw_client(cl);
break;
2006-03-05 16:16:48 +03:00
case FsFgeom:
2006-02-16 17:28:51 +03:00
if(fcall->count > sizeof(buf))
return Ebadvalue;
2006-02-16 17:28:51 +03:00
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
2006-05-01 21:39:26 +04:00
if(dir_type == FsDclient) {
XRectangle new;
f = view.data[i1]->area.data[i2]->frame.data[i3];
new = f->rect;
blitz_strtorect(&rect, &new, buf);
if(i2)
resize_column(f->client, &new, nil);
else
resize_client(f->client, &new, False);
2006-03-07 19:22:36 +03:00
}
break;
2006-03-05 16:16:48 +03:00
case FsFdata:
len = fcall->count;
2006-04-13 18:52:33 +04:00
if(len >= sizeof(bar.data[i1]->data))
len = sizeof(bar.data[i1]->data) - 1;
memcpy(bar.data[i1]->data, fcall->data, len);
bar.data[i1]->data[len] = 0;
draw_bar();
break;
2006-03-05 16:16:48 +03:00
case FsFcolors:
2006-04-13 18:52:33 +04:00
if((i1 >= bar.size) || (fcall->count != 23) || (fcall->data[0] != '#')
2006-03-23 18:07:18 +03:00
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
return Ebadvalue;
2006-04-13 18:52:33 +04:00
memcpy(bar.data[i1]->colstr, fcall->data, fcall->count);
bar.data[i1]->colstr[fcall->count] = 0;
blitz_loadcolor(dpy, &bar.data[i1]->color, screen, bar.data[i1]->colstr);
draw_bar();
break;
2006-03-05 16:16:48 +03:00
case FsFselcolors:
2006-03-23 18:07:18 +03:00
if((fcall->count != 23) || (fcall->data[0] != '#')
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
return Ebadvalue;
memcpy(def.selcolor, fcall->data, fcall->count);
def.selcolor[fcall->count] = 0;
blitz_loadcolor(dpy, &def.sel, screen, def.selcolor);
draw_clients();
break;
2006-03-05 16:16:48 +03:00
case FsFnormcolors:
2006-03-23 18:07:18 +03:00
if((fcall->count != 23) || (fcall->data[0] != '#')
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
return Ebadvalue;
memcpy(def.normcolor, fcall->data, fcall->count);
def.normcolor[fcall->count] = 0;
blitz_loadcolor(dpy, &def.norm, screen, def.normcolor);
draw_clients();
break;
case FsFkeys:
if(def.keyssz < fcall->offset + fcall->count + 1) {
def.keyssz = fcall->offset + fcall->count + 1;
tmp = cext_emallocz(def.keyssz);
len = def.keys ? strlen(def.keys) : 0;
if(len) {
memcpy(tmp, def.keys, len);
free(def.keys);
}
def.keys = tmp;
}
memcpy(def.keys + fcall->offset, fcall->data, fcall->count);
def.keys[fcall->offset + fcall->count] = 0;
break;
2006-03-10 16:39:46 +03:00
case FsFrules:
if(def.rulessz < fcall->offset + fcall->count + 1) {
def.rulessz = fcall->offset + fcall->count + 1;
tmp = cext_emallocz(def.rulessz);
len = def.rules ? strlen(def.rules) : 0;
if(len) {
memcpy(tmp, def.rules, len);
free(def.rules);
}
def.rules = tmp;
2006-03-10 16:39:46 +03:00
}
memcpy(def.rules + fcall->offset, fcall->data, fcall->count);
def.rules[fcall->offset + fcall->count] = 0;
2006-03-10 16:39:46 +03:00
break;
case FsFgrabmod:
{
unsigned long mod;
if(fcall->count > sizeof(buf))
return Ebadvalue;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
mod = mod_key_of_str(buf);
if((mod != Mod1Mask) && (mod != Mod2Mask) && (mod != Mod3Mask)
&& (mod != Mod4Mask) && (mod != Mod5Mask))
return Ebadvalue;
cext_strlcpy(def.grabmod, buf, sizeof(def.grabmod));
def.mod = mod;
if(view.size)
restack_view(view.data[sel]);
}
break;
case FsFcolw:
if(fcall->count > sizeof(buf))
return Ebadvalue;
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
2006-04-14 14:47:10 +04:00
i = cext_strtonum(buf, 0, rect.width - MIN_COLWIDTH, &err);
if(err || (i && i < MIN_COLWIDTH))
return Ebadvalue;
def.colw = i;
break;
2006-03-05 16:16:48 +03:00
case FsFfont:
if(def.font)
free(def.font);
def.font = cext_emallocz(fcall->count + 1);
memcpy(def.font, fcall->data, fcall->count);
blitz_loadfont(dpy, &blitzfont, def.font);
2006-04-12 12:44:07 +04:00
resize_bar();
break;
2006-03-05 16:16:48 +03:00
case FsFmode:
if(fcall->count > sizeof(buf))
return Ebadvalue;
2006-05-01 21:39:26 +04:00
if(dir_type == FsDarea && !i2)
return Enofile;
2006-03-05 02:11:08 +03:00
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
2006-04-12 12:44:07 +04:00
if((i = column_mode_of_str(buf)) == -1)
return Ebadvalue;
2006-05-01 21:39:26 +04:00
if(dir_type == FsDarea) {
view.data[i1]->area.data[i2]->mode = i;
arrange_column(view.data[i1]->area.data[i2], True);
restack_view(view.data[i1]);
draw_clients();
}
else
def.colmode = i;
2006-03-23 18:07:18 +03:00
break;
case FsFevent:
if(fcall->count > sizeof(buf))
return Ebadvalue;
2006-03-15 11:02:25 +03:00
if(fcall->count) {
memcpy(buf, fcall->data, fcall->count);
buf[fcall->count] = 0;
write_event(buf);
2006-03-15 11:02:25 +03:00
}
break;
default:
return Enoperm;
break;
}
2006-03-23 18:07:18 +03:00
fcall->id = RWRITE;
2006-02-03 20:11:22 +03:00
ixp_server_respond_fcall(c, fcall);
return nil;
}
2006-02-03 20:11:22 +03:00
static char *
xclunk(IXPConn *c, Fcall *fcall)
{
2006-03-23 18:07:18 +03:00
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
unsigned char type;
2006-03-23 18:07:18 +03:00
if(!m)
return Enofile;
type = unpack_type(m->wqid[m->sel].path);
if(type == FsFkeys)
2006-03-23 18:07:18 +03:00
update_keys();
else if(type == FsFrules)
update_rules();
2006-04-13 17:35:10 +04:00
cext_vdetach(ixp_vector_of_maps(&c->map), m);
2006-03-23 18:07:18 +03:00
free(m);
fcall->id = RCLUNK;
2006-02-03 20:11:22 +03:00
ixp_server_respond_fcall(c, fcall);
2006-03-23 18:07:18 +03:00
return nil;
}
static void
2006-02-03 20:11:22 +03:00
do_fcall(IXPConn *c)
{
2006-02-03 20:11:22 +03:00
static Fcall fcall;
2006-03-23 18:07:18 +03:00
unsigned int msize;
2006-02-03 20:11:22 +03:00
char *errstr;
if((msize = ixp_server_receive_fcall(c, &fcall))) {
switch(fcall.id) {
case TVERSION: errstr = xversion(c, &fcall); break;
case TATTACH: errstr = xattach(c, &fcall); break;
case TWALK: errstr = xwalk(c, &fcall); break;
case TCREATE: errstr = xcreate(c, &fcall); break;
2006-02-03 20:11:22 +03:00
case TOPEN: errstr = xopen(c, &fcall); break;
case TREMOVE: errstr = xremove(c, &fcall); break;
2006-02-03 20:11:22 +03:00
case TREAD: errstr = xread(c, &fcall); break;
case TWRITE: errstr = xwrite(c, &fcall); break;
case TCLUNK: errstr = xclunk(c, &fcall); break;
case TSTAT: errstr = xstat(c, &fcall); break;
default: errstr = Enofunc; break;
}
2006-02-03 20:11:22 +03:00
if(errstr)
ixp_server_respond_error(c, &fcall, errstr);
}
check_x_event(nil);
}
void
write_event(char *event)
{
unsigned int i = 0;
2006-03-23 18:07:18 +03:00
2006-04-03 18:48:41 +04:00
for(i = 0; i < srv.conn.size; i++) {
IXPConn *c = srv.conn.data[i];
2006-02-12 02:49:38 +03:00
if(c->is_pending) {
/* pending reads on /event only, no qid checking */
IXPMap *m = ixp_server_fid2map(c, c->pending.fid);
if(!m) {
if(ixp_server_respond_error(c, &c->pending, Enofile))
return;
}
2006-05-01 21:39:26 +04:00
else if(unpack_type(m->wqid[m->sel].path) == FsFevent) {
/* pending reads on /event only, no qid checking */
2006-02-12 02:49:38 +03:00
c->pending.count = strlen(event);
memcpy(c->pending.data, event, c->pending.count);
2006-02-12 02:49:38 +03:00
c->pending.id = RREAD;
if(ixp_server_respond_fcall(c, &c->pending))
return;
}
}
}
}
void
2006-02-03 20:11:22 +03:00
new_ixp_conn(IXPConn *c)
{
int fd = ixp_accept_sock(c->fd);
2006-03-23 18:07:18 +03:00
2006-02-03 20:11:22 +03:00
if(fd >= 0)
ixp_server_open_conn(c->srv, fd, do_fcall, ixp_server_close_conn);
}