[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gnash-commit] /srv/bzr/gnash/trunk r12020: Fixes and documentation for
From: |
Benjamin Wolsey |
Subject: |
[Gnash-commit] /srv/bzr/gnash/trunk r12020: Fixes and documentation for XMLSocket and Socket. |
Date: |
Thu, 11 Mar 2010 13:41:28 +0100 |
User-agent: |
Bazaar (2.0.3) |
------------------------------------------------------------
revno: 12020 [merge]
committer: Benjamin Wolsey <address@hidden>
branch nick: trunk
timestamp: Thu 2010-03-11 13:41:28 +0100
message:
Fixes and documentation for XMLSocket and Socket.
modified:
libbase/Socket.cpp
libbase/Socket.h
libcore/URLAccessManager.cpp
libcore/asobj/flash/net/XMLSocket_as.cpp
=== modified file 'libbase/Socket.cpp'
--- a/libbase/Socket.cpp 2010-03-10 17:31:45 +0000
+++ b/libbase/Socket.cpp 2010-03-11 11:59:51 +0000
@@ -113,19 +113,24 @@
_socket = 0;
_size = 0;
_pos = 0;
+ _connected = false;
+ _error = false;
}
bool
Socket::connect(const std::string& hostname, boost::uint16_t port)
{
- if (connected()) {
+ // We use _socket here because connected() or _connected might not
+ // be true if a connection attempt is underway but not completed.
+ if (_socket) {
log_error("Connection attempt while already connected");
return false;
}
+ // If _socket is 0, either there has been no connection, or close() has
+ // been called. There must not be an error in either case.
assert(!_error);
- assert(!_socket);
if (hostname.empty()) return false;
=== modified file 'libbase/Socket.h'
--- a/libbase/Socket.h 2010-03-10 13:05:38 +0000
+++ b/libbase/Socket.h 2010-03-11 11:37:39 +0000
@@ -117,11 +117,11 @@
private:
- mutable bool _connected;
-
/// Fill the cache.
void fillCache();
+ mutable bool _connected;
+
/// A cache for received data.
boost::uint8_t _cache[16384];
=== modified file 'libcore/URLAccessManager.cpp'
--- a/libcore/URLAccessManager.cpp 2010-01-25 18:52:20 +0000
+++ b/libcore/URLAccessManager.cpp 2010-03-11 12:22:09 +0000
@@ -264,8 +264,12 @@
}
bool
-allowXMLSocket(const std::string& host, short /* port */)
+allowXMLSocket(const std::string& host, short port)
{
+ if (port < 1024) {
+ log_security("Attempt to connect to disallowed port %s", port);
+ return false;
+ }
return allowHost(host);
}
=== modified file 'libcore/asobj/flash/net/XMLSocket_as.cpp'
--- a/libcore/asobj/flash/net/XMLSocket_as.cpp 2010-03-11 01:47:08 +0000
+++ b/libcore/asobj/flash/net/XMLSocket_as.cpp 2010-03-11 12:15:22 +0000
@@ -67,11 +67,19 @@
~XMLSocket_as();
/// True only when the XMLSocket is ready for read/write.
+ //
+ /// This should always match the known state of the Socket.
bool ready() const {
return _ready;
}
/// Attempt a connection.
+ //
+ /// @param host The host name to connect to.
+ /// @param port The port to connect to.
+ /// @return false if the connection is not allowed, otherwise true.
+ /// Note that a return of true does not mean a successful
+ /// connection.
bool connect(const std::string& host, boost::uint16_t port);
/// Send a string with a null-terminator to the socket.
@@ -79,12 +87,20 @@
/// Actionscript doesn't care about the result.
void send(std::string str);
- /// Close the socket
- //
- /// Actionscript doesn't care about the result.
+ /// Close the XMLSocket
+ //
+ /// This removes the core callback and instructs the Socket to close
+ /// in case it isn't already. After close() is called, the XMLSocket is
+ /// no longer ready.
+ //
+ /// You must call close() to ensure that the Socket object is ready for
+ /// a new connection.
void close();
/// Called on advance() when socket is connected
+ //
+ /// This handles reading of data and error checking. If the Socket is
+ /// in error, it is closed and this XMLSocket object is no longer ready.
virtual void update();
private:
@@ -241,11 +257,10 @@
if (_socket.bad()) {
callMethod(&owner(), NSV::PROP_ON_CLOSE);
- getRoot(owner()).removeAdvanceCallback(this);
+ close();
return;
}
-
}
@@ -254,7 +269,7 @@
void
XMLSocket_as::send(std::string str)
{
- if (!_socket.connected()) {
+ if (!ready()) {
log_error(_("XMLSocket.send(): socket not initialized"));
return;
}
@@ -349,8 +364,6 @@
as_value
xmlsocket_close(const fn_call& fn)
{
- GNASH_REPORT_FUNCTION;
-
XMLSocket_as* ptr = ensure<ThisIsNative<XMLSocket_as> >(fn);
ptr->close();
@@ -368,7 +381,6 @@
as_value
xmlsocket_onData(const fn_call& fn)
{
- GNASH_REPORT_FUNCTION;
if (!fn.nargs) {
IF_VERBOSE_ASCODING_ERRORS(
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gnash-commit] /srv/bzr/gnash/trunk r12020: Fixes and documentation for XMLSocket and Socket.,
Benjamin Wolsey <=