Пример #1
0
void PHD2::readPHD2()
{
    QTextStream stream(tcpSocket);

    QJsonParseError qjsonError;

    while (stream.atEnd() == false)
    {
        QString rawString = stream.readLine();

        if (rawString.isEmpty())
            continue;

        QJsonDocument jdoc = QJsonDocument::fromJson(rawString.toLatin1(), &qjsonError);

        if (qjsonError.error != QJsonParseError::NoError)
        {
            emit newLog(rawString);
            emit newLog(qjsonError.errorString());
            continue;
        }

        emit newLog(rawString);

        processJSON(jdoc.object());
    }

}
Пример #2
0
boolean CmdProcessor::processWSFrame(){
  boolean fin = false;
  uint8_t opcode = 0;
  boolean mask_set = false;
  uint8_t length = 0;
  uint8_t mask[4] = {0,0,0,0};
  
  
  if(httpState == WEBSOCKET_READY && input_buffer_pos > 6){
  
    // byte 1
    fin = input_buffer[0] >> 7;
    opcode = input_buffer[0] & 0x0F;
    
    if(fin != 1 && opcode != 0x01 && opcode != 0x08){
      //It's not a websocket frame or it's not final
      return false;
    }
    
    //byte 2
    mask_set = input_buffer[1] >> 7;
    length = input_buffer[1] & 0x7F;
    
    if(input_buffer_pos >= (length + 6)){
      if(length < 125){
          //extract the mask
          if(mask_set){
            for(char i = 0; i<4; i++){
              mask[i] = input_buffer[i + 2];
            }
          }
          //process the message
          for(uint8_t i=0; i<length; i++){
            input_buffer[i] = (char)(input_buffer[i+6] ^ mask[i % 4]);
          }
          input_buffer_pos = length;
          input_buffer[input_buffer_pos] = '\0';
          if(opcode == 0x08){
            // The socket is closing, we need to send a close frame in response
            _s->write(0x88);
            _s->write(0x02);
            _s->write(0x03);
            _s->write(0xe9);
          }else{
            processJSON();
          }
          return true;
      }else{
        sendResponse("error", "Message too long", (char&)"");
        return true;
      }
    }
  }
Пример #3
0
boolean CmdProcessor::processLine(){
  //do a simple check to see if it looks like json
  if(input_buffer_pos > 0 && input_buffer[0] == '{' && input_buffer[input_buffer_pos - 1] == '}'){
    socketMode = RAW;
    processJSON();
    return true;
  }else if(processHeaders()){
    return true;
  }
  
  if(httpState == WEBSOCKET_READY){
    return false;
  }else{
    return true;
  }
}