Ejemplo n.º 1
0
void i2c::write( const buffer_t& data )
{
    setAddress();
    if( ::write(mDevice, data.data(), data.size()) < 0 )
    {
        ostringstream os;
        os << "unable to write: " << strerror( errno );
        throw runtime_error{ move( os.str() ) };
    }
}
Ejemplo n.º 2
0
 static void append(std::vector<buffer_t>& buffers, buffer_t const& arg)
 {
   append_size(buffers, '$', arg.size());
   if (arg.size() > RESP_LARGE_BUFFER_SIZE)
   {
     buffers.push_back(arg);
     buffers.push_back("\r\n");
   }
   else
   {
     buffer_t& buffer = buffers.back();
     buffer.append(arg);
     buffer.append("\r\n");
   }
 }
Ejemplo n.º 3
0
void SidTuneBase::loadFile(const char* fileName, buffer_t& bufferRef)
{
    std::ifstream inFile(fileName, std::ifstream::binary);

    if (!inFile.is_open())
    {
        throw loadError(ERR_CANT_OPEN_FILE);
    }

    inFile.seekg(0, inFile.end);
    const size_t fileLen = (size_t)inFile.tellg();

    if (fileLen == 0)
    {
        throw loadError(ERR_EMPTY);
    }

    inFile.seekg(0, inFile.beg);

    buffer_t fileBuf;
    fileBuf.reserve(fileLen);

    fileBuf.assign(std::istreambuf_iterator<char>(inFile), std::istreambuf_iterator<char>());

    if (inFile.bad())
    {
        throw loadError(ERR_CANT_LOAD_FILE);
    }

    inFile.close();

    bufferRef.swap(fileBuf);
}
bool
CLabelManagerLanguageMonitor::ReadStatus(buffer_t& Status)
{
    time_t t = time(NULL);
    fprintf(stderr, "DEBUG: CLabelManagerLanguageMonitor::ReadStatus() %s\n", ctime(&t));

    bool Result = false;
    Status.clear();

    buffer_t RequestStatusCommand = CLabelManagerDriver::GetRequestStatusCommand();
    Environment_.WriteData(RequestStatusCommand);

    Environment_.ReadData(Status);

    if (Status.size() > 0)
    {
        Result = true;
    }

    fprintf(stderr, "DEBUG: ReadStatus() returned %i %i\n", (int)Status.size(), (int)Result);
    return Result;
}
Ejemplo n.º 5
0
buffer_t
hmac::make(
    hash_t type, const buffer_t& key, const unsigned char* src, size_t length) {
    auto digest = digest_pair(type);

    mbedcrypto_c_call(
        mbedtls_md_hmac,
        std::get<0>(digest),
        to_const_ptr(key),
        key.size(),
        src,
        length,
        to_ptr(std::get<1>(digest)));

    return std::get<1>(digest);
}
Ejemplo n.º 6
0
void
hmac::start(const buffer_t& key) {
    mbedcrypto_c_call(
        mbedtls_md_hmac_starts, &pimpl->ctx_, to_const_ptr(key), key.size());
}
Ejemplo n.º 7
0
 uint8_t* end() const { return buffer.get() + length(); }
Ejemplo n.º 8
0
 uint8_t* pos() const { return buffer.get() + offset; }
Ejemplo n.º 9
0
 uint8_t* begin() const { return buffer.get(); }
Ejemplo n.º 10
0
 virtual size_t read(buffer_t& buffer, size_t len) {
     auto l = buffer_.read(buffer.data(), len);
     if(buffer_.size() < buffer_update*frame_size_) fill_buffer();
     return l;
 }
