#include #include #include "lx.h" #include "proto.h" #include "internal.h" typedef struct priv_GetFontPath PRIV_GetFontPath; struct priv_GetFontPath { LX_STRLIST **slp; } ; static void done_GetFontPath(LX_OP *op, const unsigned char *rep, void *pv) { PRIV_GetFontPath *p; int n; LX_STRLIST *l; int i; int pl; int po; int rl; int ro; int sl; p = pv; do <"ret"> { n = r_card16(rep+8); do <"fail"> { do <"mem"> { if (p->slp) { l = malloc(sizeof(LX_STRLIST)); if (! l) break <"mem">; l->len = n; l->lens = 0; l->data = 0; l->alldata = 0; l->lens = malloc(n*sizeof(int)); if (! l->lens) break <"mem">; l->data = malloc(n*sizeof(char *)); if (! l->data) break <"mem">; rl = r_card32(rep+4) * 4; l->alldata = malloc(rl); if (! l->alldata) break <"mem">; pl = 32 + rl; po = 32; ro = 0; for (i=0;i pl) { lx__protoerr(op->conn,"GetFontPath reply string overruns packet"); break <"fail">; } sl = rep[po]; if (po+1+sl > pl) { lx__protoerr(op->conn,"GetFontPath reply string overruns packet"); break <"fail">; } l->lens[i] = sl; l->data[i] = l->alldata + ro; bcopy(rep+po+1,l->alldata+ro,sl); l->alldata[ro+sl] = '\0'; ro += sl + 1; po += 1 + sl; } if (po > pl) lx_abort(); if (pl-po > 3) { lx__protoerr(op->conn,"GetFontPath reply is too long"); break <"fail">; } *p->slp = l; } break <"ret">; } while (0); lx__nomem_fail(op->conn); } while (0); if (l) { free(l->lens); free(l->data); free(l->alldata); free(l); } } while (0); free(p); } LX_OP *lx_GetFontPath(LX_CONN *xc, LX_STRLIST **slp) { unsigned char req[4]; PRIV_GetFontPath *p; if (xc->flags & XCF_FAIL) { lx__bad_call(xc,"lx_GetFontPath"); return(0); } lx__nochain(xc); p = malloc(sizeof(PRIV_GetFontPath)); if (! p) { lx__nomem_fail(xc); return(0); } p->slp = slp; req[0] = XP_REQ_GetFontPath; req[1] = 0; w_card16(&req[2],1); return(lx__expect_reply(xc,&req[0],-1,&done_GetFontPath,p)); }