提交 a675da25 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Replace stupid MSX_BYTES macros with uintX_t.

上级 5c3b2180
......@@ -23,7 +23,7 @@ namespace Channel
};
private:
static MS_BYTE writeBuffer[];
static uint8_t writeBuffer[];
public:
UnixStreamSocket(int fd);
......
......@@ -73,7 +73,7 @@ namespace RTC
// DTLS has completed negotiation of a secure connection (including DTLS-SRTP
// and remote fingerprint verification). Outgoing media can now flow through.
// NOTE: The caller MUST NOT call any method during this callback.
virtual void onDTLSConnected(DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, MS_BYTE* srtp_local_key, size_t srtp_local_key_len, MS_BYTE* srtp_remote_key, size_t srtp_remote_key_len) = 0;
virtual void onDTLSConnected(DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len) = 0;
// The DTLS connection has been closed as the result of an error (such as a
// DTLS alert or a failure to validate the remote fingerprint).
// NOTE: The caller MUST NOT call Close() during this callback.
......@@ -83,10 +83,10 @@ namespace RTC
virtual void onDTLSClosed(DTLSTransport* dtlsTransport) = 0;
// Need to send DTLS data to the peer.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual void onOutgoingDTLSData(DTLSTransport* dtlsTransport, const MS_BYTE* data, size_t len) = 0;
virtual void onOutgoingDTLSData(DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
// DTLS application data received.
// NOTE: The caller MUST NOT call Close() during this callback.
virtual void onDTLSApplicationData(DTLSTransport* dtlsTransport, const MS_BYTE* data, size_t len) = 0;
virtual void onDTLSApplicationData(DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) = 0;
};
public:
......@@ -95,7 +95,7 @@ namespace RTC
static Json::Value& GetLocalFingerprints();
static Role StringToRole(std::string role);
static FingerprintAlgorithm GetFingerprintAlgorithm(std::string fingerprint);
static bool IsDTLS(const MS_BYTE* data, size_t len);
static bool IsDTLS(const uint8_t* data, size_t len);
private:
static void GenerateCertificateAndPrivateKey();
......@@ -107,7 +107,7 @@ namespace RTC
static X509* certificate;
static EVP_PKEY* privateKey;
static SSL_CTX* sslCtx;
static MS_BYTE sslReadBuffer[];
static uint8_t sslReadBuffer[];
static std::map<std::string, Role> string2Role;
static std::map<std::string, FingerprintAlgorithm> string2FingerprintAlgorithm;
static Json::Value localFingerprints;
......@@ -121,10 +121,10 @@ namespace RTC
void Dump();
void Run(Role localRole);
void SetRemoteFingerprint(Fingerprint fingerprint);
void ProcessDTLSData(const MS_BYTE* data, size_t len);
void ProcessDTLSData(const uint8_t* data, size_t len);
DtlsState GetState();
Role GetLocalRole();
void SendApplicationData(const MS_BYTE* data, size_t len);
void SendApplicationData(const uint8_t* data, size_t len);
private:
bool IsRunning();
......@@ -192,7 +192,7 @@ namespace RTC
}
inline
bool DTLSTransport::IsDTLS(const MS_BYTE* data, size_t len)
bool DTLSTransport::IsDTLS(const uint8_t* data, size_t len)
{
return (
// Minimum DTLS record length is 13 bytes.
......
......@@ -42,7 +42,7 @@ namespace RTC
uint32_t priority;
std::string ip;
Protocol protocol;
MS_PORT port;
uint16_t port;
CandidateType type;
TcpCandidateType tcpType;
};
......
......@@ -12,40 +12,40 @@ namespace RTC
struct CommonHeader
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE count:5;
MS_BYTE padding:1;
MS_BYTE version:2;
uint8_t count:5;
uint8_t padding:1;
uint8_t version:2;
#elif defined(MS_BIG_ENDIAN)
MS_BYTE version:2;
MS_BYTE padding:1;
MS_BYTE count:5;
uint8_t version:2;
uint8_t padding:1;
uint8_t count:5;
#endif
MS_BYTE packet_type:8;
MS_2BYTES length:16;
uint8_t packet_type:8;
uint16_t length:16;
};
public:
static bool IsRTCP(const MS_BYTE* data, size_t len);
static RTCPPacket* Parse(const MS_BYTE* data, size_t len);
static bool IsRTCP(const uint8_t* data, size_t len);
static RTCPPacket* Parse(const uint8_t* data, size_t len);
public:
RTCPPacket(CommonHeader* header, const MS_BYTE* raw, size_t length);
RTCPPacket(CommonHeader* header, const uint8_t* raw, size_t length);
~RTCPPacket();
const MS_BYTE* GetRaw();
const uint8_t* GetRaw();
size_t GetLength();
private:
// Passed by argument.
CommonHeader* header = nullptr;
MS_BYTE* raw = nullptr;
uint8_t* raw = nullptr;
size_t length = 0;
};
/* Inline static methods. */
inline
bool RTCPPacket::IsRTCP(const MS_BYTE* data, size_t len)
bool RTCPPacket::IsRTCP(const uint8_t* data, size_t len)
{
CommonHeader* header = (CommonHeader*)data;
......@@ -65,7 +65,7 @@ namespace RTC
/* Inline instance methods. */
inline
const MS_BYTE* RTCPPacket::GetRaw()
const uint8_t* RTCPPacket::GetRaw()
{
return this->raw;
}
......
......@@ -12,68 +12,68 @@ namespace RTC
struct Header
{
#if defined(MS_LITTLE_ENDIAN)
MS_BYTE csrc_count:4;
MS_BYTE extension:1;
MS_BYTE padding:1;
MS_BYTE version:2;
MS_BYTE payload_type:7;
MS_BYTE marker:1;
uint8_t csrc_count:4;
uint8_t extension:1;
uint8_t padding:1;
uint8_t version:2;
uint8_t payload_type:7;
uint8_t marker:1;
#elif defined(MS_BIG_ENDIAN)
MS_BYTE version:2;
MS_BYTE padding:1;
MS_BYTE extension:1;
MS_BYTE csrc_count:4;
MS_BYTE marker:1;
MS_BYTE payload_type:7;
uint8_t version:2;
uint8_t padding:1;
uint8_t extension:1;
uint8_t csrc_count:4;
uint8_t marker:1;
uint8_t payload_type:7;
#endif
MS_2BYTES sequence_number;
MS_4BYTES timestamp;
MS_4BYTES ssrc;
uint16_t sequence_number;
uint32_t timestamp;
uint32_t ssrc;
};
/* Struct for RTP header extension. */
struct ExtensionHeader
{
MS_2BYTES id;
MS_2BYTES length; // Size of value in multiples of 4 bytes.
MS_BYTE* value;
uint16_t id;
uint16_t length; // Size of value in multiples of 4 bytes.
uint8_t* value;
};
public:
static bool IsRTP(const MS_BYTE* data, size_t len);
static RTPPacket* Parse(const MS_BYTE* data, size_t len);
static bool IsRTP(const uint8_t* data, size_t len);
static RTPPacket* Parse(const uint8_t* data, size_t len);
public:
RTPPacket(Header* header, ExtensionHeader* extensionHeader, const MS_BYTE* payload, size_t payloadLen, MS_BYTE payloadPadding, const MS_BYTE* raw, size_t length);
RTPPacket(Header* header, ExtensionHeader* extensionHeader, const uint8_t* payload, size_t payloadLen, uint8_t payloadPadding, const uint8_t* raw, size_t length);
~RTPPacket();
void Dump();
const MS_BYTE* GetRaw();
const uint8_t* GetRaw();
size_t GetLength();
MS_BYTE GetPayloadType();
void SetPayloadType(MS_BYTE payload_type);
uint8_t GetPayloadType();
void SetPayloadType(uint8_t payload_type);
bool HasMarker();
void SetMarker(bool marker);
MS_2BYTES GetSequenceNumber();
MS_4BYTES GetTimestamp();
MS_4BYTES GetSSRC();
void SetSSRC(MS_4BYTES ssrc);
uint16_t GetSequenceNumber();
uint32_t GetTimestamp();
uint32_t GetSSRC();
void SetSSRC(uint32_t ssrc);
bool HasExtensionHeader();
MS_2BYTES GetExtensionHeaderId();
uint16_t GetExtensionHeaderId();
size_t GetExtensionHeaderLength();
MS_BYTE* GetPayload();
uint8_t* GetPayload();
size_t GetPayloadLength();
void Serialize();
private:
// Passed by argument.
Header* header = nullptr;
MS_BYTE* csrcList = nullptr;
uint8_t* csrcList = nullptr;
ExtensionHeader* extensionHeader = nullptr;
MS_BYTE* payload = nullptr;
uint8_t* payload = nullptr;
size_t payloadLength = 0;
MS_BYTE payloadPadding = 0;
MS_BYTE* raw = nullptr; // Allocated when Serialize().
uint8_t payloadPadding = 0;
uint8_t* raw = nullptr; // Allocated when Serialize().
size_t length = 0;
// Others.
bool isSerialized = false;
......@@ -82,7 +82,7 @@ namespace RTC
/* Inline static methods. */
inline
bool RTPPacket::IsRTP(const MS_BYTE* data, size_t len)
bool RTPPacket::IsRTP(const uint8_t* data, size_t len)
{
// NOTE: RTCPPacket::IsRTCP() must always be called before this method.
......@@ -100,7 +100,7 @@ namespace RTC
/* Inline instance methods. */
inline
const MS_BYTE* RTPPacket::GetRaw()
const uint8_t* RTPPacket::GetRaw()
{
return this->raw;
}
......@@ -112,13 +112,13 @@ namespace RTC
}
inline
MS_BYTE RTPPacket::GetPayloadType()
uint8_t RTPPacket::GetPayloadType()
{
return this->header->payload_type;
}
inline
void RTPPacket::SetPayloadType(MS_BYTE payload_type)
void RTPPacket::SetPayloadType(uint8_t payload_type)
{
this->header->payload_type = payload_type;
}
......@@ -136,26 +136,26 @@ namespace RTC
}
inline
MS_2BYTES RTPPacket::GetSequenceNumber()
uint16_t RTPPacket::GetSequenceNumber()
{
return ntohs(this->header->sequence_number);
}
inline
MS_4BYTES RTPPacket::GetTimestamp()
uint32_t RTPPacket::GetTimestamp()
{
return ntohl(this->header->timestamp);
}
inline
MS_4BYTES RTPPacket::GetSSRC()
uint32_t RTPPacket::GetSSRC()
{
return ntohl(this->header->ssrc);
}
// TODO temp
inline
void RTPPacket::SetSSRC(MS_4BYTES ssrc)
void RTPPacket::SetSSRC(uint32_t ssrc)
{
this->header->ssrc = htonl(ssrc);
}
......@@ -167,10 +167,10 @@ namespace RTC
}
inline
MS_2BYTES RTPPacket::GetExtensionHeaderId()
uint16_t RTPPacket::GetExtensionHeaderId()
{
if (this->extensionHeader)
return MS_2BYTES(ntohs(this->extensionHeader->id));
return uint16_t(ntohs(this->extensionHeader->id));
else
return 0;
}
......@@ -185,7 +185,7 @@ namespace RTC
}
inline
MS_BYTE* RTPPacket::GetPayload()
uint8_t* RTPPacket::GetPayload()
{
return this->payload;
}
......
......@@ -63,12 +63,20 @@ namespace RTC
void RtpReceiver::SetRtpListener(RtpListener* rtpListener)
{
this->rtpListener = rtpListener;
// If we already had rtpParameters then provide the new listener with them.
if (this->rtpParameters)
this->rtpListener->onRtpListenerParameters(this, this->rtpParameters);
}
inline
void RtpReceiver::SetRtpListenerForRtcp(RtpListener* rtcpListener)
{
this->rtcpListener = rtcpListener;
// If we already had rtpParameters then provide the new listener with them.
if (this->rtpParameters)
this->rtcpListener->onRtpListenerParameters(this, this->rtpParameters);
}
inline
......
......@@ -31,16 +31,16 @@ namespace RTC
static void onSRTPEvent(srtp_event_data_t* data);
private:
static MS_BYTE encryptBuffer[];
static uint8_t encryptBuffer[];
public:
SRTPSession(Type type, SRTPProfile profile, MS_BYTE* key, size_t key_len);
SRTPSession(Type type, SRTPProfile profile, uint8_t* key, size_t key_len);
~SRTPSession();
bool EncryptRTP(const MS_BYTE** data, size_t* len);
bool DecryptSRTP(const MS_BYTE* data, size_t* len);
bool EncryptRTCP(const MS_BYTE** data, size_t* len);
bool DecryptSRTCP(const MS_BYTE* data, size_t* len);
bool EncryptRTP(const uint8_t** data, size_t* len);
bool DecryptSRTP(const uint8_t* data, size_t* len);
bool EncryptRTCP(const uint8_t** data, size_t* len);
bool DecryptSRTCP(const uint8_t* data, size_t* len);
const char* GetLastErrorDesc();
void Close();
......
......@@ -10,7 +10,7 @@ namespace RTC
{
public:
// STUN message class.
enum class Class : MS_2BYTES
enum class Class : uint16_t
{
Request = 0,
Indication = 1,
......@@ -19,13 +19,13 @@ namespace RTC
};
// STUN message method.
enum class Method : MS_2BYTES
enum class Method : uint16_t
{
Binding = 1
};
// Attribute type.
enum class Attribute : MS_2BYTES
enum class Attribute : uint16_t
{
MappedAddress = 0x0001,
Username = 0x0006,
......@@ -53,42 +53,42 @@ namespace RTC
};
public:
static bool IsSTUN(const MS_BYTE* data, size_t len);
static STUNMessage* Parse(const MS_BYTE* data, size_t len);
static bool IsSTUN(const uint8_t* data, size_t len);
static STUNMessage* Parse(const uint8_t* data, size_t len);
private:
static const MS_BYTE magicCookie[];
static const uint8_t magicCookie[];
public:
STUNMessage(Class klass, Method method, const MS_BYTE* transactionId, const MS_BYTE* raw, size_t length);
STUNMessage(Class klass, Method method, const uint8_t* transactionId, const uint8_t* raw, size_t length);
~STUNMessage();
void Dump();
Class GetClass();
Method GetMethod();
const MS_BYTE* GetRaw();
const uint8_t* GetRaw();
void SetLength(size_t length);
size_t GetLength();
void SetUsername(const char* username, size_t len);
void SetPriority(const MS_4BYTES priority);
void SetIceControlling(const MS_8BYTES iceControlling);
void SetIceControlled(const MS_8BYTES iceControlled);
void SetPriority(const uint32_t priority);
void SetIceControlling(const uint64_t iceControlling);
void SetIceControlled(const uint64_t iceControlled);
void SetUseCandidate();
void SetXorMappedAddress(const struct sockaddr* xorMappedAddress);
void SetErrorCode(MS_2BYTES errorCode);
void SetMessageIntegrity(const MS_BYTE* messageIntegrity);
void SetErrorCode(uint16_t errorCode);
void SetMessageIntegrity(const uint8_t* messageIntegrity);
void SetFingerprint();
const std::string& GetUsername();
const MS_4BYTES GetPriority();
const MS_8BYTES GetIceControlling();
const MS_8BYTES GetIceControlled();
const uint32_t GetPriority();
const uint64_t GetIceControlling();
const uint64_t GetIceControlled();
bool HasUseCandidate();
MS_2BYTES GetErrorCode();
uint16_t GetErrorCode();
bool HasMessageIntegrity();
bool HasFingerprint();
Authentication CheckAuthentication(const std::string &local_username, const std::string &local_password);
STUNMessage* CreateSuccessResponse();
STUNMessage* CreateErrorResponse(MS_2BYTES errorCode);
STUNMessage* CreateErrorResponse(uint16_t errorCode);
void Authenticate(const std::string &password);
void Serialize();
......@@ -96,28 +96,28 @@ namespace RTC
// Passed by argument.
Class klass; // 2 bytes.
Method method; // 2 bytes.
const MS_BYTE* transactionId = nullptr; // 12 bytes.
MS_BYTE* raw = nullptr; // Allocated when Serialize().
const uint8_t* transactionId = nullptr; // 12 bytes.
uint8_t* raw = nullptr; // Allocated when Serialize().
size_t length = 0; // The full message size (including header).
// Others.
bool isSerialized = false;
// STUN attributes.
std::string username; // Less than 513 bytes.
MS_4BYTES priority = 0; // 4 bytes unsigned integer.
MS_8BYTES iceControlling = 0; // 8 bytes unsigned integer.
MS_8BYTES iceControlled = 0; // 8 bytes unsigned integer.
uint32_t priority = 0; // 4 bytes unsigned integer.
uint64_t iceControlling = 0; // 8 bytes unsigned integer.
uint64_t iceControlled = 0; // 8 bytes unsigned integer.
bool hasUseCandidate = false; // 0 bytes.
const MS_BYTE* messageIntegrity = nullptr; // 20 bytes.
const uint8_t* messageIntegrity = nullptr; // 20 bytes.
bool hasFingerprint = false; // 4 bytes.
const struct sockaddr* xorMappedAddress = nullptr; // 8 or 20 bytes.
MS_2BYTES errorCode = 0; // 4 bytes (no reason phrase).
uint16_t errorCode = 0; // 4 bytes (no reason phrase).
std::string password;
};
/* Inline methods. */
inline
bool STUNMessage::IsSTUN(const MS_BYTE* data, size_t len)
bool STUNMessage::IsSTUN(const uint8_t* data, size_t len)
{
return (
// STUN headers are 20 bytes.
......@@ -145,7 +145,7 @@ namespace RTC
}
inline
const MS_BYTE* STUNMessage::GetRaw()
const uint8_t* STUNMessage::GetRaw()
{
return this->raw;
}
......@@ -170,21 +170,21 @@ namespace RTC
}
inline
void STUNMessage::SetPriority(const MS_4BYTES priority)
void STUNMessage::SetPriority(const uint32_t priority)
{
if (!this->priority)
this->priority = priority;
}
inline
void STUNMessage::SetIceControlling(const MS_8BYTES iceControlling)
void STUNMessage::SetIceControlling(const uint64_t iceControlling)
{
if (!this->iceControlling)
this->iceControlling = iceControlling;
}
inline
void STUNMessage::SetIceControlled(const MS_8BYTES iceControlled)
void STUNMessage::SetIceControlled(const uint64_t iceControlled)
{
if (!this->iceControlled)
this->iceControlled = iceControlled;
......@@ -204,13 +204,13 @@ namespace RTC
}
inline
void STUNMessage::SetErrorCode(MS_2BYTES errorCode)
void STUNMessage::SetErrorCode(uint16_t errorCode)
{
this->errorCode = errorCode;
}
inline
void STUNMessage::SetMessageIntegrity(const MS_BYTE* messageIntegrity)
void STUNMessage::SetMessageIntegrity(const uint8_t* messageIntegrity)
{
if (!this->messageIntegrity)
this->messageIntegrity = messageIntegrity;
......@@ -229,19 +229,19 @@ namespace RTC
}
inline
const MS_4BYTES STUNMessage::GetPriority()
const uint32_t STUNMessage::GetPriority()
{
return this->priority;
}
inline
const MS_8BYTES STUNMessage::GetIceControlling()
const uint64_t STUNMessage::GetIceControlling()
{
return this->iceControlling;
}
inline
const MS_8BYTES STUNMessage::GetIceControlled()
const uint64_t STUNMessage::GetIceControlled()
{
return this->iceControlled;
}
......@@ -253,7 +253,7 @@ namespace RTC
}
inline
MS_2BYTES STUNMessage::GetErrorCode()
uint16_t STUNMessage::GetErrorCode()
{
return this->errorCode;
}
......
......@@ -13,14 +13,14 @@ namespace RTC
class Listener
{
public:
virtual void onPacketRecv(RTC::TCPConnection *connection, const MS_BYTE* data, size_t len) = 0;
virtual void onPacketRecv(RTC::TCPConnection *connection, const uint8_t* data, size_t len) = 0;
};
public:
TCPConnection(Listener* listener, size_t bufferSize);
virtual ~TCPConnection();
void Send(const MS_BYTE* data, size_t len);
void Send(const uint8_t* data, size_t len);
/* Pure virtual methods inherited from ::TCPConnection. */
public:
......
......@@ -31,10 +31,10 @@ namespace RTC
private:
static struct sockaddr_storage sockaddrStorageIPv4;
static struct sockaddr_storage sockaddrStorageIPv6;
static MS_PORT minPort;
static MS_PORT maxPort;
static std::unordered_map<MS_PORT, bool> availableIPv4Ports;
static std::unordered_map<MS_PORT, bool> availableIPv6Ports;
static uint16_t minPort;
static uint16_t maxPort;
static std::unordered_map<uint16_t, bool> availableIPv4Ports;
static std::unordered_map<uint16_t, bool> availableIPv6Ports;
public:
TCPServer(Listener* listener, RTC::TCPConnection::Listener* connListener, uv_tcp_t* uvHandle);
......
......@@ -43,7 +43,7 @@ namespace RTC
// - Table of SSRC / RtpReceiver pairs.
std::unordered_map<uint32_t, RTC::RtpReceiver*> ssrcTable;
// - Table of MID RTP header extension / RtpReceiver pairs.
// std::unordered_map<MS_2BYTES, RTC::RtpReceiver*> midTable;
// std::unordered_map<uint16_t, RTC::RtpReceiver*> midTable;
// - Table of RTP payload type / RtpReceiver pairs.
std::unordered_map<uint8_t, RTC::RtpReceiver*> ptTable;
};
......@@ -65,15 +65,15 @@ namespace RTC
/* Private methods to unify UDP and TCP behavior. */
private:
void onPacketRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len);
void onSTUNDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len);
void onDTLSDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len);
void onRTPDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len);
void onRTCPDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len);
void onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
void onSTUNDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
void onDTLSDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
void onRTPDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
void onRTCPDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len);
/* Pure virtual methods inherited from RTC::UDPSocket::Listener. */
public:
virtual void onPacketRecv(RTC::UDPSocket *socket, const MS_BYTE* data, size_t len, const struct sockaddr* remote_addr) override;
virtual void onPacketRecv(RTC::UDPSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr) override;
/* Pure virtual methods inherited from RTC::TCPServer::Listener. */
public:
......@@ -81,7 +81,7 @@ namespace RTC
/* Pure virtual methods inherited from RTC::TCPConnection::Listener. */
public:
virtual void onPacketRecv(RTC::TCPConnection *connection, const MS_BYTE* data, size_t len) override;
virtual void onPacketRecv(RTC::TCPConnection *connection, const uint8_t* data, size_t len) override;
/* Pure virtual methods inherited from RTC::ICEServer::Listener. */
public:
......@@ -94,11 +94,11 @@ namespace RTC
/* Pure virtual methods inherited from RTC::DTLSTransport::Listener. */
public:
virtual void onDTLSConnecting(DTLSTransport* dtlsTransport) override;
virtual void onDTLSConnected(DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, MS_BYTE* srtp_local_key, size_t srtp_local_key_len, MS_BYTE* srtp_remote_key, size_t srtp_remote_key_len) override;
virtual void onDTLSConnected(DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len) override;
virtual void onDTLSFailed(DTLSTransport* dtlsTransport) override;
virtual void onDTLSClosed(DTLSTransport* dtlsTransport) override;
virtual void onOutgoingDTLSData(RTC::DTLSTransport* dtlsTransport, const MS_BYTE* data, size_t len) override;
virtual void onDTLSApplicationData(RTC::DTLSTransport* dtlsTransport, const MS_BYTE* data, size_t len) override;
virtual void onOutgoingDTLSData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) override;
virtual void onDTLSApplicationData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len) override;
/* Pure virtual methods inherited from RTC::RtpReceiver::RtpListener. */
virtual void onRtpListenerParameters(RTC::RtpReceiver* rtpReceiver, RTC::RtpParameters* rtpParameters) override;
......
......@@ -27,7 +27,7 @@ namespace RTC
void Dump();
void StoreUdpRemoteAddress();
bool Compare(TransportTuple* tuple);
void Send(const MS_BYTE* data, size_t len);
void Send(const uint8_t* data, size_t len);
Protocol GetProtocol();
const struct sockaddr* GetLocalAddress();
const struct sockaddr* GetRemoteAddress();
......@@ -97,7 +97,7 @@ namespace RTC
}
inline
void TransportTuple::Send(const MS_BYTE* data, size_t len)
void TransportTuple::Send(const uint8_t* data, size_t len)
{
if (this->protocol == Protocol::UDP)
this->udpSocket->Send(data, len, this->udpRemoteAddr);
......
......@@ -15,7 +15,7 @@ namespace RTC
class Listener
{
public:
virtual void onPacketRecv(RTC::UDPSocket *socket, const MS_BYTE* data, size_t len, const struct sockaddr* remote_addr) = 0;
virtual void onPacketRecv(RTC::UDPSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr) = 0;
};
public:
......@@ -29,17 +29,17 @@ namespace RTC
private:
static struct sockaddr_storage sockaddrStorageIPv4;
static struct sockaddr_storage sockaddrStorageIPv6;
static MS_PORT minPort;
static MS_PORT maxPort;
static std::unordered_map<MS_PORT, bool> availableIPv4Ports;
static std::unordered_map<MS_PORT, bool> availableIPv6Ports;
static uint16_t minPort;
static uint16_t maxPort;
static std::unordered_map<uint16_t, bool> availableIPv4Ports;
static std::unordered_map<uint16_t, bool> availableIPv6Ports;
public:
UDPSocket(Listener* listener, uv_udp_t* uvHandle);
/* Pure virtual methods inherited from ::UDPSocket. */
public:
virtual void userOnUDPDatagramRecv(const MS_BYTE* data, size_t len, const struct sockaddr* addr) override;
virtual void userOnUDPDatagramRecv(const uint8_t* data, size_t len, const struct sockaddr* addr) override;
virtual void userOnUDPSocketClosed() override;
private:
......
......@@ -16,8 +16,8 @@ public:
uint8_t logLevel { MS_LOG_LEVEL_DEBUG };
std::string rtcListenIPv4;
std::string rtcListenIPv6;
MS_PORT rtcMinPort { 10000 };
MS_PORT rtcMaxPort { 59999 };
uint16_t rtcMinPort { 10000 };
uint16_t rtcMaxPort { 59999 };
std::string dtlsCertificateFile;
std::string dtlsPrivateKeyFile;
// Private fields.
......
......@@ -13,7 +13,7 @@ namespace Utils
public:
static int GetFamily(const char *ip, size_t ip_len);
static int GetFamily(const std::string &ip);
static void GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, MS_PORT* port);
static void GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, uint16_t* port);
static bool CompareAddresses(const struct sockaddr* addr1, const struct sockaddr* addr2);
static struct sockaddr_storage CopyAddress(const struct sockaddr* addr);
};
......@@ -85,97 +85,97 @@ namespace Utils
/**
* All these functions get and set bytes in Network Byte Order (Big Endian).
*/
static MS_BYTE Get1Byte(const MS_BYTE* data, size_t i);
static MS_2BYTES Get2Bytes(const MS_BYTE* data, size_t i);
static MS_4BYTES Get3Bytes(const MS_BYTE* data, size_t i);
static MS_4BYTES Get4Bytes(const MS_BYTE* data, size_t i);
static MS_8BYTES Get8Bytes(const MS_BYTE* data, size_t i);
static void Set1Byte(MS_BYTE* data, size_t i, MS_BYTE value);
static void Set2Bytes(MS_BYTE* data, size_t i, MS_2BYTES value);
static void Set3Bytes(MS_BYTE* data, size_t i, MS_4BYTES value);
static void Set4Bytes(MS_BYTE* data, size_t i, MS_4BYTES value);
static void Set8Bytes(MS_BYTE* data, size_t i, MS_8BYTES value);
static MS_2BYTES PadTo4Bytes(MS_2BYTES size);
static MS_4BYTES PadTo4Bytes(MS_4BYTES size);
static uint8_t Get1Byte(const uint8_t* data, size_t i);
static uint16_t Get2Bytes(const uint8_t* data, size_t i);
static uint32_t Get3Bytes(const uint8_t* data, size_t i);
static uint32_t Get4Bytes(const uint8_t* data, size_t i);
static uint64_t Get8Bytes(const uint8_t* data, size_t i);
static void Set1Byte(uint8_t* data, size_t i, uint8_t value);
static void Set2Bytes(uint8_t* data, size_t i, uint16_t value);
static void Set3Bytes(uint8_t* data, size_t i, uint32_t value);
static void Set4Bytes(uint8_t* data, size_t i, uint32_t value);
static void Set8Bytes(uint8_t* data, size_t i, uint64_t value);
static uint16_t PadTo4Bytes(uint16_t size);
static uint32_t PadTo4Bytes(uint32_t size);
};
/* Inline static methods. */
inline
MS_BYTE Byte::Get1Byte(const MS_BYTE* data, size_t i)
uint8_t Byte::Get1Byte(const uint8_t* data, size_t i)
{
return data[i];
}
inline
MS_2BYTES Byte::Get2Bytes(const MS_BYTE* data, size_t i)
uint16_t Byte::Get2Bytes(const uint8_t* data, size_t i)
{
return (MS_2BYTES)(data[i+1]) | ((MS_2BYTES)(data[i]))<<8;
return (uint16_t)(data[i+1]) | ((uint16_t)(data[i]))<<8;
}
inline
MS_4BYTES Byte::Get3Bytes(const MS_BYTE* data, size_t i)
uint32_t Byte::Get3Bytes(const uint8_t* data, size_t i)
{
return (MS_4BYTES)(data[i+2]) | ((MS_4BYTES)(data[i+1]))<<8 | ((MS_4BYTES)(data[i]))<<16;
return (uint32_t)(data[i+2]) | ((uint32_t)(data[i+1]))<<8 | ((uint32_t)(data[i]))<<16;
}
inline
MS_4BYTES Byte::Get4Bytes(const MS_BYTE* data, size_t i)
uint32_t Byte::Get4Bytes(const uint8_t* data, size_t i)
{
return (MS_4BYTES)(data[i+3]) | ((MS_4BYTES)(data[i+2]))<<8 | ((MS_4BYTES)(data[i+1]))<<16 | ((MS_4BYTES)(data[i]))<<24;
return (uint32_t)(data[i+3]) | ((uint32_t)(data[i+2]))<<8 | ((uint32_t)(data[i+1]))<<16 | ((uint32_t)(data[i]))<<24;
}
inline
MS_8BYTES Byte::Get8Bytes(const MS_BYTE* data, size_t i)
uint64_t Byte::Get8Bytes(const uint8_t* data, size_t i)
{
return ((MS_8BYTES)Byte::Get4Bytes(data,i))<<32 | Byte::Get4Bytes(data,i+4);
return ((uint64_t)Byte::Get4Bytes(data,i))<<32 | Byte::Get4Bytes(data,i+4);
}
inline
void Byte::Set1Byte(MS_BYTE* data, size_t i, MS_BYTE value)
void Byte::Set1Byte(uint8_t* data, size_t i, uint8_t value)
{
data[i] = value;
}
inline
void Byte::Set2Bytes(MS_BYTE* data, size_t i, MS_2BYTES value)
void Byte::Set2Bytes(uint8_t* data, size_t i, uint16_t value)
{
data[i+1] = (MS_BYTE)(value);
data[i] = (MS_BYTE)(value>>8);
data[i+1] = (uint8_t)(value);
data[i] = (uint8_t)(value>>8);
}
inline
void Byte::Set3Bytes(MS_BYTE* data, size_t i, MS_4BYTES value)
void Byte::Set3Bytes(uint8_t* data, size_t i, uint32_t value)
{
data[i+2] = (MS_BYTE)(value);
data[i+1] = (MS_BYTE)(value>>8);
data[i] = (MS_BYTE)(value>>16);
data[i+2] = (uint8_t)(value);
data[i+1] = (uint8_t)(value>>8);
data[i] = (uint8_t)(value>>16);
}
inline
void Byte::Set4Bytes(MS_BYTE* data, size_t i, MS_4BYTES value)
void Byte::Set4Bytes(uint8_t* data, size_t i, uint32_t value)
{
data[i+3] = (MS_BYTE)(value);
data[i+2] = (MS_BYTE)(value>>8);
data[i+1] = (MS_BYTE)(value>>16);
data[i] = (MS_BYTE)(value>>24);
data[i+3] = (uint8_t)(value);
data[i+2] = (uint8_t)(value>>8);
data[i+1] = (uint8_t)(value>>16);
data[i] = (uint8_t)(value>>24);
}
inline
void Byte::Set8Bytes(MS_BYTE* data, size_t i, MS_8BYTES value)
void Byte::Set8Bytes(uint8_t* data, size_t i, uint64_t value)
{
data[i+7] = (MS_BYTE)(value);
data[i+6] = (MS_BYTE)(value>>8);
data[i+5] = (MS_BYTE)(value>>16);
data[i+4] = (MS_BYTE)(value>>24);
data[i+3] = (MS_BYTE)(value>>32);
data[i+2] = (MS_BYTE)(value>>40);
data[i+1] = (MS_BYTE)(value>>48);
data[i] = (MS_BYTE)(value>>56);
data[i+7] = (uint8_t)(value);
data[i+6] = (uint8_t)(value>>8);
data[i+5] = (uint8_t)(value>>16);
data[i+4] = (uint8_t)(value>>24);
data[i+3] = (uint8_t)(value>>32);
data[i+2] = (uint8_t)(value>>40);
data[i+1] = (uint8_t)(value>>48);
data[i] = (uint8_t)(value>>56);
}
inline
MS_2BYTES Byte::PadTo4Bytes(MS_2BYTES size)
uint16_t Byte::PadTo4Bytes(uint16_t size)
{
// If size is not multiple of 32 bits then pad it.
if (size & 0x03)
......@@ -185,7 +185,7 @@ namespace Utils
}
inline
MS_4BYTES Byte::PadTo4Bytes(MS_4BYTES size)
uint32_t Byte::PadTo4Bytes(uint32_t size)
{
// If size is not multiple of 32 bits then pad it.
if (size & 0x03)
......@@ -201,14 +201,14 @@ namespace Utils
static void ClassDestroy();
static uint32_t GetRandomUInt(uint32_t min, uint32_t max);
static const std::string GetRandomString(size_t len);
static MS_4BYTES GetCRC32(const MS_BYTE* data, size_t size);
static const MS_BYTE* GetHMAC_SHA1(const std::string &key, const MS_BYTE* data, size_t len);
static uint32_t GetCRC32(const uint8_t* data, size_t size);
static const uint8_t* GetHMAC_SHA1(const std::string &key, const uint8_t* data, size_t len);
private:
static uint32_t seed;
static HMAC_CTX hmacSha1Ctx;
static MS_BYTE hmacSha1Buffer[];
static const MS_4BYTES crc32Table[256];
static uint8_t hmacSha1Buffer[];
static const uint32_t crc32Table[256];
};
/* Inline static methods. */
......@@ -247,10 +247,10 @@ namespace Utils
}
inline
MS_4BYTES Crypto::GetCRC32(const MS_BYTE* data, size_t size)
uint32_t Crypto::GetCRC32(const uint8_t* data, size_t size)
{
MS_4BYTES crc = 0xFFFFFFFF;
const MS_BYTE* p = data;
uint32_t crc = 0xFFFFFFFF;
const uint8_t* p = data;
while (size--)
crc = Crypto::crc32Table[(crc ^ *p++) & 0xFF] ^ (crc >> 8);
......
......@@ -15,12 +15,6 @@
#define MS_LOG_LEVEL_WARN 1
#define MS_LOG_LEVEL_ERROR 0
#define MS_BYTE uint8_t
#define MS_2BYTES uint16_t
#define MS_4BYTES uint32_t
#define MS_8BYTES uint64_t
#define MS_PORT uint16_t
// Detect Little-Endian or Big-Endian CPU.
// NOTE: If the macro MS_LITTLE_ENDIAN or MS_BIG_ENDIAN is already defined
// then don't autodetect it.
......
......@@ -20,7 +20,7 @@ public:
{
TCPConnection* connection;
uv_write_t req;
MS_BYTE store[1];
uint8_t store[1];
};
public:
......@@ -29,19 +29,19 @@ public:
void Close();
virtual void Dump();
void Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, MS_PORT localPort);
void Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, uint16_t localPort);
bool IsClosing();
uv_tcp_t* GetUvHandle();
void Start();
void Write(const MS_BYTE* data, size_t len);
void Write(const MS_BYTE* data1, size_t len1, const MS_BYTE* data2, size_t len2);
void Write(const uint8_t* data, size_t len);
void Write(const uint8_t* data1, size_t len1, const uint8_t* data2, size_t len2);
void Write(const std::string &data);
const struct sockaddr* GetLocalAddress();
const std::string& GetLocalIP();
MS_PORT GetLocalPort();
uint16_t GetLocalPort();
const struct sockaddr* GetPeerAddress();
const std::string& GetPeerIP();
MS_PORT GetPeerPort();
uint16_t GetPeerPort();
private:
bool SetPeerAddress();
......@@ -73,14 +73,14 @@ protected:
// Passed by argument.
size_t bufferSize = 0;
// Allocated by this.
MS_BYTE* buffer = nullptr;
uint8_t* buffer = nullptr;
// Others.
size_t bufferDataLen = 0;
std::string localIP;
MS_PORT localPort = 0;
uint16_t localPort = 0;
struct sockaddr_storage peerAddr;
std::string peerIP;
MS_PORT peerPort = 0;
uint16_t peerPort = 0;
};
/* Inline methods. */
......@@ -100,7 +100,7 @@ uv_tcp_t* TCPConnection::GetUvHandle()
inline
void TCPConnection::Write(const std::string &data)
{
Write((const MS_BYTE*)data.c_str(), data.size());
Write((const uint8_t*)data.c_str(), data.size());
}
inline
......@@ -116,7 +116,7 @@ const std::string& TCPConnection::GetLocalIP()
}
inline
MS_PORT TCPConnection::GetLocalPort()
uint16_t TCPConnection::GetLocalPort()
{
return this->localPort;
}
......@@ -134,7 +134,7 @@ const std::string& TCPConnection::GetPeerIP()
}
inline
MS_PORT TCPConnection::GetPeerPort()
uint16_t TCPConnection::GetPeerPort()
{
return this->peerPort;
}
......
......@@ -10,7 +10,7 @@
class TCPServer : public TCPConnection::Listener
{
public:
TCPServer(const std::string &ip, MS_PORT port, int backlog);
TCPServer(const std::string &ip, uint16_t port, int backlog);
/**
* uvHandle must be an already initialized and binded uv_tcp_t pointer.
*/
......@@ -22,7 +22,7 @@ public:
bool IsClosing();
const struct sockaddr* GetLocalAddress();
const std::string& GetLocalIP();
MS_PORT GetLocalPort();
uint16_t GetLocalPort();
size_t GetNumConnections();
private:
......@@ -54,7 +54,7 @@ private:
protected:
struct sockaddr_storage localAddr;
std::string localIP;
MS_PORT localPort = 0;
uint16_t localPort = 0;
};
/* Inline methods. */
......
......@@ -17,7 +17,7 @@ public:
Timer(Listener* listener);
void Close();
void Start(MS_8BYTES timeout);
void Start(uint64_t timeout);
void Stop();
/* Callbacks fired by UV events. */
......
......@@ -13,14 +13,14 @@ public:
{
UDPSocket* socket;
uv_udp_send_t req;
MS_BYTE store[1];
uint8_t store[1];
};
private:
static MS_BYTE readBuffer[];
static uint8_t readBuffer[];
public:
UDPSocket(const std::string &ip, MS_PORT port);
UDPSocket(const std::string &ip, uint16_t port);
/**
* uvHandle must be an already initialized and binded uv_udp_t pointer.
*/
......@@ -29,13 +29,13 @@ public:
void Close();
virtual void Dump();
void Send(const MS_BYTE* data, size_t len, const struct sockaddr* addr);
void Send(const uint8_t* data, size_t len, const struct sockaddr* addr);
void Send(const std::string &data, const struct sockaddr* addr);
void Send(const MS_BYTE* data, size_t len, const std::string &ip, MS_PORT port);
void Send(const std::string &data, const std::string &ip, MS_PORT port);
void Send(const uint8_t* data, size_t len, const std::string &ip, uint16_t port);
void Send(const std::string &data, const std::string &ip, uint16_t port);
const struct sockaddr* GetLocalAddress();
const std::string& GetLocalIP();
MS_PORT GetLocalPort();
uint16_t GetLocalPort();
private:
bool SetLocalAddress();
......@@ -49,7 +49,7 @@ public:
/* Pure virtual methods that must be implemented by the subclass. */
protected:
virtual void userOnUDPDatagramRecv(const MS_BYTE* data, size_t len, const struct sockaddr* addr) = 0;
virtual void userOnUDPDatagramRecv(const uint8_t* data, size_t len, const struct sockaddr* addr) = 0;
virtual void userOnUDPSocketClosed() = 0;
private:
......@@ -61,7 +61,7 @@ private:
protected:
struct sockaddr_storage localAddr;
std::string localIP;
MS_PORT localPort = 0;
uint16_t localPort = 0;
};
/* Inline methods. */
......@@ -69,13 +69,13 @@ protected:
inline
void UDPSocket::Send(const std::string &data, const struct sockaddr* addr)
{
Send((const MS_BYTE*)data.c_str(), data.size(), addr);
Send((const uint8_t*)data.c_str(), data.size(), addr);
}
inline
void UDPSocket::Send(const std::string &data, const std::string &ip, MS_PORT port)
void UDPSocket::Send(const std::string &data, const std::string &ip, uint16_t port)
{
Send((const MS_BYTE*)data.c_str(), data.size(), ip, port);
Send((const uint8_t*)data.c_str(), data.size(), ip, port);
}
inline
......@@ -91,7 +91,7 @@ const std::string& UDPSocket::GetLocalIP()
}
inline
MS_PORT UDPSocket::GetLocalPort()
uint16_t UDPSocket::GetLocalPort()
{
return this->localPort;
}
......
......@@ -13,7 +13,7 @@ public:
{
UnixStreamSocket* socket;
uv_write_t req;
MS_BYTE store[1];
uint8_t store[1];
};
public:
......@@ -22,7 +22,7 @@ public:
void Close();
bool IsClosing();
void Write(const MS_BYTE* data, size_t len);
void Write(const uint8_t* data, size_t len);
void Write(const std::string &data);
/* Callbacks fired by UV events. */
......@@ -50,7 +50,7 @@ protected:
// Passed by argument.
size_t bufferSize = 0;
// Allocated by this.
MS_BYTE* buffer = nullptr;
uint8_t* buffer = nullptr;
// Others.
size_t bufferDataLen = 0;
};
......@@ -66,7 +66,7 @@ bool UnixStreamSocket::IsClosing()
inline
void UnixStreamSocket::Write(const std::string &data)
{
Write((const MS_BYTE*)data.c_str(), data.size());
Write((const uint8_t*)data.c_str(), data.size());
}
#endif
......@@ -17,7 +17,7 @@ namespace Channel
{
/* Class variables. */
MS_BYTE UnixStreamSocket::writeBuffer[NS_MAX_SIZE];
uint8_t UnixStreamSocket::writeBuffer[NS_MAX_SIZE];
/* Instance methods. */
......@@ -232,7 +232,7 @@ namespace Channel
// If here it means that json_start points to the beginning of a JSON string
// with json_len bytes length, so recalculate read_len.
read_len = (const MS_BYTE*)json_start - (this->buffer + this->msgStart) + json_len + 1;
read_len = (const uint8_t*)json_start - (this->buffer + this->msgStart) + json_len + 1;
Json::Value json;
std::string json_parse_error;
......
......@@ -62,7 +62,7 @@ namespace RTC
X509* DTLSTransport::certificate = nullptr;
EVP_PKEY* DTLSTransport::privateKey = nullptr;
SSL_CTX* DTLSTransport::sslCtx = nullptr;
MS_BYTE DTLSTransport::sslReadBuffer[MS_SSL_READ_BUFFER_SIZE];
uint8_t DTLSTransport::sslReadBuffer[MS_SSL_READ_BUFFER_SIZE];
std::map<std::string, DTLSTransport::FingerprintAlgorithm> DTLSTransport::string2FingerprintAlgorithm =
{
{ "sha-1", DTLSTransport::FingerprintAlgorithm::SHA1 },
......@@ -636,7 +636,7 @@ namespace RTC
}
}
void DTLSTransport::ProcessDTLSData(const MS_BYTE* data, size_t len)
void DTLSTransport::ProcessDTLSData(const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -681,11 +681,11 @@ namespace RTC
}
// Notify the listener.
this->listener->onDTLSApplicationData(this, (MS_BYTE*)DTLSTransport::sslReadBuffer, (size_t)read);
this->listener->onDTLSApplicationData(this, (uint8_t*)DTLSTransport::sslReadBuffer, (size_t)read);
}
}
void DTLSTransport::SendApplicationData(const MS_BYTE* data, size_t len)
void DTLSTransport::SendApplicationData(const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -853,7 +853,7 @@ namespace RTC
MS_DEBUG("%ld bytes of DTLS data ready to sent to the peer", read);
// Notify the listener.
this->listener->onOutgoingDTLSData(this, (MS_BYTE*)data, (size_t)read);
this->listener->onOutgoingDTLSData(this, (uint8_t*)data, (size_t)read);
// Clear the BIO buffer.
// NOTE: the (void) avoids the -Wunused-value warning.
......@@ -867,7 +867,7 @@ namespace RTC
long int ret;
struct timeval dtls_timeout;
MS_8BYTES timeout_ms;
uint64_t timeout_ms;
// NOTE: If ret == 0 then ignore the value in dtls_timeout.
// NOTE: No DTLSv_1_2_get_timeout() or DTLS_get_timeout() in OpenSSL 1.1.0-dev.
......@@ -875,7 +875,7 @@ namespace RTC
if (ret == 0)
return true;
timeout_ms = (dtls_timeout.tv_sec * (MS_8BYTES)1000) + (dtls_timeout.tv_usec / 1000);
timeout_ms = (dtls_timeout.tv_sec * (uint64_t)1000) + (dtls_timeout.tv_usec / 1000);
if (timeout_ms == 0)
{
return true;
......@@ -1030,13 +1030,13 @@ namespace RTC
{
MS_TRACE();
MS_BYTE srtp_material[MS_SRTP_MASTER_LENGTH * 2];
MS_BYTE* srtp_local_key;
MS_BYTE* srtp_local_salt;
MS_BYTE* srtp_remote_key;
MS_BYTE* srtp_remote_salt;
MS_BYTE srtp_local_master_key[MS_SRTP_MASTER_LENGTH];
MS_BYTE srtp_remote_master_key[MS_SRTP_MASTER_LENGTH];
uint8_t srtp_material[MS_SRTP_MASTER_LENGTH * 2];
uint8_t* srtp_local_key;
uint8_t* srtp_local_salt;
uint8_t* srtp_remote_key;
uint8_t* srtp_remote_salt;
uint8_t srtp_local_master_key[MS_SRTP_MASTER_LENGTH];
uint8_t srtp_remote_master_key[MS_SRTP_MASTER_LENGTH];
int ret;
ret = SSL_export_keying_material(this->ssl, srtp_material, MS_SRTP_MASTER_LENGTH * 2, "EXTRACTOR-dtls_srtp", 19, nullptr, 0, 0);
......
......@@ -7,7 +7,7 @@ namespace RTC
{
/* Class methods. */
RTCPPacket* RTCPPacket::Parse(const MS_BYTE* data, size_t len)
RTCPPacket* RTCPPacket::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -24,9 +24,9 @@ namespace RTC
/* Instance methods. */
RTCPPacket::RTCPPacket(CommonHeader* header, const MS_BYTE* raw, size_t length) :
RTCPPacket::RTCPPacket(CommonHeader* header, const uint8_t* raw, size_t length) :
header(header),
raw((MS_BYTE*)raw),
raw((uint8_t*)raw),
length(length)
{
MS_TRACE();
......
......@@ -9,7 +9,7 @@ namespace RTC
{
/* Class methods. */
RTPPacket* RTPPacket::Parse(const MS_BYTE* data, size_t len)
RTPPacket* RTPPacket::Parse(const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -70,9 +70,9 @@ namespace RTC
}
// Get payload.
MS_BYTE* payload = (MS_BYTE*)data + pos;
uint8_t* payload = (uint8_t*)data + pos;
size_t payloadLength = len - pos;
MS_BYTE payloadPadding = 0;
uint8_t payloadPadding = 0;
MS_ASSERT(len >= pos, "payload has negative size");
......@@ -114,19 +114,19 @@ namespace RTC
/* Instance methods. */
RTPPacket::RTPPacket(Header* header, ExtensionHeader* extensionHeader, const MS_BYTE* payload, size_t payloadLength, MS_BYTE payloadPadding, const MS_BYTE* raw, size_t length) :
RTPPacket::RTPPacket(Header* header, ExtensionHeader* extensionHeader, const uint8_t* payload, size_t payloadLength, uint8_t payloadPadding, const uint8_t* raw, size_t length) :
header(header),
extensionHeader(extensionHeader),
payload((MS_BYTE*)payload),
payload((uint8_t*)payload),
payloadLength(payloadLength),
payloadPadding(payloadPadding),
raw((MS_BYTE*)raw),
raw((uint8_t*)raw),
length(length)
{
MS_TRACE();
if (this->header->csrc_count)
this->csrcList = (MS_BYTE*)raw + sizeof(Header);
this->csrcList = (uint8_t*)raw + sizeof(Header);
}
RTPPacket::~RTPPacket()
......@@ -192,7 +192,7 @@ namespace RTC
this->length += (size_t)this->payloadPadding;
// Allocate it.
this->raw = new MS_BYTE[this->length];
this->raw = new uint8_t[this->length];
// Add minimun header.
std::memcpy(this->raw, this->header, sizeof(Header));
......
......@@ -12,7 +12,7 @@ namespace RTC
{
/* Class variables. */
MS_BYTE SRTPSession::encryptBuffer[MS_ENCRYPT_BUFFER_SIZE];
uint8_t SRTPSession::encryptBuffer[MS_ENCRYPT_BUFFER_SIZE];
/* Class methods. */
......@@ -57,7 +57,7 @@ namespace RTC
/* Instance methods. */
SRTPSession::SRTPSession(Type type, SRTPProfile profile, MS_BYTE* key, size_t key_len)
SRTPSession::SRTPSession(Type type, SRTPProfile profile, uint8_t* key, size_t key_len)
{
MS_TRACE();
......@@ -126,7 +126,7 @@ namespace RTC
// TODO: It must not memcpy it but instead the provided packet must already be
// allocated into a buffer.
bool SRTPSession::EncryptRTP(const MS_BYTE** data, size_t* len)
bool SRTPSession::EncryptRTP(const uint8_t** data, size_t* len)
{
MS_TRACE();
......@@ -148,12 +148,12 @@ namespace RTC
}
// Update the given data pointer.
*data = (const MS_BYTE*)SRTPSession::encryptBuffer;
*data = (const uint8_t*)SRTPSession::encryptBuffer;
return true;
}
bool SRTPSession::DecryptSRTP(const MS_BYTE* data, size_t* len)
bool SRTPSession::DecryptSRTP(const uint8_t* data, size_t* len)
{
MS_TRACE();
......@@ -167,7 +167,7 @@ namespace RTC
return true;
}
bool SRTPSession::EncryptRTCP(const MS_BYTE** data, size_t* len)
bool SRTPSession::EncryptRTCP(const uint8_t** data, size_t* len)
{
MS_TRACE();
......@@ -189,12 +189,12 @@ namespace RTC
}
// Update the given data pointer.
*data = (const MS_BYTE*)SRTPSession::encryptBuffer;
*data = (const uint8_t*)SRTPSession::encryptBuffer;
return true;
}
bool SRTPSession::DecryptSRTCP(const MS_BYTE* data, size_t* len)
bool SRTPSession::DecryptSRTCP(const uint8_t* data, size_t* len)
{
MS_TRACE();
......
......@@ -63,7 +63,7 @@ namespace RTC
// We have packet_len bytes.
if (data_len >= 2 && data_len >= 2 + packet_len)
{
const MS_BYTE* packet = this->buffer + this->frameStart + 2;
const uint8_t* packet = this->buffer + this->frameStart + 2;
// Notify the listener.
if (packet_len != 0)
......@@ -139,13 +139,13 @@ namespace RTC
}
}
void TCPConnection::Send(const MS_BYTE* data, size_t len)
void TCPConnection::Send(const uint8_t* data, size_t len)
{
MS_TRACE();
// Write according to Framing RFC 4571.
MS_BYTE frame_len[2];
uint8_t frame_len[2];
Utils::Byte::Set2Bytes(frame_len, 0, len);
......
......@@ -27,10 +27,10 @@ namespace RTC
struct sockaddr_storage TCPServer::sockaddrStorageIPv4;
struct sockaddr_storage TCPServer::sockaddrStorageIPv6;
MS_PORT TCPServer::minPort;
MS_PORT TCPServer::maxPort;
std::unordered_map<MS_PORT, bool> TCPServer::availableIPv4Ports;
std::unordered_map<MS_PORT, bool> TCPServer::availableIPv6Ports;
uint16_t TCPServer::minPort;
uint16_t TCPServer::maxPort;
std::unordered_map<uint16_t, bool> TCPServer::availableIPv4Ports;
std::unordered_map<uint16_t, bool> TCPServer::availableIPv6Ports;
/* Class methods. */
......@@ -57,7 +57,7 @@ namespace RTC
TCPServer::minPort = Settings::configuration.rtcMinPort;
TCPServer::maxPort = Settings::configuration.rtcMaxPort;
MS_PORT i = RTC::TCPServer::minPort;
uint16_t i = RTC::TCPServer::minPort;
do
{
RTC::TCPServer::availableIPv4Ports[i] = true;
......@@ -106,13 +106,13 @@ namespace RTC
struct sockaddr_storage first_bind_addr;
struct sockaddr_storage second_bind_addr;
const char* listenIP;
MS_PORT random_first_port;
MS_PORT iterate_first_port;
MS_PORT iterate_second_port;
uint16_t random_first_port;
uint16_t iterate_first_port;
uint16_t iterate_second_port;
uint16_t attempt = 0;
uint16_t bindAttempt = 0;
int flags = 0;
std::unordered_map<MS_PORT, bool>* available_ports;
std::unordered_map<uint16_t, bool>* available_ports;
switch (address_family)
{
......@@ -138,7 +138,7 @@ namespace RTC
}
// Choose a random first port to start from.
random_first_port = (MS_PORT)Utils::Crypto::GetRandomUInt((uint32_t)RTC::TCPServer::minPort, (uint32_t)RTC::TCPServer::maxPort);
random_first_port = (uint16_t)Utils::Crypto::GetRandomUInt((uint32_t)RTC::TCPServer::minPort, (uint32_t)RTC::TCPServer::maxPort);
// Make it even if pair is requested.
if (pair)
random_first_port &= ~1;
......
......@@ -637,7 +637,7 @@ namespace RTC
}
inline
void Transport::onPacketRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len)
void Transport::onPacketRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -669,7 +669,7 @@ namespace RTC
}
inline
void Transport::onSTUNDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len)
void Transport::onSTUNDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -688,7 +688,7 @@ namespace RTC
}
inline
void Transport::onDTLSDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len)
void Transport::onDTLSDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -719,7 +719,7 @@ namespace RTC
}
inline
void Transport::onRTPDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len)
void Transport::onRTPDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -748,7 +748,7 @@ namespace RTC
}
inline
void Transport::onRTCPDataRecv(RTC::TransportTuple* tuple, const MS_BYTE* data, size_t len)
void Transport::onRTCPDataRecv(RTC::TransportTuple* tuple, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -766,7 +766,7 @@ namespace RTC
MS_DEBUG("received RTCP data");
}
void Transport::onPacketRecv(RTC::UDPSocket *socket, const MS_BYTE* data, size_t len, const struct sockaddr* remote_addr)
void Transport::onPacketRecv(RTC::UDPSocket *socket, const uint8_t* data, size_t len, const struct sockaddr* remote_addr)
{
MS_TRACE();
......@@ -785,7 +785,7 @@ namespace RTC
this->iceServer->RemoveTuple(&tuple);
}
void Transport::onPacketRecv(RTC::TCPConnection *connection, const MS_BYTE* data, size_t len)
void Transport::onPacketRecv(RTC::TCPConnection *connection, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -901,7 +901,7 @@ namespace RTC
this->notifier->Emit(this->transportId, "dtlsstatechange", eventData);
}
void Transport::onDTLSConnected(RTC::DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, MS_BYTE* srtp_local_key, size_t srtp_local_key_len, MS_BYTE* srtp_remote_key, size_t srtp_remote_key_len)
void Transport::onDTLSConnected(RTC::DTLSTransport* dtlsTransport, RTC::SRTPSession::SRTPProfile srtp_profile, uint8_t* srtp_local_key, size_t srtp_local_key_len, uint8_t* srtp_remote_key, size_t srtp_remote_key_len)
{
MS_TRACE();
......@@ -959,7 +959,7 @@ namespace RTC
Close();
}
void Transport::onOutgoingDTLSData(RTC::DTLSTransport* dtlsTransport, const MS_BYTE* data, size_t len)
void Transport::onOutgoingDTLSData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -976,7 +976,7 @@ namespace RTC
this->selectedTuple->Send(data, len);
}
void Transport::onDTLSApplicationData(RTC::DTLSTransport* dtlsTransport, const MS_BYTE* data, size_t len)
void Transport::onDTLSApplicationData(RTC::DTLSTransport* dtlsTransport, const uint8_t* data, size_t len)
{
MS_TRACE();
......
......@@ -26,7 +26,7 @@ namespace RTC
Json::Value json_remote;
int ip_family;
std::string ip;
MS_PORT port;
uint16_t port;
Utils::IP::GetAddressInfo(this->GetLocalAddress(), &ip_family, ip, &port);
json_local[k_ip] = ip;
......@@ -64,7 +64,7 @@ namespace RTC
{
int remote_family;
std::string remote_ip;
MS_PORT remote_port;
uint16_t remote_port;
Utils::IP::GetAddressInfo(GetRemoteAddress(), &remote_family, remote_ip, &remote_port);
......
......@@ -24,10 +24,10 @@ namespace RTC
struct sockaddr_storage UDPSocket::sockaddrStorageIPv4;
struct sockaddr_storage UDPSocket::sockaddrStorageIPv6;
MS_PORT UDPSocket::minPort;
MS_PORT UDPSocket::maxPort;
std::unordered_map<MS_PORT, bool> UDPSocket::availableIPv4Ports;
std::unordered_map<MS_PORT, bool> UDPSocket::availableIPv6Ports;
uint16_t UDPSocket::minPort;
uint16_t UDPSocket::maxPort;
std::unordered_map<uint16_t, bool> UDPSocket::availableIPv4Ports;
std::unordered_map<uint16_t, bool> UDPSocket::availableIPv6Ports;
/* Class methods. */
......@@ -54,7 +54,7 @@ namespace RTC
UDPSocket::minPort = Settings::configuration.rtcMinPort;
UDPSocket::maxPort = Settings::configuration.rtcMaxPort;
MS_PORT i = RTC::UDPSocket::minPort;
uint16_t i = RTC::UDPSocket::minPort;
do
{
RTC::UDPSocket::availableIPv4Ports[i] = true;
......@@ -103,13 +103,13 @@ namespace RTC
struct sockaddr_storage first_bind_addr;
struct sockaddr_storage second_bind_addr;
const char* listenIP;
MS_PORT random_first_port;
MS_PORT iterate_first_port;
MS_PORT iterate_second_port;
uint16_t random_first_port;
uint16_t iterate_first_port;
uint16_t iterate_second_port;
uint16_t attempt = 0;
uint16_t bindAttempt = 0;
int flags = 0;
std::unordered_map<MS_PORT, bool>* available_ports;
std::unordered_map<uint16_t, bool>* available_ports;
switch (address_family)
{
......@@ -135,7 +135,7 @@ namespace RTC
}
// Choose a random first port to start from.
random_first_port = (MS_PORT)Utils::Crypto::GetRandomUInt((uint32_t)RTC::UDPSocket::minPort, (uint32_t)RTC::UDPSocket::maxPort);
random_first_port = (uint16_t)Utils::Crypto::GetRandomUInt((uint32_t)RTC::UDPSocket::minPort, (uint32_t)RTC::UDPSocket::maxPort);
// Make it even if pair is requested.
if (pair)
random_first_port &= ~1;
......@@ -320,7 +320,7 @@ namespace RTC
MS_TRACE();
}
void UDPSocket::userOnUDPDatagramRecv(const MS_BYTE* data, size_t len, const struct sockaddr* addr)
void UDPSocket::userOnUDPDatagramRecv(const uint8_t* data, size_t len, const struct sockaddr* addr)
{
MS_TRACE();
......@@ -334,7 +334,7 @@ namespace RTC
if (Logger::HasDebugLevel())
{
int family;
MS_PORT port;
uint16_t port;
std::string ip;
Utils::IP::GetAddressInfo(addr, &family, ip, &port);
......
......@@ -238,7 +238,7 @@ void Settings::SetDefaultRtcListenIP(int requested_family)
continue;
int family;
MS_PORT port;
uint16_t port;
std::string ip;
Utils::IP::GetAddressInfo((struct sockaddr*)(&address.address.address4), &family, ip, &port);
......@@ -371,8 +371,8 @@ void Settings::SetRtcPorts()
{
MS_TRACE();
MS_PORT minPort = Settings::configuration.rtcMinPort;
MS_PORT maxPort = Settings::configuration.rtcMaxPort;
uint16_t minPort = Settings::configuration.rtcMinPort;
uint16_t maxPort = Settings::configuration.rtcMaxPort;
if (minPort < 1024)
MS_THROW_ERROR("rtcMinPort must be greater or equal than 1024");
......
......@@ -10,8 +10,8 @@ namespace Utils
uint32_t Crypto::seed;
HMAC_CTX Crypto::hmacSha1Ctx;
MS_BYTE Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long.
const MS_4BYTES Crypto::crc32Table[] =
uint8_t Crypto::hmacSha1Buffer[20]; // SHA-1 result is 20 bytes long.
const uint32_t Crypto::crc32Table[] =
{
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
......@@ -79,7 +79,7 @@ namespace Utils
HMAC_CTX_cleanup(&Crypto::hmacSha1Ctx);
}
const MS_BYTE* Crypto::GetHMAC_SHA1(const std::string &key, const MS_BYTE* data, size_t len)
const uint8_t* Crypto::GetHMAC_SHA1(const std::string &key, const uint8_t* data, size_t len)
{
MS_TRACE();
......
......@@ -3452,7 +3452,7 @@ case 85:
return AF_UNSPEC;
}
void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, MS_PORT* port)
void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, uint16_t* port)
{
MS_TRACE();
......@@ -3465,13 +3465,13 @@ case 85:
err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, INET_ADDRSTRLEN);
if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (MS_PORT)ntohs(((struct sockaddr_in*)addr)->sin_port);
*port = (uint16_t)ntohs(((struct sockaddr_in*)addr)->sin_port);
break;
case AF_INET6:
err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, INET6_ADDRSTRLEN);
if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (MS_PORT)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
*port = (uint16_t)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
break;
default:
MS_ABORT("unknown network family: %d", (int)addr->sa_family);
......
......@@ -68,7 +68,7 @@ namespace Utils
return AF_UNSPEC;
}
void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, MS_PORT* port)
void IP::GetAddressInfo(const struct sockaddr* addr, int* family, std::string &ip, uint16_t* port)
{
MS_TRACE();
......@@ -81,13 +81,13 @@ namespace Utils
err = uv_inet_ntop(AF_INET, &((struct sockaddr_in*)addr)->sin_addr, _ip, INET_ADDRSTRLEN);
if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (MS_PORT)ntohs(((struct sockaddr_in*)addr)->sin_port);
*port = (uint16_t)ntohs(((struct sockaddr_in*)addr)->sin_port);
break;
case AF_INET6:
err = uv_inet_ntop(AF_INET6, &((struct sockaddr_in6*)addr)->sin6_addr, _ip, INET6_ADDRSTRLEN);
if (err)
MS_ABORT("uv_inet_ntop() failed: %s", uv_strerror(err));
*port = (MS_PORT)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
*port = (uint16_t)ntohs(((struct sockaddr_in6*)addr)->sin6_port);
break;
default:
MS_ABORT("unknown network family: %d", (int)addr->sa_family);
......
......@@ -71,7 +71,7 @@ TCPConnection::~TCPConnection()
delete[] this->buffer;
}
void TCPConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, MS_PORT localPort)
void TCPConnection::Setup(Listener* listener, struct sockaddr_storage* localAddr, const std::string &localIP, uint16_t localPort)
{
MS_TRACE();
......@@ -155,7 +155,7 @@ void TCPConnection::Start()
MS_THROW_ERROR("error setting peer IP and port");
}
void TCPConnection::Write(const MS_BYTE* data, size_t len)
void TCPConnection::Write(const uint8_t* data, size_t len)
{
MS_TRACE();
......@@ -213,7 +213,7 @@ void TCPConnection::Write(const MS_BYTE* data, size_t len)
MS_ABORT("uv_write() failed: %s", uv_strerror(err));
}
void TCPConnection::Write(const MS_BYTE* data1, size_t len1, const MS_BYTE* data2, size_t len2)
void TCPConnection::Write(const uint8_t* data1, size_t len1, const uint8_t* data2, size_t len2)
{
MS_TRACE();
......@@ -311,7 +311,7 @@ void TCPConnection::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
// If this is the first call to onUvReadAlloc() then allocate the receiving buffer now.
if (!this->buffer)
this->buffer = new MS_BYTE[this->bufferSize];
this->buffer = new uint8_t[this->bufferSize];
// Tell UV to write after the last data byte in the buffer.
buf->base = (char *)(this->buffer + this->bufferDataLen);
......
......@@ -28,7 +28,7 @@ void on_error_close(uv_handle_t* handle)
/* Instance methods. */
TCPServer::TCPServer(const std::string &ip, MS_PORT port, int backlog)
TCPServer::TCPServer(const std::string &ip, uint16_t port, int backlog)
{
MS_TRACE();
......@@ -173,7 +173,7 @@ const std::string& TCPServer::GetLocalIP()
return this->localIP;
}
MS_PORT TCPServer::GetLocalPort()
uint16_t TCPServer::GetLocalPort()
{
MS_TRACE();
......
......@@ -50,7 +50,7 @@ void Timer::Close()
delete this;
}
void Timer::Start(MS_8BYTES timeout)
void Timer::Start(uint64_t timeout)
{
MS_TRACE();
......
......@@ -50,11 +50,11 @@ void on_error_close(uv_handle_t* handle)
/* Class variables. */
MS_BYTE UDPSocket::readBuffer[MS_READ_BUFFER_SIZE];
uint8_t UDPSocket::readBuffer[MS_READ_BUFFER_SIZE];
/* Instance methods. */
UDPSocket::UDPSocket(const std::string &ip, MS_PORT port)
UDPSocket::UDPSocket(const std::string &ip, uint16_t port)
{
MS_TRACE();
......@@ -176,7 +176,7 @@ void UDPSocket::Dump()
(!this->isClosing) ? "open" : "closed");
}
void UDPSocket::Send(const MS_BYTE* data, size_t len, const struct sockaddr* addr)
void UDPSocket::Send(const uint8_t* data, size_t len, const struct sockaddr* addr)
{
MS_TRACE();
......@@ -239,7 +239,7 @@ void UDPSocket::Send(const MS_BYTE* data, size_t len, const struct sockaddr* add
}
}
void UDPSocket::Send(const MS_BYTE* data, size_t len, const std::string &ip, MS_PORT port)
void UDPSocket::Send(const uint8_t* data, size_t len, const std::string &ip, uint16_t port)
{
MS_TRACE();
......@@ -333,7 +333,7 @@ void UDPSocket::onUvRecv(ssize_t nread, const uv_buf_t* buf, const struct sockad
if (nread > 0)
{
// Notify the subclass.
userOnUDPDatagramRecv((MS_BYTE*)buf->base, nread, addr);
userOnUDPDatagramRecv((uint8_t*)buf->base, nread, addr);
}
// Some error.
......
......@@ -138,7 +138,7 @@ void UnixStreamSocket::Close()
}
}
void UnixStreamSocket::Write(const MS_BYTE* data, size_t len)
void UnixStreamSocket::Write(const uint8_t* data, size_t len)
{
if (this->isClosing)
return;
......@@ -198,7 +198,7 @@ void UnixStreamSocket::onUvReadAlloc(size_t suggested_size, uv_buf_t* buf)
// If this is the first call to onUvReadAlloc() then allocate the receiving buffer now.
if (!this->buffer)
this->buffer = new MS_BYTE[this->bufferSize];
this->buffer = new uint8_t[this->bufferSize];
// Tell UV to write after the last data byte in the buffer.
buf->base = (char *)(this->buffer + this->bufferDataLen);
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论