Ejemplo n.º 11
0
bool buffer_t::operator!=( const buffer_t& other) const
{
    return ( bounds() != other.bounds()) || ( pixels_ != other.pixels_);
}
Ejemplo n.º 12
0
bool buffer_t::operator==( const buffer_t& other) const
{
    return ( bounds() == other.bounds()) && ( pixels_ == other.pixels_);
}
Ejemplo n.º 13
0
void SidTuneBase::acceptSidTune(const char* dataFileName, const char* infoFileName,
                            buffer_t& buf, bool isSlashedFileName)
{
    // Make a copy of the data file name and path, if available.
    if (dataFileName != nullptr)
    {
        const size_t fileNamePos = isSlashedFileName ?
            SidTuneTools::slashedFileNameWithoutPath(dataFileName) :
            SidTuneTools::fileNameWithoutPath(dataFileName);
        info->m_path = std::string(dataFileName, fileNamePos);
        info->m_dataFileName = std::string(dataFileName + fileNamePos);
    }

    // Make a copy of the info file name, if available.
    if (infoFileName != nullptr)
    {
        const size_t fileNamePos = isSlashedFileName ?
            SidTuneTools::slashedFileNameWithoutPath(infoFileName) :
            SidTuneTools::fileNameWithoutPath(infoFileName);
        info->m_infoFileName = std::string(infoFileName + fileNamePos);
    }

    // Fix bad sidtune set up.
    if (info->m_songs > MAX_SONGS)
    {
        info->m_songs = MAX_SONGS;
    }
    else if (info->m_songs == 0)
    {
        info->m_songs = 1;
    }

    if (info->m_startSong == 0
        || info->m_startSong > info->m_songs)
    {
        info->m_startSong = 1;
    }

    info->m_dataFileLen = buf.size();
    info->m_c64dataLen = buf.size() - fileOffset;

    // Calculate any remaining addresses and then
    // confirm all the file details are correct
    resolveAddrs(&buf[fileOffset]);

    if (checkRelocInfo() == false)
    {
        throw loadError(ERR_BAD_RELOC);
    }
    if (checkCompatibility() == false)
    {
         throw loadError(ERR_BAD_ADDR);
    }

    if (info->m_dataFileLen >= 2)
    {
        // We only detect an offset of two. Some position independent
        // sidtunes contain a load address of 0xE000, but are loaded
        // to 0x0FFE and call player at 0x1000.
        info->m_fixLoad = (endian_little16(&buf[fileOffset])==(info->m_loadAddr+2));
    }

    // Check the size of the data.
    if (info->m_c64dataLen > MAX_MEMORY)
    {
        throw loadError(ERR_DATA_TOO_LONG);
    }
    else if (info->m_c64dataLen == 0)
    {
        throw loadError(ERR_EMPTY);
    }

    cache.swap(buf);
}
void
MockPrintEnvironment::ReadData(buffer_t& Data)
{
  Data.clear();
}
void
CLabelManagerLanguageMonitor::ProcessData(const buffer_t& Data)
{
    PageData_.insert(PageData_.end(), Data.begin(), Data.end());
}
Ejemplo n.º 16
0
		void write(const_pointer buf, std::uint32_t len, std::uint32_t pos)
		{
			buffer_.write(buf, len, pos);
		}
Ejemplo n.º 17
0
		void read(pointer buf, std::uint32_t len, std::uint32_t pos)
		{
			buffer_.read(buf, len, pos);
		}
Ejemplo n.º 18
0
		const_pointer buffer() const
		{
			return buffer_.buffer();
		}
Ejemplo n.º 19
0
		pointer buffer()
		{
			return buffer_.buffer();
		}
void
MockPrintEnvironment::WriteData(const buffer_t& Data)
{
  Data_.insert(Data_.end(), Data.begin(), Data.end());
}
  void Client_connection::recv_response(buffer_t buf)
  {
    if (buf->empty()) {
      end_response({Error::NO_REPLY});
      return;
    }

    const std::string data{(char*) buf->data(), buf->size()};

    // restart timer since we got data
    if(timer_.is_running())
      timer_.restart(timeout_dur_);

    // create response if not exist
    if(res_ == nullptr)
    {
      try {
        res_ = make_response(data); // this also parses
      }
      catch(...)
      {
        end_response({Error::INVALID});
        return;
      }
    }
    // if there already is a response
    else
    {
      // this is the case when Status line is received, but not yet headers.
      if(not res_->headers_complete() && req_->method() != HEAD)
      {
        *res_ << data;
        res_->parse();
      }
      // here we assume all headers has already been received (could not be true?)
      else
      {
        // add chunks of body data
        res_->add_chunk(data);
      }
    }

    const auto& header = res_->header();
    // TODO: Temporary, not good enough
    // if(res_->is_complete())
    // Assume we want some headers
    if(!header.is_empty())
    {
      if(header.has_field(header::Content_Length))
      {
        try
        {
          const unsigned conlen = std::stoul(std::string(header.value(header::Content_Length)));
          const unsigned body_size = res_->body().size();
          //printf("<http::Connection> [%s] Data: %u ConLen: %u Body:%u\n",
          //  req_->uri().to_string().to_string().c_str(), data.size(), conlen, body_size);
          // risk buffering forever if no timeout
          if(body_size == conlen)
          {
            end_response();
          }
          else if(body_size > conlen)
          {
            end_response({Error::INVALID});
          }
        }
        catch(...)
        { end_response({Error::INVALID}); }
      }
      else
        end_response();
    }
    else if(req_->method() == HEAD)
    {
      end_response();
    }
  }
Ejemplo n.º 22
0
 /*
   Add a request to the back of the queue.
   If the queue was empty/finished, point current to the new request.
 */
 void push_back(buffer_t wr) {
   debug2("<WriteQueue> Inserted WR: size=%u, current=%u, size=%u\n",
     (uint32_t) wr->size(), current_, (uint32_t) size());
   q.push_back(std::move(wr));
 }
Ejemplo n.º 23
0
 ostream(buffer_t &buf) : buf(buf), offset(buf.size()) {}