Example #1
0
	TInt ReadAllChars(char* ch, int length)
	{
		TInt status = KErrNone;

		while(length > 0)
		{
			if(bufferTop == bufferBottom)
			{
				status = ReadIntoBuffer();
				if(status != KErrNone)
					break;
			}

			if(bufferTop - bufferBottom >= length)
			{
				memcpy(ch, buffer + bufferBottom, length);
				bufferBottom += length;
				length = 0;
			}
			else
			{
				int l = min(length, bufferTop - bufferBottom);
				memcpy(ch, buffer + bufferBottom, l);
				length -= l;
				ch += l;
				bufferBottom += l;
			}
		}

		return status;
	}
Example #2
0
	TInt ReadOneOrMore(char* ch, int length)
	{
		TInt status = KErrNone;

		if(bufferTop == bufferBottom)
		{
			status = ReadIntoBuffer();
			if(status != KErrNone)
				return status;
		}

		if(bufferTop - bufferBottom >= length)
		{
			memcpy(ch, buffer + bufferBottom, length);
			bufferBottom += length;
		}
		else
		{
			int l = min(length, bufferTop - bufferBottom);
			memcpy(ch, buffer + bufferBottom, l);
			bufferBottom += l;
		}

		return status;
	}
///////////////////////////////////////////////////////////////////////
///  Function: XosWebRtcClientConnection::
///
///    Author: $author$
///      Date: 4/1/2012
///////////////////////////////////////////////////////////////////////
void XosWebRtcClientConnection::OnRead(talk_base::AsyncSocket* socket) {
  LOG(INFO) << __FUNCTION__;
  size_t content_length = 0;
  if (ReadIntoBuffer(socket, &control_data_, &content_length)) {
    size_t peer_id = 0, eoh = 0;
    bool ok = ParseServerResponse(control_data_, content_length, &peer_id,
                                  &eoh);
    if (ok) {
      if (my_id_ == -1) {
        // First response.  Let's store our server assigned ID.
        ASSERT(state_ == SIGNING_IN);
        my_id_ = peer_id;
        ASSERT(my_id_ != -1);

        // The body of the response will be a list of already connected peers.
        if (content_length) {
          size_t pos = eoh + 4;
          while (pos < control_data_.size()) {
            size_t eol = control_data_.find('\n', pos);
            if (eol == std::string::npos)
              break;
            int id = 0;
            std::string name;
            bool connected;
            if (ParseEntry(control_data_.substr(pos, eol - pos), &name, &id,
                           &connected) && id != my_id_) {
              peers_[id] = name;
              callback_->OnPeerConnected(id, name);
            }
            pos = eol + 1;
          }
        }
        ASSERT(is_connected());
        callback_->OnSignedIn();
      } else if (state_ == SIGNING_OUT) {
        Close();
        callback_->OnDisconnected();
      } else if (state_ == SIGNING_OUT_WAITING) {
        SignOut();
      }
    }

    control_data_.clear();

    if (state_ == SIGNING_IN) {
      ASSERT(hanging_get_->GetState() == talk_base::Socket::CS_CLOSED);
      state_ = CONNECTED;
      hanging_get_->Connect(server_address_);
    }
  }
}
IFileBitStream::IFileBitStream(PacketQueue *q, mplexStreamDescriptor *desc, unsigned int buf_size) : IBitStream(desc) //MEANX
{
        queue=q;        
        SetBufSize(buf_size);
        eobs = false;
        byteidx = 0;
        
        if (!ReadIntoBuffer())
        {
                        ADM_assert(buffered);
                
        }
        
}
Example #5
0
	TInt ReadChar(char* ch)
	{
		TInt status = KErrNone;
		if(bufferTop == bufferBottom)
		{
			status = ReadIntoBuffer();
		}

		if(status == KErrNone)
		{
			*ch = buffer[bufferBottom++];
		}

		return status;
	}
