X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgldecoder.c;h=22b6285a244130fae4dd8d7af9481433402e7741;hb=6d297b506314c07bff3d77c2853a5f59380cfcb0;hp=6e903736f726a5840c9252056858c52b910d0592;hpb=6475e8951e1901b247f5d1d1dd9fcfc1e77e163a;p=gldbg.git diff --git a/source/gldecoder.c b/source/gldecoder.c index 6e90373..22b6285 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,117 +35,61 @@ 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; + unsigned char flag; + packet_read_short(pkt, (short *)&func); + packet_read_char(pkt, (char *)&flag); + if(dec->gldBreak) + dec->gldBreak(dec->user_data, func, flag); + 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; }