Changeset 513

Show
Ignore:
Timestamp:
04/10/06 16:23:14 (3 years ago)
Author:
common
Message:

library
- GotekPacket::writeRaw() seems to be buggy?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/trunk/modules/service-gotek2/GotekPacket.hpp

    r512 r513  
    55#include <inttypes.h> 
    66#include <string> 
     7#include "service-gotek2.hpp" 
    78 
    89namespace library 
  • library/trunk/modules/service-gotek2/Makefile.am

    r504 r513  
    99AM_LDFLAGS = -lpcre 
    1010 
    11 pkglib_LTLIBRARIES = servicegotek.la 
     11pkglib_LTLIBRARIES = servicegotek2.la 
    1212 
    13 servicegotek_la_SOURCES = service-gotek2.cpp service-gotek2.hpp 
     13servicegotek2_la_SOURCES = service-gotek2.cpp service-gotek2.hpp 
     14servicegotek2_la_SOURCES += GotekPacket.cpp GotekPacket.hpp 
     15servicegotek2_la_SOURCES += GotekException.cpp GotekException.hpp 
    1416 
    15 servicegotek_la_LDFLAGS = -module -no-undefined -avoid-version 
     17servicegotek2_la_LDFLAGS = -module -no-undefined -avoid-version 
  • library/trunk/modules/service-gotek2/service-gotek2.cpp

    r509 r513  
    3333#include "service-gotek2.hpp" 
    3434 
     35#include "GotekPacket.hpp" 
     36#include "GotekException.hpp" 
     37 
     38#include "SQLContext.hpp" 
     39 
     40 
    3541#include "Socket.hpp" 
    3642#include "SocketManager.hpp" 
     
    5258 
    5359#include "Utilities.hpp" 
     60 
    5461 
    5562#ifdef STDTAGS  
     
    7481Library *g_Library; 
    7582 
     83 
     84 
     85char *library::mapEnum(GotekPacketType t) 
     86{ 
     87        static uint8_t  GotekPacketTypeEnumMapping; 
     88        GotekPacketTypeEnumMapping = (uint8_t) t; 
     89        return (char *)&GotekPacketTypeEnumMapping; 
     90} 
     91 
     92 
     93 
     94 
    7695/** 
    7796 * The Constructor 
     
    163182        m_ConsumeLevel = CL_ASSIGN; 
    164183 
    165     m_State             = GCS_VIRGIN; 
    166         m_ClientType    = GCT_UNKNOWN; 
     184        m_ClientType    = GCT_LOGIN; 
     185 
     186 
     187        GotekPacket *gp = GotekPacket::createWritePacket(SCMD_WELCOME); 
     188// protocol version 
     189        gp->writeUInt8(2);       
     190        gp->writeUInt8(0); 
     191 
     192// session key 
     193        m_SessionKey = (((unsigned long long) time(0)) << 48) | (((unsigned long long) (rand() & 0xFF)) << 32); 
     194        m_SessionKey |= (unsigned long long) rand(); 
     195//      gp->writeRaw(string(m_SessionKey,8)); 
     196 
     197// server version 
     198        gp->writeString(string("library going gotek 2.0")); 
     199 
     200// server description 
     201        gp->writeString(string("no description yet")); 
     202 
     203//      m_Socket->doWrite((char *)gp->buffer(), 20); 
     204 
    167205 
    168206} 
     
    212250                        break; 
    213251 
    214                 case GCT_CTRL: 
     252                case GCT_CONTROL: 
    215253                        cl=processCTRL(&needmoredata); 
    216254                        break; 
     
    235273        } 
    236274 
    237         GotekPacket gp = GotekPacket(m_Buffer); 
    238  
    239         gp.readByte(); 
    240  
    241         if (m_Buffer.size() < gp.readUnsignedInt32() - 5 ) 
     275        GotekPacket *gp = GotekPacket::createReadPacket(m_Buffer); 
     276 
     277        gp->readUInt8(); 
     278 
     279        if (m_Buffer.size() < gp->readUInt32() + 5 ) 
    242280        { 
    243281                *needmoredata = true; 
     
    250288        try 
    251289        { 
    252                 gp.readString(); 
    253                 gp.readString(); 
    254                 m_Username = gp.readString(); 
    255                 hash = pg.readRawString(64); 
    256                 command = gp.readByte(); 
     290                gp->readString(); 
     291                gp->readString(); 
     292                m_Username = gp->readString(); 
     293                hash = gp->readRaw(64); 
     294                command = gp->readUInt8(); 
    257295 
    258296        } 
    259297        catch ( GotekException e ) 
    260298        { 
     299                delete gp; 
    261300                return CL_DROP; 
    262301        } 
     302        delete gp; 
    263303 
    264304// verfiy the data is sane 
     
    286326 
    287327 
    288  
     328         return CL_ASSIGN; 
    289329} 
    290330 
     
    317357        ConsumeLevel cl = CL_ASSIGN; 
    318358 
    319         GotekPacket gp = GotekPacket(m_Buffer); 
    320  
    321         uint8_t command = gp.readByte(); 
    322  
    323         if (m_Buffer.size() < gp.readUnsignedInt32() - 5 ) 
     359        GotekPacket *gp = GotekPacket::createReadPacket(m_Buffer); 
     360 
     361        uint8_t command = gp->readUInt8(); 
     362 
     363        if (m_Buffer.size() < gp->readUInt32() + 5 ) 
    324364        { 
    325365                *needmoredata = true; 
     
    332372                { 
    333373                case CCMD_CHECK_PRESENCE: 
    334                         cl = processCTRL_CHECK_PRESENCE(&gp); 
     374                        cl = processCTRL_CHECK_PRESENCE(gp); 
    335375                        break; 
    336376 
    337377                case CCMD_STORE_MAGNET: 
    338                         cl = processCTRL_STORE_MAGNET(&gp); 
     378                        cl = processCTRL_STORE_MAGNET(gp); 
    339379                        break; 
    340380 
    341381                case CCMD_REQUEST_NOTIFICATION: 
    342                         cl = processCTRL_REQUEST_NOTIFICATION(&gp); 
     382                        cl = processCTRL_REQUEST_NOTIFICATION(gp); 
    343383                        break; 
    344384 
    345385                case CCMD_REQUEST_SILENCE: 
    346                         cl = processCTRL_REQUEST_SILENCE(&gp); 
     386                        cl = processCTRL_REQUEST_SILENCE(gp); 
    347387                        break; 
    348388 
    349389                case CCMD_REPORT_INSTANCE: 
    350                         cl = processCTRL_REPORT_INSTANCE(&gp); 
     390                        cl = processCTRL_REPORT_INSTANCE(gp); 
    351391                        break; 
    352392                } 
     
    473513        logPF(); 
    474514 
     515 
    475516        if ( m_QueryQueue.size() == 0 ) 
    476517        { 
     
    480521        } 
    481522 
     523        bool ret = false; 
     524 
    482525        switch ( m_ClientType ) 
    483526        { 
     
    486529                break; 
    487530 
    488         case GCT_CTRL: 
     531        case GCT_CONTROL: 
    489532                ret = sqlSuccessCTRL(sqlresult); 
    490533                break; 
     
    495538        } 
    496539 
     540        return ret; 
    497541} 
    498542 
     
    526570                        } 
    527571 
    528                         m_Socket->doWrite(&RPL_AUTHORIZED,1); 
     572                        m_Socket->doWrite(mapEnum(RPL_AUTHORIZED),1); 
    529573 
    530574                }else 
     
    532576                        // invalid login 
    533577                        logInfo("Login failed: %s\n",m_Username.c_str()); 
    534                         m_Socket->doWrite(&RPL_DENIED,1); 
     578                        m_Socket->doWrite(mapEnum(RPL_DENIED),1); 
    535579                        m_Socket->setStatus(SS_CLEANQUIT); 
    536580                } 
     
    540584                // invalid login 
    541585                logInfo("Login failed: %s\n",m_Username.c_str()); 
    542                 m_Socket->doWrite(&RPL_DENIED,1); 
     586                m_Socket->doWrite(mapEnum(RPL_DENIED),1); 
    543587                m_Socket->setStatus(SS_CLEANQUIT); 
    544588        } 
     
    580624        } 
    581625 
     626        bool ret = true; 
     627 
    582628        switch ( m_ClientType ) 
    583629        { 
     
    586632                break; 
    587633 
    588         case GCT_CTRL: 
     634        case GCT_CONTROL: 
    589635                ret = sqlFailureCTRL(sqlresult); 
    590636                break; 
     
    594640                break; 
    595641        } 
     642 
     643        return ret; 
    596644} 
    597645 
  • library/trunk/modules/service-gotek2/service-gotek2.hpp

    r509 r513  
    2828 /* $Id$ */ 
    2929 
     30#ifndef HAVE_SERVICE_GOTEK2_HPP 
     31#define HAVE_SERVICE_GOTEK2_HPP 
     32 
    3033#include "DialogueFactory.hpp" 
    3134#include "Module.hpp" 
     
    4144using namespace std; 
    4245 
     46 
     47 
    4348namespace library 
    4449{ 
     
    4752        class SQLResult; 
    4853        class SQLQuery; 
     54        class GotekPacket; 
    4955 
    5056        enum GotekClientType 
     
    101107        }GotekPacketType; 
    102108 
     109        char *mapEnum(GotekPacketType t);  
    103110 
    104111        class ServiceGotek2 : public Module , public DialogueFactory 
     
    149156 
    150157                bool sqlFailure(SQLResult *result); 
    151                 bool sqlSuccessLOGIN(SQLResult *result); 
     158                bool sqlFailureLOGIN(SQLResult *result); 
    152159                bool sqlFailureCTRL(SQLResult *result); 
    153160                bool sqlFailureDATA(SQLResult *result); 
     
    166173} 
    167174extern library::Library *g_Library; 
     175 
     176#endif 
     177