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/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
|
|
|
|
2006-02-10 00:48:01 +03:00
|
|
|
static char E9pversion[] = "9P version not supported";
|
|
|
|
static char Enoperm[] = "permission denied";
|
|
|
|
static char Enofid[] = "fid not found";
|
|
|
|
static char Enofile[] = "file not found";
|
|
|
|
static char Enomode[] = "mode not supported";
|
|
|
|
static char Enofunc[] = "function not supported";
|
|
|
|
static char Enocommand[] = "command not supported";
|
|
|
|
|
2006-02-10 11:13:35 +03:00
|
|
|
#define WMII_IOUNIT 2048
|
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
/*
|
|
|
|
* filesystem specification
|
|
|
|
* / Droot
|
2006-02-09 21:40:12 +03:00
|
|
|
* /def/ Ddef
|
|
|
|
* /def/border Fborder 0..n
|
|
|
|
* /def/snap Fsnap 0..n
|
|
|
|
* /def/inc Finc 0..n
|
2006-02-10 20:32:35 +03:00
|
|
|
* /def/font Ffont xlib font name
|
|
|
|
* /def/selcolors Fselcolors sel color
|
|
|
|
* /def/normcolors Fnormcolors normal colors
|
2006-02-09 21:40:12 +03:00
|
|
|
* /keys/ Dkeys
|
|
|
|
* /keys/foo Fkey
|
2006-02-10 00:48:01 +03:00
|
|
|
* /bar/ Dbar
|
|
|
|
* /bar/expand Fexpand id of expandable label
|
2006-02-10 17:59:30 +03:00
|
|
|
* /bar/new/ Dlabel
|
|
|
|
* /bar/1/ Dlabel
|
2006-02-10 00:48:01 +03:00
|
|
|
* /bar/1/data Fdata <arbitrary data which gets displayed>
|
2006-02-10 20:32:35 +03:00
|
|
|
* /bar/1/colors Fcolors <#RRGGBB> <#RRGGBB> <#RRGGBB>
|
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/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/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
|
|
|
*/
|
|
|
|
|
2006-02-06 17:20:25 +03:00
|
|
|
Qid root_qid;
|
2006-02-02 00:24:07 +03:00
|
|
|
const char *err;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
|
|
|
/* IXP stuff */
|
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
/**
|
|
|
|
* Qid->path is calculated related to the index of the associated structure.
|
|
|
|
* i1 is associated to page, key or label
|
|
|
|
* i2 is associated to area
|
|
|
|
* i3 is associated to client
|
|
|
|
* ie /sel/sel/ctl is i1id = sel page id, i2id = sel area id , i3id = 0 (no id)
|
|
|
|
*/
|
2006-02-02 16:50:04 +03:00
|
|
|
unsigned long long
|
2006-02-10 17:59:30 +03:00
|
|
|
mkqpath(unsigned char type, unsigned short i1id, unsigned short i2id, unsigned short i3id)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
return ((unsigned long long) type << 48) | ((unsigned long long) i1id << 32)
|
|
|
|
| ((unsigned long long) i2id << 16) | (unsigned long long) i3id;
|
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-10 17:59:30 +03:00
|
|
|
qpath_i1id(unsigned long long path)
|
2006-01-31 15:25:23 +03:00
|
|
|
{
|
|
|
|
return (path >> 32) & 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned short
|
2006-02-10 17:59:30 +03:00
|
|
|
qpath_i2id(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-10 17:59:30 +03:00
|
|
|
qpath_i3id(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
|
|
|
}
|
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
static void
|
|
|
|
decode_qpath(Qid *qid, unsigned char *type, int *i1, int *i2, int *i3)
|
|
|
|
{
|
|
|
|
unsigned short i1id = qpath_i1id(qid->path);
|
|
|
|
unsigned short i2id = qpath_i2id(qid->path);
|
|
|
|
unsigned short i3id = qpath_i3id(qid->path);
|
|
|
|
*type = qpath_type(qid->path);
|
|
|
|
|
|
|
|
if(i1id) {
|
|
|
|
switch(*type) {
|
|
|
|
case Fkey: *i1 = kid_to_index(i1id); break;
|
|
|
|
case Fdata:
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fcolors:
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dlabel: *i1 = lid_to_index(i1id); break;
|
2006-02-16 13:53:10 +03:00
|
|
|
default: *i1 = pid_to_index(i1id); break;
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
|
|
|
if(i2id && (*i1 != -1)) {
|
|
|
|
*i2 = aid_to_index(page[*i1], i2id);
|
|
|
|
if(i3id && (*i2 != -1))
|
|
|
|
*i3 = cid_to_index(page[*i1]->area[*i2], i3id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
static char *
|
|
|
|
qid_to_name(Qid *qid)
|
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
|
|
|
int i1 = 0, i2 = 0, i3 = 0;
|
2006-01-30 21:43:32 +03:00
|
|
|
static char buf[32];
|
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(qid, &type, &i1, &i2, &i3);
|
|
|
|
if((i1 == -1) || (i2 == -1) || (i3 == -1))
|
|
|
|
return 0;
|
2006-02-03 20:11:22 +03:00
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
switch(type) {
|
2006-01-30 21:43:32 +03:00
|
|
|
case Droot: return "/"; break;
|
2006-02-09 21:40:12 +03:00
|
|
|
case Ddef: return "def"; break;
|
|
|
|
case Dkeys: return "keys"; break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Dbar: return "bar"; break;
|
2006-01-31 01:48:41 +03:00
|
|
|
case Dpage:
|
2006-02-10 17:59:30 +03:00
|
|
|
if(i1 == sel)
|
2006-01-31 15:25:23 +03:00
|
|
|
return "sel";
|
2006-02-10 17:59:30 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i1 + 1);
|
2006-01-31 15:25:23 +03:00
|
|
|
return buf;
|
|
|
|
break;
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dlabel:
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i1 + 1);
|
2006-02-10 00:48:01 +03:00
|
|
|
return buf;
|
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Darea:
|
2006-02-10 17:59:30 +03:00
|
|
|
if(!i2) {
|
|
|
|
if(page[i1]->sel)
|
2006-02-02 21:04:15 +03:00
|
|
|
return "float";
|
|
|
|
else
|
|
|
|
return "sel";
|
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
if(page[i1]->sel == i2)
|
2006-01-31 15:25:23 +03:00
|
|
|
return "sel";
|
2006-02-10 17:59:30 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i2 + 1);
|
2006-01-31 15:25:23 +03:00
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case Dclient:
|
2006-02-10 17:59:30 +03:00
|
|
|
if(page[i1]->area[i2]->sel == i3)
|
2006-01-31 19:52:14 +03:00
|
|
|
return "sel";
|
2006-02-10 17:59:30 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i3 + 1);
|
2006-01-30 21:43:32 +03:00
|
|
|
return buf;
|
|
|
|
break;
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fselcolors: return "selcolors"; break;
|
|
|
|
case Fnormcolors: return "normcolors"; break;
|
|
|
|
case Ffont: return "font"; break;
|
|
|
|
case Fcolors: return "colors"; break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Fdata: return "data"; break;
|
|
|
|
case Fexpand: return "expand"; break;
|
2006-01-30 21:43:32 +03:00
|
|
|
case Fctl: return "ctl"; break;
|
2006-01-31 01:48:41 +03:00
|
|
|
case Fborder: return "border"; break;
|
|
|
|
case Fsnap: return "border"; 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;
|
2006-02-10 17:59:30 +03:00
|
|
|
case Fkey: return key[i1]->name; break;
|
2006-01-30 21:43:32 +03:00
|
|
|
default: return nil; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-02-10 17:59:30 +03:00
|
|
|
name_to_type(char *name, unsigned char dir_type)
|
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-02-10 17:59:30 +03:00
|
|
|
switch(dir_type) {
|
|
|
|
case Droot: return Dpage; break;
|
|
|
|
case Dbar: return Dlabel; break;
|
|
|
|
case Dpage: return Darea; break;
|
|
|
|
}
|
2006-01-31 15:25:23 +03:00
|
|
|
}
|
2006-02-24 12:38:48 +03:00
|
|
|
if(!strncmp(name, "bar", 4))
|
|
|
|
return Dbar;
|
2006-02-09 21:40:12 +03:00
|
|
|
if(!strncmp(name, "def", 4))
|
|
|
|
return Ddef;
|
|
|
|
if(!strncmp(name, "keys", 5))
|
|
|
|
return Dkeys;
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!strncmp(name, "ctl", 4))
|
|
|
|
return Fctl;
|
|
|
|
if(!strncmp(name, "event", 6))
|
|
|
|
return Fevent;
|
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 15:20:07 +03:00
|
|
|
if(!strncmp(name, "inc", 4))
|
|
|
|
return Finc;
|
|
|
|
if(!strncmp(name, "geometry", 9))
|
|
|
|
return Fgeom;
|
2006-02-10 00:48:01 +03:00
|
|
|
if(!strncmp(name, "expand", 7))
|
|
|
|
return Fexpand;
|
2006-02-10 20:32:35 +03:00
|
|
|
if(!strncmp(name, "colors", 7))
|
|
|
|
return Fcolors;
|
|
|
|
if(!strncmp(name, "selcolors", 10))
|
|
|
|
return Fselcolors;
|
|
|
|
if(!strncmp(name, "normcolors", 11))
|
|
|
|
return Fnormcolors;
|
|
|
|
if(!strncmp(name, "font", 5))
|
|
|
|
return Ffont;
|
2006-02-10 00:48:01 +03:00
|
|
|
if(!strncmp(name, "data", 5))
|
|
|
|
return Fdata;
|
2006-02-10 17:59:30 +03:00
|
|
|
if(name_to_key(name))
|
2006-02-09 21:40:12 +03:00
|
|
|
return Fkey;
|
2006-02-02 15:20:07 +03:00
|
|
|
if(!strncmp(name, "sel", 4))
|
2006-01-31 19:52:14 +03:00
|
|
|
goto dyndir;
|
2006-02-06 11:20:23 +03:00
|
|
|
i = (unsigned short) cext_strtonum(name, 1, 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-10 17:59:30 +03:00
|
|
|
/*fprintf(stderr, "nametotype: dir_type = %d\n", dir_type);*/
|
|
|
|
switch(dir_type) {
|
2006-01-31 19:52:14 +03:00
|
|
|
case Droot: return Dpage; break;
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dbar: return Dlabel; 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
|
2006-02-06 11:20:23 +03:00
|
|
|
mkqid(Qid *dir, char *wname, Qid *new, Bool iswalk)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char dir_type;
|
|
|
|
int dir_i1 = 0, dir_i2 = 0, dir_i3 = 0;
|
|
|
|
int type, i;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(dir, &dir_type, &dir_i1, &dir_i2, &dir_i3);
|
|
|
|
if((dir_i1 == -1) || (dir_i2 == -1) || (dir_i3 == -1))
|
2006-02-03 20:11:22 +03:00
|
|
|
return -1;
|
2006-02-10 17:59:30 +03:00
|
|
|
type = name_to_type(wname, dir_type);
|
|
|
|
|
|
|
|
new->dir_type = dir_type;
|
2006-01-30 21:43:32 +03:00
|
|
|
new->version = 0;
|
|
|
|
switch(type) {
|
|
|
|
case Droot:
|
|
|
|
*new = root_qid;
|
|
|
|
break;
|
2006-02-09 21:40:12 +03:00
|
|
|
case Ddef:
|
2006-01-31 15:25:23 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-02-09 21:40:12 +03:00
|
|
|
new->path = mkqpath(Ddef, 0, 0, 0);
|
|
|
|
break;
|
|
|
|
case Dkeys:
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
new->path = mkqpath(Dkeys, 0, 0, 0);
|
2006-01-31 15:25:23 +03:00
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Dbar:
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
new->path = mkqpath(Dbar, 0, 0, 0);
|
|
|
|
break;
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dlabel:
|
2006-02-10 00:48:01 +03:00
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
if(!strncmp(wname, "new", 4)) {
|
|
|
|
if(iswalk)
|
2006-02-10 17:59:30 +03:00
|
|
|
new->path = mkqpath(Dlabel, new_label()->id, 0, 0);
|
2006-02-10 00:48:01 +03:00
|
|
|
else
|
2006-02-10 17:59:30 +03:00
|
|
|
new->path = mkqpath(Dlabel, 0,0 ,0);
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
i = cext_strtonum(wname, 1, 0xffff, &err);
|
2006-02-10 17:59:30 +03:00
|
|
|
if(err || (i - 1 >= nlabel))
|
2006-02-10 00:48:01 +03:00
|
|
|
return -1;
|
2006-02-10 17:59:30 +03:00
|
|
|
new->path = mkqpath(Dlabel, label[i - 1]->id, 0, 0);
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-01-31 15:25:23 +03:00
|
|
|
case Dpage:
|
2006-01-30 21:43:32 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-02-06 11:20:23 +03:00
|
|
|
if(!strncmp(wname, "new", 4)) {
|
|
|
|
if(iswalk) {
|
|
|
|
Page *p = alloc_page();
|
|
|
|
new->path = mkqpath(Dpage, p->id, 0, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new->path = mkqpath(Dpage, 0, 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-06 11:20:23 +03:00
|
|
|
i = cext_strtonum(wname, 1, 0xffff, &err);
|
|
|
|
if(err || (i - 1 >= npage))
|
2006-01-30 21:43:32 +03:00
|
|
|
return -1;
|
2006-02-06 11:20:23 +03:00
|
|
|
new->path = mkqpath(Dpage, page[i - 1]->id, 0, 0);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Darea:
|
2006-02-10 17:59:30 +03:00
|
|
|
{
|
|
|
|
Page *p = page[dir_i1];
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
if(!strncmp(wname, "new", 4)) {
|
|
|
|
if(iswalk) {
|
2006-02-19 17:56:16 +03:00
|
|
|
Area *a = new_column(p->area[p->sel]);
|
|
|
|
if(!a)
|
|
|
|
return -1;
|
2006-02-10 17:59:30 +03:00
|
|
|
new->path = mkqpath(Darea, p->id, a->id, 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
new->path = mkqpath(Darea, p->id, 0, 0); /* simple stat */
|
|
|
|
}
|
2006-02-16 13:53:10 +03:00
|
|
|
else if(!strncmp(wname, "sel", 4)) {
|
2006-02-10 17:59:30 +03:00
|
|
|
new->path = mkqpath(Darea, p->id, p->area[p->sel]->id, 0);
|
2006-02-16 13:53:10 +03:00
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
else {
|
|
|
|
i = cext_strtonum(wname, 1, 0xffff, &err);
|
|
|
|
if(err || (i - 1 >= p->narea))
|
|
|
|
return -1;
|
|
|
|
new->path = mkqpath(Darea, p->id, p->area[i - 1]->id, 0);
|
2006-02-06 11:20:23 +03:00
|
|
|
}
|
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-10 17:59:30 +03:00
|
|
|
{
|
|
|
|
Page *p = page[dir_i1];
|
|
|
|
Area *a = p->area[dir_i2];
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
if(!strncmp(wname, "sel", 4)) {
|
|
|
|
if(!a->nclient)
|
|
|
|
return -1;
|
|
|
|
new->path = mkqpath(Dclient, p->id, a->id, a->client[a->sel]->id);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
i = cext_strtonum(wname, 1, 0xffff, &err);
|
|
|
|
if(err || (i - 1 >= a->nclient))
|
|
|
|
return -1;
|
|
|
|
new->path = mkqpath(Dclient, p->id, a->id, a->client[i - 1]->id);
|
|
|
|
}
|
2006-01-31 19:52:14 +03:00
|
|
|
}
|
2006-01-31 15:25:23 +03:00
|
|
|
break;
|
2006-02-09 21:40:12 +03:00
|
|
|
case Fkey:
|
|
|
|
{
|
|
|
|
Key *k;
|
2006-02-10 17:59:30 +03:00
|
|
|
if(!(k = name_to_key(wname)))
|
2006-02-09 21:40:12 +03:00
|
|
|
return -1;
|
|
|
|
new->type = IXP_QTFILE;
|
|
|
|
new->path = mkqpath(Fkey, k->id, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Fdata:
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fcolors:
|
2006-02-10 19:09:59 +03:00
|
|
|
if((dir_type == Dlabel) && (dir_i1 >= nlabel))
|
2006-02-10 00:48:01 +03:00
|
|
|
return -1;
|
2006-01-30 21:43:32 +03:00
|
|
|
default:
|
|
|
|
new->type = IXP_QTFILE;
|
2006-02-10 17:59:30 +03:00
|
|
|
new->path = mkqpath(type, qpath_i1id(dir->path), qpath_i2id(dir->path), qpath_i3id(dir->path));
|
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-08 14:44:51 +03:00
|
|
|
/*fprintf(stderr, "wm: xwalk: fid=%d\n", fcall->fid);*/
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!(m = ixp_server_fid2map(c, fcall->fid)))
|
|
|
|
return Enofid;
|
2006-02-08 14:44:51 +03:00
|
|
|
/*fprintf(stderr, "wm: xwalk1: fid=%d\n", fcall->fid);*/
|
2006-02-03 20:11:22 +03:00
|
|
|
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)
|
2006-02-06 11:20:23 +03:00
|
|
|
&& !mkqid(&dir, fcall->wname[nwqid], &fcall->wqid[nwqid], True); nwqid++)
|
2006-02-02 18:44:45 +03:00
|
|
|
{
|
2006-02-03 20:11:22 +03:00
|
|
|
dir = fcall->wqid[nwqid];
|
2006-02-02 18:44:45 +03:00
|
|
|
}
|
2006-02-03 22:02:37 +03:00
|
|
|
if(!nwqid) {
|
2006-02-16 13:53:10 +03:00
|
|
|
fprintf(stderr, "%s", "xwalk: no such 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) {
|
2006-02-16 13:53:10 +03:00
|
|
|
/*fprintf(stderr, "wm: xwalk4: newfid=%d\n", fcall->newfid);*/
|
2006-02-03 20:11:22 +03:00
|
|
|
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-12 03:49:33 +03:00
|
|
|
static char *
|
|
|
|
xcreate(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
|
|
|
|
|
|
|
if(!(fcall->mode | IXP_OWRITE))
|
|
|
|
return Enomode;
|
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
|
|
|
if(!strncmp(fcall->name, ".", 2) || !strncmp(fcall->name, "..", 3))
|
|
|
|
return "illegal file name";
|
|
|
|
if(qpath_type(m->qid.path) != Dkeys)
|
|
|
|
return Enoperm;
|
|
|
|
grab_key(create_key(fcall->name));
|
|
|
|
mkqid(&m->qid, fcall->name, &m->qid, False);
|
|
|
|
fcall->id = RCREATE;
|
|
|
|
fcall->qid = m->qid;
|
|
|
|
fcall->iounit = WMII_IOUNIT;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
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;
|
2006-02-10 11:13:35 +03:00
|
|
|
fcall->iounit = WMII_IOUNIT;
|
2006-02-03 20:11:22 +03:00
|
|
|
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;
|
2006-02-06 11:20:23 +03:00
|
|
|
mkqid(dir, name, &stat->qid, False);
|
2006-01-30 21:43:32 +03:00
|
|
|
return ixp_sizeof_stat(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
2006-02-10 17:59:30 +03:00
|
|
|
type_to_stat(Stat *stat, char *wname, Qid *dir)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char dir_type;
|
|
|
|
int dir_i1 = 0, dir_i2 = 0, dir_i3 = 0;
|
|
|
|
int type;
|
2006-02-02 15:20:07 +03:00
|
|
|
char buf[32];
|
|
|
|
Client *c;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(dir, &dir_type, &dir_i1, &dir_i2, &dir_i3);
|
|
|
|
if((dir_i1 == -1) || (dir_i2 == -1) || (dir_i3 == -1))
|
|
|
|
return -1;
|
|
|
|
type = name_to_type(wname, dir_type);
|
2006-02-03 22:02:37 +03:00
|
|
|
|
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:
|
2006-02-09 21:40:12 +03:00
|
|
|
case Ddef:
|
|
|
|
case Dkeys:
|
2006-02-10 00:48:01 +03:00
|
|
|
case Dbar:
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dlabel:
|
2006-02-02 19:19:32 +03:00
|
|
|
case Droot:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMDIR | DMREAD | DMEXEC);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
case Fctl:
|
|
|
|
case Fevent:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMREAD);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fborder:
|
2006-02-24 12:38:48 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d", def.border);
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-01-31 19:52:14 +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), "%d", def.inc);
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
|
|
|
case Fgeom:
|
2006-02-10 17:59:30 +03:00
|
|
|
c = page[dir_i1]->area[dir_i2]->client[dir_i3];
|
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);
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
2006-01-31 19:52:14 +03:00
|
|
|
case Fsnap:
|
|
|
|
snprintf(buf, sizeof(buf), "%d", def.snap);
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 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-10 17:59:30 +03:00
|
|
|
c = page[dir_i1]->area[dir_i2]->client[dir_i3];
|
|
|
|
return mkstat(stat, dir, wname, strlen(c->name), DMREAD);
|
2006-01-31 19:52:14 +03:00
|
|
|
break;
|
2006-02-09 21:40:12 +03:00
|
|
|
case Fkey:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMWRITE);
|
2006-02-09 21:40:12 +03:00
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Fexpand:
|
|
|
|
snprintf(buf, sizeof(buf), "%u", iexpand + 1);
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
|
|
|
case Fdata:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, (dir_i1 == nlabel) ? 0 : strlen(label[dir_i1]->data), DMREAD | DMWRITE);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fcolors:
|
|
|
|
case Fselcolors:
|
|
|
|
case Fnormcolors:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 23, DMREAD | DMWRITE);
|
2006-02-10 20:32:35 +03:00
|
|
|
case Ffont:
|
|
|
|
return mkstat(stat, dir, wname, strlen(def.font), DMREAD | DMWRITE);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-02-10 00:48:01 +03:00
|
|
|
static char *
|
|
|
|
xremove(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
|
|
|
int i1 = 0, i2 = 0, i3 = 0;
|
2006-02-10 00:48:01 +03:00
|
|
|
|
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(&m->qid, &type, &i1, &i2, &i3);
|
|
|
|
if((i1 == -1) || (i2 == -1) || (i3 == -1))
|
2006-02-10 00:48:01 +03:00
|
|
|
return Enofile;
|
2006-02-10 17:59:30 +03:00
|
|
|
switch(type) {
|
2006-02-28 12:04:48 +03:00
|
|
|
case Dpage:
|
|
|
|
if(destroy_page(page[i1]) == page[i1])
|
|
|
|
return Enoperm;
|
|
|
|
break;
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dlabel:
|
|
|
|
{
|
|
|
|
Label *l = label[i1];
|
|
|
|
/* clunk */
|
|
|
|
cext_array_detach((void **)c->map, m, &c->mapsz);
|
|
|
|
free(m);
|
|
|
|
/* now detach the label */
|
|
|
|
detach_label(l);
|
|
|
|
free(l);
|
|
|
|
if(iexpand >= nlabel)
|
|
|
|
iexpand = 0;
|
|
|
|
draw_bar();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Fkey:
|
|
|
|
{
|
|
|
|
Key *k = key[i1];
|
|
|
|
ungrab_key(k);
|
|
|
|
destroy_key(k);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return Enoperm;
|
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
fcall->id = RREMOVE;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
|
|
|
|
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;
|
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-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
|
|
|
int i1 = 0, i2 = 0, i3 = 0;
|
2006-02-02 15:20:07 +03:00
|
|
|
Client *client;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(&m->qid, &type, &i1, &i2, &i3);
|
|
|
|
if((i1 == -1) || (i2 == -1) || (i3 == -1))
|
2006-02-03 20:11:22 +03:00
|
|
|
return Enofile;
|
|
|
|
|
|
|
|
fcall->count = 0;
|
|
|
|
if(fcall->offset) {
|
2006-02-10 17:59:30 +03:00
|
|
|
switch (type) {
|
2006-01-30 21:43:32 +03:00
|
|
|
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);
|
2006-02-10 11:13:35 +03:00
|
|
|
len += type_to_stat(&stat, "def", &m->qid);
|
2006-02-10 00:48:01 +03:00
|
|
|
len += type_to_stat(&stat, "keys", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "bar", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
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
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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;
|
2006-02-09 21:40:12 +03:00
|
|
|
case Dkeys:
|
|
|
|
/* jump to offset */
|
2006-02-10 17:59:30 +03:00
|
|
|
len = 0;
|
2006-02-09 21:40:12 +03:00
|
|
|
for(i = 0; i < nkey; i++) {
|
|
|
|
len += type_to_stat(&stat, key[i]->name, &m->qid);
|
|
|
|
if(len <= fcall->offset)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
|
|
|
for(; i < nkey; i++) {
|
|
|
|
len = type_to_stat(&stat, key[i]->name, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Dbar:
|
|
|
|
/* jump to offset */
|
|
|
|
len = type_to_stat(&stat, "expand", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "new", &m->qid);
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++) {
|
2006-02-10 00:48:01 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
|
|
|
len += type_to_stat(&stat, buf, &m->qid);
|
|
|
|
if(len <= fcall->offset)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
2006-02-10 17:59:30 +03:00
|
|
|
for(; i < nlabel; i++) {
|
2006-02-10 00:48:01 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Dpage:
|
|
|
|
/* jump to offset */
|
|
|
|
len = type_to_stat(&stat, "ctl", &m->qid);
|
|
|
|
len += type_to_stat(&stat, "new", &m->qid);
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < page[i1]->narea; i++) {
|
|
|
|
if(i == page[i1]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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 */
|
2006-02-10 17:59:30 +03:00
|
|
|
for(; i < page[i1]->narea; i++) {
|
|
|
|
if(i == page[i1]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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);
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < page[i1]->area[i2]->nclient; i++) {
|
|
|
|
if(i == page[i1]->area[i2]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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 */
|
2006-02-10 17:59:30 +03:00
|
|
|
for(; i < page[i1]->area[i2]->nclient; i++) {
|
|
|
|
if(i == page[i1]->area[i2]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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-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;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2006-02-10 17:59:30 +03:00
|
|
|
switch (type) {
|
2006-01-30 21:43:32 +03:00
|
|
|
case Droot:
|
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-10 11:13:35 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "def", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-10 00:48:01 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "keys", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
fcall->count += type_to_stat(&stat, "bar", &m->qid);
|
|
|
|
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
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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-09 21:40:12 +03:00
|
|
|
case Dkeys:
|
|
|
|
for(i = 0; i < nkey; i++) {
|
|
|
|
len = type_to_stat(&stat, key[i]->name, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Dbar:
|
|
|
|
fcall->count = type_to_stat(&stat, "expand", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
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-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++) {
|
2006-02-10 00:48:01 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
|
|
|
len = type_to_stat(&stat, buf, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 17:59:30 +03:00
|
|
|
case Dlabel:
|
|
|
|
if(i1 >= nlabel)
|
2006-02-10 00:48:01 +03:00
|
|
|
return Enofile;
|
2006-02-10 20:32:35 +03:00
|
|
|
fcall->count = type_to_stat(&stat, "colors", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-10 00:48:01 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "data", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
|
|
|
case Ddef:
|
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, "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);
|
2006-02-10 20:32:35 +03:00
|
|
|
fcall->count += type_to_stat(&stat, "selcolors", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
fcall->count += type_to_stat(&stat, "normcolors", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
fcall->count += type_to_stat(&stat, "font", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
|
|
|
case Dpage:
|
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-10 17:59:30 +03:00
|
|
|
for(i = 0; i < page[i1]->narea; i++) {
|
|
|
|
if(i == page[i1]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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);
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < page[i1]->area[i2]->nclient; i++) {
|
|
|
|
if(i == page[i1]->area[i2]->sel)
|
2006-02-04 18:17:54 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", "sel");
|
|
|
|
else
|
2006-02-06 11:20:23 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i + 1);
|
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-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, "name", &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, "geometry", &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, "ctl", &m->qid);
|
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;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Fevent:
|
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;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-01 18:27:53 +03:00
|
|
|
case Fborder:
|
2006-02-24 12:38:48 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", def.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 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:
|
2006-02-10 17:59:30 +03:00
|
|
|
client = page[i1]->area[i2]->client[i3];
|
2006-02-02 15:20:07 +03:00
|
|
|
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-10 17:59:30 +03:00
|
|
|
if((fcall->count = strlen(page[i1]->area[i2]->client[i3]->name)))
|
|
|
|
memcpy(p, page[i1]->area[i2]->client[i3]->name, fcall->count);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Fexpand:
|
|
|
|
snprintf(buf, sizeof(buf), "%u", iexpand + 1);
|
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
|
|
|
break;
|
|
|
|
case Fdata:
|
2006-02-10 17:59:30 +03:00
|
|
|
if(i1 >= nlabel)
|
2006-02-10 00:48:01 +03:00
|
|
|
return Enofile;
|
2006-02-10 17:59:30 +03:00
|
|
|
if((fcall->count = strlen(label[i1]->data)))
|
|
|
|
memcpy(p, label[i1]->data, fcall->count);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fcolors:
|
2006-02-10 17:59:30 +03:00
|
|
|
if(i1 >= nlabel)
|
2006-02-10 00:48:01 +03:00
|
|
|
return Enofile;
|
2006-02-10 17:59:30 +03:00
|
|
|
if((fcall->count = strlen(label[i1]->colstr)))
|
|
|
|
memcpy(p, label[i1]->colstr, fcall->count);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fselcolors:
|
|
|
|
if((fcall->count = strlen(def.selcolor)))
|
|
|
|
memcpy(p, def.selcolor, fcall->count);
|
|
|
|
break;
|
|
|
|
case Fnormcolors:
|
|
|
|
if((fcall->count = strlen(def.normcolor)))
|
|
|
|
memcpy(p, def.normcolor, fcall->count);
|
|
|
|
break;
|
|
|
|
case Ffont:
|
|
|
|
if((fcall->count = strlen(def.font)))
|
|
|
|
memcpy(p, def.font, fcall->count);
|
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
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);
|
2006-01-30 21:43:32 +03:00
|
|
|
unsigned short i;
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
|
|
|
int i1 = 0, i2 = 0, i3 = 0;
|
2006-02-16 17:28:51 +03:00
|
|
|
Client *cl;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofid;
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(&m->qid, &type, &i1, &i2, &i3);
|
|
|
|
if((i1 == -1) || (i2 == -1) || (i3 == -1))
|
2006-02-03 20:11:22 +03:00
|
|
|
return Enofile;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
|
|
|
switch (qpath_type(m->qid.path)) {
|
|
|
|
case Fctl:
|
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-02-10 17:59:30 +03:00
|
|
|
switch(m->qid.dir_type) {
|
2006-02-02 00:24:07 +03:00
|
|
|
case Droot:
|
2006-02-06 11:46:52 +03:00
|
|
|
if(!strncmp(buf, "quit", 5))
|
2006-02-08 13:07:30 +03:00
|
|
|
srv.running = 0;
|
2006-02-06 11:46:52 +03:00
|
|
|
else if(!strncmp(buf, "pager", 6))
|
|
|
|
pager();
|
|
|
|
else if(!strncmp(buf, "select", 6))
|
|
|
|
select_page(&buf[7]);
|
2006-02-16 03:05:16 +03:00
|
|
|
else if(!strncmp(buf, "warp ", 5)) {
|
|
|
|
char *err;
|
|
|
|
if((err = warp_mouse(&buf[5])))
|
|
|
|
return err;
|
|
|
|
}
|
2006-02-06 11:46:52 +03:00
|
|
|
else
|
|
|
|
return Enocommand;
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
|
|
|
case Dpage:
|
2006-02-19 18:21:01 +03:00
|
|
|
if(!strncmp(buf, "select ", 7))
|
|
|
|
select_area(page[i1]->area[page[i1]->sel], &buf[7]);
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
|
|
|
case Darea:
|
2006-02-14 14:06:16 +03:00
|
|
|
if(!strncmp(buf, "select ", 7)) {
|
|
|
|
Area *a = page[i1]->area[i2];
|
|
|
|
if(a->nclient)
|
|
|
|
select_client(a->client[a->sel], &buf[7]);
|
|
|
|
}
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
|
|
|
case Dclient:
|
2006-02-16 17:28:51 +03:00
|
|
|
cl = page[i1]->area[i2]->client[i3];
|
|
|
|
if(!strncmp(buf, "kill", 5))
|
|
|
|
kill_client(cl);
|
2006-02-24 11:52:20 +03:00
|
|
|
else if(!strncmp(buf, "sendtopage ", 11))
|
|
|
|
sendtopage_client(cl, &buf[11]);
|
|
|
|
else if(!strncmp(buf, "sendtoarea ", 11))
|
|
|
|
sendtoarea_client(cl, &buf[11]);
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
|
|
|
default:
|
2006-02-06 11:46:52 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-02-02 00:24:07 +03:00
|
|
|
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-24 12:38:48 +03:00
|
|
|
def.border = i;
|
|
|
|
resize_all_clients();
|
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;
|
2006-02-24 12:38:48 +03:00
|
|
|
resize_all_clients();
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
|
|
|
case Fgeom:
|
2006-02-16 17:28:51 +03:00
|
|
|
cl = page[i1]->area[i2]->client[i3];
|
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return "geometry values out of range";
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
|
|
|
blitz_strtorect(&rect, &cl->frame.rect, buf);
|
|
|
|
resize_client(cl, &cl->frame.rect, 0);
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
case Fexpand:
|
|
|
|
{
|
|
|
|
const char *err;
|
|
|
|
if(fcall->count && fcall->count < 16) {
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
|
|
|
i = (unsigned short) cext_strtonum(buf, 1, 0xffff, &err);
|
2006-02-10 17:59:30 +03:00
|
|
|
if(!err && (i - 1 < nlabel)) {
|
|
|
|
iexpand = i - 1;
|
2006-02-10 00:48:01 +03:00
|
|
|
draw_bar();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Enofile;
|
|
|
|
break;
|
|
|
|
case Fdata:
|
|
|
|
{
|
|
|
|
unsigned int len = fcall->count;
|
2006-02-10 17:59:30 +03:00
|
|
|
if(len >= sizeof(label[i1]->data))
|
|
|
|
len = sizeof(label[i1]->data) - 1;
|
|
|
|
memcpy(label[i1]->data, fcall->data, len);
|
|
|
|
label[i1]->data[len] = 0;
|
2006-02-10 00:48:01 +03:00
|
|
|
draw_bar();
|
|
|
|
}
|
|
|
|
break;
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fcolors:
|
2006-02-10 17:59:30 +03:00
|
|
|
if((i1 >= nlabel) || (fcall->count != 23)
|
2006-02-10 00:48:01 +03:00
|
|
|
|| (fcall->data[0] != '#') || (fcall->data[8] != '#')
|
|
|
|
|| (fcall->data[16] != '#')
|
|
|
|
)
|
|
|
|
return "wrong color format";
|
2006-02-10 17:59:30 +03:00
|
|
|
memcpy(label[i1]->colstr, fcall->data, fcall->count);
|
|
|
|
label[i1]->colstr[fcall->count] = 0;
|
|
|
|
blitz_loadcolor(dpy, screen, label[i1]->colstr, &label[i1]->color);
|
2006-02-10 00:48:01 +03:00
|
|
|
draw_bar();
|
|
|
|
break;
|
2006-02-10 20:32:35 +03:00
|
|
|
case Fselcolors:
|
2006-02-10 22:52:32 +03:00
|
|
|
if((fcall->count != 23)
|
2006-02-10 20:32:35 +03:00
|
|
|
|| (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;
|
|
|
|
blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
|
|
|
|
for(i = 0; i < nclient; i++)
|
2006-02-11 17:22:42 +03:00
|
|
|
if(client[i]->area->page == page[sel])
|
2006-02-10 20:32:35 +03:00
|
|
|
draw_client(client[i]);
|
|
|
|
break;
|
|
|
|
case Fnormcolors:
|
2006-02-10 22:52:32 +03:00
|
|
|
if((fcall->count != 23)
|
2006-02-10 20:32:35 +03:00
|
|
|
|| (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;
|
|
|
|
blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
|
|
|
|
for(i = 0; i < nclient; i++)
|
2006-02-11 17:22:42 +03:00
|
|
|
if(client[i]->area->page == page[sel])
|
2006-02-10 20:32:35 +03:00
|
|
|
draw_client(client[i]);
|
|
|
|
break;
|
|
|
|
case Ffont:
|
|
|
|
if(def.font)
|
|
|
|
free(def.font);
|
|
|
|
def.font = cext_emallocz(fcall->count + 1);
|
|
|
|
memcpy(def.font, fcall->data, fcall->count);
|
|
|
|
XFreeFont(dpy, xfont);
|
|
|
|
xfont = blitz_getfont(dpy, def.font);
|
|
|
|
update_bar_geometry();
|
2006-02-24 12:38:48 +03:00
|
|
|
resize_all_clients();
|
2006-02-10 20:32:35 +03:00
|
|
|
break;
|
2006-02-12 03:49:33 +03:00
|
|
|
case Fkey:
|
|
|
|
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-16 13:53:10 +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;
|
2006-02-12 03:49:33 +03:00
|
|
|
case TCREATE: errstr = xcreate(c, &fcall); break;
|
2006-02-03 20:11:22 +03:00
|
|
|
case TOPEN: errstr = xopen(c, &fcall); break;
|
2006-02-10 00:48:01 +03:00
|
|
|
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-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-08 20:35:40 +03:00
|
|
|
check_x_event(nil);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-02-02 00:24:07 +03:00
|
|
|
void
|
2006-02-16 13:53:10 +03:00
|
|
|
write_event(char *event)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
for(i = 0; (i < srv.connsz) && srv.conn[i]; i++) {
|
|
|
|
IXPConn *c = srv.conn[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);
|
|
|
|
unsigned char *p = c->pending.data;
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!m) {
|
2006-02-12 02:49:38 +03:00
|
|
|
if(ixp_server_respond_error(c, &c->pending, Enofid))
|
2006-02-03 20:11:22 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
else if(qpath_type(m->qid.path) == Fevent) {
|
2006-02-12 02:49:38 +03:00
|
|
|
c->pending.count = strlen(event);
|
|
|
|
memcpy(p, event, c->pending.count);
|
|
|
|
c->pending.id = RREAD;
|
|
|
|
if(ixp_server_respond_fcall(c, &c->pending))
|
2006-02-03 20:11:22 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|