Skip to content
http_codec.hh 2.23 KiB
Newer Older
garciay's avatar
garciay committed
#pragma once

garciay's avatar
garciay committed
#include <memory>

garciay's avatar
garciay committed
#include "codec.hh"
garciay's avatar
garciay committed
#include "params.hh"
garciay's avatar
garciay committed

class Base_Type;
garciay's avatar
garciay committed
class Record_Type;
garciay's avatar
garciay committed
class TTCN_Typedescriptor_t;
class TTCN_Buffer;

namespace LibItsHttp__TypesAndValues {
  class HttpMessage;
  class Request;
  class Response;
  class HeaderLines;
  class HeaderLine;
}
garciay's avatar
garciay committed
namespace LibItsHttp__MessageBodyTypes {
  class HttpMessageBody;
}

struct encoding_context {
  unsigned int length;
  unsigned char is_content_length_present;

  encoding_context() { reset(); };
  void reset() { length = -1; is_content_length_present = 0x00; };
};

struct decoding_context {
  unsigned int length;
  unsigned char is_binary;

  decoding_context() { reset(); };
  void reset() { length = -1; is_binary = 0x00; };
};
garciay's avatar
garciay committed

garciay's avatar
garciay committed
class http_codec: public codec <
garciay's avatar
garciay committed
LibItsHttp__TypesAndValues::HttpMessage,
LibItsHttp__TypesAndValues::HttpMessage>
{
garciay's avatar
garciay committed
  encoding_context _ec;
  decoding_context _dc;
garciay's avatar
garciay committed
  std::map<std::string, std::unique_ptr<codec<Record_Type, Record_Type> > >  _codecs;
garciay's avatar
garciay committed
public:
garciay's avatar
garciay committed
  explicit http_codec() : codec<LibItsHttp__TypesAndValues::HttpMessage, LibItsHttp__TypesAndValues::HttpMessage>(), _ec(), _dc(), _codecs() { };
garciay's avatar
garciay committed
  virtual ~http_codec() { };
garciay's avatar
garciay committed

  virtual int encode (const LibItsHttp__TypesAndValues::HttpMessage&, OCTETSTRING& data);
garciay's avatar
garciay committed
  virtual int decode (const OCTETSTRING& data, LibItsHttp__TypesAndValues::HttpMessage&, params* params = NULL);
garciay's avatar
garciay committed

garciay's avatar
garciay committed
  void set_payload_codecs(const std::string& p_codecs);

garciay's avatar
garciay committed
private:
  int encode_request (const LibItsHttp__TypesAndValues::Request& p_request, TTCN_Buffer& p_encoding_buffer);
garciay's avatar
garciay committed
  int encode_response (const LibItsHttp__TypesAndValues::Response& p_response, TTCN_Buffer& p_encoding_buffer);
garciay's avatar
garciay committed
  int encode_body(const LibItsHttp__MessageBodyTypes::HttpMessageBody& p_message_body, OCTETSTRING& p_encoding_buffer);
garciay's avatar
garciay committed

  int decode_headers(TTCN_Buffer& decoding_buffer, LibItsHttp__TypesAndValues::HeaderLines& headers);
  int decode_header(CHARSTRING& header_line, LibItsHttp__TypesAndValues::HeaderLine& header);
garciay's avatar
garciay committed
  int decode_body(TTCN_Buffer& decoding_buffer, LibItsHttp__MessageBodyTypes::HttpMessageBody& message_body);
garciay's avatar
garciay committed
  int get_line(TTCN_Buffer& buffer, CHARSTRING& to, const bool concatenate_header_lines = false);

garciay's avatar
garciay committed
}; // End of class http_codec