Logo Search packages:      
Sourcecode: jabber-jit version File versions  Download package

void ICQ2000::Client::Parse (  )  [private]

non-blocking receives all waiting packets from server and parses and handles them

Definition at line 865 of file Client.cpp.

                     {
    
    // -- FLAP header --

    unsigned char start_byte, channel;
    unsigned short seq_num, data_len;

    // process FLAP(s) in packet

    if (m_recv.empty()) return;

    while (!m_recv.empty()) {
      m_recv.setPos(0);

      m_recv >> start_byte;
      if (start_byte != 42) {
      m_recv.clear();
      SignalLog(LogEvent::WARN, "Invalid Start Byte on FLAP");
      return;
      }

      /* if we don't have at least six bytes we don't have enough
       * info to determine if we have the whole of the FLAP
       */
      if (m_recv.remains() < 5) return;
      
      m_recv >> channel;
      m_recv >> seq_num; // check sequence number - todo
      
      m_recv >> data_len;
      if (m_recv.remains() < data_len) return; // waiting for more of the FLAP

      /* Copy into another Buffer which is passed
       * onto the separate parse code that way
       * multiple FLAPs in one packet are split up
       */
      Buffer sb(&m_translator);
      m_recv.chopOffBuffer( sb, data_len+6 );

      //      {
      //    ostringstream ostr;
      //    ostr << "Received packet from Server" << endl << sb;
      //    SignalLog(LogEvent::PACKET, ostr.str());
      //      }

      sb.advance(6);

      // -- FLAP body --
      
      ostringstream ostr;
      
      switch(channel) {
      case 1:
      ParseCh1(sb,seq_num);
      break;
      case 2:
      ParseCh2(sb,seq_num);
      break;
      case 3:
      ParseCh3(sb,seq_num);
      break;
      case 4:
      ParseCh4(sb,seq_num);
      break;
      default:
      ostr << "FLAP on unrecognised channel 0x" << std::hex << (int)channel;
      SignalLog(LogEvent::WARN, ostr.str());
      break;
      }

      if (sb.beforeEnd()) {
      /* we assert that parsing code eats uses all data
       * in the FLAP - seems useful to know when they aren't
       * as it probably means they are faulty
       */
      ostringstream ostr;
      ostr  << "Buffer pointer not at end after parsing FLAP was: 0x" << std::hex << sb.pos()
            << " should be: 0x" << sb.size() << " on channel 0x" << std::hex << (int)channel;
      SignalLog(LogEvent::WARN, ostr.str());
      }
      
    }

  }


Generated by  Doxygen 1.6.0   Back to index