Bug 1170299: Fix const-correctness on some functions. r=mjf

Making this part of the stack for bug 857668, since it avoids adding even more
const casting there.

Differential Revision: https://phabricator.services.mozilla.com/D115282
This commit is contained in:
Byron Campen [:bwc] 2021-05-27 21:08:40 +00:00
Родитель 11bc292b6d
Коммит 4197f6eb19
21 изменённых файлов: 101 добавлений и 121 удалений

Просмотреть файл

@ -179,11 +179,9 @@ void StunAddrsRequestParent::SendStunAddrs_m(const NrIceStunAddrArray& addrs) {
std::ostringstream o;
char buffer[16];
for (auto& addr : addrs) {
nr_transport_addr* local_addr =
const_cast<nr_transport_addr*>(&addr.localAddr().addr);
if (addr.localAddr().addr.ip_version == NR_IPV4 &&
!nr_transport_addr_is_loopback(local_addr)) {
nr_transport_addr_get_addrstring(local_addr, buffer, 16);
!nr_transport_addr_is_loopback(&addr.localAddr().addr)) {
nr_transport_addr_get_addrstring(&addr.localAddr().addr, buffer, 16);
o << buffer << ";";
}
}

Просмотреть файл

@ -379,7 +379,7 @@ int NrSocket::cancel(int how) {
}
// Helper functions for addresses
static int nr_transport_addr_to_praddr(nr_transport_addr* addr,
static int nr_transport_addr_to_praddr(const nr_transport_addr* addr,
PRNetAddr* naddr) {
int _status;
@ -444,7 +444,7 @@ abort:
return (_status);
}
static int nr_transport_addr_to_netaddr(nr_transport_addr* addr,
static int nr_transport_addr_to_netaddr(const nr_transport_addr* addr,
net::NetAddr* naddr) {
int r, _status;
PRNetAddr praddr;
@ -530,7 +530,7 @@ abort:
* nr_transport_addr_get_addrstring_and_port
* convert nr_transport_addr to IP address string and port number
*/
int nr_transport_addr_get_addrstring_and_port(nr_transport_addr* addr,
int nr_transport_addr_get_addrstring_and_port(const nr_transport_addr* addr,
nsACString* host, int32_t* port) {
int r, _status;
char addr_string[64];
@ -781,7 +781,7 @@ static int ShouldDrop(size_t len) {
// This should be called on the STS thread.
int NrSocket::sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) {
const nr_transport_addr* to) {
ASSERT_ON_THREAD(ststhread_);
int r, _status;
PRNetAddr naddr;
@ -848,7 +848,7 @@ void NrSocket::close() {
cancel(NR_ASYNC_WAIT_WRITE);
}
int NrSocket::connect(nr_transport_addr* addr) {
int NrSocket::connect(const nr_transport_addr* addr) {
ASSERT_ON_THREAD(ststhread_);
int r, _status;
PRNetAddr naddr;
@ -1301,7 +1301,7 @@ abort:
}
int NrUdpSocketIpc::sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) {
const nr_transport_addr* to) {
ASSERT_ON_THREAD(sts_thread_);
ReentrantMonitorAutoEnter mon(monitor_);
@ -1411,7 +1411,7 @@ int NrUdpSocketIpc::getaddr(nr_transport_addr* addrp) {
return nr_transport_addr_copy(addrp, &my_addr_);
}
int NrUdpSocketIpc::connect(nr_transport_addr* addr) {
int NrUdpSocketIpc::connect(const nr_transport_addr* addr) {
int r, _status;
int32_t port;
nsCString host;
@ -1604,14 +1604,14 @@ using namespace mozilla;
// Bridge to the nr_socket interface
static int nr_socket_local_destroy(void** objp);
static int nr_socket_local_sendto(void* obj, const void* msg, size_t len,
int flags, nr_transport_addr* to);
int flags, const nr_transport_addr* to);
static int nr_socket_local_recvfrom(void* obj, void* restrict buf,
size_t maxlen, size_t* len, int flags,
nr_transport_addr* from);
static int nr_socket_local_getfd(void* obj, NR_SOCKET* fd);
static int nr_socket_local_getaddr(void* obj, nr_transport_addr* addrp);
static int nr_socket_local_close(void* obj);
static int nr_socket_local_connect(void* sock, nr_transport_addr* addr);
static int nr_socket_local_connect(void* obj, const nr_transport_addr* addr);
static int nr_socket_local_write(void* obj, const void* msg, size_t len,
size_t* written);
static int nr_socket_local_read(void* obj, void* restrict buf, size_t maxlen,
@ -1710,7 +1710,7 @@ static int nr_socket_local_destroy(void** objp) {
}
static int nr_socket_local_sendto(void* obj, const void* msg, size_t len,
int flags, nr_transport_addr* addr) {
int flags, const nr_transport_addr* addr) {
NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
return sock->sendto(msg, len, flags, addr);
@ -1760,7 +1760,7 @@ static int nr_socket_local_read(void* obj, void* restrict buf, size_t maxlen,
return sock->read(buf, maxlen, len);
}
static int nr_socket_local_connect(void* obj, nr_transport_addr* addr) {
static int nr_socket_local_connect(void* obj, const nr_transport_addr* addr) {
NrSocketBase* sock = static_cast<NrSocketBase*>(obj);
return sock->connect(addr);

Просмотреть файл

@ -110,12 +110,12 @@ class NrSocketBase {
// the nr_socket APIs
virtual int create(nr_transport_addr* addr) = 0;
virtual int sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) = 0;
const nr_transport_addr* to) = 0;
virtual int recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
nr_transport_addr* from) = 0;
virtual int getaddr(nr_transport_addr* addrp) = 0;
virtual void close() = 0;
virtual int connect(nr_transport_addr* addr) = 0;
virtual int connect(const nr_transport_addr* addr) = 0;
virtual int write(const void* msg, size_t len, size_t* written) = 0;
virtual int read(void* buf, size_t maxlen, size_t* len) = 0;
virtual int listen(int backlog) = 0;
@ -172,12 +172,12 @@ class NrSocket : public NrSocketBase, public nsASocketHandler {
virtual int create(nr_transport_addr* addr)
override; // (really init, but it's called create)
virtual int sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) override;
const nr_transport_addr* to) override;
virtual int recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
nr_transport_addr* from) override;
virtual int getaddr(nr_transport_addr* addrp) override;
virtual void close() override;
virtual int connect(nr_transport_addr* addr) override;
virtual int connect(const nr_transport_addr* addr) override;
virtual int write(const void* msg, size_t len, size_t* written) override;
virtual int read(void* buf, size_t maxlen, size_t* len) override;
virtual int listen(int backlog) override;
@ -250,12 +250,12 @@ class NrUdpSocketIpc : public NrSocketIpc {
// Implementations of the NrSocketBase APIs
virtual int create(nr_transport_addr* addr) override;
virtual int sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) override;
const nr_transport_addr* to) override;
virtual int recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
nr_transport_addr* from) override;
virtual int getaddr(nr_transport_addr* addrp) override;
virtual void close() override;
virtual int connect(nr_transport_addr* addr) override;
virtual int connect(const nr_transport_addr* addr) override;
virtual int write(const void* msg, size_t len, size_t* written) override;
virtual int read(void* buf, size_t maxlen, size_t* len) override;
virtual int listen(int backlog) override;
@ -311,7 +311,7 @@ int nr_netaddr_to_transport_addr(const net::NetAddr* netaddr,
int nr_praddr_to_transport_addr(const PRNetAddr* praddr,
nr_transport_addr* addr, int protocol,
int keep);
int nr_transport_addr_get_addrstring_and_port(nr_transport_addr* addr,
int nr_transport_addr_get_addrstring_and_port(const nr_transport_addr* addr,
nsACString* host, int32_t* port);
} // namespace mozilla
#endif

Просмотреть файл

@ -95,7 +95,7 @@ int NrTcpSocket::create(nr_transport_addr* aAddr) {
return 0;
}
int NrTcpSocket::connect(nr_transport_addr* aAddr) {
int NrTcpSocket::connect(const nr_transport_addr* aAddr) {
r_log(LOG_GENERIC, LOG_DEBUG, "NrTcpSocket::connect %p\n", this);
nsCString remote_host;
@ -216,7 +216,7 @@ int NrTcpSocket::getaddr(nr_transport_addr* aAddr) {
}
int NrTcpSocket::sendto(const void* aBuffer, size_t aCount, int aFlags,
nr_transport_addr* aAddr) {
const nr_transport_addr* aAddr) {
// never call this
MOZ_ASSERT(0);
return R_FAILED;

Просмотреть файл

@ -74,13 +74,13 @@ class NrTcpSocket : public NrSocketBase, public WebrtcTCPSocketCallback {
// NrSocketBase
int create(nr_transport_addr* aAddr) override;
int connect(nr_transport_addr* aAddr) override;
int connect(const nr_transport_addr* aAddr) override;
void close() override;
int write(const void* aBuffer, size_t aCount, size_t* aWrote) override;
int read(void* aBuffer, size_t aCount, size_t* aRead) override;
int getaddr(nr_transport_addr* aAddr) override;
int sendto(const void* aBuffer, size_t aCount, int aFlags,
nr_transport_addr* aAddr) override;
const nr_transport_addr* aAddr) override;
int recvfrom(void* aBuffer, size_t aCount, size_t* aRead, int aFlags,
nr_transport_addr* aAddr) override;
int listen(int aBacklog) override;

Просмотреть файл

@ -62,7 +62,7 @@ class DummySocket : public NrSocketBase {
virtual int create(nr_transport_addr* addr) override { return 0; }
virtual int sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) override {
const nr_transport_addr* to) override {
MOZ_CRASH();
return 0;
}
@ -80,7 +80,7 @@ class DummySocket : public NrSocketBase {
virtual void close() override {}
virtual int connect(nr_transport_addr* addr) override {
virtual int connect(const nr_transport_addr* addr) override {
nr_transport_addr_copy(&connect_addr_, addr);
return 0;
}

Просмотреть файл

@ -128,7 +128,7 @@ static int nr_socket_wrapped_destroy(void** objp) {
}
static int nr_socket_wrapped_sendto(void* obj, const void* msg, size_t len,
int flags, nr_transport_addr* addr) {
int flags, const nr_transport_addr* addr) {
nr_socket_wrapped* wrapped = static_cast<nr_socket_wrapped*>(obj);
return nr_socket_sendto(wrapped->sock_, msg, len, flags, &wrapped->addr_);

Просмотреть файл

@ -372,7 +372,7 @@ TEST_F(TestNrSocketIceUnitTest, TestIcePeersPacketLoss) {
}
int on_sendto(TestNat* nat, const void* msg, size_t len, int flags,
nr_transport_addr* to) override {
const nr_transport_addr* to) override {
++messages;
// 25% packet loss
if (messages % 4 == 0) {

Просмотреть файл

@ -252,10 +252,7 @@ class TestNrSocketTest : public MtransportTest {
int SendData_s(TestNrSocket* from, const nr_transport_addr& to) {
// It is up to caller to ensure that |from| is writeable.
const char buf[] = "foobajooba";
return from->sendto(
buf, sizeof(buf), 0,
// TODO(bug 1170299): Remove const_cast when no longer necessary
const_cast<nr_transport_addr*>(&to));
return from->sendto(buf, sizeof(buf), 0, &to);
}
int SendDataTcp_s(NrSocketBase* from) {

Просмотреть файл

@ -175,9 +175,7 @@ bool TestNat::is_an_internal_tuple(const nr_transport_addr& addr) const {
MOZ_CRASH("TestNrSocket::getaddr failed!");
}
// TODO(bug 1170299): Remove const_cast when no longer necessary
if (!nr_transport_addr_cmp(const_cast<nr_transport_addr*>(&addr),
&addr_behind_nat,
if (!nr_transport_addr_cmp(&addr, &addr_behind_nat,
NR_TRANSPORT_ADDR_CMP_MODE_ALL)) {
return true;
}
@ -210,10 +208,8 @@ RefPtr<NrSocketBase> TestNrSocket::create_external_socket(
nr_transport_addr nat_external_addr;
// Open the socket on an arbitrary port, on the same address.
// TODO(bug 1170299): Remove const_cast when no longer necessary
if ((r = nr_transport_addr_copy(
&nat_external_addr,
const_cast<nr_transport_addr*>(&internal_socket_->my_addr())))) {
if ((r = nr_transport_addr_copy(&nat_external_addr,
&internal_socket_->my_addr()))) {
r_log(LOG_GENERIC, LOG_CRIT, "%s: Failure in nr_transport_addr_copy: %d",
__FUNCTION__, r);
return nullptr;
@ -295,7 +291,7 @@ void TestNrSocket::process_delayed_cb(NR_SOCKET s, int how, void* cb_arg) {
}
int TestNrSocket::sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) {
const nr_transport_addr* to) {
MOZ_ASSERT(internal_socket_->my_addr().protocol != IPPROTO_TCP);
if (nat_->nat_delegate_ &&
@ -468,7 +464,7 @@ bool TestNrSocket::allow_ingress(const nr_transport_addr& from,
return true;
}
int TestNrSocket::connect(nr_transport_addr* addr) {
int TestNrSocket::connect(const nr_transport_addr* addr) {
r_log(LOG_GENERIC, LOG_DEBUG, "TestNrSocket %p %s connecting", this,
internal_socket_->my_addr().as_string);
@ -749,9 +745,7 @@ bool TestNrSocket::is_my_external_tuple(const nr_transport_addr& addr) const {
MOZ_CRASH("NrSocket::getaddr failed!");
}
// TODO(bug 1170299): Remove const_cast when no longer necessary
if (!nr_transport_addr_cmp(const_cast<nr_transport_addr*>(&addr),
&port_mapping_addr,
if (!nr_transport_addr_cmp(&addr, &port_mapping_addr,
NR_TRANSPORT_ADDR_CMP_MODE_ALL)) {
return true;
}
@ -868,10 +862,10 @@ TestNrSocket::PortMapping* TestNrSocket::get_port_mapping(
}
for (PortMapping* port_mapping : port_mappings_) {
// TODO(bug 1170299): Remove const_cast when no longer necessary
if (!nr_transport_addr_cmp(const_cast<nr_transport_addr*>(&remote_address),
&port_mapping->remote_address_, compare_flags))
if (!nr_transport_addr_cmp(&remote_address, &port_mapping->remote_address_,
compare_flags)) {
return port_mapping;
}
}
return nullptr;
}
@ -890,9 +884,7 @@ TestNrSocket::PortMapping::PortMapping(
const nr_transport_addr& remote_address,
const RefPtr<NrSocketBase>& external_socket)
: external_socket_(external_socket) {
// TODO(bug 1170299): Remove const_cast when no longer necessary
nr_transport_addr_copy(&remote_address_,
const_cast<nr_transport_addr*>(&remote_address));
nr_transport_addr_copy(&remote_address_, &remote_address);
}
int TestNrSocket::PortMapping::send_from_queue() {
@ -934,10 +926,7 @@ int TestNrSocket::PortMapping::sendto(const void* msg, size_t len,
to.as_string);
last_used_ = PR_IntervalNow();
int r = external_socket_->sendto(
msg, len, 0,
// TODO(bug 1170299): Remove const_cast when no longer necessary
const_cast<nr_transport_addr*>(&to));
int r = external_socket_->sendto(msg, len, 0, &to);
if (r == R_WOULDBLOCK) {
r_log(LOG_GENERIC, LOG_DEBUG, "Enqueueing UDP packet to %s", to.as_string);
@ -975,7 +964,7 @@ class nr_stun_message_deleter {
};
bool TestNrSocket::maybe_send_fake_response(const void* msg, size_t len,
nr_transport_addr* to) {
const nr_transport_addr* to) {
Maybe<nsTArray<nsCString>> redirect_targets = maybe_get_redirect_targets(to);
if (!redirect_targets.isSome()) {
return false;
@ -1079,7 +1068,7 @@ bool TestNrSocket::maybe_send_fake_response(const void* msg, size_t len,
}
Maybe<nsTArray<nsCString>> TestNrSocket::maybe_get_redirect_targets(
nr_transport_addr* to) const {
const nr_transport_addr* to) const {
Maybe<nsTArray<nsCString>> result;
// 256 is overkill, but it hardly matters

Просмотреть файл

@ -125,7 +125,7 @@ class TestNat {
virtual int on_read(TestNat* nat, void* buf, size_t maxlen,
size_t* len) = 0;
virtual int on_sendto(TestNat* nat, const void* msg, size_t len, int flags,
nr_transport_addr* to) = 0;
const nr_transport_addr* to) = 0;
virtual int on_write(TestNat* nat, const void* msg, size_t len,
size_t* written) = 0;
};
@ -221,12 +221,12 @@ class TestNrSocket : public NrSocketBase {
// Overrides of NrSocketBase
int create(nr_transport_addr* addr) override;
int sendto(const void* msg, size_t len, int flags,
nr_transport_addr* to) override;
const nr_transport_addr* to) override;
int recvfrom(void* buf, size_t maxlen, size_t* len, int flags,
nr_transport_addr* from) override;
int getaddr(nr_transport_addr* addrp) override;
void close() override;
int connect(nr_transport_addr* addr) override;
int connect(const nr_transport_addr* addr) override;
int write(const void* msg, size_t len, size_t* written) override;
int read(void* buf, size_t maxlen, size_t* len) override;
@ -247,9 +247,7 @@ class TestNrSocket : public NrSocketBase {
UdpPacket(const void* msg, size_t len, const nr_transport_addr& addr)
: buffer_(new MediaPacket) {
buffer_->Copy(static_cast<const uint8_t*>(msg), len);
// TODO(bug 1170299): Remove const_cast when no longer necessary
nr_transport_addr_copy(&remote_address_,
const_cast<nr_transport_addr*>(&addr));
nr_transport_addr_copy(&remote_address_, &addr);
}
UdpPacket(UdpPacket&& aOrig) = default;
@ -288,7 +286,7 @@ class TestNrSocket : public NrSocketBase {
struct DeferredPacket {
DeferredPacket(TestNrSocket* sock, const void* data, size_t len, int flags,
nr_transport_addr* addr,
const nr_transport_addr* addr,
RefPtr<NrSocketBase> internal_socket)
: socket_(sock),
buffer_(),
@ -335,9 +333,9 @@ class TestNrSocket : public NrSocketBase {
static void process_delayed_cb(NR_SOCKET s, int how, void* cb_arg);
bool maybe_send_fake_response(const void* msg, size_t len,
nr_transport_addr* to);
const nr_transport_addr* to);
Maybe<nsTArray<nsCString>> maybe_get_redirect_targets(
nr_transport_addr* to) const;
const nr_transport_addr* to) const;
RefPtr<NrSocketBase> readable_socket_;
// The socket for the "internal" address; used to talk to stuff behind the

Просмотреть файл

@ -81,7 +81,7 @@ int nr_socket_destroy(nr_socket **sockp)
}
int nr_socket_sendto(nr_socket *sock,const void *msg, size_t len, int flags,
nr_transport_addr *addr)
const nr_transport_addr *addr)
{
CHECK_DEFINED(ssendto);
return sock->vtbl->ssendto(sock->obj,msg,len,flags,addr);
@ -112,7 +112,7 @@ int nr_socket_close(nr_socket *sock)
return sock->vtbl->close(sock->obj);
}
int nr_socket_connect(nr_socket *sock, nr_transport_addr *addr)
int nr_socket_connect(nr_socket *sock, const nr_transport_addr *addr)
{
CHECK_DEFINED(connect);
return sock->vtbl->connect(sock->obj, addr);

Просмотреть файл

@ -68,12 +68,12 @@ typedef struct nr_socket_vtbl_ {
UINT4 version; /* Currently 2 */
int (*destroy)(void **obj);
int (*ssendto)(void *obj,const void *msg, size_t len, int flags,
nr_transport_addr *addr);
const nr_transport_addr *addr);
int (*srecvfrom)(void *obj,void * restrict buf, size_t maxlen, size_t *len, int flags,
nr_transport_addr *addr);
int (*getfd)(void *obj, NR_SOCKET *fd);
int (*getaddr)(void *obj, nr_transport_addr *addrp);
int (*connect)(void *obj, nr_transport_addr *addr);
int (*connect)(void *obj, const nr_transport_addr *addr);
int (*swrite)(void *obj,const void *msg, size_t len, size_t *written);
int (*sread)(void *obj,void * restrict buf, size_t maxlen, size_t *len);
int (*close)(void *obj);
@ -103,13 +103,13 @@ typedef struct nr_socket_factory_ {
int nr_socket_create_int(void *obj, nr_socket_vtbl *vtbl, nr_socket **sockp);
int nr_socket_destroy(nr_socket **sockp);
int nr_socket_sendto(nr_socket *sock,const void *msg, size_t len,
int flags,nr_transport_addr *addr);
int flags, const nr_transport_addr *addr);
int nr_socket_recvfrom(nr_socket *sock,void * restrict buf, size_t maxlen,
size_t *len, int flags, nr_transport_addr *addr);
int nr_socket_getfd(nr_socket *sock, NR_SOCKET *fd);
int nr_socket_getaddr(nr_socket *sock, nr_transport_addr *addrp);
int nr_socket_close(nr_socket *sock);
int nr_socket_connect(nr_socket *sock, nr_transport_addr *addr);
int nr_socket_connect(nr_socket *sock, const nr_transport_addr *addr);
int nr_socket_write(nr_socket *sock,const void *msg, size_t len, size_t *written, int flags);
int nr_socket_read(nr_socket *sock, void * restrict buf, size_t maxlen, size_t *len, int flags);
int nr_socket_listen(nr_socket *sock, int backlog);

Просмотреть файл

@ -107,7 +107,7 @@ abort:
}
static int nr_tcp_socket_ctx_initialize(nr_tcp_socket_ctx *tcpsock,
nr_transport_addr *addr, void* cb_arg)
const nr_transport_addr *addr, void* cb_arg)
{
int r, _status;
NR_SOCKET fd;
@ -138,12 +138,12 @@ typedef struct nr_socket_multi_tcp_ {
static int nr_socket_multi_tcp_destroy(void **objp);
static int nr_socket_multi_tcp_sendto(void *obj,const void *msg, size_t len,
int flags, nr_transport_addr *to);
int flags, const nr_transport_addr *to);
static int nr_socket_multi_tcp_recvfrom(void *obj,void * restrict buf,
size_t maxlen, size_t *len, int flags, nr_transport_addr *from);
static int nr_socket_multi_tcp_getaddr(void *obj, nr_transport_addr *addrp);
static int nr_socket_multi_tcp_close(void *obj);
static int nr_socket_multi_tcp_connect(void *sock, nr_transport_addr *addr);
static int nr_socket_multi_tcp_connect(void *sock, const nr_transport_addr *addr);
static int nr_socket_multi_tcp_listen(void *obj, int backlog);
static nr_socket_vtbl nr_socket_multi_tcp_vtbl={
@ -309,14 +309,12 @@ int nr_socket_multi_tcp_set_readable_cb(nr_socket *sock,
#define PREALLOC_DONT_CONNECT_UNLESS_SO 2
static int nr_socket_multi_tcp_get_sock_connected_to(nr_socket_multi_tcp *sock,
nr_transport_addr *to, int preallocated_connect_mode, nr_socket **ret_sock)
const nr_transport_addr *to, int preallocated_connect_mode, nr_socket **ret_sock)
{
int r, _status;
nr_tcp_socket_ctx *tcp_sock_ctx;
nr_socket * nrsock;
to->protocol=IPPROTO_TCP;
TAILQ_FOREACH(tcp_sock_ctx, &sock->sockets, entry) {
if (!nr_transport_addr_is_wildcard(&tcp_sock_ctx->remote_addr)) {
if (!nr_transport_addr_cmp(to, &tcp_sock_ctx->remote_addr, NR_TRANSPORT_ADDR_CMP_MODE_ALL)) {
@ -397,7 +395,7 @@ static int nr_socket_multi_tcp_get_sock_connected_to(nr_socket_multi_tcp *sock,
}
int nr_socket_multi_tcp_stun_server_connect(nr_socket *sock,
nr_transport_addr *addr)
const nr_transport_addr *addr)
{
int r, _status;
nr_socket_multi_tcp *mtcp_sock = (nr_socket_multi_tcp *)sock->obj;
@ -454,7 +452,7 @@ static int nr_socket_multi_tcp_destroy(void **objp)
}
static int nr_socket_multi_tcp_sendto(void *obj, const void *msg, size_t len,
int flags, nr_transport_addr *to)
int flags, const nr_transport_addr *to)
{
int r, _status;
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;
@ -548,7 +546,7 @@ static void nr_tcp_socket_readable_cb(NR_SOCKET s, int how, void *arg)
sock->readable_cb(s, how, sock->readable_cb_arg);
}
static int nr_socket_multi_tcp_connect(void *obj, nr_transport_addr *addr)
static int nr_socket_multi_tcp_connect(void *obj, const nr_transport_addr *addr)
{
int r, _status;
nr_socket_multi_tcp *sock=(nr_socket_multi_tcp *)obj;

Просмотреть файл

@ -47,6 +47,6 @@ int nr_socket_multi_tcp_set_readable_cb(nr_socket *sock,
NR_async_cb readable_cb,void *readable_cb_arg);
int nr_socket_multi_tcp_stun_server_connect(nr_socket *sock,
nr_transport_addr *addr);
const nr_transport_addr *addr);
#endif

Просмотреть файл

@ -162,7 +162,7 @@ int nr_sockaddr_to_transport_addr(struct sockaddr *saddr, int protocol, int keep
}
int nr_transport_addr_copy(nr_transport_addr *to, nr_transport_addr *from)
int nr_transport_addr_copy(nr_transport_addr *to, const nr_transport_addr *from)
{
int _status;
@ -186,7 +186,7 @@ int nr_transport_addr_copy(nr_transport_addr *to, nr_transport_addr *from)
return(_status);
}
int nr_transport_addr_copy_keep_ifname(nr_transport_addr *to, nr_transport_addr *from)
int nr_transport_addr_copy_keep_ifname(nr_transport_addr *to, const nr_transport_addr *from)
{
int r,_status;
char save_ifname[MAXIFNAME];
@ -308,7 +308,7 @@ int nr_transport_addr_get_addrstring(const nr_transport_addr *addr, char *str, i
return(_status);
}
int nr_transport_addr_get_port(nr_transport_addr *addr, int *port)
int nr_transport_addr_get_port(const nr_transport_addr *addr, int *port)
{
int _status;
@ -350,7 +350,7 @@ int nr_transport_addr_set_port(nr_transport_addr *addr, int port)
/* memcmp() may not work if, for instance, the string or interface
haven't been made. Hmmm.. */
int nr_transport_addr_cmp(nr_transport_addr *addr1,nr_transport_addr *addr2,int mode)
int nr_transport_addr_cmp(const nr_transport_addr *addr1,const nr_transport_addr *addr2,int mode)
{
assert(mode);
@ -391,7 +391,7 @@ int nr_transport_addr_cmp(nr_transport_addr *addr1,nr_transport_addr *addr2,int
return(0);
}
int nr_transport_addr_is_loopback(nr_transport_addr *addr)
int nr_transport_addr_is_loopback(const nr_transport_addr *addr)
{
switch(addr->ip_version){
case NR_IPV4:
@ -417,7 +417,7 @@ int nr_transport_addr_is_loopback(nr_transport_addr *addr)
return(0);
}
int nr_transport_addr_is_link_local(nr_transport_addr *addr)
int nr_transport_addr_is_link_local(const nr_transport_addr *addr)
{
switch(addr->ip_version){
case NR_IPV4:
@ -439,7 +439,7 @@ int nr_transport_addr_is_link_local(nr_transport_addr *addr)
return(0);
}
int nr_transport_addr_is_mac_based(nr_transport_addr *addr)
int nr_transport_addr_is_mac_based(const nr_transport_addr *addr)
{
switch(addr->ip_version){
case NR_IPV4:
@ -463,7 +463,7 @@ int nr_transport_addr_is_mac_based(nr_transport_addr *addr)
return(0);
}
int nr_transport_addr_is_teredo(nr_transport_addr *addr)
int nr_transport_addr_is_teredo(const nr_transport_addr *addr)
{
switch(addr->ip_version){
case NR_IPV4:
@ -482,7 +482,7 @@ int nr_transport_addr_is_teredo(nr_transport_addr *addr)
return(0);
}
int nr_transport_addr_check_compatibility(nr_transport_addr *addr1, nr_transport_addr *addr2)
int nr_transport_addr_check_compatibility(const nr_transport_addr *addr1, const nr_transport_addr *addr2)
{
// first make sure we're comparing the same ip versions and protocols
if ((addr1->ip_version != addr2->ip_version) ||
@ -500,7 +500,7 @@ int nr_transport_addr_check_compatibility(nr_transport_addr *addr1, nr_transport
return(0);
}
int nr_transport_addr_is_wildcard(nr_transport_addr *addr)
int nr_transport_addr_is_wildcard(const nr_transport_addr *addr)
{
switch(addr->ip_version){
case NR_IPV4:
@ -533,7 +533,7 @@ nr_transport_addr_mask nr_private_ipv4_addrs[] = {
{0x64400000, 0xFFC00000}
};
int nr_transport_addr_get_private_addr_range(nr_transport_addr *addr)
int nr_transport_addr_get_private_addr_range(const nr_transport_addr *addr)
{
switch(addr->ip_version){
case NR_IPV4:
@ -554,7 +554,7 @@ int nr_transport_addr_get_private_addr_range(nr_transport_addr *addr)
return(0);
}
int nr_transport_addr_is_reliable_transport(nr_transport_addr *addr)
int nr_transport_addr_is_reliable_transport(const nr_transport_addr *addr)
{
return addr->protocol == IPPROTO_TCP;
}

Просмотреть файл

@ -87,26 +87,26 @@ int nr_str_port_to_transport_addr(const char *str, UINT2 port, int protocol, nr_
int nr_ip6_port_to_transport_addr(struct in6_addr* addr6, UINT2 port, int protocol, nr_transport_addr *addr);
int nr_transport_addr_get_addrstring(const nr_transport_addr *addr, char *str, int maxlen);
int nr_transport_addr_get_port(nr_transport_addr *addr, int *port);
int nr_transport_addr_cmp(nr_transport_addr *addr1,nr_transport_addr *addr2,int mode);
int nr_transport_addr_get_port(const nr_transport_addr *addr, int *port);
int nr_transport_addr_cmp(const nr_transport_addr *addr1,const nr_transport_addr *addr2,int mode);
#define NR_TRANSPORT_ADDR_CMP_MODE_VERSION 1
#define NR_TRANSPORT_ADDR_CMP_MODE_PROTOCOL 2
#define NR_TRANSPORT_ADDR_CMP_MODE_ADDR 3
#define NR_TRANSPORT_ADDR_CMP_MODE_ALL 4
int nr_transport_addr_is_wildcard(nr_transport_addr *addr);
int nr_transport_addr_is_loopback(nr_transport_addr *addr);
int nr_transport_addr_get_private_addr_range(nr_transport_addr *addr);
int nr_transport_addr_is_link_local(nr_transport_addr *addr);
int nr_transport_addr_is_mac_based(nr_transport_addr *addr);
int nr_transport_addr_is_teredo(nr_transport_addr *addr);
int nr_transport_addr_check_compatibility(nr_transport_addr *addr1, nr_transport_addr *addr2);
int nr_transport_addr_copy(nr_transport_addr *to, nr_transport_addr *from);
int nr_transport_addr_copy_keep_ifname(nr_transport_addr *to, nr_transport_addr *from);
int nr_transport_addr_is_wildcard(const nr_transport_addr *addr);
int nr_transport_addr_is_loopback(const nr_transport_addr *addr);
int nr_transport_addr_get_private_addr_range(const nr_transport_addr *addr);
int nr_transport_addr_is_link_local(const nr_transport_addr *addr);
int nr_transport_addr_is_mac_based(const nr_transport_addr *addr);
int nr_transport_addr_is_teredo(const nr_transport_addr *addr);
int nr_transport_addr_check_compatibility(const nr_transport_addr *addr1, const nr_transport_addr *addr2);
int nr_transport_addr_copy(nr_transport_addr *to, const nr_transport_addr *from);
int nr_transport_addr_copy_keep_ifname(nr_transport_addr *to, const nr_transport_addr *from);
int nr_transport_addr_fmt_addr_string(nr_transport_addr *addr);
int nr_transport_addr_fmt_ifname_addr_string(const nr_transport_addr *addr, char *buf, int len);
int nr_transport_addr_set_port(nr_transport_addr *addr, int port);
int nr_transport_addr_is_reliable_transport(nr_transport_addr *addr);
int nr_transport_addr_is_reliable_transport(const nr_transport_addr *addr);
#endif

Просмотреть файл

@ -79,13 +79,13 @@ typedef struct nr_socket_buffered_stun_ {
static int nr_socket_buffered_stun_destroy(void **objp);
static int nr_socket_buffered_stun_sendto(void *obj,const void *msg, size_t len,
int flags, nr_transport_addr *to);
int flags, const nr_transport_addr *to);
static int nr_socket_buffered_stun_recvfrom(void *obj,void * restrict buf,
size_t maxlen, size_t *len, int flags, nr_transport_addr *from);
static int nr_socket_buffered_stun_getfd(void *obj, NR_SOCKET *fd);
static int nr_socket_buffered_stun_getaddr(void *obj, nr_transport_addr *addrp);
static int nr_socket_buffered_stun_close(void *obj);
static int nr_socket_buffered_stun_connect(void *sock, nr_transport_addr *addr);
static int nr_socket_buffered_stun_connect(void *sock, const nr_transport_addr *addr);
static int nr_socket_buffered_stun_write(void *obj,const void *msg, size_t len, size_t *written);
static void nr_socket_buffered_stun_writable_cb(NR_SOCKET s, int how, void *arg);
static int nr_socket_buffered_stun_listen(void *obj, int backlog);
@ -216,7 +216,7 @@ int nr_socket_buffered_stun_destroy(void **objp)
}
static int nr_socket_buffered_stun_sendto(void *obj,const void *msg, size_t len,
int flags, nr_transport_addr *to)
int flags, const nr_transport_addr *to)
{
nr_socket_buffered_stun *sock = (nr_socket_buffered_stun *)obj;
int r, _status;
@ -440,7 +440,7 @@ abort:
}
}
static int nr_socket_buffered_stun_connect(void *obj, nr_transport_addr *addr)
static int nr_socket_buffered_stun_connect(void *obj, const nr_transport_addr *addr)
{
nr_socket_buffered_stun *sock = (nr_socket_buffered_stun *)obj;
int r, _status;

Просмотреть файл

@ -53,7 +53,7 @@ typedef struct nr_socket_turn_ {
static int nr_socket_turn_destroy(void **objp);
static int nr_socket_turn_sendto(void *obj,const void *msg, size_t len,
int flags, nr_transport_addr *to);
int flags, const nr_transport_addr *to);
static int nr_socket_turn_recvfrom(void *obj,void * restrict buf,
size_t maxlen, size_t *len, int flags, nr_transport_addr *from);
static int nr_socket_turn_getfd(void *obj, NR_SOCKET *fd);
@ -118,7 +118,7 @@ static int nr_socket_turn_destroy(void **objp)
}
static int nr_socket_turn_sendto(void *obj,const void *msg, size_t len,
int flags, nr_transport_addr *addr)
int flags, const nr_transport_addr *addr)
{
int r,_status;
nr_socket_turn *sturn=obj;

Просмотреть файл

@ -79,10 +79,10 @@ static int nr_turn_client_start_refresh_timer(nr_turn_client_ctx *ctx,
nr_turn_stun_ctx *sctx,
UINT4 lifetime);
static int nr_turn_permission_create(nr_turn_client_ctx *ctx,
nr_transport_addr *addr,
const nr_transport_addr *addr,
nr_turn_permission **permp);
static int nr_turn_permission_find(nr_turn_client_ctx *ctx,
nr_transport_addr *addr,
const nr_transport_addr *addr,
nr_turn_permission **permp);
static int nr_turn_permission_destroy(nr_turn_permission **permp);
static void nr_turn_client_refresh_cb(NR_SOCKET s, int how, void *arg);
@ -809,7 +809,7 @@ abort:
We might in the future. Mozilla bug 857736 */
int nr_turn_client_send_indication(nr_turn_client_ctx *ctx,
const UCHAR *msg, size_t len,
int flags, nr_transport_addr *remote_addr)
int flags, const nr_transport_addr *remote_addr)
{
int r,_status;
nr_stun_client_send_indication_params params = { { 0 } };
@ -923,7 +923,7 @@ abort:
unused.
*/
int nr_turn_client_ensure_perm(nr_turn_client_ctx *ctx, nr_transport_addr *addr)
int nr_turn_client_ensure_perm(nr_turn_client_ctx *ctx, const nr_transport_addr *addr)
{
int r, _status;
nr_turn_permission *perm = 0;
@ -962,7 +962,7 @@ abort:
return(_status);
}
static int nr_turn_permission_create(nr_turn_client_ctx *ctx, nr_transport_addr *addr,
static int nr_turn_permission_create(nr_turn_client_ctx *ctx, const nr_transport_addr *addr,
nr_turn_permission **permp)
{
int r, _status;
@ -1007,7 +1007,7 @@ abort:
}
static int nr_turn_permission_find(nr_turn_client_ctx *ctx, nr_transport_addr *addr,
static int nr_turn_permission_find(nr_turn_client_ctx *ctx, const nr_transport_addr *addr,
nr_turn_permission **permp)
{
nr_turn_permission *perm;

Просмотреть файл

@ -129,7 +129,7 @@ int nr_turn_client_failed(nr_turn_client_ctx *ctx);
int nr_turn_client_deallocate(nr_turn_client_ctx *ctx);
int nr_turn_client_send_indication(nr_turn_client_ctx *ctx,
const UCHAR *msg, size_t len,
int flags, nr_transport_addr *remote_addr);
int flags, const nr_transport_addr *remote_addr);
int nr_turn_client_parse_data_indication(nr_turn_client_ctx *ctx,
nr_transport_addr *source_addr,
UCHAR *msg, size_t len,
@ -137,6 +137,6 @@ int nr_turn_client_parse_data_indication(nr_turn_client_ctx *ctx,
size_t newsize,
nr_transport_addr *remote_addr);
int nr_turn_client_ensure_perm(nr_turn_client_ctx *ctx,
nr_transport_addr *addr);
const nr_transport_addr *addr);
#endif