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 Enofile[] = "file not found";
|
|
|
|
static char Enomode[] = "mode not supported";
|
|
|
|
static char Enofunc[] = "function not supported";
|
|
|
|
static char Enocommand[] = "command not supported";
|
2006-03-11 03:07:19 +03:00
|
|
|
static char Ebadvalue[] = "bad value";
|
2006-02-10 00:48:01 +03:00
|
|
|
|
2006-03-23 18:12:28 +03:00
|
|
|
#define WMII_IOUNIT 2048
|
2006-02-10 11:13:35 +03:00
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
/*
|
|
|
|
* filesystem specification
|
2006-03-23 18:32:45 +03:00
|
|
|
* / FsDroot
|
|
|
|
* /def/ FsDdef
|
2006-03-23 18:56:47 +03:00
|
|
|
* /def/border FsFborder 0..n
|
|
|
|
* /def/font FsFfont xlib font name
|
|
|
|
* /def/selcolors FsFselcolors selected colors
|
|
|
|
* /def/normcolors FsFnormcolors normal colors
|
|
|
|
* /def/rules FsFrules rules
|
|
|
|
* /def/keys FsFkeys keys
|
2006-03-23 18:32:45 +03:00
|
|
|
* /tags FsFtags
|
|
|
|
* /bar/ FsDbar
|
2006-03-23 18:56:47 +03:00
|
|
|
* /bar/lab/ FsDlabel
|
|
|
|
* /bar/lab/data FsFdata <arbitrary data which gets displayed>
|
|
|
|
* /bar/lab/colors FsFcolors <#RRGGBB> <#RRGGBB> <#RRGGBB>
|
|
|
|
* /clients/ FsDclients
|
|
|
|
* /clients/1/ FsDGclient see /view/X/X/ namespace below
|
2006-03-23 18:32:45 +03:00
|
|
|
* /event FsFevent
|
2006-03-23 18:56:47 +03:00
|
|
|
* /ctl FsFctl command interface (root)
|
|
|
|
* /view/ FsDview view
|
|
|
|
* /view/tag FsFtag current tag
|
|
|
|
* /view/ctl FsFctl command interface (tag)
|
|
|
|
* /view/sel/ FsDarea
|
2006-03-23 18:32:45 +03:00
|
|
|
* /view/1/ FsDarea
|
2006-03-23 18:56:47 +03:00
|
|
|
* /view/1/ctl FsFctl command interface (area)
|
|
|
|
* /view/1/mode FsFmode column mode
|
|
|
|
* /view/1/sel/ FsDclient
|
|
|
|
* /view/1/1/class FsFclass class:instance of client
|
|
|
|
* /view/1/1/name FsFname name of client
|
|
|
|
* /view/1/1/tags FsFtags tag of client
|
|
|
|
* /view/1/1/geom FsFgeom geometry of client
|
|
|
|
* /view/1/1/ctl FsFctl 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-03-23 18:07:18 +03:00
|
|
|
/*
|
2006-02-10 17:59:30 +03:00
|
|
|
* Qid->path is calculated related to the index of the associated structure.
|
2006-03-10 00:43:24 +03:00
|
|
|
* i1 is associated to tag, key, global client, or label
|
2006-02-10 17:59:30 +03:00
|
|
|
* i2 is associated to area
|
|
|
|
* i3 is associated to client
|
2006-03-23 11:54:20 +03:00
|
|
|
* ie /view/sel/ctl is i1id = sel tag id, i2id = sel area id , i3id = 0 (no id)
|
2006-02-10 17:59:30 +03:00
|
|
|
*/
|
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-03-23 18:07:18 +03:00
|
|
|
return ((unsigned long long) type << 48) | ((unsigned long long) i1id << 32)
|
2006-02-10 17:59:30 +03:00
|
|
|
| ((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-03-23 18:07:18 +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
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
return (path >> 32) & 0xffff;
|
2006-01-31 15:25:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-23 18:07:18 +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-03-23 18:07:18 +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) {
|
2006-03-07 19:22:36 +03:00
|
|
|
if(qid->dir_type == FsDGclient || qid->dir_type == FsDclients)
|
|
|
|
*i1 = cid2index(i1id);
|
|
|
|
else {
|
|
|
|
switch(*type) {
|
|
|
|
case FsFdata:
|
|
|
|
case FsFcolors:
|
|
|
|
case FsDlabel: *i1 = lid2index(i1id); break;
|
2006-03-23 17:58:36 +03:00
|
|
|
default: *i1 = vid2index(i1id); break;
|
2006-03-07 19:22:36 +03:00
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
2006-03-05 18:48:14 +03:00
|
|
|
if(i2id && (*i1 != -1)) {
|
2006-03-23 12:36:51 +03:00
|
|
|
*i2 = aid2index(view[*i1], i2id);
|
2006-03-05 18:48:14 +03:00
|
|
|
if(i3id && (*i2 != -1))
|
2006-03-23 12:36:51 +03:00
|
|
|
*i3 = frid2index(view[*i1]->area[*i2], i3id);
|
2006-03-05 18:48:14 +03:00
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
static char *
|
2006-03-01 09:51:04 +03:00
|
|
|
qid2name(Qid *qid)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
2006-03-05 18:48:14 +03:00
|
|
|
int i1 = -1, i2 = -1, i3 = -1;
|
2006-03-08 19:45:16 +03:00
|
|
|
static char buf[256];
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
decode_qpath(qid, &type, &i1, &i2, &i3);
|
2006-02-03 20:11:22 +03:00
|
|
|
|
2006-02-10 17:59:30 +03:00
|
|
|
switch(type) {
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsDroot: return "/"; break;
|
|
|
|
case FsDdef: return "def"; break;
|
|
|
|
case FsDclients: return "clients"; break;
|
|
|
|
case FsDbar: return "bar"; break;
|
|
|
|
case FsDview:
|
|
|
|
if(qid->dir_type == FsDroot)
|
|
|
|
return "view";
|
|
|
|
return nil;
|
|
|
|
break;
|
|
|
|
case FsDlabel:
|
|
|
|
if(i1 == -1)
|
2006-03-15 15:18:05 +03:00
|
|
|
return nil;
|
2006-03-23 18:07:18 +03:00
|
|
|
return label[i1]->name;
|
|
|
|
break;
|
|
|
|
case FsDarea:
|
|
|
|
if(i1 == -1 || i2 == -1)
|
|
|
|
return nil;
|
|
|
|
if(view[i1]->sel == i2)
|
|
|
|
return "sel";
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i2);
|
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case FsDGclient:
|
|
|
|
if(i1 == -1)
|
|
|
|
return nil;
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i1);
|
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case FsDclient:
|
|
|
|
if(i1 == -1 || i2 == -1 || i3 == -1)
|
|
|
|
return nil;
|
|
|
|
if(view[i1]->area[i2]->sel == i3)
|
|
|
|
return "sel";
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i3);
|
|
|
|
return buf;
|
|
|
|
break;
|
|
|
|
case FsFselcolors: return "selcolors"; break;
|
|
|
|
case FsFnormcolors: return "normcolors"; break;
|
|
|
|
case FsFfont: return "font"; break;
|
|
|
|
case FsFrules: return "rules"; break;
|
|
|
|
case FsFkeys: return "keys"; break;
|
|
|
|
case FsFcolors: return "colors"; break;
|
|
|
|
case FsFdata:
|
|
|
|
if(i1 == -1)
|
|
|
|
return nil;
|
|
|
|
return "data";
|
|
|
|
break;
|
|
|
|
case FsFctl: return "ctl"; break;
|
|
|
|
case FsFborder: return "border"; break;
|
|
|
|
case FsFgeom:
|
|
|
|
if((qid->dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
|
|
|
|
return nil;
|
|
|
|
else if(i1 == -1)
|
|
|
|
return nil;
|
|
|
|
return "geom";
|
|
|
|
break;
|
|
|
|
case FsFclass:
|
|
|
|
case FsFname:
|
|
|
|
if((qid->dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
|
|
|
|
return nil;
|
|
|
|
else if(i1 == -1)
|
|
|
|
return nil;
|
|
|
|
if(type == FsFname)
|
|
|
|
return "name";
|
|
|
|
else
|
|
|
|
return "class";
|
|
|
|
break;
|
|
|
|
case FsFtags:
|
|
|
|
if((qid->dir_type == FsDclient) && (i1 == -1 || i2 == -1 || i3 == -1))
|
|
|
|
return nil;
|
|
|
|
else if((qid->dir_type == FsDGclient) && (i1 == -1))
|
|
|
|
return nil;
|
|
|
|
return "tags";
|
|
|
|
break;
|
|
|
|
case FsFmode:
|
|
|
|
if(i1 == -1 || i2 == -1)
|
|
|
|
return nil;
|
|
|
|
return "mode";
|
|
|
|
break;
|
|
|
|
case FsFevent: return "event"; break;
|
|
|
|
default: return nil; break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-08 19:45:16 +03:00
|
|
|
static unsigned char
|
2006-03-01 09:51:04 +03:00
|
|
|
name2type(char *name, unsigned char dir_type)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
unsigned int i;
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!name || !name[0] || !strncmp(name, "/", 2) || !strncmp(name, "..", 3))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsDroot;
|
2006-03-11 03:07:19 +03:00
|
|
|
if(!strncmp(name, "tags", 5))
|
|
|
|
return FsFtags;
|
2006-03-07 19:22:36 +03:00
|
|
|
if(!strncmp(name, "clients", 8))
|
|
|
|
return FsDclients;
|
2006-03-23 11:54:20 +03:00
|
|
|
if(!strncmp(name, "view", 5) && (dir_type == FsDroot))
|
|
|
|
return FsDview;
|
2006-02-24 12:38:48 +03:00
|
|
|
if(!strncmp(name, "bar", 4))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsDbar;
|
2006-02-09 21:40:12 +03:00
|
|
|
if(!strncmp(name, "def", 4))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsDdef;
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!strncmp(name, "ctl", 4))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFctl;
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!strncmp(name, "event", 6))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFevent;
|
2006-03-10 13:59:26 +03:00
|
|
|
if(!strncmp(name, "class", 5))
|
|
|
|
return FsFclass;
|
2006-01-31 11:27:54 +03:00
|
|
|
if(!strncmp(name, "name", 5))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFname;
|
2006-01-31 11:27:54 +03:00
|
|
|
if(!strncmp(name, "border", 7))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFborder;
|
2006-03-05 18:48:14 +03:00
|
|
|
if(!strncmp(name, "geom", 5))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFgeom;
|
2006-02-10 20:32:35 +03:00
|
|
|
if(!strncmp(name, "colors", 7))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFcolors;
|
2006-02-10 20:32:35 +03:00
|
|
|
if(!strncmp(name, "selcolors", 10))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFselcolors;
|
2006-02-10 20:32:35 +03:00
|
|
|
if(!strncmp(name, "normcolors", 11))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFnormcolors;
|
2006-03-10 16:55:44 +03:00
|
|
|
if(!strncmp(name, "font", 5))
|
|
|
|
return FsFfont;
|
2006-03-10 18:21:20 +03:00
|
|
|
if(!strncmp(name, "keys", 5))
|
|
|
|
return FsFkeys;
|
2006-03-10 16:39:46 +03:00
|
|
|
if(!strncmp(name, "rules", 6))
|
|
|
|
return FsFrules;
|
2006-02-10 00:48:01 +03:00
|
|
|
if(!strncmp(name, "data", 5))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFdata;
|
2006-02-28 18:23:05 +03:00
|
|
|
if(!strncmp(name, "mode", 5))
|
2006-03-05 16:16:48 +03:00
|
|
|
return FsFmode;
|
2006-03-07 21:32:47 +03:00
|
|
|
if(!strncmp(name, "tag", 4))
|
|
|
|
return FsFtag;
|
2006-03-09 04:15:43 +03:00
|
|
|
if((dir_type == FsDbar) && name2label(name))
|
|
|
|
return FsDlabel;
|
2006-02-02 15:20:07 +03:00
|
|
|
if(!strncmp(name, "sel", 4))
|
2006-01-31 19:52:14 +03:00
|
|
|
goto dyndir;
|
2006-03-23 18:07:18 +03:00
|
|
|
i = (unsigned short) cext_strtonum(name, 0, 0xffff, &err);
|
|
|
|
if(err)
|
2006-01-31 11:27:54 +03:00
|
|
|
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-03-05 16:16:48 +03:00
|
|
|
case FsDbar: return FsDlabel; break;
|
2006-03-23 11:54:20 +03:00
|
|
|
case FsDview: return FsDarea; break;
|
2006-03-07 19:22:36 +03:00
|
|
|
case FsDclients: return FsDGclient; break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDarea: return FsDclient; break;
|
2006-01-31 11:27:54 +03:00
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-03-09 04:15:43 +03:00
|
|
|
mkqid(Qid *dir, char *wname, Qid *new)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char dir_type;
|
2006-03-08 19:45:16 +03:00
|
|
|
int dir_i1 = -1, dir_i2 = -1, dir_i3 = -1, i;
|
|
|
|
unsigned char type;
|
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);
|
2006-03-01 09:51:04 +03:00
|
|
|
type = name2type(wname, dir_type);
|
2006-02-10 17:59:30 +03:00
|
|
|
|
|
|
|
new->dir_type = dir_type;
|
2006-03-23 18:07:18 +03:00
|
|
|
new->version = 0;
|
2006-01-30 21:43:32 +03:00
|
|
|
switch(type) {
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDroot:
|
2006-01-30 21:43:32 +03:00
|
|
|
*new = root_qid;
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDdef:
|
2006-03-07 19:22:36 +03:00
|
|
|
case FsDclients:
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDbar:
|
2006-03-07 19:53:16 +03:00
|
|
|
if(dir_type != FsDroot)
|
|
|
|
return -1;
|
2006-02-10 00:48:01 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-03-05 21:20:27 +03:00
|
|
|
new->path = mkqpath(type, 0, 0, 0);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-03-23 11:54:20 +03:00
|
|
|
case FsDview:
|
2006-03-05 22:00:18 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-03-23 12:36:51 +03:00
|
|
|
new->path = mkqpath(FsDview, nview ? view[sel]->id : 0, 0, 0);
|
2006-03-05 22:00:18 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDarea:
|
2006-03-23 11:54:20 +03:00
|
|
|
if(dir_i1 == -1 || dir_type != FsDview)
|
2006-03-05 18:48:14 +03:00
|
|
|
return -1;
|
2006-02-10 17:59:30 +03:00
|
|
|
{
|
2006-03-23 12:36:51 +03:00
|
|
|
View *p = view[dir_i1];
|
2006-02-10 17:59:30 +03:00
|
|
|
new->type = IXP_QTDIR;
|
2006-03-04 11:23:17 +03:00
|
|
|
if(!strncmp(wname, "sel", 4)) {
|
2006-03-05 16:16:48 +03:00
|
|
|
new->path = mkqpath(FsDarea, 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 {
|
2006-03-01 13:09:49 +03:00
|
|
|
i = cext_strtonum(wname, 0, 0xffff, &err);
|
|
|
|
if(err || (i >= p->narea))
|
2006-02-10 17:59:30 +03:00
|
|
|
return -1;
|
2006-03-05 16:16:48 +03:00
|
|
|
new->path = mkqpath(FsDarea, p->id, p->area[i]->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-03-05 16:16:48 +03:00
|
|
|
case FsDclient:
|
2006-03-07 19:53:16 +03:00
|
|
|
if(dir_i1 == -1 || dir_i2 == -1 || dir_type != FsDarea)
|
2006-03-05 18:48:14 +03:00
|
|
|
return -1;
|
2006-02-10 17:59:30 +03:00
|
|
|
{
|
2006-03-23 12:36:51 +03:00
|
|
|
View *p = view[dir_i1];
|
2006-02-10 17:59:30 +03:00
|
|
|
Area *a = p->area[dir_i2];
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
if(!strncmp(wname, "sel", 4)) {
|
2006-03-05 03:55:45 +03:00
|
|
|
if(!a->nframe)
|
2006-02-10 17:59:30 +03:00
|
|
|
return -1;
|
2006-03-05 16:16:48 +03:00
|
|
|
new->path = mkqpath(FsDclient, p->id, a->id, a->frame[a->sel]->id);
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
|
|
|
else {
|
2006-03-01 13:09:49 +03:00
|
|
|
i = cext_strtonum(wname, 0, 0xffff, &err);
|
2006-03-05 03:55:45 +03:00
|
|
|
if(err || (i >= a->nframe))
|
2006-02-10 17:59:30 +03:00
|
|
|
return -1;
|
2006-03-05 16:16:48 +03:00
|
|
|
new->path = mkqpath(FsDclient, p->id, a->id, a->frame[i]->id);
|
2006-02-10 17:59:30 +03:00
|
|
|
}
|
2006-01-31 19:52:14 +03:00
|
|
|
}
|
2006-01-31 15:25:23 +03:00
|
|
|
break;
|
2006-03-07 19:22:36 +03:00
|
|
|
case FsDGclient:
|
2006-03-07 19:53:16 +03:00
|
|
|
if(dir_type != FsDclients)
|
|
|
|
return -1;
|
2006-03-07 19:22:36 +03:00
|
|
|
i = cext_strtonum(wname, 0, 0xffff, &err);
|
|
|
|
if(err || (i >= nclient))
|
|
|
|
return -1;
|
|
|
|
new->path = mkqpath(FsDGclient, client[i]->id, 0, 0);
|
|
|
|
break;
|
2006-03-09 04:15:43 +03:00
|
|
|
case FsDlabel:
|
|
|
|
if(dir_type != FsDbar)
|
|
|
|
return -1;
|
|
|
|
{
|
|
|
|
Label *l;
|
|
|
|
if(!(l = name2label(wname)))
|
|
|
|
return -1;
|
|
|
|
new->type = IXP_QTDIR;
|
|
|
|
new->path = mkqpath(FsDlabel, l->id, 0, 0);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFdata:
|
|
|
|
case FsFcolors:
|
2006-03-07 19:53:16 +03:00
|
|
|
if((dir_i1 == -1) || (dir_type != FsDlabel))
|
2006-02-10 00:48:01 +03:00
|
|
|
return -1;
|
2006-03-22 21:57:18 +03:00
|
|
|
goto Mkfile;
|
2006-03-05 18:48:14 +03:00
|
|
|
break;
|
|
|
|
case FsFmode:
|
2006-03-07 19:53:16 +03:00
|
|
|
if(dir_i1 == -1 || dir_i2 == -1 || dir_type != FsDarea)
|
2006-03-05 18:48:14 +03:00
|
|
|
return -1;
|
2006-03-22 21:57:18 +03:00
|
|
|
goto Mkfile;
|
2006-03-05 18:48:14 +03:00
|
|
|
break;
|
2006-03-21 20:14:50 +03:00
|
|
|
case FsFtag:
|
2006-03-23 11:54:20 +03:00
|
|
|
if(dir_i1 == -1 || dir_type != FsDview)
|
2006-03-21 20:14:50 +03:00
|
|
|
return -1;
|
2006-03-22 21:57:18 +03:00
|
|
|
goto Mkfile;
|
2006-03-21 20:14:50 +03:00
|
|
|
break;
|
2006-03-05 18:48:14 +03:00
|
|
|
case FsFgeom:
|
|
|
|
case FsFname:
|
2006-03-10 13:59:26 +03:00
|
|
|
case FsFclass:
|
2006-03-21 20:14:50 +03:00
|
|
|
if(dir_type == FsDroot)
|
|
|
|
return -1;
|
2006-03-05 21:20:27 +03:00
|
|
|
case FsFtags:
|
2006-03-21 20:14:50 +03:00
|
|
|
if(dir_type != FsDroot && dir_type != FsDGclient && dir_type != FsDclient)
|
|
|
|
return -1;
|
2006-03-07 20:11:52 +03:00
|
|
|
if((dir_type == FsDclient) && ((dir_i1 == -1 || dir_i2 == -1 || dir_i3 == -1)))
|
2006-03-07 19:22:36 +03:00
|
|
|
return -1;
|
2006-03-11 03:07:19 +03:00
|
|
|
else if((dir_type == FsDGclient) && (dir_i1 == -1))
|
2006-03-05 18:48:14 +03:00
|
|
|
return -1;
|
2006-03-22 21:57:18 +03:00
|
|
|
goto Mkfile;
|
|
|
|
break;
|
2006-03-10 16:55:44 +03:00
|
|
|
case FsFborder:
|
|
|
|
case FsFfont:
|
|
|
|
case FsFrules:
|
|
|
|
case FsFselcolors:
|
|
|
|
case FsFnormcolors:
|
2006-03-10 18:21:20 +03:00
|
|
|
case FsFkeys:
|
2006-03-23 18:07:18 +03:00
|
|
|
if(dir_type != FsDdef)
|
2006-03-10 16:55:44 +03:00
|
|
|
return -1;
|
2006-03-22 21:54:27 +03:00
|
|
|
case FsFctl:
|
|
|
|
case FsFevent:
|
2006-03-22 21:57:18 +03:00
|
|
|
Mkfile:
|
2006-01-30 21:43:32 +03:00
|
|
|
new->type = IXP_QTFILE;
|
2006-03-23 18:07:18 +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;
|
2006-03-22 21:54:27 +03:00
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
2006-03-23 18:07:18 +03:00
|
|
|
return 0;
|
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)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
stat->mode = mode;
|
|
|
|
stat->atime = stat->mtime = time(0);
|
|
|
|
cext_strlcpy(stat->uid, getenv("USER"), sizeof(stat->uid));
|
|
|
|
cext_strlcpy(stat->gid, getenv("USER"), sizeof(stat->gid));
|
|
|
|
cext_strlcpy(stat->muid, getenv("USER"), sizeof(stat->muid));
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
cext_strlcpy(stat->name, name, sizeof(stat->name));
|
|
|
|
stat->length = length;
|
|
|
|
mkqid(dir, name, &stat->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
return ixp_sizeof_stat(stat);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int
|
2006-03-01 09:51:04 +03:00
|
|
|
type2stat(Stat *stat, char *wname, Qid *dir)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-03-08 19:45:16 +03:00
|
|
|
unsigned char dir_type, type;
|
2006-02-10 17:59:30 +03:00
|
|
|
int dir_i1 = 0, dir_i2 = 0, dir_i3 = 0;
|
2006-03-08 19:45:16 +03:00
|
|
|
char buf[256];
|
2006-03-05 03:55:45 +03:00
|
|
|
Frame *f;
|
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;
|
2006-03-01 09:51:04 +03:00
|
|
|
type = name2type(wname, dir_type);
|
2006-02-03 22:02:37 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
switch (type) {
|
|
|
|
case FsDclient:
|
|
|
|
case FsDGclient:
|
|
|
|
case FsDarea:
|
|
|
|
case FsDview:
|
|
|
|
case FsDdef:
|
2006-03-07 19:22:36 +03:00
|
|
|
case FsDclients:
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDlabel:
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsDroot:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMDIR | DMREAD | DMEXEC);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
2006-03-09 04:15:43 +03:00
|
|
|
case FsDbar:
|
2006-03-11 01:30:08 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMDIR | DMREAD | DMWRITE | DMEXEC);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFctl:
|
2006-03-07 19:22:36 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMWRITE);
|
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsFevent:
|
2006-03-12 12:51:12 +03:00
|
|
|
return mkstat(stat, dir, wname, 0, DMREAD | DMWRITE);
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsFborder:
|
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-03-23 18:07:18 +03:00
|
|
|
break;
|
|
|
|
case FsFgeom:
|
2006-03-07 19:22:36 +03:00
|
|
|
if(dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
|
2006-03-07 19:22:36 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y,
|
|
|
|
f->rect.width, f->rect.height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Client *c = client[dir_i1];
|
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y,
|
|
|
|
c->rect.width, c->rect.height);
|
|
|
|
}
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
|
|
|
case FsFclass:
|
2006-03-10 13:59:26 +03:00
|
|
|
if(dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
|
2006-03-10 13:59:26 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(f->client->classinst), DMREAD);
|
|
|
|
}
|
2006-03-23 18:07:18 +03:00
|
|
|
else
|
2006-03-10 13:59:26 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(client[dir_i1]->classinst), DMREAD);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
|
|
|
case FsFname:
|
2006-03-07 19:22:36 +03:00
|
|
|
if(dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
|
2006-03-07 19:22:36 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(f->client->name), DMREAD);
|
|
|
|
}
|
2006-03-23 18:07:18 +03:00
|
|
|
else
|
2006-03-07 19:22:36 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(client[dir_i1]->name), DMREAD);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
|
|
|
case FsFtags:
|
2006-03-11 03:07:19 +03:00
|
|
|
switch(dir_type) {
|
|
|
|
case FsDclient:
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[dir_i1]->area[dir_i2]->frame[dir_i3];
|
2006-03-23 18:07:18 +03:00
|
|
|
tags2str(buf, sizeof(buf), f->client->tag, f->client->ntag);
|
2006-03-15 11:02:25 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-03-11 03:07:19 +03:00
|
|
|
break;
|
|
|
|
case FsDGclient:
|
2006-03-23 18:07:18 +03:00
|
|
|
tags2str(buf, sizeof(buf), client[dir_i1]->tag, client[dir_i1]->ntag);
|
2006-03-15 11:02:25 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(buf), DMREAD | DMWRITE);
|
2006-03-11 03:07:19 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
unsigned int i, len = 0;
|
2006-03-23 12:46:35 +03:00
|
|
|
for(i = 0; i < ntag; i++)
|
|
|
|
len += strlen(tag[i]) + 1;
|
2006-03-11 03:07:19 +03:00
|
|
|
return mkstat(stat, dir, wname, len, DMREAD);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2006-03-06 18:35:07 +03:00
|
|
|
break;
|
|
|
|
case FsFtag:
|
2006-03-23 11:54:20 +03:00
|
|
|
if(dir_type == FsDview)
|
2006-03-22 22:09:22 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(def.tag), DMREAD);
|
2006-03-06 18:35:07 +03:00
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsFdata:
|
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-03-23 18:07:18 +03:00
|
|
|
break;
|
|
|
|
case FsFmode:
|
2006-03-23 12:36:51 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(mode2str(view[dir_i1]->area[dir_i2]->mode)), DMREAD | DMWRITE);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
|
|
|
case FsFcolors:
|
|
|
|
case FsFselcolors:
|
|
|
|
case FsFnormcolors:
|
2006-02-10 17:59:30 +03:00
|
|
|
return mkstat(stat, dir, wname, 23, DMREAD | DMWRITE);
|
2006-03-10 16:55:44 +03:00
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsFkeys:
|
2006-03-10 18:21:20 +03:00
|
|
|
return mkstat(stat, dir, wname, def.keys ? strlen(def.keys) : 0, DMREAD | DMWRITE);
|
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsFrules:
|
2006-03-10 16:39:46 +03:00
|
|
|
return mkstat(stat, dir, wname, def.rules ? strlen(def.rules) : 0, DMREAD | DMWRITE);
|
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
case FsFfont:
|
2006-02-10 20:32:35 +03:00
|
|
|
return mkstat(stat, dir, wname, strlen(def.font), DMREAD | DMWRITE);
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-03-23 18:07:18 +03:00
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-03-08 19:45:16 +03:00
|
|
|
static char *
|
|
|
|
xversion(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
if(strncmp(fcall->version, IXP_VERSION, strlen(IXP_VERSION)))
|
|
|
|
return E9pversion;
|
|
|
|
else if(fcall->maxmsg > IXP_MAX_MSG)
|
|
|
|
fcall->maxmsg = IXP_MAX_MSG;
|
|
|
|
fcall->id = RVERSION;
|
2006-03-08 19:45:16 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
xattach(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
IXPMap *new = cext_emallocz(sizeof(IXPMap));
|
|
|
|
new->qid = root_qid;
|
|
|
|
new->fid = fcall->fid;
|
2006-03-08 19:45:16 +03:00
|
|
|
c->map = (IXPMap **)cext_array_attach((void **)c->map, new,
|
2006-03-23 18:07:18 +03:00
|
|
|
sizeof(IXPMap *), &c->mapsz);
|
|
|
|
fcall->id = RATTACH;
|
|
|
|
fcall->qid = root_qid;
|
2006-03-08 19:45:16 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
xwalk(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
unsigned short nwqid = 0;
|
|
|
|
Qid dir = root_qid;
|
|
|
|
IXPMap *m;
|
2006-03-08 19:45:16 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!(m = ixp_server_fid2map(c, fcall->fid)))
|
|
|
|
return Enofile;
|
|
|
|
if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid)))
|
|
|
|
return Enofile;
|
|
|
|
if(fcall->nwname) {
|
|
|
|
dir = m->qid;
|
|
|
|
for(nwqid = 0; (nwqid < fcall->nwname)
|
|
|
|
&& !mkqid(&dir, fcall->wname[nwqid], &fcall->wqid[nwqid]); nwqid++)
|
|
|
|
dir = fcall->wqid[nwqid];
|
|
|
|
if(!nwqid) {
|
2006-03-22 21:54:27 +03:00
|
|
|
fprintf(stderr, "xwalk: no such file '%s'\n", fcall->wname[nwqid]);
|
2006-03-08 19:45:16 +03:00
|
|
|
return Enofile;
|
|
|
|
}
|
2006-03-23 18:07:18 +03:00
|
|
|
}
|
|
|
|
/* a fid will only be valid, if the walk was complete */
|
|
|
|
if(nwqid == fcall->nwname) {
|
|
|
|
if(fcall->fid != fcall->newfid) {
|
2006-03-08 19:45:16 +03:00
|
|
|
m = cext_emallocz(sizeof(IXPMap));
|
|
|
|
c->map = (IXPMap **)cext_array_attach((void **)c->map, m,
|
2006-03-23 18:07:18 +03:00
|
|
|
sizeof(IXPMap *), &c->mapsz);
|
|
|
|
}
|
|
|
|
m->qid = dir;
|
|
|
|
m->fid = fcall->newfid;
|
|
|
|
}
|
|
|
|
fcall->id = RWALK;
|
|
|
|
fcall->nwqid = nwqid;
|
2006-03-08 19:45:16 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
xcreate(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-03-08 19:45:16 +03:00
|
|
|
unsigned char type;
|
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!(fcall->mode | IXP_OWRITE))
|
|
|
|
return Enomode;
|
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
2006-03-08 19:45:16 +03:00
|
|
|
if(!strncmp(fcall->name, ".", 2) || !strncmp(fcall->name, "..", 3))
|
|
|
|
return "illegal file name";
|
|
|
|
type = qpath_type(m->qid.path);
|
|
|
|
switch(type) {
|
2006-03-09 04:15:43 +03:00
|
|
|
case FsDbar:
|
|
|
|
get_label(fcall->name);
|
|
|
|
break;
|
2006-03-08 19:45:16 +03:00
|
|
|
default:
|
2006-03-22 16:32:46 +03:00
|
|
|
return Enofile;
|
2006-03-08 19:45:16 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-03-09 04:15:43 +03:00
|
|
|
mkqid(&m->qid, fcall->name, &m->qid);
|
2006-03-08 19:45:16 +03:00
|
|
|
fcall->qid = m->qid;
|
|
|
|
fcall->id = RCREATE;
|
|
|
|
fcall->iounit = WMII_IOUNIT;
|
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static char *
|
|
|
|
xopen(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-03-08 19:45:16 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
|
|
|
if(!(fcall->mode | IXP_OREAD) && !(fcall->mode | IXP_OWRITE))
|
|
|
|
return Enomode;
|
|
|
|
fcall->id = ROPEN;
|
|
|
|
fcall->qid = m->qid;
|
|
|
|
fcall->iounit = WMII_IOUNIT;
|
2006-03-08 19:45:16 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
2006-03-08 19:45:16 +03:00
|
|
|
}
|
|
|
|
|
2006-02-10 00:48:01 +03:00
|
|
|
static char *
|
|
|
|
xremove(IXPConn *c, Fcall *fcall)
|
|
|
|
{
|
2006-03-23 18:07:18 +03:00
|
|
|
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
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
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-03-10 18:21:20 +03:00
|
|
|
if(type != FsDlabel)
|
2006-03-09 04:15:43 +03:00
|
|
|
return Enoperm;
|
|
|
|
/* clunk */
|
|
|
|
cext_array_detach((void **)c->map, m, &c->mapsz);
|
|
|
|
free(m);
|
2006-02-10 17:59:30 +03:00
|
|
|
switch(type) {
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDlabel:
|
2006-02-10 17:59:30 +03:00
|
|
|
{
|
|
|
|
Label *l = label[i1];
|
2006-03-24 15:36:35 +03:00
|
|
|
if(l->intern)
|
|
|
|
return Enoperm;
|
2006-02-10 17:59:30 +03:00
|
|
|
/* now detach the label */
|
2006-03-09 04:15:43 +03:00
|
|
|
destroy_label(l);
|
2006-02-10 17:59:30 +03:00
|
|
|
free(l);
|
|
|
|
draw_bar();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2006-02-10 00:48:01 +03:00
|
|
|
}
|
2006-03-23 18:07:18 +03:00
|
|
|
fcall->id = RREMOVE;
|
2006-02-10 17:59:30 +03:00
|
|
|
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-03-23 18:07:18 +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-03-08 19:45:16 +03:00
|
|
|
char buf[256];
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
|
|
|
int i1 = 0, i2 = 0, i3 = 0;
|
2006-03-05 03:55:45 +03:00
|
|
|
Frame *f;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
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-03-07 19:22:36 +03:00
|
|
|
case FsDclients:
|
|
|
|
/* jump to offset */
|
|
|
|
len = 0;
|
|
|
|
for(i = 0; i < nclient; i++) {
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
|
|
|
len += type2stat(&stat, buf, &m->qid);
|
|
|
|
if(len <= fcall->offset)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
|
|
|
for(; i < nclient; i++) {
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
|
|
|
len = type2stat(&stat, buf, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDbar:
|
2006-02-10 00:48:01 +03:00
|
|
|
/* jump to offset */
|
2006-03-24 15:36:35 +03:00
|
|
|
len = 0;
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++) {
|
2006-03-09 04:15:43 +03:00
|
|
|
len += type2stat(&stat, label[i]->name, &m->qid);
|
2006-02-10 00:48:01 +03:00
|
|
|
if(len <= fcall->offset)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
2006-02-10 17:59:30 +03:00
|
|
|
for(; i < nlabel; i++) {
|
2006-03-09 04:15:43 +03:00
|
|
|
len = type2stat(&stat, label[i]->name, &m->qid);
|
2006-02-10 00:48:01 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-23 11:54:20 +03:00
|
|
|
case FsDview:
|
2006-02-01 18:27:53 +03:00
|
|
|
/* jump to offset */
|
2006-03-22 15:02:41 +03:00
|
|
|
len = type2stat(&stat, "tag", &m->qid);
|
2006-03-23 12:36:51 +03:00
|
|
|
if(nview) {
|
2006-03-22 15:02:41 +03:00
|
|
|
len += type2stat(&stat, "ctl", &m->qid);
|
2006-03-23 12:36:51 +03:00
|
|
|
if(view[i1]->narea)
|
2006-03-22 15:02:41 +03:00
|
|
|
len += type2stat(&stat, "sel", &m->qid);
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < view[i1]->narea; i++) {
|
2006-03-22 15:02:41 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
|
|
|
len += type2stat(&stat, buf, &m->qid);
|
|
|
|
if(len <= fcall->offset)
|
|
|
|
continue;
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-03-22 15:02:41 +03:00
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
2006-03-23 12:36:51 +03:00
|
|
|
for(; i < view[i1]->narea; i++) {
|
2006-03-22 15:02:41 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
|
|
|
len = type2stat(&stat, buf, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
2006-02-01 18:27:53 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDarea:
|
2006-02-01 18:27:53 +03:00
|
|
|
/* jump to offset */
|
2006-03-01 09:51:04 +03:00
|
|
|
len = type2stat(&stat, "ctl", &m->qid);
|
2006-03-02 21:58:54 +03:00
|
|
|
if(i2)
|
2006-03-01 09:51:04 +03:00
|
|
|
len += type2stat(&stat, "mode", &m->qid);
|
2006-03-23 12:36:51 +03:00
|
|
|
if(view[i1]->area[i2]->nframe)
|
2006-03-22 11:48:08 +03:00
|
|
|
len += type2stat(&stat, "sel", &m->qid);
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < view[i1]->area[i2]->nframe; i++) {
|
2006-03-22 11:48:08 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-03-01 09:51:04 +03:00
|
|
|
len += type2stat(&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-03-23 12:36:51 +03:00
|
|
|
for(; i < view[i1]->area[i2]->nframe; i++) {
|
2006-03-22 11:48:08 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-03-01 09:51:04 +03:00
|
|
|
len = type2stat(&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-03-05 16:16:48 +03:00
|
|
|
case FsFevent:
|
2006-02-12 02:49:38 +03:00
|
|
|
memcpy(&c->pending, fcall, sizeof(Fcall));
|
|
|
|
c->is_pending = 1;
|
2006-02-03 20:11:22 +03:00
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-03-10 18:21:20 +03:00
|
|
|
case FsFkeys:
|
|
|
|
len = def.keys ? strlen(def.keys) : 0;
|
|
|
|
if(len <= fcall->offset) {
|
|
|
|
fcall->count = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fcall->count = len - fcall->offset;
|
|
|
|
if(fcall->count > fcall->iounit) {
|
|
|
|
memcpy(p, def.keys + fcall->offset, fcall->iounit);
|
|
|
|
fcall->count = fcall->iounit;
|
|
|
|
}
|
|
|
|
else if(fcall->count)
|
|
|
|
memcpy(p, def.keys + fcall->offset, fcall->count);
|
|
|
|
break;
|
2006-03-10 17:22:36 +03:00
|
|
|
case FsFrules:
|
|
|
|
len = def.rules ? strlen(def.rules) : 0;
|
|
|
|
if(len <= fcall->offset) {
|
|
|
|
fcall->count = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fcall->count = len - fcall->offset;
|
|
|
|
if(fcall->count > fcall->iounit) {
|
|
|
|
memcpy(p, def.rules + fcall->offset, fcall->iounit);
|
|
|
|
fcall->count = fcall->iounit;
|
|
|
|
}
|
|
|
|
else if(fcall->count)
|
|
|
|
memcpy(p, def.rules + fcall->offset, fcall->count);
|
|
|
|
break;
|
2006-03-11 03:07:19 +03:00
|
|
|
case FsFtags:
|
2006-03-12 12:04:37 +03:00
|
|
|
if(m->qid.dir_type == FsDroot) {
|
2006-03-12 12:03:54 +03:00
|
|
|
len = 0;
|
|
|
|
/* jump to offset */
|
2006-03-23 12:46:35 +03:00
|
|
|
for(i = 0; i < ntag; i++) {
|
|
|
|
len += strlen(tag[i]) + 1;
|
2006-03-12 12:03:54 +03:00
|
|
|
if(len <= fcall->offset)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* offset found, proceeding */
|
2006-03-23 12:46:35 +03:00
|
|
|
for(; i < ntag; i++) {
|
|
|
|
len = strlen(tag[i]) + 1;
|
2006-03-12 12:03:54 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
2006-03-23 12:46:35 +03:00
|
|
|
memcpy(p + fcall->count, tag[i], len - 1);
|
2006-03-12 12:03:54 +03:00
|
|
|
memcpy(p + fcall->count + len - 1, "\n", 1);
|
|
|
|
fcall->count += len;
|
|
|
|
}
|
2006-03-11 03:07:19 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2006-02-10 17:59:30 +03:00
|
|
|
switch (type) {
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDroot:
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count = type2stat(&stat, "ctl", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "event", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "def", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "bar", &m->qid);
|
2006-02-10 00:48:01 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-23 12:46:35 +03:00
|
|
|
if(ntag) {
|
2006-03-22 15:02:41 +03:00
|
|
|
fcall->count += type2stat(&stat, "tags", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
if(nclient) {
|
|
|
|
fcall->count += type2stat(&stat, "clients", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
2006-03-23 11:54:20 +03:00
|
|
|
fcall->count += type2stat(&stat, "view", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
break;
|
2006-03-07 19:22:36 +03:00
|
|
|
case FsDclients:
|
|
|
|
for(i = 0; i < nclient; i++) {
|
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
|
|
|
len = type2stat(&stat, buf, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDbar:
|
2006-02-10 17:59:30 +03:00
|
|
|
for(i = 0; i < nlabel; i++) {
|
2006-03-09 04:15:43 +03:00
|
|
|
len = type2stat(&stat, label[i]->name, &m->qid);
|
2006-02-10 00:48:01 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDlabel:
|
2006-02-10 17:59:30 +03:00
|
|
|
if(i1 >= nlabel)
|
2006-02-10 00:48:01 +03:00
|
|
|
return Enofile;
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count = type2stat(&stat, "colors", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&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;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDdef:
|
2006-03-10 00:43:24 +03:00
|
|
|
fcall->count = type2stat(&stat, "border", &m->qid);
|
2006-03-09 13:39:15 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "selcolors", &m->qid);
|
2006-02-10 20:32:35 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "normcolors", &m->qid);
|
2006-02-10 20:32:35 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "font", &m->qid);
|
2006-02-10 20:32:35 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-10 18:21:20 +03:00
|
|
|
fcall->count += type2stat(&stat, "keys", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-10 16:55:44 +03:00
|
|
|
fcall->count += type2stat(&stat, "rules", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-02-01 18:27:53 +03:00
|
|
|
break;
|
2006-03-23 11:54:20 +03:00
|
|
|
case FsDview:
|
2006-03-22 15:02:41 +03:00
|
|
|
fcall->count = type2stat(&stat, "tag", &m->qid);
|
2006-03-10 00:43:24 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-23 12:36:51 +03:00
|
|
|
if(nview) {
|
2006-03-22 15:02:41 +03:00
|
|
|
fcall->count += type2stat(&stat, "ctl", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-23 12:36:51 +03:00
|
|
|
if(view[i1]->narea) {
|
2006-03-22 15:02:41 +03:00
|
|
|
fcall->count += type2stat(&stat, "sel", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < view[i1]->narea; i++) {
|
2006-03-22 15:02:41 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
|
|
|
len = type2stat(&stat, buf, &m->qid);
|
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
|
|
|
fcall->count += len;
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
2006-02-01 18:27:53 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDarea:
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count = type2stat(&stat, "ctl", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-22 11:48:08 +03:00
|
|
|
if(i2) {
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "mode", &m->qid);
|
2006-02-28 18:23:05 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-22 11:48:08 +03:00
|
|
|
}
|
2006-03-23 12:36:51 +03:00
|
|
|
if(view[i1]->area[i2]->nframe) {
|
2006-03-22 11:48:08 +03:00
|
|
|
fcall->count += type2stat(&stat, "sel", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
}
|
2006-03-23 12:36:51 +03:00
|
|
|
for(i = 0; i < view[i1]->area[i2]->nframe; i++) {
|
2006-03-22 11:48:08 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%u", i);
|
2006-03-01 09:51:04 +03:00
|
|
|
len = type2stat(&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-03-07 19:22:36 +03:00
|
|
|
case FsDGclient:
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDclient:
|
2006-03-10 16:55:44 +03:00
|
|
|
fcall->count = type2stat(&stat, "class", &m->qid);
|
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-08 18:52:05 +03:00
|
|
|
fcall->count += type2stat(&stat, "name", &m->qid);
|
2006-02-01 18:27:53 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-05 21:20:27 +03:00
|
|
|
fcall->count += type2stat(&stat, "tags", &m->qid);
|
2006-03-05 18:48:14 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
fcall->count += type2stat(&stat, "geom", &m->qid);
|
2006-02-02 15:20:07 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
2006-03-01 09:51:04 +03:00
|
|
|
fcall->count += type2stat(&stat, "ctl", &m->qid);
|
2006-01-30 21:43:32 +03:00
|
|
|
p = ixp_enc_stat(p, &stat);
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFctl:
|
2006-02-04 17:13:11 +03:00
|
|
|
return Enoperm;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFevent:
|
2006-02-12 02:49:38 +03:00
|
|
|
memcpy(&c->pending, fcall, sizeof(Fcall));
|
|
|
|
c->is_pending = 1;
|
2006-02-03 20:11:22 +03:00
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFborder:
|
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-03-05 16:16:48 +03:00
|
|
|
case FsFgeom:
|
2006-03-07 19:22:36 +03:00
|
|
|
if(m->qid.dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[i1]->area[i2]->frame[i3];
|
2006-03-07 19:22:36 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", f->rect.x, f->rect.y,
|
|
|
|
f->rect.width, f->rect.height);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
Client *c = client[i1];
|
|
|
|
snprintf(buf, sizeof(buf), "%d %d %d %d", c->rect.x, c->rect.y,
|
|
|
|
c->rect.width, c->rect.height);
|
|
|
|
}
|
2006-02-03 20:11:22 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
2006-03-10 13:59:26 +03:00
|
|
|
case FsFclass:
|
|
|
|
if(m->qid.dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
if((fcall->count = strlen(view[i1]->area[i2]->frame[i3]->client->classinst)))
|
|
|
|
memcpy(p, view[i1]->area[i2]->frame[i3]->client->classinst, fcall->count);
|
2006-03-10 13:59:26 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if((fcall->count = strlen(client[i1]->classinst)))
|
2006-03-10 16:55:44 +03:00
|
|
|
memcpy(p, client[i1]->classinst, fcall->count);
|
2006-03-10 13:59:26 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFname:
|
2006-03-07 19:22:36 +03:00
|
|
|
if(m->qid.dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
if((fcall->count = strlen(view[i1]->area[i2]->frame[i3]->client->name)))
|
|
|
|
memcpy(p, view[i1]->area[i2]->frame[i3]->client->name, fcall->count);
|
2006-03-07 19:22:36 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if((fcall->count = strlen(client[i1]->name)))
|
|
|
|
memcpy(p, client[i1]->name, fcall->count);
|
|
|
|
}
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-03-05 21:20:27 +03:00
|
|
|
case FsFtags:
|
2006-03-11 03:07:19 +03:00
|
|
|
switch(m->qid.dir_type) {
|
|
|
|
case FsDclient:
|
2006-03-15 12:35:38 +03:00
|
|
|
{
|
2006-03-23 12:36:51 +03:00
|
|
|
Client *c = view[i1]->area[i2]->frame[i3]->client;
|
2006-03-23 18:07:18 +03:00
|
|
|
tags2str(buf, sizeof(buf), c->tag, c->ntag);
|
2006-03-15 12:35:38 +03:00
|
|
|
if((fcall->count = strlen(buf)))
|
|
|
|
memcpy(p, buf, fcall->count);
|
|
|
|
}
|
2006-03-11 03:07:19 +03:00
|
|
|
break;
|
|
|
|
case FsDGclient:
|
2006-03-23 18:07:18 +03:00
|
|
|
tags2str(buf, sizeof(buf), client[i1]->tag, client[i1]->ntag);
|
2006-03-15 11:02:25 +03:00
|
|
|
if((fcall->count = strlen(buf)))
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-03-11 03:07:19 +03:00
|
|
|
break;
|
|
|
|
default:
|
2006-03-23 12:46:35 +03:00
|
|
|
for(i = 0; i < ntag; i++) {
|
|
|
|
len = strlen(tag[i]) + 1;
|
2006-03-11 03:07:19 +03:00
|
|
|
if(fcall->count + len > fcall->iounit)
|
|
|
|
break;
|
2006-03-23 12:46:35 +03:00
|
|
|
memcpy(p + fcall->count, tag[i], len - 1);
|
2006-03-11 03:07:19 +03:00
|
|
|
memcpy(p + fcall->count + len - 1, "\n", 1);
|
|
|
|
fcall->count += len;
|
|
|
|
}
|
|
|
|
break;
|
2006-03-07 19:22:36 +03:00
|
|
|
}
|
2006-03-05 18:48:14 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFdata:
|
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-03-10 00:43:24 +03:00
|
|
|
case FsFtag:
|
|
|
|
if((fcall->count = strlen(def.tag)))
|
|
|
|
memcpy(p, def.tag, fcall->count);
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFcolors:
|
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-03-05 16:16:48 +03:00
|
|
|
case FsFselcolors:
|
2006-02-10 20:32:35 +03:00
|
|
|
if((fcall->count = strlen(def.selcolor)))
|
|
|
|
memcpy(p, def.selcolor, fcall->count);
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFnormcolors:
|
2006-02-10 20:32:35 +03:00
|
|
|
if((fcall->count = strlen(def.normcolor)))
|
|
|
|
memcpy(p, def.normcolor, fcall->count);
|
|
|
|
break;
|
2006-03-10 18:21:20 +03:00
|
|
|
case FsFkeys:
|
|
|
|
fcall->count = def.keys ? strlen(def.keys) : 0;
|
|
|
|
if(fcall->count > fcall->iounit) {
|
|
|
|
memcpy(p, def.keys, fcall->iounit);
|
|
|
|
fcall->count = fcall->iounit;
|
|
|
|
}
|
|
|
|
else if(fcall->count)
|
|
|
|
memcpy(p, def.keys, fcall->count);
|
|
|
|
break;
|
2006-03-10 16:39:46 +03:00
|
|
|
case FsFrules:
|
2006-03-10 17:22:36 +03:00
|
|
|
fcall->count = def.rules ? strlen(def.rules) : 0;
|
|
|
|
if(fcall->count > fcall->iounit) {
|
|
|
|
memcpy(p, def.rules, fcall->iounit);
|
|
|
|
fcall->count = fcall->iounit;
|
|
|
|
}
|
|
|
|
else if(fcall->count)
|
|
|
|
memcpy(p, def.rules, fcall->count);
|
2006-03-10 16:39:46 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFfont:
|
2006-02-10 20:32:35 +03:00
|
|
|
if((fcall->count = strlen(def.font)))
|
|
|
|
memcpy(p, def.font, fcall->count);
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFmode:
|
2006-02-28 18:23:05 +03:00
|
|
|
if(!i2)
|
|
|
|
return Enofile;
|
2006-03-23 12:36:51 +03:00
|
|
|
snprintf(buf, sizeof(buf), "%s", mode2str(view[i1]->area[i2]->mode));
|
2006-02-28 18:23:05 +03:00
|
|
|
fcall->count = strlen(buf);
|
|
|
|
memcpy(p, buf, fcall->count);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
default:
|
2006-03-11 03:07:19 +03:00
|
|
|
return Enoperm;
|
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);
|
2006-03-23 18:07:18 +03:00
|
|
|
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-03-23 18:07:18 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-01-30 21:43:32 +03:00
|
|
|
char *name;
|
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
2006-03-01 09:51:04 +03:00
|
|
|
name = qid2name(&m->qid);
|
|
|
|
if(!type2stat(&fcall->stat, name, &m->qid))
|
2006-02-03 20:11:22 +03:00
|
|
|
return Enofile;
|
2006-03-23 18:07:18 +03:00
|
|
|
fcall->id = RSTAT;
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
|
2006-03-11 22:58:08 +03:00
|
|
|
static void
|
|
|
|
draw_clients()
|
|
|
|
{
|
|
|
|
unsigned int i, j;
|
|
|
|
for(i = 0; i < nclient; i++)
|
|
|
|
for(j = 0; j < client[i]->nframe; j++)
|
2006-03-23 12:36:51 +03:00
|
|
|
if(client[i]->frame[j]->area->view == view[sel])
|
2006-03-11 22:58:08 +03:00
|
|
|
draw_client(client[i]);
|
|
|
|
}
|
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
static char *
|
|
|
|
xwrite(IXPConn *c, Fcall *fcall)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-03-10 18:21:20 +03:00
|
|
|
char buf[256], *tmp;
|
2006-03-23 18:07:18 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-02-10 17:59:30 +03:00
|
|
|
unsigned char type;
|
2006-03-10 17:22:36 +03:00
|
|
|
unsigned int len;
|
2006-03-11 22:58:08 +03:00
|
|
|
int i, i1 = 0, i2 = 0, i3 = 0;
|
2006-03-05 03:55:45 +03:00
|
|
|
Frame *f;
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
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
|
|
|
|
2006-03-07 19:22:36 +03:00
|
|
|
switch(type) {
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFctl:
|
2006-02-06 11:46:52 +03:00
|
|
|
if(fcall->count > sizeof(buf) - 1)
|
|
|
|
return Enocommand;
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-02-10 17:59:30 +03:00
|
|
|
switch(m->qid.dir_type) {
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDroot:
|
2006-02-06 11:46:52 +03:00
|
|
|
if(!strncmp(buf, "quit", 5))
|
2006-02-08 13:07:30 +03:00
|
|
|
srv.running = 0;
|
2006-03-23 12:50:04 +03:00
|
|
|
else if(!strncmp(buf, "view ", 5))
|
2006-03-23 12:43:57 +03:00
|
|
|
select_view(&buf[5]);
|
2006-02-06 11:46:52 +03:00
|
|
|
else
|
|
|
|
return Enocommand;
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
2006-03-23 11:54:20 +03:00
|
|
|
case FsDview:
|
2006-02-19 18:21:01 +03:00
|
|
|
if(!strncmp(buf, "select ", 7))
|
2006-03-23 12:36:51 +03:00
|
|
|
if(nview)
|
|
|
|
select_area(view[i1]->area[view[i1]->sel], &buf[7]);
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDarea:
|
2006-02-14 14:06:16 +03:00
|
|
|
if(!strncmp(buf, "select ", 7)) {
|
2006-03-23 12:36:51 +03:00
|
|
|
Area *a = view[i1]->area[i2];
|
2006-03-05 03:55:45 +03:00
|
|
|
if(a->nframe)
|
|
|
|
select_client(a->frame[a->sel]->client, &buf[7]);
|
2006-02-14 14:06:16 +03:00
|
|
|
}
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsDclient:
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[i1]->area[i2]->frame[i3];
|
2006-02-16 17:28:51 +03:00
|
|
|
if(!strncmp(buf, "kill", 5))
|
2006-03-05 03:55:45 +03:00
|
|
|
kill_client(f->client);
|
2006-03-08 18:05:09 +03:00
|
|
|
else if(!strncmp(buf, "sendto ", 7))
|
|
|
|
send2area_client(f->client, &buf[7]);
|
2006-02-02 00:24:07 +03:00
|
|
|
break;
|
2006-03-07 19:22:36 +03:00
|
|
|
case FsDGclient:
|
|
|
|
if(!strncmp(buf, "kill", 5))
|
|
|
|
kill_client(client[i1]);
|
2006-03-08 18:05:09 +03:00
|
|
|
else if(!strncmp(buf, "sendto ", 7))
|
|
|
|
send2area_client(client[i1], &buf[7]);
|
2006-03-07 19:22:36 +03:00
|
|
|
break;
|
2006-02-02 00:24:07 +03:00
|
|
|
default:
|
2006-02-06 11:46:52 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFborder:
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-02-03 20:11:22 +03:00
|
|
|
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)
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-02-24 12:38:48 +03:00
|
|
|
def.border = i;
|
|
|
|
resize_all_clients();
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
2006-03-05 21:20:27 +03:00
|
|
|
case FsFtags:
|
2006-03-11 03:07:19 +03:00
|
|
|
if(m->qid.dir_type == FsDroot)
|
|
|
|
return Enoperm;
|
2006-03-24 17:17:50 +03:00
|
|
|
if(!fcall->count || (fcall->count > sizeof(buf)))
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-03-09 18:41:11 +03:00
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-03-07 19:22:36 +03:00
|
|
|
if(m->qid.dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[i1]->area[i2]->frame[i3];
|
2006-03-15 12:35:38 +03:00
|
|
|
f->client->ntag = str2tags(f->client->tag, buf);
|
2006-03-07 19:22:36 +03:00
|
|
|
}
|
2006-03-09 18:41:11 +03:00
|
|
|
else
|
2006-03-15 12:35:38 +03:00
|
|
|
client[i1]->ntag = str2tags(client[i1]->tag, buf);
|
2006-03-09 01:53:52 +03:00
|
|
|
update_tags();
|
2006-03-24 17:06:47 +03:00
|
|
|
draw_client(client[i1]);
|
2006-03-05 18:48:14 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFgeom:
|
2006-02-16 17:28:51 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-02-16 17:28:51 +03:00
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-03-07 19:22:36 +03:00
|
|
|
if(m->qid.dir_type == FsDclient) {
|
2006-03-23 12:36:51 +03:00
|
|
|
f = view[i1]->area[i2]->frame[i3];
|
2006-03-07 19:22:36 +03:00
|
|
|
blitz_strtorect(&rect, &f->rect, buf);
|
2006-03-15 18:00:39 +03:00
|
|
|
if(i2)
|
|
|
|
resize_area(f->client, &f->rect, nil);
|
|
|
|
else
|
|
|
|
resize_client(f->client, &f->rect, False);
|
2006-03-07 19:22:36 +03:00
|
|
|
}
|
2006-02-02 15:20:07 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFdata:
|
2006-03-10 17:22:36 +03:00
|
|
|
len = fcall->count;
|
|
|
|
if(len >= sizeof(label[i1]->data))
|
|
|
|
len = sizeof(label[i1]->data) - 1;
|
|
|
|
memcpy(label[i1]->data, fcall->data, len);
|
|
|
|
label[i1]->data[len] = 0;
|
|
|
|
draw_bar();
|
2006-02-10 00:48:01 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFcolors:
|
2006-03-23 18:07:18 +03:00
|
|
|
if((i1 >= nlabel) || (fcall->count != 23) || (fcall->data[0] != '#')
|
|
|
|
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
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-03-05 16:16:48 +03:00
|
|
|
case FsFselcolors:
|
2006-03-23 18:07:18 +03:00
|
|
|
if((fcall->count != 23) || (fcall->data[0] != '#')
|
|
|
|
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-02-10 20:32:35 +03:00
|
|
|
memcpy(def.selcolor, fcall->data, fcall->count);
|
|
|
|
def.selcolor[fcall->count] = 0;
|
|
|
|
blitz_loadcolor(dpy, screen, def.selcolor, &def.sel);
|
2006-03-11 22:58:08 +03:00
|
|
|
draw_clients();
|
2006-02-10 20:32:35 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFnormcolors:
|
2006-03-23 18:07:18 +03:00
|
|
|
if((fcall->count != 23) || (fcall->data[0] != '#')
|
|
|
|
|| (fcall->data[8] != '#') || (fcall->data[16] != '#'))
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-02-10 20:32:35 +03:00
|
|
|
memcpy(def.normcolor, fcall->data, fcall->count);
|
|
|
|
def.normcolor[fcall->count] = 0;
|
|
|
|
blitz_loadcolor(dpy, screen, def.normcolor, &def.norm);
|
2006-03-11 22:58:08 +03:00
|
|
|
draw_clients();
|
2006-02-10 20:32:35 +03:00
|
|
|
break;
|
2006-03-10 18:21:20 +03:00
|
|
|
case FsFkeys:
|
|
|
|
if(def.keyssz < fcall->offset + fcall->count + 1) {
|
|
|
|
def.keyssz = fcall->offset + fcall->count + 1;
|
|
|
|
tmp = cext_emallocz(def.keyssz);
|
|
|
|
len = def.keys ? strlen(def.keys) : 0;
|
|
|
|
if(len) {
|
|
|
|
memcpy(tmp, def.keys, len);
|
|
|
|
free(def.keys);
|
|
|
|
}
|
|
|
|
def.keys = tmp;
|
|
|
|
}
|
|
|
|
memcpy(def.keys + fcall->offset, fcall->data, fcall->count);
|
|
|
|
def.keys[fcall->offset + fcall->count] = 0;
|
|
|
|
break;
|
2006-03-10 16:39:46 +03:00
|
|
|
case FsFrules:
|
2006-03-10 18:21:20 +03:00
|
|
|
if(def.rulessz < fcall->offset + fcall->count + 1) {
|
|
|
|
def.rulessz = fcall->offset + fcall->count + 1;
|
|
|
|
tmp = cext_emallocz(def.rulessz);
|
|
|
|
len = def.rules ? strlen(def.rules) : 0;
|
|
|
|
if(len) {
|
|
|
|
memcpy(tmp, def.rules, len);
|
|
|
|
free(def.rules);
|
2006-03-10 17:22:36 +03:00
|
|
|
}
|
2006-03-10 18:21:20 +03:00
|
|
|
def.rules = tmp;
|
2006-03-10 16:39:46 +03:00
|
|
|
}
|
2006-03-10 18:21:20 +03:00
|
|
|
memcpy(def.rules + fcall->offset, fcall->data, fcall->count);
|
|
|
|
def.rules[fcall->offset + fcall->count] = 0;
|
2006-03-10 16:39:46 +03:00
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFfont:
|
2006-02-10 20:32:35 +03:00
|
|
|
if(def.font)
|
|
|
|
free(def.font);
|
|
|
|
def.font = cext_emallocz(fcall->count + 1);
|
|
|
|
memcpy(def.font, fcall->data, fcall->count);
|
|
|
|
XFreeFont(dpy, xfont);
|
2006-03-23 18:07:18 +03:00
|
|
|
xfont = blitz_getfont(dpy, def.font);
|
2006-02-10 20:32:35 +03:00
|
|
|
update_bar_geometry();
|
|
|
|
break;
|
2006-03-05 16:16:48 +03:00
|
|
|
case FsFmode:
|
2006-03-05 02:11:08 +03:00
|
|
|
if(!i2)
|
|
|
|
return Enofile;
|
2006-03-12 12:51:12 +03:00
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return Ebadvalue;
|
2006-03-05 02:11:08 +03:00
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
|
|
|
if((i = str2mode(buf)) == -1)
|
2006-03-11 03:07:19 +03:00
|
|
|
return Ebadvalue;
|
2006-03-23 12:36:51 +03:00
|
|
|
view[i1]->area[i2]->mode = i;
|
|
|
|
arrange_area(view[i1]->area[i2]);
|
2006-03-23 18:07:18 +03:00
|
|
|
break;
|
2006-03-12 12:51:12 +03:00
|
|
|
case FsFevent:
|
|
|
|
if(fcall->count > sizeof(buf))
|
|
|
|
return Ebadvalue;
|
2006-03-15 11:02:25 +03:00
|
|
|
if(fcall->count) {
|
|
|
|
memcpy(buf, fcall->data, fcall->count);
|
|
|
|
buf[fcall->count] = 0;
|
2006-03-23 20:08:55 +03:00
|
|
|
write_event(buf);
|
2006-03-15 11:02:25 +03:00
|
|
|
}
|
2006-03-12 12:51:12 +03:00
|
|
|
break;
|
2006-01-30 21:43:32 +03:00
|
|
|
default:
|
2006-03-11 03:07:19 +03:00
|
|
|
return Enoperm;
|
2006-01-30 21:43:32 +03:00
|
|
|
break;
|
|
|
|
}
|
2006-03-23 18:07:18 +03:00
|
|
|
fcall->id = RWRITE;
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
|
|
|
return nil;
|
2006-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-03-23 18:07:18 +03:00
|
|
|
IXPMap *m = ixp_server_fid2map(c, fcall->fid);
|
2006-01-30 21:43:32 +03:00
|
|
|
|
2006-03-23 18:07:18 +03:00
|
|
|
if(!m)
|
|
|
|
return Enofile;
|
2006-03-10 18:21:20 +03:00
|
|
|
if(qpath_type(m->qid.path) == FsFkeys)
|
2006-03-23 18:07:18 +03:00
|
|
|
update_keys();
|
2006-01-30 21:43:32 +03:00
|
|
|
cext_array_detach((void **)c->map, m, &c->mapsz);
|
2006-03-23 18:07:18 +03:00
|
|
|
free(m);
|
|
|
|
fcall->id = RCLUNK;
|
2006-02-03 20:11:22 +03:00
|
|
|
ixp_server_respond_fcall(c, fcall);
|
2006-03-23 18:07:18 +03:00
|
|
|
return nil;
|
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-03-23 18:07:18 +03:00
|
|
|
unsigned int msize;
|
2006-02-03 20:11:22 +03:00
|
|
|
char *errstr;
|
|
|
|
|
|
|
|
if((msize = ixp_server_receive_fcall(c, &fcall))) {
|
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-03-23 20:08:55 +03:00
|
|
|
write_event(char *event)
|
2006-01-30 21:43:32 +03:00
|
|
|
{
|
2006-03-23 20:08:55 +03:00
|
|
|
unsigned int i = 0;
|
2006-03-23 18:07:18 +03:00
|
|
|
|
2006-01-30 21:43:32 +03:00
|
|
|
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);
|
2006-01-30 21:43:32 +03:00
|
|
|
if(!m) {
|
2006-03-22 21:54:27 +03:00
|
|
|
if(ixp_server_respond_error(c, &c->pending, Enofile))
|
2006-03-23 10:43:26 +03:00
|
|
|
return;
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|
2006-03-05 16:16:48 +03:00
|
|
|
else if(qpath_type(m->qid.path) == FsFevent) {
|
2006-03-23 10:43:26 +03:00
|
|
|
/* pending reads on /event only, no qid checking */
|
2006-02-12 02:49:38 +03:00
|
|
|
c->pending.count = strlen(event);
|
2006-03-23 10:43:26 +03:00
|
|
|
memcpy(c->pending.data, event, c->pending.count);
|
2006-02-12 02:49:38 +03:00
|
|
|
c->pending.id = RREAD;
|
|
|
|
if(ixp_server_respond_fcall(c, &c->pending))
|
2006-03-23 10:43:26 +03:00
|
|
|
return;
|
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-03-23 18:07:18 +03:00
|
|
|
|
2006-02-03 20:11:22 +03:00
|
|
|
if(fd >= 0)
|
|
|
|
ixp_server_open_conn(c->srv, fd, do_fcall, ixp_server_close_conn);
|
2006-01-30 21:43:32 +03:00
|
|
|
}
|