Commit ef7c84a0 authored by Bernhard Link's avatar Bernhard Link

allow variable length events

parent 42035f08
......@@ -856,7 +856,27 @@ static size_t printLISTofVarStruct(struct connection *c,const uint8_t *buffer,si
}
/* buffer must have at least 32 valid bytes */
static void print_event(struct connection *c,const unsigned char *buffer);
static const struct event *find_event(struct connection *c, const unsigned char *buffe, const char **extension_name);
static void print_event_data(struct connection *c, const unsigned char *buffer, size_t len, const struct event *event, const char *extension);
static inline void print_event(struct connection *c, const unsigned char *buffer, size_t len) {
const struct event *event;
const char *name;
size_t l;
event = find_event(c, buffer, &name);
if( event != NULL && event->type == event_xge)
l = 32 + 4*getCARD32(4);
else
l = 32;
if( len < l ) {
// TODO: warn about incomplete?
return;
}
print_event_data(c, buffer, l, event, name);
}
static size_t print_parameters(struct connection *c,const unsigned char *buffer,unsigned int len, const struct parameter *parameters,bool bigrequest, struct stack *oldstack) {
const struct parameter *p;
......@@ -1052,7 +1072,8 @@ static size_t print_parameters(struct connection *c,const unsigned char *buffer,
continue;
case ft_EVENT:
if( len >= ofs + 32 )
print_event(c,buffer+ofs);
print_event(c, buffer + ofs, len - ofs);
// TODO: do something with the size here?
continue;
case ft_ATOM:
if( ofs + 4 > len )
......@@ -1240,6 +1261,7 @@ static size_t print_parameters(struct connection *c,const unsigned char *buffer,
return lastofs;
}
/* replace ra(GrabButton) in requests.inc by ra2(GrabButton)
* and add this function and all
* GrabButton requests will have an AnyModifier set before
......@@ -1474,10 +1496,80 @@ static inline void print_client_request(struct connection *c,bool bigrequest) {
}
}
static inline void print_generic_event(struct connection *c, const unsigned char *buffer, size_t len, const struct event *event) {
unsigned long stackvalues[30];
struct stack stack;
stack.base = stackvalues;
stack.num = 30;
stack.ofs = 0;
uint8_t opcode = getCARD8(1);
const struct extension *extension;
extension = find_extension_by_opcode(c, opcode);
if( extension != NULL ) {
fprintf(out, "%s(%hhu) ", extension->name, opcode);
// TODO: get description from format...
print_parameters(c, buffer, len, event->parameters, false, &stack);
} else {
const char *name = find_unknown_extension(c, opcode);
if( name != NULL ) {
fprintf(out, "%s(%hhu) ", name, opcode);
} else {
fprintf(out, "unknown extension %hhu ", opcode);
}
print_parameters(c, buffer, len, event->parameters, false, &stack);
}
}
static void print_event_data(struct connection *c, const unsigned char *buffer, size_t len, const struct event *event, const char *extension) {
uint8_t code = getCARD8(0);
unsigned long stackvalues[30];
struct stack stack;
stack.base = stackvalues;
stack.num = 30;
stack.ofs = 0;
if( (code & 0x80) != 0 )
fputs("(generated) ",out);
code &= 0x7F;
if( event == NULL ) {
fprintf(out, "unknown code %hhu", code);
// TODO: print data as LISTofCARD8 ?
return;
}
if( extension != NULL ) {
fputs(extension, out);
putc('-', out);
}
fprintf(out,"%s(%hhu) ", event->name, code);
switch( event->type ) {
case event_normal:
print_parameters(c, buffer, len,
event->parameters, false, &stack);
break;
case event_xge:
print_generic_event(c, buffer, len,
event);
break;
}
}
static inline void print_server_event(struct connection *c) {
const struct event *event;
const char *name;
event = find_event(c, c->serverbuffer, &name);
if( event != NULL && event->type == event_xge) {
if( c->servercount < 32 + 4*serverCARD32(4) ) {
/* wait till fully received */
return;
}
c->serverignore = 32 + 4*serverCARD32(4);
} else
c->serverignore = 32;
startline(c, TO_CLIENT, "%04llx: Event ", (unsigned long long)c->seq);
print_event(c,c->serverbuffer);
print_event_data(c, c->serverbuffer, c->serverignore, event, name);
putc('\n',out);
}
......@@ -1492,6 +1584,7 @@ static inline void print_server_reply(struct connection *c) {
stack.num = 30;
stack.ofs = 0;
c->serverignore = 32 + 4*serverCARD32(4);
len = c->serverignore;
if( len > c->servercount )
len = c->servercount;
......@@ -1545,7 +1638,9 @@ static inline void print_server_error(struct connection *c) {
struct usedextension *u;
const char *errorname;
uint16_t seq;
struct expectedreply *replyto,**lastp;
struct expectedreply *replyto, **lastp;
c->serverignore = 32;
if( cmd < num_errors )
errorname = errors[cmd];
else {
......@@ -1705,16 +1800,14 @@ void parse_server(struct connection *c) {
return;
switch( c->serverbuffer[0] ) {
case 0: /* Error */
c->serverignore = 32;
print_server_error(c);
break;
case 1: /* Reply */
c->serverignore = 32 + 4*serverCARD32(4);
print_server_reply(c);
break;
default:
c->serverignore = 32;
print_server_event(c);
break;
}
return;
case s_amlost:
......@@ -1726,43 +1819,10 @@ void parse_server(struct connection *c) {
const struct event *events;
size_t num_events;
void print_generic_event(struct connection *c, const unsigned char *buffer, const struct event *event) {
unsigned long stackvalues[30];
struct stack stack;
stack.base = stackvalues;
stack.num = 30;
stack.ofs = 0;
uint8_t opcode = getCARD8(1);
const struct extension *extension;
extension = find_extension_by_opcode(c, opcode);
if( extension != NULL ) {
fprintf(out, "%s(%hhu) ", extension->name, opcode);
// TODO: get description from format...
print_parameters(c, buffer, 32, event->parameters, false, &stack);
} else {
const char *name = find_unknown_extension(c, opcode);
if( name != NULL ) {
fprintf(out, "%s(%hhu) ", name, opcode);
} else {
fprintf(out, "unknown extension %hhu ", opcode);
}
print_parameters(c, buffer, 32, event->parameters, false, &stack);
}
}
static void print_event(struct connection *c,const unsigned char *buffer) {
static const struct event *find_event(struct connection *c, const unsigned char *buffer, const char **extension_name) {
struct usedextension *u;
const struct event *event;
uint8_t code = getCARD8(0);
unsigned long stackvalues[30];
struct stack stack;
stack.base = stackvalues;
stack.num = 30;
stack.ofs = 0;
if( (code & 0x80) != 0 )
fputs("(generated) ",out);
code &= 0x7F;
/* first look in extensions, in case we are on an xserver that
* uses some of the new core event codes for extensions */
......@@ -1771,29 +1831,20 @@ static void print_event(struct connection *c,const unsigned char *buffer) {
continue;
if( code >= u->first_event &&
code-u->first_event < u->extension->numevents) {
event = u->extension->events +
*extension_name = u->extension->name;
return u->extension->events +
(code - u->first_event);
break;
}
}
if( u == NULL ) {
if( code <= 1 || code > num_events ) {
fprintf(out, "unknown code %hhu", code);
return;
} else
event = &events[code];
} else {
fputs(u->extension->name, out);
putc('-', out);
}
fprintf(out,"%s(%hhu) ",event->name,code);
if( event->handler == NULL ) {
print_parameters(c,buffer,32,event->parameters,false,&stack);
} else {
event->handler(c, buffer, event);
if( code > 1 || code <= num_events ) {
*extension_name = NULL;
return &events[code];
}
return NULL;
}
const struct extension *extensions;
size_t num_extensions;
......
......@@ -22,7 +22,7 @@ struct request {
struct event {
const char *name;
const struct parameter *parameters;
event_func *handler;
enum event_type { event_normal = 0, event_xge } type;
};
struct extension {
......@@ -143,6 +143,5 @@ extern request_func requestInternAtom;
extern reply_func replyListFontsWithInfo;
extern reply_func replyQueryExtension;
extern reply_func replyInternAtom;
extern event_func print_generic_event;
#endif
......@@ -2351,7 +2351,7 @@ static const struct event *finalize_events(struct parser *parser, struct namespa
ns->name);
parser->error = true;
} else if( strcmp(es[i].name, "Generic") == 0 ) {
es[i].handler = print_generic_event;
es[i].type = event_xge;
} else {
fprintf(stderr, "No specials available for '%s::%s'!\n",
ns->name, es[i].name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment