X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgldecoder.c;h=81b1a43c128b8f3ddba292f86cc883dff2c9ff17;hb=17fa41a4dfef75ce671bf71306929d1f5b91025a;hp=863be925aeaaf55eee6961c9114ddaae7e0e3ebf;hpb=3c32a221de1435ae7af8d96182560e8b28f1a4c0;p=gldbg.git diff --git a/source/gldecoder.c b/source/gldecoder.c index 863be92..81b1a43 100644 --- a/source/gldecoder.c +++ b/source/gldecoder.c @@ -1,7 +1,7 @@ /* $Id$ This file is part of gldbg -Copyright © 2009 Mikko Rasa, Mikkosoft Productions +Copyright © 2009-2010 Mikko Rasa, Mikkosoft Productions Distributed under the GPL */ @@ -9,11 +9,10 @@ Distributed under the GPL #include #include "functions.h" #include "gldecoder.h" +#include "packet.h" -static unsigned read_short(short *, const char *); -static unsigned read_int(int *, const char *); -static int decode_func(GlDecoder *, unsigned short, const char *); -static int decode_gldfunc(GlDecoder *, unsigned short, const char *); +static int decode_func(GlDecoder *, unsigned short, GlPacket *); +static int decode_gldfunc(GlDecoder *, unsigned short, GlPacket *); GlDecoder *gldecoder_new(void *user_data, void (*destroy)(void *)) { @@ -36,129 +35,59 @@ void gldecoder_delete(GlDecoder *dec) int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len) { - unsigned pos = 0; - int pktlen; + GlPacket *pkt; unsigned short func; - int ret; - if(lengldError) dec->gldError(dec->user_data, code); - return pos; + else if(dec->unhandled) + dec->unhandled(dec->user_data, FUNC_GLDERROR); +} + +static void decode_gldBreak(GlDecoder *dec, GlPacket *pkt) +{ + unsigned short func; + packet_read_short(pkt, (short *)&func); + if(dec->gldBreak) + dec->gldBreak(dec->user_data, func); + else if(dec->unhandled) + dec->unhandled(dec->user_data, FUNC_GLDBREAK); } -static int decode_gldfunc(GlDecoder *dec, unsigned short func, const char *data) +static int decode_gldfunc(GlDecoder *dec, unsigned short func, GlPacket *pkt) { switch(func) { - case FUNC_GLDERROR: return decode_gldError(dec, data); + case FUNC_GLDERROR: decode_gldError(dec, pkt); break; + case FUNC_GLDBREAK: decode_gldBreak(dec, pkt); break; default: return -1; } + return 0; }