#include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_GetMotionEvents PRIV_GetMotionEvents; struct priv_GetMotionEvents { int *nevp; LX_TIMECOORD **evp; } ; static void done_GetMotionEvents(LX_OP *op, const unsigned char *rep) { PRIV_GetMotionEvents *p; unsigned int n; unsigned int i; size_t sz; LX_TIMECOORD *v; int o; p = op->reqpriv; do <"ret"> { // We have to be careful of overflow.... n = r_card32(rep+8); if (r_card32(rep+4) != n*2ULL) { lx__protoerr(op->conn,"GetMotionEvents response length wrong (%u, expecting %llu)",r_card32(rep+4),n*2ULL); break <"ret">; } sz = n * (size_t)8; if (sz>>3 != n) { lx__protoerr(op->conn,"GetMotionEvents response requires too much data (%llu, max size_t is %llu)", (unsigned long long int)(n*8ULL),(unsigned long long int)~(size_t)0); break <"ret">; } if (p->evp) { v = malloc(sz); if (! v) { lx__nomem_fail(op->conn); break <"ret">; } o = 32; for (i=0;ievp = v; } if (p->nevp) *p->nevp = n; } while (0); op->reqpriv = 0; free(p); } LX_OP *lx_GetMotionEvents(LX_CONN *xc, LX_XID window, LX_TIME start, LX_TIME stop, int *nevp, LX_TIMECOORD **evp) { unsigned char req[16]; PRIV_GetMotionEvents *p; if (xc->flags & XCF_FAIL) { lx__bad_call(xc,"lx_GetMotionEvents"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_GetMotionEvents)); if (! p) { lx__nomem_fail(xc); return(0); } p->nevp = nevp; p->evp = evp; req[0] = XP_REQ_GetMotionEvents; req[1] = 0; w_card16(&req[2],4); w_card32(&req[4],window); w_card32(&req[8],start); w_card32(&req[12],stop); return(lx__expect_reply(xc,&req[0],-1,&done_GetMotionEvents,p)); }