From: <bo...@us...> - 2004-01-06 05:59:58
|
Update of /cvsroot/sharedaemon/core/src In directory sc8-pr-cvs1:/tmp/cvs-serv13920 Modified Files: ParseClass.cpp ParseClass.h osdep.h test.cpp Log Message: Fixed the five-week bug Index: ParseClass.cpp =================================================================== RCS file: /cvsroot/sharedaemon/core/src/ParseClass.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ParseClass.cpp 13 Dec 2003 05:06:15 -0000 1.16 +++ ParseClass.cpp 6 Jan 2004 05:59:55 -0000 1.17 @@ -201,11 +201,8 @@ size=ps->offset+ps->size+numPCs*sizeof(ParseClass*); } else { - if (IsStruct()) { - assert(!IsStruct()); - } else { - size=::type[type->type_id].len; - } + assert(!IsStruct()); + size=::type[type->type_id].len; } return; @@ -256,12 +253,12 @@ || ps->type_id==STRUCT) { assert(ps->referer_id<numPCs); if (ps->type_id==STRUCT) { - (*(PC+ps->referer_id))=new + PC[ps->referer_id]=new ParseClass(this,reinterpret_cast< struct parsestruct * >(ps->default_value)); } else { - (*(PC+ps->referer_id))=new + PC[ps->referer_id]=new ParseClass(this,ps); } assert (!constructed[ps->referer_id]); @@ -558,7 +555,8 @@ } } else { ParseClass * * PC; - u32 val; + u32 val=0; + // Initialisation of val only to get GCC to shut up unsigned j; bool scalar; @@ -670,7 +668,7 @@ "same data as just being Read in.\n" ,__FILE__,__FUNCTION__,__LINE__ ); - Write("wrondata.met"); + Write("wrongdata.met"); exit(1); } } @@ -882,8 +880,7 @@ if (!tag->id_len) { fprintf( stderr, - "%s:%s:%i: Fatal: ParseClass::" - "IncrementalWrite: Type id len = 0.\n" + "%s:%s:%i: Fatal: Type id len = 0.\n" ,__FILE__,__FUNCTION__,__LINE__ ); exit(1); @@ -922,8 +919,7 @@ default: fprintf( stderr, - "%s:%s:%i: Fatal: ParseClass::" - "IncrementalRead: Unknown tag " + "%s:%s:%i: Fatal: Unknown tag " "type %i\n" ,__FILE__,__FUNCTION__,__LINE__ ,tag->type @@ -1016,7 +1012,7 @@ p.SetData(protocol,opcode,buffsize,buffer); - delete buffer; + delete[] buffer; return true; } @@ -1033,7 +1029,7 @@ return false; } - delete buffer; + delete[] buffer; return true; } @@ -1079,7 +1075,7 @@ unlink(othername); } - delete othername; + delete[] othername; return rc; } Index: ParseClass.h =================================================================== RCS file: /cvsroot/sharedaemon/core/src/ParseClass.h,v retrieving revision 1.12 retrieving revision 1.13 diff -u -d -r1.12 -r1.13 --- ParseClass.h 12 Dec 2003 16:48:54 -0000 1.12 +++ ParseClass.h 6 Jan 2004 05:59:55 -0000 1.13 @@ -76,6 +76,12 @@ inline int GetTypeID(const tag &t ) { return TAG; } inline int GetTypeID(const bitmap &t ) { return BITMAP; } +inline u32 GetIpOf(const ipport &t) { return hton32(t.ip); } +template <class T> u32 GetIpOf(const T &t) { fprintf(stderr,"We should never reach this point (GetIpOf)!\n"); exit(2); } + +inline u16 GetPortOf(const ipport &t) { return t.port; } +template <class T> u16 GetPortOf(const T &t) { fprintf(stderr,"We should never reach this point (GetPortOf)!\n"); exit(2); } + #define ISSTRUCT(x) true #define ISARRAY(x) true @@ -337,7 +343,7 @@ } fprintf(stderr, - "%s:%s:%i: FATAL: Type doesn " + "%s:%s:%i: FATAL: Type does " "not match. %s was expected " "but %s was given\n" ,__FILE__,__FUNCTION__,__LINE__ @@ -397,7 +403,12 @@ resize=false; if (tid == ps->type_id) { - *(T*)ptr=var; + if (tid == IPPORT) { + ((u32*)ptr)[0]=GetIpOf(var); + ((u16*)ptr)[2]=GetPortOf(var); + } else { + *(T*)ptr=var; + } if (tid == DWORD || tid == WORD || tid == BYTE) { resize = true; Index: osdep.h =================================================================== RCS file: /cvsroot/sharedaemon/core/src/osdep.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- osdep.h 16 Dec 2003 22:47:21 -0000 1.15 +++ osdep.h 6 Jan 2004 05:59:55 -0000 1.16 @@ -39,6 +39,12 @@ * b = big endian */ +#define hton32 htonl +#define hton16 htons + +#define ntoh32 ntohl +#define ntoh16 ntohs + #define bswap16(x) ( \ ((((x) )&(u16)0xff)<< 8) \ |((((x)>> 8)&(u16)0xff) ) \ @@ -53,15 +59,15 @@ #define ltoh32(x) ntohl(lton32(x)) #define lton32(x) bswap32(x) -#define ltoh16(x) ntohs(lton16(x)) +#define ltoh16(x) ntoh16(lton16(x)) #define lton16(x) bswap16(x) -#define btoh32(x) ntohl(x) +#define btoh32(x) ntoh32(x) #define htol16(x) bswap16(htons(x)) #define htol32(x) bswap32(htonl(x)) #define ntol16(x) bswap16(x) #define ntol32(x) bswap32(x) -#define htob32(x) htonl(x) +#define htob32(x) hton32(x) #ifdef MACOSX #include <sys/types.h> Index: test.cpp =================================================================== RCS file: /cvsroot/sharedaemon/core/src/test.cpp,v retrieving revision 1.30 retrieving revision 1.31 diff -u -d -r1.30 -r1.31 --- test.cpp 9 Dec 2003 00:16:29 -0000 1.30 +++ test.cpp 6 Jan 2004 05:59:55 -0000 1.31 @@ -558,6 +558,7 @@ u32 nt; ServerMet->Read(server_met); + ServerMet->Get(server_met_magic,"magic"); ServerMet->Get(num_servers,"num_servers"); @@ -812,6 +813,14 @@ ipport(MY_IP,DEFAULT_SERVERPORT) ); + printf( + "Dumping packet [Using old BuildHello3Packet] (id=%lu; ip:port=%lu:%u. Protocol=0x%02x, Opcode=0x%02x, Size=0x%08x\n", + (long unsigned)id,(long unsigned)Connection::GetSocket(id).GetIP(), + (unsigned)Connection::GetSocket(id).GetPort(),p.GetProtocol(), + p.GetOpcode(),(int)p.GetSize() + ); + printf("%s:%i: \n",__FILE__,__LINE__); HexDump(p.GetPtr(),p.GetSize(),true); + ParseClass * PC=GetParseClass("HELLO"); // e301 const ipport & client=ipport(MY_IP,DEFAULT_CLIENTPORT); const ipport & server=ipport(MY_IP,DEFAULT_SERVERPORT); @@ -839,17 +848,17 @@ PC->Set(tag, "tag[2]"); PC->Set(server, "server_address"); -/* - PC->Write(p); -*/ + + PC->Write(p,0xe3,0x01); printf( - "Sending packet (id=%lu; ip:port=%lu:%u. Protocol=0x%02x, Opcode=0x%02x, Size=0x%08x\n", + "Sending packet [Using new Write method] (id=%lu; ip:port=%lu:%u. Protocol=0x%02x, Opcode=0x%02x, Size=0x%08x\n", (long unsigned)id,(long unsigned)Connection::GetSocket(id).GetIP(), (unsigned)Connection::GetSocket(id).GetPort(),p.GetProtocol(), p.GetOpcode(),(int)p.GetSize() ); printf("%s:%i: \n",__FILE__,__LINE__); HexDump(p.GetPtr(),p.GetSize(),true); + rc=Connection::GetSocket(id).EnqueuePacket(p); if (!rc) { if (get_errno()!=SOCKET_EWOULDBLOCK) { @@ -960,7 +969,7 @@ PC->Read(p); switch ((u16)p.GetProtocol()*0x100+p.GetOpcode()) { - case 0xe338: // Servermessage + case 0xe338U: // Servermessage u16 msglen,i; char * msg; @@ -977,13 +986,13 @@ delete msg; break; - case 0xe334: // Serverstatus + case 0xe334U: // Serverstatus printf("Serverstatus:\n"); // Update ServerMet // Schedule ServerMet to write back to disk break; - case 0xe340: // IDchange + case 0xe340U: // IDchange printf("IDchange:\n"); if (num_connected) { Log("Duh, we are already connected.\n"); @@ -1005,7 +1014,7 @@ connection_id[num_connected]=id; PC->Get(OurClientID[num_connected],"new_id"); char * tmp,*t; - if (OurClientID[num_connected]<0x1000000) { + if (OurClientID[num_connected]<0x1000000L) { t=strdup("LowID"); } else { t=mprintf( @@ -1032,7 +1041,7 @@ ++num_connected; break; - case 0xe341: // ServerIdent + case 0xe341U: // ServerIdent printf("ServerIdent:\n"); printf("%s:%i: \n",__FILE__,__LINE__); HexDump(p.GetPtr(),p.GetSize(),false); // Update ServerMet @@ -1114,7 +1123,7 @@ for (again=true;!(again=!again);) switch (Connection::GetStatus(id)) { case CLIENT_TCP_LISTENING: - if (nc==0xffffffff) { + if (nc==0xffffffffLU) { nc=Connection::Alloc(); } if (!(rc=ClientTcpAccept(id,nc))) { @@ -1123,7 +1132,7 @@ } rc=true; } else { - nc=0xffffffff; + nc=0xffffffffLU; } break; case CLIENT_UDP_LISTENING: |