///////////////////////////////////////////////////////////////////////
///  Function: XosWebRtcClientConnection::
///
///    Author: $author$
///      Date: 4/1/2012
///////////////////////////////////////////////////////////////////////
void XosWebRtcClientConnection::OnHangingGetRead(talk_base::AsyncSocket* socket) {
  LOG(INFO) << __FUNCTION__;
  size_t content_length = 0;
  if (ReadIntoBuffer(socket, &notification_data_, &content_length)) {
    size_t peer_id = 0, eoh = 0;
    bool ok = ParseServerResponse(notification_data_, content_length,
                                  &peer_id, &eoh);

    if (ok) {
      // Store the position where the body begins.
      size_t pos = eoh + 4;

      if (my_id_ == static_cast<int>(peer_id)) {
        // A notification about a new member or a member that just
        // disconnected.
        int id = 0;
        std::string name;
        bool connected = false;
        if (ParseEntry(notification_data_.substr(pos), &name, &id,
                       &connected)) {
          if (connected) {
            peers_[id] = name;
            callback_->OnPeerConnected(id, name);
          } else {
            peers_.erase(id);
            callback_->OnPeerDisconnected(id);
          }
        }
      } else {
        OnMessageFromPeer(peer_id, notification_data_.substr(pos));
      }
    }

    notification_data_.clear();
  }

  if (hanging_get_->GetState() == talk_base::Socket::CS_CLOSED &&
      state_ == CONNECTED) {
    hanging_get_->Connect(server_address_);
  }
}
Example #7
0
	TInt ReadLine(char* ch, int length)
	{
		TInt status = KErrNone;
		int state = 0;

		while(length > 0)
		{
			if(bufferTop == bufferBottom)
			{
				status = ReadIntoBuffer();
				if(status != KErrNone)
					break;
			}

			if(bufferTop - bufferBottom >= length)
			{
				char* start = buffer + bufferBottom;
				char* end = buffer + length;

				while(start != end)
				{
					char c = *start++;
					if(c == 13)
					{
						state = 1;
					}
					else if(c == 10)
					{
						if(state == 1)
						{
							state = 2;
							bufferBottom = start - buffer;
							length = 0;
							return status;
							break;
						}
						else
						{
							*ch++ = c;
						}
					}
					else
					{
						if(state == 1)
						{
							*ch++ = 13;
						}
						else
						{
							*ch++ = c;
						}
						state = 0;
					}
				}
				bufferBottom += length;
				length = 0;
			}
			else
			{
				int l = min(length, bufferTop - bufferBottom);
				char* start = buffer + bufferBottom;
				char* end = buffer + l;
				while(state != 2 && start != end)
				{
					char c = *start++;
					if(c == 13)
					{
						state = 1;
					}
					else if(c == 10)
					{
						if(state == 1)
						{
							state = 2;
							bufferBottom = start - buffer;
							length = 0;
							return status;
							break;
						}
						else
						{
							*ch++ = c;
						}
					}
					else
					{
						if(state == 1)
						{
							*ch++ = 13;
						}
						else
						{
							*ch++ = c;
						}
						state = 0;
					}
				}
				
				length -= l;
				ch += l;
				bufferBottom += l;
			}
		}
		return status;
	}
Example #8
0
bool PFSArchive::Open(std::string filename)
{
    if(!ReadIntoBuffer(filename)) {
        Close();
        return false;
    }

    PFSHeader *header = NULL;
    PFSDirectoryHeader *directory_header = NULL;
    PFSDirectory *directory = NULL;
    PFSDataBlock *data_block = NULL;
    PFSFilenameHeader *filename_header = NULL;
    PFSFilenameEntry *filename_entry = NULL;
    size_t position = 0;

    BufferRead(header, PFSHeader);

    if(header->magic[0] != 'P' ||
        header->magic[1] != 'F' ||
        header->magic[2] != 'S' ||
        header->magic[3] != ' ') 
    {
        Close();
        return false;
    }

    position = header->offset;
    BufferRead(directory_header, PFSDirectoryHeader);

    std::vector<uint32_t> offsets(directory_header->count, 0);
    _filenames.resize(directory_header->count);
    _files.resize(directory_header->count);

    size_t i = 0;
    size_t j = 0;
    size_t running = 0;
    size_t temp_position = 0;
    size_t inflate = 0;
    char temp_buffer[32768];
    char temp_buffer2[32768];
    char temp_string[MAX_FILENAME_SIZE];
    for(; i < directory_header->count; ++i) {
        BufferRead(directory, PFSDirectory);
        if(directory->crc == ntohl(0xC90A5861)) {
            temp_position = position;
            position = directory->offset;
            memset(temp_buffer, 0, directory->size);
            inflate = 0;
            
            while(inflate < directory->size) {
                BufferRead(data_block, PFSDataBlock);
                BufferReadLength(temp_buffer2, data_block->deflate_length);
                decompress(temp_buffer2, data_block->deflate_length, temp_buffer + inflate, data_block->inflate_length);
				inflate += data_block->inflate_length;
            }

            position = temp_position;
            filename_header = (PFSFilenameHeader*)&temp_buffer[0];
            temp_position = sizeof(PFSFilenameHeader);
            
            for(j = 0; j < filename_header->filename_count; ++j)
			{
				filename_entry = (PFSFilenameEntry*)&temp_buffer[temp_position];
                if(filename_entry->filename_length + 1 >= MAX_FILENAME_SIZE) {
                    Close();
                    return false;
                }
				temp_string[filename_entry->filename_length] = 0;
				memcpy(temp_string, &temp_buffer[temp_position + sizeof(PFSFilenameEntry)], filename_entry->filename_length);
                _filenames[j] = temp_string;
				temp_position += sizeof(PFSFilenameEntry) + filename_entry->filename_length;
			}
        } else {
            _files[running] = position - 12;
			offsets[running] = directory->offset;
			++running;
        }
    }

    uint32_t temp = 0;
    for(i = directory_header->count - 2; i > 0; i--) {
        for(j = 0; j < i; j++) {
            if(offsets[j] > offsets[j + 1]) {
                temp = offsets[j];
				offsets[j] = offsets[j + 1];
				offsets[j + 1] = temp;
				temp = _files[j];
				_files[j] = _files[j + 1];
				_files[j + 1] = temp;
            }
        }
    }

    return true;
}