2006-01-30 21:43:32 +03:00
|
|
|
/*
|
|
|
|
* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
|
|
|
|
* See LICENSE file for license details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#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/cursorfont.h>
|
|
|
|
#include <X11/Xproto.h>
|
|
|
|
#include <X11/Xutil.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2006-01-31 15:25:23 +03:00
|
|
|
#include "wm.h"
|
2006-01-30 21:43:32 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* filesystem specification
|
|
|
|
* / Droot
|
|
|
|
* /default/ Ddefault
|
|
|
|
* /default/font Ffont <xlib font name>
|
2006-01-31 19:52:14 +03:00
|
|
|
* /default/selcolor Fselcolor <#RRGGBB> <#RRGGBB> <#RRGGBB>
|
|
|
|
* /default/normcolor Fnormcolor <#RRGGBB> <#RRGGBB> <#RRGGBB>
|
2006-01-31 01:48:41 +03:00
|
|
|
* /default/border Fborder 0..n
|
2006-02-02 22:36:10 +03:00
|
|
|
* /default/bar Fbar 0, 1
|
2006-01-31 01:48:41 +03:00
|
|
|
* /default/snap Fsnap 0..n
|
2006-02-02 15:20:07 +03:00
|
|
|
* /default/inc Finc 0..n
|
2006-01-30 21:43:32 +03:00
|
|
|
* /event Fevent
|
|
|
|
* /ctl Fctl command interface (root)
|
|
|
|
* /new/ Dpage returns new page
|
|
|
|
* /sel/ Dpage sel page
|
|
|
|
* /1/ Dpage page
|
|
|
|
* /1/ctl Fctl command interface (page)
|
2006-02-01 18:27:53 +03:00
|
|
|
* /1/sel/ Darea
|
|
|
|
* /1/new/ Darea
|
|
|
|
* /1/float/ Darea floating clients in area 0
|
|
|
|
* /1/float/ctl Fctl command interface (area)
|
2006-02-01 16:23:24 +03:00
|
|
|
* /1/float/sel/ Dclient
|
|
|
|
* /1/float/1/ Dclient
|
|
|
|
* /1/float/1/border Fborder 0..n
|
2006-02-02 22:36:10 +03:00
|
|
|
* /1/float/1/bar Fbar 0, 1
|
2006-02-01 16:23:24 +03:00
|
|
|
* /1/float/1/name Fname name of client
|
2006-02-02 15:20:07 +03:00
|
|
|
* /1/float/1/geom Fgeom geometry of client
|
2006-02-01 16:23:24 +03:00
|
|
|
* /1/float/1/ctl Fctl command interface (client)
|
2006-02-01 18:27:53 +03:00
|
|
|
* /1/1/ Darea
|
|
|
|
* /1/1/ctl Fctl command interface (area)
|
2006-02-01 16:23:24 +03:00
|
|
|
* /1/1/1/sel/ Dclient
|
|
|
|
* /1/1/1/1/ Dclient
|
|
|
|
* /1/1/1/border Fborder 0..n
|
2006-02-02 22:36:10 +03:00
|
|
|
* /1/1/1/bar Fbar 0, 1
|
2006-02-01 16:23:24 +03:00
|
|
|
* /1/1/1/name Fname name of client
|
2006-02-02 15:20:07 +03:00
|
|
|
* /1/1/1/geom Fgeom geometry of client
|
2006-02-01 16:23:24 +03:00
|
|
|
* /1/1/1/ctl Fctl command interface (client)
|
2006-01-30 21:43:32 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
static char E9pversion[] = "9P version not supported";
|
2006-02-04 17:13:11 +03:00
|
|
|
static char Enoperm[] = "permission denied";
|
2006-01-30 21:43:32 +03:00
|
|
|
static char Enofid[] = "fid not assigned";
|
|
|
|
static char Enofile[] = "file not found";
|
|
|
|
static char Enomode[] = "mode not supported";
|
|
|
|
static char Enofunc[] = "function not supported";
|
2006-02-03 20:11:22 +03:00
|
|
|
static char Enocommand[] = "command not supported";
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
const char *err;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
|
|
|
/* IXP stuff */
|
|
|
|
|
2006-02-02 16:50:04 +03:00
|
|
|
unsigned long long
|
2006-02-03 20:11:22 +03:00
|
|
|
mkqpath(unsigned char type, unsigned short pgid, unsigned short aid, unsigned short cid)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
return ((unsigned long long) type << 48) | ((unsigned long long) pgid << 32)
|
|
|
|
| ((unsigned long long) aid << 16) | (unsigned long long) cid;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char
|
|
|
|
qpath_type(unsigned long long path)
|
|
|
|
{
|
2006-01-31 15:25:23 +03:00
|
|
|
return (path >> 48) & 0xff;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-01-31 15:25:23 +03:00
|
|
|
static unsigned short
|
2006-02-03 20:11:22 +03:00
|
|
|
qpath_pgid(unsigned long long path)
|
2006-01-31 15:25:23 +03:00
|
|
|
{
|
|
|
|
return (path >> 32) & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned short
|
2006-02-03 20:11:22 +03:00
|
|
|
qpath_aid(unsigned long long path)
|
2006-01-31 01:48:41 +03:00
|
|
|
{
|
2006-01-31 15:25:23 +03:00
|
|
|
return (path >> 16) & 0xffff;
|
2006-01-31 01:48:41 +03:00
|
|
|
}
|
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
static unsigned short
|
2006-02-03 20:11:22 +03:00
|
|
|
qpath_cid(unsigned long long path)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-01-31 15:25:23 +03:00
|
|
|
return path & 0xffff;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
qid_to_name(Qid *qid)
|
|
|
|
{
|
2006-01-31 19:52:14 +03:00
|
|
|
unsigned char typ = qpath_type(qid->path);
|
2006-02-03 20:11:22 +03:00
|
|
|
unsigned short pgid = qpath_pgid(qid->path);
|
|
|
|
unsigned short aid = qpath_aid(qid->path);
|
|
|
|
unsigned short cid = qpath_cid(qid->path);
|
|
|
|
int pg = 0, area = 0, cl = 0;
|
2006-01-30 21:43:32 +03:00
|
|
|
static char buf[32];
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(pgid && ((pg = index_of_page_id(pgid)) == -1))
|
|
|
|
return nil;
|
|
|
|
if(aid && ((area = index_of_area_id(page[pg], aid)) == -1))
|
|
|
|
return nil;
|
|
|
|
if(cid && ((cl = index_of_client_id(page[pg]->area[area], cid)) == -1))
|
|
|
|
return nil;
|
|
|
|
|
2006-01-31 19:52:14 +03:00
|
|
|
switch(typ) {
|
2006-01-30 21:43:32 +03:00
|
|
|
case Droot: return "/"; break;
|
2006-01-31 01:48:41 +03:00
|
|
|
case Ddefault: return "default"; break;
|
|
|
|
case Dpage:
|
2006-02-02 01:43:17 +03:00
|
|
|
if(pg == sel)
|
2006-01-31 15:25:23 +03:00
|
|
|
return "sel";
|
|
|
|
if(pg == npage)
|
|
|
|
return "new";
|
|
|
|
snprintf(buf, sizeof(buf), "%u", pg);
|
|
|
|
return buf;
|
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Darea:
|
2006-02-02 21:04:15 +03:00
|
|
|
if(!area) {
|
|
|
|
if(page[pg]->sel)
|
|
|
|
return "float";
|
|
|
|
else
|
|
|
|
return "sel";
|
|
|
|
}
|
2006-02-01 18:27:53 +03:00
|
|
|
if(page[pg]->narea == area)
|
2006-01-30 21:43:32 +03:00
|
|
|
return "new";
|
2006-02-01 18:27:53 +03:00
|
|
|
if(page[pg]->sel == area)
|
2006-01-31 15:25:23 +03:00
|
|
|
return "sel";
|
2006-02-01 18:27:53 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", area);
|
2006-01-31 15:25:23 +03:00
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case Dclient:
|
2006-02-01 18:27:53 +03:00
|
|
|
if(page[pg]->area[area]->sel == cl)
|
2006-01-31 19:52:14 +03:00
|
|
|
return "sel";
|
|
|
|
snprintf(buf, sizeof(buf), "%u", cl);
|
2006-01-30 21:43:32 +03:00
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case Fctl: return "ctl"; break;
|
|
|
|
case Ffont: return "font"; break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fselcolor: return "selcolor"; break;
|
|
|
|
case Fnormcolor: return "normcolor"; break;
|
2006-01-31 01:48:41 +03:00
|
|
|
case Fborder: return "border"; break;
|
|
|
|
case Fsnap: return "border"; break;
|
2006-02-02 22:36:10 +03:00
|
|
|
case Fbar: return "bar"; break;
|
2006-02-02 15:20:07 +03:00
|
|
|
case Finc: return "inc"; break;
|
|
|
|
case Fgeom: return "geometry"; break;
|
2006-01-31 01:48:41 +03:00
|
|
|
case Fname: return "name"; break;
|
2006-01-30 21:43:32 +03:00
|
|
|
case Fevent: return "event"; break;
|
|
|
|
default: return nil; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-01-31 19:52:14 +03:00
|
|
|
name_to_type(char *name, unsigned char dtyp)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
if(!name || !name[0] || !strncmp(name, "/", 2) || !strncmp(name, "..", 3))
|
|
|
|
return Droot;
|
2006-01-31 15:25:23 +03:00
|
|
|
if(!strncmp(name, "new", 4)) {
|
2006-01-31 19:52:14 +03:00
|
|
|
if(dtyp == Droot)
|
2006-01-31 15:25:23 +03:00
|
|
|
return Dpage;
|
2006-01-31 19:52:14 +03:00
|
|
|
else if(dtyp == Dpage)
|
2006-02-01 18:27:53 +03:00
|
|
|
return Darea;
|
2006-01-31 15:25:23 +03:00
|
|
|
}
|
2006-02-02 18:44:45 +03:00
|
|
|
if(!strncmp(name, "default", 8))
|
|
|
|
return Ddefault;
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!strncmp(name, "ctl", 4))
|
|
|
|
return Fctl;
|
|
|
|
if(!strncmp(name, "font", 5))
|
|
|
|
return Ffont;
|
|
|
|
if(!strncmp(name, "event", 6))
|
|
|
|
return Fevent;
|
2006-02-02 15:20:07 +03:00
|
|
|
if(!strncmp(name, "selcolor", 9))
|
2006-01-31 19:52:14 +03:00
|
|
|
return Fselcolor;
|
2006-02-02 15:20:07 +03:00
|
|
|
if(!strncmp(name, "normcolor", 10))
|
2006-01-31 19:52:14 +03:00
|
|
|
return Fnormcolor;
|
2006-01-31 11:27:54 +03:00
|
|
|
if(!strncmp(name, "snap", 5))
|
|
|
|
return Fsnap;
|
|
|
|
if(!strncmp(name, "name", 5))
|
|
|
|
return Fname;
|
|
|
|
if(!strncmp(name, "border", 7))
|
2006-01-31 15:25:23 +03:00
|
|
|
return Fborder;
|
2006-02-02 22:36:10 +03:00
|
|
|
if(!strncmp(name, "bar", 4))
|
|
|
|
return Fbar;
|
2006-02-02 15:20:07 +03:00
|
|
|
if(!strncmp(name, "inc", 4))
|
|
|
|
return Finc;
|
|
|
|
if(!strncmp(name, "geometry", 9))
|
|
|
|
return Fgeom;
|
|
|
|
if(!strncmp(name, "sel", 4))
|
2006-01-31 19:52:14 +03:00
|
|
|
goto dyndir;
|
2006-02-02 21:14:34 +03:00
|
|
|
i = (unsigned short) cext_strtonum(name, 0, 0xffff, &err);
|
2006-01-31 11:27:54 +03:00
|
|
|
if(err)
|
|
|
|
return -1;
|
2006-01-31 19:52:14 +03:00
|
|
|
dyndir:
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "nametotype: dtyp = %d\n", dtyp);
|
2006-01-31 19:52:14 +03:00
|
|
|
switch(dtyp) {
|
|
|
|
case Droot: return Dpage; break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Dpage: return Darea; break;
|
|
|
|
case Darea: return Dclient; break;
|
2006-01-31 11:27:54 +03:00
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
mkqid(Qid *dir, char *wname, Qid *new)
|
|
|
|
{
|
2006-01-31 19:52:14 +03:00
|
|
|
unsigned char dtyp = qpath_type(dir->path);
|
2006-02-03 20:11:22 +03:00
|
|
|
unsigned short dpgid = qpath_pgid(dir->path);
|
|
|
|
unsigned short daid = qpath_aid(dir->path);
|
|
|
|
unsigned short dcid = qpath_cid(dir->path);
|
|
|
|
int dpg = 0, darea = 0, dcl = 0;
|
2006-01-31 19:52:14 +03:00
|
|
|
unsigned short i;
|
|
|
|
int type = name_to_type(wname, dtyp);
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(dpgid && ((dpg = index_of_page_id(dpgid)) == -1))
|
|
|
|
return -1;
|
|
|
|
if(daid && ((darea = index_of_area_id(page[dpg], daid)) == -1))
|
|
|
|
return -1;
|
|
|
|
if(dcid && ((dcl = index_of_client_id(page[dpg]->area[darea], dcid)) == -1))
|
|
|
|
return -1;
|
2006-01-30 21:43:32 +03:00
|
|
|
if((dir->type != IXP_QTDIR) || (type == -1))
|
|
|
|
return -1;
|
|
|
|
|
2006-02-02 18:44:45 +03:00
|
|
|
new->dtype = dtyp;
|
2006-01-30 21:43:32 +03:00
|
|
|
new->version = 0;
|
|
|
|
switch(type) {
|
|
|
|
case Droot:
|
|
|
|
*new = root_qid;
|
|
|
|
break;
|
2006-01-31 15:25:23 +03:00
|
|
|
case Ddefault:
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
new->path = mkqpath(Ddefault, 0, 0, 0);
|
|
|
|
break;
|
|
|
|
case Dpage:
|
2006-01-30 21:43:32 +03:00
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
if(!strncmp(wname, "new", 4))
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Dpage, NEW_OBJ, 0, 0);
|
2006-02-02 19:19:32 +03:00
|
|
|
else if(!strncmp(wname, "sel", 4)) {
|
|
|
|
if(!npage)
|
|
|
|
return -1;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Dpage, page[sel]->id, 0, 0);
|
2006-02-02 19:19:32 +03:00
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
else {
|
2006-02-02 21:14:34 +03:00
|
|
|
i = cext_strtonum(wname, 0, 0xffff, &err);
|
2006-01-31 15:25:23 +03:00
|
|
|
if(err || (i >= npage))
|
2006-01-30 21:43:32 +03:00
|
|
|
return -1;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Dpage, page[i]->id, 0, 0);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Darea:
|
2006-02-02 21:04:15 +03:00
|
|
|
fprintf(stderr, "mkqid(): %s\n", "Darea");
|
2006-02-04 20:39:05 +03:00
|
|
|
if(!npage || dpg >= npage)
|
2006-02-02 19:19:32 +03:00
|
|
|
return -1;
|
2006-01-31 15:25:23 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-01-31 19:52:14 +03:00
|
|
|
if(!strncmp(wname, "new", 4))
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Darea, dpgid, NEW_OBJ, 0);
|
|
|
|
else if(!strncmp(wname, "sel", 4)) {
|
|
|
|
Page *p = page[dpg];
|
2006-02-04 20:39:05 +03:00
|
|
|
if(!p->narea)
|
|
|
|
return -1;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Darea, dpgid, p->area[p->sel]->id, 0);
|
|
|
|
}
|
2006-01-31 19:52:14 +03:00
|
|
|
else {
|
2006-02-02 21:14:34 +03:00
|
|
|
i = cext_strtonum(wname, 0, 0xffff, &err);
|
2006-02-02 19:19:32 +03:00
|
|
|
if(err || (i >= page[dpg]->narea))
|
2006-01-31 19:52:14 +03:00
|
|
|
return -1;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Darea, dpgid, page[dpg]->area[i]->id, 0);
|
2006-01-31 19:52:14 +03:00
|
|
|
}
|
2006-01-31 15:25:23 +03:00
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Dclient:
|
2006-02-02 19:19:32 +03:00
|
|
|
if(!npage)
|
|
|
|
return -1;
|
2006-01-31 15:25:23 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!strncmp(wname, "sel", 4)) {
|
|
|
|
Area *a = page[dpg]->area[darea];
|
2006-02-04 20:39:05 +03:00
|
|
|
if(!a->nclient)
|
|
|
|
return -1;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Dclient, dpgid, daid, a->client[a->sel]->id);
|
|
|
|
}
|
2006-01-31 19:52:14 +03:00
|
|
|
else {
|
2006-02-03 20:11:22 +03:00
|
|
|
Area *a = page[dpg]->area[darea];
|
2006-02-02 21:14:34 +03:00
|
|
|
i = cext_strtonum(wname, 0, 0xffff, &err);
|
2006-02-02 19:19:32 +03:00
|
|
|
if(err || (i >= page[dpg]->area[darea]->nclient))
|
2006-01-31 19:52:14 +03:00
|
|
|
return -1;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(Dclient, dpgid, daid, a->client[i]->id);
|
2006-01-31 19:52:14 +03:00
|
|
|
}
|
2006-01-31 15:25:23 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
default:
|
|
|
|
new->type = IXP_QTFILE;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->path = mkqpath(type, dpgid, daid, dcid);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xversion(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +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);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xattach(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
IXPMap *new = cext_emallocz(sizeof(IXPMap));
|
|
|
|
new->qid = root_qid;
|
2006-02-03 20:11:22 +03:00
|
|
|
new->fid = fcall->fid;
|
2006-01-30 21:43:32 +03:00
|
|
|
c->map = (IXPMap **)cext_array_attach((void **)c->map, new,
|
|
|
|
sizeof(IXPMap *), &c->mapsz);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->id = RATTACH;
|
|
|
|
fcall->qid = root_qid;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xwalk(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
unsigned short nwqid = 0;
|
|
|
|
Qid dir = root_qid;
|
|
|
|
IXPMap *m;
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!(m = ixp_server_fid2map(c, fcall->fid)))
|
|
|
|
return Enofid;
|
|
|
|
if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid)))
|
|
|
|
return Enofid;
|
|
|
|
if(fcall->nwname) {
|
2006-01-30 21:43:32 +03:00
|
|
|
dir = m->qid;
|
2006-02-03 20:11:22 +03:00
|
|
|
for(nwqid = 0; (nwqid < fcall->nwname)
|
|
|
|
&& !mkqid(&dir, fcall->wname[nwqid], &fcall->wqid[nwqid]); nwqid++)
|
2006-02-02 18:44:45 +03:00
|
|
|
{
|
|
|
|
fprintf(stderr, "dir.dtype=%d\n", dir.dtype);
|
2006-02-03 20:11:22 +03:00
|
|
|
dir = fcall->wqid[nwqid];
|
2006-02-02 18:44:45 +03:00
|
|
|
fprintf(stderr, "walk: qid_to_name()=%s qpath_type(dir.path)=%d dir.dtype=%d\n",
|
|
|
|
qid_to_name(&dir), qpath_type(dir.path), dir.dtype);
|
|
|
|
}
|
2006-02-03 22:02:37 +03:00
|
|
|
if(!nwqid) {
|
|
|
|
fprintf(stderr, "%s", "xwalk: no sucj file\n");
|
2006-02-03 20:11:22 +03:00
|
|
|
return Enofile;
|
2006-02-03 22:02:37 +03:00
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
/* a fid will only be valid, if the walk was complete */
|
2006-02-03 20:11:22 +03:00
|
|
|
if(nwqid == fcall->nwname) {
|
|
|
|
if(fcall->fid != fcall->newfid) {
|
2006-01-30 21:43:32 +03:00
|
|
|
m = cext_emallocz(sizeof(IXPMap));
|
|
|
|
c->map = (IXPMap **)cext_array_attach((void **)c->map, m,
|
|
|
|
sizeof(IXPMap *), &c->mapsz);
|
|
|
|
}
|
|
|
|
m->qid = dir;
|
2006-02-03 20:11:22 +03:00
|
|
|
m->fid = fcall->newfid;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->id = RWALK;
|
|
|
|
fcall->nwqid = nwqid;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xopen(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
|
|
|
|
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
|
|
|
if(!(fcall->mode | IXP_OREAD) && !(fcall->mode | IXP_OWRITE))
|
|
|
|
return Enomode;
|
|
|
|
fcall->id = ROPEN;
|
|
|
|
fcall->qid = m->qid;
|
|
|
|
fcall->iounit = 2048;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
|
|
|
mkstat(Stat *stat, Qid *dir, char *name, unsigned long long length, unsigned int mode)
|
|
|
|
{
|
|
|
|
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));
|
|
|
|
|
|
|
|
cext_strlcpy(stat->name, name, sizeof(stat->name));
|
|
|
|
stat->length = length;
|
|
|
|
mkqid(dir, name, &stat->qid);
|
|
|
|
return ixp_sizeof_stat(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
2006-02-01 18:27:53 +03:00
|
|
|
type_to_stat(Stat *stat, char *name, Qid *dir)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-01-31 19:52:14 +03:00
|
|
|
unsigned char dtyp = qpath_type(dir->path);
|
2006-02-03 20:11:22 +03:00
|
|
|
unsigned short dpgid = qpath_pgid(dir->path);
|
|
|
|
unsigned short daid = qpath_aid(dir->path);
|
|
|
|
unsigned short dcid = qpath_cid(dir->path);
|
|
|
|
int dpg = 0, darea = 0, dcl = 0;
|
2006-02-03 22:02:37 +03:00
|
|
|
int type = name_to_type(name, dir->dtype);
|
2006-02-02 15:20:07 +03:00
|
|
|
char buf[32];
|
|
|
|
Client *c;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "typetostat(0): name=%s dpgid=%d daid=%d dcid=%d\n", name, dpgid, daid, dcid);
|
|
|
|
fprintf(stderr, "typetostat (0) Dtype=%d\n", type);
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(dpgid && ((dpg = index_of_page_id(dpgid)) == -1))
|
|
|
|
return 0;
|
|
|
|
if(daid && ((darea = index_of_area_id(page[dpg], daid)) == -1))
|
|
|
|
return 0;
|
|
|
|
if(dcid && ((dcl = index_of_client_id(page[dpg]->area[darea], dcid)) == -1))
|
|
|
|
return 0;
|
|
|
|
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "typetostat(1): dpg=%d darea=%d dcl=%d\n", dpg, darea, dcl);
|
|
|
|
fprintf(stderr, "typetostat (3) Dtype=%d\n", type);
|
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
switch (type) {
|
2006-01-31 19:52:14 +03:00
|
|
|
case Dclient:
|
2006-02-02 19:19:32 +03:00
|
|
|
case Darea:
|
|
|
|
case Dpage:
|
|
|
|
case Ddefault:
|
|
|
|
case Droot:
|
2006-01-31 19:52:14 +03:00
|
|
|
return mkstat(stat, dir, name, 0, DMDIR | DMREAD | DMEXEC);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
case Fctl:
|
2006-02-04 17:13:11 +03:00
|
|
|
return mkstat(stat, dir, name, 0, DMWRITE);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
case Fevent:
|
2006-01-31 19:52:14 +03:00
|
|
|
return mkstat(stat, dir, name, 0, DMREAD);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
case Ffont:
|
2006-01-31 19:52:14 +03:00
|
|
|
return mkstat(stat, dir, name, strlen(def.font), DMREAD | DMWRITE);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fselcolor:
|
|
|
|
return mkstat(stat, dir, name, 24, DMREAD | DMWRITE);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fnormcolor:
|
|
|
|
return mkstat(stat, dir, name, 24, DMREAD | DMWRITE);
|
|
|
|
break;
|
|
|
|
case Fborder:
|
|
|
|
if(dtyp == Ddefault)
|
|
|
|
snprintf(buf, sizeof(buf), "%d", def.border);
|
2006-02-03 22:02:37 +03:00
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%d", page[dpg]->area[darea]->client[dcl]->frame.border);
|
2006-01-31 19:52:14 +03:00
|
|
|
return mkstat(stat, dir, name, strlen(buf), DMREAD | DMWRITE);
|
|
|
|
break;
|
2006-02-02 22:36:10 +03:00
|
|
|
case Fbar:
|
2006-01-31 19:52:14 +03:00
|
|
|
if(dtyp == Ddefault)
|
2006-02-02 22:36:10 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d", def.bar);
|
2006-02-03 22:02:37 +03:00
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%d", page[dpg]->area[darea]->client[dcl]->frame.bar);
|
2006-01-31 19:52:14 +03:00
|
|
|
return mkstat(stat, dir, name, strlen(buf), DMREAD | DMWRITE);
|
|
|
|
break;
|
2006-02-02 15:20:07 +03:00
|
|
|
case Finc:
|
2006-02-03 18:15:36 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d", def.inc);
|
2006-02-02 15:20:07 +03:00
|
|
|
return mkstat(stat, dir, name, strlen(buf), DMREAD | DMWRITE);
|
|
|
|
break;
|
|
|
|
case Fgeom:
|
2006-02-03 22:02:37 +03:00
|
|
|
c = page[dpg]->area[darea]->client[dcl];
|
2006-02-02 15:20:07 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", c->frame.rect.x, c->frame.rect.y,
|
|
|
|
c->frame.rect.width, c->frame.rect.height);
|
|
|
|
return mkstat(stat, dir, name, strlen(buf), DMREAD | DMWRITE);
|
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fsnap:
|
|
|
|
snprintf(buf, sizeof(buf), "%d", def.snap);
|
|
|
|
return mkstat(stat, dir, name, strlen(buf), DMREAD | DMWRITE);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fname:
|
2006-02-03 22:02:37 +03:00
|
|
|
c = page[dpg]->area[darea]->client[dcl];
|
|
|
|
return mkstat(stat, dir, name, strlen(c->name), DMREAD);
|
2006-01-31 19:52:14 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xread(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
Stat stat;
|
2006-02-03 20:11:22 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
|
|
|
unsigned char *p = fcall->data;
|
|
|
|
unsigned short pgid, aid, cid;
|
2006-01-31 21:57:14 +03:00
|
|
|
unsigned int i, len;
|
2006-01-30 21:43:32 +03:00
|
|
|
char buf[32];
|
2006-02-02 15:20:07 +03:00
|
|
|
Client *client;
|
2006-02-03 20:12:44 +03:00
|
|
|
int pg = 0, area = 0, cl = 0;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
pgid = qpath_pgid(m->qid.path);
|
|
|
|
aid = qpath_aid(m->qid.path);
|
|
|
|
cid = qpath_cid(m->qid.path);
|
|
|
|
|
|
|
|
if(pgid && ((pg = index_of_page_id(pgid)) == -1))
|
|
|
|
return Enofile;
|
|
|
|
if(aid && ((area = index_of_area_id(page[pg], aid)) == -1))
|
|
|
|
return Enofile;
|
|
|
|
if(cid && ((cl = index_of_client_id(page[pg]->area[area], cid)) == -1))
|
|
|
|
return Enofile;
|
|
|
|
|
|
|
|
fcall->count = 0;
|
|
|
|
if(fcall->offset) {
|
2006-01-30 21:43:32 +03:00
|
|
|
switch (qpath_type(m->qid.path)) {
|
|
|
|
case Droot:
|
|
|
|
/* jump to offset */
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, "ctl", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "event", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "default", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "new", &m->qid);
|
2006-02-02 21:04:15 +03:00
|
|
|
for(i = 0; i < npage; i++) {
|
|
|
|
if(i == sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len += type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(len <= fcall->offset)
|
2006-01-30 21:43:32 +03:00
|
|
|
continue;
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
2006-01-31 21:57:14 +03:00
|
|
|
for(; i < npage; i++) {
|
2006-02-02 21:04:15 +03:00
|
|
|
if(i == sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += len;
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Dpage:
|
|
|
|
/* jump to offset */
|
|
|
|
len = type_to_stat(&stat, "ctl", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "new", &m->qid);
|
2006-02-02 21:04:15 +03:00
|
|
|
for(i = 0; i < page[pg]->narea; i++) {
|
|
|
|
if(i == page[pg]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len += type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(len <= fcall->offset)
|
2006-02-01 18:27:53 +03:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
|
|
|
for(; i < page[pg]->narea; i++) {
|
2006-02-02 21:04:15 +03:00
|
|
|
if(i == page[pg]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += len;
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Darea:
|
|
|
|
/* jump to offset */
|
|
|
|
len = type_to_stat(&stat, "ctl", &m->qid);
|
|
|
|
for(i = 0; i < page[pg]->area[area]->nclient; i++) {
|
2006-02-02 21:04:15 +03:00
|
|
|
if(i == page[pg]->area[area]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len += type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(len <= fcall->offset)
|
2006-02-01 18:27:53 +03:00
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
|
|
|
for(; i < page[pg]->area[area]->nclient; i++) {
|
2006-02-02 21:04:15 +03:00
|
|
|
if(i == page[pg]->area[area]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += len;
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Fevent:
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_enqueue_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
switch (qpath_type(m->qid.path)) {
|
|
|
|
case Droot:
|
2006-02-02 18:44:45 +03:00
|
|
|
fprintf(stderr, "%s", "Droot dir creation\n");
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = type_to_stat(&stat, "ctl", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "event", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "default", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "new", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-02 21:04:15 +03:00
|
|
|
for(i = 0; i < npage; i++) {
|
2006-02-04 18:17:54 +03:00
|
|
|
if(i == sel)
|
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += len;
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-01 16:25:02 +03:00
|
|
|
case Ddefault:
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = type_to_stat(&stat, "font", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "selcolor", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "normcolor", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "border", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "bar", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "inc", &m->qid);
|
2006-02-02 15:20:07 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "snap", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
break;
|
|
|
|
case Dpage:
|
2006-02-04 18:17:54 +03:00
|
|
|
if(pg == npage) {
|
|
|
|
Page *page = alloc_page();
|
|
|
|
m->qid.path = mkqpath(Dpage, page->id, 0, 0);
|
|
|
|
focus_page(page);
|
|
|
|
}
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = type_to_stat(&stat, "ctl", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "new", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-02 21:04:15 +03:00
|
|
|
for(i = 0; i < page[pg]->narea; i++) {
|
|
|
|
if(i == page[pg]->area[area]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += len;
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Darea:
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = type_to_stat(&stat, "ctl", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
for(i = 0; i < page[pg]->area[area]->nclient; i++) {
|
2006-02-02 21:04:15 +03:00
|
|
|
if(i == page[pg]->area[area]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-02-01 18:27:53 +03:00
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += len;
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Dclient:
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = type_to_stat(&stat, "border", &m->qid);
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "msgl=%d\n", fcall->count);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "bar", &m->qid);
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "msgl=%d\n", fcall->count);
|
2006-02-02 15:20:07 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "name", &m->qid);
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "msgl=%d\n", fcall->count);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "geometry", &m->qid);
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "msgl=%d\n", fcall->count);
|
2006-02-02 15:20:07 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "ctl", &m->qid);
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "msgl=%d\n", fcall->count);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
break;
|
|
|
|
case Fctl:
|
2006-02-04 17:13:11 +03:00
|
|
|
return Enoperm;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
case Ffont:
|
2006-02-03 20:11:22 +03:00
|
|
|
if((fcall->count = strlen(def.font)))
|
|
|
|
memcpy(p, def.font, fcall->count);
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
|
|
|
case Fevent:
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_enqueue_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Fselcolor:
|
2006-02-03 20:11:22 +03:00
|
|
|
if((fcall->count = strlen(def.selcolor)))
|
|
|
|
memcpy(p, def.selcolor, fcall->count);
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
|
|
|
case Fnormcolor:
|
2006-02-03 20:11:22 +03:00
|
|
|
if((fcall->count = strlen(def.normcolor)))
|
|
|
|
memcpy(p, def.normcolor, fcall->count);
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
|
|
|
case Fborder:
|
2006-02-02 18:44:45 +03:00
|
|
|
fprintf(stderr, "Fborder: qpath_type(m->qid.path)=%d, m->qid.dtype=%d\n",
|
|
|
|
qpath_type(m->qid.path), m->qid.dtype);
|
|
|
|
|
|
|
|
if(m->qid.dtype == Ddefault)
|
2006-02-01 18:27:53 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", def.border);
|
|
|
|
else
|
|
|
|
snprintf(buf, sizeof(buf), "%u", page[pg]->area[area]->client[cl]->frame.border);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-02 22:36:10 +03:00
|
|
|
case Fbar:
|
2006-02-02 18:44:45 +03:00
|
|
|
if(m->qid.dtype == Ddefault)
|
2006-02-02 22:36:10 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", def.bar);
|
2006-02-01 18:27:53 +03:00
|
|
|
else
|
2006-02-02 22:36:10 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", page[pg]->area[area]->client[cl]->frame.bar);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-02 15:20:07 +03:00
|
|
|
case Finc:
|
2006-02-03 18:15:36 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", def.inc);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
|
|
|
case Fgeom:
|
|
|
|
client = page[pg]->area[area]->client[cl];
|
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", client->frame.rect.x, client->frame.rect.y,
|
|
|
|
client->frame.rect.width, client->frame.rect.height);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Fsnap:
|
|
|
|
snprintf(buf, sizeof(buf), "%u", def.snap);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Fname:
|
2006-02-03 20:11:22 +03:00
|
|
|
if((fcall->count = strlen(page[pg]->area[area]->client[cl]->name)))
|
|
|
|
memcpy(p, page[pg]->area[area]->client[cl]->name, fcall->count);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
default:
|
2006-02-03 20:11:22 +03:00
|
|
|
return "invalid read";
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->id = RREAD;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xstat(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-01-30 21:43:32 +03:00
|
|
|
char *name;
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
2006-01-30 21:43:32 +03:00
|
|
|
name = qid_to_name(&m->qid);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!type_to_stat(&fcall->stat, name, &m->qid))
|
|
|
|
return Enofile;
|
|
|
|
fcall->id = RSTAT;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xwrite(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
char buf[256];
|
2006-02-03 20:11:22 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
|
|
|
unsigned short pgid, aid, cid;
|
2006-01-30 21:43:32 +03:00
|
|
|
unsigned short i;
|
2006-02-03 20:12:44 +03:00
|
|
|
int pg = 0, area = 0, cl = 0;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
|
|
|
|
|
|
|
pgid = qpath_pgid(m->qid.path);
|
|
|
|
aid = qpath_aid(m->qid.path);
|
|
|
|
cid = qpath_cid(m->qid.path);
|
|
|
|
|
|
|
|
if(pgid && ((pg = index_of_page_id(pgid)) == -1))
|
|
|
|
return Enofile;
|
|
|
|
if(aid && ((area = index_of_area_id(page[pg], aid)) == -1))
|
|
|
|
return Enofile;
|
|
|
|
if(cid && ((cl = index_of_client_id(page[pg]->area[area], cid)) == -1))
|
|
|
|
return Enofile;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
|
|
|
switch (qpath_type(m->qid.path)) {
|
|
|
|
case Fctl:
|
2006-02-02 18:44:45 +03:00
|
|
|
switch(m->qid.dtype) {
|
2006-02-02 00:24:07 +03:00
|
|
|
case Droot:
|
|
|
|
/* TODO: /ctl commands */
|
|
|
|
break;
|
|
|
|
case Dpage:
|
|
|
|
/* /TODO: /n/ctl commands */
|
|
|
|
break;
|
|
|
|
case Darea:
|
|
|
|
/* /TODO: /n/{float,n}/ctl commands */
|
|
|
|
break;
|
|
|
|
case Dclient:
|
|
|
|
/* /TODO: /n/{float,n}/n/ctl commands */
|
|
|
|
break;
|
|
|
|
default:
|
2006-02-03 20:11:22 +03:00
|
|
|
return Enocommand;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Ffont:
|
2006-02-02 00:24:07 +03:00
|
|
|
if(def.font)
|
|
|
|
free(def.font);
|
2006-02-03 20:11:22 +03:00
|
|
|
def.font = cext_emallocz(fcall->count + 1);
|
|
|
|
memcpy(def.font, fcall->data, fcall->count);
|
2006-02-02 00:24:07 +03:00
|
|
|
XFreeFont(dpy, xfont);
|
|
|
|
xfont = blitz_getfont(dpy, def.font);
|
|
|
|
/* TODO: update geometry */
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-02 00:24:07 +03:00
|
|
|
case Fselcolor:
|
2006-02-03 20:11:22 +03:00
|
|
|
if((fcall->count != 24)
|
|
|
|
|| (fcall->data[0] != '#') || (fcall->data[8] != '#')
|
|
|
|
|| (fcall->data[16] != '#')
|
|
|
|
)
|
|
|
|
return "wrong color format";
|
|
|
|
memcpy(def.selcolor, fcall->data, fcall->count);
|
|
|
|
def.selcolor[fcall->count] = 0;
|
2006-02-02 22:08:34 +03:00
|
|
|
blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
|
|
|
|
XSetForeground(dpy, gc_xor, def.sel.bg);
|
2006-02-02 00:24:07 +03:00
|
|
|
/* TODO: update color */
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-02 00:24:07 +03:00
|
|
|
case Fnormcolor:
|
2006-02-03 20:11:22 +03:00
|
|
|
if((fcall->count != 24)
|
|
|
|
|| (fcall->data[0] != '#') || (fcall->data[8] != '#')
|
|
|
|
|| (fcall->data[16] != '#')
|
|
|
|
)
|
|
|
|
return "wrong color format";
|
|
|
|
memcpy(def.normcolor, fcall->data, fcall->count);
|
|
|
|
def.normcolor[fcall->count] = 0;
|
2006-02-02 22:08:34 +03:00
|
|
|
blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
|
2006-02-02 00:24:07 +03:00
|
|
|
/* TODO: update color */
|
|
|
|
break;
|
|
|
|
case Fsnap:
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return "snap value out of range 0..0xffff";
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-02-02 21:14:34 +03:00
|
|
|
i = cext_strtonum(buf, 0, 0xffff, &err);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(err)
|
|
|
|
return "snap value out of range 0..0xffff";
|
2006-02-02 00:24:07 +03:00
|
|
|
def.snap = i;
|
|
|
|
break;
|
|
|
|
case Fborder:
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return "border value out of range 0..0xffff";
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-02-02 00:24:07 +03:00
|
|
|
i = cext_strtonum(buf, 0, 0xffff, &err);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(err)
|
|
|
|
return "border value out of range 0..0xffff";
|
2006-02-02 18:44:45 +03:00
|
|
|
if(m->qid.dtype == Ddefault)
|
2006-02-02 00:24:07 +03:00
|
|
|
def.border = i;
|
|
|
|
else {
|
|
|
|
page[pg]->area[area]->client[cl]->frame.border = i;
|
|
|
|
/* TODO: resize client */
|
|
|
|
}
|
|
|
|
break;
|
2006-02-02 22:36:10 +03:00
|
|
|
case Fbar:
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return "bar value out of range 0, 1";
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-02-02 00:24:07 +03:00
|
|
|
i = cext_strtonum(buf, 0, 1, &err);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(err)
|
|
|
|
return "bar value out of range 0, 1";
|
2006-02-02 18:44:45 +03:00
|
|
|
if(m->qid.dtype == Ddefault)
|
2006-02-02 00:24:07 +03:00
|
|
|
def.border = i;
|
|
|
|
else {
|
|
|
|
page[pg]->area[area]->client[cl]->frame.border = i;
|
|
|
|
/* TODO: resize client */
|
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-02 15:20:07 +03:00
|
|
|
case Finc:
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return "increment value out of range 0, 1";
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-02-02 15:20:07 +03:00
|
|
|
i = cext_strtonum(buf, 0, 1, &err);
|
2006-02-03 20:11:22 +03:00
|
|
|
if(err)
|
|
|
|
return "increment value out of range 0, 1";
|
2006-02-03 18:15:36 +03:00
|
|
|
def.inc = i;
|
|
|
|
/* TODO: resize all clients */
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
|
|
|
case Fgeom:
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return "geometry values out of range";
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-02-02 15:20:07 +03:00
|
|
|
blitz_strtorect(&rect, &page[pg]->area[area]->client[cl]->frame.rect, buf);
|
|
|
|
/* TODO: resize client */
|
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
default:
|
2006-02-03 20:11:22 +03:00
|
|
|
return "invalid write";
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->id = RWRITE;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xclunk(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
2006-01-30 21:43:32 +03:00
|
|
|
cext_array_detach((void **)c->map, m, &c->mapsz);
|
|
|
|
free(m);
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->id = RCLUNK;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-02-03 20:11:22 +03:00
|
|
|
do_fcall(IXPConn *c)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
static Fcall fcall;
|
2006-01-30 21:43:32 +03:00
|
|
|
unsigned int msize;
|
2006-02-03 20:11:22 +03:00
|
|
|
char *errstr;
|
|
|
|
|
|
|
|
if((msize = ixp_server_receive_fcall(c, &fcall))) {
|
2006-02-03 22:02:37 +03:00
|
|
|
fprintf(stderr, "do_fcall=%d\n", fcall.id);
|
2006-02-03 20:11:22 +03:00
|
|
|
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 TOPEN: errstr = xopen(c, &fcall); break;
|
|
|
|
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-01-30 21:43:32 +03:00
|
|
|
}
|
2006-02-03 20:11:22 +03:00
|
|
|
if(errstr)
|
|
|
|
ixp_server_respond_error(c, &fcall, errstr);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
void
|
2006-01-30 21:43:32 +03:00
|
|
|
do_pend_fcall(char *event)
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
Fcall *fcall;
|
|
|
|
for(i = 0; (i < srv.connsz) && srv.conn[i]; i++) {
|
|
|
|
IXPConn *c = srv.conn[i];
|
|
|
|
/* all pending TREADs are on /event, so no qid checking necessary */
|
2006-02-03 20:11:22 +03:00
|
|
|
while((fcall = ixp_server_dequeue_fcall(c, TREAD))) {
|
2006-01-30 21:43:32 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
|
|
|
unsigned char *p = fcall->data;
|
|
|
|
|
|
|
|
if(!m) {
|
2006-02-03 20:11:22 +03:00
|
|
|
if(ixp_server_respond_error(c, fcall, Enofid))
|
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
else if(qpath_type(m->qid.path) == Fevent) {
|
|
|
|
fcall->count = strlen(event);
|
|
|
|
memcpy(p, event, fcall->count);
|
|
|
|
fcall->id = RREAD;
|
2006-02-03 20:11:22 +03:00
|
|
|
if(ixp_server_respond_fcall(c, fcall))
|
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
free(fcall);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
void
|
2006-02-03 20:11:22 +03:00
|
|
|
new_ixp_conn(IXPConn *c)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
int fd = ixp_accept_sock(c->fd);
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fd >= 0)
|
|
|
|
ixp_server_open_conn(c->srv, fd, do_fcall, ixp_server_close_conn);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|