wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit 7d76910f15f3e239665c658ec428cefc55092778
parent 8738150767e6f7b450a0bc17de54efaf6c031703
Author: garbeam <garbeam@localhost>
Date:   Wed,  4 Jan 2006 17:23:09 +0200

fixed several serious issues in ixp2 to work with Plan 9 9P


Diffstat:
cmd/wmiibar2.c | 33+++++++++++++++++----------------
cmd/wmiir2.c | 60+++++++++++++++++++++++++++++-------------------------------
libcext/cext.h | 6------
libixp2/client.c | 46+++++++++++++++++++++++-----------------------
libixp2/ixp.h | 20+++++++-------------
libixp2/message.c | 25++++++++++++++++++-------
libixp2/server.c | 15++++++++-------
liblitz/draw.c | 4++--
liblitz/geometry.c | 8++++----
9 files changed, 108 insertions(+), 109 deletions(-)

diff --git a/cmd/wmiibar2.c b/cmd/wmiibar2.c @@ -234,7 +234,7 @@ attach(IXPServer * s, IXPConn * c) new->fid = s->fcall.fid; s->fcall.id = RATTACH; s->fcall.qid = root_qid; - return TRUE; + return 0; } static int @@ -247,12 +247,12 @@ walk(IXPServer * s, IXPConn * c) fprintf(stderr, "%s", "walking\n"); if(!(map = fid_to_map(c->aux, s->fcall.fid))) { s->errstr = "no directory associated with fid"; - return FALSE; + return -1; } if(s->fcall.fid != s->fcall.newfid && (fid_to_map(c->aux, s->fcall.newfid))) { s->errstr = "fid alreay in use"; - return FALSE; + return -1; } if(s->fcall.nwname) { qid = map->qid; @@ -262,7 +262,7 @@ walk(IXPServer * s, IXPConn * c) qid = s->fcall.wqid[nwqid]; if(!nwqid) { s->errstr = "file not found"; - return FALSE; + return -1; } } /* @@ -291,7 +291,7 @@ walk(IXPServer * s, IXPConn * c) } s->fcall.id = RWALK; s->fcall.nwqid = nwqid; - return TRUE; + return 0; } static int @@ -302,17 +302,17 @@ _open(IXPServer * s, IXPConn * c) fprintf(stderr, "%s", "opening\n"); if(!map) { s->errstr = "invalid fid"; - return FALSE; + return -1; } if((s->fcall.mode != IXP_OREAD) && (s->fcall.mode != IXP_OWRITE)) { s->errstr = "mode not supported"; - return FALSE; + return -1; } s->fcall.id = ROPEN; s->fcall.qid = map->qid; s->fcall.iounit = s->fcall.maxmsg - (sizeof(unsigned char) + sizeof(unsigned short) + 2 * sizeof(unsigned int)); - return TRUE; + return 0; } static int @@ -325,7 +325,7 @@ _read(IXPServer * s, IXPConn * c) fprintf(stderr, "%s", "reading\n"); if(!map) { s->errstr = "invalid fid"; - return FALSE; + return -1; } stat.mode = 0xff; stat.atime = stat.mtime = time(0); @@ -337,6 +337,7 @@ _read(IXPServer * s, IXPConn * c) switch (qpath_type(map->qid.path)) { default: case Droot: + s->fcall.count = 0; p = s->fcall.data; cext_strlcpy(stat.name, "display", sizeof(stat.name)); stat.length = strlen(align); @@ -357,7 +358,8 @@ _read(IXPServer * s, IXPConn * c) s->fcall.count += stat.size; p = ixp_enc_stat(p, &stat); s->fcall.id = RREAD; - fprintf(stderr, "%d msize\n", s->fcall.count); + if(s->fcall.offset >= s->fcall.count) + s->fcall.count = 0; /* EOF */ break; case Ditem: break; @@ -375,14 +377,13 @@ _read(IXPServer * s, IXPConn * c) break; } - return TRUE; + return 0; } static int _write(IXPServer * s, IXPConn * c) { - - return FALSE; + return -1; } static int @@ -393,7 +394,7 @@ clunk(IXPServer * s, IXPConn * c) if(!map) { s->errstr = "invalid fid"; - return FALSE; + return -1; } if(maps == map) maps = maps->next; @@ -403,7 +404,7 @@ clunk(IXPServer * s, IXPConn * c) } free(map); s->fcall.id = RCLUNK; - return TRUE; + return 0; } static void @@ -462,7 +463,7 @@ main(int argc, char *argv[]) XSetErrorHandler(dummy_error_handler); screen_num = DefaultScreen(dpy); - if(!ixp_server_init(&srv, sockfile, funcs, freeconn)) { + if(ixp_server_init(&srv, sockfile, funcs, freeconn) == -1) { fprintf(stderr, "wmiibar: fatal: %s\n", srv.errstr); exit(1); } diff --git a/cmd/wmiir2.c b/cmd/wmiir2.c @@ -50,7 +50,7 @@ usage() exit(1); } -static unsigned int +static int write_data(unsigned int fid, unsigned char *data, unsigned int count) { unsigned int len, i, runs = count / c.fcall.iounit; @@ -64,7 +64,7 @@ write_data(unsigned int fid, unsigned char *data, unsigned int count) (&c, fid, i * c.fcall.iounit, len, &data[i * c.fcall.iounit]) != count) { fprintf(stderr, "wmiir: cannot write file: %s\n", c.errstr); - return 0; + return -1; } } return count; @@ -79,19 +79,19 @@ xcreate(char **argv) fid = c.root_fid << 2; /* walk to bottom-most directory */ *p = 0; - if(!ixp_client_walk(&c, fid, argv[0])) { + if(ixp_client_walk(&c, fid, argv[0]) == -1) { fprintf(stderr, "wmiir: cannot walk to %s: %s\n", argv[0], c.errstr); - return 1; + return -1; } /* create */ p++; - if(!ixp_client_create(&c, fid, p, (unsigned int) 0xff, IXP_OWRITE)) { + if(ixp_client_create(&c, fid, p, (unsigned int) 0xff, IXP_OWRITE) == -1) { fprintf(stderr, "wmiir: cannot create file: %s\n", c.errstr); - return 1; + return -1; } write_data(fid, (unsigned char *) argv[1], strlen(argv[1])); - return !ixp_client_close(&c, fid); + return ixp_client_close(&c, fid); } static int @@ -99,12 +99,12 @@ xwrite(char **argv) { /* open */ unsigned int fid = c.root_fid << 2; - if(!ixp_client_open(&c, fid, argv[0], IXP_OWRITE)) { + if(ixp_client_open(&c, fid, argv[0], IXP_OWRITE) == -1) { fprintf(stderr, "wmiir: cannot open file: %s\n", c.errstr); - return 1; + return -1; } write_data(fid, (unsigned char *) argv[1], strlen(argv[1])); - return !ixp_client_close(&c, fid); + return ixp_client_close(&c, fid); } static void @@ -128,32 +128,30 @@ print_directory(void *result, unsigned int msize) static int xread(char **argv) { - unsigned int count, fid = c.root_fid << 2; - int is_directory = FALSE; + unsigned int fid = c.root_fid << 2; + int count, is_directory = 0; static unsigned char result[IXP_MAX_MSG]; /* open */ - if(!ixp_client_open(&c, fid, argv[0], IXP_OREAD)) { + if(ixp_client_open(&c, fid, argv[0], IXP_OREAD) == -1) { fprintf(stderr, "wmiir: cannot open file '%s': %s\n", argv[0], c.errstr); - return 1; + return -1; } is_directory = !c.fcall.nwqid || (c.fcall.qid.type == IXP_QTDIR); /* read */ - if(!(count = ixp_client_read(&c, fid, 0, result, IXP_MAX_MSG)) - && c.errstr) { + count = ixp_client_read(&c, fid, 0, result, IXP_MAX_MSG); + if(count == -1) { fprintf(stderr, "wmiir: cannot read file: %s\n", c.errstr); - return 1; + return -1; } - if(count) { - if(is_directory) - print_directory(result, count); - else { - unsigned int i; - for(i = 0; i < count; i++) - putchar(result[i]); - } - } - return !ixp_client_close(&c, fid); + if(is_directory) + print_directory(result, count); + else { + unsigned int i; + for(i = 0; i < count; i++) + putchar(result[i]); + } + return ixp_client_close(&c, fid); } static int @@ -163,9 +161,9 @@ xremove(char **argv) /* remove */ fid = c.root_fid << 2; - if(!ixp_client_remove(&c, fid, argv[0])) { + if(ixp_client_remove(&c, fid, argv[0]) == -1) { fprintf(stderr, "wmiir: cannot remove file: %s\n", c.errstr); - return 1; + return -1; } return 0; } @@ -182,7 +180,7 @@ perform_cmd(int argc, char **argv) usage(); } /* bogus command */ - return 1; + return -1; } int @@ -219,7 +217,7 @@ main(int argc, char *argv[]) usage(); } /* open socket */ - if(!ixp_client_init(&c, sockfile)) { + if(ixp_client_init(&c, sockfile) == -1) { fprintf(stderr, "wmiir: %s\n", c.errstr); exit(1); } diff --git a/libcext/cext.h b/libcext/cext.h @@ -8,12 +8,6 @@ #ifndef nil #define nil (void *)0 #endif -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif /* emallocz.c */ void *cext_emallocz(size_t size); diff --git a/libixp2/client.c b/libixp2/client.c @@ -21,18 +21,18 @@ do_fcall(IXPClient * c) unsigned int msize = ixp_fcall_to_msg(&c->fcall, msg, IXP_MAX_MSG); c->errstr = 0; if(ixp_send_message(c->fd, msg, msize, &c->errstr) != msize) - return FALSE; + return -1; if(!ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &c->errstr)) - return FALSE; + return -1; if(!(msize = ixp_msg_to_fcall(msg, IXP_MAX_MSG, &c->fcall))) { c->errstr = "received bad message"; - return FALSE; + return -1; } if(c->fcall.id == RERROR) { c->errstr = c->fcall.errstr; - return FALSE; + return -1; } - return TRUE; + return 0; } int @@ -40,21 +40,21 @@ ixp_client_init(IXPClient * c, char *sockfile) { if((c->fd = ixp_connect_sock(sockfile)) < 0) { c->errstr = "cannot connect server"; - return FALSE; + return -1; } /* version */ c->fcall.id = TVERSION; c->fcall.tag = IXP_NOTAG; c->fcall.maxmsg = IXP_MAX_MSG; cext_strlcpy(c->fcall.version, IXP_VERSION, sizeof(c->fcall.version)); - if(!do_fcall(c)) { + if(do_fcall(c) == -1) { ixp_client_deinit(c); - return FALSE; + return -1; } if(strncmp(c->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) { c->errstr = "9P versions differ"; ixp_client_deinit(c); - return FALSE; /* we cannot handle this version */ + return -1; /* we cannot handle this version */ } c->root_fid = getpid(); @@ -65,19 +65,19 @@ ixp_client_init(IXPClient * c, char *sockfile) c->fcall.afid = IXP_NOFID; cext_strlcpy(c->fcall.uname, getenv("USER"), sizeof(c->fcall.uname)); c->fcall.aname[0] = 0; - if(!do_fcall(c)) { + if(do_fcall(c) == -1) { ixp_client_deinit(c); - return FALSE; + return -1; } c->root_qid = c->fcall.qid; - return TRUE; + return 0; } int ixp_client_remove(IXPClient * c, unsigned int newfid, char *filepath) { - if(!ixp_client_walk(c, newfid, filepath)) - return FALSE; + if(ixp_client_walk(c, newfid, filepath) == -1) + return -1; /* remove */ c->fcall.id = TREMOVE; c->fcall.tag = IXP_NOTAG; @@ -119,8 +119,8 @@ int ixp_client_open(IXPClient * c, unsigned int newfid, char *filepath, unsigned char mode) { - if(!ixp_client_walk(c, newfid, filepath)) - return FALSE; + if(ixp_client_walk(c, newfid, filepath) == -1) + return -1; /* open */ c->fcall.id = TOPEN; @@ -130,7 +130,7 @@ ixp_client_open(IXPClient * c, unsigned int newfid, char *filepath, return do_fcall(c); } -unsigned int +int ixp_client_read(IXPClient * c, unsigned int fid, unsigned long long offset, void *result, unsigned int res_len) { @@ -144,13 +144,13 @@ ixp_client_read(IXPClient * c, unsigned int fid, unsigned long long offset, c->fcall.fid = fid; c->fcall.offset = offset; c->fcall.count = res_len < bytes ? res_len : bytes; - if(!do_fcall(c)) - return 0; + if(do_fcall(c) == -1) + return -1; memcpy(result, c->fcall.data, c->fcall.count); return c->fcall.count; } -unsigned int +int ixp_client_write(IXPClient * c, unsigned int fid, unsigned long long offset, unsigned int count, unsigned char *data) @@ -160,7 +160,7 @@ ixp_client_write(IXPClient * c, unsigned int fid, 2 * sizeof(unsigned int) + sizeof(unsigned long long))) { c->errstr = "message size exceeds buffer size"; - return 0; + return -1; } /* write */ c->fcall.id = TWRITE; @@ -169,8 +169,8 @@ ixp_client_write(IXPClient * c, unsigned int fid, c->fcall.offset = offset; c->fcall.count = count; memcpy(c->fcall.data, data, count); - if(!do_fcall(c)) - return 0; + if(do_fcall(c) == -1) + return -1; return c->fcall.count; } diff --git a/libixp2/ixp.h b/libixp2/ixp.h @@ -5,12 +5,6 @@ #include <sys/types.h> -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif #ifndef nil #define nil 0 #endif @@ -176,7 +170,7 @@ typedef struct { unsigned char mode; /* Tcreate, Topen */ unsigned int newfid; /* Twalk */ unsigned short nwname; /* Twalk */ - char *wname[IXP_MAX_WELEM]; /* Twalk */ + char wname[IXP_MAX_WELEM][IXP_MAX_FLEN]; /* Twalk */ unsigned short nwqid; /* Rwalk */ Qid wqid[IXP_MAX_WELEM]; /* Rwalk */ unsigned long long offset; /* Tread, Twrite */ @@ -229,12 +223,12 @@ int ixp_client_create(IXPClient * c, unsigned int dirfid, char *name, int ixp_client_walk(IXPClient * c, unsigned int newfid, char *filepath); int ixp_client_open(IXPClient * c, unsigned int newfid, char *filepath, unsigned char mode); -unsigned int ixp_client_read(IXPClient * c, unsigned int fid, - unsigned long long offset, void *result, - unsigned int res_len); -unsigned int ixp_client_write(IXPClient * c, unsigned int fid, - unsigned long long offset, - unsigned int count, unsigned char *data); +int ixp_client_read(IXPClient * c, unsigned int fid, + unsigned long long offset, void *result, + unsigned int res_len); +int ixp_client_write(IXPClient * c, unsigned int fid, + unsigned long long offset, + unsigned int count, unsigned char *data); int ixp_client_close(IXPClient * c, unsigned int fid); /* convert.c */ diff --git a/libixp2/message.c b/libixp2/message.c @@ -3,10 +3,14 @@ * See LICENSE file for license details. */ +#include <stdio.h> #include <stdlib.h> #include <string.h> #include "ixp.h" +#define IXP_QIDSZ (sizeof(unsigned char) + sizeof(unsigned int)\ + + sizeof(unsigned long long)) + static unsigned short sizeof_string(const char *s) { @@ -16,7 +20,7 @@ sizeof_string(const char *s) unsigned short ixp_sizeof_stat(Stat * stat) { - return sizeof(Qid) + return IXP_QIDSZ + 2 * sizeof(unsigned short) + 4 * sizeof(unsigned int) + sizeof(unsigned long long) @@ -46,7 +50,7 @@ ixp_fcall_to_msg(Fcall * fcall, void *msg, unsigned int msglen) break; case RAUTH: case RATTACH: - msize += sizeof(Qid); + msize += IXP_QIDSZ; break; case TATTACH: msize += @@ -71,14 +75,14 @@ ixp_fcall_to_msg(Fcall * fcall, void *msg, unsigned int msglen) msize += sizeof(unsigned short); break; case RWALK: - msize += sizeof(unsigned short) + fcall->nwqid * sizeof(Qid); + msize += sizeof(unsigned short) + fcall->nwqid * IXP_QIDSZ; break; case TOPEN: msize += sizeof(unsigned int) + sizeof(unsigned char); break; case ROPEN: case RCREATE: - msize += sizeof(Qid) + sizeof(unsigned int); + msize += IXP_QIDSZ + sizeof(unsigned int); break; case TCREATE: msize += @@ -197,7 +201,10 @@ ixp_fcall_to_msg(Fcall * fcall, void *msg, unsigned int msglen) p = ixp_enc_stat(p, &fcall->stat); break; } - return msize; + + if(msg + msize == p) + return msize; + return 0; } unsigned int @@ -244,8 +251,10 @@ ixp_msg_to_fcall(void *msg, unsigned int msglen, Fcall * fcall) p = ixp_dec_u32(p, &fcall->fid); p = ixp_dec_u32(p, &fcall->newfid); p = ixp_dec_u16(p, &fcall->nwname); - for(i = 0; i < fcall->nwname; i++) + for(i = 0; i < fcall->nwname; i++) { + p = ixp_dec_string(p, fcall->wname[i], IXP_MAX_FLEN, &len); + } break; case RWALK: p = ixp_dec_u16(p, &fcall->nwqid); @@ -299,5 +308,7 @@ ixp_msg_to_fcall(void *msg, unsigned int msglen, Fcall * fcall) break; } - return msize; + if(msg + msize == p) + return msize; + return 0; } diff --git a/libixp2/server.c b/libixp2/server.c @@ -104,7 +104,7 @@ server_client_read(IXPServer * s, IXPConn * c) if((msize = ixp_msg_to_fcall(msg, IXP_MAX_MSG, &s->fcall))) { for(i = 0; s->funcs && s->funcs[i].id; i++) { if(s->funcs[i].id == s->fcall.id) { - if(!s->funcs[i].tfunc(s, c)) + if(s->funcs[i].tfunc(s, c) == -1) break; msize = ixp_fcall_to_msg(&s->fcall, msg, s->fcall.maxmsg); fprintf(stderr, "msize=%d\n", msize); @@ -115,6 +115,7 @@ server_client_read(IXPServer * s, IXPConn * c) } } } + fprintf(stderr, "function id=%d\n", s->fcall.id); if(!s->errstr) s->errstr = "function not supported"; s->fcall.id = RERROR; @@ -137,7 +138,7 @@ void ixp_server_loop(IXPServer * s) { int r; - s->running = TRUE; + s->running = 1; s->errstr = 0; /* main loop */ @@ -163,11 +164,11 @@ ixp_server_tversion(IXPServer * s, IXPConn * c) IXP_VERSION, s->fcall.maxmsg, IXP_MAX_MSG); if(strncmp(s->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) { s->errstr = "9P versions differ"; - return FALSE; + return -1; } else if(s->fcall.maxmsg > IXP_MAX_MSG) s->fcall.maxmsg = IXP_MAX_MSG; s->fcall.id = RVERSION; - return TRUE; + return 0; } int @@ -180,14 +181,14 @@ ixp_server_init(IXPServer * s, char *sockfile, IXPTFunc * funcs, s->errstr = 0; if(!sockfile) { s->errstr = "no socket file provided or invalid directory"; - return FALSE; + return -1; } if((fd = ixp_create_sock(sockfile, &s->errstr)) < 0) - return FALSE; + return -1; for(i = 0; i < IXP_MAX_CONN; i++) s->conn[i] = zero_conn; ixp_server_add_conn(s, fd, 0, server_read); - return TRUE; + return 0; } void diff --git a/liblitz/draw.c b/liblitz/draw.c @@ -77,7 +77,7 @@ static void _draw_border(Display * dpy, Draw * d) static void draw_text(Display * dpy, Draw * d) { - unsigned int x, y, w, h, shortened = FALSE; + unsigned int x, y, w, h, shortened = 0; size_t len = 0; static char text[2048]; @@ -94,7 +94,7 @@ static void draw_text(Display * dpy, Draw * d) while (len && (w = XTextWidth(d->font, text, len)) > d->rect.width) { text[len - 1] = 0; len--; - shortened = TRUE; + shortened = 1; } if (w > d->rect.width) diff --git a/liblitz/geometry.c b/liblitz/geometry.c @@ -36,8 +36,8 @@ static int strtoalign(Align * result, char *val) else if (!strncmp(val, "center", 6)) *result = CENTER; else - return FALSE; - return TRUE; + return -1; + return 0; } /** @@ -53,7 +53,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val) int rx, ry, rw, rh, sx, sy, sw, sh; if (!val) - return FALSE; + return -1; rx = r->x; ry = r->y; rw = r->width; @@ -193,7 +193,7 @@ int blitz_strtorect(XRectangle *root, XRectangle *r, char *val) r->y = ry; r->width = rw; r->height = rh; - return TRUE; + return 0; } Bool blitz_ispointinrect(int x, int y, XRectangle * r)